private void QuestionListBox_MouseDoubleClick(object sender, MouseEventArgs e) { //When the user selects a question the question information is displayed over the previous, this code completes that action AnswerHeaderLabel.Show(); QuestionHeaderLabel.Show(); if (QuestionListBox.SelectedItem == null) { } else { //Assigning the selected question to a variable StoredQuestions SelectedQuestion = (StoredQuestions)QuestionListBox.SelectedItem; if (SelectedQuestion.PictureUrl == "" || SelectedQuestion.PictureUrl == null) { QuestionPictureBox.Hide(); } else { QuestionPictureBox.Show(); QuestionPictureBox.Image = Image.FromFile(SelectedQuestion.PictureUrl); } QuestionLabel.Text = SelectedQuestion.Question; AnswerLabel.Text = SelectedQuestion.CorrectAns; } }
private void AddButton_Click(object sender, EventArgs e) { //When the add button is pressed the question must be coppied from the stored questions, to the NewQuiz collection if (QuestionListBox.SelectedItem == null) { return; } else if (NewQuiz.Count() == 15) { //Only 15 questions MAX are allowed per quiz so if they try to add too many the program will display this error MessageBox.Show("Error, Invalid number of items, please select between 3 and 15 questions. Remove items or create multiple quizzes.", "Error", MessageBoxButtons.OK); return; } StoredQuestions SelectedQuestion = (StoredQuestions)QuestionListBox.SelectedItem; //If the quiz already contains the question then this message will display if (NewQuiz.Contains(SelectedQuestion)) { string message = "This question has already been added to the quiz!"; string caption = "Error Detected in Input"; MessageBoxButtons buttons = MessageBoxButtons.OK; MessageBox.Show(message, caption, buttons); return; } //If none of the other criteria have occured it will add the question to the quiz NewQuiz.Add(SelectedQuestion); //Resets the variables QuizListBox.DataSource = null; QuizListBox.DataSource = NewQuiz; QuizListBox.DisplayMember = "Question"; QuestionCapacityProgressBar.Increment(1); }
StoredQuestions CurrentQuestion = new StoredQuestions(); //The current question is stored here public TextQuestionForm(StoredQuestions CQuestions) { InitializeComponent(); CurrentQuestion = CQuestions; //The paramter of the current question is passed into the form QuestionLabel.Text = CurrentQuestion.Question; //The currentquestion`s question is displayed List <string> Answers = new List <string>(); //A new list of answers is created //Each individual answer that is stored in currentquestion including the correct answer and the 3 incorrect ones Answers.Add(CurrentQuestion.CorrectAns); Answers.Add(CurrentQuestion.IncorrectAns1); Answers.Add(CurrentQuestion.IncorrectAns2); Answers.Add(CurrentQuestion.IncorrectAns3); //Answers are shuffled Answers = Answers.OrderBy(x => Guid.NewGuid()).ToList(); //The answers are assigned to the radio buttons AnswerRadioButton1.Text = $"{Answers.ElementAt(0)}"; AnswerRadioButton2.Text = $"{ Answers.ElementAt(1)}"; AnswerRadioButton3.Text = $"{ Answers.ElementAt(2)}"; AnswerRadioButton4.Text = $"{ Answers.ElementAt(3)}"; }
private void RemoveButton_Click(object sender, EventArgs e) { //If no question is selected then the question cannot be removed if (QuizListBox.SelectedItem == null) { return; } //The selected question is saved to a variable StoredQuestions SelectedQuestion = (StoredQuestions)QuizListBox.SelectedItem; //Removes the question from the quiz NewQuiz.Remove(SelectedQuestion); QuizListBox.DataSource = null; QuizListBox.DataSource = NewQuiz; QuizListBox.DisplayMember = "Question"; QuestionCapacityProgressBar.Increment(-1); }
private void StartQuizButton_Click(object sender, EventArgs e) { //Hides the main form this.Hide(); CalculateDifficulty cd = new CalculateDifficulty(); //Claculated difficulty is initilised //Trys to decide which option the user wants. //Adaptive question order: Questions answered incorrectly are presented more often than the correct ones //Standard: Questions are presented normally //If the user hasn`t selected an option a null exception is thrown try { if (SelectModeComboBox.SelectedItem.ToString() == "Adaptive Questions Order") { foreach (CompletedQuestion cq in completedQuestion) { if ((cq.CalculatedDifficulty > 80) && (cq.XCompleted > 5)) { //This removes the question from the quiz so that the user doesn`t answer this question that they have already answered correctly the majority of times storedQuizQuestions.Remove(storedQuizQuestions.Find(x => x.QuestionId == cq.QuestionId)); } } } } catch (System.NullReferenceException) { //The null excpetion is caught and this message is displayed MessageBox.Show("Please Select A Question Mode", "Error", MessageBoxButtons.OK); return; } //The stored quiz question need to be shuffled so this line of code does that List <StoredQuizQuestions> ShuffledQuizQuestions = storedQuizQuestions.OrderBy(x => Guid.NewGuid()).ToList(); foreach (StoredQuizQuestions QuizQuestion in ShuffledQuizQuestions) { StoredQuestions CurrentQuestion = (storedQuestions.Find(x => x.QuestionId == QuizQuestion.QuestionId)); //The current question is saved to the varaible called current question CompletedQuestion CurrentCompletedQuestion = (completedQuestion.Find(x => x.QuestionId == QuizQuestion.QuestionId)); if (CurrentQuestion.PictureUrl == "") //If there is no picture URL then it doesn`t have a picture { var page2 = new TextQuestionForm(CurrentQuestion); //The next form is created page2.Answered += (source, Correct) => //This event is used to return the answer that the user selects and treats it accordingly based upon if the correct bool is true or false { //Question is removed from both storedquestion and completedquestion storedQuestions.Remove(CurrentQuestion); completedQuestion.Remove(CurrentCompletedQuestion); //If the user has ansewred correctly then the current quiz question`s XAnsweredCorrect will increase by one if (Correct == true) { CurrentQuestion.XAnsweredCorrectly++; CurrentCompletedQuestion.XCorrect++; } //Regardless of if the answer was answered correctly the times answered counter must also increment by one CurrentQuestion.XAnswered++; CurrentCompletedQuestion.XCompleted++; //The difficulty rating must be recalculated CurrentQuestion.CalculatedDifficulty = cd.CalcDifficulty(CurrentQuestion.XAnswered, CurrentQuestion.XAnsweredCorrectly); CurrentCompletedQuestion.CalculatedDifficulty = cd.CalcDifficulty(CurrentCompletedQuestion.XCompleted, CurrentCompletedQuestion.XCorrect); //The question is added back to the storedquestion and complted question lists storedQuestions.Add(CurrentQuestion); completedQuestion.Add(CurrentCompletedQuestion); }; //Displays the question answering form page2.ShowDialog(); } else { var page2 = new PictureQuestionForm(CurrentQuestion); page2.Answered += (source, Correct) => { //Question is removed from both storedquestion and completedquestion storedQuestions.Remove(CurrentQuestion); completedQuestion.Remove(CurrentCompletedQuestion); //If the user has ansewred correctly then the current quiz question`s XAnsweredCorrect will increase by one if (Correct == true) { CurrentQuestion.XAnsweredCorrectly++; CurrentCompletedQuestion.XCorrect++; } //Regardless of if the answer was answered correctly the times answered counter must also increment by one CurrentQuestion.XAnswered++; CurrentCompletedQuestion.XCompleted++; //The difficulty rating must be recalculated CurrentQuestion.CalculatedDifficulty = cd.CalcDifficulty(CurrentQuestion.XAnswered, CurrentQuestion.XAnsweredCorrectly); CurrentCompletedQuestion.CalculatedDifficulty = cd.CalcDifficulty(CurrentCompletedQuestion.XCompleted, CurrentCompletedQuestion.XCorrect); //The question is added back to the storedquestion and complted question lists storedQuestions.Add(CurrentQuestion); completedQuestion.Add(CurrentCompletedQuestion); }; //Displays the question answering form page2.ShowDialog(); } } //Question class is initilized QuestionClass qc = new QuestionClass(); //The method update scored is called in order to refresh the scored that are in the database qc.UpdateScores(storedQuestions, completedQuestion); this.Show(); }