日期:2014-05-17 浏览次数:20526 次
protected void Button1_Click(object sender, EventArgs e) { //投票防作弊 if (Session["UserID"] == null ) { Response.Write("<script language=javascript>alert('您还未登录');</script>"); Response.Redirect("<script>window.location.href='Default.aspx';</script>"); } else { if (Convert.ToBoolean(Session["Role"]))//已经投过票 { Response.Write("<script language=javascript>alert('你已经成功投过票,不能重新投票!');</script>"); return; } else//还没投过票,执行投票操作,票数加1 { int num1 = 0; foreach (Control c in this.Controls) { if (c is CheckBox && ((CheckBox)c).Checked) { num1++; } } if (num1 > 0) { if (num1 < 6) { Response.Write(CC.MessageBox(string.Format("共有{0}人被选中,请继续选足6人", num1.ToString()))); } else if (num1 == 6) { int i = 1; string[] strarr = new string[5]; int j = 0; foreach (Control a in this.Controls) { if (a is CheckBox && ((CheckBox)a).Checked&&(i < 15)) { string P_Str_voteItemID = ((CheckBox)a).ID; string P_Str_cmdtxt = "update tb_VoteItem set voteTotal=voteTotal+1 where voteItemID=" + P_Str_voteItemID; strarr[j] = Convert.ToString(i); CC.ExSql(P_Str_cmdtxt); i++; j++; } else { i = i + 1; } } string ttt = string.Join(",", strarr ); string P_Str_cmdtxt1 = "update tb_User set Role=1 where UserID=" + M_Str_voteID; string P_Str_cmdtxt2 = "update tb_User set Choose= '" + ttt + "' where UserID=" + M_Str_voteID; string P_Str_cmdtxt3 = "update tb_User set VoteDate='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where UserID=" + M_Str_voteID; CC.ExSql(P_Str_cmdtxt1); CC.ExSql(P_Str_cmdtxt2); CC.ExSql(P_Str_cmdtxt3); Response.Write("<script>alert('投票成功,感谢您的支持!');</script>"); } else { Response.Write(CC.MessageBox("您选择的选手已经超过6名")); } } else { Response.Write(CC.MessageBox("请选择参赛选手")); } } } }