绑定答题卡的部分
1 public void InitSubjectAnswer(string ExamPaperGuid) 2 { 3 //20130105 加载xml文件 4 5 String strTempFilePath = System.Web.HttpContext.Current.Server.MapPath(GetApplicationPath() + "px/xmlFile/"); 6 7 if (!Directory.Exists(strTempFilePath)) 8 {//文件夹路径不存在则创建 9 Directory.CreateDirectory(strTempFilePath); 10 } 11 strTempFilePath = strTempFilePath + "EpointExam_" + ViewState["ExamGuid"] + "_" + ExamPaperGuid + "_" + Session["UserGuid"].ToString() + ".xml"; 12 XmlDocument xmlExam = new XmlDocument(); 13 if (File.Exists(strTempFilePath)) 14 xmlExam.Load(strTempFilePath); 15 else 16 return; 17 18 Epoint.PeiXun.Bizlogic.BLL.ExamOnline.IPaperDetail iPaper = new Epoint.PeiXun.Bizlogic.BLL.ExamOnline.DB_IPaper().GetDetailPaper(xmlExam); 19 Epoint.PeiXun.Bizlogic.BLL.ExamOnline.IQuestionDetail iQuestion = new Epoint.PeiXun.Bizlogic.BLL.ExamOnline.IQuestionDetail(); 20 21 StringBuilder strHTML = new StringBuilder(); 22 int m = 0; 23 int Count = 0; 24 int row = 0; 25 string type = ""; 26 //单选题 27 Count = Epoint.Common.Functions.IntNull(iPaper.QuestionCount0); 28 type = "single"; 29 if (Count > 0) 30 { 31 strHTML.Append("<div class='answer-block'><h2>单选题</h2>"); 32 strHTML.Append(BindAnswerSheet(Count, type, ref m)); 33 } 34 35 //多选题 36 Count = Epoint.Common.Functions.IntNull(iPaper.QuestionCount1); 37 type = "mult"; 38 if (Count > 0) 39 { 40 strHTML.Append("<div class='answer-block'><h2>多选题</h2>"); 41 strHTML.Append(BindAnswerSheet(Count, type, ref m)); 42 } 43 44 //判断题 45 Count = Epoint.Common.Functions.IntNull(iPaper.QuestionCount2); 46 type = "judge"; 47 if (Count > 0) 48 { 49 strHTML.Append("<div class='answer-block'><h2>判断题</h2>"); 50 strHTML.Append(BindAnswerSheet(Count, type, ref m)); 51 } 52 53 //填空题 54 Count = Epoint.Common.Functions.IntNull(iPaper.QuestionCount3); 55 type = "fill"; 56 if (Count > 0) 57 { 58 strHTML.Append("<div class='answer-block'><h2>填空题</h2>"); 59 strHTML.Append(BindAnswerSheet(Count, type, ref m)); 60 } 61 62 //简答题 63 Count = Epoint.Common.Functions.IntNull(iPaper.QuestionCount4); 64 type = "answer"; 65 if (Count > 0) 66 { 67 strHTML.Append("<div class='answer-block'><h2>简答题</h2>"); 68 strHTML.Append(BindAnswerSheet(Count, type, ref m)); 69 } 70 AnswerSheet.InnerHtml = strHTML.ToString(); 71 } 72 73 74 public string BindAnswerSheet(int Count, string type, ref int mm) 75 { 76 StringBuilder sb = new StringBuilder(); 77 sb.Append("<ul class='answer-list'>"); 78 79 for (int i = 0; i < Count; i++) 80 { 81 mm++; 82 sb.Append("<li onclick="Skip('" + type + (i + 1) + "','" + type + "');" id='" + type + (i + 1) + "'>" + (mm) + "</li>"); 83 } 84 85 sb.Append("</ul>"); 86 sb.Append("</div>"); 87 //AnswerSheet.InnerHtml = sb.ToString(); 88 return sb.ToString(); 89 }
生成Xml文件,必须在取题目之前
1 public void InitQuestion() 2 { 3 //Response.Write("<div id='loading' style='position:absolute; left:45%;top:40%;padding:2px;z-index:20001;height:auto;'>"); 4 //Response.Write("<div style='font-size:11px;height:18px; text-align:left;'>"); 5 ////Response.Write("<img src='../Images/extanim32.gif' alt='' width='32' height='32' style='margin-right: 8px;' align='absmiddle' />"); 6 //Response.Write("<div id='myDiv'></div>"); 7 //Response.Write("</div>"); 8 //Response.Write("</div>"); 9 //Response.Write(" <script language=javascript>"); 10 //Response.Write("var dots = 0;var dotmax = 10;function ShowWait()"); 11 //Response.Write("{var output; output = '试卷加载中,请稍后';dots++;if(dots>=dotmax)dots=1;"); 12 //Response.Write("for(var x = 0;x < dots;x++){output += '·';}document.getElementById('mydiv').innerText = output;}"); 13 //Response.Write("function StartShowWait(){document.getElementById('loading').style.display = ''; "); 14 //Response.Write("window.setInterval('ShowWait()',300);}"); 15 //Response.Write("StartShowWait(); </script>"); 16 //Response.Flush(); 17 Thread.Sleep(1000); 18 19 ViewState["ExamGuid"] = ExamGuid; 20 string tExamGuid = ViewState["ExamGuid"].ToString(); 21 string tExamPaperGuid = ""; 22 string tBasePaperGuid = ""; 23 M_Exam_List m_exam = b_examlist.SelectByRowGuid(tExamGuid); 24 tBasePaperGuid = m_exam.ExamPaperGuid; 25 ViewState["BasePaperGuid"] = tBasePaperGuid; 26 27 if (Request.QueryString["ExamPaperGuid"] != "" && Request["ExamPaperGuid"] != null) 28 ViewState["ExamPaperGuid"] = Request.QueryString["ExamPaperGuid"]; 29 else 30 ViewState["ExamPaperGuid"] = tBasePaperGuid; 31 32 //if (ExamPaperGuid != "" && ExamPaperGuid != null) 33 // ViewState["ExamPaperGuid"] = ExamPaperGuid; 34 //else 35 // ViewState["ExamPaperGuid"] = tBasePaperGuid; 36 37 tExamPaperGuid = ViewState["ExamPaperGuid"].ToString(); 38 39 new Epoint.PeiXun.Bizlogic.BLL.ExamOnline.DB_IPaper().InitXml(RegisGuid, ExamGuid, ViewState["ExamPaperGuid"].ToString(), ViewState["BasePaperGuid"].ToString()); 40 41 }
取出题目(这里是从Xml文件中取出题目,所以上面生成Xml文件的方法必须在此方法之前生成,否则会报错,无法取出题目)
1 public void GetSubject(string ExamPaperGuid, string BasePaperGuid) 2 { 3 Epoint.PeiXun.Bizlogic.BLL.ExamSubject.B_Exam_Answer b_answer = new Epoint.PeiXun.Bizlogic.BLL.ExamSubject.B_Exam_Answer();//答案 4 List<M_Exam_Answer> listanswer; 5 M_Exam_Paper m_paper = b_paper.SelectByRowGuid(BasePaperGuid); 6 7 //是否启用选对一个得分模式 8 string IsShowMultiCode2 = new Epoint.Frame.Bizlogic.Frame_Config().GetDetail("IsShowMultiCode2").ConfigValue; 9 10 //20130105 加载xml文件 11 String strTempFilePath = System.Web.HttpContext.Current.Server.MapPath(GetApplicationPath() + "px/xmlFile/"); 12 13 if (!Directory.Exists(strTempFilePath)) 14 Directory.CreateDirectory(strTempFilePath); 15 strTempFilePath = strTempFilePath + "EpointExam_" + ViewState["ExamGuid"].ToString().Trim() + "_" + ExamPaperGuid.Trim() + "_" + RegisGuid + ".xml"; 16 XmlDocument xmlExam = new XmlDocument(); 17 xmlExam.Load(strTempFilePath); 18 19 Epoint.PeiXun.Bizlogic.BLL.ExamOnline.IPaperDetail iPaper = new Epoint.PeiXun.Bizlogic.BLL.ExamOnline.DB_IPaper().GetDetailPaper(xmlExam); 20 Epoint.PeiXun.Bizlogic.BLL.ExamOnline.IQuestionDetail iQuestion = new Epoint.PeiXun.Bizlogic.BLL.ExamOnline.IQuestionDetail(); 21 22 StringBuilder strHTML = new StringBuilder(); 23 string typeString = ""; 24 //DataView dvAnswerList = new DataView(); 25 ArrayList Strnum = new ArrayList(); 26 String strChk = ""; 27 string SubjectGuid = ""; 28 int Code = 0; 29 string yourAnswer = ""; 30 31 #region 32 Strnum.Add("A"); 33 Strnum.Add("B"); 34 Strnum.Add("C"); 35 Strnum.Add("D"); 36 Strnum.Add("E"); 37 Strnum.Add("F"); 38 39 #endregion 40 41 42 #region 题目 43 List<M_Exam_Question> list_question = b_question.SelectByExamPaperGuid(ExamPaperGuid); 44 45 for (int i = 0; i < list_question.Count; i++) 46 { 47 //int IsCheck = Convert.ToInt32(iPaper.QuestionList[i].IsCheck);//题目类型 48 int IsCheck = Convert.ToInt32(list_question[i].Type);//题目类型 49 50 int QuestionNum = 0; 51 iQuestion = iPaper.QuestionList[i]; 52 SubjectGuid = iQuestion.SubjectGuid; 53 //存储题目以及答案的信息 54 //questionGuid[m] = SubjectGuid; 55 56 switch (IsCheck) 57 { 58 case 0://0-单选 59 typeString = "一"; 60 strChk = ""; 61 if (iQuestion.IsFirst == "1") 62 { 63 QuestionNum = Convert.ToInt32(iPaper.QuestionCount0); 64 if (IsShowMultiCode2 == "1") 65 strHTML.Append("<div class='ques-category' id='single'><h2>" + typeString + "、单选题(选对得" + m_paper.DanXSore.ToString() + "分,选错、多选不得分,合计" + (m_paper.DanXSore * QuestionNum).ToString() + "分)</h2>"); 66 else 67 strHTML.Append("<div class='ques-category' id='single'><h2>" + typeString + "、单选题,共" + QuestionNum.ToString() + "题,每题" + m_paper.DanXSore.ToString() + "分,请选择正确答案</h2>"); 68 strHTML.Append("<div class='ques-list'>"); 69 } 70 //生成试卷的题目 71 strHTML.Append("<div class='question'><p class='title'>题目" + (i + 1) + ".<span class='orange'>(单选题)</span>" + iQuestion.SubjectName + "</p>"); 72 73 listanswer = b_answer.SelectBySubjectGuid(SubjectGuid); 74 strHTML.Append("<ul class='result single'>"); 75 for (int j = 0; j < listanswer.Count; j++) 76 { 77 strChk = ((iQuestion.AnswerID.IndexOf(listanswer[j].AnswerGuid.ToString()) >= 0) ? " checked " : ""); 78 strHTML.Append("<li onclick="ChangeStatus('single" + (i + 1) + "');" name="" + SubjectGuid + "" value="" + listanswer[j].AnswerGuid + ""> " + Strnum[j] + ". " + listanswer[j].AnswerName + "</li>"); 79 } 80 81 strHTML.Append("<input type="text" " + strChk + " id="answer_" + SubjectGuid + "" name="" + SubjectGuid + "" value="" + iQuestion.AnswerID.ToString() + "" style='display:none;'></input>"); 82 83 strHTML.Append("</ul>"); 84 strHTML.Append("</div>"); 85 86 break; 87 case 1: //1-多选 88 typeString = "二"; 89 strChk = ""; 90 if (iQuestion.IsFirst == "1") 91 { 92 if (Convert.ToInt32(iPaper.QuestionCount0) > 0) 93 strHTML.Append("</div></div>"); 94 95 QuestionNum = Convert.ToInt32(iPaper.QuestionCount1); 96 if (IsShowMultiCode2 == "1") 97 strHTML.Append("<div class='ques-category' id='mult'><h2>" + typeString + "、多选题(选对得" + m_paper.DanXSore.ToString() + "分,选错、多选不得分,合计" + (m_paper.DanXSore * QuestionNum).ToString() + "分)</h2>"); 98 else 99 strHTML.Append("<div class='ques-category' id='mult'><h2>" + typeString + "、多选题,共" + QuestionNum.ToString() + "题,每题" + m_paper.DanXSore.ToString() + "分,请选择正确答案</h2>"); 100 strHTML.Append("<div class='ques-list'>"); 101 } 102 //生成试卷的题目 103 104 strHTML.Append("<div class='question'><p class='title'>题目" + (i + 1) + ".<span class='orange'>(多选题)</span>" + iQuestion.SubjectName + "</p>"); 105 106 listanswer = b_answer.SelectBySubjectGuid(SubjectGuid); 107 strHTML.Append("<ul class='result'>"); 108 for (int j = 0; j < listanswer.Count; j++) 109 { 110 strChk = ((iQuestion.AnswerID.IndexOf(listanswer[j].AnswerGuid.ToString()) >= 0) ? " checked " : ""); 111 strHTML.Append("<li onclick="ChangeStatus('mult" + (i - Convert.ToInt32(iPaper.QuestionCount0) + 1) + "');" name="" + SubjectGuid + "" value="" + listanswer[j].AnswerGuid + "">" + Strnum[j] + ". " + listanswer[j].AnswerName + "</li>"); 112 } 113 114 strHTML.Append("<input type="text" " + strChk + " id="answer_" + SubjectGuid + "" name="" + SubjectGuid + "" value="" + iQuestion.AnswerID.ToString() + "" style='830px;display:none;'></input>"); 115 strHTML.Append("</ul>"); 116 strHTML.Append("</div>"); 117 118 break; 119 120 case 2: //2-判断 121 typeString = "三"; 122 strChk = ""; 123 if (iQuestion.IsFirst == "1") 124 { 125 if (Convert.ToInt32(iPaper.QuestionCount0) + Convert.ToInt32(iPaper.QuestionCount1) > 0) 126 strHTML.Append("</div></div>"); 127 128 QuestionNum = Convert.ToInt32(iPaper.QuestionCount2); 129 if (IsShowMultiCode2 == "1") 130 strHTML.Append("<div class='ques-category' id='judge'><h2>" + typeString + "、判断题(选对得" + m_paper.DanXSore.ToString() + "分,选错、多选不得分,合计" + (m_paper.DanXSore * QuestionNum).ToString() + "分)</h2>"); 131 else 132 strHTML.Append("<div class='ques-category' id='judge'><h2>" + typeString + "、判断题,共" + QuestionNum.ToString() + "题,每题" + m_paper.DanXSore.ToString() + "分,请选择正确答案</h2>"); 133 strHTML.Append("<div class='ques-list'>"); 134 } 135 //生成试卷的题目 136 strHTML.Append("<div class='question'><p class='title'>题目" + (i + 1) + ".<span class='orange'>(判断题)</span>" + iQuestion.SubjectName + "</p>"); 137 138 listanswer = b_answer.SelectBySubjectGuid(SubjectGuid); 139 strHTML.Append("<ul class='result single'>"); 140 for (int j = 0; j < listanswer.Count; j++) 141 { 142 strChk = ((iQuestion.AnswerID.IndexOf(listanswer[j].AnswerGuid.ToString()) >= 0) ? " checked " : ""); 143 strHTML.Append("<li onclick="ChangeStatus('judge" + (i - Convert.ToInt32(iPaper.QuestionCount0) - Convert.ToInt32(iPaper.QuestionCount1) + 1) + "');" name="" + SubjectGuid + "" value="" + listanswer[j].AnswerGuid + "">" + Strnum[j] + ". " + listanswer[j].AnswerName + "</li>"); 144 } 145 strHTML.Append("<input type="text" " + strChk + " id="answer_" + SubjectGuid + "" name="" + SubjectGuid + "" value="" + iQuestion.AnswerID.ToString() + "" style='display:none;'></input>"); 146 147 strHTML.Append("</ul>"); 148 strHTML.Append("</div>"); 149 150 break; 151 152 case 3: // 3-填空 153 typeString = "四"; 154 strChk = ""; 155 if (iQuestion.IsFirst == "1") 156 { 157 if (Convert.ToInt32(iPaper.QuestionCount0) + Convert.ToInt32(iPaper.QuestionCount1) + Convert.ToInt32(iPaper.QuestionCount2) > 0) 158 strHTML.Append("</div></div>"); 159 160 QuestionNum = Convert.ToInt32(iPaper.QuestionCount3); 161 strHTML.Append("<div class='ques-category' id='fill'><h2>" + typeString + "、填空题,共" + QuestionNum.ToString() + "题,每题" + m_paper.DanXSore.ToString() + "分,请选择正确答案</h2>"); 162 strHTML.Append("<div class='ques-list'>"); 163 } 164 yourAnswer = iQuestion.AnswerID; 165 166 //生成试卷的题目 167 strHTML.Append("<div class='question'><p class='title'>题目" + (i + 1) + ".<span class='orange'>(填空题)</span>" + iQuestion.SubjectName + "</p>"); 168 169 strHTML.Append("<ul class='result'>"); 170 171 strHTML.Append("<textarea onclick="ChangeStatus('fill" + (i - Convert.ToInt32(iPaper.QuestionCount0) - Convert.ToInt32(iPaper.QuestionCount1) - Convert.ToInt32(iPaper.QuestionCount2) + 1) + "');" maxlength="200" class="inputtxt" style="98%; height:50px">" + yourAnswer + "</textarea><br>"); 172 173 strHTML.Append("</ul>"); 174 strHTML.Append("</div>"); 175 176 break; 177 178 case 4: // 4-简答 179 180 typeString = "五"; 181 strChk = ""; 182 if (iQuestion.IsFirst == "1") 183 { 184 if (Convert.ToInt32(iPaper.QuestionCount0) + Convert.ToInt32(iPaper.QuestionCount1) + Convert.ToInt32(iPaper.QuestionCount2) + Convert.ToInt32(iPaper.QuestionCount3) > 0) 185 strHTML.Append("</div></div>"); 186 187 QuestionNum = Convert.ToInt32(iPaper.QuestionCount3); 188 strHTML.Append("<div class='ques-category' id='answer'><h2>" + typeString + "、简答题,共" + QuestionNum.ToString() + "题,每题" + m_paper.DanXSore.ToString() + "分,请选择正确答案</h2>"); 189 strHTML.Append("<div class='ques-list'>"); 190 } 191 yourAnswer = iQuestion.AnswerID; 192 193 //生成试卷的题目 194 strHTML.Append("<div class='question'><p class='title'>题目" + (i + 1) + ".<span class='orange'>(简答题)</span>" + iQuestion.SubjectName + "</p>"); 195 196 strHTML.Append("<ul class='result'>"); 197 198 strHTML.Append("<textarea onclick="ChangeStatus('answer" + (i - Convert.ToInt32(iPaper.QuestionCount0) - Convert.ToInt32(iPaper.QuestionCount1) - Convert.ToInt32(iPaper.QuestionCount2) - Convert.ToInt32(iPaper.QuestionCount3) + 1) + "');" maxlength="200" class="inputtxt" style="98%; height:50px">" + yourAnswer + "</textarea><br>"); 199 200 strHTML.Append("</ul>"); 201 strHTML.Append("</div>"); 202 203 break; 204 } 205 206 207 } 208 strHTML.Append("</div>"); 209 strHTML.Append("</div>"); 210 #endregion 211 div_ask.InnerHtml = strHTML.ToString(); 212 //ViewState["questionGuid"] = questionGuid; 213 }
答完题目,提交试卷
1 protected void btnSubmitExam_Click(object sender, EventArgs e) 2 { 3 SaveAnswer(); 4 M_Exam_User m_user = b_user.SelectByRowGuid(EURowGuid); 5 if (m_user != null) 6 { 7 if (string.IsNullOrEmpty(m_user.EndDate.ToString())) 8 { 9 #region 10 11 String strTempFilePath = System.Web.HttpContext.Current.Server.MapPath(GetApplicationPath() + "px/xmlFile/"); 12 strTempFilePath = strTempFilePath + "EpointExam_" + ViewState["ExamGuid"].ToString() + "_" + ViewState["ExamPaperGuid"].ToString() + "_" + RegisGuid + ".xml"; 13 XmlDocument xmlExam = new XmlDocument(); 14 xmlExam.Load(strTempFilePath); 15 #region 16 m_user.EndDate = DateTime.Now; 17 m_user.ExamPaperGuid = ViewState["ExamPaperGuid"].ToString(); 18 m_user.ExamXml = xmlExam.InnerXml; 19 b_user.Update(m_user); 20 #endregion 21 Epoint.PeiXun.Bizlogic.BLL.ExamOnline.CalculateThread thWorker = new Epoint.PeiXun.Bizlogic.BLL.ExamOnline.CalculateThread(EURowGuid, ViewState["ExamGuid"].ToString(), RegisGuid, ViewState["ExamPaperGuid"].ToString());//插入到 Exam_Result表的操作 22 23 thWorker.Run(1000); 24 25 26 int zhuguantiCount = 0; //主观题数目 27 List<M_Exam_Question> list_ques = b_question.SelectByExamPaperGuid(ViewState["ExamPaperGuid"].ToString()).FindAll(x => x.Type == "4"); 28 29 zhuguantiCount = list_ques.Count; 30 if (zhuguantiCount == 0) 31 { 32 int totalScore = 0; //客观题得分 33 try 34 { 35 totalScore = b_saveresult.GetSumCode(ViewState["ExamGuid"].ToString(), RegisGuid, ViewState["ExamPaperGuid"].ToString()); 36 } 37 catch (Exception ex) //没有提交任何信息 38 { 39 totalScore = 0; 40 } 41 //无主观题,若考试及格,直接获得学分等 42 M_Exam_Paper m_paper = b_paper.SelectByRowGuid(ViewState["ExamPaperGuid"].ToString()); 43 string strpassline = m_paper.PassingLine.ToString(); 44 int passingLine = 60; 45 Int32.TryParse(strpassline, out passingLine); 46 47 UpdateCourse(totalScore, passingLine);//考试结束后,更新学习计划中需要考试课程的系列操作 48 49 } 50 #endregion 51 52 AlertAjaxMessage("提交成功!"); 53 this.WriteAjaxMessage("Close()"); 54 } 55 else 56 { 57 AlertAjaxMessage("已经提交过,不允许重复提交!"); 58 this.WriteAjaxMessage("Close()"); 59 } 60 } 61 else 62 { 63 AlertAjaxMessage("考试记录异常,联系管理员!"); 64 this.WriteAjaxMessage("Close()"); 65 } 66 }
保存答案的方法
1 public void SaveAnswer() 2 { 3 string ExamGuid = ViewState["ExamGuid"].ToString(); 4 string ExamPaperGuid = ViewState["ExamPaperGuid"].ToString(); 5 string BasePaperGuid = ViewState["BasePaperGuid"].ToString(); 6 7 //20130105 加载xml文件 8 String strTempFilePath = System.Web.HttpContext.Current.Server.MapPath(GetApplicationPath() + "px/xmlFile/"); 9 if (!Directory.Exists(strTempFilePath)) 10 Directory.CreateDirectory(strTempFilePath); 11 strTempFilePath = strTempFilePath + "EpointExam_" + ExamGuid + "_" + ExamPaperGuid + "_" + RegisGuid + ".xml"; 12 XmlDocument xmlExam = new XmlDocument(); 13 xmlExam.Load(strTempFilePath); 14 15 Epoint.PeiXun.Bizlogic.BLL.ExamOnline.IPaperDetail iPaper = new Epoint.PeiXun.Bizlogic.BLL.ExamOnline.DB_IPaper().GetDetailPaper(xmlExam); 16 M_Exam_User m_eu = b_user.SelectByRowGuid(EURowGuid); 17 TimeSpan ts = DateTime.Now - Convert.ToDateTime(m_eu.StartDate); 18 iPaper.ExamTime = ts.Minutes.ToString(); 19 20 //按照check的name判断答案 21 //string[] questionGuid = (string[])(ViewState["questionGuid"]); 22 23 List<M_Exam_Question> list_question = b_question.SelectByExamPaperGuid(ExamPaperGuid); 24 25 for (int i = 0; i < list_question.Count; i++) 26 { 27 string answerID = ""; 28 string SubjectGuid = ""; 29 SubjectGuid = list_question[i].SubjectGuid; 30 answerID = Request.Params[SubjectGuid];//必须用input标签才能取出值 31 32 iPaper.QuestionList[i].AnswerID = answerID; 33 } 34 string strException = ""; 35 db_IPaper.SaveAnswer(iPaper, out strException); 36 }