コード例 #1
0
        private static void CreateFIBQuestion(FIBQuestion question,
                                              int index,
                                              FlowDocument flowDocument,
                                              bool showAnswer,
                                              bool showResponse,
                                              FIBQuestionResponse response)
        {
            System.Windows.Documents.Section questionSection = new System.Windows.Documents.Section();
            flowDocument.Blocks.Add(questionSection);

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

            if (showAnswer)
            {
                lastParagraph.Inlines.Add(CreateText("。   正确答案:"));
                foreach (QuestionBlank blank in question.QuestionBlankCollection)
                {
                    lastParagraph.Inlines.Add(CreateText(blank.ReferenceAnswerList[0].Content + "  "));
                }
            }

            questionSection.Blocks.Add(questionContentBlock);
        }
コード例 #2
0
        internal static Paragraph CreateContentControl(QuestionContent content, string prefix, Paragraph paragraph, Response response)
        {
            Paragraph section = paragraph;

            if (section == null)
            {
                section = new Paragraph();
            }

            string questionContent = content.Content;
            int    startIndex      = 0;

            section.Inlines.Add(prefix);
            while (true)
            {
                startIndex = questionContent.IndexOf("_$", 0);
                if (startIndex >= 0)
                {
                    int    endIndex    = questionContent.IndexOf("$_", startIndex);
                    string placeHolder = questionContent.Substring(startIndex, endIndex - startIndex + 2);

                    string text = questionContent.Substring(0, startIndex);

                    if (!string.IsNullOrEmpty(text) &&
                        text[text.Length - 1] == '\n')
                    {
                        section.Inlines.Add(CreateText(text.Remove(text.Length - 1)));
                    }
                    else
                    {
                        section.Inlines.Add(CreateText(text));
                    }

                    QuestionContentPart part = content.GetContentPart(placeHolder);
                    if (response is FIBQuestionResponse)
                    {
                        FIBQuestionResponse fibResponse = response as FIBQuestionResponse;
                        section.Inlines.Add(CreateUIPart(part, fibResponse.GetBlankResponse(part.Id, false)));
                    }
                    else
                    {
                        section.Inlines.Add(CreateUIPart(part, null));
                    }

                    questionContent = questionContent.Remove(0, endIndex + 2);
                    if (string.IsNullOrEmpty(questionContent))
                    {
                        break;
                    }
                }
                else
                {
                    section.Inlines.Add(CreateText(questionContent));
                    break;
                }
            }

            return(section);
        }
コード例 #3
0
        public FIBQuestionUserControl(FIBQuestion fibQuestion, FIBQuestionResponse fibResponse, int index)
        {
            this.fibQuestion = fibQuestion;
            this.fibResponse = fibResponse;
            this.index       = index;

            InitializeComponent();
        }
コード例 #4
0
 internal static Inline CreateBlankWithResponse(FIBQuestionResponse fibResponse)
 {
     return(null);
 }
コード例 #5
0
        internal static System.Windows.Documents.Section CreateContentControl(QuestionContent content, string prefix, System.Windows.Documents.Section paragraph, Response response)
        {
            System.Windows.Documents.Section rootSection = paragraph;
            if (rootSection == null)
            {
                rootSection = new System.Windows.Documents.Section();
            }

            if (content.ContentType == ContentType.Html ||
                content.ContentType == ContentType.FlowDocument)
            {
                string doc = string.Empty;
                if (content.ContentType == ContentType.Html)
                {
                    doc = HtmlToXamlConverter.ConvertHtmlToXaml(content.Content, true);
                }
                else
                {
                    doc = content.Content;
                }

                System.Windows.Documents.FlowDocument flowDocument = HtmlToXamlConverter.DeserializeFlowDocument(doc);

                replaceTextBoxWithText(flowDocument, content, null);

                List <Block> tempList = new List <Block>();
                tempList.AddRange(flowDocument.Blocks);
                flowDocument.Blocks.Clear();
                rootSection.Blocks.AddRange(tempList);

                Paragraph firstPara = null;
                if (rootSection.Blocks.FirstBlock is Paragraph)
                {
                    firstPara = rootSection.Blocks.FirstBlock as Paragraph;
                }
                else
                {
                    firstPara = new Paragraph();
                    rootSection.Blocks.InsertBefore(rootSection.Blocks.FirstBlock, firstPara);
                }

                if (firstPara.Inlines.Count > 0)
                {
                    firstPara.Inlines.InsertBefore(firstPara.Inlines.FirstInline, new Run(prefix));
                }
                else
                {
                    firstPara.Inlines.Add(prefix);
                }
            }
            else
            {
                Paragraph para = null;
                if (rootSection.Blocks.LastBlock is Paragraph)
                {
                    para = rootSection.Blocks.LastBlock as Paragraph;
                }
                else
                {
                    para = new Paragraph();
                    rootSection.Blocks.Add(para);
                }

                string questionContent = content.Content;
                int    startIndex      = 0;

                para.Inlines.Add(prefix);

                while (true)
                {
                    startIndex = questionContent.IndexOf("_$", 0);
                    if (startIndex >= 0)
                    {
                        int    endIndex    = questionContent.IndexOf("$_", startIndex);
                        string placeHolder = questionContent.Substring(startIndex, endIndex - startIndex + 2);

                        string text = questionContent.Substring(0, startIndex);

                        if (!string.IsNullOrEmpty(text) &&
                            text[text.Length - 1] == '\n')
                        {
                            para.Inlines.Add(CreateText(text.Remove(text.Length - 1)));
                        }
                        else
                        {
                            para.Inlines.Add(CreateText(text));
                        }

                        QuestionContentPart part = content.GetContentPart(placeHolder);
                        if (response is FIBQuestionResponse)
                        {
                            FIBQuestionResponse fibResponse = response as FIBQuestionResponse;
                            para.Inlines.Add(CreateUIPart(part, fibResponse.GetBlankResponse(part.Id, false)));
                        }
                        else
                        {
                            para.Inlines.Add(CreateUIPart(part, null));
                        }

                        questionContent = questionContent.Remove(0, endIndex + 2);
                        if (string.IsNullOrEmpty(questionContent))
                        {
                            break;
                        }
                    }
                    else
                    {
                        para.Inlines.Add(CreateText(questionContent));
                        break;
                    }
                }
            }

            return(rootSection);
        }