Exemple #1
0
 //method clear all list boxes ansd labels
 public void ClearAllText()
 {
     CorrectAnswerData.Clear();
     StudentAnswerData.Clear();
     IncorrectAnswerData.Clear();
     Result         = "";
     CorrectMarks   = "";
     IncorrectMarks = "";
     LabelColor     = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
 }
Exemple #2
0
        //method Compare two sets of question from saved files and show result
        public void Compare()
        {
            if (selectedFileName == "")
            {
                MessageBox.Show("Please Select a sample file");
                return;
            }
            else
            {
                string[] correctAnswerDataArray = File.ReadAllLines("correctAnswer.txt");
                string[] studentAnswerDataArray = File.ReadAllLines(selectedFileName);
                int      correctcount           = 0;
                int      incorrectcount         = 0;

                for (int i = 0; i < correctAnswerDataArray.Length; i++)
                {
                    CorrectAnswerData.Add(correctAnswerDataArray[i]);
                    StudentAnswerData.Add(studentAnswerDataArray[i]);
                    if (correctAnswerDataArray[i] == studentAnswerDataArray[i])
                    {
                        correctcount++;
                    }
                    else
                    {
                        incorrectcount++;
                        string[] spliteElementArray = studentAnswerDataArray[i].Split('.');
                        IncorrectAnswerData.Add(spliteElementArray[0]);
                    }
                }
                if (correctcount < PASSING_MARK)
                {
                    Result     = $"Sorry you didn't pass the exam.";
                    LabelColor = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
                }
                else
                {
                    Result     = $"Congratulations!! You have passed the exam.";
                    LabelColor = new SolidColorBrush(Color.FromArgb(255, 0, 255, 0));
                }
                CorrectMarks   = $"Total number of correct answers= {correctcount}";
                IncorrectMarks = $"Total number of incorrect answers= {incorrectcount}";
            }
        }
Exemple #3
0
        void ConfirmAnswers(object sender, RoutedEventArgs arg)
        {
            try
            {
                sQLiteConnection = new SQLiteConnection(@"Data Source=..\TestDB.db;Version=3;");
                if (list == null || currentTestQuestionData == null)
                {
                    throw new Exception("Question List or Question Data are not initialized!\nFatal Error!");
                }

                List <IncorrectAnswerData> incorrectAnswerDatas = new List <IncorrectAnswerData>();
                foreach (QuestionData qData in currentTestQuestionData)
                {
                    List <int> checkedAnswers = new List <int>();
                    List <int> correctAnswers = new List <int>();
                    foreach (CheckBox check in qData.AnswerCheckBoxes)
                    {
                        if ((bool)check.IsChecked)
                        {
                            checkedAnswers.Add(
                                Convert.ToInt32(check.Name.Split('_')[1].ToString())
                                );
                        }
                    }
                    sQLiteConnection.Open();
                    SQLiteCommand sCommand = new SQLiteCommand(sQLiteConnection)
                    {
                        CommandText = "select CorrectAnswers.answerId AS Odgovor from CorrectAnswers where CorrectAnswers.questonId = " + qData.QuestionId.ToString()
                    };
                    SQLiteDataReader sQ = sCommand.ExecuteReader();
                    while (sQ.Read())
                    {
                        correctAnswers.Add(sQ.GetInt32(0));
                    }

                    var answerCheck = checkedAnswers.Except(correctAnswers).ToList();
                    int emptyCheck  = correctAnswers.Except(checkedAnswers).ToList().Count;
                    if (answerCheck.Count > 0)
                    {
                        IncorrectAnswerData incorrect = new IncorrectAnswerData()
                        {
                            QuestionText = qData.QuestionText,
                            AnswerText   = new List <string>()
                        };
                        int i = 0;
                        foreach (var answer in answerCheck)
                        {
                            while (answer != Convert.ToInt32(qData.AnswerCheckBoxes[i].Name.Split('_')[1].ToString()))
                            {
                                i++;
                            }
                            incorrect.AnswerText.Add(((TextBlock)qData.AnswerCheckBoxes[i].Content).Text);
                        }
                        incorrectAnswerDatas.Add(incorrect);
                    }
                    else if (answerCheck.Count == 0 && emptyCheck > 0)
                    {
                        IncorrectAnswerData incorrect = new IncorrectAnswerData()
                        {
                            QuestionText = qData.QuestionText,
                            AnswerText   = new List <string>()
                        };
                        incorrect.AnswerText.Add("Question left empty");
                        incorrectAnswerDatas.Add(incorrect);
                    }
                    sQLiteConnection.Close();
                }
                if (incorrectAnswerDatas.Count > 0)
                {
                    string builder = "";
                    foreach (var incorrectAnswer in incorrectAnswerDatas)
                    {
                        builder += incorrectAnswer.QuestionText;
                        builder += "\n";
                        foreach (var error in incorrectAnswer.AnswerText)
                        {
                            builder += "- " + error + "\n";
                        }
                        builder += "------------------------------------\n";
                    }
                    builder += "\n " + (10 - incorrectAnswerDatas.Count) + "/10 correct answers \n";
                    new ErrorWindow("Incorrect Answers!", builder).ShowDialog();
                }
                else if (incorrectAnswerDatas.Count == 0)
                {
                    new ErrorWindow("Congratulations!", "Everything is correct!").ShowDialog();
                }
            }
            catch (Exception ex)
            {
                new ErrorWindow("Fatal error", ex.Message).ShowDialog();
            }
            finally
            {
                QuestionContainer.Visibility  = Visibility.Hidden;
                GenerateTestButton.Visibility = Visibility.Visible;
                list = null;
                currentTestQuestionData = null;
                foreach (var panel in questionStackPanelList)
                {
                    QuestionContainer.Children.Remove(panel);
                }
                QuestionContainer.Children.Remove(confirmationButton);
            }
        }