Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
 private void NavigateExam(NavOption option)
 {
     lbl_explanation.Visible = false;
     //
     if (option == NavOption.Begin)
     {
         if (settings.Questions.Count > 0)
         {
             currentQuestionIndex = 0;
             PrintQuestionToScreen();
         }
         //
         if (settings.Questions.Count > 1)
         {
             btn_next.Enabled = true;
         }
     }
     else if (option == NavOption.Next)
     {
         //Save current answer
         userAnswers[currentQuestionIndex] = SelectedAnswer();
         //
         RemoveOptions();
         //
         currentQuestionIndex++;
         PrintQuestionToScreen();
         //
         btn_previous.Enabled = true;
         //
         if (currentQuestionIndex == settings.Questions.Count - 1)
         {
             btn_next.Enabled = false;
         }
     }
     else if (option == NavOption.Previous)
     {
         //Save current answer
         userAnswers[currentQuestionIndex] = SelectedAnswer();
         //
         RemoveOptions();
         //
         currentQuestionIndex--;
         PrintQuestionToScreen();
         //
         btn_next.Enabled = true;
         //
         if (currentQuestionIndex == 0)
         {
             btn_previous.Enabled = false;
         }
     }
     else if (option == NavOption.End)
     {
         //Save current answer
         userAnswers[currentQuestionIndex] = SelectedAnswer();
         //
         settings.ElapsedTime = TimeSpan.FromSeconds(exam.Properties.TimeLimit * 60 - timeLeft);
         //
         int numOfCorrectAnswers = 0;
         for (int i = 0; i < settings.Questions.Count; i++)
         {
             if (userAnswers[i] == settings.Questions[i].Answer)
             {
                 numOfCorrectAnswers++;
             }
         }
         settings.NumberOfCorrectAnswers = numOfCorrectAnswers;
         //
         foreach (var section in settings.Sections)
         {
             int numOfQuestions = 0;
             int numOfCorrect   = 0;
             for (int i = 0; i < settings.Questions.Count; i++)
             {
                 if (section.Questions.Contains(settings.Questions[i]))
                 {
                     numOfQuestions++;
                     if (userAnswers[i] == settings.Questions[i].Answer)
                     {
                         numOfCorrect++;
                     }
                 }
             }
             settings.ResultSpread.Add(new Tuple <string, int, int>(section.Title, numOfQuestions, numOfCorrect));
         }
         //
         Score_Sheet ss = new Score_Sheet(settings, exam);
         this.Hide();
         ss.ShowDialog();
         this.Close();
     }
 }
Ejemplo n.º 3
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();
 }