Example #1
0
 private void btn_end_Click(object sender, EventArgs e)
 {
     for (int j = pan_display.Controls.OfType<RadioButton>().Count() - 1; j >= 0; --j)
     {
         var ctrls = pan_display.Controls.OfType<RadioButton>();
         var ctrl = ctrls.ElementAt(j);
         if (((RadioButton)ctrl).Checked)
         {
             givenAnswers[questionIndex] = Convert.ToChar(ctrl.Name.Replace("rdb_", ""));
         }
         pan_display.Controls.Remove(ctrl);
         ctrl.Dispose();
     }
     timer.Stop();
     //determine how many answers are correct and get section details
     int numOfCorrect = 0;
     int total;
     Dictionary<string, int> totalQuestionsPerSection = new Dictionary<string, int>();
     Dictionary<string, int> rightQuestionsPerSection = new Dictionary<string, int>();
     for (int i = 0; i < questions.Count; i++)
     {
         if (totalQuestionsPerSection.ContainsKey(questions.ElementAt(i).SectionTitle))
         {
             totalQuestionsPerSection[questions.ElementAt(i).SectionTitle] += 1;
         }
         else
         {
             totalQuestionsPerSection.Add(questions.ElementAt(i).SectionTitle, 1);
         }
         if (rightQuestionsPerSection.ContainsKey(questions.ElementAt(i).SectionTitle))
         {
             if (questions.ElementAt(i).QuestionAnswer == givenAnswers[i])
             {
                 rightQuestionsPerSection[questions.ElementAt(i).SectionTitle] += 1;
                 numOfCorrect += 1;
             }
         }
         else
         {
             rightQuestionsPerSection.Add(questions.ElementAt(i).SectionTitle, 0);
             if (questions.ElementAt(i).QuestionAnswer == givenAnswers[i])
             {
                 rightQuestionsPerSection[questions.ElementAt(i).SectionTitle] += 1;
                 numOfCorrect += 1;
             }
         }
     }
     total = questions.Count;
     Score_Sheet scs = new Score_Sheet(Properties.Settings.Default.CandidatesName, Properties.Settings.Default.TimerValue, totalSeconds / 60, examCode, ((numOfCorrect * 1000)/ total), passingScore, totalQuestionsPerSection, rightQuestionsPerSection);
     this.Hide();
     scs.ShowDialog();
     this.Close();
 }
Example #2
0
        private void UI_Load(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.FirstRun)
            {
                string OESFolderPath = Path.GetDirectoryName(Application.StartupPath);
                string OESExamplesFolderPath = Path.Combine(OESFolderPath, "Examples");
                if (Directory.Exists(OESExamplesFolderPath))
                {
                    string[] oesFilePaths = Directory.GetFiles(OESExamplesFolderPath, "*.oef", SearchOption.TopDirectoryOnly);
                    List<string> paths = new List<string>();
                    foreach (string oesFile in oesFilePaths)
                    {
                        for (int i = 0; i < dgv_exams.Rows.Count; i++)
                        {
                            paths.Add(dgv_exams.Rows[i].Cells[1].Value.ToString());
                        }
                        if (!(paths.Exists(p => p == oesFile)))
                        {
                            dgv_exams.Rows.Add(Path.GetFileNameWithoutExtension(oesFile), oesFile);
                        }
                    }
                    Properties.Settings.Default.FirstRun = false;
                    Properties.Settings.Default.Save();
                }
                else
                {
                    Properties.Settings.Default.FirstRun = false;
                    Properties.Settings.Default.Save();
                }
            }
            Dictionary<string, string> exams = new Dictionary<string, string>();
            if (Properties.Settings.Default.ExamPaths != null)
            {
                for (int i = 0; i < Properties.Settings.Default.ExamPaths.Count; i++)
                {
                    exams.Add(Properties.Settings.Default.ExamPaths[i], Properties.Settings.Default.ExamTitles[i]);
                }
            }
            dgv_exams.Rows.Clear();
            foreach (var exam in exams)
            {
                dgv_exams.Rows.Add(exam.Value, exam.Key);
            }

            //Select opened file
            if (!string.IsNullOrWhiteSpace(openedFilePath))
            {
                foreach(DataGridViewRow row in dgv_exams.Rows)
                {
                    if (row.Cells[1].Value.ToString() == openedFilePath)
                    {
                        row.Selected = true;
                    }
                }
            }
        }
