/// <summary> /// 我的课程讲师端学员端列表(加入考试成绩) /// </summary> /// <param name="totalCount"></param> /// <param name="CourseId"></param> /// <param name="TeacherId"></param> /// <param name="startIndex"></param> /// <param name="pageLength"></param> /// <returns></returns> public List <Cl_CourseOrder> GetTeacherOnLineTest(out int totalCount, int CourseId, int TeacherId, int startIndex = 0, int pageLength = int.MaxValue) { //return _courseOrderDB.GetTeacherOnLineTest(out totalCount, CourseId, TeacherId, startIndex, pageLength); var list = _courseOrderDB.GetTeacherOnLineTest(out totalCount, CourseId, TeacherId, startIndex, pageLength); for (int i = 0; i < list.Count; i++) { tbExamSendStudent exam = _ExamDB.GetExamSendStudentBySQL2005(list[i].CourseId.Value, list[i].UserId, list[i].CoPaperID, list[i].PaperId); var exampaper = _paperDB.GetExampaper(list[i].PaperId); list[i].LevelScoreStr = Convert.ToInt32(list[i].LevelScore * 0.01 * (exampaper == null ? 0 : exampaper.ExampaperScore)); if (exam != null) { list[i].tbExamstudentId = exam._id; list[i].DoExamStatus = exam.DoExamStatus; //list[i].GetexamScore = (exam.StudentAnswerList.Sum(pa => pa.GetScore) / exampaper.ExampaperScore) * 100; list[i].GetexamScore = exam.StudentAnswerList.Sum(pa => pa.GetScore); list[i].ExamTestTimes = exam.TestTimes; //记录考试次数,考了几次 } else { list[i].GetexamScore = 0; list[i].tbExamstudentId = 0; } } return(list); }
/// <summary> /// 我的年度培训目标 /// </summary> /// <param name="userid"></param> /// <param name="bentime"></param> /// <param name="endtime"></param> /// <param name="totalcount"></param> /// <param name="startIndex"></param> /// <param name="startLength"></param> /// <param name="Order"></param> /// <param name="where"></param> /// <returns></returns> public List <Co_CourseShow> GetMyCourse(int userid, int year, int way, out int totalcount, int startIndex = 0, int startLength = int.MaxValue, string Order = "asc", string where = "1=1") { var list = new List <Co_CourseShow>(); list = way == 1 ? _userDB.GetMyCourse(userid, year, startIndex, startLength, Order, where) : _userDB.GetMyVidioCourse(userid, year, startIndex, startLength, Order, where); totalcount = list.Count > 0 ? list[0].totalcount : 0; for (int i = 0; i < list.Count; i++) { if (list[i].CoPaperID > 0 && list[i].PaperId > 0) { tbExamSendStudent exam = new tbExamSendStudent(); if (list[i].Way == 2) { exam = _ExamDB.GetExamSendStudentBySQL2008(list[i].Id, userid, list[i].CoPaperID, list[i].PaperId, 2); } else { exam = _ExamDB.GetExamSendStudentBySQL2008(list[i].Id, userid, list[i].CoPaperID, list[i].PaperId, 1); } list[i].GetexamScore = exam == null?0:exam.StudentAnswerList.Sum(pa => pa.GetScore); tbExampaper paper = _paperDB.GetExampaper(list[i].PaperId); list[i].ExamScore = paper.ExampaperScore; } else { list[i].GetexamScore = 0; list[i].ExamScore = 0; } } return(list); }
public ActionResult MyExam() { //获取我的考试信息 List <tbExamSendStudent> myTotalExamList = _examTestManager.GetMyExamList(CurrentUser.UserId); //相关的考试 List <tbExamination> examlist = _examinationManager.GetAllExamination(myTotalExamList.Select(p => p.RelationID)) .FindAll( p => p.PublishResult == 1 && p.ExamBeginTime.ToLocalTime() <= DateTime.Now && p.ExamEndTime.ToLocalTime() >= DateTime.Now); examlist = examlist.OrderByDescending(p => p.ExamBeginTime).Take(5).ToList(); var myExamListShow = new List <ExamTestShow>(); foreach (tbExamination exam in examlist) { tbExamSendStudent examuser = myTotalExamList.Find(p => p.RelationID == exam._id); myExamListShow.Add(new ExamTestShow { ExamUserID = examuser._id, StartTime = exam.ExamBeginTime.ToLocalTime(), EndTime = exam.ExamEndTime.ToLocalTime(), ExamLength = exam.ExamLength, ExamTitle = exam.ExaminationTitle }); } return(View(myExamListShow)); }
/// <summary> /// 判断是否可以进入考试 /// </summary> /// <param name="euID">考试人员ID</param> /// <param name="type">0:列表进入;1:真正进入</param> /// <returns>为0时,如果可以进入,则直接返回考试信息</returns> public JsonResult IsCanExamTest(int euId, int type = 0) { int leavePageTimes = 0; tbExamSendStudent eu = _examTestManager.GetExamUser(euId); if (eu.RemainingTime == 0) { return(Json(new { result = 0, msg = "您的考试时间已用完,不可进入!" }, JsonRequestBehavior.AllowGet)); } int examTestTimes = 0; //当SourceType不等于0的时候 表示是课程下的考试 if (eu.SourceType == 0) { tbExamination exam = _examinationManager.GetExamination(eu.RelationID); examTestTimes = exam.TestTimes; if (exam.LeavePageTimes < eu.LeavePageTimes) { return(Json(new { result = 0, msg = "您离开页面的总次数已用完,不可进入!" }, JsonRequestBehavior.AllowGet)); } if (eu.TestTimes >= exam.TestTimes) { return(Json(new { result = 0, msg = "进入次数已达到上限,不可进入!" }, JsonRequestBehavior.AllowGet)); } if (exam.ExamEndTime.ToLocalTime() <= DateTime.Now) { return(Json(new { result = 0, msg = "本场考试已经结束,不可进入!" }, JsonRequestBehavior.AllowGet)); } } else if (eu.SourceType == 1) { } //if (type == 1) //{ eu.TestTimes += 1; _examTestManager.SaveExamUser(eu); return(Json(new { result = 1, msg = "开始考试!" }, JsonRequestBehavior.AllowGet)); //} //var exambase = _examTestManager.GetExamBaseInforShow(euId, leavePageTimes); //return Json(new //{ // result = 1, // msg = "参与考试!", // data = new // { // exambase.ExamRuleList, // exambase.ExamEndTime, // exambase.ExamStartTime, // exambase.ExamLength, // exambase.ExamTitle, // exambase.UserRemainingTime // }, // testTimes = eu.TestTimes > 1000 ? 0 : examTestTimes - eu.TestTimes, // examTestTimes = examTestTimes //}, JsonRequestBehavior.AllowGet); }
/// <summary> /// /// </summary> /// <param name="examSendStudent"></param> /// <param name="rules"></param> /// <returns></returns> public tbExamSendStudent RandomGenerate(tbExamSendStudent examSendStudent, IEnumerable <ReRuleQuestion> rules) { var list = RandomGenerate(new List <tbExamSendStudent>() { examSendStudent }, rules); return(list.First()); }
/// <summary> /// 判断是否可以进入考试 /// </summary> /// <param name="euID">考试人员ID</param> /// <param name="flag">0:列表进入;1:真正进入</param> /// <returns></returns> public JsonResult JudgeCanExamTest(int euID, int flag) { tbExamSendStudent eu = ExamTestBL.GetExamUser(euID); //当SourceType不等于0的时候 表示是课程下的考试 //if (eu.SourceType == 0) //{ if (eu.SourceType == 0) { tbExamination exam = ExaminationBL.GetExamination(eu.RelationID); if (eu.TestTimes >= exam.TestTimes) { return(Json(new { result = 0, message = "进入次数已达到上限!" }, JsonRequestBehavior.AllowGet)); } if (exam.ExamEndTime.ToLocalTime() <= DateTime.Now) { return(Json(new { result = 0, message = "本场考试已经结束,不可进入!" }, JsonRequestBehavior.AllowGet)); } eu.TestTimes += 1; if (flag == 1) { ExamTestBL.SaveExamUser(eu); } } //} else { var coursepaper = ICoCoursePaperBL.GetCo_CourseMainPaper(eu.RelationID); if (eu.TestTimes >= coursepaper.TestTimes) { return(Json(new { result = 0, message = "进入次数已达到上限!" }, JsonRequestBehavior.AllowGet)); } eu.TestTimes += 1; if (flag == 1) { ExamTestBL.SaveExamUser(eu); } //ICoCoursePaperBL.UpdateTestTimes(eu.RelationID); } return(Json(new { result = 1 }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 进入考试 /// </summary> public JsonResult GoInExam(int courseId, int recordId, int examId) { var model = _learningRecord.GetCourseExampaper(courseId).FirstOrDefault(p => p.ExampaperId == examId); if (model != null) { var student = _examinationManager.GetExamSendStudentByCIdAndUIdAndExampaperId(recordId, 1, examId, CurrentUser.UserId); if (student == null) { var exampaperRedundancy = _exampaperManager.GetExampaperRedundancy(examId); student = new tbExamSendStudent { RelationID = recordId, //存放课程学习记录ID SourceType = 1, //区分0;1 ExamPaperID = examId, UserID = CurrentUser.UserId, DoExamStatus = 0, LastUpdateTime = DateTime.Now, SubmitTime = DateTime.Now, TestTimes = 0, IsPass = 0, Status = 0, Score = 0, StudentAnswerList = new List <ReStudentExamAnswer>(), AlreadyModifyScore = 0, ModifyScoreMemos = new List <ModifyScoreMemo>(), PaperScore = model.PassScore * exampaperRedundancy.ExampaperScore / 100,//考试通过分数 ReadOver = 0, RemainingTime = model.TimeLength * 60, TenantId = CurrentTenant.TenantId }; _examinationManager.InserttbExamSendStudent(student); } return(Json(new { result = 1, EuId = student._id }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { result = 0 }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 判断是否可以进入考试 /// </summary> /// <param name="euID">考试人员ID</param> /// <param name="type">0:列表进入;1:真正进入</param> /// <returns>为0时,如果可以进入,则直接返回考试信息</returns> public JsonResult IsCanExamTest(int euId) { int leavePageTimes = 0; tbExamSendStudent eu = _examTestManager.GetExamUser(euId); int examTestTimes = 0; if (eu.SourceType == 1) { if (eu.RemainingTime == 0) { return(Json(new { result = 2, msg = "您的考试时间已用完,不可进入!" }, JsonRequestBehavior.AllowGet)); } var len = _learningRecord.GetLearningRecord(eu.RelationID); var list = _courseManager.LoadCourseExaminations(len.CourseId); var coursepaper = list.FirstOrDefault(p => p.ExampaperRedundancyId == eu.ExamPaperID); examTestTimes = coursepaper.AllowTimes; string examinationOpenWindowCount = SystemConfigManager.GetConfig(Configs.ExaminationOpenWindowCount.ToString(), eu.TenantId); if (!string.IsNullOrEmpty(examinationOpenWindowCount)) { leavePageTimes = Convert.ToInt32(examinationOpenWindowCount); } if (leavePageTimes < eu.LeavePageTimes) { return(Json(new { result = 2, msg = "您离开页面的总次数已用完,不可进入!" }, JsonRequestBehavior.AllowGet)); } if (eu.TestTimes >= coursepaper.AllowTimes) { return(Json(new { result = 2, msg = "进入次数已达到上限!" }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { result = 0, msg = "进入失败!" }, JsonRequestBehavior.AllowGet)); } eu.TestTimes += 1; _examTestManager.SaveExamUser(eu); return(Json(new { result = 1, msg = "开始考试!" }, JsonRequestBehavior.AllowGet)); }
public List <Co_CourseShow> GetMyExamList(out int totalCount, int UserId = 0, string TrainGrade = "", int DeptId = 0, string where = " 1 = 1 ", int startIndex = 0, int pageLength = int.MaxValue) { var list = attendceDb.GetMyExamList(out totalCount, UserId, TrainGrade, DeptId, where, startIndex, pageLength); //totalCount = list.Count > 0 ? list[0].totalcount : 0; for (int i = 0; i < list.Count; i++) { tbExamSendStudent exam = _ExamDB.GetExamSendStudentBySQL2005(list[i].Id, UserId, list[i].CoPaperID, list[i].PaperId); var exampaper = _paperDB.GetExampaper(list[i].PaperId); list[i].LevelScoreStr = Convert.ToInt32(list[i].LevelScore * 0.01 * (exampaper == null?0:exampaper.ExampaperScore)); list[i].ExampaperScore = exampaper == null ? 0 : exampaper.ExampaperScore; //var CoCoursePaper = ICoCoursePaperBL.GetCo_CourseMainPaper( //((double)examUser.StudentAnswerList.Sum(p => p.GetScore) / (double)exampaper.ExampaperScore) * 100 if (exam != null) { //var exampaper = _paperDB.GetExampaper(exam.ExamPaperID); //根据得分和试卷总分算出百分比 //double sum = 8 / 11; //list[i].GetexamScore = (exam.StudentAnswerList.Sum(pa => pa.GetScore) / exampaper.ExampaperScore) * 100; list[i].GetexamScore = exam.StudentAnswerList.Sum(pa => pa.GetScore); list[i].ExamTestTimes = exam.TestTimes; //记录考试次数,考了几次 //tbExampaper paper = _paperDB.GetExampaper(list[i].PaperId); //list[i].ExamScore = paper.ExampaperScore; } else { list[i].GetexamScore = 0; //list[i].ExamScore } } return(list); }
/// <summary> /// 保存学员考试的信息 /// </summary> /// <param name="model">考试学员信息</param> /// <returns></returns> public bool SaveExamUser(tbExamSendStudent model) { return(Etdb.Modify(model)); }
/// <summary> /// 保存学员答案 /// </summary> /// <param name="answer"></param> /// <param name="quScore"></param> /// <param name="quOrder"></param> /// <param name="euid"></param> /// <param name="userRemainingTime"></param> /// <returns></returns> public JsonResult SubmitStudentAnswer(string answer, int euid, int userRemainingTime = -1) { try { tbExamSendStudent examUser = _examTestManager.GetExamUser(euid); var exampaper = _examTestManager.GetExampaperBaseInforShow(euid); if (!string.IsNullOrWhiteSpace(answer)) { var dicAnswer = new Dictionary <int, List <string> >(); var tmpAnswer = Newtonsoft.Json.JsonConvert.DeserializeObject <List <dynamic> >(answer); foreach (var item in tmpAnswer) { int id = item.id; List <string> content = new List <string>(); foreach (var c in item.content) { content.Add((string)c); } ; dicAnswer.Add(id, content); } List <tbQuestionRedundancy> qulist = _examTestManager.GetQuestionRedundancyList(dicAnswer.Keys.ToList()); examUser.StudentAnswerList = new List <ReStudentExamAnswer>(); //循环学员答案 foreach (var o in dicAnswer) { var qu = qulist.FirstOrDefault(p => p._id == o.Key); //试题 var exampaperQuestion = exampaper.QuestionList.Find(p => p.QuestionID == o.Key); if (qu != null) { string a = ""; switch (qu.QuestionType) { case 1: a = o.Value.Count == 0 ? "" : o.Value[0]; break; case 2: a = o.Value.Count == 0 ? "" : o.Value[0]; break; case 3: a = o.Value.Count == 0 ? "" : string.Join(",", o.Value.OrderBy(p => p)); break; case 4: a = o.Value.Count == 0 ? "" : o.Value[0]; break; case 5: a = o.Value.Count == 0 ? "" : string.Join("##**##", o.Value); break; case 6: if (o.Value.Count == 0) { a = ""; } else { if (qu.QuestionAnswer[0].AnswerType != 2) { a = o.Value[0]; } else { a = string.Join(",", o.Value.OrderBy(p => p)); } } break; } int score = GetScore(qu, a, exampaperQuestion.Score, examUser.SourceType); examUser.StudentAnswerList.Add(new ReStudentExamAnswer { DoneFlag = o.Value.Count == 0 ? 0 : 1, Evlution = "", GetScore = score, Answer = a, Qid = o.Key, Questionid = qu.QuestionId, QType = qu.QuestionType, Order = exampaperQuestion.QuestionOrder, Score = exampaperQuestion.Score, WrongQuestionFlag = 0 }); } } examUser.DoExamStatus = 2; int totalScore = exampaper.QuestionList.Sum(p => p.Score); //总分 int userScore = examUser.StudentAnswerList.Sum(p => p.GetScore); //考生得分 if (examUser.SourceType == 1) { examUser.Score = userScore; examUser.IsPass = userScore >= examUser.PaperScore ? 1 : 0; } else if (examUser.SourceType == 0) { if (qulist.Any(p => p.QuestionType == 1 || p.QuestionType == 5 || (p.QuestionType == 6 && p.QuestionAnswer[0].AnswerType == 0))) { examUser.IsPass = 0; } else { examUser.Score = userScore; examUser.IsPass = userScore >= examUser.PaperScore ? 1 : 0; examUser.ReadOver = 1; } } } if (userRemainingTime > -1) { examUser.RemainingTime = userRemainingTime; } examUser.SubmitTime = DateTime.Now; _examTestManager.SaveExamUser(examUser); return(Json(new { result = 1, msg = "提交成功!" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { result = 0, msg = "提交失败!" + ex.ToString() }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 课程下考试添加记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public int InserttbExamSendStudent(tbExamSendStudent model) { return(_examinationDb.Insert(model)); }
/// <summary> /// 修改 考试关联考生实体 2012-8-29 13:49:30【复评成绩时用】 /// </summary> /// <param name="examSendStudent"></param> /// <returns></returns> public bool ModifyExamSendStudent(tbExamSendStudent examSendStudent) { return(_examinationDb.Modify(examSendStudent)); }
/// <summary> /// 根据 考生考试关联ID 获取考生答题详情 /// </summary> /// <returns></returns> public JsonResult GetReStudentExamAnswerByExamUserId(int examUserId) { tbExamSendStudent examSendStudent = _examinationBL.GetExamSendStudent(examUserId); ExamBaseInforShow exam = _examTestBL.GetExamBaseInforShow(examUserId); tbExampaper examPaper = _exampaperBL.GetExampaper(examSendStudent.ExamPaperID); var itemArray = new object[examSendStudent.StudentAnswerList.Count]; int n = 0; string questionTypeHtml = ""; int q1Count = examSendStudent.StudentAnswerList.Count(q => q.QType == 1); int q2Count = examSendStudent.StudentAnswerList.Count(q => q.QType == 2); int q3Count = examSendStudent.StudentAnswerList.Count(q => q.QType == 3); int q4Count = examSendStudent.StudentAnswerList.Count(q => q.QType == 4); int q5Count = examSendStudent.StudentAnswerList.Count(q => q.QType == 5); int q6Count = examSendStudent.StudentAnswerList.Count(q => q.QType == 6); questionTypeHtml += q1Count > 0 ? "<span>问答题 ( " + q1Count + " )</span>" : ""; questionTypeHtml += q2Count > 0 ? "<span>单选题 ( " + q2Count + " )</span>" : ""; questionTypeHtml += q3Count > 0 ? "<span>多选题 ( " + q3Count + " )</span>" : ""; questionTypeHtml += q4Count > 0 ? "<span>判断题 ( " + q4Count + " )</span>" : ""; questionTypeHtml += q5Count > 0 ? "<span>填空题 ( " + q5Count + " )</span>" : ""; questionTypeHtml += q6Count > 0 ? "<span>多媒体题 ( " + q6Count + " )</span>" : ""; string answerCaseHtml = ""; answerCaseHtml += "<span>答错: " + examSendStudent.StudentAnswerList.Count(p => p.GetScore == 0 && p.Answer != "") + "</span>"; answerCaseHtml += "<span>未答: " + examSendStudent.StudentAnswerList.Count(p => p.Answer == "") + "</span>"; answerCaseHtml += "<span>正确: " + examSendStudent.StudentAnswerList.Count(p => p.GetScore > 0) + "</span>"; int totalScore = 0; foreach (ReStudentExamAnswer item in examSendStudent.StudentAnswerList) { //根据Qid 查Question表 tbQuestion question = _questionBL.GetSingleByID(item.Qid); string multi_mediaHtml = ""; if (question.QuestionType == 6) { string name = question.FileUpload[0].FileName; switch (question.FileUpload[0].FileType) { case 0: { multi_mediaHtml = " <table class='all80 cen'>" + "<tr>" + "<td class='all20' align='center' valign='middle'>" + " <a id='k-prev' style='position:relative;' onclick='turnToNext(this,\"left\");' ></a>" + "</td>" + "<td id='imageCollection' align='center' style='height: 300px;'>" + "<input type='hidden' value='1' />"; for (int i = 0; i < question.FileUpload.Count; i++) { multi_mediaHtml += "<img src='../../ClientBin/UploadFile/" + question.FileUpload[i].FileName + "' style='width:250px; height:250px; " + (i == 0 ? " display:block; " : " display:none; ") + "' />"; } multi_mediaHtml += " </td>" + "<td class='all20' align='center' valign='middle'>" + "<a id='k-next' style='position:relative;' onclick='turnToNext(this,\"right\");' ></a>" + "</td>" + "</tr>" + "</table>"; } break; case 1: { multi_mediaHtml += @"<embed class='mLeft_2' src='../../Scripts/mp3player/player.swf?url=../../ClientBin/UploadFile/" + name + "&autoplay=0;autostart=0' type='application/x-shockwave-flash' wmode='transparent' allowscriptaccess='always' height='25' width='400'></embed>"; } break; case 2: { var id = name.Substring(0, name.Length - 4); multi_mediaHtml += @"<input name='FlvName' value='" + name + @"' type='hidden' /><div class='mLeft_2'><div id='" + id + "'></div></div>"; } break; } } ReStudentExamAnswer reStuExamAnswer = examSendStudent.StudentAnswerList.Where(a => a.Qid == item.Qid).FirstOrDefault(); string qUserAnswerHtml = ""; string qRightAnswerHtml = ""; switch (item.QType) { case 1: qUserAnswerHtml = "<p><textarea class='Boxarea all60' disabled='disabled'>" + item.Answer + "</textarea></p>"; qRightAnswerHtml = question.QuestionAnswer[0].Answer; break; case 2: case 3: foreach (QuestionAnswer itemQueAnswer in question.QuestionAnswer.OrderBy(q => q.Order)) { qRightAnswerHtml += itemQueAnswer.AnswerFlag == 1 ? (qRightAnswerHtml == "" ? ((char)(itemQueAnswer.Order + 64)).ToString() : (". " + ((char)(itemQueAnswer.Order + 64)))) : ""; qUserAnswerHtml += " <p><input disabled='disabled' type='" + (item.QType == 2 ? "radio" : "checkbox") + "'" + (("," + item.Answer + ",").IndexOf("," + itemQueAnswer.Order + ",") >= 0 ? "checked='checked'" : "") + "name='answer_" + question._id + "' />" + ((char)(itemQueAnswer.Order + 64)) + ". " + itemQueAnswer.Answer + "</p>"; } break; case 4: qRightAnswerHtml = question.QuestionAnswer[0].Answer == "0" ? "A. 正确" : "B. 错误"; // 判断题 qUserAnswerHtml = "<p><input disabled='disabled' type='radio' name='answer_" + question._id + "'" + (item.Answer == "0" ? "checked='checked'" : "") + "/>A. 正确</p> <p><input disabled='disabled' type='radio' name='answer_" + question._id + "'" + (item.Answer == "1" ? "checked='checked'" : "") + " />B. 错误</p>"; break; case 5: qRightAnswerHtml = question.QuestionAnswer[0].Answer.Replace("!!%%!!", " "); // 填空题 qUserAnswerHtml = " <p>学员答案:" + (item.Answer.Replace("##**##", " ")) + "</p>"; break; case 6: int type = question.QuestionAnswer[0].AnswerType; if (type == 0) { qRightAnswerHtml = question.QuestionAnswer[0].Answer; // 问答题 qUserAnswerHtml = "<p><textarea class='Boxarea all60' disabled='disabled'>" + (item.Answer) + "</textarea></p>"; } else { //单选题 foreach (QuestionAnswer an in question.QuestionAnswer.OrderBy(p => p.Order)) { qRightAnswerHtml += an.AnswerFlag == 1 ? (qRightAnswerHtml == "" ? ((char)(an.Order + 64)).ToString() : (". " + ((char)(an.Order + 64)))) : ""; qUserAnswerHtml += " <p><input disabled='disabled' type='" + (type == 1 ? "radio" : "checkbox") + "'" + (("," + item.Answer + ",").IndexOf("," + an.Order + ",") >= 0 ? "checked=checked" : "") + " name='answer_" + question._id + "' />" + ((char)(an.Order + 64)) + ". " + (an.Answer) + "</p>"; } } break; default: break; } var temp = new { item.Qid, QOrder = item.Order, QuestionContent = "<h5>" + question.QuestionContent + "</h5><div class='db'>" + multi_mediaHtml + "</div>", UserAnswer = qUserAnswerHtml, QuestionAnswer = qRightAnswerHtml, UserGetScore = reStuExamAnswer.GetScore, QuestionScore = item.Score }; totalScore += reStuExamAnswer.GetScore; itemArray[n] = temp; n++; } return (Json( new { result = 1, dataList = itemArray.ToList(), questionTypeHtml, answerCaseHtml, examTitle = exam.ExamTitle, totalScore }, JsonRequestBehavior.AllowGet)); }
public JsonResult SubmitSaveReEvaluation(int examUserId, string qorderScore) { int totalScore = 0; string answerCaseHtml = ""; int result = 0; string content = ""; tbExamSendStudent examSendStudent = _examinationBL.GetExamSendStudent(examUserId); if (examSendStudent != null) { if (qorderScore.EndsWith(";")) { qorderScore = qorderScore.Substring(0, qorderScore.Length - 1); } List <string> list = qorderScore.Split(new[] { ';' }).ToList(); foreach (string itemStr in list) { string[] strArray = itemStr.Split(new[] { ',' }); foreach (ReStudentExamAnswer item in examSendStudent.StudentAnswerList) { if (item.Order == int.Parse(strArray[0])) { item.GetScore = int.Parse(strArray[1]); } } } //通过还是不通过 var gScore = examSendStudent.StudentAnswerList.Sum(p => p.GetScore); var tScore = examSendStudent.StudentAnswerList.Sum(p => p.Score); if (tScore == 0) { examSendStudent.IsPass = 0; } else { examSendStudent.IsPass = gScore >= examSendStudent.PaperScore ? 1 : 0; } if (_examinationBL.ModifyExamSendStudent(examSendStudent)) { result = 1; answerCaseHtml += "答错:" + examSendStudent.StudentAnswerList.Count(p => p.GetScore == 0 && p.Answer != ""); answerCaseHtml += "未答:" + examSendStudent.StudentAnswerList.Count(p => p.Answer == ""); answerCaseHtml += "正确:" + examSendStudent.StudentAnswerList.Count(p => p.GetScore > 0); totalScore = examSendStudent.StudentAnswerList.Sum(p => p.GetScore); content = "复评成功!"; } else { content = "复评失败!"; } } else { content = "该条数据已被删除,无法进行复评操作!"; } return(Json(new { result, content, totalScore, answerCaseHtml }, JsonRequestBehavior.DenyGet)); }
/// <summary> /// 保存学员答案 /// </summary> /// <param name="form">答案</param> /// <param name="euid">学员考试ID</param> /// <param name="submitType">1:暂存;2:提交</param> /// <param name="pecent">是否百分制(0:是;1:否)</param> /// <param name="passScore">及格线</param> /// 0为考试试卷1为课程下试卷 /// <returns></returns> public JsonResult SubmitStudentAnswer(FormCollection form, int euid = 0, int submitType = 1, int pecent = 0, int passScore = 0, int courseType = 0) { string answer = form["userAnswer"]; //答案 string quScore = form["questionScore"]; //试题分值 string quOrder = form["questionOrder"]; //试题题序 if (answer == "" || quScore == "" || quOrder == "") { return(Json(new { result = 0 }, JsonRequestBehavior.AllowGet)); } //tbExamSendStudent examUser = ExamTestBL.GetExamUser(euid); tbExamSendStudent examUser = null; tbExamSendStudent student = null; if (courseType == 0) { examUser = ExamTestBL.GetExamUser(euid); } else { //var student= ExamTestBL.GetExamUser(euid); student = ExamTestBL.GetExamUser(euid); examUser = ExaminationBL.GetSingletbExamSendStudentByCourseIdAndUserId(student.RelationID, CurrentUser.UserId, student.SourceType); //if (student.SourceType == 1) //{ // examUser = ExaminationBL.GetSingletbExamSendStudentByCourseIdAndUserId(student.RelationID, CurrentUser.UserId,1); //} //else //{ // examUser = ExaminationBL.GetSingletbExamSendStudentByCourseIdAndUserId(student.RelationID, CurrentUser.UserId, 2); //} } var oldPaperScore = examUser.StudentAnswerList; //.Sum(p => p.GetScore); var pass = 0; //0没通过,1通过 var nopassnumber = 0; var dicAnswer = new Dictionary <int, string>(); answer.Split(new[] { "**!!!**" }, StringSplitOptions.None).ToList().ForEach(p => { string[] arr = p.Split(new[] { "!!***!!" }, StringSplitOptions.None); dicAnswer.Add(arr[0].StringToInt32(), arr[1]); }); var dicScore = new Dictionary <int, int>(); quScore.Split(';').ToList().ForEach(p => { string[] arr = p.Split(','); dicScore.Add(arr[0].StringToInt32(), arr[1].StringToInt32()); }); var dicOrder = new Dictionary <int, int>(); quOrder.Split(';').ToList().ForEach(p => { string[] arr = p.Split(','); dicOrder.Add(arr[0].StringToInt32(), arr[1].StringToInt32()); }); List <tbQuestion> qulist = ExamTestBL.GetQuestionList(dicAnswer.Keys.ToList()); examUser.StudentAnswerList = new List <ReStudentExamAnswer>(); //int NowSum = 0;//记录当前分数 //循环学员答案 foreach (var o in dicAnswer) { tbQuestion qu = qulist.FirstOrDefault(p => p._id == o.Key); //试题 if (qu != null) { int score = submitType == 2 ? GetScore(qu, o.Value, dicScore[o.Key]) : 0; examUser.StudentAnswerList.Add(new ReStudentExamAnswer { DoneFlag = o.Value == "" ? 0 : 1, Evlution = "", GetScore = score, Answer = o.Value, Qid = o.Key, QType = qu.QuestionType, Order = dicOrder[o.Key], Score = dicScore[o.Key] }); // NowSum += score; } } if (submitType == 2) { examUser.DoExamStatus = 2; int totalScore = dicScore.Values.Sum(); //总分 examUser.PaperScore = pecent == 1 ? passScore : totalScore * passScore / 100; //考试通过的基线 int userScore = examUser.StudentAnswerList.Sum(p => p.GetScore); //考生得分 if (pecent == 0) { examUser.IsPass = userScore * 100 / totalScore >= passScore ? 1 : 0; } else { examUser.IsPass = userScore >= passScore ? 1 : 0; } } //当1的时候是课程下的考试 if (examUser.SourceType == 1) //if(courseType==1) { //var student = ExamTestBL.GetExamUser(euid); //查找这门课程对应的通过线和考试次数 var CoCoursePaper = ICoCoursePaperBL.GetCo_CourseMainPaper(student.RelationID); //查找课程信息 用于查找该课程的学时 var course = ICourseBl.GetCo_Course(student.RelationID); //查找试卷总分 var exampaper = ExampaperBL.GetExampaper(CoCoursePaper.PaperId); if (IAttendceBL.ExistAtts(course.Id, CurrentUser.UserId)) { //获取这个人预定信息 因为集中课程学时是走一步算一步 获取已经获得的学时 var courseorder = CourseOrderBL.GetCourseById(student.RelationID, CurrentUser.UserId); //如果当前考试分数大于上一次考的分数则修改, 如果小则还是记录以前的分数 int fenshju = examUser.StudentAnswerList.Sum(p => p.GetScore); //int olderfenshuju= if (fenshju > oldPaperScore.Sum(p => p.GetScore)) { //examUser.PaperScore = fenshju; ExamTestBL.SaveExamUser(examUser); } else { if (oldPaperScore.Count != 0) // 如果第一次没过就记录当前选项 { examUser.StudentAnswerList = oldPaperScore; } ExamTestBL.SaveExamUser(examUser); } //var xueshi = AllSystemConfigs.Find(p => p.ConfigType == 24); var xueshi = course.CourseLengthDistribute; var aa = examUser.StudentAnswerList.Sum(p => p.GetScore); var tongguofen = (exampaper.ExampaperScore * CoCoursePaper.LevelScore) / 100; //var aa = ((double)examUser.StudentAnswerList.Sum(p => p.GetScore) / (double)exampaper.ExampaperScore)*100; //考试没有超过通线 记录课后评估 //if ((int)aa < CoCoursePaper.LevelScore) nopassnumber = Convert.ToInt32(CoCoursePaper.TestTimes) - student.TestTimes; if ((int)aa < (int)tongguofen) { pass = 0; //考试不过则不做任何操作 if (examUser.Number == 0) { //double afterlenght = (double) Convert.ToInt32(xueshi.ConfigValue.Split(';')[0])/100 + // (double) Convert.ToInt32(xueshi.ConfigValue.Split(';')[2])/100; ////获取考试不过的百分比 //decimal forlenght = course.CourseLength*Convert.ToDecimal(afterlenght); ////加上已得分数 //decimal tt = courseorder.GetScore + forlenght; ////PassStatus;1:通过;2:不通过;LearnStatus: 1:进行中;2:已完成 //CourseOrderBL.UpdateGetScore(course.Id, CurrentUser.UserId, tt, 2, 1); } } else //考试通过 { pass = 1; //当Number为1的时候 则不在记录学时 if (examUser.Number == 0) { //只有考勤和考试 没有评估 考试通过后则把考试和评估的部分都加上去 if (course.IsPing == 0 && course.IsTest == 1) { double afterlenght = (double)Convert.ToInt32(xueshi.Split(';')[1]) / 100 + (double)Convert.ToInt32(xueshi.Split(';')[2]) / 100; decimal fortestlenght = (Convert.ToDecimal(afterlenght) * course.CourseLength) + courseorder.GetScore; #region 折算CPA学时 if (course.IsCPA == 1) { Cl_CpaLearnStatus cls = ICpaLearnStatusBL.GetCl_CpaLearnStatusByCourseId(course.Id, CurrentUser.UserId); if (cls == null) { cls = new Cl_CpaLearnStatus(); cls.CourseID = course.Id; cls.UserID = CurrentUser.UserId; cls.IsAttFlag = 0; cls.Progress = 0; cls.LearnTimes = 0; if (course.IsMust == 1) { cls.GetLength = fortestlenght * Convert.ToDecimal(0.5); } if (course.IsMust == 0) { cls.GetLength = fortestlenght; } cls.CpaFlag = 2; cls.GradeStatus = 1; ICpaLearnStatusBL.SubscribeCPALearnStatus(cls); } else { cls.IsAttFlag = 0; cls.IsPass = 1; cls.Progress = 0; cls.LearnTimes = 0; //cls.GetLength = fortestlenght; if (course.IsMust == 1) { cls.GetLength = fortestlenght * Convert.ToDecimal(0.5); } if (course.IsMust == 0) { cls.GetLength = fortestlenght; } cls.CpaFlag = 2; cls.GradeStatus = 1; ICpaLearnStatusBL.UpdateCPALearnStatusByModel(cls); } } #endregion CourseOrderBL.UpdateGetScore(course.Id, CurrentUser.UserId, fortestlenght, 1, 2); //考试通过后就把Number标志位改成1 以后在考试则不记学时 ExaminationBL.UpdateNumber(student._id, 1); } else //有考勤 评估 考试。考试通过则把考试那部分加上去 { //考过后 已得到的分数+考试所占的比例 decimal fortestlenght = (course.CourseLength * Convert.ToDecimal((double)Convert.ToInt32(xueshi.Split(';')[1]) / 100)) + courseorder.GetScore; CourseOrderBL.UpdateGetScore(course.Id, CurrentUser.UserId, fortestlenght, 1, 2); //考试通过后就把Number标志位改成1 以后在考试则不记学时 ExaminationBL.UpdateNumber(student._id, 1); #region 折算CPA学时 if (course.IsCPA == 1) { Cl_CpaLearnStatus cls = ICpaLearnStatusBL.GetCl_CpaLearnStatusByCourseId(course.Id, CurrentUser.UserId); if (cls == null) { cls = new Cl_CpaLearnStatus(); cls.CourseID = course.Id; cls.UserID = CurrentUser.UserId; cls.IsAttFlag = 0; cls.Progress = 0; cls.LearnTimes = 0; if (course.IsMust == 1) { cls.GetLength = fortestlenght * Convert.ToDecimal(0.5); } if (course.IsMust == 0) { cls.GetLength = fortestlenght; } cls.CpaFlag = 2; cls.GradeStatus = 1; ICpaLearnStatusBL.SubscribeCPALearnStatus(cls); } else { cls.IsAttFlag = 0; cls.IsPass = 1; cls.Progress = 0; cls.LearnTimes = 0; //cls.GetLength = fortestlenght; if (course.IsMust == 1) { cls.GetLength = fortestlenght * Convert.ToDecimal(0.5); } if (course.IsMust == 0) { cls.GetLength = fortestlenght; } cls.CpaFlag = 2; cls.GradeStatus = 1; ICpaLearnStatusBL.UpdateCPALearnStatusByModel(cls); } } #endregion } } } //如果当前考试次数等于考试总次数后 改变考试通过LearnStatus if (CoCoursePaper.TestTimes == examUser.TestTimes) { CourseOrderBL.UpdateLearnStatus(course.Id, CurrentUser.UserId, 2); } } } else if (examUser.SourceType == 2)//2为视频下的考试 { //var student = ExamTestBL.GetExamUser(euid); var CoCoursePaper = ICoCoursePaperBL.GetCo_CourseMainPaper(student.RelationID); var course = ICourseBl.GetCo_Course(student.RelationID); var exampaper = ExampaperBL.GetExampaper(CoCoursePaper.PaperId); //var courseorder = CourseOrderBL.GetCourseById(student.RelationID); //如果当前考试分数大于上一次考的分数则修改, 如果小则还是记录以前的分数 if (examUser.StudentAnswerList.Sum(p => p.GetScore) > oldPaperScore.Sum(p => p.GetScore)) { ExamTestBL.SaveExamUser(examUser); } else { if (oldPaperScore.Count != 0) { examUser.StudentAnswerList = oldPaperScore; } ExamTestBL.SaveExamUser(examUser); } var aa = examUser.StudentAnswerList.Sum(p => p.GetScore); var tongguofen = (exampaper.ExampaperScore * CoCoursePaper.LevelScore) / 100; //var aa = ((double)examUser.StudentAnswerList.Sum(p => p.GetScore) / (double)exampaper.ExampaperScore) * 100; nopassnumber = Convert.ToInt32(CoCoursePaper.TestTimes) - student.TestTimes; //考试没有超过通线 记录课后评估 if (aa < tongguofen) { pass = 0; //考试没过的话 if (student.TestTimes == 1) { ICpaLearnStatusBL.UpdateGetCl_CpaLearnStatusByCourseId(course.Id, CurrentUser.UserId, 0, 0); } //关键 如果考试次数达到考试次数还没过 则清空他学习记录 重新在读 } else { pass = 1; if (examUser.Number == 0) { ICpaLearnStatusBL.UpdateGetCl_CpaLearnStatusByCourseId(course.Id, CurrentUser.UserId, course.CourseLength, 1); ExaminationBL.UpdateNumber(student._id, 1); #region 折算cpa学时 if (course.IsCPA == 1) { Cl_CpaLearnStatus cls = new Cl_CpaLearnStatus(); cls.CourseID = course.Id; cls.UserID = CurrentUser.UserId; cls.IsAttFlag = 0; cls.Progress = 0; cls.LearnTimes = 0; if (course.IsMust == 1) { cls.GetLength = course.CourseLength * (Convert.ToDecimal(0.5)); } if (course.IsMust == 0) { cls.GetLength = course.CourseLength; } cls.CpaFlag = 2; cls.GradeStatus = 1; cls.IsPass = 1; ICpaLearnStatusBL.SubscribeCPALearnStatus(cls); } #endregion } } //通过了之后 达到考试次数就不在清数据..如果达到次数都没过就清次数 if (examUser.Number == 0 && examUser.TestTimes == CoCoursePaper.TestTimes) { var examUserSecond = ExaminationBL.GetSingletbExamSendStudentByCourseIdAndUserId(student.RelationID, CurrentUser.UserId, 2); if (examUser.TestTimes == CoCoursePaper.TestTimes && aa < CoCoursePaper.LevelScore) { var cpa = ICpaLearnStatusBL.GetCl_CpaLearnStatusByCourseId(examUserSecond.RelationID, CurrentUser.UserId); ICpaLearnStatusBL.DeleteLearn(cpa.Id); ExaminationBL.DeleteExamSendStudentWithByCourseIdAndUserId(course.Id, CurrentUser.UserId, 2); } } } else { ExamTestBL.SaveExamUser(examUser); return(Json(new { result = 1 }, JsonRequestBehavior.AllowGet)); } return(Json(new { result = 0, courseid = examUser.RelationID, way = examUser.SourceType, pass = pass, nopassnumber = nopassnumber }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 获取一个考试的详情【考前须知、试卷信息】 /// </summary> /// <param name="euId"></param> /// <returns></returns> public JsonResult GetExamDetailByEuId(int euId, int dw = 0) { try { int leavePageTimes = 0; tbExamSendStudent eu = _examTestManager.GetExamUser(euId); if (eu.RemainingTime == 0 && dw == 0) { return(Json(new { result = 0, msg = "您的考试时间已用完,不可进入!" }, JsonRequestBehavior.AllowGet)); } int examTestTimes = 0; tbExamination exam = _examinationManager.GetExamination(eu.RelationID); examTestTimes = exam.TestTimes; if (exam.LeavePageTimes < eu.LeavePageTimes && dw == 0) { return(Json(new { result = 0, msg = "您离开页面的总次数已用完,不可进入!" }, JsonRequestBehavior.AllowGet)); } if (eu.TestTimes >= exam.TestTimes && dw == 0) { return(Json(new { result = 0, msg = "进入次数已达到上限,不可进入!" }, JsonRequestBehavior.AllowGet)); } if (exam.ExamEndTime.ToLocalTime() <= DateTime.Now && dw == 0) { return(Json(new { result = 0, msg = "本场考试已经结束,不可进入!" }, JsonRequestBehavior.AllowGet)); } var exambase = _examTestManager.GetExamBaseInforShow(euId, leavePageTimes); var exampaper = _examTestManager.GetExampaperBaseInforShow(euId); List <KeyValuePair <string, string> > filePath = new List <KeyValuePair <string, string> >(); foreach (var item in exampaper.QuestionList) { if (item.QType == 6) { foreach (var p in item.FileUpload) { p.fileName = "http://" + Request.Url.Authority + p._fileName; filePath.Add(new KeyValuePair <string, string>(p._fileName, p._fileName)); } } } string txtContent = Newtonsoft.Json.JsonConvert.SerializeObject(new { exambase = new { exambase.ExamRuleList, exambase.ExamEndTime, exambase.ExamStartTime, exambase.ExamLength, exambase.ExamTitle, exambase.UserRemainingTime }, exampaper = new { QuestionList = exampaper.QuestionList.Select(p => new { FileUpload = p.FileUpload.Select(f => new { fileName = f._fileName, fileType = f._fileType }), p.QAnswerType, p.QType, QuestionAnswer = p.QuestionAnswer.Select(q => new { q.AnswerContent, q.AnswerType, q.Order, q.oldOrder }), p.QuestionContent, p.QuestionID, p.QuestionOrder, p.FillBlankCount, p.UserAnswer, p.Score }) }, testTimes = examTestTimes - eu.TestTimes }); string jsonfilename = Guid.NewGuid().ToString(); string jsonfilefilepath = Server.MapPath(Url.Addr("~/UploadFiles/ExamQuestionResource/") + jsonfilename + ".json"); System.IO.File.WriteAllText(jsonfilefilepath, txtContent); filePath.Add(new KeyValuePair <string, string>(jsonfilefilepath, "data.json")); string zipFilePath = ""; long filesize = 0; if (filePath.Count > 0) { string filename = Guid.NewGuid().ToString(); if (!Directory.Exists(Server.MapPath("~/UploadFiles/tmp/"))) { Directory.CreateDirectory(Server.MapPath("~/UploadFiles/tmp/")); } FileZipHelper.PackFiles(Server.MapPath("~/UploadFiles/tmp/" + filename + ".zip"), filePath); zipFilePath = "http://" + Request.Url.Authority + Url.Addr("~/UploadFiles/tmp/") + filename + ".zip"; filesize = new System.IO.FileInfo(Server.MapPath("~/UploadFiles/tmp/" + filename + ".zip")).Length; } return(Json(new { result = 1, msg = "获取成功!", zipFilePath = zipFilePath, FileSize = filesize }, JsonRequestBehavior.AllowGet)); } catch { return(Json(new { result = 0, msg = "获取失败!" }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 获取试卷的试题 /// </summary> /// <param name="exampaper">试卷信息</param> /// <param name="exam">试卷信息</param> /// <param name="examuser">学员答案</param> public void GetExampaper(ExampaperShow exampaper, tbExampaper exam, tbExamSendStudent examuser) { if (exampaper.ExampaperType == 0) { #region 正常 IMongoQuery query = Query.In("_id", new BsonArray(exam.QuestionList.Select(p => p.Qid))); List <tbQuestion> quList = Etdb.GetAllList <tbQuestion>(query); //获取试题 exam.QuestionList.ForEach(p => { tbQuestion qu = quList.FirstOrDefault(q => q._id == p.Qid); if (qu != null) { ReStudentExamAnswer an = examuser == null ? null : examuser.StudentAnswerList.FirstOrDefault( pa => pa.Qid == p.Qid); var newqu = new MQuestion { QAnswerType = qu.QuestionAnswer[0].AnswerType, QType = qu.QuestionType, QuestionContent = qu.QuestionContent, QuestionID = qu._id, QuestionLevel = ((QuestionLevel)qu.QuestionLevel).ToString(), QuestionOrder = p.QOrder, Score = p.QScore, UserAnswer = an == null ? "" : (an.Answer), FillBlankCount = qu.QuestionContent.Split(new[] { "()" }, StringSplitOptions.None).Count() - 1 }; qu.QuestionAnswer.OrderBy(o => o.Order) .ToList() .ForEach(pa => newqu.QuestionAnswer.Add(new MQuestionAnswer { AnswerContent = pa.Answer, AnswerFlag = pa.AnswerFlag, AnswerType = pa.AnswerType, Order = pa.Order, QuID = newqu.QuestionID, QType = newqu.QType })); qu.FileUpload.ForEach(pa => newqu.FileUpload.Add(new QuestionFile { _fileName = pa.FileName, _fileType = pa.FileType, _realName = pa.RealName })); exampaper.QuestionList.Add(newqu); } }); #endregion } else { #region 随机 List <tbQuestion> questionList = Etdb.GetAllList <tbQuestion>(Query.EQ("Status", 0)); exam.QuestionRule.ForEach(p => { var newqulist = new List <tbQuestion>(); foreach (string s in p.QLevelStr.Split(';')) { newqulist.AddRange( questionList.Where( qu => p.QSort == qu.QuestionSortID && p.Qtype == qu.QuestionType && s.Split(':')[0].StringToInt32() == qu.QuestionLevel) .ToList() .RandomGetSome(s.Split(':')[1].StringToInt32())); } newqulist.ForEach(qu => { var newqu = new MQuestion { QAnswerType = qu.QuestionAnswer[0].AnswerType, QType = qu.QuestionType, QuestionContent = qu.QuestionContent, QuestionID = qu._id, QuestionLevel = ((QuestionLevel)qu.QuestionLevel).ToString(), QuestionOrder = 0, Score = p.QScore, UserAnswer = "", FillBlankCount = qu.QuestionContent.Split(new[] { "()" }, StringSplitOptions.None).Count() - 1 }; qu.QuestionAnswer.OrderBy(o => o.Order) .ToList() .ForEach(pa => newqu.QuestionAnswer.Add(new MQuestionAnswer { AnswerContent = pa.Answer, AnswerFlag = pa.AnswerFlag, AnswerType = pa.AnswerType, Order = pa.Order, QuID = newqu.QuestionID, QType = newqu.QType })); qu.FileUpload.ForEach(pa => newqu.FileUpload.Add(new QuestionFile { _fileName = pa.FileName, _fileType = pa.FileType, _realName = pa.RealName })); exampaper.QuestionList.Add(newqu); }); }); #endregion } //if (exampaper.ExampaperType == 1 || (examination._id > 0 && examination.RadomOrderFlag == 1)) if (exampaper.ExampaperType == 1) { //排序 int order = 1; foreach (string s in exam.QuestionTypeOrder.Split(',')) { exampaper.QuestionList.Where(p => p.QType == s.StringToInt32()) .ToList() .RandomListOrder() .ForEach(p => { p.QuestionOrder = order; order++; }); } } exampaper.QuestionList = exampaper.QuestionList.OrderBy(p => p.QuestionOrder).ToList(); }
/// <summary> /// 获取试卷的试题 /// </summary> /// <param name="exampaper">试卷信息</param> /// <param name="exam">试卷信息</param> /// <param name="examuser">学员答案</param> /// <param name="examination">考试信息</param> private void GetExampaper(ExampaperShow exampaper, tbExampaperRedundancy exam, tbExamSendStudent examuser, tbExamination examination) { var radomOrder = string.IsNullOrWhiteSpace(examination.RadomOrderFlag) ? new string[0] : examination.RadomOrderFlag.Split(','); //IMongoQuery query = Query.In("_id", new BsonArray(exam.QuestionList.Select(p => p.Qid))); IMongoQuery query = Query.In("_id", new BsonArray(examuser.StudentAnswerList.Select(p => p.Qid))); if (!examuser.StudentAnswerList.Any()) { //如果没有试题,则加入试题 if (exam.ExamType == 0) { exam.QuestionList.ForEach(p => { examuser.StudentAnswerList.Add(new ReStudentExamAnswer { Qid = p.Qid, Questionid = p.Questionid, Order = p.QOrder, QType = p.QType, Score = p.QScore, DoneFlag = 0, Answer = "", Evlution = "", GetScore = 0, WrongQuestionFlag = 0 }); }); } else { examuser = new RetechWing.BusinessCommon.Examination.GenerateExampaper().RandomGenerate(examuser, exam.QuestionRule); var questionIds = examuser.StudentAnswerList.Select(p => p.Questionid); var questions = Etdb.GetAllList <tbQuestion>(Query.In("_id", new BsonArray(questionIds))); int i = 1; foreach (var item in examuser.StudentAnswerList) { var tmp = questions.FirstOrDefault(p => p._id == item.Questionid); var questionRed = new tbQuestionRedundancy { QuestionId = tmp._id, QuestionSortID = tmp.QuestionSortID, QuestionOpen = tmp.QuestionOpen, UserID = tmp.UserID, CreateTime = tmp.CreateTime, FileUpload = tmp.FileUpload, LastUpdateTime = tmp.LastUpdateTime, QuestionAnalysis = tmp.QuestionAnalysis, QuestionAnswer = tmp.QuestionAnswer, QuestionAnswerKeys = tmp.QuestionAnswerKeys, QuestionAvailable = tmp.QuestionAvailable, QuestionContent = tmp.QuestionContent, QuestionKey = tmp.QuestionKey, QuestionLevel = tmp.QuestionLevel, QuestionType = tmp.QuestionType, Status = tmp.Status, TenantId = tmp.TenantId }; item.Qid = Etdb.Insert <tbQuestionRedundancy>(questionRed); item.Order = i; i++; } } Etdb.Modify <tbExamSendStudent>(examuser); query = Query.In("_id", new BsonArray(examuser.StudentAnswerList.Select(p => p.Qid))); } ////从缓存中读取所有问题 //List<tbQuestionRedundancy> quList; //获取试题 //var cachekey = "examquestions:tenant:" + exam.TenantId; //quList = _cacheService.Get<List<tbQuestionRedundancy>>(cachekey); //if (quList == null || quList.Count == 0) //{ // quList = Etdb.GetAllList<tbQuestionRedundancy>(query); // _cacheService.Set(cachekey, quList, CachingExpirationType.Stable); //} var quList = Etdb.GetAllList <tbQuestionRedundancy>(query); //题目随机 if (radomOrder.Contains("1")) { var radomList = new List <int>(); var next = 0; var length = examuser.StudentAnswerList.Count; for (int i = 0; i < length; i++) { do { next = new Random().Next(); if (!radomList.Contains(next)) { examuser.StudentAnswerList[i].Order = next; radomList.Add(next); break; } } while (true); } } var m = 0; examuser.StudentAnswerList.OrderBy(p => p.Order).ToList().ForEach(p => { p.Order = ++m; tbQuestionRedundancy qu = quList.FirstOrDefault(q => q._id == p.Qid); if (qu != null) { ReStudentExamAnswer an = examuser == null ? null : examuser.StudentAnswerList.FirstOrDefault( pa => pa.Qid == p.Qid); var newqu = new MQuestion { QAnswerType = qu.QuestionType == 6 ? qu.QuestionAnswer[0].AnswerType : 0, QType = qu.QuestionType, //QuestionContent = qu.QuestionContent, QuestionContent = qu.QuestionContent.NoHtml().HtmlDecode(), QuestionID = qu._id, QuestionLevel = EnumsLanguage.GetString(((QuestionLevel)qu.QuestionLevel).ToString()), QuestionOrder = p.Order, Score = p.Score, UserAnswer = an == null ? "" : (an.Answer), UserAnswerScore = an == null ? 0 : an.GetScore, FillBlankCount = qu.QuestionContent.Split(new[] { "()" }, StringSplitOptions.None).Length - 1, WrongQuestionFlag = an == null ? 0 : an.WrongQuestionFlag, QuestionAnalysis = qu.QuestionAnalysis }; //记录选项随机前的原有序号 var tmpquestionlist = new List <MQuestionAnswer>(); //选择随机 if (radomOrder.Contains("2")) { var radomList = new List <int>(); var next = 0; var length = qu.QuestionAnswer.Count; for (int i = 0; i < length; i++) { do { next = new Random().Next(); if (!radomList.Contains(next)) { tmpquestionlist.Add(new MQuestionAnswer { Order = next, oldOrder = qu.QuestionAnswer[i].Order }); qu.QuestionAnswer[i].Order = next; radomList.Add(next); break; } } while (true); } } var n = 0; qu.QuestionAnswer.OrderBy(o => o.Order).ToList().ForEach(pa => { var tmp = tmpquestionlist.FirstOrDefault(t => t.Order == pa.Order); pa.Order = ++n; newqu.QuestionAnswer.Add(new MQuestionAnswer { AnswerContent = pa.Answer, AnswerFlag = pa.AnswerFlag, AnswerType = pa.AnswerType, Order = pa.Order, QuID = newqu.QuestionID, QType = newqu.QType, oldOrder = tmp == null ? pa.Order : tmp.oldOrder }); }); qu.FileUpload.ForEach(pa => newqu.FileUpload.Add(new QuestionFile { _fileName = pa.FileName, _fileType = pa.FileType, _realName = pa.RealName })); exampaper.QuestionList.Add(newqu); } }); exampaper.QuestionList = exampaper.QuestionList.OrderBy(p => p.QuestionOrder).ToList(); }
/// <summary> /// 保存单个考试人员答案 /// </summary> /// <param name="eu">考试人员信息</param> /// <returns></returns> public bool SaveExamUser(tbExamSendStudent eu) { return(Etdb.Modify(eu)); }