Ejemplo n.º 1
0
        public void LoadQuestions()
        {
            var currentQuestion = CurrentQuestion;

            if (currentQuestion != null)
            {
                AnswerList.Clear();
                foreach (var answer in currentQuestion.Answers)
                {
                    AnswerList.Add(answer);
                }
            }
        }
Ejemplo n.º 2
0
        public override IEnumerable <InputValue> Execute(IEnumerable <InputValue> inputValues)
        {
            foreach (var i in inputValues)
            {
                switch (i.Name)
                {
                case "number":
                    AnswerList.Add(i);
                    return(AnswerList);

                default:
                    break;
                }
            }

            return(AnswerList);
        }
Ejemplo n.º 3
0
        public override IEnumerable <InputValue> Execute(IEnumerable <InputValue> inputValues)
        {
            String input = "";

            foreach (var i in inputValues)
            {
                input += i.Name;
                input += i.Data;
            }
            Expression e = new Expression(input);

            InputValue.Data = e.Evaluate().ToString();
            InputValue.Name = "answer";
            AnswerList.Add(InputValue);
            InputValue.Data = input;
            InputValue.Name = "formula";
            AnswerList.Add(InputValue);
            return(AnswerList);
        }
Ejemplo n.º 4
0
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int result;

                //Check whether adding a new question or updating a question
                switch (editMode)
                {
                /////////////////Editing a question/answer
                case EditMode.Update:
                    //Check if question of answer
                    if (txtText.Text != String.Empty)
                    {
                        switch (qaMode)
                        {
                        case QAMode.Answer:
                            Answer answer = answers.ElementAt(cboQorAs.SelectedIndex);
                            answer.Text = txtText.Text;
                            result      = answer.Update();
                            if (result > 0)
                            {
                                lblStatus.Content = "Updated Answer: " + answer.Text;
                            }
                            else
                            {
                                throw new Exception("Answer not updated");
                            }


                            break;

                        case QAMode.Question:
                            Question question = questions.ElementAt(cboQorAs.SelectedIndex);
                            question.Text = txtText.Text;
                            result        = question.UpdateQuestion();
                            if (result > 0)
                            {
                                lblStatus.Content = "Updated Question: " + question.Text;
                            }
                            else
                            {
                                throw new Exception("Question not updated");
                            }

                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        throw new Exception("Did you mean to delete this " + qaMode.ToString() + "? Please use the delete button instead.");
                    }

                    rebindComboBox(qaMode);
                    break;



                ////////////////////////Adding a question/answer
                case EditMode.Add:
                    //Check if question of answer
                    if (txtText.Text != String.Empty)
                    {
                        switch (qaMode)
                        {
                        case QAMode.Answer:
                            //Create a new answer and put it in the database
                            Answer answer = new Answer();
                            answer.Text = txtText.Text;
                            answers.Add(answer);
                            result = answer.Insert();

                            //Update the label with success or failure message
                            if (result > 0)
                            {
                                lblStatus.Content = "Added Answer: " + answer.Text;
                            }
                            else
                            {
                                throw new Exception("Answer not inserted");
                            }


                            break;

                        case QAMode.Question:
                            //Create question and add to the DB
                            Question question = new Question();
                            question.Text = txtText.Text;
                            questions.Add(question);
                            result = question.InsertQuestion();
                            //Show result on screen
                            if (result > 0)
                            {
                                lblStatus.Content = "Added Question: " + question.Text;
                            }
                            else
                            {
                                throw new Exception("Question not inserted");
                            }

                            break;

                        default:
                            break;
                        }

                        //Clear the entered text
                        txtText.Text = String.Empty;
                    }
                    else
                    {
                        throw new Exception("You must enter a value to add");
                    }
                    break;

                default:
                    break;
                }

                //Rebind the combobox
                rebindComboBox(qaMode);
            }
            catch (Exception ex)
            {
                lblStatus.Content = ex.Message;
            }
        }
