您目前尚未登陆,请选择【登陆】或【注册
首页->投票调查->大学生调查投票系统源码>>Vote.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:大学生调查投票系统源码
当前文件:文件类型 StudentVote/Vote.aspx.cs打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Collections; 5using System.Web; 6using System.Web.Security; 7using System.Web.UI; 8using System.Web.UI.WebControls; 9using System.Web.UI.WebControls.WebParts; 10using System.Web.UI.HtmlControls; 11using System.Data.SqlClient; 12 13public partial class Vote : System.Web.UI.Page 14{ 15 public string strContent, strID = null; 16 protected void Page_Load(object sender, EventArgs e) 17 { 18 strID = Request["ID"].ToString(); 19 20 HttpCookie readcookie = Request.Cookies["Vote"]; 21 22 if (readcookie == null) 23 { 24 this.labState.Text = "你还未在该投票系统中投票!"; 25 } 26 else 27 { 28 this.labState.Text = "你已经在该投票系统投过票了!"; 29 } 30 SqlData da = new SqlData(); 31 SqlDataReader dr = da.ExceRead("select * from tb_Vote where ID='" + strID + "'") ; 32 dr.Read(); 33 this.labContent.Text = dr["Title"].ToString(); 34 strContent = dr["Content"].ToString(); 35 string[] str = strContent.Split('|'); 36 int intORDER = 0;//排序 37 if (!Page.IsPostBack)//有提交行为,不执行以下数据的重载 38 { 39 foreach (string strContentIN in str) 40 { 41 string strContentOK = strContentIN.Split(',')[1]; 42 this.RadioButtonList1.Items.Add(new ListItem(strContentOK, intORDER.ToString())); 43 intORDER++;//累加选项的值 44 } 45 } 46 } 47 48 49 protected void btnVote_Click(object sender, EventArgs e) 50 { 51 if (this.RadioButtonList1.SelectedIndex != -1)//如果有选定项目 52 { 53 //投票防作弊 54 HttpCookie makecookie = new HttpCookie("Vote");//制造cookie 55 HttpCookie readcookie = Request.Cookies["Vote"];//读出cookie 56 57 if (readcookie == null)//从未投过票 58 { 59 makecookie.Values.Add("VoteItem", "<" + strID + ">"); 60 } 61 else 62 { 63 //Response.Write(readcookie.Values["VoteItem"]); 64 //Response.End(); 65 string strAllItem = readcookie.Values["VoteItem"].ToString();//读取已投票的项 66 if (strAllItem.IndexOf("<" + strID + ">") == -1)//未投过票 67 { 68 makecookie.Values.Add("VoteItem", readcookie.Values["VoteItem"] + "<" + strID + ">"); 69 } 70 else//如果已投过票 71 { 72 Response.Write("<script language=javascript>alert('该主题你已经成功投过票,不能重新投票!');</script>"); 73 return; 74 //Response.Write("<script language=javascript>alert('该主题你已经成功投过票,不能重新投票!');location='Index.aspx'</script>"); 75 } 76 } 77 Response.AppendCookie(makecookie);//写入Cookie 78 79 string strSelect = strContent.Split('|')[Convert.ToInt32(this.RadioButtonList1.SelectedValue.ToString())];//当前选中的项目,如“ 2,不错” 80 int intVote = Convert.ToInt32(strSelect.Split(',')[0]);//当前投票数+1 81 int intVoteOK = intVote + 1; 82 string strSelectOK = strSelect.Replace(intVote.ToString(), intVoteOK.ToString());//更新原投票数,所以期望更新的定位精确,可附带+"," 83 string strUPDATE = strContent.Replace(strSelect, strSelectOK);//得到最终 84 SqlData da = new SqlData(); 85 bool update = da.ExceSQL("update tb_Vote set Content='" + strUPDATE + "' where ID='" + strID + "'"); 86 if (update) 87 { 88 Response.Write("<script language=javascript>alert('投票成功!');</script>"); 89 } 90 else 91 { 92 Response.Redirect("Index.aspx"); 93 } 94 } 95 else//如果没有选中项目 96 { 97 Response.Write("<script language=javascript>alert('请选择投票项!');location='javascript:history.go(-1)'</script>"); 98 } 99 } 100 protected void btnEdit_Click(object sender, EventArgs e) 101 { 102 Response.Redirect("Login.aspx?ID="+Request["ID"]+""); 103 } 104 protected void btnView_Click(object sender, EventArgs e) 105 { 106 Response.Redirect("Result.aspx?ID=" + Request["ID"] + ""); 107 } 108} 109
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:大学生调查投票系统源码
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号