private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (txtUserName.Text != "")
            {
                if (!ResetPW && !Common.Int2Bool(((NguoiDungInfor)Declare.USER_INFOR).SupperUser))
                {
                    string oldPass = Password.SetPassword(txtOldPass.Text, objUser.Salt);
                    if (oldPass != objUser.MatKhau)
                    {
                        MessageBox.Show(Declare.msgChangePass_WrongPassword, Declare.titleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        txtOldPass.Focus();
                        return;
                    }

                    if (txtNewPass.Text == txtOldPass.Text)
                    {
                        MessageBox.Show("Mật khẩu mới không được trùng với mật khẩu cũ", Declare.titleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        txtNewPass.Focus();
                        return;
                    }
                }
                if (txtNewPass.Text != txtRetypePass.Text)
                {
                    MessageBox.Show(Declare.msgChangePass_RetypePass, Declare.titleWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtRetypePass.Focus();
                    return;
                }
                try
                {
                    string mySalt  = Password.CreateSalt();
                    string newPass = Password.SetPassword(txtNewPass.Text, mySalt);
                    objUser.MatKhau = newPass;
                    objUser.Salt    = mySalt;

                    objUser.ChangeOnNext = chkForceChangeAtFirst.Enabled;

                    if (chkForceChangeAtFirst.Enabled)
                    {
                        objUser.ChangeOnNext = chkForceChangeAtFirst.Checked;
                    }

                    NguoiDungDataProvider.Update(objUser);

                    NguoiDungDataProvider.ChangePass(objUser.IdNguoiDung, newPass);

                    MessageBox.Show(Declare.msgChangePass_PassHasChanged, Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Information);

                    this.DialogResult = DialogResult.OK;

                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(Declare.msgUpdateErr, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtUserName.Text.Trim().Equals(""))
                {
                    MessageBox.Show(Declare.msgInputData, Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtUserName.Focus();
                    return;
                }

                if (txtPassword.Text.Trim() != txtRetypePassword.Text.Trim())
                {
                    MessageBox.Show("Xác nhận lại mật khẩu!", Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtRetypePassword.Focus();
                    return;
                }

                if (bteThuongVien.Tag == null)
                {
                    MessageBox.Show("Phải chọn nhân viên!", Declare.titleNotice, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    bteThuongVien.Focus();
                    return;
                }

                if (!String.IsNullOrEmpty(txtExpiredIn.Text) && !Common.IsNumeric4(txtExpiredIn.Text))
                {
                    txtExpiredIn.Focus();

                    throw new ManagedException("Thời gian áp dụng không đúng định dạng.");
                }

                if (Convert.ToInt32(txtExpiredIn.Text) < 0)
                {
                    throw new ManagedException("Thời gian áp dụng phải lớn hơn hoặc bằng 0.");
                }

                if (objNguoiDung == null)
                {
                    if (NguoiDungDataProvider.Exist(txtUserName.Text.Trim()))
                    {
                        MessageBox.Show("Tên đăng nhập này đã được sử dụng. Hãy chọn tên đăng nhập khác!");
                        txtUserName.Focus();
                        return;
                    }
                    objNguoiDung = new NguoiDungInfor();
                    //cap nhat thong tin NND
                    string mySalt = Password.CreateSalt();
                    string myPass = Password.SetPassword(txtPassword.Text.Trim(), mySalt);

                    objNguoiDung.TenDayDu        = txtFullName.Text.Trim();
                    objNguoiDung.TenDangNhap     = txtUserName.Text.Trim();
                    objNguoiDung.MatKhau         = myPass;
                    objNguoiDung.Salt            = mySalt;
                    objNguoiDung.IdNhanVien      = ((DMNhanVienInfo)bteThuongVien.Tag).IdNhanVien;
                    objNguoiDung.IdNhomNguoiDung = Common.IntValue(cboGroup.SelectedValue);
                    objNguoiDung.SuDung          = chkSuDung.Checked;// (chkSuDung.Checked ? 1 : 0);

                    if (chkNeverExpired.Checked)
                    {
                        objNguoiDung.ThoiGianApDung = -1;
                    }
                    else
                    {
                        objNguoiDung.ThoiGianApDung = Convert.ToInt32(txtExpiredIn.Text);
                    }

                    objNguoiDung.ChangeOnNext = chkForceChangeAtFirst.Checked;

                    NguoiDungDataProvider.Insert(objNguoiDung);

                    MessageBox.Show("Thêm mới thông tin người dùng thành công!");
                }
                else
                {
                    objNguoiDung.TenDayDu        = txtFullName.Text.Trim();
                    objNguoiDung.IdNhanVien      = ((DMNhanVienInfo)bteThuongVien.Tag).IdNhanVien;
                    objNguoiDung.IdNhomNguoiDung = Common.IntValue(cboGroup.SelectedValue);
                    objNguoiDung.SuDung          = chkSuDung.Checked;// (chkSuDung.Checked ? 1 : 0);

                    if (chkNeverExpired.Checked)
                    {
                        objNguoiDung.ThoiGianApDung = -1;
                    }
                    else
                    {
                        objNguoiDung.ThoiGianApDung = Convert.ToInt32(txtExpiredIn.Text);
                    }

                    objNguoiDung.ChangeOnNext = chkForceChangeAtFirst.Checked;

                    NguoiDungDataProvider.Update(objNguoiDung);

                    MessageBox.Show("Cập nhật thông tin người dùng thành công!");
                }
                this.frm.LoadAllNguoiDung();
            }
            catch (ManagedException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            catch (Exception ex)
            {
#if DEBUG
                MessageBox.Show(ex.ToString());
#else
                MessageBox.Show(ex.Message);
#endif
                EventLogProvider.Instance.WriteOfflineLog(ex.ToString(), "");
            }
        }