Ejemplo n.º 5
0
        void TranslationClickCommand_Execute(object parameter)
        {
            TranslationClickCanExecute = false;

            List <object> objUserAnswer = parameter as List <object>;
            List <string> userAnswer    = objUserAnswer.Select(s => (string)s).ToList();

            int correctAnswerNumber = 0;

            if (Model.IsTestOpenFirstly)
            {
                foreach (Dictionary <string, bool> listItem in VariantsList)
                {
                    foreach (KeyValuePair <string, bool> translation in listItem)
                    {
                        if (translation.Value == true)
                        {
                            if (" " + userAnswer[0] == translation.Key)
                            {
                                AnswerList.Add(new Dictionary <string, bool> {
                                    { Term + " " + "-" + translation.Key, true }
                                });
                                CorrectAnswersCounter++;
                            }
                            else
                            {
                                AnswerList.Add(new Dictionary <string, bool> {
                                    { Term + " " + "-" + translation.Key, false }
                                });
                                IncorrectAnswersCounter++;
                                if (Model.IsTestOpenFirstly)
                                {
                                    PopUp.CurrentWordsDictionary.Add(Term + " " + "-" + translation.Key, 5);
                                }
                            }
                            goto FillColor;
                        }
                        correctAnswerNumber++;
                    }
                }
            }
            else
            {
                foreach (Dictionary <string, bool> listItem in VariantsList)
                {
                    foreach (KeyValuePair <string, bool> translation in listItem)
                    {
                        if (translation.Value == true)
                        {
                            if (" " + userAnswer[0] == translation.Key)
                            {
                                AnswerList.Add(new Dictionary <string, bool> {
                                    { Term + " " + "-" + translation.Key, true }
                                });
                                CorrectAnswersCounter++;
                            }
                            else
                            {
                                AnswerList.Add(new Dictionary <string, bool> {
                                    { Term + " " + "-" + translation.Key, false }
                                });
                                IncorrectAnswersCounter++;
                            }
                            goto FillColor;
                        }
                        correctAnswerNumber++;
                    }
                }
            }


FillColor:
            switch (userAnswer[1])
            {
            case "TranslationOne":
                TranslationOneColor = Color.FromArgb(255, 128, 0, 0);
                break;

            case "TranslationTwo":
                TranslationTwoColor = Color.FromArgb(255, 128, 0, 0);
                break;

            case "TranslationThree":
                TranslationThreeColor = Color.FromArgb(255, 128, 0, 0);
                break;

            case "TranslationFour":
                TranslationFourColor = Color.FromArgb(255, 128, 0, 0);
                break;
            }
            switch (correctAnswerNumber)
            {
            case 0:
                TranslationOneColor = Color.FromArgb(255, 0, 128, 0);
                break;

            case 1:
                TranslationTwoColor = Color.FromArgb(255, 0, 128, 0);
                break;

            case 2:
                TranslationThreeColor = Color.FromArgb(255, 0, 128, 0);
                break;

            case 3:
                TranslationFourColor = Color.FromArgb(255, 0, 128, 0);
                break;
            }

            if (Model.IsTestOpenFirstly)
            {
                if (IncorrectAnswersCounter < 10)
                {
                    if (InitialFillTestIndex < PopUp.WordsDictionary.Count)
                    {
                        Task.Run(() =>
                        {
                            Thread.Sleep(500);
                            Application.Current.Dispatcher.Invoke(() =>
                            {
                                InitialFillTest();
                            });
                        });
                    }
                    else
                    {
                        //StaticConfigProvider.IsTestOpenFirstly = false;
                        CompleteWordsDictionary();
                        Model.IsTestOpenFirstly         = false;
                        IsCountersVisible               = false;
                        StaticConfigProvider.StartTimer = true;
                        Model.FillCurrentTermTranslationLists(PopUp.CurrentWordsDictionary);

                        openWindowService.HideTestWindow();

                        Task.Run(() =>
                        {
                            Thread.Sleep(2000);
                            Application.Current.Dispatcher.Invoke(() =>
                            {
                                FillTest();
                            });
                        });
                    }
                }
                else
                {
                    //StaticConfigProvider.IsTestOpenFirstly = false;
                    Model.IsTestOpenFirstly         = false;
                    IsCountersVisible               = false;
                    StaticConfigProvider.StartTimer = true;
                    Model.FillCurrentTermTranslationLists(PopUp.CurrentWordsDictionary);
                    WordsDictionaryChangePriority(AnswerList);
                    AnswerList.Clear();

                    openWindowService.HideTestWindow();

                    Task.Run(() =>
                    {
                        Thread.Sleep(2000);
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            FillTest();
                        });
                    });
                }
            }
            else
            {
                TestAppearCounter++;

                if (TestAppearCounter < BlockVolume)
                {
                    Task.Run(() =>
                    {
                        Thread.Sleep(500);
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            FillTest();
                        });
                    });
                }
                else
                {
                    CurrentWordsDictionaryChangePriority(AnswerList);

                    if (NextWordCounter != 0)
                    {
                        IsCountersVisible = true;
                        AnswerList.Clear();
                        Task.Run(() =>
                        {
                            Thread.Sleep(500);
                            Application.Current.Dispatcher.Invoke(() =>
                            {
                                FillTestNext();
                            });
                        });
                    }
                    else
                    {
                        openWindowService.HideTestWindow();
                        StaticConfigProvider.StartTimer = true;

                        IsCountersVisible = false;
                        IsNextWord        = false;

                        AnswerList.Clear();
                        TestAppearCounter = 0;
                        FillTestIndex     = 0;

                        // Delay and next appearing filling
                        Task.Run(() =>
                        {
                            Thread.Sleep(2000);
                            Application.Current.Dispatcher.Invoke(() =>
                            {
                                FillTest();
                            });
                        });
                        // Delay and next appearing filling
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public void AddAnswer(IAnswer answer)
 {
     AnswerList.Add(answer);
 }
Ejemplo n.º 7
0
        public void SetupTest()
        {
            Answers = new AnswerList();

            // add the test questions/answers

            Answers.Add(
                new Answer(
                    Question.New <string>("Test1", new string[] { "First", "Second" }, true)
                    , "Test-Value-1"));

            Answers.Add(
                new Answer(
                    Question.New <string>("Test2", new string[] { "First", "Second" }, true)
                    , "Test-Value-2"));

            Answers.Add(
                new Answer(
                    Question.New <string>("Test3", new string[] { "First", "Second" }, true)
                    , "Test-Value-3"));

            // add some other questions/answers with the same names but different paths and values
            // this is to avoid chance hits

            Answers.Add(
                new Answer(
                    Question.New <string>("Test1", new string[] { "One", "Two" }, true)
                    , "Different-Test-Value-1"));

            Answers.Add(
                new Answer(
                    Question.New <string>("Test2", new string[] { "One", "Two" }, true)
                    , "Different-Test-Value-2"));

            Answers.Add(
                new Answer(
                    Question.New <string>("Test3", new string[] { "One", "Two" }, true)
                    , "Different-Test-Value-3"));

            // add some questions with path = null

            Answers.Add(
                new Answer(
                    Question.New <string>("Test1", null, true)
                    , "NullPath-Test-Value-1"));

            Answers.Add(
                new Answer(
                    Question.New <string>("Test2", null, true)
                    , "NullPath-Test-Value-2"));

            Answers.Add(
                new Answer(
                    Question.New <string>("Test3", null, true)
                    , "NullPath-Test-Value-3"));

            // add some questions with path = empty-string-array

            Answers.Add(
                new Answer(
                    Question.New <string>("EmptyTest1", new string[] { }, true)
                    , "EmptyPath-Test-Value-1"));

            Answers.Add(
                new Answer(
                    Question.New <string>("EmptyTest2", new string[] { }, true)
                    , "EmptyPath-Test-Value-2"));

            Answers.Add(
                new Answer(
                    Question.New <string>("EmptyTest3", new string[] { }, true)
                    , "EmptyPath-Test-Value-3"));
        }