Пример #1
0
        public string GetOptionText(MultiChoiceOption opt)
        {
            switch (opt)
            {
            case MultiChoiceOption.A:
                return(OptionA);

            case MultiChoiceOption.B:
                return(OptionB);

            case MultiChoiceOption.C:
                return(OptionC);

            case MultiChoiceOption.D:
                return(OptionD);

            default:
                return("invalid arg");
            }
        }
Пример #2
0
        private void DrawQuestion(MarkingQuestion mq, Document doc)
        {
            //Get the question
            Question question = smd.Scripts.First().Script.FindQuestion(mq.QuestionName);

            Paragraph mainPara = new Paragraph();

            mainPara.SpacingBefore   = 20f;
            mainPara.IndentationLeft = GetIndent(mq.QuestionName);

            //Question header text
            Phrase questionHeader = new Phrase(mq.QuestionName, QuestionHeaderFont);

            mainPara.Add(questionHeader);
            if (question.AnswerType != AnswerType.None)
            {
                //Marks
                mainPara.Add(new Chunk(new VerticalPositionMark()));
                mainPara.Add(new Chunk($"Marks: {mq.AssignedMarks.ToString("0.#")} / {question.Marks}", MarksHeaderFont));
            }
            mainPara.Add("\n");

            //Question text
            Paragraph questionTextPara = new Paragraph(question.QuestionTextRaw, QuestionTextFont);

            questionTextPara.FirstLineIndent = 15f;
            mainPara.Add(questionTextPara);
            mainPara.Add("\n");

            //Question image
            if (question.Image != null)
            {
                try
                {
                    Image i = Image.GetInstance(question.Image, System.Drawing.Imaging.ImageFormat.Jpeg);
                    i.ScaleToFit(doc.PageSize.Width - 70f, i.Height);
                    mainPara.Add(i);
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"An error occured adding image from {question.Name}\n\n {ex.Message}", "Error adding image", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            //Multi Choice options if applicable
            if (question.AnswerType == AnswerType.Multi)
            {
                Phrase    optA        = new Phrase($"A) {question.OptionA}\n", QuestionTextFont);
                Phrase    optB        = new Phrase($"B) {question.OptionB}\n", QuestionTextFont);
                Phrase    optC        = new Phrase($"C) {question.OptionC}\n", QuestionTextFont);
                Phrase    optD        = new Phrase($"D) {question.OptionD}\n", QuestionTextFont);
                Paragraph optionsPara = new Paragraph();
                optionsPara.Add(optA);
                optionsPara.Add(optB);
                optionsPara.Add(optC);
                optionsPara.Add(optD);
                mainPara.Add(optionsPara);
            }

            //Model answer
            if (question.AnswerType != AnswerType.None)
            {
                if (includeModelAnswers && !question.ModelAnswer.NullOrEmpty())
                {
                    mainPara.Add(new Phrase("Model answer: \n", ModelAnswerHeaderFont));
                    if (question.AnswerType == AnswerType.Multi)
                    {
                        Paragraph multiAnswerPara = new Paragraph($"The correct option was: ({question.CorrectOption}) {question.GetOptionText(question.CorrectOption)}", QuestionTextFont);
                        mainPara.Add(multiAnswerPara);
                    }
                    else
                    {
                        Paragraph longAnswerPara = new Paragraph(question.ModelAnswer, QuestionTextFont);
                        mainPara.Add(longAnswerPara);
                    }
                    mainPara.Add("\n");
                }

                //Student response
                mainPara.Add(new Phrase("Student answer: \n", ModelAnswerHeaderFont));
                Answer answer = smd.Scripts.First().Script.Answers[mq.QuestionName];
                if (answer.Attempted)
                {
                    if (question.AnswerType == AnswerType.Multi)
                    {
                        MultiChoiceOption opt = answer.SelectedOption;
                        mainPara.Add(new Paragraph($"Student answered option ({opt}) {question.GetOptionText(opt)}", QuestionTextFont));
                    }
                    else
                    {
                        string sAnswer = question.AnswerType == AnswerType.Open ? answer.LongAnswer : answer.ShortAnswer;
                        mainPara.Add(new Paragraph(sAnswer, QuestionTextFont));
                    }
                }
                else
                {
                    mainPara.Add(new Paragraph("Student did not answer", QuestionTextFont));
                }
                mainPara.Add("\n");

                //Marker response
                if (!mq.MarkerResponse.NullOrEmpty())
                {
                    mainPara.Add(new Phrase("Marker response: \n", ModelAnswerHeaderFont));
                    mainPara.Add(new Paragraph(mq.MarkerResponse, QuestionTextFont));
                    mainPara.Add("\n");
                }
            }

            doc.Add(mainPara);
        }