private void AddQuestionButton_Click(object sender, RoutedEventArgs e)
        {
            if (QuestionNameTextBox.Text.Equals(string.Empty))
            {
                return;
            }

            actualAnswers.RemoveAll(x => x.Name == null);

            if (actualAnswers.Count == 0)
            {
                return;
            }

            if (editMode)
            {
                editMode = false;

                var questionItem = questionItems.Find(x => x.ID == actualQuestionID);
                var question     = new Question(questionItem.ID, QuestionNameTextBox.Text, new List <Answer>(actualAnswers));
                QuestionManager.SetQuestion(question);
                InitQuestionItems();
            }
            else
            {
                actualAnswersID = 0;

                var question = new Question(questionsID, QuestionNameTextBox.Text, new List <Answer>(actualAnswers));
                QuestionManager.AddQuestion(question);

                var questionItem = new QuestionItem(question);
                QuestionListStackPanel.Children.Add(questionItem);
                questionItems.Add(questionItem);

                questionsID++;
            }

            QuestionNameTextBox.Text = string.Empty;
            AnswersStackPanel.Children.Clear();
            actualAnswers.Clear();

            ChangeAddOrEditQuestionIcon();

            SaveQuestions();
        }
Ejemplo n.º 2
0
        public void AddNewQuestion()
        {
            if (actualQuestionNumber > QuestionManager.Questions.Count)
            {
                return;
            }

            actualAnswers.Clear();
            AnswersStackPanel.Children.Clear();
            GoodAnswerCountsLabel.Content = string.Empty;
            QuestionNumberLabel.Content   = string.Empty;
            QuestionTextBlock.Text        = string.Empty;

            var question = QuestionManager.GetQuestion(actualQuestionNumber);

            if (question == null)
            {
                return;
            }

            QuestionNumberLabel.Content = $"{question.ID + 1}. kérdés";
            QuestionTextBlock.Text      = question.Name;

            QuestionNumberInputTextBox.Text = (actualQuestionNumber + 1).ToString();

            var rand            = new Random();
            var shuffledAnswers = new List <Answer>(question.Answers);

            shuffledAnswers = shuffledAnswers.OrderBy(x => rand.Next()).ToList();
            foreach (var answer in shuffledAnswers)
            {
                AnswersStackPanel.Children.Add(new AnswerContent(answer));

                AddAnswer(answer.ID, answer.Name, answer.Right);
            }

            actualQuestions.Add(question);

            CheckAnswersButton.IsEnabled = true;
            NextQuestionButton.IsEnabled = false;
            PrevQuestionButton.IsEnabled = false;
        }
Ejemplo n.º 3
0
        public static void ReadFile(string fileName, ref Snackbar errorSnackbar)
        {
            Mouse.OverrideCursor = Cursors.Wait;

            QuestionManager.ClearQuestions();

            using (var reader = new StreamReader(fileName))
            {
                try
                {
                    dynamic json = JsonConvert.DeserializeObject(reader.ReadToEnd());

                    for (int i = 0; i < json.Count; i++)
                    {
                        string question = json[i].Name;
                        var    answers  = new List <Answer>();

                        for (int j = 0; j < json[i].Answers.Count; j++)
                        {
                            string answer = json[i].Answers[j].Name;
                            bool   right  = json[i].Answers[j].Right;
                            answers.Add(new Answer(j, answer, right));
                        }

                        QuestionManager.AddQuestion(new Question(i, question, answers));

                        ((QuestionsContent)TabManager.GetTab("Questions").Content).AddNewQuestion();
                        ((SettingsContent)TabManager.GetTab("Settings").Content).UpdateQuestionItems(fileName);
                    }
                }
                catch (Exception)
                {
                    errorSnackbar.MessageQueue.Enqueue("Can't read file.", null, null, null, false, true, TimeSpan.FromSeconds(4));
                }
            }

            Mouse.OverrideCursor = Cursors.Arrow;
        }
        private void InsertDraggedQuestionItem()
        {
            if (beforeDrag == afterDrag)
            {
                return;
            }

            var temp = QuestionManager.GetQuestion(beforeDrag);

            for (int i = afterDrag; i < QuestionManager.Questions.Count; i++)
            {
                QuestionManager.Questions[i].SetID(i + 1);
            }
            temp.SetID(afterDrag);

            questionItems = (from questionItem in questionItems
                             orderby questionItem.ID ascending
                             select questionItem).ToList();

            InitQuestionItems();

            SaveQuestions();
        }
Ejemplo n.º 5
0
        private void CheckAnswersButton_Click(object sender, RoutedEventArgs e)
        {
            var question          = new Question(actualQuestionNumber, QuestionTextBlock.Text);
            int pickedGoodAnswers = 0;
            int goodAnswers       = 0;
            int picks             = 0;

            foreach (AnswerContent answerContent in AnswersStackPanel.Children)
            {
                question.Answers.Add(new Answer(answerContent.AnswerID)
                {
                    Name  = answerContent.AnswerName,
                    Right = answerContent.IsChecked
                });

                var getGoodAnswer = actualAnswers.Find(x => x.Name.Equals(answerContent.AnswerName));
                if (getGoodAnswer.Right == true)
                {
                    answerContent.ChangeAnswerWeightToColor("#56c649", change: true);
                    goodAnswers++;
                }
                else
                {
                    if (answerContent.IsChecked)
                    {
                        answerContent.ChangeAnswerWeightToColor("#dd2727", change: true);
                    }
                }

                if (answerContent.IsChecked == true)
                {
                    picks++;

                    if (answerContent.IsChecked == getGoodAnswer.Right)
                    {
                        pickedGoodAnswers++;
                    }
                }

                answerContent.Disable();
            }

            if (!(goodAnswers == pickedGoodAnswers && picks == pickedGoodAnswers))
            {
                if (QuestionManager.WrongAnsweredQuestions.Find(x => x.ID == question.ID) == null)
                {
                    QuestionManager.WrongAnsweredQuestions.Add(question);
                }
            }
            else
            {
                if (QuestionManager.GetWrongQuestion(question.ID) != null)
                {
                    QuestionManager.RemoveWrongQuestion(question.ID);
                }
            }

            CheckAnswersButton.IsEnabled = false;
            NextQuestionButton.IsEnabled = true;
            PrevQuestionButton.IsEnabled = true;

            GoodAnswerCountsLabel.Foreground = goodAnswers == pickedGoodAnswers && picks == pickedGoodAnswers ? Brushes.Green : Brushes.Red;
            GoodAnswerCountsLabel.Content    = $"{picks}/{pickedGoodAnswers}/{actualAnswers.Count}";

            ((CheckAnswersContent)TabManager.GetTab("Wrong answers").Content).UpdateQuestions();
        }