public bool Login(User user) { try { User aUser = dataContext.Users.SingleOrDefault( u => u.UserName.Equals(user.UserName) && u.Password.Equals(user.Password)); if (aUser != null) { return true; } return false; } catch (Exception exception) { throw new Exception(exception.Message); } }
private void btnOK_Click(object sender, EventArgs e) { if (txtUserName.Text == "") { MessageBox.Show("Please enter user name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtUserName.Focus(); return; } if (txtPassword.Text == "") { MessageBox.Show("Please enter password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPassword.Focus(); return; } try { User user = new User() { UserName = txtUserName.Text, Password = txtPassword.Text }; if (userGateway.Login(user)) { DialogResult = DialogResult.OK; } else { MessageBox.Show("Login is Failed...Try again !", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error); txtUserName.Clear(); txtPassword.Clear(); txtUserName.Focus(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }