/// <summary> /// Event handler for "Save to XML" MenuItem /// </summary> /// <param name="sender">The object sending the request, in this case a MenuItem</param> /// <param name="e">The event arguments</param> private void SaveToXMLMenuItem_Click(object sender, RoutedEventArgs e) { if (quizHandler.quizManager.Count > 0) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "XML File | *.XML"; bool saved = (bool)saveFileDialog.ShowDialog(); if (saved) { try { quizHandler.quizManager.XMLSerialize(saveFileDialog.FileName); dataSaved = true; MessageBoxes.ShowInformationMessageBox("The Questions where saved"); } catch (Exception exSave) { MessageBoxes.ShowErrorMessageBox($"{exSave.Message} {exSave.InnerException}"); } } } else { MessageBoxes.ShowInformationMessageBox("There is nothing to save yet, please create some quizes"); } }
/// <summary> /// Event handler for "Load from XML" menu item /// </summary> /// <param name="sender">The object sending the request, in this case a MenuItem</param> /// <param name="e">The event arguments</param> private void LoadFromXMLMenuItem_Click(object sender, RoutedEventArgs e) { if (quizHandler.quizManager.Count == 0 || (quizHandler.quizManager.Count > 0 && WantToContinueWithoutSaving())) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "XML File | *.XML"; bool opened = (bool)openFileDialog.ShowDialog(); if (opened) { try { quizHandler.quizManager.XMLDeserialize(openFileDialog.FileName); quizes = new ObservableCollection <QuizItem>(quizHandler.quizManager.GetAllItems()); QuizesListView.ItemsSource = quizes; TransferQuizesToProgram(); MessageBoxes.ShowInformationMessageBox("The Created questions where saved!"); } catch (Exception exOpen) { MessageBoxes.ShowErrorMessageBox($"{exOpen.Message} {exOpen.InnerException}"); } } } }
/// <summary> /// Event handler for the "Create Quiz" button /// </summary> /// <param name="sender">The object sending the request, in this case a button</param> /// <param name="e">The event arguments</param> private void CreateQuizButton_Click(object sender, RoutedEventArgs e) { QuizItem newQuiz = quizHandler.CreateQuiz(QuizNameTextBox.Text, QuizDescriptionTextBox.Text); if (quizHandler.AddQuiz(newQuiz)) { quizes = new ObservableCollection <QuizItem>(quizHandler.quizManager.GetAllItems()); QuizesListView.ItemsSource = quizes; MessageBoxes.ShowInformationMessageBox("Quiz Added"); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ShowSearchFieldButton_Click(object sender, RoutedEventArgs e) { if (quizHandler.quizManager.Count > 0) { SearchTermTextBox.Visibility = Visibility.Visible; SearchGroupBox.Visibility = Visibility.Visible; } else { MessageBoxes.ShowInformationMessageBox("There is nothing to search, please create some quizes."); } }
/// <summary> /// Event handler for "Delete answer" button /// </summary> /// <param name="sender">The object sending the request, in this case a button</param> /// <param name="e">The event arguments</param> private void DeleteAnswerButton_Click(object sender, RoutedEventArgs e) { if (QuizesListView.SelectedIndex >= 0) { if (quizHandler.quizManager.GetAt(QuizesListView.SelectedIndex).Questions.GetAt(QuestionsOfSelectedQuizListView.SelectedIndex).Answers.RemoveAnswer(AnswersOfSelectedQuestionListView.SelectedIndex)) { AnswersOfSelectedQuestion.RemoveAt(AnswersOfSelectedQuestionListView.SelectedIndex); } } else { MessageBoxes.ShowInformationMessageBox("Please select an answer to remove"); } }
/// <summary> /// Event handler for "Delete quiz" button /// </summary> /// <param name="sender">The object sending the request, in this case a button</param> /// <param name="e">Event arguments</param> private void DeleteQuizButton_Click(object sender, RoutedEventArgs e) { if (QuizesListView.SelectedIndex >= 0) { if (quizHandler.RemoveQuiz(QuizesListView.SelectedIndex)) { quizes.RemoveAt(QuizesListView.SelectedIndex); QuestionsOfSelectedQuiz.Clear(); QuestionsAnswersTabControl.IsEnabled = false; } } else { MessageBoxes.ShowInformationMessageBox("Please select a quiz to remove"); } }
/// <summary> /// Event handler for "Edit quiz" button /// </summary> /// <param name="sender">The object sending the request, in this case a ListView</param> /// <param name="e">The event arguments</param> private void EditQuestionButton_Click(object sender, RoutedEventArgs e) { if (QuestionsOfSelectedQuizListView.SelectedIndex >= 0) { GenericChangePopupUserControl popupCtrl = new GenericChangePopupUserControl(); popupCtrl.TypeOfAction = Mode.Edit; popupCtrl.TypeOfItemToHandle = TypeOfItemToChange.Question; popupCtrl.OldTitle = QuestionsOfSelectedQuiz.Where(x => x.Id == QuestionsOfSelectedQuizListView.SelectedIndex + 1).FirstOrDefault().Title; popupCtrl.IsSavedEvent += (senderIsSaved, eIsSaved) => { ChangeQuestionInformation(QuestionsOfSelectedQuizListView.SelectedIndex, eIsSaved.NewTitle); UcContainer.Children.Remove(eIsSaved.UserControl); }; popupCtrl.InitializeGui(); UcContainer.Children.Add(popupCtrl); } else { MessageBoxes.ShowInformationMessageBox("Please select an question to edit"); } }
/// <summary> /// Event handler for "Edit answer" button /// </summary> /// <param name="sender">The object sending the request, in this case a button</param> /// <param name="e">The event arguments</param> private void EditAnswerButton_Click(object sender, RoutedEventArgs e) { if (AnswersOfSelectedQuestionListView.SelectedIndex >= 0) { GenericChangePopupUserControl popupCtrl = new GenericChangePopupUserControl(); popupCtrl.TypeOfAction = Mode.Edit; popupCtrl.TypeOfItemToHandle = TypeOfItemToChange.Answer; popupCtrl.OldTitle = quizHandler.quizManager.GetAt(QuizesListView.SelectedIndex).Questions.GetAt(QuestionsOfSelectedQuizListView.SelectedIndex).Answers.GetAt(AnswersOfSelectedQuestionListView.SelectedIndex).Title; popupCtrl.OldIsRightAnswer = quizHandler.quizManager.GetAt(QuizesListView.SelectedIndex).Questions.GetAt(QuestionsOfSelectedQuizListView.SelectedIndex).Answers.GetAt(AnswersOfSelectedQuestionListView.SelectedIndex).RightAnswer; popupCtrl.IsSavedEvent += (senderIsSaved, eIsSaved) => { ChangeAnswerInformation(AnswersOfSelectedQuestionListView.SelectedIndex, eIsSaved.NewTitle); UcContainer.Children.Remove(eIsSaved.UserControl); }; popupCtrl.InitializeGui(); UcContainer.Children.Add(popupCtrl); } else { MessageBoxes.ShowInformationMessageBox("Please select an answer to edit"); } }