/// <summary> /// Event handler for BackButton. Returns to previous UI /// </summary> private void BackButton_Click(object sender, EventArgs e) { var chooseProfile = new ChooseProfileInterface(); chooseProfile.Show(); this.Close(); }
/// <summary> /// Validates user input and logs in if correct /// </summary> private void LoginButton_Click(object sender, EventArgs e) { //Pulls user input string emailInput = emailTextBox.Text; string passwordInput = passwordTextBox.Text; //True if user input match DB bool isMatch = false; //Displays error message if no input in one or more textbox if (string.IsNullOrEmpty(emailInput) || string.IsNullOrEmpty(passwordInput)) { MessageBox.Show("Please enter your E-mail and password.", "Error"); return; } //Creates query that selects email and password from DB string loginQuery = "SELECT email, password FROM dbo.parent"; SqlCommand command = new SqlCommand(loginQuery, Functions.DatabaseFunctions.DatabaseConnection); //Executes the query Functions.DatabaseFunctions.DatabaseConnection.Open(); SqlDataReader reader = command.ExecuteReader(); //Reads loaded data from DB while (reader.Read()) { //Sets email and password from DB string email = reader["email"].ToString(); string password = reader["password"].ToString(); //Checks if input matches DB and sets isMatch to true if so if (emailInput == email && passwordInput == password) { isMatch = true; } //Displays error message if no match else { MessageBox.Show("Incorrect password or E-mail entered.", "Error"); Functions.DatabaseFunctions.DatabaseConnection.Close(); return; } } //If user input and DB match proceeds to ChooseProfileInterface if (isMatch == true) { Functions.DatabaseFunctions.DatabaseConnection.Close(); var chooseProfileUI = new ChooseProfileInterface(); chooseProfileUI.Show(); this.Hide(); } }