示例#1
0
 //登录按扭点击事件
 private void pboxLogin_Click(object sender, EventArgs e)
 {
     if (ValidateInput())//如果能够正常登录
     {
         string sql = "select count(*) from tb_User where ID=" + int.Parse(txtID.Text.Trim()) + "and Pwd='" + txtPwd.Text.Trim() + "'";
         int    num = dataOper.ExecSQL(sql);//返回第一行第一列的查询结果
         if (num == 1)
         {
             PublicClass.loginID = int.Parse(txtID.Text.Trim());//设置登录的用户号码
             //如果"记住密码"复选框选中
             if (cboxRemember.Checked)
             {
                 dataOper.ExecSQLResult("update tb_User set Remember=1 where ID=" + int.Parse(txtID.Text.Trim()));
                 if (cboxAutoLogin.Checked)//立即登录复选框选中
                 {
                     dataOper.ExecSQLResult("update tb_User set AutoLogin=1 where ID=" + int.Parse(txtID.Text.Trim()));
                 }
             }
             else
             {
                 dataOper.ExecSQLResult("update tb_User set Remember=0 where ID=" + int.Parse(txtID.Text.Trim()));
                 dataOper.ExecSQLResult("update tb_User set AutoLogin=0 where ID=" + int.Parse(txtID.Text.Trim()));
             }
             dataOper.ExecSQLResult("update tb_User set Flag=1 where ID=" + int.Parse(txtID.Text.Trim()));
             Frm_Main frmMain = new Frm_Main();
             frmMain.Show();
             this.Visible = false;
         }
         else
         {
             MessageBox.Show("输入的用户名或密码有误!", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
示例#2
0
文件: Frm_Login.cs 项目: tenli/CSharp
 private void PboxLogin_Click(object sender, EventArgs e)
 {
     if (Validate())
     {
         //定义查询语句
         string sql = "select count(*) from tb_User where ID=" + int.Parse(txtID.Text.Trim()) + "and Pwd=" + txtPwd.Text.Trim() + "";
         int    num = dataOper.ExecSql(sql);
         if (num == 1)
         {
             PublicClass.loginID = int.Parse(txtID.Text.Trim()); //设置登录的用户号码
             if (cboxRemember.Checked)                           //记住密码选中
             {
                 dataOper.ExecSQLResult("update tb_User set Remember=1 where ID=" + int.Parse(txtID.Text.Trim()));
             }
             if (cboxAutoLogin.Checked)//自动登录选中
             {
                 dataOper.ExecSQLResult("update tb_User set AutoLogin=1 where id=" + int.Parse(txtID.Text.Trim()));
             }
             else
             {
                 dataOper.ExecSQLResult("update tb_User set Remember=0 where ID=" + int.Parse(txtID.Text.Trim()));
                 dataOper.ExecSQLResult("update tb_User set AutoLogin=0 where id=" + int.Parse(txtID.Text.Trim()));
                 dataOper.ExecSQLResult("update tb_User set Flag=1 where id=" + int.Parse(txtID.Text.Trim()));
                 Frm_Main frmMain = new Frm_Main(); //创建主窗体对象
                 frmMain.Show();                    //启动
                 this.Visible = false;              //隐藏当前登录窗体
             }
         }
         else
         {
             MessageBox.Show("输入的用户名或密码有误!", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
示例#3
0
        private void pboxLogin_Click(object sender, EventArgs e)
        {
            if (ValidateInput()) //调用自定义方法验证用户输入
            {
                string sql = "select count(*) from tb_User where ID=" + int.Parse(txtID.Text.Trim())
                    + "and Pwd ='" + txtPwd.Text.Trim() + "'"; //定义查询SQL语句
                int num = dataOper.ExecSQL(sql); //执行SQL语句
                if(num ==1)         //验证通过
                {
                    PublicClass.loginID = int.Parse(txtID.Text.Trim());//设置登录的用户号码
                    if(cboxRemember.Checked)
                    {
                        dataOper.ExecSQLResult("update tb_User set Remember = 1 where ID="
                            + int.Parse(txtID.Text.Trim()));             //记住密码
                        if(cboxAutoLogin.Checked)
                        {
                            dataOper.ExecSQLResult("update tb_User set AutoLogin=1 where ID="
                                + int.Parse(txtID.Text.Trim())); //自动登录
                        }
                    }
                    else
                    {
                        dataOper.ExecSQLResult("update tb_User set Remember=0 where ID=" +
                            int.Parse(txtID.Text.Trim()));
                        dataOper.ExecSQLResult("update tb_User set AutoLogin=0 where ID=" +
                            int.Parse(txtID.Text.Trim()));
                    }
                    dataOper.ExecSQLResult("Update tb_User set Flag=1 where ID=" +
                        int.Parse(txtID.Text.Trim()));//设置在线状态
                    Frm_Main frmMain = new Frm_Main();  //创建主窗体对象
                    frmMain.Show();//显示主窗体
                    this.Visible = false;//隐藏登录主窗体

                }
                else
                {
                    MessageBox.Show("输入的用户名或密码有误", "登录提示", MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }



            }

        }
示例#4
0
        //登录按钮
        private void pboxLogin_Click(object sender, EventArgs e)
        {
            if (clientSocket == null || !clientSocket.Connected)
            {
                try
                {
                    clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    //参考网址: https://msdn.microsoft.com/zh-cn/library/6aeby4wt.aspx
                    // Socket.BeginConnect 方法 (String, Int32, AsyncCallback, Object)
                    //开始一个对远程主机连接的异步请求

                    /* string host,     远程主机名
                     * int port,        远程主机的端口
                     * AsyncCallback requestCallback,   一个 AsyncCallback 委托,它引用连接操作完成时要调用的方法,也是一个异步的操作
                     * object state     一个用户定义对象,其中包含连接操作的相关信息。 当操作完成时,此对象会被传递给 requestCallback 委托
                     */
                    //如果txtIP里面有值,就选择填入的IP作为服务器IP,不填的话就默认是本机的

                    clientSocket.BeginConnect("2478ij6364.wicp.vip", 52827, (args) =>
                    {
                        if (args.IsCompleted)   //判断该异步操作是否执行完毕
                        {
                            if (clientSocket != null && clientSocket.Connected)
                            {
                                thDataFromServer = new Thread(DataFromServer);
                                thDataFromServer.IsBackground = true;
                                thDataFromServer.Start();
                            }
                            else
                            {
                                MessageBox.Show("服务器已关闭");
                            }
                        }
                    }, null);
                }
                catch (SocketException ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                if (ValidateInput()) //调用自定义方法验证用户输入
                {
                    //定义查询SQL语句
                    string sql = "select count(*) from tb_User where ID=" + int.Parse(txtID.Text.Trim()) + " and Pwd = '" + txtPwd.Text.Trim() + "'";
                    int    num = dataOper.ExecSQL(sql);
                    if (num == 1)                                           //验证通过
                    {
                        PublicClass.loginID = int.Parse(txtID.Text.Trim()); //设置登录的用户号码
                        if (cboxRemember.Checked)
                        {
                            //记住密码
                            dataOper.ExecSQLResult("update tb_User set Remember=1 where ID=" + int.Parse(txtID.Text.Trim()));
                            if (cboxAutoLogin.Checked)
                            {
                                //自动登录
                                dataOper.ExecSQLResult("update tb_User set AutoLogin=1 where ID=" + int.Parse(txtID.Text.Trim()));
                            }
                        }
                        else
                        {
                            dataOper.ExecSQLResult("update tb_User set Remember=0 where ID=" + int.Parse(txtID.Text.Trim()));
                            dataOper.ExecSQLResult("update tb_User set AutoLogin=0 where ID=" + int.Parse(txtID.Text.Trim()));
                        }
                        dataOper.ExecSQLResult("update tb_User set Flag=1 where ID=" + int.Parse(txtID.Text.Trim())); //设置在线状态
                        Frm_Main frmMain = new Frm_Main();                                                            //创建主窗体对象
                        frmMain.Show();                                                                               //显示主窗体
                        this.Visible = false;                                                                         //隐藏登录主窗体

                        thDataFromServer.Abort();
                        clientSocket.Close();
                        clientSocket = null;
                    }
                    else
                    {
                        MessageBox.Show("输入的用户名或密码有误!", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }