private void loadLastUser() { userProfile.user.name = files.loadCurrentUsername (); // No user data exists. Load a sample guest profile. if (String.IsNullOrEmpty (userProfile.user.name)) { userProfile = GUEST_PROFILE; editProfileMenuItem.Enabled = false; } else { files.updateCurrentUser (userProfile.user.name); userProfile = files.loadUserProfile (); } }
/* * Fill the List with newly generated facts if no known facts exist; * otherwise, fill with unknown facts. */ void generateFactsList(ref FactsQueue facts, MathOperation oper, UserProfile userProfile) { FactsList mathFactsList = new FactsList (); // Determine whether to read previously generated facts or generate new facts. if ((System.IO.File.Exists (FactsFiles.getDailyFactsFilename (oper.operationType, false)))) { readUnknownFactsFromFile (ref mathFactsList, oper); } else { generateAndStoreNewFacts (ref mathFactsList, oper, userProfile); } // Determine the number of facts and obtain a set of random numbers for displaying of the facts if (mathFactsList != null) { randomizeFacts (ref facts, mathFactsList); } }
public void changeUser() { ChangeUserDialog changeUserDialog = new ChangeUserDialog (); changeUserDialog.setUserChoices (FactsFiles.loadUsers ()); if (changeUserDialog.ShowDialog () == DialogResult.OK) { String selectedUser = changeUserDialog.getSelectedUser (); if (selectedUser == "<New User>") { createNewUserProfile (); } else { files.updateCurrentUser (selectedUser); userProfile = files.loadUserProfile (); } m_mainMenuControl.setUserButtonText ("Welcome " + userProfile.user.name + "!" + "\nNot " + userProfile.user.name + "?\nClick Here to Change Users."); } if (!userProfile.Equals(GUEST_PROFILE)) { editProfileMenuItem.Enabled = true; } if (changeUserDialog != null) { changeUserDialog.Dispose (); } }
/* * Generate and stores the facts. */ static void generateAndStoreNewFacts(ref FactsList factsList, MathOperation operation, UserProfile userProfile) { Fact newFact; newFact.operation = operation; MathOperationTypeEnum operationType = operation.operationType; // Generate facts starting from 0 to the max number. for (int i = 0; i <= userProfile.maxFactNumbers[System.Convert.ToInt16 (operation.operationType)]; ++i) { for (int j = 0; j <= userProfile.maxFactNumbers[System.Convert.ToInt16 (operation.operationType)]; ++j) { if (operationType == MathOperationTypeEnum.ADDITION || operationType == MathOperationTypeEnum.MULTIPLICATION) { newFact.leftNum = i; newFact.rightNum = j; factsList.Add (newFact); } // Don't allow division by 0 or results with remainders for division facts. else if (i >= j && (operationType == MathOperationTypeEnum.SUBTRACTION || (operationType == MathOperationTypeEnum.DIVISION && j != 0 && (i % j == 0)))) { newFact.leftNum = i; newFact.rightNum = j; factsList.Add (newFact); } } } }
/* * Handles starting the daily facts and speed test. */ public void startProcessingFacts(bool speedTest, MathOperation operation, FactsDisplayControl displayControl, bool processingAllDailyFacts, UserProfile userProfile) { MathOperationTypeEnum opType = MathFactsForm.operationType.operationType; // Suppress messages if all daily facts are being processed. if (!MathFactsForm.speedTest && !getSavedResponseTime (opType, factResponseTime, ref maxResponseTime)) { if (!processingAllDailyFacts) { // No saved response data was found for this fact type. MathFactsForm.toggleInputDisplay (); String operatorName = MathFactsForm.operationType.ToString (); MathFactsForm.m_factsDisplayControl.messageLabel.Text = "No data could be found for " + operatorName + " facts.\n" + "Please take the " + operatorName + " speed test first.\n" + MathFactsForm.COMPLETION_CONTINUE_PROMPT; return; } } correctResponseCount = 0; numberOfFactsProcessed = 0; if (!speedTest) { generateFactsList (ref queueOfFacts, operation, userProfile); } else { if (userProfile.hasCustomSpeedFacts) { randomizeFacts (ref queueOfFacts, FactsFiles.loadCustomSpeedFacts (operation)); } else { randomizeFacts (ref queueOfFacts, FactsFiles.loadDefaultSpeedFacts (operation)); } } if (queueOfFacts.Count () == 0) { if (!processingAllDailyFacts) { MathFactsForm.toggleInputDisplay (); displayControl.messageLabel.Text = "You have mastered all the facts, there are none to practice!\n" + MathFactsForm.COMPLETION_CONTINUE_PROMPT; } } else { // Set up the progress bar. FactsDisplayControl reference = FactsDisplayControl.Instance; reference.factsProgressBar.Maximum = queueOfFacts.Count (); reference.factsProgressBar.Increment (1); // Display the first fact. displayControl.factSignLabel.Text = operation.getOperationSign (); displayControl.num1Label.Text = System.Convert.ToString (queueOfFacts.First ().leftNum); displayControl.num2Label.Text = System.Convert.ToString (queueOfFacts.First ().rightNum); displayControl.inputMaskedTextBox.Focus (); MathFactsForm.timer = System.Diagnostics.Stopwatch.StartNew (); } }
public void updateUserProfile(UserProfile profile) { try { using (System.IO.StreamWriter file = new System.IO.StreamWriter (userFilename)) { file.WriteLine (profile.user.name); for (int index = 0; index < profile.maxFactNumbers.Count (); ++index) { file.WriteLine (profile.maxFactNumbers[index]); } file.WriteLine (profile.hasCustomSpeedFacts.ToString()); file.WriteLine (profile.maxDaysBetweenSpeedTests); } } catch (Exception e) { Console.WriteLine (e); } }
/* * Creates files and directories for a new user. */ public void createNewUserDirectory(UserProfile newUserProfile) { // Create the individual user directories. userPath = System.IO.Path.Combine (usersPath, newUserProfile.user.name); paths.Add (userPath); // Create the individual user subdirectories. dailyFactsPath = System.IO.Path.Combine (userPath, "dailyFactsData"); paths.Add (dailyFactsPath); unknownFactsPath = System.IO.Path.Combine (userPath, "unknownFacts"); paths.Add (unknownFactsPath); knownFactsPath = System.IO.Path.Combine (userPath, "knownFacts"); paths.Add (knownFactsPath); speedTestPath = System.IO.Path.Combine (userPath, "speedTest"); paths.Add (speedTestPath); customSpeedTestPath = System.IO.Path.Combine (speedTestPath, "custom"); // Create the individual user files. dailyAdditionFactsData = System.IO.Path.Combine (dailyFactsPath, ADDITION); dailySubtractionFactsData = System.IO.Path.Combine (dailyFactsPath, SUBTRACTION); dailyMultiplicationFactsData = System.IO.Path.Combine (dailyFactsPath, MULTIPLICATION); dailyDivisionFactsData = System.IO.Path.Combine (dailyFactsPath, DIVISION); files.Add (dailyAdditionFactsData); files.Add (dailySubtractionFactsData); files.Add (dailyMultiplicationFactsData); files.Add (dailyDivisionFactsData); userFilename = System.IO.Path.Combine (userPath, USER__PROFILE); files.Add (userFilename); speedAdditionFactsDataFilename = System.IO.Path.Combine (speedTestPath, ADDITION); speedSubtractionFactsDataFilename = System.IO.Path.Combine (speedTestPath, SUBTRACTION); speedMultiplicationFactsDataFilename = System.IO.Path.Combine (speedTestPath, MULTIPLICATION); speedDivisionFactsDataFilename = System.IO.Path.Combine (speedTestPath, DIVISION); files.Add (speedAdditionFactsDataFilename); files.Add (speedSubtractionFactsDataFilename); files.Add (speedMultiplicationFactsDataFilename); files.Add (speedDivisionFactsDataFilename); createFilesAndDirectories (); updateUsersData (newUserProfile.user.name); }
private void saveNewProfile() { String username = usernameMaskedTextBox.Text; UserProfile newUserProfile = new UserProfile (new User ()); bool fieldProcessed; newUserProfile.user.name = processUsernameField (out fieldProcessed); if (!fieldProcessed) { return; } newUserProfile.hasCustomSpeedFacts = customFactsCheckBox.Checked; newUserProfile.maxDaysBetweenSpeedTests = processMaxDaysBetweenSpeedTestField (out fieldProcessed); if (!fieldProcessed) { return; } newUserProfile.maxFactNumbers = processMaxFactNumberFields (out fieldProcessed, true); if (!fieldProcessed) { return; } if (passwordTextBox != passwordConfirmTextBox) { if (!processNewPassword (newUserProfile.user.name)) { return; } } else { MessageBox.Show ("The passwords you entered do not match.", "Passwords Do Not Match", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Valid data was entered. MathFactsForm.userProfile = newUserProfile; files.createNewUserDirectory (newUserProfile); files.updateUserProfile (newUserProfile); MessageBox.Show ("Your profile has been successfully created!", "Profile Created", MessageBoxButtons.OK, MessageBoxIcon.None); this.Close (); }