private void btnLogin_Click(object sender, EventArgs e) { try { //logger.Info("btnLogin_Click"); if (Validate()) { var objUserInfo = new UserInfo { UserName = txtUsername.Text.Trim(), Password = txtPassword.Text.Trim() }; var userInfo = _userBOL.GetUser(objUserInfo); if (userInfo != null) // Login sucessfully { // Redirect to the main form var mainForm = new frmMainForm(userInfo); mainForm.WindowState = FormWindowState.Maximized; mainForm.Show(); this.Hide(); } else { MessageBox.Show(ConstantInfo.MESSAGE_LOGIN_FAIL, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { logger.Error(ex.ToString()); if (GlobalInfo.IsDebug) MessageBox.Show(ex.ToString()); } }
/// <summary> /// Logins this instance. /// </summary> private void Login() { try { //logger.Info("btnLogin_Click"); if (Validate()) { var objTblUer = new tblUser(); objTblUer.UserName = txtUsername.Text.Trim(); objTblUer.Password = txtPassword.Text.Trim(); var userInfoNew = UserFactory.GetUserInfo(objTblUer); if (userInfoNew != null && !userInfoNew.UserName.Equals(string.Empty)) // Login sucessfully { // Bind UserInfo var userInfo = new UserInfo(); userInfo.UserName = userInfoNew.UserName; userInfo.Name = userInfoNew.Name; userInfo.Password = userInfoNew.Password; userInfo.UserID = userInfoNew.UserID; //get all User's permission userInfo.UserPermission = UserGroupPermissionFactory.GetAllPermissionOfUser(userInfo.UserID); //if user is admin, set all permission for admin if (userInfo.UserName == "admin") { userInfo.UserPermission = UserGroupPermissionFactory.GetAllPermissionForAdmin(); } // Redirect to the main form var mainForm = new frmMainForm(userInfo); mainForm.WindowState = FormWindowState.Maximized; mainForm.Show(); this.Hide(); } else { MessageBox.Show(ConstantInfo.MESSAGE_LOGIN_FAIL, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { logger.Error(ex.ToString()); if (GlobalInfo.IsDebug) MessageBox.Show(ex.ToString()); } }
private void txtUsername_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) // Enter key { if (Validate()) { var objUserInfo = new UserInfo { UserName = txtUsername.Text.Trim(), Password = txtPassword.Text.Trim() }; var userInfo = _userBOL.GetUser(objUserInfo); if (userInfo != null) // Login sucessfully { // Redirect to the main form var mainForm = new frmMainForm(userInfo); mainForm.WindowState = FormWindowState.Maximized; mainForm.Show(); this.Hide(); } else { MessageBox.Show(ConstantInfo.MESSAGE_LOGIN_FAIL, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }