温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:苹果投票系统源码及毕业论文
当前文件:
AppleVote/mycontroler/vote.ascx.cs[7K,2009-6-12 11:31:41],打开代码结构图
AppleVote/mycontroler/vote.ascx.cs[7K,2009-6-12 11:31:41],打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.Data.SqlClient; 12
13
//该源码下载自www.51aspx.com(51aspx.com) 14
15
public partial class myctroler_vote : System.Web.UI.UserControl 16
{ 17
18
bool flag = false; 19
DB db = new DB(); 20
private int Id = 0; 21
22
public int _ID 23
{ 24
set { 25
26
Id=value; 27
} 28
get 29
{ 30
31
return this.Id; 32
} 33
34
35
36
} 37
38
39
40
protected void Page_Load(object sender, EventArgs e) 41
{ 42
getid(); 43
getvotetile(); 44
if (!Page.IsPostBack) 45
{ 46
bindata(); 47
} 48
49
} 50
public void getid() 51
{ 52
string strsql = "select id from voteConfig"; 53
if (Id==0) 54
55
Id = Convert.ToInt32(db.executeGetReturn(strsql)); 56
57
} 58
public void getvotetile() 59
{ 60
string strsql = "select voteTitle from voteMaster where id=" + Id; 61
this.labvoteTitle.Text = db.executeGetReturn(strsql); 62
63
64
65
} 66
public void bindata() 67
{ 68
string strsql = "select voteDetailsID,voteItem from voetDetails where id=" + Id; 69
SqlDataReader sdr = db.getsdr(strsql); 70
71
this.RadioButtonList1.DataSource = sdr; 72
this.RadioButtonList1.DataTextField = "voteItem"; 73
this.RadioButtonList1.DataValueField = "voteDetailsID"; 74
this.RadioButtonList1.DataBind(); 75
sdr.Close(); 76
db.clear(); 77
78
79
80
81
82
83
84
} 85
protected void Button1_Click(object sender, EventArgs e) 86
{ 87
88
//string x=Request.UserHostAddress; 89
flag = false; 90
DateTime d = Convert.ToDateTime(DateTime.Now); 91
string x=Request.ServerVariables.Get("Remote_Addr").ToString(); 92
93
94
95
96
97
98
99
100
string strsql = "update voetDetails set voteNum=voteNum+1 where voteDetailsID= "+ this.RadioButtonList1.SelectedValue; 101
if (checkip()) 102
{ //系统需要检测IP 103
104
if (isIP()) 105
{//此用户第一次投票 106
//string IP=Request.UserHostAddress.ToString(); 107
string c = "insert into voter(id,ip,voteTime) values(" + Id + ",'" + x + "','"+d+"') "; 108
string[] arrg = new string[2]; 109
arrg[0] = strsql; 110
arrg[1] = c; 111
if (db.trantion(arrg)) 112
{ 113
this.labMessage.Text = "感谢你的投票"; 114
115
116
} 117
else 118
{ 119
120
this.labMessage.Text = "投票不成功!"; 121
122
} 123
} 124
125
126
127
128
else 129
{ //此用户已投过票 130
if (checkTime()) 131
{ //你的投票过于频繁 132
this.labMessage.Text = "对不起,你的投票太过于频繁,为了公平,请稍后进行投票!"; 133
134
135
136
137
138
} 139
else 140
{ //你可以再次进行投票 141
string c = "update voter set voteNum=voteNum+1,voteTime=getdate() where id=" + Id + "and ip='" + x + "'"; 142
string[] orrg = new string[2]; 143
orrg[0] = strsql; 144
orrg[1] = c; 145
if (db.trantion(orrg)) 146
{ 147
this.labMessage.Text = "你的再次投票成功!"; 148
149
} 150
else 151
{ 152
this.labMessage.Text = "你的投票不成功"; 153
154
} 155
156
157
158
159
} 160
161
} 162
163
164
} 165
else 166
{ //系统不需要检测IP 167
if (isIP()) 168
{//此用户第一次投票 169
//string IP=Request.UserHostAddress.ToString(); 170
string c = "insert into voter(id,ip,voteTime) values(" + Id + ",'" + x + "','"+d+"') "; 171
string[] srrg = new string[2]; 172
srrg[0] = strsql; 173
srrg[1] = c; 174
if (db.trantion(srrg)) 175
{ 176
177
this.labMessage.Text = "welocom!"; 178
179
} 180
else 181
{ 182
this.labMessage.Text="eorr!"; 183
184
} 185
} 186
else 187
{ 188
string c = "update voter set voteNum=voteNum+1,voteTime=getdate(),where id=" + Id + "and ip='" + x + "'"; 189
string[] zrrg = new string[2]; 190
zrrg[0] = strsql; 191
zrrg[1] = c; 192
if(db.trantion(zrrg)) 193
{ 194
195
this.labMessage.Text="欢迎再来!"; 196
197
} 198
199
else 200
{ 201
202
this.labMessage.Text="hello word!"; 203
204
} 205
206
} 207
208
209
210
211
} 212
213
214
215
216
217
218
219
220
221
222
223
} 224
public bool checkip() 225
{ 226
flag = false; 227
string strsql = "select checkIP from voteConfig where id=" + Id; 228
int a = Convert.ToInt16(db.executeGetReturn(strsql)); 229
if (a == 0) 230
{ //系统检测IP 231
flag = true; 232
233
} 234
else 235
{ 236
flag = false; 237
238
} 239
return flag; 240
} 241
public bool checkTime() 242
{ 243
244
flag = false; 245
//string IP = Request.UserHostAddress; 246
string IP = Request.ServerVariables.Get("Remote_Addr").ToString(); 247
string strsql = "select datediff(s,voteTime,getdate()) from voter where ip='" + IP + "'and id=" + Id; 248
string m = "select checkTime from voteConfig where id=" + Id; 249
long c = Convert.ToInt64(db.executeGetReturn(strsql)); 250
int b = Convert.ToInt16(db.executeGetReturn(m)); 251
if (c < b * 60) 252
{ //投票过于频繁 253
flag = true; 254
255
256
257
} 258
else 259
{ //你可以进行投票了 260
flag = false; 261
262
263
} 264
return flag; 265
} 266
public bool isIP() 267
{ 268
flag=false; 269
//string IP = Request.UserHostAddress; 270
string IP = Request.ServerVariables.Get("Remote_Addr").ToString(); 271
string strsql = "select count(*) from voter where ip='" + IP + "'and id=" + Id; 272
int c = Convert.ToInt16(db.executeGetReturn(strsql)); 273
if (c == 0) 274
{//此IP第一次对此项目投票 275
276
flag = true; 277
278
} 279
else 280
{ //此用户与针对此项目投过票 281
282
flag = false; 283
284
285
} 286
return flag; 287
288
289
290
291
292
293
294
} 295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
protected void Button2_Click(object sender, EventArgs e) 312
{ 313
Response.Redirect("showRuslt.aspx?w=" + Id); 314
} 315
} 316






}
}