public void Check_VoteIp()
{
string strSql="SELECT id, ip, PageUrl, createtime FROM voteip ORDER BY ip, PageUrl, createtime ASC";
string connStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection sqlConn = new SqlConnection(connStr);
SqlCommand sqlCmd = new SqlCommand(strSql,sqlConn);
sqlConn.Open();
SqlDataReader dr = sqlCmd.ExecuteReader();
string prevIp = string.Empty;
string prevPageUrl=string.Empty;
DateTime prevCreateTime = new DateTime();
while(dr.Read())
{
string voteId = dr["id"]+"";
string thisPrevIp = dr["ip"]+"";
string thisPageUrl = dr["PageUrl"]+"";
DateTime thisPreCreateTime = Convert.ToDateTime(dr["createtime"]+"");
int isNullVoteNum = 1;//有效
if(prevIp == thisPrevIp && prevPageUrl==thisPageUrl)
{
int timeSpan =((System.TimeSpan)(thisPreCreateTime - prevCreateTime)).Minutes;
if(timeSpan<10)
{
isNullVoteNum =0; //无效
}
}
this.Update_IsValidate(voteId, isNullVoteNum);
prevIp = thisPrevIp;
prevPageUrl = thisPageUrl;
prevCreateTime = thisPreCreateTime;
}
}
public void Update_IsValidate(string voteId, int isValidate)
{
string strSql="UPDATE voteip SET isValidate="+ isValidate +" WHERE [id]="+voteId;
string connStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection sqlConn = new SqlConnection(connStr);
SqlCommand sqlCmd = new SqlCommand(strSql,sqlConn);
sqlConn.Open();
bool blnResult = sqlCmd.ExecuteNonQuery()>0;
sqlConn.Close();
if(blnResult)
{
Response.Write("更新成功");
}
}
public void AllCount_IsValidate()
{
string strSql="SELECT [id] FROM vote ORDER BY [id]";
string connStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection sqlConn = new SqlConnection(connStr);
SqlCommand sqlCmd = new SqlCommand(strSql,sqlConn);
sqlConn.Open();
SqlDataReader dr = sqlCmd.ExecuteReader();
while(dr.Read())
{
string voteId = dr["id"].ToString();
this.Count_IsValidate(voteId);
}
}
public void Count_IsValidate(string voteId)
{
string strSql="DECLARE @voteNum INT;"+
"SELECT @voteNum = (SELECT COUNT(*) FROM voteip WHERE PageUrl='vote.aspx?id="+ voteId +"' AND isValidate = 0);"+
"UPDATE vote SET isNullVoteNum = @voteNum WHERE [id]="+ voteId;
string connStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection sqlConn = new SqlConnection(connStr);
SqlCommand sqlCmd = new SqlCommand(strSql,sqlConn);
sqlConn.Open();
bool blnResult = sqlCmd.ExecuteNonQuery()>0;
sqlConn.Close();
if(blnResult)
{
Response.Write("无效票总数更新成功");
}
}
public void List_IsNullVote(string voteId)
{
string strSql="SELECT V.[id], V.school, V.team, V.opusType, I.ip, I.createtime FROM "+
"vote V INNER JOIN voteip I ON I.PageUrl = 'vote.aspx?id=' + CAST(V.[id] AS VARCHAR) "+
"WHERE (I.isValidate = 0) AND V.id="+voteId+" ORDER BY I.createtime DESC";
string connStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection sqlConn = new SqlConnection(connStr);
SqlCommand sqlCmd = new SqlCommand(strSql,sqlConn);
DataSet ds = new DataSet();
SqlDataAdapter da= new SqlDataAdapter(sqlCmd);
da.Fill(ds);
this.DataGrid1.DataSource = ds;//查看无效
this.DataGrid1.DataBind();
}
public void AllList_IsNullVote()
{
string strSql="SELECT V.id, V.school, V.team, V.opusType, I.ip, I.createtime FROM "+
"vote V INNER JOIN voteip I ON I.PageUrl = '/vote.aspx?id=' + CAST(V.id AS VARCHAR) "+
"WHERE (I.isValidate = 0) ORDER BY I.createtime DESC";
string connStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection sqlConn = new SqlConnection(connStr);
SqlCommand sqlCmd = new SqlCommand(strSql,sqlConn);
DataSet ds = new DataSet();
SqlDataAdapter da= new SqlDataAdapter(sqlCmd);
da.Fill(ds);
this.DataGrid1.DataSource = ds;//查看所有无效
this.DataGrid1.DataBind();
}