private void LoginButton_Click(object sender, EventArgs e) { //check username and password is empty or not if (string.IsNullOrEmpty(UserNameTextBox.Text) || string.IsNullOrEmpty(PasswordTextBox.Text)) { if (string.IsNullOrEmpty(UserNameTextBox.Text)) { UserNameTextBox.Focus(); errorProvider1.SetError(UserNameTextBox, "Please enter username"); }//end of string.IsNullOrEmpty(UserNameTextBox.Text)) else { PasswordTextBox.Focus(); errorProvider1.SetError(PasswordTextBox, "Please enter password"); }////end of settinng password text box error } else { LoginDal logInDataAccess = new LoginDal(); // created an object to invoke the login data access connection in the DAL. Login _loginDetails = new Login { UserName = UserNameTextBox.Text, PassWord = PasswordTextBox.Text }; int recordsCount = logInDataAccess.GetuserDetails(_loginDetails); //this statement acts multipurpose 1)recordsCount acts as variable for checking number of rows retrived 2) for validating the entered user details if (recordsCount > 0) // when the username and password matches one row will be retrived from the database so count is > 0 { this.Hide(); AdminMenuForm menuFm = new AdminMenuForm(); menuFm.Closed += (s, args) => this.Close(); // if username and password matches by using delegate property the current form will be hidden and admin menu form is shown. menuFm.Show(); } else { ErrorMessagelabel.Visible = true; //MessageBox.Show("Please enter Correct Username and Password"); // errorProvider1.SetError(UserNameTextBox, "User Name is Invaldi"); } } }