基本信息
源码名称:c# 投票网站完整源码下载(含数据库)
源码大小:0.06M
文件格式:.rar
开发语言:C#
更新时间:2014-03-10
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
入门级的实例 大家多多交流学习
入门级的实例 大家多多交流学习
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Data.SqlClient; namespace vote { /// <summary> /// vote 的摘要说明。 /// </summary> public class vote : System.Web.UI.Page { protected System.Web.UI.WebControls.Panel Panel1; protected System.Web.UI.WebControls.Label title; protected System.Web.UI.WebControls.Button updata; protected System.Web.UI.WebControls.RadioButtonList radl; protected System.Web.UI.WebControls.CheckBoxList chkl; protected System.Web.UI.WebControls.Button sohw; protected System.Web.UI.WebControls.Panel Panel2; protected System.Web.UI.WebControls.DataGrid DataGrid1; protected System.Web.UI.WebControls.Panel Panel3; protected System.Web.UI.WebControls.DataGrid DataGrid2; protected System.Web.UI.WebControls.Panel Panel4; protected System.Web.UI.WebControls.Label Label1; protected System.Web.UI.WebControls.Label Label2; protected System.Web.UI.HtmlControls.HtmlTable Table2; // public int id=2; private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if(!Page.IsPostBack) { //限制时间就在这下面,主要是时间的转换我不怎么明白,所以没有做好,希望那位做好了告诉我下!!实在感谢! string ip=Request.ServerVariables["REMOTE_ADDR"]; //得到当前IP this.Label1.Text=ip; string dt=DateTime.Now.Hour.ToString(); //得到当前时间 this.Label2.Text=dt; int id=Convert.ToInt32(Request.QueryString["id"].ToString());//得到当前投票ID string jgdt=db.rengyi("select jgdt from votemaster where id=" id "");////得到当前投票的间隔时间 if(db.vlog("select count(*) from vlog where voteid=" id "")) { string dtime=db.rengyi("select dtime from vlog where addr='" ip "' and voteid=" id ""); //得到当前IP上次给该ID投票的时间 if(db.vlog("select count(*) from vlog where addr='" ip "' and voteid=" id ""))//判断数据库里是否已经有相同的IP啦 { if(Convert.ToInt32(dt)>Convert.ToInt32(jgdt) Convert.ToInt32(dtime))//如果是相同的就判断现在的时间是否大于预设间隔时间加上次投票时间 { this.typfill(); Response.Write("时间允许"); } else { this.Panel1.Visible=false; this.Panel2.Visible=true; this.fill(); this.filltitle(); } } else { this.typfill(); Response.Write("IP可以过"); } this.fill(); } else { this.fill(); this.typfill(); Response.Write("数据库没有东西"); } } } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.updata.Click = new System.EventHandler(this.updata_Click); this.sohw.Click = new System.EventHandler(this.sohw_Click); this.DataGrid1.SortCommand = new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.DataGrid1_SortCommand); this.DataGrid1.ItemDataBound = new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound); this.DataGrid2.PageIndexChanged = new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid2_PageIndexChanged); this.DataGrid2.ItemDataBound = new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid2_ItemDataBound); this.Load = new System.EventHandler(this.Page_Load); } #endregion private void typfill() { //----------------------------------------下面判断显示投票项------------------------------------- int id=Convert.ToInt32(Request.QueryString["id"].ToString());//得到当前投票ID this.filltitle(); int typ=db.typ(id); if(typ==1) { this.title.Text=db.title(1); this.radl.DataSource=db.fill("select * from vote where mid='" id "' order by orde asc"); this.radl.DataTextField="votexiang"; this.radl.DataValueField="voteid"; this.radl.DataBind(); } else { this.title.Text=db.title(2); this.chkl.DataSource=db.fill("select * from vote where mid='" id "' order by orde asc"); this.chkl.DataTextField="votexiang"; this.chkl.DataValueField="voteid"; this.chkl.DataBind(); } //--------------------------------------------------------------------------------------------- } private void fill() { int id=Convert.ToInt32(Request.QueryString["id"].ToString()); this.DataGrid1.DataSource=db.fill("select * from vote where mid=" id ""); this.DataGrid1.DataBind(); } private void filltitle() { this.DataGrid2.DataSource=db.fill("select * from votemaster"); this.DataGrid2.DataBind(); } private void updata_Click(object sender, System.EventArgs e) {//处理投票 string IP=Request.ServerVariables["Remote_Addr"]; string dt=DateTime.Now.Hour.ToString(); int id=Convert.ToInt32(Request.QueryString["id"].ToString()); int typ=db.typ(id); //--------------------------------------------------------------------------------------------- if(typ==1) { for(int i=0;i<this.radl.Items.Count;i ) {//循环到投票项的最大项 if(this.radl.Items[i].Selected) { string voteid=this.radl.Items[i].Value.ToString(); SqlConnection con=db.con(); con.Open(); SqlCommand cmd=new SqlCommand("update vote set votenum=votenum 1 where voteid='" voteid "'",con); SqlCommand cmddt=new SqlCommand("insert into vlog(dtime,addr,voteid) values('" dt "','" IP "','" id "')",con); cmd.ExecuteNonQuery(); cmddt.ExecuteNonQuery(); } } } else { for(int i=0;i<this.chkl.Items.Count;i ) {//循环到投票项的最大项 if(this.chkl.Items[i].Selected) { string voteid=this.chkl.Items[i].Value.ToString(); SqlConnection con=db.con(); con.Open(); SqlCommand cmd=new SqlCommand("update vote set votenum=votenum 1 where voteid='" voteid "'",con); SqlCommand cmddt1=new SqlCommand("insert into vlog(dtime,addr,voteid) values('" dt "','" IP "','" id "')",con); cmd.ExecuteNonQuery(); cmddt1.ExecuteNonQuery(); } } } //--------------------------------------------------------------------------------------------- this.fill(); this.updata.Text="感谢参与"; this.updata.Enabled=false; } private void DataGrid1_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e) { if(ViewState["Order"]==null) { ViewState["Order"]="ASC"; } else { if(ViewState["Order"].ToString()=="ASC") { ViewState["Order"]="DESC"; } else { ViewState["Order"]="ASC"; } } int id=Convert.ToInt32(Request.QueryString["id"].ToString()); SqlConnection con=db.con(); SqlDataAdapter sda=new SqlDataAdapter(); sda.SelectCommand=new SqlCommand("select * from vote where mid=" id "",con); DataSet ds=new DataSet(); sda.Fill(ds,"vote"); ds.Tables["vote"].DefaultView.Sort=e.SortExpression " " ViewState["Order"].ToString(); this.DataGrid1.DataSource=ds.Tables["vote"].DefaultView; this.DataGrid1.DataBind(); } private void sohw_Click(object sender, System.EventArgs e) { this.Panel2.Visible=true; this.Panel1.Visible=false; } private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemType==ListItemType.AlternatingItem||e.Item.ItemType==ListItemType.Item) { e.Item.Attributes.Add("onmouseover","c=this.style.backgroundColor;this.style.backgroundColor='#99ff66'"); e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=c"); } } private void DataGrid2_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemType==ListItemType.AlternatingItem||e.Item.ItemType==ListItemType.Item) { e.Item.Attributes.Add("onmouseover","c=this.style.backgroundColor;this.style.backgroundColor='#99ff66'"); e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=c"); } } private void DataGrid2_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) { this.DataGrid2.CurrentPageIndex=e.NewPageIndex; this.filltitle(); } } }