?? vote.ascx.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;
//該源碼下載自www.cnzz.cn
public partial class myctroler_vote : System.Web.UI.UserControl
{
bool flag = false;
DB db = new DB();
private int Id = 0;
public int _ID
{
set {
Id=value;
}
get
{
return this.Id;
}
}
protected void Page_Load(object sender, EventArgs e)
{
getid();
getvotetile();
if (!Page.IsPostBack)
{
bindata();
}
}
public void getid()
{
string strsql = "select id from voteConfig";
if (Id==0)
Id = Convert.ToInt32(db.executeGetReturn(strsql));
}
{
string strsql = "select voteTitle from voteMaster where id=" + Id;
this.labvoteTitle.Text = db.executeGetReturn(strsql);
}
public void bindata()
{
string strsql = "select voteDetailsID,voteItem from voetDetails where id=" + Id;
SqlDataReader sdr = db.getsdr(strsql);
this.RadioButtonList1.DataSource = sdr;
this.RadioButtonList1.DataTextField = "voteItem";
this.RadioButtonList1.DataValueField = "voteDetailsID";
this.RadioButtonList1.DataBind();
sdr.Close();
db.clear();
}
protected void Button1_Click(object sender, EventArgs e)
{
//string x=Request.UserHostAddress;
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 voteDetailsID= "+ this.RadioButtonList1.SelectedValue;
if (checkip())
{ //系統需要檢測IP
if (isIP())
{//此用戶第一次投票
//string IP=Request.UserHostAddress.ToString();
string c = "insert into voter(id,ip,voteTime) values(" + Id + ",'" + 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=" + Id + "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(" + Id + ",'" + 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=" + Id + "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()
{
flag = false;
string strsql = "select checkIP from voteConfig where id=" + Id;
int a = Convert.ToInt16(db.executeGetReturn(strsql));
if (a == 0)
{ //系統檢測IP
flag = true;
}
else
{
flag = false;
}
return flag;
}
public bool checkTime()
{
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=" + Id;
string m = "select checkTime from voteConfig where id=" + Id;
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()
{
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=" + Id;
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("showRuslt.aspx?w=" + Id);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -