Esempio n. 1
0
        private void gvDanhMucNguoiDung_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e)
        {
            if (gvDanhMucNguoiDung.FocusedRowHandle > -1)
            {
                try
                {
                    NguoiDungDTO itemDTO = new NguoiDungDTO();
                    NguoiDungBUS itemBUS = new NguoiDungBUS();
                    MD5          maHoa   = new MD5();

                    itemDTO.MaNguoiDung  = gvDanhMucNguoiDung.GetFocusedRowCellValue("MaNguoiDung").ToString();
                    itemDTO.TenNguoiDung = gvDanhMucNguoiDung.GetFocusedRowCellValue("TenNguoiDung").ToString();
                    itemDTO.MatKhau      = maHoa.md5(gvDanhMucNguoiDung.GetFocusedRowCellValue("MatKhau").ToString());
                    itemDTO.VoHieu       = bool.Parse(gvDanhMucNguoiDung.GetFocusedRowCellValue("VoHieu").ToString());
                    itemDTO.IdChucDanh   = int.Parse(gvDanhMucNguoiDung.GetFocusedRowCellValue("IdChucDanh").ToString());
                    itemDTO.DiaChi       = gvDanhMucNguoiDung.GetFocusedRowCellValue("DiaChi").ToString();
                    itemDTO.DienThoai    = gvDanhMucNguoiDung.GetFocusedRowCellValue("DienThoai").ToString();
                    itemDTO.NgayBatDau   = DateTime.Parse(gvDanhMucNguoiDung.GetFocusedRowCellValue("NgayBatDau").ToString());
                    itemDTO.NgayKetThuc  = DateTime.Parse(gvDanhMucNguoiDung.GetFocusedRowCellValue("NgayKetThuc").ToString());
                    itemDTO.GhiChu       = gvDanhMucNguoiDung.GetFocusedRowCellValue("GhiChu").ToString();
                    itemDTO.Id           = int.Parse(gvDanhMucNguoiDung.GetFocusedRowCellValue("Id").ToString());

                    if (this.flagThem && gvDanhMucNguoiDung.FocusedRowHandle == gvDanhMucNguoiDung.RowCount - 2)
                    {
                        if (itemDTO.MaNguoiDung.Length > 0)
                        {
                            DialogResult hopThoai = MessageBox.Show("Bạn chắc chắn muốn thêm mới?", "Thêm mới", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (hopThoai == DialogResult.Yes)
                            {
                                itemBUS.Them(itemDTO);
                                this.flagThem = false;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Bạn chưa nhập mã!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        DialogResult hopThoai = MessageBox.Show("Bạn chắc chắn muốn cập nhật?", "Cập nhật", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (hopThoai == DialogResult.Yes)
                        {
                            itemBUS.Sua(itemDTO);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                this.LayDanhSachNguoiDung();
            }
        }
Esempio n. 2
0
        private void btnThayDoi_Click(object sender, EventArgs e)
        {
            MD5          mahoa        = new MD5();
            string       tenDangNhap  = nguoiDungDTO.MaNguoiDung;
            string       matKhau      = mahoa.md5(txtMatKhauCu.Text.Trim());
            NguoiDungBUS nguoiDungBUS = new NguoiDungBUS();
            bool         ketQua       = nguoiDungBUS.KiemTraDangNhap(tenDangNhap, matKhau);

            if (ketQua == false)
            {
                MessageBox.Show("Mật khẩu cũ không chính xác", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            else
            {
                if (this.txtMatKhauMoi.Text.Length < 6 && this.txtMatKhauMoi.Text.Length > 0)
                {
                    MessageBox.Show("Mật khẩu có ít nhất 6 ký tự", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return;
                }
                else if (this.txtMatKhauMoi.Text != this.txtMatKhauNhapLai.Text && this.txtMatKhauMoi.Text.Length > 0)
                {
                    MessageBox.Show("Mật khẩu mới nhập lại không trùng khớp", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return;
                }
                else
                {
                    if (this.txtDiaChi.Text.Length == 0 || this.txtSoDienThoai.Text.Length == 0)
                    {
                        MessageBox.Show("Điện thoại và địa chỉ không được bỏ trống", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        return;
                    }
                    else
                    {
                        try
                        {
                            nguoiDungDTO.DiaChi    = this.txtDiaChi.Text;
                            nguoiDungDTO.DienThoai = this.txtSoDienThoai.Text;
                            if (this.txtMatKhauMoi.Text.Length > 0)
                            {
                                nguoiDungDTO.MatKhau = mahoa.md5(txtMatKhauMoi.Text.Trim());
                            }
                            nguoiDungBUS.Sua(nguoiDungDTO);
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 private void btnThayDoi_Click(object sender, EventArgs e)
 {
     MD5 mahoa = new MD5();
     string tenDangNhap = nguoiDungDTO.MaNguoiDung;
     string matKhau = mahoa.md5(txtMatKhauCu.Text.Trim());
     NguoiDungBUS nguoiDungBUS = new NguoiDungBUS();
     bool ketQua = nguoiDungBUS.KiemTraDangNhap(tenDangNhap, matKhau);
     if(ketQua == false)
     {
         MessageBox.Show("Mật khẩu cũ không chính xác", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Hand);
         return;
     }
     else
     {
         if (this.txtMatKhauMoi.Text.Length < 6 && this.txtMatKhauMoi.Text.Length > 0)
         {
             MessageBox.Show("Mật khẩu có ít nhất 6 ký tự", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Hand);
             return;
         }
         else if (this.txtMatKhauMoi.Text != this.txtMatKhauNhapLai.Text && this.txtMatKhauMoi.Text.Length > 0)
         {
             MessageBox.Show("Mật khẩu mới nhập lại không trùng khớp", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Hand);
             return;
         }
         else
         {
             if (this.txtDiaChi.Text.Length == 0 || this.txtSoDienThoai.Text.Length ==0)
             {
                 MessageBox.Show("Điện thoại và địa chỉ không được bỏ trống", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                 return;
             }
             else
             {
                 try
                 {
                     nguoiDungDTO.DiaChi = this.txtDiaChi.Text;
                     nguoiDungDTO.DienThoai = this.txtSoDienThoai.Text;
                     if (this.txtMatKhauMoi.Text.Length > 0)
                         nguoiDungDTO.MatKhau = mahoa.md5(txtMatKhauMoi.Text.Trim());
                     nguoiDungBUS.Sua(nguoiDungDTO);
                     this.Close();
                 }
                 catch(Exception ex)
                 {
                     MessageBox.Show(ex.ToString());
                 }
             }
         }
     }
 }
        private void btnLuu_Sua_Click(object sender, RoutedEventArgs e)
        {
            bool TrungMaND = false;

SuaLai:
            string mand = null;

            if (txtMaND.Text.Length != 0)
            {
                mand = txtMaND.Text;
            }
            string hoten = null;

            if (txtHoTen.Text.Length != 0)
            {
                hoten = txtHoTen.Text;
            }
            string chucvu = null;

            if (txtChucVu.Text.Length != 0)
            {
                chucvu = txtChucVu.Text;
            }
            string phanquyen = null;

            if (txtPhanQuyen.Text.Length != 0)
            {
                phanquyen = txtPhanQuyen.Text;
            }

            NguoiDungDTO nv = new NguoiDungDTO(mand, hoten, chucvu, phanquyen);

            if (mand == null)
            {
                if (TrungMaND == false)
                {
                    MessageBox.Show("Mã số người dùng không được để trống");
                }
                else
                {
                    MessageBox.Show("Mã số người dùng bị trùng");
                }
                txtMaND.Focus();
            }
            else if (hoten == null)
            {
                MessageBox.Show("Họ tên không được để trống");
                txtHoTen.Focus();
            }
            else if (chucvu == null)
            {
                MessageBox.Show("Chức vụ không được để trống");
                txtChucVu.Focus();
            }
            else if (phanquyen == null)
            {
                MessageBox.Show("Phân quyền không được để trống");
                txtPhanQuyen.Focus();
            }
            else
            {
                try
                {
                    NguoiDungBUS.Sua(nv);
                }
                catch
                {
                    txtMaND.Clear();
                    TrungMaND = true;
                    goto SuaLai;
                }
                MessageBox.Show("Sửa thông tin người dùng  thành công", "Thông báo");

                DataTable dataTable = new DataTable();
                dataTable = NguoiDungBUS.LoadDSND();
                Load_Data(dataTable);

                KhongChoNhap();
                btnLuu_Sua.Visibility = Visibility.Hidden;
                btnSua.Visibility     = Visibility.Visible;
                btnThem.IsEnabled     = btnXoa.IsEnabled = true;
                dtgDSND.IsEnabled     = true;
                Selected = false;
            }
        }