Asp.net源码专业站
首页->投票调查->苹果投票系统源码及毕业论文>>vote.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:苹果投票系统源码及毕业论文
当前文件:文件类型 AppleVote/vote.aspx.cs[6K,2009-6-12 11:31:41]打开代码结构图
普通视图
		            
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 16 DB db = new DB(); 17 bool flag = false; 18 private int a = 0; 19 protected void Page_Load(object sender, EventArgs e) 20 { 21 a = Convert.ToInt32(Request.QueryString["id"].ToString()); 22 getTitle(); 23 if (!Page.IsPostBack) 24 { 25 dataBind();//第一次加载时对数据进行绑定 26 } 27 } 28 //获取投票标题 29 public void getTitle() 30 { //获得投票题目 31 32 string strsql = "select voteTitle from voteMaster where id=" +a; 33 this.Label2.Text = db.executeGetReturn(strsql).ToString(); 34 35 } 36 public void dataBind() 37 { //绑定选项 38 39 string strsql = "select voteDetailsID,voteItem from voetDetails where id=" +a; 40 SqlDataReader sdr = db.getsdr(strsql); 41 RadioButtonList1.DataSource = sdr; 42 RadioButtonList1.DataTextField = "voteItem"; 43 this.RadioButtonList1.DataValueField = "voteDetailsID"; 44 RadioButtonList1.DataBind(); 45 sdr.Close(); 46 } 47 48 protected void Button1_Click(object sender, EventArgs e) 49 { 50 51 flag = false; 52 DateTime d = Convert.ToDateTime(DateTime.Now); 53 string x = Request.ServerVariables.Get("Remote_Addr").ToString(); 54 string strsql = "update voetDetails set voteNum=voteNum+1 where voteDetailsID=" + this.RadioButtonList1.SelectedValue;//更新票数 55 if (checkip()) 56 { //系统需要检测IP 57 58 if (isIP()) 59 {//此用户第一次投票 60 //string IP=Request.UserHostAddress.ToString(); 61 string c = "insert into voter(id,ip,voteTime) values(" + a + ",'" + x + "','" + d + "') "; 62 string[] arrg = new string[2]; 63 arrg[0] = strsql; 64 arrg[1] = c; 65 if (db.trantion(arrg)) 66 { 67 this.labMessage.Text = "感谢你的投票"; 68 69 70 } 71 else 72 { 73 74 this.labMessage.Text = "投票不成功!"; 75 76 } 77 } 78 79 80 81 82 else 83 { //此用户已投过票 84 if (checkTime()) 85 { //你的投票过于频繁 86 this.labMessage.Text = "对不起,你的投票太过于频繁,为了公平,请稍后进行投票!"; 87 88 89 90 91 92 } 93 else 94 { //你可以再次进行投票 95 string c = "update voter set voteNum=voteNum+1,voteTime=getdate() where id=" + a + "and ip='" + x + "'"; 96 string[] orrg = new string[2]; 97 orrg[0] = strsql; 98 orrg[1] = c; 99 if (db.trantion(orrg)) 100 { 101 this.labMessage.Text = "你的再次投票成功!"; 102 103 } 104 else 105 { 106 this.labMessage.Text = "你的投票不成功"; 107 108 } 109 110 111 112 113 } 114 115 } 116 117 118 } 119 else 120 { //系统不需要检测IP 121 if (isIP()) 122 {//此用户第一次投票 123 //string IP=Request.UserHostAddress.ToString(); 124 string c = "insert into voter(id,ip,voteTime) values(" + a + ",'" + x + "','" + d + "') "; 125 string[] srrg = new string[2]; 126 srrg[0] = strsql; 127 srrg[1] = c; 128 if (db.trantion(srrg)) 129 { 130 131 this.labMessage.Text = "welocom!"; 132 133 } 134 else 135 { 136 this.labMessage.Text = "eorr!"; 137 138 } 139 } 140 else 141 { 142 string c = "update voter set voteNum=voteNum+1,voteTime=getdate(),where id=" + a+ "and ip='" + x + "'"; 143 string[] zrrg = new string[2]; 144 zrrg[0] = strsql; 145 zrrg[1] = c; 146 if (db.trantion(zrrg)) 147 { 148 149 this.labMessage.Text = "欢迎再来!"; 150 151 } 152 153 else 154 { 155 156 this.labMessage.Text = "hello word!"; 157 158 } 159 160 } 161 } 162 } 163 public bool checkip() 164 { //检测是否需要限定IP 165 166 flag = false; 167 string strsql = "select checkIP from voteConfig where id=" +a; 168 int c = Convert.ToInt16(db.executeGetReturn(strsql)); 169 if (c == 0) 170 { //系统检测IP 171 flag = true; 172 173 } 174 else 175 { 176 flag = false; 177 178 } 179 return flag; 180 } 181 public bool checkTime() 182 { 183 //检测投票时间是否合格 184 flag = false; 185 string IP = Request.ServerVariables.Get("Remote_Addr").ToString(); 186 string strsql = "select datediff(s,voteTime,getdate()) from voter where ip='" + IP + "'and id=" +a; 187 string m = "select checkTime from voteConfig where id=" + a; 188 long c = Convert.ToInt64(db.executeGetReturn(strsql)); 189 int b = Convert.ToInt16(db.executeGetReturn(m)); 190 if (c < b * 60) 191 { //投票过于频繁 192 flag = true; 193 194 195 196 } 197 else 198 { //你可以进行投票了 199 flag = false; 200 201 202 } 203 return flag; 204 } 205 public bool isIP() 206 { 207 //检测是否已投过票 208 flag = false; 209 //string IP = Request.UserHostAddress; 210 string IP = Request.ServerVariables.Get("Remote_Addr").ToString(); 211 string strsql = "select count(*) from voter where ip='" + IP + "'and id=" +a; 212 int c = Convert.ToInt16(db.executeGetReturn(strsql)); 213 if (c == 0) 214 {//此IP第一次对此项目投票 215 216 flag = true; 217 218 } 219 else 220 { //此用户与针对此项目投过票 221 222 flag = false; 223 224 225 } 226 return flag; 227 228 229 230 231 232 233 234 } 235 236 protected void Button2_Click(object sender, EventArgs e) 237 { 238 //int a = Convert.ToInt32(Request.QueryString["id"].ToString()); 239 Response.Redirect("showResult.aspx?id=" +a); 240 } 241} 242 243 244
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:苹果投票系统源码及毕业论文
51Aspx.com 版权所有 CopyRight © 2006-2010. 京ICP备06046876号 本站法律顾问:ITlaw-庄毅雄律师
返回顶部
客户服务:点击这里进行客户咨询 业务合作:点击这里洽谈业务合作 合作热线:010-68880146