// When the Reset Passwors Button is clicked private void ResetPasswordButton_Click(object sender, EventArgs e) { // Validation if (PasswordETF.Text.Equals("")) // If no username has been entered { MessageBox.Show("Please enter a Password"); // Show a message box describing the error return; // Stop this method } else if (ReEnterPasswordETF.Text.Equals("")) // If no username has been entered { MessageBox.Show("Please Reenter the Password"); // Show a message box describing the error return; // Stop this method } if (!PasswordETF.Text.Equals(ReEnterPasswordETF.Text)) { // If the passwords entered do not match MessageBox.Show("Passwords to not match. Please try again."); // Show a messagebox displaying the error message return; // Stop the method } UserDatabase userDB = new UserDatabase(); // Create a new instance of a User Database. This can be read from and written to a file userDB.ChangeUserPassword(username, PasswordETF.Text); // Change the User's password (Details have been verified in the 'Start Display') userDB.SaveDatabase(); // Save the Database to a file this.Close(); // Close this form now that the password has been reset }
private void ResetPasswordButton_Click(object sender, EventArgs e) { if(!PasswordETF.Text.Equals(ReEnterPasswordETF.Text)){ MessageBox.Show("Passwords to not match. Please try again."); return; } UserDatabase userDB = new UserDatabase(); userDB.ChangeUserPassword(username, PasswordETF.Text); userDB.SaveDatabase(); }
private void CompleteRegistrationButton_Click(object sender, EventArgs e) { if (UsernameETF.Text.Equals("")) { MessageBox.Show("Please enter a Username"); return; } else if (PasswordETF.Text.Equals("")) { MessageBox.Show("Please enter a Password"); return; } else if (ReenterPasswordETF.Text.Equals("")) { MessageBox.Show("Please enter a Reentered Password"); return; } if (!PasswordETF.Text.Equals(ReenterPasswordETF.Text)) { MessageBox.Show("Passwords do not match"); return; } UserDatabase userDB = new UserDatabase(); try { userDB.AddUser(UsernameETF.Text, PasswordETF.Text); userDB.setUserForgotPassword(UsernameETF.Text, ForgotPasswordQuestionETF.Text, ForgotPasswordAnswerETF.Text); } catch (Exception exception) { MessageBox.Show(exception.ToString()); return; } userDB.OutputDatabaseContents(); userDB.SaveDatabase(); ClearTextFields(); }
private void SettingsSave_Click(object sender, EventArgs e) { questionEntryBox1.SaveAllQuestions(); UserDatabase userDB = new UserDatabase(); userDB.SetUserQuestionButtonState(username, SettingsBiologyT1.Enabled, SettingsOtherSubjectT1.Enabled, SettingsOtherSubjectT1.Text.Substring(0, SettingsOtherSubjectT1.Text.Length - 7)); userDB.SaveDatabase(); SettingsReturnButton_Click(sender, e); }
public void SaveOnePupilQuestions(string pupilUsername) { StoreDisplay(); // Store the current display UserDatabase userDB = new UserDatabase(); // Create a new instance of a UserDatabase. This can be read from and written to List<TempStoredDisplay> storedDetailsValues = storedDetails[pupilUsername].Values.ToList<TempStoredDisplay>(); // List all of the TempStoredDisplays in the storedDetials Dictionary for (int j = 0; j < storedDetailsValues.Count; j++) // For each display that needs to be saved { TempStoredDisplay tempStoredDisplay = storedDetailsValues[j]; // get the current display that we are saving if (tempStoredDisplay.questions.Count == 0) // If there are no questions in this display { continue; // Skip this display } string[][] questionDetails = new string[4][]; // Create a multi-dimensional array to format the display questionDetails[0] = new string[tempStoredDisplay.questions.Count]; // Set the size of each array in the multi-dimensional array to the number of questions questionDetails[1] = new string[tempStoredDisplay.questions.Count]; questionDetails[2] = new string[tempStoredDisplay.questions.Count]; questionDetails[3] = new string[tempStoredDisplay.questions.Count]; for (int i = 0; i < tempStoredDisplay.questions.Count; i++) // For each question in this display { questionDetails[0][i] = tempStoredDisplay.questions[i].Text; // Add the question to the stored details questionDetails[1][i] = tempStoredDisplay.correctAnswers[i].Text; // Add the correct answer to the stored details questionDetails[2][i] = tempStoredDisplay.wrongAnswers1[i].Text; // Add the wrong answer 1 to the stored details questionDetails[3][i] = tempStoredDisplay.wrongAnswers2[i].Text; // Add the wrong answer 2 to the stored details } userDB.ClearQuestionSet(pupilUsername, storedDetails[pupilUsername].Keys.ToList<string>()[j]); // Clear the question set that we are about to fill userDB.FillQuestionSet(pupilUsername, storedDetails[pupilUsername].Keys.ToList<string>()[j], questionDetails[0], questionDetails[1], questionDetails[2], questionDetails[3]); // Fill the question set with our formatted details } userDB.SaveDatabase(); // Save the database as a file }
// When the Save Settings button has been clicked private void SettingsSave_Click(object sender, EventArgs e) { SettingsQuestionEntryBox.SaveAllQuestions(); // Save all questions held by the SettingsQuestionEntryBox UserDatabase userDB = new UserDatabase(); // Create a new instance of a User Database to save the buttons state userDB.SetUserQuestionButtonState(username, SettingsBiologyT1.Enabled, SettingsOtherSubjectT1.Enabled, SettingsOtherSubjectT1.Text.Substring(0, SettingsOtherSubjectT1.Text.Length - 7)); // Update the button state in the new User Database userDB.SaveDatabase(); // Save the Database OtherSubjectT1Button.Text = SettingsOtherSubjectT1.Text; // Update the text of the Other Subject buttons to contain the chosen subject name OtherSubjectT2Button.Text = SettingsOtherSubjectT2.Text; OtherSubjectT3Button.Text = SettingsOtherSubjectT3.Text; SettingsReturnButton_Click(sender, e); // Return from the settings view by calling the functions used when the user clicks on the return button on the settings page }
// Used to complete the game public void CompleteGame() { AirTimer.Stop(); // Stop all timers WaterTimer.Stop(); FoodTimer.Stop(); SecondTimer.Stop(); GameCompletedForm gameCompletedForm = new GameCompletedForm(); // Create a new instance of a GameCompletedForm gameCompletedForm.Visible = true; // Make this new instance visible this.Visible = false; // Hide the current Form gameCompletedForm.SetTimeLabel(secondsPassed); // Set the time label on the new form gameCompletedForm.SetQuestionLists(problemQuestions, resolvedProblemQuestions); // Set the values of the question lists on the new form gameCompletedForm.SetTotalCorrectAnswers(answersCorrect[0], answersCorrect[1], answersCorrect[2]); // Set the value for total correct answers on the new form gameCompletedForm.SetTotalNumMistakes(answersIncorrect[0], answersIncorrect[1], answersIncorrect[2]); // Set the value for the total number of mistakes on the new form gameCompletedForm.SetProblemQuestionsLabel(problemQuestions.Count); // Set the data for the Problem Questions on the new form gameCompletedForm.SetResolvedQuestionsLabel(resolvedProblemQuestions.Count); // Set the data for the Resolved Questions on the new form UserDatabase userDB = new UserDatabase(); UserDatabase.GameCompletedDetails gameCompletedDetails = new UserDatabase.GameCompletedDetails(); gameCompletedDetails.timeInSeconds = secondsPassed; gameCompletedDetails.numCorrectAnswers = answersCorrect; gameCompletedDetails.numMistakes = answersIncorrect; gameCompletedDetails.problemQuestions = problemQuestions; gameCompletedDetails.resolvedQuestions = resolvedProblemQuestions; userDB.AddGameCompletedDetails(username, gameCompletedDetails); userDB.SaveDatabase(); }
private void SavePupilButton_Click(object sender, EventArgs e) { PupilSettingsQuestionEntryBox.SaveOnePupilQuestions(activePupilUsername); UserDatabase userDB = new UserDatabase(); // Create a new instance of a User Database to save the buttons state userDB.SetUserQuestionButtonState(activePupilUsername, SettingsBiologyT1Button.Enabled, SettingsOtherSubjectT1Button.Enabled, SettingsOtherSubjectT1Button.Text.Substring(0, SettingsOtherSubjectT1Button.Text.Length - 7)); // Update the button state in the new User Database userDB.SaveDatabase(); // Save the Database MessageBox.Show("Details saved for this pupil"); }
private void SaveAllPupilsButton_Click(object sender, EventArgs e) { PupilSettingsQuestionEntryBox.SaveSetForAllPupils(activePupilUsername); UserDatabase userDB = new UserDatabase(); // Create a new instance of a User Database to save the buttons state List<string> usernames = userDB.getUsernames(); foreach (string name in usernames) { userDB.SetUserQuestionButtonState(name, SettingsBiologyT1Button.Enabled, SettingsOtherSubjectT1Button.Enabled, SettingsOtherSubjectT1Button.Text.Substring(0, SettingsOtherSubjectT1Button.Text.Length - 7)); // Update the button state in the new User Database } userDB.SaveDatabase(); MessageBox.Show("Details Saved for all pupils"); }
// When the Complete Registration Button has been clicked private void CompleteRegistrationButton_Click(object sender, EventArgs e) { // Validation if (UsernameETF.Text.Equals("")) // If no username has been entered { MessageBox.Show("Please enter a Username"); // Show a message box describing the error return; // Stop this method } else if (PasswordETF.Text.Equals("")) // If no password has been entered { MessageBox.Show("Please enter a Password"); return; } else if (ReenterPasswordETF.Text.Equals("")) // If the password has not been reentered { MessageBox.Show("Please reenter a Password"); return; } else if (ForgotPasswordQuestionETF.Text.Equals("")) // If the Forgot Password Question has not been entered { MessageBox.Show("Please enter a Question that will be asked when you have forgotten your password."); return; } else if (ForgotPasswordAnswerETF.Text.Equals("")) // If the Forgot Password Question answer has not been entered { MessageBox.Show("Please enter the answer to your Forgot Password Question."); return; } if (!PasswordETF.Text.Equals(ReenterPasswordETF.Text)) // If the password and the Reentered Password do not match { MessageBox.Show("Passwords do not match, please try re-entering them"); return; } //Begin Registering the new user UserDatabase userDB = new UserDatabase(); // Create a new instance of the User Database. This allows reading and writing of the database try { userDB.AddUser(UsernameETF.Text, PasswordETF.Text); // Attempt to add the new user to the database. Duplicate usernames will be detected here userDB.setUserForgotPassword(UsernameETF.Text, ForgotPasswordQuestionETF.Text, ForgotPasswordAnswerETF.Text.ToLower()); // Attempt to give the user a 'Forgot Password Question' and answer } catch (Exception exception) // Catch any exception, and perform the following { MessageBox.Show(exception.Message + ""); // Display a message box describing the error return; // Stop this method } SwitchToLoginView(); RegistrationCompletedLabel.Visible = true; userDB.SaveDatabase(); // Save the database to a file ClearTextFields(); // Clear all of the TextBoxes }