实例介绍
【实例简介】入门级的实例 大家多多交流学习
【实例截图】
【实例截图】
【核心代码】
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(); } } }
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论