//go back to the login screen private void btnBack_Click(object sender, EventArgs e) { Login login = new Login(); login.Show(); this.Hide(); }
private void btnOK_Click(object sender, EventArgs e) { if (txtFirstName.Text == "") //validating that information has been entered into the text boxes. { MessageBox.Show("Please enter first name"); this.txtFirstName.Focus(); return; } if (txtLastName.Text == "") { MessageBox.Show("Please enter last name"); this.txtLastName.Focus(); return; } if (txtUsername.Text == "") { MessageBox.Show("Please enter user name"); this.txtUsername.Focus(); return; } if (txtPassword.Text == "") { MessageBox.Show("Please enter password"); this.txtPassword.Focus(); return; } Boolean approved = false; //bool for approval of validation u = txtUsername.Text; p = txtPassword.Text; firstname = txtFirstName.Text; lastname = txtLastName.Text; approved = UserValidate.validate(u,p); //send to u and p to UserValidate to validate that it is in the correct format try { if (approved == true) //once approved, the username is queryed against the database to see if there is another user with the same name { var queryIsUsernameTaken = from users in context.users where users.username == u select u; string usernameIsTaken = Convert.ToString(queryIsUsernameTaken); if (!usernameIsTaken.Equals(u,StringComparison.OrdinalIgnoreCase))//if statement condition that name is not taken { this.addNewUserInformation(); //use the addNewUserInformation method MessageBox.Show("Your information has been entered in the database, you will be re-routed to the login screen.","ScoreTrend"); Login login = new Login(); //create new login object and view login GUI login.Show(); this.Hide(); } else { //Message box to tell the username has been used and if they would like to go back to the login screen if (MessageBox.Show(u + " is already been used, please select another username. Would you like to go back to login screen?", "", MessageBoxButtons.YesNo) == DialogResult.Yes) ; { Login login = new Login(); login.Show(); this.Hide(); } txtUsername.Clear(); txtPassword.Clear(); txtUsername.Focus(); } } else { MessageBox.Show("Usernames and Passwords must be a length of 8 to 20 aplhanumeric characters. The password cannot start with a digit, underscore or special character and must contain at least one digit."); txtUsername.Clear(); } } catch (Exception ex) { MessageBox.Show("Cannot communicate with database. Application will now close." + ex.Message); Application.Exit(); } }