Exemplo n.º 1
0
 private void btn_xoa_Click(object sender, EventArgs e)
 {
     try
     {
         if (txt_emailNhanVien.Text == cache.mail)
         {
             MessageBox.Show("Bạn không thể xoá chính mình!");
             return;
         }
         string email = txt_emailNhanVien.Text;
         if (MessageBox.Show("Bạn Có Chắc Muốn Xoá Nhân Viên Này", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
         {
             if (BUS_NHANVIEN.deleteNhanVien(email))
             {
                 MessageBox.Show("Xoá Dữ Liệu Thành Công");
                 ResetValue();
                 LoadGridView_NhanVien();
             }
             else
             {
                 MessageBox.Show("Xoá Dữ Liệu Không Thành Công");
             }
         }
         else
         {
             ResetValue();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 2
0
 private void btn_quenMatKhau_Click(object sender, EventArgs e)
 {
     if (txt_EmailDangNhap.Text != "")
     {
         if (BUS_NHANVIEN.QuenMatKhau(txt_EmailDangNhap.Text))
         {
             StringBuilder builder = new StringBuilder();
             builder.Append(RandomString(4, true));
             builder.Append(RandomNumber(1000, 9990));
             builder.Append(RandomString(2, false));
             MessageBox.Show(builder.ToString());
             string matkhaumoi = BUS_NHANVIEN.encryption(builder.ToString());
             BUS_NHANVIEN.TaoMatKhauMoi(txt_EmailDangNhap.Text, matkhaumoi);
             SendMail(txt_EmailDangNhap.Text, matkhaumoi);
         }
         else
         {
             MessageBox.Show("Email Không tồn tại");
         }
     }
     else
     {
         MessageBox.Show("bạn cần nhập email để phục hồi mật khẩu");
         txt_EmailDangNhap.Focus();
     }
 }
Exemplo n.º 3
0
 public void btn_DangNhap_Click(object sender, EventArgs e)
 {
     try
     {
         if (txt_EmailDangNhap.Text == "" || txt_MatKhauDangNhap.Text == "")
         {
             MessageBox.Show("Email đăng nhập và Password không được để trống!");
             return;
         }
         if (!KiemTraEmail(txt_EmailDangNhap.Text))
         {
             MessageBox.Show("Email không đúng định dạng!");
             return;
         }
         if (txt_MatKhauDangNhap.Text.Length < 6)
         {
             MessageBox.Show("Mật khẩu phải dài hơn hoặc bằng 6 kỹ tự!");
             return;
         }
         DTO_NHANVIEN nv = new DTO_NHANVIEN();
         nv.Email   = txt_EmailDangNhap.Text.ToLower();
         nv.matKhau = txt_MatKhauDangNhap.Text.ToLower();
         if (BUS_NHANVIEN.DangNhap(nv))
         {
             string mail = nv.Email;
             cache.mail = mail;                 // truyền mail đăng nhập cho Home
             DataTable dt = BUS_NHANVIEN.LayVaiTroNV(nv.Email);
             vaitro = dt.Rows[0][0].ToString(); // lấy vai trò nhân viên
             MessageBox.Show("Login Successfully");
             cache.session = 1;                 // đăng nhập thành công
             if (cbx_ghiNhoDangNhap.Checked)
             {
                 Properties.Settings.Default.user = txt_EmailDangNhap.Text;
                 Properties.Settings.Default.pass = txt_MatKhauDangNhap.Text;
                 Properties.Settings.Default.Save();
             }
             else
             {
                 Properties.Settings.Default.user      = "";
                 Properties.Settings.Default.pass      = "";
                 Properties.Settings.Default.isChecked = false;
                 Properties.Settings.Default.Save();
             }
             this.Close();
         }
         else
         {
             MessageBox.Show("Login Fail, Email or PassWord Wrong!");
             txt_EmailDangNhap.Text   = null;
             txt_MatKhauDangNhap.Text = null;
             txt_EmailDangNhap.Focus();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 4
0
        public void TestDangNhap004()
        {
            DTO_NHANVIEN nv = new DTO_NHANVIEN();

            nv.Email   = "*****@*****.**";
            nv.matKhau = "123456";
            bool result = BUS_NHANVIEN.DangNhap(nv);

            Assert.IsTrue(result);
        }
Exemplo n.º 5
0
        public void TestDangNhap003()
        {
            DTO_NHANVIEN nv = new DTO_NHANVIEN();

            nv.Email   = "*****@*****.**";
            nv.matKhau = "654321";
            bool result = BUS_NHANVIEN.DangNhap(nv);

            Assert.IsFalse(result);
        }
Exemplo n.º 6
0
        public void TestDangNhap001()
        {
            DTO_NHANVIEN nv = new DTO_NHANVIEN();

            nv.Email   = " ";
            nv.matKhau = "123456";
            bool result = BUS_NHANVIEN.DangNhap(nv);

            Assert.IsFalse(result);
        }
Exemplo n.º 7
0
 private void btn_sua_Click(object sender, EventArgs e)
 {
     try {
         if (txt_TenNhanVien.Text.Trim().Length == 0)
         {
             MessageBox.Show("Vui Lòng Nhập Tên Nhân Viên", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             txt_TenNhanVien.Focus();
             return;
         }
         else if (txt_DiaChiNhanVien.Text.Trim().Length == 0)
         {
             MessageBox.Show("Vui Lòng Nhập Địa Chỉ Nhân Viên", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             txt_DiaChiNhanVien.Focus();
             return;
         }
         else
         {
             int role      = 0;
             int tinhTrang = 0;
             if (rad_quanTri.Checked)
             {
                 role = 1;
             }
             if (rad_hoatDong.Checked)
             {
                 tinhTrang = 1;
             }
             DTO_NHANVIEN nv = new DTO_NHANVIEN(txt_emailNhanVien.Text, txt_TenNhanVien.Text, txt_DiaChiNhanVien.Text, role, tinhTrang);
             if (MessageBox.Show("Bạn Có Muốn Thay Đổi Thông Tin Nhân Viên Không", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
             {
                 if (BUS_NHANVIEN.updateNhanVien(nv))
                 {
                     MessageBox.Show("Sửa Thông Tin Thành Công");
                     ResetValue();
                     LoadGridView_NhanVien();
                 }
                 else
                 {
                     MessageBox.Show("Sửa Thông Tin Không Thành Công");
                 }
             }
             else
             {
                 ResetValue();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 8
0
 private void btnXoaNV_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         BUS_NHANVIEN.Xoa_NhanVien(txtMaNV.Text);
         DialogResult dr = MessageBox.Show("Xoa thành công");
         if (dr == DialogResult.OK)
         {
             loadata();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Lỗi" + ex.ToString());
     }
 }
Exemplo n.º 9
0
        private void btn_doiMatKhau_Click(object sender, EventArgs e)
        {
            if (txt_MatKhauCu.Text == "")
            {
                MessageBox.Show("Mật khẩu cũ không được để trống!");
                return;
            }
            DTO_NHANVIEN nv = new DTO_NHANVIEN();

            nv.Email   = txt_EmailNhanVien.Text;
            nv.matKhau = txt_MatKhauCu.Text;
            if (!BUS.BUS_NHANVIEN.DangNhap(nv))
            {
                MessageBox.Show("Đổi mật khẩu không thành công! Mật khẩu cũ sai!");
                return;
            }
            string matKhauMoi = BUS_NHANVIEN.encryption(txt_matKhauMoi.Text);
            string matKhauCu  = BUS_NHANVIEN.encryption(txt_MatKhauCu.Text);

            if (txt_matKhauMoi.Text == "" || txt_nhapLaiMatKhauMoi.Text == "")
            {
                MessageBox.Show("Không được để trống!");
                return;
            }
            if (txt_matKhauMoi.Text.Length < 6 || txt_nhapLaiMatKhauMoi.Text.Length < 6)
            {
                MessageBox.Show("Độ dài của mâ khẩu phải lớn hơn hoặc bằng 6 ký tự");
                return;
            }
            if (txt_matKhauMoi.Text != txt_nhapLaiMatKhauMoi.Text)
            {
                MessageBox.Show("Mật khẩu mới không trùng khớp");
                return;
            }
            if (BUS_NHANVIEN.DoimatKhau(txt_EmailNhanVien.Text, matKhauCu, matKhauMoi))
            {
                cache.profile = 1;
                cache.session = 0;
                sendMail(txt_EmailNhanVien.Text, txt_nhapLaiMatKhauMoi.Text);
                MessageBox.Show("Đổi mật khẩu thành công vui lòng đăng nhập lại để thực hiện chức năng!");
                return;
            }
            else
            {
                MessageBox.Show("Đổi mật khẩu không thành công!");
            }
        }
Exemplo n.º 10
0
 private void btnSuaNV_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         NhanVienInfo nv = new NhanVienInfo(txtMaNV.Text, txtHoTenNV.Text, txtDiaChi.Text, txtDienThoai.Text, txtGioiTinh.Text);
         BUS_NHANVIEN.Sua_NhanVien(nv);
         DialogResult dr = MessageBox.Show("Sửa thành công");
         if (dr == DialogResult.OK)
         {
             loadata();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Lỗi" + ex.ToString());
     }
 }
Exemplo n.º 11
0
        private void btn_timKiem_Click(object sender, EventArgs e)
        {
            DataTable ds = BUS_NHANVIEN.SearchNhanVien(txt_timKiemNhanVien.Text);

            if (ds.Rows.Count > 0)
            {
                dgv_NhanVien.DataSource            = ds;
                dgv_NhanVien.Columns[0].HeaderText = "Email";
                dgv_NhanVien.Columns[1].HeaderText = "Tên Nhân Viên";
                dgv_NhanVien.Columns[2].HeaderText = "Địa Chỉ";
                dgv_NhanVien.Columns[3].HeaderText = "Vai Trò";
                dgv_NhanVien.Columns[4].HeaderText = "Tình Trạng";
            }
            else
            {
                MessageBox.Show("Không Tìm Thấy Kết Quả");
            }
            txt_timKiemNhanVien.Text      = "Nhập Tên Nhân Viên";
            txt_timKiemNhanVien.BackColor = Color.White;
            ResetValue();
        }
Exemplo n.º 12
0
 private void loadata()
 {
     dt = BUS_NHANVIEN.HienThi_NhanVien_All();
     grcNhanVien.DataSource = dt;
 }
Exemplo n.º 13
0
 private void LoadGridView_NhanVien()
 {
     dgv_NhanVien.DataSource = BUS_NHANVIEN.getNhanVien();
 }
Exemplo n.º 14
0
 private void btn_luu_Click(object sender, EventArgs e)
 {
     try
     {
         var ktraEmail = from n in db.NHANVIENs
                         select n.Email;
         foreach (var item in ktraEmail)
         {
             if (txt_emailNhanVien.Text == item)
             {
                 MessageBox.Show("Email đã tồn tại vui lòng thử lại ");
                 return;
             }
         }
         int Role = 0;//role = 0 là nhân viên
         if (rad_quanTri.Checked)
         {
             Role = 1;
         }
         int tinhTrang = 0;// tình trạng = 0 là không hoạt động
         if (rad_hoatDong.Checked)
         {
             tinhTrang = 1;
         }
         if (txt_emailNhanVien.Text.Trim().Length == 0)//kiểm tra email đã nhập chưa
         {
             MessageBox.Show("Vui Lòng Nhập Email", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             txt_emailNhanVien.Focus();
             return;
         }
         else if (!IsValid(txt_emailNhanVien.Text.Trim()))
         {
             MessageBox.Show("Vui Lòng Nhập Email", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else if (txt_TenNhanVien.Text.Trim().Length == 0)
         {
             MessageBox.Show("Vui Lòng Nhập Tên Nhân Viên", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             txt_TenNhanVien.Focus();
             return;
         }
         else if (txt_DiaChiNhanVien.Text.Trim().Length == 0)
         {
             MessageBox.Show("Vui Lòng Nhập Địa Chỉ Nhân Viên", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             txt_DiaChiNhanVien.Focus();
             return;
         }
         else if (rad_hoatDong.Checked == false && rad_khongHoatDong.Checked == false)
         {
             MessageBox.Show("Vui Lòng Chọn Tình Trạng Tài Khoản", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         else if (rad_nhanVien.Checked == false && rad_quanTri.Checked == false)
         {
             MessageBox.Show("Vui Lòng Chọn Chức Vụ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         else
         {
             DTO_NHANVIEN nv = new DTO_NHANVIEN(txt_emailNhanVien.Text, txt_TenNhanVien.Text, txt_DiaChiNhanVien.Text, Role, tinhTrang);
             if (BUS_NHANVIEN.insertNhanVien(nv))
             {
                 MessageBox.Show("Thêm Nhân Viên Thành Công!");
                 ResetValue();
                 LoadGridView_NhanVien();
                 sendMail(nv.Email);
             }
             else
             {
                 MessageBox.Show("Thêm Không Thành Công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }