Beispiel #1
0
        public TableQuestionUserControl(TableQuestion mrQuestion, SelectableQuestionResponse response)
        {
            this.mrQuestion = mrQuestion;
            this.response   = response;

            InitializeComponent();
        }
        public MCQuestionUserControl(MCQuestion mcQuestion, SelectableQuestionResponse response, int index)
        {
            this.mcQuestion = mcQuestion;
            this.index      = index;
            this.response   = response;

            InitializeComponent();
        }
Beispiel #3
0
        public MCQuestionUserControl(SelectableQuestion selectableQuestion, SelectableQuestionResponse response, int index)
        {
            this.selectableQuestion = selectableQuestion;
            this.index    = index;
            this.response = response;

            InitializeComponent();

            this.toggleButtonCheckedHandler = (s, e) =>
            {
                this.radioBtn_Checked(s, e);
            };

            this.toggleButtonUnCheckedHandler = (s, e) =>
            {
                this.radioBtn_UnChecked(s, e);
            };
        }
        private static Paragraph CreateTableQuestion(TableQuestion question,
                                                     int index,
                                                     FlowDocument flowDocument,
                                                     bool showAnswer,
                                                     bool showResponse,
                                                     SelectableQuestionResponse response)
        {
            Paragraph questionPara = new Paragraph();

            flowDocument.Blocks.Add(questionPara);

            Run questionBodyRun = new Run((index + 1).ToString() + ". " + question.Content.Content + "\n");

            questionPara.Inlines.Add(questionBodyRun);

            Table         optionTable   = new Table();
            TableRowGroup tableRowGroup = new TableRowGroup();

            optionTable.RowGroups.Add(tableRowGroup);
            flowDocument.Blocks.Add(optionTable);

            int i        = 0;
            int rowCount = (int)System.Math.Sqrt(question.QuestionOptionCollection.Count);

            for (int row = 0; row < rowCount; row++)
            {
                tableRowGroup.Rows.Add(new TableRow());
                TableRow tableRow = tableRowGroup.Rows[row];
                for (int col = 0; col < rowCount; col++)
                {
                    QuestionOption option = question.QuestionOptionCollection[i++];

                    System.Windows.Documents.Section optionPara = CreateContentControl(option.OptionContent, string.Empty, null, response);
                    if (showResponse)
                    {
                        if (Enumerable.Count <string>(Enumerable.Where <string>(response.OptionIdList, (c => (c == option.Id)))) > 0)
                        {
                            optionPara.FontWeight = FontWeights.Bold;
                            optionPara.FontSize   = 16f;
                            optionPara.FontStyle  = FontStyles.Italic;
                        }
                    }
                    TableCell cell = new TableCell(optionPara);
                    cell.BorderThickness = new Thickness(1);
                    cell.BorderBrush     = new SolidColorBrush(Colors.Black);
                    cell.TextAlignment   = TextAlignment.Center;
                    cell.LineHeight      = 30f;
                    tableRow.Cells.Add(cell);
                }
            }

            if (showAnswer)
            {
                System.Windows.Documents.Section answerSection = new System.Windows.Documents.Section();

                Paragraph answerPara = new Paragraph();

                answerSection.Blocks.Add(answerPara);

                flowDocument.Blocks.Add(answerSection);

                answerPara.Inlines.Add("答案:");
                foreach (QuestionOption option in question.QuestionOptionCollection)
                {
                    if (option.IsCorrect)
                    {
                        CreateContentControl(option.OptionContent, " ", answerSection, response);
                        answerPara.Inlines.Add(", ");
                    }
                }
            }

            return(questionPara);
        }
        private static void CreateMCQuestion(SelectableQuestion question,
                                             int index,
                                             FlowDocument flowDocument,
                                             bool showAnswer,
                                             bool showResponse,
                                             SelectableQuestionResponse response)
        {
            System.Windows.Documents.Section questionSection = new System.Windows.Documents.Section();
            flowDocument.Blocks.Add(questionSection);

            // Shuffle options
            List <int> optionIndexList = new List <int>();

            if (question.RandomOption)
            {
                Random rand = new Random((int)DateTime.Now.Ticks);
                while (true)
                {
                    int  i     = rand.Next(question.QuestionOptionCollection.Count * 10) % question.QuestionOptionCollection.Count;
                    bool found = false;
                    foreach (int temp in optionIndexList)
                    {
                        if (temp == i)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        optionIndexList.Add(i);
                    }

                    if (optionIndexList.Count == question.QuestionOptionCollection.Count)
                    {
                        break;
                    }

                    Thread.Sleep(10);
                }
            }
            else
            {
                for (int i = 0; i < question.QuestionOptionCollection.Count; i++)
                {
                    optionIndexList.Add(i);
                }
            }

            System.Windows.Documents.Section questionContentBlock = CreateContentControl(question.Content, (index + 1).ToString() + ". ", null, response);
            Paragraph lastParagraph = null;

            if (questionContentBlock.Blocks.LastBlock is Paragraph)
            {
                lastParagraph = questionContentBlock.Blocks.LastBlock as Paragraph;
            }
            if (lastParagraph == null)
            {
                lastParagraph = new Paragraph();
                questionContentBlock.Blocks.Add(lastParagraph);
            }
            if (showResponse)
            {
                if (Enumerable.Count <string>(response.OptionIdList) > 0)
                {
                    for (int i = 0; i < question.QuestionOptionCollection.Count; i++)
                    {
                        QuestionOption option = question.QuestionOptionCollection[optionIndexList[i]];
                        if (option.Id == response.OptionIdList[0])
                        {
                            lastParagraph.Inlines.Add(CreateText(" ( " + (char)('A' + i) + " )"));
                            break;
                        }
                    }
                }
                else
                {
                    lastParagraph.Inlines.Add(CreateText("(    )"));
                }
            }
            else
            {
                lastParagraph.Inlines.Add(CreateText("(    )"));
            }

            if (showAnswer)
            {
                for (int i = 0; i < question.QuestionOptionCollection.Count; i++)
                {
                    QuestionOption option = question.QuestionOptionCollection[optionIndexList[i]];
                    if (option.IsCorrect)
                    {
                        lastParagraph.Inlines.Add(CreateText("    正确答案:" + (char)('A' + i)));
                        break;
                    }
                }
            }

            questionSection.Blocks.Add(questionContentBlock);

            for (int i = 0; i < question.QuestionOptionCollection.Count; i++)
            {
                QuestionOption option = question.QuestionOptionCollection[optionIndexList[i]];
                System.Windows.Documents.Section optionSec = CreateContentControl(option.OptionContent, string.Format("\t{0}. ", (char)('A' + i)), null, response);
                List <Block> tempList = new List <Block>();
                tempList.AddRange(optionSec.Blocks);
                optionSec.Blocks.Clear();

                questionSection.Blocks.AddRange(tempList);
            }
        }