public void AddVote(M_Vote model) { SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@SubjectId", SqlDbType.Int, 4), new SqlParameter("@VoteTitle", SqlDbType.NVarChar), new SqlParameter("@DisplayType", SqlDbType.Int, 4), new SqlParameter("@IsMore", SqlDbType.Bit, 1), new SqlParameter("@ModelType", SqlDbType.Int, 4), new SqlParameter("@ItemTitle1", SqlDbType.NVarChar), new SqlParameter("@ItemNum1", SqlDbType.Int, 4), new SqlParameter("@ItemTitle2", SqlDbType.NVarChar), new SqlParameter("@ItemNum2", SqlDbType.Int, 4), new SqlParameter("@ItemTitle3", SqlDbType.NVarChar), new SqlParameter("@ItemNum3", SqlDbType.Int, 4), new SqlParameter("@ItemTitle4", SqlDbType.NVarChar), new SqlParameter("@ItemNum4", SqlDbType.Int, 4), new SqlParameter("@ItemTitle5", SqlDbType.NVarChar), new SqlParameter("@ItemNum5", SqlDbType.Int, 4), new SqlParameter("@ItemTitle6", SqlDbType.NVarChar), new SqlParameter("@ItemNum6", SqlDbType.Int, 4) }; commandParameters[0].Value = model.SubjectId; commandParameters[1].Value = model.VoteTitle; commandParameters[2].Value = model.DisplayType; commandParameters[3].Value = model.IsMore; commandParameters[4].Value = model.ModelType; commandParameters[5].Value = model.ItemTitle1; commandParameters[6].Value = model.ItemNum1; commandParameters[7].Value = model.ItemTitle2; commandParameters[8].Value = model.ItemNum2; commandParameters[9].Value = model.ItemTitle3; commandParameters[10].Value = model.ItemNum3; commandParameters[11].Value = model.ItemTitle4; commandParameters[12].Value = model.ItemNum4; commandParameters[13].Value = model.ItemTitle5; commandParameters[14].Value = model.ItemNum5; commandParameters[15].Value = model.ItemTitle6; commandParameters[16].Value = model.ItemNum6; SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringKy, CommandType.StoredProcedure, "Up_Vote_Add", commandParameters); }
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 M_Vote GetVoteIdbyInfo(int voteId) { SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@voteId", SqlDbType.Int) }; commandParameters[0].Value = voteId; DataTable table = SqlHelper.ExecuteTable(SqlHelper.ConnectionStringKy, CommandType.StoredProcedure, "Up_Vote_GetVoteIdByInfo", commandParameters); M_Vote vote = new M_Vote(); vote.VoteTitle = table.Rows[0]["VoteTitle"].ToString(); if (table.Rows[0]["isMore"].ToString() == "True") { vote.IsMore = true; } else { vote.IsMore = false; } vote.ItemTitle1 = table.Rows[0]["ItemTitle1"].ToString(); vote.ItemTitle2 = table.Rows[0]["ItemTitle2"].ToString(); vote.ItemTitle3 = table.Rows[0]["ItemTitle3"].ToString(); vote.ItemTitle4 = table.Rows[0]["ItemTitle4"].ToString(); vote.ItemTitle5 = table.Rows[0]["ItemTitle5"].ToString(); vote.ItemTitle6 = table.Rows[0]["ItemTitle6"].ToString(); vote.ItemNum1 = int.Parse(table.Rows[0]["ItemNum1"].ToString()); vote.ItemNum2 = int.Parse(table.Rows[0]["ItemNum2"].ToString()); vote.ItemNum3 = int.Parse(table.Rows[0]["ItemNum3"].ToString()); vote.ItemNum4 = int.Parse(table.Rows[0]["ItemNum4"].ToString()); vote.ItemNum5 = int.Parse(table.Rows[0]["ItemNum5"].ToString()); vote.ItemNum6 = int.Parse(table.Rows[0]["ItemNum6"].ToString()); vote.SubjectId = int.Parse(table.Rows[0]["SubjectId"].ToString()); return vote; }
public void UpdateVote(M_Vote model) { this.iV.UpdateVote(model); }
public void AddVote(M_Vote model) { this.iV.AddVote(model); B_Log.Add(LogType.Add, "新增投票内容成功"); }