Beispiel #1
0
 /// <summary>
 /// Constructor for creating new QSet
 /// </summary>
 /// <param name="navManager"></param>
 /// <param name="qSetsManager"></param>
 /// <param name="name"></param>
 /// <param name="path"></param>
 public QSetEditorUC(NavigationManager navManager, QSetsManager qSetsManager, string name, string path) : this(navManager, qSetsManager)
 {
     EditedQSet = new QSet(name, path);
     isNew      = true;
     saved      = false;
     SetCollectionViews();
 }
Beispiel #2
0
 /// <summary>
 /// Constructor for editing existing QSet
 /// </summary>
 /// <param name="navManager"></param>
 /// <param name="qSetsManager"></param>
 /// <param name="index"></param>
 public QSetEditorUC(NavigationManager navManager, QSetsManager qSetsManager, QSet qSet, int index) : this(navManager, qSetsManager)
 {
     EditedQSet = qSet;
     isNew      = false;
     this.index = index;
     actualPath = qSet.Path;
     SetCollectionViews();
 }
Beispiel #3
0
        /// <summary>
        /// Check and save edited question set
        /// </summary>
        /// <returns>True if the qSet was saved successfuly, otherwise false </returns>
        private bool Save()
        {
            if (saved)
            {
                return(true);
            }

            string error = QSetsManager.CheckQSet(EditedQSet); //check number of questions

            if (error != null)
            {
                MessageBox.Show($"Chyba při ukládání otázek:\n{error}", "Chyba", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            var result = qSetsManager.CheckQuestions(editedQuestions); //check individal questions

            if (result.Item1 != null && result.Item2 != null)
            {
                MessageBox.Show($"Chyba při ukládání otázek:\n{result.Item2}", "Chyba", MessageBoxButton.OK, MessageBoxImage.Error);
                SelectQuestion(result.Item1); //select problematic question
                return(false);
            }

            if (nameChanged && actualPath != null) //rename if EditedQSet has been renamed and there is a file to rename
            {
                try
                {
                    File.Move(actualPath, EditedQSet.Path);
                    actualPath = EditedQSet.Path;
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Chyba při ukládání otázek:\nPřejmenování souboru se nezdařilo: {ex.Message}", "Chyba", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }
            }

            try
            {
                FileManager.SaveQSet(EditedQSet);
                actualPath = EditedQSet.Path; //if this was the first saving of the new QSet, actual path was null
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Chyba při ukládání otázek:\n{ex.Message}", "Chyba", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            Saved       = true;
            nameChanged = false;
            editedQuestions.Clear();
            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Base constructor
        /// </summary>
        /// <param name="navManager"></param>
        /// <param name="qSetsManager"></param>
        public QSetEditorUC(NavigationManager navManager, QSetsManager qSetsManager)
        {
            InitializeComponent();
            DataContext = this;

            this.navManager   = navManager;
            this.qSetsManager = qSetsManager;

            editedQuestions = new HashSet <Question>();

            questionTextBoxes = new List <TextBox> {
                questionTextBox, rightAnswerTextBox, wrongAnswer1TextBox, wrongAnswer2TextBox, wrongAnswer3TextBox
            };
        }
Beispiel #5
0
 public NavigationManager()
 {
     ScoresManager = new ScoresManager();
     QSetsManager  = new QSetsManager();
     try
     {
         ScoresManager.Scores = FileManager.LoadScores();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Nepodařilo se načíst uložená skóre: " + ex.Message + "\nNebude možné ukládat skóre. Pokud chcete umožnit ukládání, restartujte aplikaci.", "Nelze načíst skóre", MessageBoxButton.OK, MessageBoxImage.Error);
         FileManager.safeToSaveScores = false;
     }
 }
        public SelectQSetsUC(NavigationManager navManager, QSetsManager qSetsManager, bool isSandbox)
        {
            InitializeComponent();

            this.navManager   = navManager;
            this.qSetsManager = qSetsManager;
            this.isSandbox    = isSandbox;

            if (qSetsManager.QuestionSets == null)
            {
                List <string> errors;
                qSetsManager.QuestionSets = FileManager.LoadQuestionSets(out errors);
                foreach (string error in errors)
                {
                    MessageBox.Show(error, "Chyba", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                qSetsManager.Sort();
            }

            QSetsListBox.ItemsSource = qSetsManager.QuestionSets;
        }
Beispiel #7
0
        public ManageQSetsUC(NavigationManager navigationManager, QSetsManager qSetsManager)
        {
            navManager        = navigationManager;
            this.qSetsManager = qSetsManager;

            if (qSetsManager.QuestionSets == null)
            {
                List <string> errors;
                qSetsManager.QuestionSets = FileManager.LoadQuestionSets(out errors);
                foreach (string error in errors)
                {
                    MessageBox.Show(error, "Chyba", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                qSetsManager.Sort();
            }

            InitializeComponent();

            qSetActionButtons = new List <Button> {
                editButton, exportButton, deleteButton
            };
            QSetsListBox.ItemsSource = qSetsManager.QuestionSets;
        }