Example #3
0
 public static List<Question> GetQuestions(string ExamFilesFolderPath)
 {
     List<Question> result = new List<Question>();
     string fileName = ExamFilesFolderPath.Replace(Path.GetDirectoryName(ExamFilesFolderPath), "");
     string[] sections = Question.GetSections(Properties.Settings.Default.SelectedSections);
     string xmlFilePath = GlobalPathVariables.GetXmlFilePath(ExamFilesFolderPath);
     XPathDocument doc = new XPathDocument(xmlFilePath);
     XPathNavigator nav = doc.CreateNavigator();
     XmlNamespaceManager nm = new XmlNamespaceManager(nav.NameTable);
     // Compile a standard XPath expression
     XPathExpression expr;
     XPathNodeIterator iterator;
     string version = "";
     expr = nav.Compile("//FileVersion");
     iterator = nav.Select(expr);
     while(iterator.MoveNext())
     {
         version = iterator.Current.Value;
     }
     for (int i = 0; i < sections.Length; i++)
     {
         expr = nav.Compile("//Section[@Title='" + sections[i] + "']/Question");
         iterator = nav.Select(expr);
         // Iterate on the node set
         while (iterator.MoveNext())
         {
             Question ques = new Question();
             ques.SectionTitle = sections[i];
             ques.QuestionNumber = Convert.ToInt32(iterator.Current.GetAttribute("No", nm.DefaultNamespace));
             Dictionary<char, string> options = new Dictionary<char, string>();
             XPathNodeIterator iter = iterator.Current.SelectChildren(XPathNodeType.Element);
             while (iter.MoveNext())
             {
                 if (iter.Current.LocalName == "Text")
                 {
                     ques.QuestionText = iter.Current.Value;
                 }
                 else if (iter.Current.LocalName == "Image")
                 {
                     ques.QuestionImagePath = iter.Current.Value;
                 }
                 else if (iter.Current.LocalName == "Answer")
                 {
                     ques.QuestionAnswer = Convert.ToChar(iter.Current.Value);
                 }
                 if (iter.Current.LocalName == "Options")
                 {
                     XPathNodeIterator ite = iter.Current.SelectChildren(XPathNodeType.Element);
                     while (ite.MoveNext())
                     {
                         char option;
                         string optionText;
                         string tempp = ite.Current.GetAttribute("Title", nm.DefaultNamespace);
                         option = Convert.ToChar(tempp);
                         optionText = ite.Current.Value;
                         options.Add(option, optionText);
                     }
                     ques.QuestionOptions = options;
                 }
                 if (version == "1.0")
                 {
                     ques.AnswerExplanation = "Version 1.0 files do not support explanations";
                 }
                 else
                 {
                     if (iterator.Current.LocalName == "AnswerExplanation")
                         ques.AnswerExplanation = iterator.Current.Value;
                 }
             }
             result.Add(ques);
         }
     }
     return result;
 }
        public void DisplayQuestion (NavigationOption option)
        {
            lbl_question_number.Visible = true;
            lbl_answer_explanation.Visible = false;
            lbl_section_title.Visible = true;
            label2.Visible = true;
            label3.Visible = true;
            txt_question.Visible = true;
            pic_image.Visible = true;
            
            if (option == NavigationOption.Begin)
            {
                currentQuestionIndex = 0;
                Question question = questions.ElementAt(currentQuestionIndex);
                lbl_question_number.Text = question.QuestionNumber.ToString();
                lbl_section_title.Text = question.SectionTitle;
                txt_question.Text = question.QuestionText;
                lbl_answer_explanation.Text = question.AnswerExplanation;
                if (!(string.IsNullOrWhiteSpace(question.QuestionImagePath)))
                {
                    string imagePath = Path.Combine(GlobalPathVariables.GetExamFilesFolder(filename), question.QuestionImagePath);
                    pic_image.ImageLocation = imagePath;
                }
                for (int i = 0; i < question.QuestionOptions.Count; i++)
                {
                    RadioButton rdb = new RadioButton();
                    rdb.AutoSize = true;
                    rdb.Text = question.QuestionOptions.ElementAt(i).Key + ". - " + question.QuestionOptions.ElementAt(i).Value;
                    rdb.Name = "rdb_" + question.QuestionOptions.ElementAt(i).Key;
                    rdb.Location = new Point(51, 464 + (i * 22));
                    pan_display.Controls.Add(rdb);
                }
                if ((Exam_Settings.ExamType.SelectedSections.ToString() == Properties.Settings.Default.ExamType && questions.Count == 1) || (Exam_Settings.ExamType.SelectedNumber.ToString() == Properties.Settings.Default.ExamType && Properties.Settings.Default.NumOfQuestions == 1))
                    btn_next.Enabled = false;
                this.Invalidate();
            }

            if (option == NavigationOption.Previous)
            {
                //determine the selected answer for this question and save it before moving to the previous question
                for (int j = pan_display.Controls.OfType<RadioButton>().Count() - 1; j >= 0; --j)
                {
                    var ctrls = pan_display.Controls.OfType<RadioButton>();
                    var ctrl = ctrls.ElementAt(j);
                    if (((RadioButton)ctrl).Checked)
                    {
                        givenAnswers[currentQuestionIndex] = Convert.ToChar(ctrl.Name.Replace("rdb_", ""));
                    }
                    pan_display.Controls.Remove(ctrl);
                    ctrl.Dispose();
                }
                if (currentQuestionIndex > 0)
                {
                    currentQuestionIndex -= 1;
                    Question question = questions.ElementAt(currentQuestionIndex);
                    lbl_question_number.Text = question.QuestionNumber.ToString();
                    lbl_section_title.Text = question.SectionTitle;
                    txt_question.Text = question.QuestionText;
                    lbl_answer_explanation.Text = question.AnswerExplanation;
                    if (string.IsNullOrWhiteSpace(question.QuestionImagePath))
                    {
                        pic_image.ImageLocation = "";
                    }
                    else
                    {
                        pic_image.ImageLocation = Path.Combine(GlobalPathVariables.GetExamFilesFolder(filename), question.QuestionImagePath);
                    }
                    for (int i = 0; i < question.QuestionOptions.Count; i++)
                    {
                        RadioButton rdb = new RadioButton();
                        rdb.AutoSize = true;
                        rdb.Text = question.QuestionOptions.ElementAt(i).Key + ". - " + question.QuestionOptions.ElementAt(i).Value;
                        rdb.Name = "rdb_" + question.QuestionOptions.ElementAt(i).Key;
                        rdb.Location = new Point(51, 464 + (i * 22));
                        if (question.QuestionOptions.ElementAt(i).Key == givenAnswers[currentQuestionIndex])
                            rdb.Checked = true;
                        pan_display.Controls.Add(rdb);
                    }
                    if (currentQuestionIndex == 0)
                    {
                        btn_previous.Enabled = false;
                    }
                }
            }

            if (option == NavigationOption.Next)
            {
                //determine the selected answer for this question and save it before moving to the next question
                for (int j = pan_display.Controls.OfType<RadioButton>().Count() - 1; j >= 0; --j)
                {
                    var ctrls = pan_display.Controls.OfType<RadioButton>();
                    var ctrl = ctrls.ElementAt(j);
                    if (((RadioButton)ctrl).Checked)
                    { 
                        givenAnswers[currentQuestionIndex] = Convert.ToChar(ctrl.Name.Replace("rdb_", ""));
                    }
                    pan_display.Controls.Remove(ctrl);
                    ctrl.Dispose();
                }
                currentQuestionIndex += 1;
                Question question = questions.ElementAt(currentQuestionIndex);
                lbl_question_number.Text = question.QuestionNumber.ToString();
                lbl_section_title.Text = question.SectionTitle;
                txt_question.Text = question.QuestionText;
                lbl_answer_explanation.Text = question.AnswerExplanation;
                if (string.IsNullOrWhiteSpace(question.QuestionImagePath))
                {
                    pic_image.ImageLocation = "";
                }
                else
                {
                    pic_image.ImageLocation = Path.Combine(GlobalPathVariables.GetExamFilesFolder(filename), question.QuestionImagePath);
                }
                for (int i = 0; i < question.QuestionOptions.Count; i++)
                {
                    RadioButton rdb = new RadioButton();
                    rdb.AutoSize = true;
                    rdb.Text = question.QuestionOptions.ElementAt(i).Key + ". - " + question.QuestionOptions.ElementAt(i).Value;
                    rdb.Name = "rdb_" + question.QuestionOptions.ElementAt(i).Key;
                    rdb.Location = new Point(51, 464 + (i * 22));
                    if (question.QuestionOptions.ElementAt(i).Key == givenAnswers[currentQuestionIndex])
                        rdb.Checked = true;
                    pan_display.Controls.Add(rdb);
                }
                btn_previous.Enabled = true;
                if ((Exam_Settings.ExamType.SelectedSections.ToString() == Properties.Settings.Default.ExamType && currentQuestionIndex == questions.Count - 1) || (Exam_Settings.ExamType.SelectedNumber.ToString() == Properties.Settings.Default.ExamType && currentQuestionIndex == Properties.Settings.Default.NumOfQuestions))
                    btn_next.Enabled = false;
                this.Invalidate();
            }           
 
            if (option == NavigationOption.End)
            {
                //determine the selected answer for this question and save it before ending the exam
                for (int j = pan_display.Controls.OfType<RadioButton>().Count() - 1; j >= 0; --j)
                {
                    var ctrls = pan_display.Controls.OfType<RadioButton>();
                    var ctrl = ctrls.ElementAt(j);
                    if (((RadioButton)ctrl).Checked)
                    {
                        givenAnswers[currentQuestionIndex] = Convert.ToChar(ctrl.Name.Replace("rdb_", ""));
                    }
                    pan_display.Controls.Remove(ctrl);
                    ctrl.Dispose();
                }
                //Stop the countdown timer
                timer.Stop();
                //determine how many answers are correct and get section details
                int numOfCorrect = 0;
                int total;
                Dictionary<string, int> totalQuestionsPerSection = new Dictionary<string, int>();
                Dictionary<string, int> rightQuestionsPerSection = new Dictionary<string, int>();
                for (int i = 0; i < questions.Count; i++)
                {
                    if (totalQuestionsPerSection.ContainsKey(questions.ElementAt(i).SectionTitle))
                    {
                        totalQuestionsPerSection[questions.ElementAt(i).SectionTitle] += 1;
                    }
                    else
                    {
                        totalQuestionsPerSection.Add(questions.ElementAt(i).SectionTitle, 1);
                    }
                    if (rightQuestionsPerSection.ContainsKey(questions.ElementAt(i).SectionTitle))
                    {
                        if (questions.ElementAt(i).QuestionAnswer == givenAnswers[i])
                        {
                            rightQuestionsPerSection[questions.ElementAt(i).SectionTitle] += 1;
                            numOfCorrect += 1;
                        }
                    }
                    else
                    {
                        rightQuestionsPerSection.Add(questions.ElementAt(i).SectionTitle, 0);
                        if (questions.ElementAt(i).QuestionAnswer == givenAnswers[i])
                        {
                            rightQuestionsPerSection[questions.ElementAt(i).SectionTitle] += 1;
                            numOfCorrect += 1;
                        }
                    }
                }
                total = questions.Count;
                Score_Sheet scs;
                if (Properties.Settings.Default.ExamType == Exam_Settings.ExamType.SelectedNumber.ToString())
                {
                    scs = new Score_Sheet(totalSeconds / 60.0, examCode, ((numOfCorrect * 1000) / Properties.Settings.Default.NumOfQuestions), totalQuestionsPerSection, rightQuestionsPerSection);
                }
                else
                {
                    scs = new Score_Sheet(totalSeconds / 60.0, examCode, ((numOfCorrect * 1000) / total), totalQuestionsPerSection, rightQuestionsPerSection);
                }
                this.Hide();
                scs.ShowDialog();
                this.Close();
            }
        }