/// <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 save button, checks if all necessary data was entered, iy yes, the window is closed /// </summary> /// <param name="sender">the object sending the request, in this case a button</param> /// <param name="e">The arguments associated with the event</param> private void SaveCloseButton_Click(object sender, RoutedEventArgs e) { if (AllInfoEntered()) { QuestionTitle = QuestionTitleTextBox.Text; this.DialogResult = true; this.Close(); } else { MessageBoxes.ShowErrorMessageBox("You have not entered all necessary information"); } }