private void btnDoi_Click(object sender, EventArgs e)
        {
            string matkhaucu = "", matkhaumoi = "";
            string strMKC   = txtMKCu.Text.Trim();
            string strMKM   = txtMKmoi.Text.Trim();
            string strNLMKM = txtNhaplaiMKMoi.Text.Trim();
            string strErr   = string.Empty;

            if (strMKC == string.Empty)
            {
                strErr = "Chưa nhập mật khẩu cũ";
            }
            if (strMKM == string.Empty)
            {
                strErr += "\n Chưa nhập mật khẩu mới";
            }
            if (strNLMKM != strMKM)
            {
                strErr += "\n Nhập lại mật khẩu mới không đúng";
            }
            if (strErr != string.Empty)
            {
                MessageBox.Show(" " + strErr, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            foreach (DataRow row in NhanVienCtr.DangNhap(manv).Rows)
            {
                matkhaucu = row["MatKhau"].ToString();
            }
            if (txtMKCu.Text == matkhaucu)
            {
                matkhaumoi = txtMKmoi.Text;
                if (NhanVienCtr.ChangePassword(manv, matkhaumoi))
                {
                    MessageBox.Show("Thay đổi thành công.", "Imformation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtMKCu.ResetText();
                    txtMKmoi.ResetText();
                    txtNhaplaiMKMoi.ResetText();
                }
                else
                {
                    MessageBox.Show("Thay đổi mật khẩu thất bại.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtMKCu.ResetText();
                    txtMKmoi.ResetText();
                }
            }
            else
            {
                MessageBox.Show("Mật khẩu cũ không đúng.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtMKCu.ResetText();
                txtMKmoi.ResetText();
            }
        }
Ejemplo n.º 2
0
        private void btnDangnhap_Click(object sender, EventArgs e)
        {
            string strMaNV = txtMaNV.Text.Trim();
            string strMK   = txtMatkhau.Text.Trim();
            string strErr  = string.Empty;

            if (strMaNV == string.Empty)
            {
                strErr = "Chưa nhập Mã Nhân Viên";
            }
            if (strMK == string.Empty)
            {
                strErr += "\n Chưa nhập Mật Khẩu";
            }
            if (strErr != string.Empty)
            {
                MessageBox.Show(" " + strErr, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            NhanVienObj nvObj = new NhanVienObj();
            string      matkhau = "", ten = "", manv = "", phanquyen = "";

            if (ValidateChildren(ValidationConstraints.Enabled))
            {
                while (true)
                {
                    manv = txtMaNV.Text;
                    foreach (DataRow row in NhanVienCtr.DangNhap(manv).Rows)
                    {
                        matkhau   = row["MatKhau"].ToString();
                        ten       = row["TenNV"].ToString();
                        phanquyen = row["Quyen"].ToString();
                    }
                    if (txtMatkhau.Text == matkhau)
                    {
                        MessageBox.Show("Đăng nhập thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Save_Data();
                        mnvlogin = txtMaNV.Text;
                        if (phanquyen == "Admin")
                        {
                            this.Hide();
                            frmTrangChu frm = new frmTrangChu(ten, manv, phanquyen);
                            frm.ShowDialog();
                            this.Show();
                            txtMatkhau.ResetText();
                            break;
                        }
                        else if (phanquyen == "User")
                        {
                            this.Hide();
                            frmUser frm = new frmUser(ten, manv, phanquyen);
                            frm.ShowDialog();
                            this.Show();
                            txtMatkhau.ResetText();
                            break;
                        }
                    }
                    else
                    {
                        if (dem == 3)
                        {
                            MessageBox.Show("Bạn nhập sai quá 3 lần cho phép.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            this.Close();
                            break;
                        }
                        dem++;
                        MessageBox.Show("Sai tên đăng nhập hoặc mật khẩu.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                    }
                }
            }
        }