Esempio n. 1
0
        private void nextButton_Click(object sender, EventArgs e)
        {
            int chosenVariant = 0;

            if (checkBox1.Checked == true)
            {
                chosenVariant = 0;
            }
            if (checkBox2.Checked == true)
            {
                chosenVariant = 1;
            }
            if (checkBox3.Checked == true)
            {
                chosenVariant = 2;
            }
            if (checkBox4.Checked == true)
            {
                chosenVariant = 3;
            }



            List <Fact> ResultFacts = Solution.Solve(currentQuestion);

            try
            {
                ResultFacts.Where(o => o.ID == currentQuestion.QuestionAnswers[chosenVariant].ID).First();
            }
            catch
            {
                totalErrors++;
                string message = "Правильный ответ:\n";// + ResultFacts.Where(o => o.);
                foreach (Fact fact in currentQuestion.QuestionAnswers)
                {
                    try
                    {
                        ResultFacts.Where(o => o.ID == fact.ID).First();
                        message += fact.Value + "\n";
                    }
                    catch
                    {
                        continue;//Поменять на break, если надо будет только один вариант ответа
                    }
                }
                string            caption = "Неверный ответ";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                DialogResult      result;
                result = MessageBox.Show(this, message, caption, buttons);
            }
            this.Hide();
            if (QuestionsList.Count > 0)
            {
                Question nextPage = new Question(QuestionsList, totalErrors, totalCount);
                nextPage.Show();
            }
            else
            {
                Result finalPage = new Result(totalErrors, totalCount);
                finalPage.Show();
            }
        }
Esempio n. 2
0
        private void startbutton_Click(object sender, EventArgs e)
        {
            int selectedTopicId = 0;

            try
            {
                selectedTopicId = Int32.Parse(topicsComboBox.Text.Split().ToList()[2]);
            }
            catch
            {
                string            caption = "Ошибка";
                string            message = "Выберите тему";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                DialogResult      result;
                result = MessageBox.Show(this, message, caption, buttons);
                return;
            }
            var topicsFile = XDocument.Load("../../DataBase/TopicsAndQuestions.xml").Root;
            var factsFile  = XDocument.Load("../../DataBase/Knowledgebase.xml").Root;
            var facts      = factsFile.Descendants("Facts").FirstOrDefault();
            var Topics     = topicsFile.Descendants("Topics").FirstOrDefault();
            var Topic      = Topics.Descendants("Topic").Where(o => Int32.Parse(o.Attribute("id").Value) == selectedTopicId).FirstOrDefault();
            var Questions  = Topic.Descendants("Questions").FirstOrDefault();
            List <QuestionModel> QuestionsList = new List <QuestionModel>();

            foreach (XElement question in Questions.Nodes())
            {
                List <Fact> QuestionFacts = new List <Fact>();
                List <Fact> AnswersFacts  = new List <Fact>();

                foreach (string factId in question.Attribute("questionRule").Value.Split().ToList())
                {
                    var fact = facts.Descendants("Fact").Where(o => o.Attribute("id").Value == factId).FirstOrDefault();
                    QuestionFacts.Add(new Fact {
                        ID        = Int32.Parse(fact.Attribute("id").Value),
                        Value     = fact.Attribute("value").Value,
                        Attribute = fact.Attribute("attribute").Value,
                        Object    = fact.Attribute("object").Value
                    });
                }
                foreach (string factId in question.Attribute("answerIds").Value.Split().ToList())
                {
                    var fact = facts.Descendants("Fact").Where(o => o.Attribute("id").Value == factId).FirstOrDefault();
                    AnswersFacts.Add(new Fact
                    {
                        ID        = Int32.Parse(fact.Attribute("id").Value),
                        Value     = fact.Attribute("value").Value,
                        Attribute = fact.Attribute("attribute").Value,
                        Object    = fact.Attribute("object").Value
                    });
                }
                QuestionsList.Add(new QuestionModel {
                    id            = Int32.Parse(question.Attribute("id").Value),
                    questionText  = question.Attribute("questionText").Value,
                    QuestionFacts = QuestionFacts, QuestionAnswers = AnswersFacts
                });
            }

            Question questionPage = new Question(QuestionsList, 0, QuestionsList.Count);

            this.Hide();
            questionPage.Show();
        }