void Load_cbMaNhanVien() { cbMaNv.DataSource = TaiKhoanBus.TaiKhoan_LoadNVChuCoTaiKhoan(); cbMaNv.DisplayMember = "nv_id"; cbMaNv.ValueMember = "nv_id"; cbMaNv.SelectedIndex = -1; }
private void btncapnhat_Click(object sender, EventArgs e) { if (cbquyen.SelectedIndex == -1 || cbquyen.SelectedIndex == -1 || txtmatkhau.Text == "") { XtraMessageBox.Show("Vui lòng điền đầy đủ thông tin", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { DialogResult dialogResult = XtraMessageBox.Show("Bạn có chắc chắn muốn CẬP NHẬT tài khoản vừa chọn", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { TaiKhoanDTO tk = new TaiKhoanDTO(); tk.Nv_id = cbmanv.Text; if (cbquyen.Text == "Nhân viên") { tk.Tk_quyen = 0; } else { tk.Tk_quyen = 1; } tk.Tm_mk = txtmatkhau.Text; tk.Tk_trangthai = 1; if (TaiKhoanBus.TaiKhoan_Them(tk, 2)) { XtraMessageBox.Show("Cập nhật thành công tài khoản: " + cbmanv.Text, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; } else { XtraMessageBox.Show("Lỗi không xóa được", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); } } } }
void TaiKhoan_Load() { cbmanv.DataSource = TaiKhoanBus.Load_TaiKhoan(); cbmanv.DisplayMember = "nv_id"; cbmanv.ValueMember = "nv_id"; cbmanv.SelectedIndex = -1; }
private void btnDangNhap_Click(object sender, EventArgs e) { if (fDN == null || fDN.IsDisposed) { fDN = new frmDangNhap(); } if (fDN.ShowDialog() == DialogResult.OK) { if (fDN.txtTenDangNhap.Text.Trim() == "") { MessageBox.Show("Tên đăng nhập không được để trống!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); btnDangNhap_Click(sender, e); } else if (fDN.txtMatKhau.Text.Trim() == "") { MessageBox.Show("Mật khẩu viên không được để trống!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); btnDangNhap_Click(sender, e); } else { TaiKhoanBus tKBus = new TaiKhoanBus(); if (tKBus.DangNhap(fDN.txtTenDangNhap.Text.Trim(), fDN.txtMatKhau.Text)) { // Đăng nhập thành công if (quyenHan == Quyen_QuanLy) { setVaiTro(Quyen_QuanLy); fDN.txtMatKhau.Clear(); } else if (quyenHan == Quyen_NhanVien) { setVaiTro(Quyen_NhanVien); fDN.txtMatKhau.Clear(); } else { setVaiTro(Quyen_Khach); } } else { // Đăng nhập thất bại MessageBox.Show("Tên đăng nhập hoặc mật khẩu không chính xác!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); btnDangNhap_Click(sender, e); } } } }
void loadmk(string manv) { DataTable dt = TaiKhoanBus.TaiKhoan_LayQuyenTruyCap(manv); string mkcu = dt.Rows[0]["tk_matkhau"].ToString(); if (mkcu == txtmatkhaucu.Text) { if (txtmkmoi.Text != txtmatkhaucu.Text) { if (txtmkmoi.Text == txtnhaplaimk.Text) { DialogResult dialogResult = XtraMessageBox.Show("Bạn có chắc chắn muốn đổi mật khẩu?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { TaiKhoanDTO tk = new TaiKhoanDTO(); tk.Nv_id = manv; tk.Tm_mk = txtmkmoi.Text; tk.Tk_trangthai = 1; tk.Tk_quyen = int.Parse(dt.Rows[0]["tk_quyen"].ToString()); if (TaiKhoanBus.TaiKhoan_Them(tk, 2)) { XtraMessageBox.Show("Đã cập nhật mật khẩu mới!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XtraMessageBox.Show("Lỗi không cập nhật được mật khẩu!", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); } } } else { XtraMessageBox.Show("Xác nhận mật khẩu không trùng khớp!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { XtraMessageBox.Show("Mật khẩu cũ và mật khẩu mới phải khác nhau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { XtraMessageBox.Show("Mật khẩu cũ cũ không đúng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void cbmanv_SelectedIndexChanged(object sender, EventArgs e) { try { DataTable dt = TaiKhoanBus.TaiKhoan_LayQuyenTruyCap(cbmanv.SelectedValue.ToString()); if (dt.Rows[0]["tk_quyen"].ToString() == "0") { cbquyen.Text = "Nhân viên"; } else { cbquyen.Text = "Quản lý"; } txtmatkhau.Text = dt.Rows[0]["tk_matkhau"].ToString(); } catch (Exception) { return; } }
private void but_ConfirmChangePass_Click(object sender, EventArgs e) { TaiKhoanBus _tkBUS = new TaiKhoanBus(); #region "Check valid front end" string l_PasswordOld = Extensions.EncryptMD5(txt_passwordOld.Text, true).Trim(); string l_PasswordNew = Extensions.EncryptMD5(txt_passwordNew.Text, true).Trim(); string l_PasswordRe = Extensions.EncryptMD5(txt_PasswordRe.Text, true).Trim(); string ErrorValidPassword = string.Empty; if (string.IsNullOrEmpty(l_PasswordOld) || string.IsNullOrEmpty(l_PasswordNew) || string.IsNullOrEmpty(l_PasswordRe)) { DialogResult dialogResult = MessageBox.Show("Thông tin nhập vào không được rỗng!!!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); if (dialogResult == DialogResult.OK) { if (string.IsNullOrEmpty(l_PasswordOld)) { txt_passwordOld.Focus(); } if (string.IsNullOrEmpty(l_PasswordNew)) { txt_passwordNew.Focus(); } if (string.IsNullOrEmpty(l_PasswordRe)) { txt_PasswordRe.Focus(); } if (string.IsNullOrEmpty(l_PasswordOld) && string.IsNullOrEmpty(l_PasswordNew) && string.IsNullOrEmpty(l_PasswordRe)) { txt_passwordOld.Focus(); } } } #endregion else if (l_PasswordNew != l_PasswordRe) { MessageBox.Show("Mật khẩu nhập lại không trùng", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (Extensions.IsValidPassword(txt_passwordNew.Text, out ErrorValidPassword) == false) { MessageBox.Show(ErrorValidPassword, "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_passwordNew.Focus(); } else { int result = _tkBUS.ChangePassWord(_loginTaiKhoan.MaNhanVien, l_PasswordOld, l_PasswordNew); if (result == 0) { MessageBox.Show("Sai mật khẩu cũ", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_passwordOld.Focus(); } else if (result == 1) { DialogResult dialogResult = MessageBox.Show("Đổi mật khẩu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); if (dialogResult == DialogResult.OK && getDataChangePasswordFormFromLoginForm != null) { this.Hide(); frm_main _frmMain = new frm_main(); _frmMain.accountLoginOrchangePasswordDelegate += delegate { return(_loginTaiKhoan); };//Set data from form change password _frmMain.Show(); } else if (dialogResult == DialogResult.OK && getDataChangePasswordFormFromMainForm != null) { this.Dispose(); } } else if (result == 2) { MessageBox.Show("Có lỗi trong quá trình đổi mật khẩu", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); txt_passwordOld.Focus(); } } }
private void Login() { string l_UserName = txt_UserName.Text.Trim(); string en_Password = string.Empty; if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.userName) && Properties.Settings.Default.passWord == txt_Password.Text) { en_Password = Extensions.DecryptMD5(Properties.Settings.Default.passWord, true); } string l_Password = string.IsNullOrEmpty(en_Password) ? Extensions.EncryptMD5(txt_Password.Text, true).Trim(): Extensions.EncryptMD5(en_Password, true).Trim(); if (string.IsNullOrEmpty(l_UserName) || string.IsNullOrEmpty(l_Password)) { DialogResult dialogResult = MessageBox.Show("Tên đăng nhập hoặc mật khẩu không được trống!!!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); if (dialogResult == DialogResult.OK) { if (string.IsNullOrEmpty(l_UserName)) { txt_UserName.Focus(); } if (string.IsNullOrEmpty(l_Password)) { txt_Password.Focus(); } if (string.IsNullOrEmpty(l_UserName) && string.IsNullOrEmpty(l_Password)) { txt_UserName.Focus(); } } } else { try { TaiKhoanBus _tk = new TaiKhoanBus(); var _login = _tk.Login(l_UserName, l_Password); if (_login == null) { DialogResult dialogResult = MessageBox.Show("Không lấy được thông tin đăng nhập!!!", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult == DialogResult.Yes) { if (string.IsNullOrEmpty(l_UserName)) { txt_UserName.Focus(); } if (string.IsNullOrEmpty(l_Password)) { txt_Password.Focus(); } if (string.IsNullOrEmpty(l_UserName) && string.IsNullOrEmpty(l_Password)) { txt_UserName.Focus(); } } else if (dialogResult == DialogResult.No) { Application.Exit(); } } else { _tkDto = _login; NhanVienDto _nvDTO = new NhanVienDto(); NhanVienBus _nvBUS = new NhanVienBus(); _nvDTO = _nvBUS.ReadStaff(_tkDto.MaNhanVien); if (_nvDTO != null) { if (!_nvDTO.DoiMatKhau) { DialogResult dialogResult = MessageBox.Show("Vui lòng đổi mật khẩu cho lần đầu tiên đăng nhập", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult == DialogResult.Yes) { this.Hide(); frm_DoiMatKhau_HeThong _frmChangPass = new frm_DoiMatKhau_HeThong(); _frmChangPass.getDataChangePasswordFormFromLoginForm += delegate { return(_login); };//set data from login form _frmChangPass.Show(); } else if (dialogResult == DialogResult.No) { Application.Exit(); } } else { this.Hide(); if (chkRememberUser.Checked) { if (Properties.Settings.Default.userName != string.Empty) { Properties.Settings.Default.Upgrade(); Properties.Settings.Default.userName = l_UserName; Properties.Settings.Default.passWord = l_Password; Properties.Settings.Default.is_Check = chkRememberUser.Checked; Properties.Settings.Default.Save(); } else { Properties.Settings.Default.userName = l_UserName; Properties.Settings.Default.passWord = l_Password; Properties.Settings.Default.is_Check = chkRememberUser.Checked; Properties.Settings.Default.Save(); } } else { Properties.Settings.Default.Reset(); Properties.Settings.Default.Save(); } frm_main _frmMain = new frm_main(); _frmMain.accountLoginOrchangePasswordDelegate += delegate { return(_login); };//Set data from form login _frmMain.Show(); } } else { DialogResult dialogResult = MessageBox.Show("Vui lòng kiểm tra trạng thái nhân viên", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { if (string.IsNullOrEmpty(l_UserName)) { txt_UserName.Focus(); } if (string.IsNullOrEmpty(l_Password)) { txt_Password.Focus(); } if (string.IsNullOrEmpty(l_UserName) && string.IsNullOrEmpty(l_Password)) { txt_UserName.Focus(); } } else if (dialogResult == DialogResult.No) { Application.Exit(); } } } } catch (Exception ex) { Logger.WriteLogError("Login Login", ex.ToString()); DialogResult dialogResult = MessageBox.Show("Vui lòng kiểm tra trạng thái nhận viên", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } }
private void btnThemTk_Click(object sender, EventArgs e) { if (txtmatkhau.Text != "" && txtnhaplaimk.Text != "" && cbMaNv.SelectedValue.ToString() != "" && cbQuyen.Text != "") { if (txtmatkhau.Text.Length > 5 && txtmatkhau.Text.Length <= 20) { if (txtmatkhau.Text == txtnhaplaimk.Text) { TaiKhoanDTO tk = new TaiKhoanDTO(); tk.Nv_id = cbMaNv.SelectedValue.ToString(); if (cbQuyen.Text == "Quản lý") { tk.Tk_quyen = 1; } else { tk.Tk_quyen = 0; } tk.Tm_mk = txtmatkhau.Text; tk.Tk_trangthai = 1; if (TaiKhoanBus.TaiKhoan_Them(tk, 1)) { if (NhanVienBUS.NhanVien_CapNhatNhanVienCoTaiKhoan(cbMaNv.SelectedValue.ToString(), 1)) { XtraMessageBox.Show("Thêm thành công!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); flag = true; if (flag == true) { DialogResult = DialogResult.OK; } else { DialogResult = DialogResult.Cancel; } this.Close(); } else { XtraMessageBox.Show("Lỗi cập nhật được trạng thái tài khoản của nhân viên!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { XtraMessageBox.Show("Lỗi không thêm được!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { XtraMessageBox.Show("Mật khẩu không trùng khớp!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { XtraMessageBox.Show("Độ dài mật khẩu từ 6-20 ký tự!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { XtraMessageBox.Show("Vui lòng điền đầy đủ thông tin!!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }