⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vote.ascx.cs

📁 很好的毕业设计拿了可以直接用
💻 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));

    }
    public void getvotetile()
    {
        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 + -