/// <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="examBeginTimeStart"></param> /// <param name"examBeginTimeEnd"></param> /// <param name="examinationTitle"></param> /// <param name="startFlag">0:未开始 1:进行中 2:已结束 -1:全部</param> /// <param name="orderbyName">0:创建时间 1:考试开始时间 2:考试次数 </param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="orderbyFlag">0:不desc 1:desc </param> /// <returns></returns> public JsonResult GetExaminationList(string examBeginTimeStart, string examBeginTimeEnd, string examinationTitle, int startFlag = -1, int orderbyFlag = 0, int orderbyName = 0, int pageSize = 10, int pageIndex = 1) { IEnumerable <tbExamination> result = _examinationBL.GetAllExamination().Where(p => p.ExaminationTitle.Contains(examinationTitle)); if (!string.IsNullOrEmpty(examBeginTimeStart)) { result = result.Where(p => p.ExamBeginTime.ToLocalTime() >= examBeginTimeStart.StringToDate(0)); } if (!string.IsNullOrEmpty(examBeginTimeEnd)) { result = result.Where(p => p.ExamBeginTime.ToLocalTime() <= examBeginTimeEnd.StringToDate(1)); } switch (startFlag) { case -1: break; case 0: result = result.Where(p => DateTime.Now < p.ExamBeginTime.ToLocalTime() && p.PublishedFlag == 1); break; case 1: result = result.Where( p => p.ExamBeginTime.ToLocalTime() < DateTime.Now && DateTime.Now < p.ExamEndTime.ToLocalTime() && p.PublishedFlag == 1); break; case 2: result = result.Where(p => p.ExamEndTime.ToLocalTime() < DateTime.Now && p.PublishedFlag == 1); break; case 3: result = result.Where(p => p.PublishedFlag == 0); break; } switch (orderbyName) { case 0: if (orderbyFlag == 0) { result = result.OrderBy(p => p.CreateTime); } else if (orderbyFlag == 1) { result = result.OrderByDescending(p => p.CreateTime); } break; case 1: if (orderbyFlag == 0) { result = result.OrderBy(p => p.ExamBeginTime); } else if (orderbyFlag == 1) { result = result.OrderByDescending(p => p.ExamBeginTime); } break; case 2: if (orderbyFlag == 0) { result = result.OrderBy(p => p.TestTimes); } else if (orderbyFlag == 1) { result = result.OrderByDescending(p => p.TestTimes); } break; } int totalCount = result.Count(); result = result.Skip((pageIndex - 1) * pageSize).Take(pageSize); var itemArray = new object[result.Count()]; int n = 0; foreach (tbExamination item in result) { string strStatus = ""; string examTotalScore = ""; int intPassScore = 0; if (item.PublishedFlag == 1) { if (item.ExamEndTime.ToLocalTime() > DateTime.Now && DateTime.Now > item.ExamBeginTime.ToLocalTime()) { strStatus = "进行中"; } else if (item.ExamEndTime.ToLocalTime() < DateTime.Now) { strStatus = "已结束"; } else { strStatus = "未开始"; } } else { strStatus = "未发布"; } if (item.PercentFlag == 1)//如果不是百分制,那么 通过分数 需要乘以 百分比 { tbExampaper paper = _exampaperBL.GetExampaper(item.PaperID); intPassScore = Convert.ToInt32(paper.ExampaperScore * item.PassScore * 0.01); examTotalScore = paper.ExampaperScore.ToString(); } else { examTotalScore = "100"; intPassScore = Convert.ToInt32(item.PassScore); } var temp = new { item._id, item.ExaminationTitle, item.ExamLength, ExamBeginTime = item.ExamBeginTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm"), ExamEndTime = item.ExamEndTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm"), item.TestTimes, intPassScore, examTotalScore, ExamStaus = strStatus, AuthExamHtml = item.PublishedFlag == 1 ? "disabled='disabled'" : " onclick='AuthExam(" + item._id + ")' ", DetailExamHtml = " onclick='DetailExam(" + item._id + ")' ", ModifyExamHtml = item.PublishedFlag == 1 ? "disabled='disabled'" : " onclick='ModifyExam(" + item._id + ")' ", DeleteExamHtml = item.PublishedFlag == 1 ? "disabled='disabled'" : " onclick='DeleteExam(" + item._id + ")' ", PublishExamHtml = (strStatus == "未发布" && item.PublishedFlag == 0) ? "onclick='PublishExam(" + item._id + ")'" : "disabled='disabled'" }; itemArray[n] = temp; n++; } return(Json(new { result = 1, dataList = itemArray.ToList(), recordCount = totalCount }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 查看试卷呈现 /// </summary> public ViewResult ExampaperDetail(int flag = 0) { int id = Convert.ToInt32(Request.QueryString["id"]); tbExampaper expape = EBL.GetExampaper(id); List <ReExampaperQuestion> questionList = expape.QuestionList; List <ReRuleQuestion> ruleList = expape.QuestionRule; var itemArray = new List <tbQuestion>(); if (questionList.Count > 0) { //遍历试卷问题ID,获取题目 foreach (ReExampaperQuestion Pquestion in questionList) { tbQuestion baseInfor = qBL.GetSingleByID(Pquestion.Qid); baseInfor.QuestionAnswer = baseInfor.QuestionAnswer.OrderByDescending(p => p.AnswerFlag).ToList(); itemArray.Add(baseInfor); } } var itemArray1 = new List <MExamRuleShow>(); if (ruleList.Count > 0) { foreach (ReRuleQuestion qRule in ruleList) { var eq = new MExamRuleShow(); eq.QuestingScore = qRule.QScore; switch (qRule.Qtype) { case 1: //问答题 eq.QuestionType = "问答题"; break; case 2: //单选题 eq.QuestionType = "单选题"; break; case 3: //多选题 eq.QuestionType = "多选题"; break; case 4: //判断题 eq.QuestionType = "判断题"; break; case 5: //填空题 eq.QuestionType = "填空题"; break; case 6: //情景题 eq.QuestionType = "情景题"; break; } tbQuestionSort qSort = qSortBL.GetSingleByID(qRule.QSort); eq.QuestionSort = qSort.Title; string[] questionLevel = qRule.QLevelStr.Split(';'); string[] Easy = questionLevel[0].Split(':'); string[] Common = questionLevel[1].Split(':'); string[] Hard = questionLevel[2].Split(':'); eq.Leveleasy = Convert.ToInt32(Easy[1]); eq.Levelcommon = Convert.ToInt32(Common[1]); eq.Levelhard = Convert.ToInt32(Hard[1]); string qit1 = qRule.Qtype + "|" + qRule.QSort; string qit = qRule.Qtype + "|" + qRule.QSort + "|" + qRule.QScore + "|" + Easy[1] + "|" + Common[1] + "|" + Hard[1]; eq.qita = qit; eq.qitaone = qit1; itemArray1.Add(eq); } } if (Request.QueryString["sortID"] != null) { if (flag == 1) { ViewData["fatherModel"] = eSortBL.GetAllExampaperSortDictionary().Keys.Contains(expape.ExamSortID) ? eSortBL.GetAllExampaperSortDictionary()[expape.ExamSortID].Title : "无"; } else { ViewData["fatherModel"] = Request.QueryString["SortID"] == "0" ? Exampaper.NO : eSortBL.GetAllExampaperSortDictionary()[ Convert.ToInt32(Request.QueryString["sortID"])].Title; } } else { ViewData["fatherModel"] = Exampaper.NO; } ViewData["expape"] = expape; ViewData["expapeQuestion"] = itemArray; ViewData["expapeRule"] = itemArray1; return(View()); }