示例#1
0
        private void btnLuu_click(object sender, EventArgs e)
        {
            if (Cur_State == 1)
            {
                int KT_NguoiDung = nguoiDungBUS.DaTonTai(txtTaiKhoan.Text);
                if (KT_NguoiDung >= 1)
                {
                    XtraMessageBox.Show("Tên người dùng đã tồn tại", "Hệ Thống", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            if (string.Compare(txtMatKhau.Text, txtReMK.Text) != 0)
            {
                XtraMessageBox.Show("Mật khẩu nhập lại không đúng", "Hệ Thống", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if (string.IsNullOrEmpty(txtTaiKhoan.Text) || string.IsNullOrEmpty(txtMatKhau.Text))
                {
                    XtraMessageBox.Show("Không được để trống tài khoản hoặc mật khẩu", "Hệ Thống", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    NguoiDung nd = new NguoiDung();
                    nd.TenDangNhap = txtTaiKhoan.Text;
                    nd.Password    = hashStringToPassword(txtMatKhau.Text);
                    nd.MaNV        = lkueNhanVien.EditValue.ToString();
                    nd.MaVaiTro    = lkueVaiTro.EditValue.ToString();
                    nd.DienGiai    = txtDienGiai.Text;
                    nd.ConQuanLy   = ckbConQuanLy.Checked;

                    //thêm
                    if (Cur_State == 1)
                    {
                        int kq = nguoiDungBUS.ThemNguoiDung(nd);
                        if (kq >= 1)
                        {
                            ThemThanhCong();
                            XtraMessageBox.Show("Thêm người dùng thành công", "Hệ Thống", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            XtraMessageBox.Show("Thêm thất bại", "Hệ Thống", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }

                    //sửa
                    else if (Cur_State == 0)
                    {
                        int kq = nguoiDungBUS.CapNhatNguoiDung(nd);
                        if (kq >= 1)
                        {
                            CapNhatThanhCong();
                            XtraMessageBox.Show("Cập nhật người dùng thành công", "Hệ Thống", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            XtraMessageBox.Show("Cập nhật thất bại", "Hệ Thống", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }
        }