protected void Page_Load(object sender, EventArgs e) { if (Request.Form["subjectflagl"] != null) { string subjectId = Request.Form["subjectflagl"].ToString(); if (Request.Cookies[subjectId] != null) { Response.Write("<script>alert('你已经投过票了');window.history.back();</script>"); } else { int ItemNum1 = 0; int ItemNum2 = 0; int ItemNum3 = 0; int ItemNum4 = 0; int ItemNum5 = 0; int ItemNum6 = 0; string[] voteIdArr = Request.Form["hidvoteIdAll"].ToString().Substring(0, Request.Form["hidvoteIdAll"].ToString().Length - 1).Split(','); foreach (string voteId in voteIdArr) { B_Vote bllVote = new B_Vote(); B_User userBll = new B_User(); M_Vote mUpdateVote = new M_Vote(); M_Vote mVote = bllVote.GetVoteIdbyInfo(int.Parse(voteId.ToString())); DataTable dt = bllVote.GetSubject((int)mVote.SubjectId); if (dt != null && dt.Rows.Count != 0) { if ((DateTime)dt.Rows[0]["EndDate"] < DateTime.Now.Date) { Response.Write("<script>alert('此投票主题已过期');window.history.back();</script>"); return; } if (dt.Rows[0]["RequireLogin"].ToString() == "True" && !userBll.IsLogin()) { Response.Write("<script>alert('请登录后再投票');window.history.back();</script>"); return; } } HttpCookie ipCookie = new HttpCookie(subjectId); ipCookie.Value = Request.UserHostAddress; ipCookie.Expires = DateTime.Now.AddHours(2); Response.Cookies.Add(ipCookie); ItemNum1 = mVote.ItemNum1; ItemNum2 = mVote.ItemNum2; ItemNum3 = mVote.ItemNum3; ItemNum4 = mVote.ItemNum4; ItemNum5 = mVote.ItemNum5; ItemNum6 = mVote.ItemNum6; string[] voteItem = null; if (Request.Form[voteId + "vote"] != null) { voteItem = Request.Form[voteId + "vote"].ToString().Split(','); foreach (string ItemValue in voteItem) { if (ItemValue == "ItemNum1") ItemNum1 = ItemNum1 + 1; if (ItemValue == "ItemNum2") ItemNum2 = ItemNum2 + 1; if (ItemValue == "ItemNum3") ItemNum3 = ItemNum3 + 1; if (ItemValue == "ItemNum4") ItemNum4 = ItemNum4 + 1; if (ItemValue == "ItemNum5") ItemNum5 = ItemNum5 + 1; if (ItemValue == "ItemNum6") ItemNum6 = ItemNum6 + 1; mUpdateVote.ItemNum1 = ItemNum1; mUpdateVote.ItemNum2 = ItemNum2; mUpdateVote.ItemNum3 = ItemNum3; mUpdateVote.ItemNum4 = ItemNum4; mUpdateVote.ItemNum5 = ItemNum5; mUpdateVote.ItemNum6 = ItemNum6; mUpdateVote.VoteId = int.Parse(voteId.ToString()); mUpdateVote.VoteTitle = mVote.VoteTitle; mUpdateVote.IsMore = mVote.IsMore; mUpdateVote.ItemTitle1 = mVote.ItemTitle1; mUpdateVote.ItemTitle2 = mVote.ItemTitle2; mUpdateVote.ItemTitle3 = mVote.ItemTitle3; mUpdateVote.ItemTitle4 = mVote.ItemTitle4; mUpdateVote.ItemTitle5 = mVote.ItemTitle5; mUpdateVote.ItemTitle6 = mVote.ItemTitle6; bllVote.UpdateVote(mUpdateVote); } } } Response.Write("<script>alert('投票成功');window.history.back();</script>"); } } }
public string GetVote(string paramStr) { string paramValue = string.Empty; string str2 = string.Empty; string str3 = string.Empty; string str4 = string.Empty; this.GetParamValue(paramStr, "arrange", ref paramValue); this.GetParamValue(paramStr, "votesubjectid", ref str2); this.GetParamValue(paramStr, "topicstyle", ref str3); this.GetParamValue(paramStr, "optionstyle", ref str4); DataTable subject = new B_Vote().GetSubject(int.Parse(str2)); int count = subject.Rows.Count; int num2 = 0; string str5 = ""; string str6 = ""; string str7 = ""; if (paramValue == "horizontal") { str7 = "style=\"float:left;\""; } if (subject.Rows.Count <= 0) { return str6; } foreach (DataRow row in subject.Rows) { string str8; if (num2 == 0) { if (row["isMore"].ToString() == "False") { str8 = "radio"; } else { str8 = "CheckBox"; } str6 = str6 + "<br>\r\n<form action=\"" + Param.ApplicationRootPath + "/common/SetVote.aspx\" method=\"post\" ><div " + str7 + "><table>\r\n"; str6 = string.Concat(new object[] { str6, "<tr><td class=\"", str3, "\">", row["VoteTitle"], "</td></tr>\r\n" }); if (row["ItemTitle1"].ToString() != "") { str6 = string.Concat(new object[] { str6, "<tr class=\"", str4, "\"><td><input type=", str8, " name=\"", row["VoteId"], "vote\" value=\"ItemNum1\">", row["ItemTitle1"], "</td></tr>\r\n" }); } if (row["ItemTitle2"].ToString() != "") { str6 = string.Concat(new object[] { str6, "<tr class=\"", str4, "\"><td><input type=", str8, " name=\"", row["VoteId"], "vote\" value=\"ItemNum2\">", row["ItemTitle2"], "</td></tr>\r\n" }); } if (row["ItemTitle3"].ToString() != "") { str6 = string.Concat(new object[] { str6, "<tr class=\"", str4, "\"><td><input type=", str8, " name=\"", row["VoteId"], "vote\" value=\"ItemNum3\">", row["ItemTitle3"], "</td></tr>\r\n" }); } if (row["ItemTitle4"].ToString() != "") { str6 = string.Concat(new object[] { str6, "<tr class=\"", str4, "\"><td><input type=", str8, " name=\"", row["VoteId"], "vote\" value=\"ItemNum4\">", row["ItemTitle4"], "</td></tr>\r\n" }); } if (row["ItemTitle5"].ToString() != "") { str6 = string.Concat(new object[] { str6, "<tr class=\"", str4, "\"><td><input type=", str8, " name=\"", row["VoteId"], "vote\" value=\"ItemNum5\">", row["ItemTitle5"], "</td></tr>\r\n" }); } if (row["ItemTitle6"].ToString() != "") { str6 = string.Concat(new object[] { str6, "<tr class=\"", str4, "\"><td><input type=", str8, " name=\"", row["VoteId"], "vote\" value=\"ItemNum6\">", row["ItemTitle6"], "</td></tr>\r\n" }); } str6 = str6 + "</table></div>\r\n"; str5 = str5 + row["VoteId"].ToString() + ","; } else { if (row["isMore"].ToString() == "False") { str8 = "radio"; } else { str8 = "CheckBox"; } str6 = str6 + "<div " + str7 + "><table>\r\n"; str6 = string.Concat(new object[] { str6, "<tr><td class=\"", str3, "\">", row["VoteTitle"], "</td></tr>\r\n" }); if (row["ItemTitle1"].ToString() != "") { str6 = string.Concat(new object[] { str6, "<tr class=\"", str4, "\"><td><input type=", str8, " name=\"", row["VoteId"], "vote\" value=\"ItemNum1\">", row["ItemTitle1"], "</td></tr>\r\n" }); } if (row["ItemTitle2"].ToString() != "") { str6 = string.Concat(new object[] { str6, "<tr class=\"", str4, "\"><td><input type=", str8, " name=\"", row["VoteId"], "vote\" value=\"ItemNum2\">", row["ItemTitle2"], "</td></tr>\r\n" }); } if (row["ItemTitle3"].ToString() != "") { str6 = string.Concat(new object[] { str6, "<tr class=\"", str4, "\"><td><input type=", str8, " name=\"", row["VoteId"], "vote\" value=\"ItemNum3\">", row["ItemTitle3"], "</td></tr>\r\n" }); } if (row["ItemTitle4"].ToString() != "") { str6 = string.Concat(new object[] { str6, "<tr class=\"", str4, "\"><td><input type=", str8, " name=\"", row["VoteId"], "vote\" value=\"ItemNum4\">", row["ItemTitle4"], "</td></tr>\r\n" }); } if (row["ItemTitle5"].ToString() != "") { str6 = string.Concat(new object[] { str6, "<tr class=\"", str4, "\"><td><input type=", str8, " name=\"", row["VoteId"], "vote\" value=\"ItemNum5\">", row["ItemTitle5"], "</td></tr>\r\n" }); } if (row["ItemTitle6"].ToString() != "") { str6 = string.Concat(new object[] { str6, "<tr class=\"", str4, "\"><td><input type=", str8, " name=\"", row["VoteId"], "vote\" value=\"ItemNum6\">", row["ItemTitle6"], "</td></tr>\r\n" }); } str6 = str6 + "</table></div>\r\n"; str5 = str5 + row["VoteId"].ToString() + ","; } num2++; } return (str6 + "<div style=\"clear:both;\"><table><tr><td><input type=\"hidden\" value=\"subject" + str2 + "\" name=\"subjectflagl\"><input type=\"hidden\" value=\"" + str5 + "\" name=\"hidvoteIdAll\"> <input type=\"submit\" value=\"投票\"> <input type=\"button\" value=\"查看\" onclick=\"javascript:window.location.href='" + Param.ApplicationRootPath + "/common/ViewVote.aspx?vid=" + str2 + "' \"></td></tr></table></div></form>"); }
private void VoteBind() { B_Vote bllVote = new B_Vote(); DataTable dt = bllVote.GetAll(); DataView dv = dt.DefaultView; dv.RowFilter = "EndDate>'" + DateTime.Now.Date + "'"; ddlVote.DataSource = dv; ddlVote.DataTextField = "Subject"; ddlVote.DataValueField = "VoteSubjectId"; DataBind(); }