public void GenPrev()
        {
            QAInstance instance = QADictionary.BackToPreviousQuestion();

            if (instance != null)
            {
                AnswerTB.Text   = instance.Answer;
                QuestionTB.Text = instance.Question;
            }
        }
        /// <summary>
        /// Create the next question in the user interface in case the XML file exists.
        /// </summary>
        public void GenNext()
        {
            QAInstance instance = QADictionary.GenerateNextQuestion();

            if (instance == null)
            {
                MessageBox.Show($"No records found in the XML file.");
            }
            else
            {
                AnswerTB.Text   = instance.Answer;
                QuestionTB.Text = instance.Question;
            }
        }
示例#3
0
        /// <summary>
        /// Updating existing record in XML.
        /// </summary>
        /// <param name="instanceOld"></param>
        /// <param name="instanceUpdated"></param>
        public void UpdateExisting(QAInstance instanceOld, QAInstance instanceUpdated)
        {
            XDocument xdoc = XDocument.Load(filePath);
            XElement  root = xdoc.Element("Questions");

            foreach (XElement xe in root.Elements("question").ToList())
            {
                if (xe.Attribute("qtext").Value == instanceOld.Question)
                {
                    xe.Attribute("qtext").Value   = instanceUpdated.Question;
                    xe.Attribute("qanswer").Value = instanceUpdated.Answer;
                }
            }
            xdoc.Save(filePath);
        }
示例#4
0
 /// <summary>
 /// Adding new record to XML.
 /// </summary>
 /// <param name="instance"></param>
 public void Increment(QAInstance instance)
 {
     if (String.IsNullOrWhiteSpace(instance.Answer) || String.IsNullOrWhiteSpace(instance.Question) ||
         instance.Question.Length < 5 || instance.Answer.Length < 5)
     {
         System.Windows.MessageBox.Show("Args is empty or shorter then 5 symbols");
     }
     else
     {
         XDocument xdoc = XDocument.Load(filePath);
         xdoc.Elements("Questions").First().Add(
             new XElement("question", new XAttribute("qtext", instance.Question),
                          new XAttribute("qanswer", instance.Answer)));
         xdoc.Save(filePath);
     }
 }
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            if (EditMode)  // Disabling UI edit mode
            {
                if (MessageBox.Show("Save changes?", "Apply?", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                {
                    QAInstance instance = new QAInstance(QuestionTB.Text, AnswerTB.Text);
                    new XMLWorker(System.IO.Directory.GetCurrentDirectory() + Properties.Settings.Default.XMLname).UpdateExisting(
                        new QAInstance(QuestionValue, AnswerValue), new QAInstance(QuestionTB.Text, AnswerTB.Text));
                }
                else
                {
                    QuestionTB.Text = QuestionValue;
                    AnswerTB.Text   = AnswerValue;
                }
                EditMode = false;

                AnswerTB.Background = Brushes.Transparent;

                QuestionTB.Background = Brushes.Transparent;
                EditButton.Content    = "Edit";
                QuestionValue         = null;
                AnswerValue           = null;
                QADictionary.ReloadDictionary();

                ControlEnableInvert(new FrameworkElement[] { AddButton, Next, Previous });

                AnswerTB.IsReadOnly   = true;
                QuestionTB.IsReadOnly = true;
            }
            else // Edit mode in UI
            {
                AnswerValue           = AnswerTB.Text;
                QuestionValue         = QuestionTB.Text;
                EditMode              = true;
                EditButton.Content    = "Save";
                AnswerTB.Background   = Brushes.WhiteSmoke;
                QuestionTB.Background = Brushes.WhiteSmoke;

                ControlEnableInvert(new FrameworkElement[] { AddButton, Next, Previous });

                AnswerTB.IsReadOnly   = false;
                QuestionTB.IsReadOnly = false;
            }
        }