예제 #1
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     try
     {
         errorProviderLogin.Clear();
         panelError.Visible = false;
         if (string.IsNullOrEmpty(txtTenDangNhap.Text))
         {
             errorProviderLogin.SetError(txtTenDangNhap, "Vui lòng nhập Tên đăng nhập!");
             txtTenDangNhap.Focus();
         }
         else
         if (string.IsNullOrEmpty(txtMatKhau.Text))
         {
             errorProviderLogin.SetError(txtMatKhau, "Vui lòng nhập Mật khẩu!");
             txtMatKhau.Focus();
         }
         else
         {
             User LoginUser = new UserLDM().Login(txtTenDangNhap.Text, txtMatKhau.Text);
             if (LoginUser != null)
             {
                 mUser.UserName     = LoginUser.UserName;
                 mUser.Address      = LoginUser.Address;
                 mUser.CreatedByID  = LoginUser.CreatedByID;
                 mUser.CreatedDate  = LoginUser.CreatedDate;
                 mUser.DateOfBirth  = LoginUser.DateOfBirth;
                 mUser.Customers    = LoginUser.Customers;
                 mUser.DisplayName  = LoginUser.DisplayName;
                 mUser.Email        = LoginUser.Email;
                 mUser.Gender       = LoginUser.Gender;
                 mUser.ID           = LoginUser.ID;
                 mUser.isAdmin      = LoginUser.isAdmin;
                 mUser.isDelete     = LoginUser.isDelete;
                 mUser.ModifiedByID = LoginUser.ModifiedByID;
                 mUser.ModifiedDate = LoginUser.ModifiedDate;
                 mUser.Password     = LoginUser.Password;
                 mUser.Phone        = LoginUser.Phone;
                 mUser.Users_Roles  = LoginUser.Users_Roles;
                 mUser.isPay        = LoginUser.isPay;
                 this.Close();
             }
             else
             {
                 mUser.ID           = -1;
                 panelError.Visible = true;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #2
0
 private void btnLuuLai_Click(object sender, EventArgs e)
 {
     try
     {
         User newUser = new User();
         erpThemNguoiDung.Clear();
         if (string.IsNullOrEmpty(txtTenDangNhap.Text.Trim()))
         {
             erpThemNguoiDung.SetError(txtTenDangNhap, "Vui lòng điền trường này!");
             txtTenDangNhap.Focus();
         }
         else
         {
             if (new UserLDM().isDuplicateUserName(txtTenDangNhap.Text.Trim()))
             {
                 erpThemNguoiDung.SetError(txtTenDangNhap, "Tên đăng nhập đã tồn tại!");
                 txtTenDangNhap.Focus();
             }
             else
             {
                 {
                     newUser.UserName = txtTenDangNhap.Text.Trim();
                     if (string.IsNullOrEmpty(txtMatKhau.Text.Trim()))
                     {
                         erpThemNguoiDung.SetError(txtMatKhau, "Vui lòng điền trường này!");
                         txtMatKhau.Focus();
                     }
                     else
                     {
                         if (string.IsNullOrEmpty(txtNhapLaiMatKhau.Text.Trim()))
                         {
                             erpThemNguoiDung.SetError(txtNhapLaiMatKhau, "Vui lòng điền trường này!");
                             txtNhapLaiMatKhau.Focus();
                         }
                         else
                         {
                             if (!txtMatKhau.Text.Trim().Equals(txtNhapLaiMatKhau.Text.Trim()))
                             {
                                 erpThemNguoiDung.SetError(txtNhapLaiMatKhau, "Nhập lại mật khẩu không khớp!");
                                 txtNhapLaiMatKhau.Focus();
                             }
                             else
                             {
                                 newUser.Password = Commons.En_Decrypt.Encrypt(txtMatKhau.Text.Trim());
                                 if (string.IsNullOrEmpty(txtTenHienThi.Text.Trim()))
                                 {
                                     erpThemNguoiDung.SetError(txtTenHienThi, "Vui lòng điền trường này!");
                                     txtTenHienThi.Focus();
                                 }
                                 else
                                 {
                                     newUser.DisplayName = txtTenHienThi.Text.Trim();
                                     if (dtpNgaySinh.Value == null)
                                     {
                                         erpThemNguoiDung.SetError(dtpNgaySinh, "Vui lòng điền trường này!");
                                         dtpNgaySinh.Focus();
                                     }
                                     else
                                     {
                                         newUser.DateOfBirth = dtpNgaySinh.Value;
                                         if (!rdoNam.Checked && !rdoNu.Checked)
                                         {
                                             erpThemNguoiDung.SetError(rdoNu, "Vui lòng điền trường này!");
                                         }
                                         else
                                         {
                                             newUser.Gender = rdoNam.Checked;
                                             if (string.IsNullOrEmpty(txtSoDienThoai.Text.Trim()))
                                             {
                                                 erpThemNguoiDung.SetError(txtSoDienThoai, "Vui lòng điền trường này!");
                                                 txtSoDienThoai.Focus();
                                             }
                                             else
                                             {
                                                 newUser.Phone = txtSoDienThoai.Text.Trim();
                                                 if (string.IsNullOrEmpty(txtEmail.Text.Trim()))
                                                 {
                                                     erpThemNguoiDung.SetError(txtEmail, "Vui lòng điền trường này!");
                                                     txtEmail.Focus();
                                                 }
                                                 else
                                                 {
                                                     Regex mRegxExpression;
                                                     mRegxExpression = new Regex(@"^([a-zA-Z0-9_\-])([a-zA-Z0-9_\-\.]*)@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$");
                                                     if (!mRegxExpression.IsMatch(txtEmail.Text.Trim()))
                                                     {
                                                         erpThemNguoiDung.SetError(txtEmail, "Địa chỉ email không hợp lệ!");
                                                         txtEmail.Focus();
                                                     }
                                                     else
                                                     {
                                                         newUser.Email = txtEmail.Text.Trim();
                                                         if (string.IsNullOrEmpty(txtDiaChi.Text.Trim()))
                                                         {
                                                             erpThemNguoiDung.SetError(txtDiaChi, "Vui lòng nhập trường này!");
                                                             txtDiaChi.Focus();
                                                         }
                                                         else
                                                         {
                                                             newUser.Address     = txtDiaChi.Text.Trim();
                                                             newUser.CreatedByID = mUser.ID;
                                                             newUser.CreatedDate = DateTime.Now.Date;
                                                             newUser.isAdmin     = 2;
                                                             newUser.isDelete    = false;
                                                             newUser.isPay       = chkThanhToan.Checked;
                                                             User UserResult = new UserLDM().Insert(newUser);
                                                             if (UserResult != null)
                                                             {
                                                                 MessageBox.Show($"Thêm người dùng thành công!");
                                                                 this.UCNguoiDung.ReloadDataNguoiDung();
                                                             }
                                                             else
                                                             {
                                                                 MessageBox.Show("Thêm người dùng thất bại!");
                                                             }
                                                             this.Close();
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #3
0
        private void btnLuuLai_Click(object sender, EventArgs e)
        {
            User newUser = new User();

            erpThemTaiKhoan.Clear();
            if (string.IsNullOrEmpty(txtTenDangNhap.Text.Trim()))
            {
                erpThemTaiKhoan.SetError(txtTenDangNhap, "Vui lòng điền trường này!");
                txtTenDangNhap.Focus();
            }
            else
            {
                newUser.UserName = txtTenDangNhap.Text;
                if (string.IsNullOrEmpty(txtMatKhau.Text.Trim()))
                {
                    erpThemTaiKhoan.SetError(txtMatKhau, "Vui lòng điền trường này!");
                    txtMatKhau.Focus();
                }
                else
                {
                    if (string.IsNullOrEmpty(txtNhapLaiMatKhau.Text.Trim()))
                    {
                        erpThemTaiKhoan.SetError(txtNhapLaiMatKhau, "Vui lòng điền trường này!");
                        txtNhapLaiMatKhau.Focus();
                    }
                    else
                    {
                        if (!txtMatKhau.Text.Equals(txtNhapLaiMatKhau.Text))
                        {
                            erpThemTaiKhoan.SetError(txtNhapLaiMatKhau, "Nhập lại mật khẩu không khớp!");
                            txtNhapLaiMatKhau.Focus();
                        }
                        else
                        {
                            newUser.Password = Commons.En_Decrypt.Encrypt(txtMatKhau.Text);
                            if (string.IsNullOrEmpty(txtTenHienThi.Text.Trim()))
                            {
                                erpThemTaiKhoan.SetError(txtTenHienThi, "Vui lòng điền trường này!");
                                txtTenHienThi.Focus();
                            }
                            else
                            {
                                newUser.DisplayName = txtTenHienThi.Text;
                                if (dtpNgaySinh.Value == null)
                                {
                                    erpThemTaiKhoan.SetError(dtpNgaySinh, "Vui lòng điền trường này!");
                                    dtpNgaySinh.Focus();
                                }
                                else
                                {
                                    newUser.DateOfBirth = dtpNgaySinh.Value;
                                    if (!rdoNam.Checked && !rdoNu.Checked)
                                    {
                                        erpThemTaiKhoan.SetError(rdoNam, "Vui lòng điền trường này!");
                                        erpThemTaiKhoan.SetError(rdoNu, "Vui lòng điền trường này!");
                                        rdoNam.Focus();
                                    }
                                    else
                                    {
                                        newUser.Gender = rdoNam.Checked;
                                        if (string.IsNullOrEmpty(txtSoDienThoai.Text.Trim()))
                                        {
                                            erpThemTaiKhoan.SetError(txtSoDienThoai, "Vui lòng điền trường này!");
                                            txtSoDienThoai.Focus();
                                        }
                                        else
                                        {
                                            newUser.Phone = txtSoDienThoai.Text;
                                            if (string.IsNullOrEmpty(txtEmail.Text.Trim()))
                                            {
                                                erpThemTaiKhoan.SetError(txtEmail, "Vui lòng điền trường này!");
                                                txtEmail.Focus();
                                            }
                                            else
                                            {
                                                Regex mRegxExpression;
                                                mRegxExpression = new Regex(@"^([a-zA-Z0-9_\-])([a-zA-Z0-9_\-\.]*)@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$");
                                                if (!mRegxExpression.IsMatch(txtEmail.Text.Trim()))
                                                {
                                                    erpThemTaiKhoan.SetError(txtEmail, "Địa chỉ email không hợp lệ!");
                                                    txtEmail.Focus();
                                                }
                                                else
                                                {
                                                    newUser.Email = txtEmail.Text.Trim();
                                                    if (string.IsNullOrEmpty(txtDiaChi.Text.Trim()))
                                                    {
                                                        erpThemTaiKhoan.SetError(txtDiaChi, "Vui lòng điền trường này!");
                                                        txtDiaChi.Focus();
                                                    }
                                                    else
                                                    {
                                                        newUser.Address     = txtDiaChi.Text.Trim();
                                                        newUser.CreatedByID = mUser.ID;
                                                        newUser.CreatedDate = DateTime.Now;
                                                        User result = new UserLDM().Insert(newUser);
                                                        if (result != null)
                                                        {
                                                            MessageBox.Show("Thêm tài khoản thành công!");
                                                            ThemKhachHang mThemKhachHang = new ThemKhachHang(mUser, result.ID);
                                                            mThemKhachHang.Show();
                                                        }
                                                        else
                                                        {
                                                            MessageBox.Show("Thêm tài khoản thất bại!");
                                                        }
                                                        this.Close();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }