关于VS2013 窗体停用程序的问题:C#登陆界面设置

2025-03-01 09:05:16
推荐回答(4个)
回答1:

        public bool CheckNull()
        {
            //SetErrorProvideEmpty();
            ep.Clear();         
            if (txtname.Text == "")
            {
                this.errorProvider1.SetError(txtname,"用户名不能为空!");
                this.txtname.Focus();
                return false;
            }
            if (txtpassword.Text == "")
            {
                this.errorProvider1.SetError(txtpassword, "密码不能为空!");
                this.txtpassword.Focus();
                return false;
            }
            if (txtname.Text.Length>10)
            {
                this.errorProvider1.SetError(txtname, "用户名长度超出范围!");
                this.txtname.Focus();
                return false;
            }
            if (txtpassword.Text.Length > 10)
            {
                this.errorProvider1.SetError(txtpassword, "密码长度超出范围!");
                this.txtpassword.Focus();
                return false;
            }
            return true;
        }
        public void Verification()
        {
           
            try
            {
                SqlConnection conn = new SqlConnection(Connection.GetConnection);
                conn.Open();
                string name = this.txtname.Text.Trim();
                string password = this.txtpassword.Text.Trim().ToString();
                string sql = "select count(*) from teacher where tno=" + name + " and password=" + password + "";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Dispose();
                int count = (int)cmd.ExecuteScalar();  
                if (count < 1)
                {
                    MessageBox.Show("用户名不存在或密码错误!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }
                else 
                {
                    search sForm = new search();
                    sForm.label1.Text = "欢迎用户:" + txtname.Text + "访问";
                    sForm.Show();
                    this.Hide();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

        }
        private void SetErrorProvideEmpty()
        {
            errorProvider1.SetError(txtname,"");
            errorProvider1.SetError(txtpassword,"");
        }
        int i = 0;
        private void btnlogin_Click(object sender, EventArgs e)
        {
           
            if (CheckNull())
            {
                
               ++i;
                if (i > 3)
                {
                    DialogResult dia=MessageBox.Show("您已错误输入超过三次,系统将强制退出!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    if (dia == DialogResult.OK)
                    {
                        Application.Exit();
                    }
                    
                 }
                Verification();
            }
        }

回答2:

没看到你读取数据库的代码。你是不需要通过数据库来进行登录?
要是直接判断两个textbox的值,你就打断点,调试看下,那两个文本框的值

回答3:

自己断点查看一下 两个textbox的值。

回答4:

帐号为A***** 密码不填 在试试

不行就反过来试试