计票

  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();
  } 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值