/* * Starts the chosen daily facts or speed test */ public void startTheFacts(MathOperationTypeEnum sign, Boolean isSpeedTest, Boolean processAllDailyFacts) { operationType = new MathOperation (sign); if (userProfile.Equals (GUEST_PROFILE)) { var confirmResult = MessageBox.Show ("Would you like to create a profile before continuing?\nA profile is required for your progress to be saved.", "Confirm Cancel", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { createNewUserProfile (); } } // Determine if the user has already used the daily facts today. String dateData = files.readDailyFactsDateDataFromFile(operationType.operationType); if (dateData == "MAX_TIME_ELAPSED") { MessageBox.Show ("A month or more has passed since your last speed test.\nPlease retake the " + operationType.ToString () + "Facts speed test.", "New Speed Test Needed"); return; } else if (dateData == DateTime.Today.ToString ("d")) { saveProgress = false; var continueWithoutSavingResponse = MessageBox.Show ("Oops! It looks like you have already practiced your " + operationType.ToString () + " facts today.\nYou can practice them again, but your progress will not be saved.\n\n Continue anyway?", "Progress Will Not Be Saved", MessageBoxButtons.YesNo); if (continueWithoutSavingResponse == DialogResult.No) { return; } } else { saveProgress = true; } speedTest = isSpeedTest; processingAllDailyFacts = processAllDailyFacts; if (!processingAllDailyFacts) { toggleMainMenuControl (); toggleFactsDisplayControl (); } // Change the bool value so the last set of messages for all daily facts are not suppressed. else if (operationType.operationType == MathOperationTypeEnum.DIVISION) { processingAllDailyFacts = !processingAllDailyFacts; } // Initialize and reset data structures for holding facts data incorrectResponses = new Stack <int> (); reference.unknownFacts.Clear (); reference.knownFacts.Clear (); reference.correctResponseCount = 0; reference.factResponseTime.Clear (); reference.factsOrder.Clear (); incorrectResponses.Clear (); factsReviewControl.incorrectQuestions.Clear (); reference.startProcessingFacts (speedTest, operationType, m_factsDisplayControl, processingAllDailyFacts, userProfile); }
public static List<Fact> loadCustomSpeedFacts(MathOperation operation) { List<Fact> speedFactsList = new List<Fact> (); Fact speedFact = new Fact (); speedFact.operation = operation; String speedFactsFilename = System.IO.Path.Combine (speedTestPath, operation.ToString () + ".txt"); using (System.IO.StreamReader file = new System.IO.StreamReader (speedFactsFilename)) { String speedFactNumber; while ((speedFactNumber = file.ReadLine ()) != null) { speedFact.leftNum = System.Convert.ToInt32 (speedFactNumber); if ((speedFactNumber = file.ReadLine ()) != null) { speedFact.rightNum = System.Convert.ToInt32 (speedFactNumber); speedFactsList.Add (speedFact); } } } return speedFactsList; }
public void saveCustomSpeedFacts(MathOperation operation, List<Fact> speedFacts) { String speedFactsFilename = System.IO.Path.Combine (speedTestPath, operation.ToString () + ".txt"); using (System.IO.StreamWriter file = new System.IO.StreamWriter (speedFactsFilename)) { foreach (Fact speedFact in speedFacts) { file.WriteLine (speedFact.leftNum); file.WriteLine (speedFact.rightNum); } } }
private void editSpeedFactsButton_MouseClick(object sender, MouseEventArgs e) { if (speedTestComboBox.Text == "") { MessageBox.Show ("You didn't select the type of speed test facts.\nPlease select the fact type before continuing.", "No Speed Test Chosen", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MathOperation operation = new MathOperation ((MathOperationTypeEnum) Enum.Parse (typeof (MathOperationTypeEnum), speedTestComboBox.Text, true)); SpeedFactEditDialog speedFactEditDialog = new SpeedFactEditDialog (); speedFactEditDialog.Text = operation.ToString () + speedFactEditDialog.Text; DataGridView speedFactDataGridView = speedFactEditDialog.speedFactsDataGridView; List<Fact> speedFacts; if ((speedFacts = FactsFiles.loadCustomSpeedFacts (operation)).Count () == 0) { // Load the default speed fact data for creation of the speed facts. speedFacts = FactsFiles.loadDefaultSpeedFacts (operation); } // Load the current speed facts. for (int index = 0; index < speedFacts.Count (); ++index) { speedFactDataGridView.Rows.Add (speedFacts[index].leftNum, speedFacts[index].rightNum); } // Update the current selected cell to a new row. speedFactDataGridView.CurrentCell = speedFactDataGridView.Rows[speedFactDataGridView.Rows.Count - 1].Cells[0]; if (speedFactEditDialog.ShowDialog () == DialogResult.OK) { speedFacts.Clear (); String topNumber; String bottomNumber; DataGridViewCell cell1; DataGridViewCell cell2; for (int rowIndex = 0; rowIndex < speedFactDataGridView.RowCount; ++rowIndex) { try { cell1 = speedFactDataGridView[rowIndex, 0]; cell2 = speedFactDataGridView[rowIndex, 1]; // TODO prompt to re-enter row with invalid input topNumber = cell1.Value.ToString (); bottomNumber = cell2.Value.ToString (); speedFacts.Add (new Fact (System.Convert.ToInt16 (topNumber), System.Convert.ToInt16 (bottomNumber), operation)); } catch (Exception exception) { if (exception is System.FormatException || exception is System.ArgumentOutOfRangeException || exception is System.NullReferenceException) { // Do nothing. No data entered in this row. } else { throw; } } } if (speedFacts.Count () < 4) { MessageBox.Show ("At least 4 speed facts are recommended.\nHaving less than 4 will affect the accuracy of determining the daily facts.\nPlease consider revising and adding more facts.", "Add More Speed Facts", MessageBoxButtons.OK, MessageBoxIcon.Warning); } files.saveCustomSpeedFacts (operation, speedFacts); } if (speedFactEditDialog != null) { speedFactEditDialog.Dispose (); } }