private void SearchButton_Click_1(object sender, EventArgs e) { //All relevant question search criteria must be saved to the class SearchCriteria QuestionClass qc = new QuestionClass(); SearchCriteria sc = new SearchCriteria(); sc.Search = SearchBarTextBox.Text; //The user`s selected topics are added the the criteria //If they have selected no topics it will select them all if ((TopicCheckedListBox.CheckedItems.Count == 0) || (TopicCheckedListBox.CheckedItems.Count == 5)) { sc.Topic1 = 1; sc.Topic2 = 2; sc.Topic3 = 3; sc.Topic4 = 4; sc.Topic5 = 5; } else { if (TopicCheckedListBox.CheckedItems.Contains("Particles")) { sc.Topic1 = 1; } if (TopicCheckedListBox.CheckedItems.Contains("Waves")) { sc.Topic2 = 2; } if (TopicCheckedListBox.CheckedItems.Contains("Mechanics")) { sc.Topic3 = 3; } if (TopicCheckedListBox.CheckedItems.Contains("Materials")) { sc.Topic4 = 4; } if (TopicCheckedListBox.CheckedItems.Contains("Electricity")) { sc.Topic5 = 5; } } //If the user selects no areas all of them are selected otherwise it will follow onto if (AreaCheckedListBox.CheckedItems.Count == 0 || AreaCheckedListBox.CheckedItems.Count == 2) { sc.Area = 1; sc.Area1 = 2; } else { if (AreaCheckedListBox.CheckedItems.Contains("Recall")) { sc.Area = 1; sc.Area1 = 1; } else { sc.Area = 2; sc.Area1 = 2; } } //The selected difficulty must be chosen and it will then assign values to search criteria based upon it if (selectedmode == 2) { sc = GeneratedDifficulty(sc); questions = qc.GetQuestionsForSearch(sc, true); } else { sc = PredefDifficultySearch(sc); questions = qc.GetQuestionsForSearch(sc, false); } QuestionListBox.DataSource = questions; QuestionListBox.DisplayMember = "DisplayItem"; }
private void SearchButton_Click(object sender, EventArgs e) { int numberselected; QuestionClass qc = new QuestionClass(); SearchCriteria sc = new SearchCriteria(); try { //The user specifies number of questions that they want the quiz to contain if (int.Parse(NumberOfQuestionsTextBox.Text) <= 15 && int.Parse(NumberOfQuestionsTextBox.Text) >= 3) { numberselected = int.Parse(NumberOfQuestionsTextBox.Text); } else { MessageBox.Show("Outside bounds, please enter a value between 3 and 15", "Error", MessageBoxButtons.OK); return; } } catch (Exception) { //If the user doesn`t input a correct number of questions then the exception is thrown MessageBox.Show("Invaid Number Entered, please enter a value between 3 and 15", "Error", MessageBoxButtons.OK); return; } if ((TopicCheckedListBox.CheckedItems.Count == 0) || (TopicCheckedListBox.CheckedItems.Count == 5)) { //If no question topics or all of them are selected then all of the topics are selected sc.Topic1 = 1; sc.Topic2 = 2; sc.Topic3 = 3; sc.Topic4 = 4; sc.Topic5 = 5; } else { //Otherwise each question must be checked individually to see if it has been selected if (TopicCheckedListBox.CheckedItems.Contains("Particles")) { sc.Topic1 = 1; } if (TopicCheckedListBox.CheckedItems.Contains("Waves")) { sc.Topic2 = 2; } if (TopicCheckedListBox.CheckedItems.Contains("Mechanics")) { sc.Topic3 = 3; } if (TopicCheckedListBox.CheckedItems.Contains("Materials")) { sc.Topic4 = 4; } if (TopicCheckedListBox.CheckedItems.Contains("Electricity")) { sc.Topic5 = 5; } } if (AreaCheckedListBox.CheckedItems.Count == 0 || AreaCheckedListBox.CheckedItems.Count == 2) { //If no question areas or all of them are selected then all of the areas are selected sc.Area = 1; sc.Area1 = 2; } else { //Otherwise each question must be checked individually to see if it has been selected if (AreaCheckedListBox.CheckedItems.Contains("Recall")) { sc.Area = 1; sc.Area1 = 1; } else { sc.Area = 2; sc.Area1 = 2; } } //The selected difficulty must be chosen and it will then assign values to search criteria based upon it if (selectedmode == 2) { sc = GeneratedDifficulty(sc); AllQuestions = qc.GetQuestionsForSearch(sc, true); } else { sc = PredefDifficultySearch(sc); AllQuestions = qc.GetQuestionsForSearch(sc, false); } //The stored questions are reshuffled by this line of code List <StoredQuestions> ShuffledQuizQuestions = AllQuestions.OrderBy(x => Guid.NewGuid()).ToList(); questions = new List <StoredQuestions>(); //The first to specified number by the user number of questions is saved to the list to be returned containing the quiz questions int count = 0; while (count < int.Parse(NumberOfQuestionsTextBox.Text) && ShuffledQuizQuestions.Count() > count) { questions.Add(ShuffledQuizQuestions.ElementAt(count)); count++; } //Display members are clarified QuestionListBox.DataSource = questions; QuestionListBox.DisplayMember = "Question"; //Displays how many question have been selected from the specified count in case there weren`t enough questions based upon their criteria InformationLabel.Text = "Selected " + questions.Count + " questions from criteria returning " + AllQuestions.Count() + " Questions"; }