62,047
社区成员
发帖
与我相关
我的任务
分享
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("请选择参赛选手"));
}
}
}
}
<script language="javascript" type="text/javascript">
function check()
{
var x=0;
var chkArray = window.document.getElementsByTagName("input");
for(var i = 0; i< chkArray.length; i++)
{
if(chkArray[i].type != "checkbox")
{
continue;
}
if(chkArray[i].checked)
{
x++;
}
}
if(x<6 || x>6)
{
alert('必须是6个!');return false;
}
}
</script>
protected void Button1_Click(object sender, EventArgs e)
{
string sql = "";
if (CheckBox1.Checked)
{
sql = sql + " update tb_VoteItem set voteTotal=voteTotal+1 where voteItemID=" + CheckBox1.ID;
}
if (CheckBox2.Checked)
{
sql = sql + " update tb_VoteItem set voteTotal=voteTotal+1 where voteItemID=" + CheckBox2.ID;
}
if (CheckBox3.Checked)
{
sql = sql + " update tb_VoteItem set voteTotal=voteTotal+1 where voteItemID=" + CheckBox3.ID;
}
if (CheckBox4.Checked)
{
sql = sql + " update tb_VoteItem set voteTotal=voteTotal+1 where voteItemID=" + CheckBox4.ID;
}
if (CheckBox5.Checked)
{
sql = sql + " update tb_VoteItem set voteTotal=voteTotal+1 where voteItemID=" + CheckBox5.ID;
}
if (CheckBox6.Checked)
{
sql = sql + " update tb_VoteItem set voteTotal=voteTotal+1 where voteItemID=" + CheckBox6.ID;
}
if (CheckBox7.Checked)
{
sql = sql + " update tb_VoteItem set voteTotal=voteTotal+1 where voteItemID=" + CheckBox7.ID;
}
if (CheckBox8.Checked)
{
sql = sql + " update tb_VoteItem set voteTotal=voteTotal+1 where voteItemID=" + CheckBox8.ID;
}
if (CheckBox9.Checked)
{
sql = sql + " update tb_VoteItem set voteTotal=voteTotal+1 where voteItemID=" + CheckBox9.ID;
}
if (CheckBox10.Checked)
{
sql = sql + " update tb_VoteItem set voteTotal=voteTotal+1 where voteItemID=" + CheckBox10.ID;
}
if (CheckBox11.Checked)
{
sql = sql + " update tb_VoteItem set voteTotal=voteTotal+1 where voteItemID=" + CheckBox11.ID;
}
if (CheckBox12.Checked)
{
sql = sql + " update tb_VoteItem set voteTotal=voteTotal+1 where voteItemID=" + CheckBox12.ID;
}
if (CheckBox13.Checked)
{
sql = sql + " update tb_VoteItem set voteTotal=voteTotal+1 where voteItemID=" + CheckBox13.ID;
}
if (CheckBox14.Checked)
{
sql = sql + " update tb_VoteItem set voteTotal=voteTotal+1 where voteItemID=" + CheckBox14.ID;
}
CC.ExSql(sql);
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>");
}