温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:苹果投票系统源码及毕业论文
当前文件:
AppleVote/vote1.aspx.cs[5K,2009-6-12 11:31:41],打开代码结构图
AppleVote/vote1.aspx.cs[5K,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
public partial class vote1 : System.Web.UI.Page 14
{ 15
DB db = new DB(); 16
private int a = 0; 17
bool flag = false; 18
protected void Page_Load(object sender, EventArgs e) 19
{ 20
a = Convert.ToInt32(Request.QueryString["id"].ToString()); 21
string strtitle = "select voteTitle from voteMaster where id=" + a; 22
this.labTitle.Text = db.executeGetReturn(strtitle); 23
} 24
25
protected void Button1_Click(object sender, EventArgs e) 26
{ 27
flag = false; 28
DateTime d = Convert.ToDateTime(DateTime.Now); 29
string x = Request.ServerVariables.Get("Remote_Addr").ToString(); 30
string strsql = "update voetDetails set voteNum=voteNum+1 where id=" +a;//更新票数 31
if (checkip()) 32
{ //系统需要检测IP 33
if (isIP()) 34
{ //用户第一次投票 35
36
string c = "insert into voter(id,ip,voteTime) values(" + a + ",'" + x + "','" + d + "') "; 37
string[] arrg = new string[2]; 38
arrg[0] = strsql; 39
arrg[1] = c; 40
if (db.trantion(arrg)) 41
{ 42
this.labMessage.Text = "感谢你的投票"; 43
44
45
} 46
else 47
{ 48
49
this.labMessage.Text = "投票不成功!"; 50
51
} 52
53
54
55
56
57
} 58
else 59
{//用户已投过票 60
61
if (checkTime()) 62
{//时间不允许 63
64
this.labMessage.Text = "对不起,你的投票太过于频繁!"; 65
66
67
} 68
else 69
{ //时间允许可以投票 70
string c = "update voter set voteNum=voteNum+1,voteTime=getdate() where id=" + a + "and ip='" + x + "'"; 71
string[] orrg = new string[2]; 72
orrg[0] = strsql; 73
orrg[1] = c; 74
if (db.trantion(orrg)) 75
{ 76
this.labMessage.Text = "你的再次投票成功!"; 77
78
} 79
else 80
{ 81
this.labMessage.Text = "你的投票不成功"; 82
83
} 84
85
86
87
88
89
} 90
91
92
} 93
94
95
96
97
98
99
100
} 101
else 102
{ //系统不需要检测IP 103
if (isIP()) 104
{//此用户第一次投票 105
//string IP=Request.UserHostAddress.ToString(); 106
string c = "insert into voter(id,ip,voteTime) values(" + a + ",'" + x + "','" + d + "') "; 107
string[] srrg = new string[2]; 108
srrg[0] = strsql; 109
srrg[1] = c; 110
if (db.trantion(srrg)) 111
{ 112
113
this.labMessage.Text = "welocom!"; 114
115
} 116
else 117
{ 118
this.labMessage.Text = "eorr!"; 119
120
} 121
} 122
else 123
{ 124
string c = "update voter set voteNum=voteNum+1,voteTime=getdate(),where id=" + a + "and ip='" + x + "'"; 125
string[] zrrg = new string[2]; 126
zrrg[0] = strsql; 127
zrrg[1] = c; 128
if (db.trantion(zrrg)) 129
{ 130
131
this.labMessage.Text = "欢迎再来!"; 132
133
} 134
135
else 136
{ 137
138
this.labMessage.Text = "hello word!"; 139
140
} 141
142
} 143
144
145
146
147
} 148
149
} 150
public bool checkip() 151
{ 152
int a = Convert.ToInt32(Request.QueryString["id"].ToString()); 153
flag = false; 154
string strsql = "select checkIP from voteConfig where id=" + a; 155
int c = Convert.ToInt16(db.executeGetReturn(strsql)); 156
if (c == 0) 157
{ //系统检测IP 158
flag = true; 159
160
} 161
else 162
{ 163
flag = false; 164
165
} 166
return flag; 167
} 168
public bool checkTime() 169
{ 170
int a = Convert.ToInt32(Request.QueryString["id"].ToString()); 171
flag = false; 172
//string IP = Request.UserHostAddress; 173
string IP = Request.ServerVariables.Get("Remote_Addr").ToString(); 174
string strsql = "select datediff(s,voteTime,getdate()) from voter where ip='" + IP + "'and id=" + a; 175
string m = "select checkTime from voteConfig where id=" + a; 176
long c = Convert.ToInt64(db.executeGetReturn(strsql)); 177
int b = Convert.ToInt16(db.executeGetReturn(m)); 178
if (c < b * 60) 179
{ //投票过于频繁 180
flag = true; 181
182
183
184
} 185
else 186
{ //你可以进行投票了 187
flag = false; 188
189
190
} 191
return flag; 192
} 193
public bool isIP() 194
{ 195
int a = Convert.ToInt32(Request.QueryString["id"].ToString()); 196
flag = false; 197
//string IP = Request.UserHostAddress; 198
string IP = Request.ServerVariables.Get("Remote_Addr").ToString(); 199
string strsql = "select count(*) from voter where ip='" + IP + "'and id=" + a; 200
int c = Convert.ToInt16(db.executeGetReturn(strsql)); 201
if (c == 0) 202
{//此IP第一次对此项目投票 203
204
flag = true; 205
206
} 207
else 208
{ //此用户与针对此项目投过票 209
210
flag = false; 211
212
213
} 214
return flag; 215
216
217
218
219
220
221
222
} 223
224
protected void Button2_Click(object sender, EventArgs e) 225
{ 226
Response.Redirect("showResult.aspx?id=" + a); 227
} 228
} 229





DB db 
}
}