예제 #1
0
        /// <summary>
        /// 试题类型处理
        /// 1.单(多)项选择题拆分选项。
        /// 2.填空题添加标识
        /// 3.判断题转换数据
        /// </summary>
        /// <param name="subjectitem">题目内容</param>
        /// <param name="subjecttype">题目类型</param>
        /// <returns></returns>
        public static void SubjectTypeMarkAndCreateOption(Subject subjectitem)
        {
            int subjecttype =(int)subjectitem.题目类型;
             //html = HtmlUtil.htmlreplace(html);
             if (subjecttype == Subject.SubjecttypeEnum.单选题.GetHashCode() || subjecttype == Subject.SubjecttypeEnum.多选题.GetHashCode())
             {
                // var strs = subjectitem.
                string tempsubjecthtmlcontent = HtmlUtil.selectSubjectOptionMarkUpload(subjectitem.subjecthtmlcontent);
                subjectitem.subjecthtmlcontent = HtmlUtil.selectSubjectOptionMarkUpload(subjectitem.subjecthtmlcontent, "<check>$0</check>");
                // subjectitem.subjecthtmlcontent = Regex.Replace(subjectitem.subjecthtmlcontent, " ((&nbsp;)|[\\s])*([ABCDEFG]{1})[\\s]*[^.]", "<nocheck>$0</nocheck>", RegexOptions.Multiline | RegexOptions.Singleline);

                 bool isanswer = false;
                 string[] htmls = Regex.Split(tempsubjecthtmlcontent, MatchArray.Select_Option, RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline);

                 for (int i = 0; i < htmls.Length; i++)
                 {
                     if (i > 0)
                     {
                         isanswer = false;
                         //判断答案是否正确
                         isanswer = SelectAnswerPair(subjectitem, i, isanswer);
                         string answercontent = ReplaceHTML(htmls[i]).Replace("</img>", "");
                         Answer answer = new Answer(answercontent, isanswer, i);
                         subjectitem.answers.Add(answer);
                     }
                     subjectitem.subjecthtmlcontent = subjectitem.subjecthtmlcontent.Replace(htmls[i], new Regex("[A-G]").Replace(new Regex("<.+?>", RegexOptions.Singleline).Replace(htmls[i], (x) => { return x.Groups[0].Value.ToLower(); }), "<nocheck>$0</nocheck>"));
                 }
                 return;
             }
             else if (subjecttype == Subject.SubjecttypeEnum.填空题.GetHashCode())
             {
                 string tempsubjecthtmlcontent = HtmlUtil.spacePlaceMarkUpLoad(subjectitem.subjecthtmlcontent);
                 Regex regex = new Regex("[^\\<check\\>]<u>.+?</u>",RegexOptions.IgnoreCase|RegexOptions.Singleline);
                 subjectitem.subjecthtmlcontent = HtmlUtil.spacePlaceMarkUpLoad(subjectitem.subjecthtmlcontent, "<check>$0</check>");
                 subjectitem.subjecthtmlcontent = regex.Replace(subjectitem.subjecthtmlcontent, "<nocheck>$0</nocheck>");
                 Regex regspacenum = new Regex(MatchArray.Space_Num);
                 int i = 0;

                 // 取得匹配项列表
                 while (regspacenum.IsMatch(tempsubjecthtmlcontent))
                 {
                     tempsubjecthtmlcontent = regspacenum.Replace(tempsubjecthtmlcontent, string.Format(MatchArray.Space_Num_Replace, i + 1), 1);
                     i++;
                 }

                 int sort = 0;//答案顺序
                 string[] answerarr = subjectitem.answer.subjecthtmlanswer.Split('|');

                 foreach (string content in answerarr)
                 {
                     string html = ReplaceHTML(content).Replace("</img>","");
                     //如果答案的长度比填空空格多,则去掉为空的答案
                     if (string.IsNullOrEmpty(html))
                     {
                         if (answerarr.Length <= i)
                         {
                             sort++;
                             Answer answer = new Answer(html, true, sort);
                             subjectitem.answers.Add(answer);
                         }
                     }
                     else
                     {
                         sort++;
                         Answer answer = new Answer(html, true, sort);
                         subjectitem.answers.Add(answer);
                     }
                 }
                 while (sort < i)
                 {
                     sort++;
                     Answer answer = new Answer("", true, sort);
                     subjectitem.answers.Add(answer);
                 }
                 return;
             }
             else if (subjecttype == Subject.SubjecttypeEnum.判断题.GetHashCode())
             {
                 string answerstr = "0";
                 if (subjectitem.answer.subjecttextanswer.IndexOf("正确") >= 0 || subjectitem.answer.subjecttextanswer.IndexOf("对") >= 0)
                     answerstr = "1";
                 Answer answer = new Answer(answerstr, true, 1);
                 subjectitem.answers.Add(answer);
                 return;
             }
             Answer answerother = new Answer(subjectitem.answer.subjecttextanswer, true, 1);
             subjectitem.answers.Add(answerother);
        }
