📄 vote1.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class vote1 : System.Web.UI.Page
{
DB db = new DB();
private int a = 0;
bool flag = false;
protected void Page_Load(object sender, EventArgs e)
{
a = Convert.ToInt32(Request.QueryString["id"].ToString());
string strtitle = "select voteTitle from voteMaster where id=" + a;
this.labTitle.Text = db.executeGetReturn(strtitle);
}
protected void Button1_Click(object sender, EventArgs e)
{
flag = false;
DateTime d = Convert.ToDateTime(DateTime.Now);
string x = Request.ServerVariables.Get("Remote_Addr").ToString();
string strsql = "update voetDetails set voteNum=voteNum+1 where id=" +a;//更新票数
if (checkip())
{ //系统需要检测IP
if (isIP())
{ //用户第一次投票
string c = "insert into voter(id,ip,voteTime) values(" + a + ",'" + x + "','" + d + "') ";
string[] arrg = new string[2];
arrg[0] = strsql;
arrg[1] = c;
if (db.trantion(arrg))
{
this.labMessage.Text = "感谢你的投票";
}
else
{
this.labMessage.Text = "投票不成功!";
}
}
else
{//用户已投过票
if (checkTime())
{//时间不允许
this.labMessage.Text = "对不起,你的投票太过于频繁!";
}
else
{ //时间允许可以投票
string c = "update voter set voteNum=voteNum+1,voteTime=getdate() where id=" + a + "and ip='" + x + "'";
string[] orrg = new string[2];
orrg[0] = strsql;
orrg[1] = c;
if (db.trantion(orrg))
{
this.labMessage.Text = "你的再次投票成功!";
}
else
{
this.labMessage.Text = "你的投票不成功";
}
}
}
}
else
{ //系统不需要检测IP
if (isIP())
{//此用户第一次投票
//string IP=Request.UserHostAddress.ToString();
string c = "insert into voter(id,ip,voteTime) values(" + a + ",'" + x + "','" + d + "') ";
string[] srrg = new string[2];
srrg[0] = strsql;
srrg[1] = c;
if (db.trantion(srrg))
{
this.labMessage.Text = "welocom!";
}
else
{
this.labMessage.Text = "eorr!";
}
}
else
{
string c = "update voter set voteNum=voteNum+1,voteTime=getdate(),where id=" + a + "and ip='" + x + "'";
string[] zrrg = new string[2];
zrrg[0] = strsql;
zrrg[1] = c;
if (db.trantion(zrrg))
{
this.labMessage.Text = "欢迎再来!";
}
else
{
this.labMessage.Text = "hello word!";
}
}
}
}
public bool checkip()
{
int a = Convert.ToInt32(Request.QueryString["id"].ToString());
flag = false;
string strsql = "select checkIP from voteConfig where id=" + a;
int c = Convert.ToInt16(db.executeGetReturn(strsql));
if (c == 0)
{ //系统检测IP
flag = true;
}
else
{
flag = false;
}
return flag;
}
public bool checkTime()
{
int a = Convert.ToInt32(Request.QueryString["id"].ToString());
flag = false;
//string IP = Request.UserHostAddress;
string IP = Request.ServerVariables.Get("Remote_Addr").ToString();
string strsql = "select datediff(s,voteTime,getdate()) from voter where ip='" + IP + "'and id=" + a;
string m = "select checkTime from voteConfig where id=" + a;
long c = Convert.ToInt64(db.executeGetReturn(strsql));
int b = Convert.ToInt16(db.executeGetReturn(m));
if (c < b * 60)
{ //投票过于频繁
flag = true;
}
else
{ //你可以进行投票了
flag = false;
}
return flag;
}
public bool isIP()
{
int a = Convert.ToInt32(Request.QueryString["id"].ToString());
flag = false;
//string IP = Request.UserHostAddress;
string IP = Request.ServerVariables.Get("Remote_Addr").ToString();
string strsql = "select count(*) from voter where ip='" + IP + "'and id=" + a;
int c = Convert.ToInt16(db.executeGetReturn(strsql));
if (c == 0)
{//此IP第一次对此项目投票
flag = true;
}
else
{ //此用户与针对此项目投过票
flag = false;
}
return flag;
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("showResult.aspx?id=" + a);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -