Exemplo n.º 1
0
 private void NewP_cancel()
 {
     CaseManage caseManage = new CaseManage();
     this.Hide();
     caseManage.ShowDialog();
     this.Close();
 }
Exemplo n.º 2
0
        //登录验证
        private void check()
        {
            int errFlag = 1;
            string inputLogName = logName.Text;
            string inputPwd = logPassword.Text;

            if (inputLogName.Length == 0)
            {
                MessageBox.Show("用户名不能为空!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (!(Regex.Match(inputLogName, "^[A-Za-z0-9]+$").Success))
            {
                MessageBox.Show("用户名应为数字或大小写字母!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (inputPwd.Length == 0)
            {
                MessageBox.Show("密码不能为空!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (!(Regex.Match(inputPwd, "^[A-Za-z0-9]{5,17}$").Success))
            {
                MessageBox.Show("密码应为6-18位数字或大小写字母!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string command = "SELECT userId, d_userName, d_password FROM [user]";
            OleDbCommand OleDbCmd = new OleDbCommand(command, PublicParams.OleDbConn);
            try
            {
                OleDbDataReader reader = OleDbCmd.ExecuteReader();
                while (reader.Read())
                {
                    string userId = reader["userId"].ToString();
                    string userName = reader["d_userName"].ToString();
                    string password = reader["d_password"].ToString();
                    if (userName == inputLogName && password == inputPwd)
                    {
                        errFlag = 0;
                        PublicParams.currentUserId = userId;
                        break;
                    }
                    else
                    {
                        errFlag = 1;
                    }
                }
                reader.Close();
            }
            catch (Exception error)
            {
                MessageBox.Show(error.ToString());
            }

            if (errFlag == 1)
            {
                MessageBox.Show("用户名或密码错误", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            PublicParams.OleDbConn.Close();
            if (errFlag == 0)
            {
                CaseManage caseManage = new CaseManage();
                this.Hide();
                caseManage.ShowDialog();
                if (PublicParams.LogoutorExit == 0)
                {
                    this.Close();
                }
                if (PublicParams.LogoutorExit == 1)
                {
                    this.Show();
                }
            }
        }