/// <summary> /// 递归查询子节中题内容是否重复 /// /// </summary> /// <param name="subject">传入节点的subject信息</param> /// <param name="node">递归节点</param> /// <returns></returns> private bool isnodeexistnode(Subject subject, TreeNode node) { Subject existsubject = (Subject)node.Tag; if (node.Nodes.Count == 0 && existsubject != null && node.Level > 0)//判断除父节点以外的节点 { if (subject.rangeend <= existsubject.rangestart || subject.rangestart >= existsubject.rangeend) { return false; } else { return true; } } else { for (int i = 0; i < node.Nodes.Count; i++) { if (isnodeexistnode(subject, node.Nodes[i])) return true; } return false; } }
/// <summary> /// 过滤内容显示html预览以及添加试题列表节点 /// </summary> /// <param name="isSpot">是否为自动判题,用来判断是否需要显示提示信息</param> private void SubjectContentBuild(bool isSpot, TreeNode treenode, SubjectStructure subjectstructure) { Subject subject = new Subject();//创建试题对象 subject.rangestart = mainContent1.WordBrowers.document.Application.Selection.Range.Start;//取得当前范围 subject.rangeend = mainContent1.WordBrowers.document.Application.Selection.Range.End;//取得当前范围 if (!isexistnode(subject, treenode))//判断是否该题已存在,如果存在提示重新选择 { if (ischildnode(subject, treenode))//并且如果是大题下面的第一级子题,则验证范围界限 { if (behindJudage(subject, treenode))//判断属于题目后面的内容 ,如果选择了该节点前面的内容提示选择, { mainContent1.WordBrowers.document.Application.Selection.Range.Copy();//包括题目前ID号内容的范围 String cliptext = ClipboardHelper.getClipboardText().TrimStart(); subject.subjecttextcontent = cliptext; int prelength = 0;//定义前段返回的字符串 string sequencestr = MatchContent.matchRe(subjectstructure.subjectPre, cliptext, ref prelength); TreeNode tn = new TreeNode(); int sequence = 1;//试题在套卷中的排序号 try { sequence = Int16.Parse(sequencestr); } catch (Exception ex) { sequence = 1; } subject.套卷序号 = sequence; if (cliptext.Length > 20) { tn.Text = cliptext.Substring(0, 20); } else { tn.Text = cliptext; } tn.Tag = subject;//对应内容属性 tn.Expand(); treenode.Nodes.Add(tn); treenode.Expand(); this.propertyGrid.SelectedObject = subject; //if (subjectstructure.childsubjectStructure != null)//判断是否还需判断子题 //{ // int subjectend = 0;//结束结束返回 // bool subjectb = SubjectBuild(tn, subjectstructure.childsubjectStructure, ref subjectend); // if (!subjectb)//没有字节点 // { // int end = 0;//结束位置返回 // bool bansw = answerspot(ref tn, ref end); // if (bansw)//存在答案。更新题目内容界定范围 // { // mainContent1.WordBrowers.document.Application.Selection.SetRange(subject.rangestart + prelength, end); // } // else // { // mainContent1.WordBrowers.document.Application.Selection.SetRange(subject.rangestart + prelength, subject.rangeend); // } // mainContent1.WordBrowers.document.Application.Selection.Range.Copy();//不包括题目前ID号内容的范围 // String html = ClipboardHelper.getClipboardHtml(); // HtmlUtil.htmlProcess(ref html); // this.webBrowser.DocumentText = html; // subject.subjecthtmlcontent = html; // subject.subjectbinarycontent = ClipboardHelper.getClipboardEmbed(); // } // else//更新题干或者大题内容范围 // { // mainContent1.WordBrowers.document.Application.Selection.SetRange(subject.rangestart + prelength, subjectend); // mainContent1.WordBrowers.document.Application.Selection.Range.Copy();//不包括题目前ID号内容的范围 // String html = ClipboardHelper.getClipboardHtml(); // HtmlUtil.htmlProcess(ref html); // this.webBrowser.DocumentText = html; // subject.subjecthtmlcontent = html; // subject.subjectbinarycontent = ClipboardHelper.getClipboardEmbed(); // } //} //else//没有子节点 //{ int end = 0; bool bansw = answerspot(ref tn, ref end); if (bansw || MessageBox.Show("确认此题不需要答案吗?","提示", MessageBoxButtons.OKCancel).Equals(DialogResult.OK))//存在答案。更新题目内容界定范围 { if (bansw) { mainContent1.WordBrowers.document.Application.Selection.SetRange(subject.rangestart + prelength, end); } else { mainContent1.WordBrowers.document.Application.Selection.SetRange(subject.rangestart + prelength, subject.rangeend); } } else { treenode.Nodes.Remove(tn); return; //mainContent1.WordBrowers.document.Application.Selection.SetRange(subject.rangestart + prelength, subject.rangeend); } mainContent1.WordBrowers.document.Application.Selection.Range.Copy();//不包括题目前ID号内容的范围 String html = ClipboardHelper.getClipboardHtml(); HtmlUtil.HtmlPictureMove(ref html); this.webBrowser.DocumentText = html; subject.subjecthtmlcontent = html; //subject.subjectbinarycontent = ClipboardHelper.getClipboardEmbed(); // } } else if (!isSpot) { MessageBox.Show("题目子题必须是题目下面的内容!"); } } else if (!isSpot) { MessageBox.Show("子题不能超过大题范围!"); } } else if (!isSpot) { MessageBox.Show("同一内容不能属于多个题目!"); } }
private bool ischildnode(Subject subject, TreeNode treenode) { TreeNode rootParentNode = getTreenodeRootParent(treenode); Subject existsubject = (Subject)rootParentNode.Tag; if (existsubject.rangestart <= subject.rangestart && existsubject.rangeend >= subject.rangeend) { return true; } return false; }
/// <summary> /// 判断节点是否已经存在 /// </summary> /// <param name="subject">传入节点的subject信息</param> /// <returns></returns> private bool isexistnode(Subject subject,TreeNode treenode) { for (int i = 0; i < treenode.Nodes.Count; i++) { if (isnodeexistnode(subject, treenode.Nodes[i])) return true; } return false; }
private bool behindJudage(Subject subject, TreeNode treenode) { Subject existsubject = (Subject)treenode.Tag; if (treenode.Level== 0 || existsubject.rangeend <= subject.rangestart) { return true; } return false; }
/// <summary> /// /// </summary> /// <param name="isSpotWord">区分是否是点击拆分按钮触发的</param> private void initTreeRootNode(bool isSpotWord) { this.treeViewSubject.SelNodes = null; this.treeViewSubject.CheckedNodes = null; this.treeViewSubject.Nodes.Clear(); MartianSpot martianSpot = new MartianSpot(); List<SubjectInfo> listsubject = null; try { this.progressBarSpot.Visible = true; progressBarSpot.Maximum = mainContent1.WordBrowers.document.Paragraphs.Count - 1; progressBarSpot.Minimum = 0; progressBarSpot.Value = 0; progressBarSpot.Step = 10; bool haspublicanswer = false;//是否存在全局答案 //得到匹配的题目列表 listsubject = martianSpot.subjectSpot(mainContent1.WordBrowers.document, ref this.progressBarSpot, MatchArray.BigSubjectPre, ref haspublicanswer); progressBarSpot.Maximum = listsubject.Count; progressBarSpot.Step = 1; progressBarSpot.Value = 0; for (int i = 0; i < listsubject.Count; i++) { SubjectInfo subjectInfo = listsubject[i]; int start = subjectInfo.paragraphsStart; int end = subjectInfo.paragraphsEnd; ; //设定选择范围 mainContent1.WordBrowers.document.Application.Selection.SetRange(start, end); //更新目录栏 mainContent1.WordBrowers.document.Application.Selection.Range.Copy(); String bigsubjecttext = ClipboardHelper.getClipboardText(); string bigSubjectLine = mainContent1.WordBrowers.document.Application.Selection.Range.Text; string subjectname = MatchContent.matchRe(MatchArray.BigSubjectPre, bigsubjecttext); TreeNode subnode = new TreeNode(); subnode.Text = subjectname; //设置node在文本中的管理范围 Subject subject = new Subject(); subject.rangestart = listsubject[i].paragraphsStart; if (i == listsubject.Count - 1) { object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */ //最后一题将范围移动至文档结束 subject.rangeend = mainContent1.WordBrowers.document.Bookmarks.get_Item(ref oEndOfDoc).Range.End; } else { subject.rangeend = listsubject[i + 1].paragraphsStart; } subnode.Tag = subject; this.treeViewSubject.Nodes.Add(subnode); if (isSpotWord) { int temp = 0;//此值在这里无用 SubjectBuild(subnode, MatchArray.SubjectPreStructure, ref temp); } //更新进度条 progressBarSpot.Value = i; progressBarSpot.PerformStep(); } } catch (NullReferenceException ex) { MessageBox.Show("请先在程序中打开word文件。"); } finally { this.progressBarSpot.Visible = false; } }
/// <summary> /// 过滤内容显示html预览以及添加试题列表节点 /// </summary> /// <param name="isSpot">是否为自动判题,用来判断是否需要显示提示信息</param> /// <param name="subjectstructure">试题匹配规则正则结构</param> /// <param name="treenode">节点信息</param> private void SubjectContentBuild(bool isSpot, TreeNode treenode, SubjectStructure subjectstructure) { Subject subject = new Subject();//创建试题对象 subject.rangestart = mainContent1.WordBrowers.document.Application.Selection.Range.Start;//取得当前范围 subject.rangeend = mainContent1.WordBrowers.document.Application.Selection.Range.End;//取得当前范围 //if (!isexistnode(subject, treenode) )//判断是否该题已存在 //{ //if (ischildnode(subject, treenode))//判断属于子节点范围 // { mainContent1.WordBrowers.document.Application.Selection.Range.Copy();//包括题目前ID号内容的范围 String cliptext = ClipboardHelper.getClipboardText(); //subject.subjecttextcontent = cliptext; int prelength = 0;//定义前段返回的字符串 TreeNode tn = new TreeNode(); string sequencestr = MatchContent.matchRe(subjectstructure.subjectPre, cliptext, ref prelength); int sequence = 1;//试题在套卷中的排序号 try { sequence = Int16.Parse(sequencestr); } catch (Exception ex) { sequence = 1; } subject.套卷序号 = sequence; //this.webBrowser.DocumentText = html; //subject.subjecthtmlcontent = html; //subject.subjectbinarycontent = ClipboardHelper.getClipboardEmbed(); if (cliptext.Length > 20) { tn.Text = cliptext.Substring(0, 20); } else { tn.Text = cliptext; } tn.Tag = subject;//对应内容属性 tn.Expand(); treenode.Nodes.Add(tn); treenode.Expand(); this.propertyGrid.SelectedObject = subject; if (subjectstructure.childsubjectStructure != null)//判断是否还需判断子题 { int subjectend = 0;//结束结束返回 bool subjectb = SubjectBuild(tn, subjectstructure.childsubjectStructure, ref subjectend,null,null); if (!subjectb)//没有字节点 { int end = 0;//结束位置返回 bool bansw = AnswerSpot(ref tn, ref end); if (bansw)//存在答案。更新题目内容界定范围 { mainContent1.WordBrowers.document.Application.Selection.SetRange(subject.rangestart + prelength, end); } else { mainContent1.WordBrowers.document.Application.Selection.SetRange(subject.rangestart + prelength, subject.rangeend); } mainContent1.WordBrowers.document.Application.Selection.Range.Copy();//不包括题目前ID号内容的范围 String html = ClipboardHelper.getClipboardHtml(); HtmlUtil.HtmlPictureMove(ref html); FilterHtmlAndShowInWebbrowser(ref html); subject.subjecthtmlcontent = html; //subject.subjectbinarycontent = ClipboardHelper.getClipboardEmbed(); subject.subjecttextcontent = ClipboardHelper.getClipboardText(); } else//更新题干或者大题内容范围 { mainContent1.WordBrowers.document.Application.Selection.SetRange(subject.rangestart + prelength, subjectend); mainContent1.WordBrowers.document.Application.Selection.Range.Copy();//不包括题目前ID号内容的范围 String html = ClipboardHelper.getClipboardHtml(); HtmlUtil.HtmlPictureMove(ref html); html = HtmlUtil.HtmlFragmentClear(html); html = HtmlUtil.htmlreplace(html); if (!isSpot) { if (html != null && !html.Trim().Equals("")) { try { this.webBrowser.DocumentText = html; } catch { MessageBox.Show("该题无法预览,请重新拆题", "提示"); } } //FilterHtmlAndShowInWebbrowser(ref html); } subject.subjecthtmlcontent = html; //subject.subjectbinarycontent = ClipboardHelper.getClipboardEmbed(); //subject.subjecttextcontent = ClipboardHelper.getClipboardText(); } } else//没有子节点 { int end = 0; bool bansw = AnswerSpot(ref tn, ref end); if (bansw)//存在答案。更新题目内容界定范围 { mainContent1.WordBrowers.document.Application.Selection.SetRange(subject.rangestart + prelength, end); } else { mainContent1.WordBrowers.document.Application.Selection.SetRange(subject.rangestart + prelength, subject.rangeend); } mainContent1.WordBrowers.document.Application.Selection.Range.Copy();//不包括题目前ID号内容的范围 String html = ClipboardHelper.getClipboardHtml(); HtmlUtil.HtmlPictureMove(ref html); html = HtmlUtil.HtmlFragmentClear(html); html = HtmlUtil.htmlreplace(html); if (!isSpot) { if (html != null && !html.Trim().Equals("")) { try { this.webBrowser.DocumentText = html; } catch { MessageBox.Show("该题无法预览,请重新拆题", "提示"); } } //FilterHtmlAndShowInWebbrowser(ref html); } subject.subjecthtmlcontent = html; //subject.subjectbinarycontent = ClipboardHelper.getClipboardEmbed(); subject.subjecttextcontent = ClipboardHelper.getClipboardText(); } }
/// <summary> /// /// 题目内容建立 /// </summary> /// <param name="treenode">建立所在节点下</param> /// <param name="subjectstructure">题目对应匹配结构</param> /// <returns> 返回是否有子节点</returns> /// private bool SubjectBuild(TreeNode treenode, SubjectStructure subjectstructure, ref int endfor, List<Subject> list2, List<Subject> list3=null,int index=1) { MartianSpot martianSpot = new MartianSpot(); List<SubjectInfo> listminisubject = null; Subject subject1 = (Subject)treenode.Tag; try { listminisubject = martianSpot.subjectSpot(mainContent1.WordBrowers.document, ref this.progressBarSpot, subjectstructure.subjectPre, subject1.rangestart, subject1.rangeend); if (listminisubject.Count == 0) return false; for (int i = 0; i < listminisubject.Count; i++) { SubjectInfo subjectInfoStart = listminisubject[i]; int start = subjectInfoStart.paragraphsStart; if (i == 0)//去第一个子题的头位置 { endfor = start; } SubjectInfo subjectInfoEnd; int end; if (i == listminisubject.Count - 1) { //subjectInfoEnd = listminisubject[i]; //object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */ //最后一题将范围移动至文档结束 end = subject1.rangeend; } else { subjectInfoEnd = listminisubject[i + 1]; end = subjectInfoEnd.paragraphsStart; } Subject subject = new Subject();//创建试题对象 subject.rangestart = start;//取得当前范围 subject.rangeend = end;//取得当前范围 var item = list2.Where(x => x.ParentId == subject1.Id).ToList()[i]; subject.ParentId = item.ParentId; subject.Id = item.Id; String cliptext = item.subjecttextcontent; //subject.subjecttextcontent = cliptext; int prelength = 0;//定义前段返回的字符串 TreeNode tn = new TreeNode(); string sequencestr = MatchContent.matchRe(subjectstructure.subjectPre, cliptext, ref prelength); int sequence = 1;//试题在套卷中的排序号 try { sequence = Int16.Parse(sequencestr); } catch (Exception ex) { sequence = 1; } subject.套卷序号 = sequence; //this.webBrowser.DocumentText = html; //subject.subjecthtmlcontent = html; //subject.subjectbinarycontent = ClipboardHelper.getClipboardEmbed(); string html = item.subjecthtmlcontent; string[] strs = null; //第一层 if (index == 1) { strs = MatchArray.SubjectPreStructure.subjectPre; //第一层需要去掉第二层的内容 var htmls = html.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (var itemHtml in htmls) { if (MatchContent.match(MatchArray.SubjectPreStructure.childsubjectStructure.subjectPre, NoHTML(itemHtml))) { html = html.Substring(0, GetStrIndex(html, itemHtml)); break; } } }else{ //第二层 strs = MatchArray.SubjectPreStructure.childsubjectStructure.subjectPre; } foreach (var sb in strs) { string tempsb = sb; if (tempsb.IndexOf("^") == 0) { tempsb = tempsb.Substring(1); } var match = Regex.Match(html, tempsb); if (match.Success) { html = html.Replace(match.Groups["pre"].Value, ""); } } if (cliptext.Length > 20) { tn.Text = cliptext.Substring(0, 20); } else { tn.Text = cliptext; } tn.Tag = subject;//对应内容属性 tn.Expand(); treenode.Nodes.Add(tn); treenode.Expand(); this.propertyGrid.SelectedObject = subject; if (subjectstructure.childsubjectStructure != null)//判断是否还需判断子题 { int subjectend = 0;//结束结束返回 bool subjectb = SubjectBuild(tn, subjectstructure.childsubjectStructure, ref subjectend, list3, null,index+1); if (!subjectb)//没有字节点 { //end = 0;//结束位置返回 //bool bansw = AnswerSpot(ref tn, ref end); //if (bansw)//存在答案。更新题目内容界定范围 //{ // mainContent1.WordBrowers.document.Application.Selection.SetRange(subject.rangestart + prelength, end); //} //else //{ // mainContent1.WordBrowers.document.Application.Selection.SetRange(subject.rangestart + prelength, subject.rangeend); //} //mainContent1.WordBrowers.document.Application.Selection.Range.Copy();//不包括题目前ID号内容的范围 //String html = ClipboardHelper.getClipboardHtml(); HtmlUtil.HtmlPictureMove(ref html); FilterHtmlAndShowInWebbrowser(ref html); //需过滤题号 subject.subjecthtmlcontent = html; //subject.subjectbinarycontent = ClipboardHelper.getClipboardEmbed(); //需过滤题号 subject.subjecttextcontent = item.subjecttextcontent; } else//更新题干或者大题内容范围 { //mainContent1.WordBrowers.document.Application.Selection.SetRange(subject.rangestart + prelength, subjectend); //mainContent1.WordBrowers.document.Application.Selection.Range.Copy();//不包括题目前ID号内容的范围 //String html = ClipboardHelper.getClipboardHtml(); HtmlUtil.HtmlPictureMove(ref html); html = HtmlUtil.HtmlFragmentClear(html); html = HtmlUtil.htmlreplace(html); //if (!isSpot) //{ // if (html != null && !html.Trim().Equals("")) // { // try // { // this.webBrowser.DocumentText = html; // } // catch // { // MessageBox.Show("该题无法预览,请重新拆题", "提示"); // } // } // //FilterHtmlAndShowInWebbrowser(ref html); //} subject.subjecthtmlcontent = html; //subject.subjectbinarycontent = ClipboardHelper.getClipboardEmbed(); //subject.subjecttextcontent = ClipboardHelper.getClipboardText(); } } else//没有子节点 { end = 0; //bool bansw = AnswerSpot(ref tn, ref end); //if (bansw)//存在答案。更新题目内容界定范围 //{ // mainContent1.WordBrowers.document.Application.Selection.SetRange(subject.rangestart + prelength, end); //} //else //{ // mainContent1.WordBrowers.document.Application.Selection.SetRange(subject.rangestart + prelength, subject.rangeend); //} //mainContent1.WordBrowers.document.Application.Selection.Range.Copy();//不包括题目前ID号内容的范围 //String html = ClipboardHelper.getClipboardHtml(); HtmlUtil.HtmlPictureMove(ref html); html = HtmlUtil.HtmlFragmentClear(html); html = HtmlUtil.htmlreplace(html); //if (!isSpot) //{ // if (html != null && !html.Trim().Equals("")) // { // try // { // this.webBrowser.DocumentText = html; // } // catch // { // MessageBox.Show("该题无法预览,请重新拆题", "提示"); // } // } // //FilterHtmlAndShowInWebbrowser(ref html); //} subject.subjecthtmlcontent = html; //subject.subjectbinarycontent = ClipboardHelper.getClipboardEmbed(); // subject.subjecttextcontent = ClipboardHelper.getClipboardText(); subject.subjecttextcontent = item.subjecttextcontent; } //设定选择范围 // mainContent1.WordBrowers.document.Application.Selection.SetRange(start, end); //更新目录栏 //SubjectContentBuild(true, treenode, subjectstructure); } return true; } catch (NullReferenceException ex) { return false; // MessageBox.Show("请先在程序中打开word文件。"); } }
private void SetPropertyReadOnly(Subject tempsubject) { //可以确定为客观题的,把是否客观题选项禁止选择 if (tempsubject.题目类型 == Subject.SubjecttypeEnum.单选题 || tempsubject.题目类型 == Subject.SubjecttypeEnum.多选题 || tempsubject.题目类型 == Subject.SubjecttypeEnum.判断题) { tempsubject.客观题 = Subject.ObjectiveEnum.是; SetPropertyReadOnly(tempsubject, "客观题", true); } else { //tempsubject.客观题 = Subject.ObjectiveEnum.否; SetPropertyReadOnly(tempsubject, "客观题", false); } }
private bool ischildnode(Subject subject, TreeNode treenode) { Subject existsubject = (Subject)treenode.Tag; if (existsubject.rangestart <= subject.rangestart && existsubject.rangeend >= subject.rangeend) { return true; } return false; }
/// <summary> /// 生成试题结构树主结构 /// </summary> /// <param name="isSpotWord">区分是否是点击拆分按钮触发的</param> private void InitTreeRootNode(bool isSpotWord) { this.treeViewSubject.SelNodes = null; this.treeViewSubject.CheckedNodes = null; this.treeViewSubject.Nodes.Clear(); treeViewSubject.TreeViewNodeSorter = new NodeSorter();//树结构的排序规则 MartianSpot martianSpot = new MartianSpot(); List<SubjectInfo> listsubject = null; try { publicanswerstart = 0; this.progressBarSpot.Visible = true; //this.lableProcess.Visible = true; //this.lableProcess.Text = "分析大题"; //this.lableProcess.Show(); progressBarSpot.Maximum = mainContent1.WordBrowers.document.Paragraphs.Count - 1; progressBarSpot.Minimum = 0; progressBarSpot.Value = 0; progressBarSpot.Step = 10; bool haspublicanswer = false;//是否存在全局答案 mainContent1.WordBrowers.document.Application.Selection.SetRange(0, mainContent1.WordBrowers.document.Paragraphs[mainContent1.WordBrowers.document.Paragraphs.Count].Range.End); mainContent1.WordBrowers.document.Application.Selection.Range.Copy();//不包括题目前ID号内容的范围 String html = ClipboardHelper.getClipboardHtml(); HtmlUtil.HtmlPictureMove(ref html); html = HtmlUtil.HtmlFragmentClear(html); html = HtmlUtil.htmlreplace(html); string html1 = ""; string html2 = ""; bool isOne = true; int index = 0; int end = 0; foreach (var answer in MatchArray.publicAnswer) { end = GetStrIndex(html, "(<p>)*" + answer, false); if (end > 0) { break; } } if (end > 0) { html1 = html.Substring(0, end); html2 = html.Substring(end); haspublicanswer = true; } else { html1 = html; } List<Subject> list = new List<Subject>(); var strs = html1.Split(new string[] { "\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries); string tempText = ""; for (int i = 0; i < strs.Length; i++) { string text = NoHTML(strs[i]); if (i == strs.Length - 1 && i != 0) { list.Add(new Subject() { Id = i.ToString(), subjecthtmlcontent = html1.Substring(index), subjecttextcontent = tempText }); } else { if (text.ToString().Length > 3)//通过字段长度过滤来提高性能; { if (MatchContent.match(MatchArray.BigSubjectPre, text.ToString().TrimStart())) { if (isOne) { index = GetStrIndex(html1, strs[i]); isOne = false; } else { end = GetStrIndex(html1, strs[i]); list.Add(new Subject() { Id = i.ToString(), subjecthtmlcontent = html1.Substring(index, end - index), subjecttextcontent = tempText }); index = end; } tempText = text; } } } } List<Subject> list2 = new List<Subject>(); List<Subject> list3 = new List<Subject>(); if (isSpotWord) { list2 = GetSubjectList(strs, list, MatchArray.SubjectPreStructure.subjectPre); list3 = GetSubjectList(strs, list2, MatchArray.SubjectPreStructure.childsubjectStructure.subjectPre); } //得到匹配的题目列表 listsubject = martianSpot.subjectSpot(mainContent1.WordBrowers.document, ref this.progressBarSpot, MatchArray.BigSubjectPre, ref haspublicanswer); progressBarSpot.Maximum = listsubject.Count; progressBarSpot.Step = 1; progressBarSpot.Value = 0; for (int i = 0; i < listsubject.Count; i++) { SubjectInfo subjectInfo = listsubject[i]; //设置node在文本中的管理范围 Subject subject = new Subject(); subject.rangestart = listsubject[i].paragraphsStart; if (i == listsubject.Count - 1) { if (haspublicanswer) { publicanswerstart = listsubject[i].paragraphsStart; break; } else { object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */ //最后一题将范围移动至文档结束 subject.rangeend = mainContent1.WordBrowers.document.Bookmarks.get_Item(ref oEndOfDoc).Range.End; } } else { subject.rangeend = listsubject[i + 1].paragraphsStart; } string bigsubjecttext = list[i].subjecttextcontent; string subjectname = MatchContent.matchRe(MatchArray.BigSubjectPre, bigsubjecttext); if (subjectname.Length > 200) { subjectname = subjectname.Substring(0, 200); } TreeNode subnode = new TreeNode(); subnode.Text = subjectname; subject.套卷序号 = i; subject.选项个数 = 0; subject.Id = list[i].Id; subnode.Tag = subject; //subnode.Tag = section; this.treeViewSubject.Nodes.Add(subnode); if (isSpotWord) { lableProcess.Text = "分析题目"; int temp = 0;//此值在这里无用 SubjectBuild(subnode, MatchArray.SubjectPreStructure, ref temp, list2, list3); } //更新进度条 progressBarSpot.Value = i; progressBarSpot.PerformStep(); } if (isSpotWord && (classtypeenglish.Equals(classtype) || classtypeenglish2.Equals(classtype)))//英语类型判断 { foreach (TreeNode treenode in this.treeViewSubject.Nodes)//获取所有节点进行判断是否有题进行二次识别 { if (treenode.Nodes.Count > 0) { } else { int temp = 0;//此值在这里无用 SubjectBuild(treenode, MatchArray.SubjectPreStructure.childsubjectStructure, ref temp, null, null); } } } GetSubjectAnswer(isSpotWord, html2); //publicanswerstart = 0; } catch (NullReferenceException ex) { MessageBox.Show("请先在程序中打开word文件。", "提示"); } finally { this.progressBarSpot.Visible = false; this.lableProcess.Visible = false; lableProcess.Text = ""; } }