예제 #2
0
파일: MainForm.cs 프로젝트: Kristd/backup
        /// <summary>
        /// 试题类型处理
        /// 1.单(多)项选择题拆分选项。
        /// 2.填空题添加标识
        /// 3.判断题转换数据
        /// </summary>
        /// <param name="subjectitem">题目内容</param>
        /// <param name="subjecttype">题目类型</param>
        /// <returns></returns>
        private void SubjectTypeMarkAndCreateOption(ref SubjectItem subjectitem, int subjecttype)
        {
            //html = HtmlUtil.htmlreplace(html);
            if (subjecttype == Subject.SubjecttypeEnum.单选题.GetHashCode() || subjecttype == Subject.SubjecttypeEnum.多选题.GetHashCode())
            {
                subjectitem.subjecthtmlcontent = HtmlUtil.selectSubjectOptionMarkUpload(subjectitem.subjecthtmlcontent);
                string tempsubjecthtmlcontent = subjectitem.subjecthtmlcontent;//临时存放试题提干变量

                bool isanswer = false;
                string[] htmls = Regex.Split(tempsubjecthtmlcontent, MatchArray.Select_Option, RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline);
                for (int i = 0; i < htmls.Length; i++)
                {
                    if (i == 0)
                    {
                        subjectitem.subjecthtmlcontent = SubjectTool.ReplaceHTML(htmls[i]);
                    }
                    else
                    {
                        isanswer = false;
                        //判断答案是否正确
                        isanswer = SelectAnswerPair(subjectitem, i, isanswer);
                        string answercontent = SubjectTool.ReplaceHTML(htmls[i]);
                        Answer answer = new Answer(answercontent, isanswer, i);
                        subjectitem.answers.Add(answer);
                    }
                }

                return;
            }

            if (subjecttype == Subject.SubjecttypeEnum.填空题.GetHashCode())
            {
                subjectitem.subjecthtmlcontent = HtmlUtil.spacePlaceMarkUpLoad(subjectitem.subjecthtmlcontent);
                Regex regspacenum = new Regex(MatchArray.Space_Num);
                int i = 0;
                // 取得匹配项列表
                while (regspacenum.IsMatch(subjectitem.subjecthtmlcontent))
                {
                    subjectitem.subjecthtmlcontent = regspacenum.Replace(subjectitem.subjecthtmlcontent, string.Format(MatchArray.Space_Num_Replace, i + 1), 1);
                    i++;
                }
                int sort = 0;//答案顺序
                string[] answerarr = subjectitem.answerhtmlcontent.Split('|');
                foreach (string content in answerarr)
                {
                    sort++;
                    Answer answer = new Answer(SubjectTool.ReplaceHTML(content), true, sort);
                    subjectitem.answers.Add(answer);
                }
                while (sort < i)
                {
                    sort++;
                    Answer answer = new Answer("", true, sort);
                    subjectitem.answers.Add(answer);
                }
                return;
            }
            if (subjecttype == Subject.SubjecttypeEnum.判断题.GetHashCode())
            {
                string answerstr = "0";
                if (subjectitem.answertextcontent.IndexOf("正确") >= 0 || subjectitem.answertextcontent.IndexOf("对") >= 0)
                    answerstr = "1";
                Answer answer = new Answer(answerstr, true, 1);
                subjectitem.answers.Add(answer);
                return;
            }
            Answer answerother = new Answer(subjectitem.answerhtmlcontent, true, 1);
            subjectitem.answers.Add(answerother);
        }