Example #1
0
        private void frm_ThongTin_Load(object sender, EventArgs e)
        {
            _loginTaiKhoan = getDataChangePasswordFormFromMainForm();
            NhanVienDto _nvDTO = new NhanVienDto();
            NhanVienBus _nvBUS = new NhanVienBus();

            _nvDTO              = _nvBUS.ReadStaff(_loginTaiKhoan.MaNhanVien);
            txt_HoTen.Text      = _nvDTO.TenNhanVien;
            txt_MaNhanVien.Text = _nvDTO.MaNV.ToString();
            txt_ChucVu.Text     = _nvDTO.ChucVu.ToString();
            txt_NgaySinh.Text   = _nvDTO.NgaySinh.ToString("dd/MM/yyyy hh:mm:ss");
            txt_Email.Text      = _nvDTO.Email;
            txt_DiaChi.Text     = _nvDTO.DiaChi;
        }
Example #2
0
        private void Login()
        {
            string l_UserName  = txt_UserName.Text.Trim();
            string en_Password = string.Empty;

            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.userName) && Properties.Settings.Default.passWord == txt_Password.Text)
            {
                en_Password = Extensions.DecryptMD5(Properties.Settings.Default.passWord, true);
            }
            string l_Password = string.IsNullOrEmpty(en_Password) ? Extensions.EncryptMD5(txt_Password.Text, true).Trim(): Extensions.EncryptMD5(en_Password, true).Trim();

            if (string.IsNullOrEmpty(l_UserName) || string.IsNullOrEmpty(l_Password))
            {
                DialogResult dialogResult = MessageBox.Show("Tên đăng nhập hoặc mật khẩu không được trống!!!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (dialogResult == DialogResult.OK)
                {
                    if (string.IsNullOrEmpty(l_UserName))
                    {
                        txt_UserName.Focus();
                    }
                    if (string.IsNullOrEmpty(l_Password))
                    {
                        txt_Password.Focus();
                    }
                    if (string.IsNullOrEmpty(l_UserName) && string.IsNullOrEmpty(l_Password))
                    {
                        txt_UserName.Focus();
                    }
                }
            }
            else
            {
                try
                {
                    TaiKhoanBus _tk    = new TaiKhoanBus();
                    var         _login = _tk.Login(l_UserName, l_Password);
                    if (_login == null)
                    {
                        DialogResult dialogResult = MessageBox.Show("Không lấy được thông tin đăng nhập!!!", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                        if (dialogResult == DialogResult.Yes)
                        {
                            if (string.IsNullOrEmpty(l_UserName))
                            {
                                txt_UserName.Focus();
                            }
                            if (string.IsNullOrEmpty(l_Password))
                            {
                                txt_Password.Focus();
                            }
                            if (string.IsNullOrEmpty(l_UserName) && string.IsNullOrEmpty(l_Password))
                            {
                                txt_UserName.Focus();
                            }
                        }
                        else if (dialogResult == DialogResult.No)
                        {
                            Application.Exit();
                        }
                    }
                    else
                    {
                        _tkDto = _login;
                        NhanVienDto _nvDTO = new NhanVienDto();
                        NhanVienBus _nvBUS = new NhanVienBus();
                        _nvDTO = _nvBUS.ReadStaff(_tkDto.MaNhanVien);
                        if (_nvDTO != null)
                        {
                            if (!_nvDTO.DoiMatKhau)
                            {
                                DialogResult dialogResult = MessageBox.Show("Vui lòng đổi mật khẩu cho lần đầu tiên đăng nhập", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                                if (dialogResult == DialogResult.Yes)
                                {
                                    this.Hide();
                                    frm_DoiMatKhau_HeThong _frmChangPass = new frm_DoiMatKhau_HeThong();
                                    _frmChangPass.getDataChangePasswordFormFromLoginForm += delegate { return(_login); };//set data from login form
                                    _frmChangPass.Show();
                                }
                                else if (dialogResult == DialogResult.No)
                                {
                                    Application.Exit();
                                }
                            }
                            else
                            {
                                this.Hide();
                                if (chkRememberUser.Checked)
                                {
                                    if (Properties.Settings.Default.userName != string.Empty)
                                    {
                                        Properties.Settings.Default.Upgrade();
                                        Properties.Settings.Default.userName = l_UserName;
                                        Properties.Settings.Default.passWord = l_Password;
                                        Properties.Settings.Default.is_Check = chkRememberUser.Checked;
                                        Properties.Settings.Default.Save();
                                    }
                                    else
                                    {
                                        Properties.Settings.Default.userName = l_UserName;
                                        Properties.Settings.Default.passWord = l_Password;
                                        Properties.Settings.Default.is_Check = chkRememberUser.Checked;
                                        Properties.Settings.Default.Save();
                                    }
                                }
                                else
                                {
                                    Properties.Settings.Default.Reset();
                                    Properties.Settings.Default.Save();
                                }
                                frm_main _frmMain = new frm_main();
                                _frmMain.accountLoginOrchangePasswordDelegate += delegate { return(_login); };//Set data from form login
                                _frmMain.Show();
                            }
                        }
                        else
                        {
                            DialogResult dialogResult = MessageBox.Show("Vui lòng kiểm tra trạng thái nhân viên", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                            if (dialogResult == DialogResult.Yes)
                            {
                                if (string.IsNullOrEmpty(l_UserName))
                                {
                                    txt_UserName.Focus();
                                }
                                if (string.IsNullOrEmpty(l_Password))
                                {
                                    txt_Password.Focus();
                                }
                                if (string.IsNullOrEmpty(l_UserName) && string.IsNullOrEmpty(l_Password))
                                {
                                    txt_UserName.Focus();
                                }
                            }
                            else if (dialogResult == DialogResult.No)
                            {
                                Application.Exit();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteLogError("Login Login", ex.ToString());
                    DialogResult dialogResult = MessageBox.Show("Vui lòng kiểm tra trạng thái nhận viên", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }
        }