/// <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> /// <param name="examName">考试名称</param> /// <param name="type">0:未开始;1:进行中;2:已结束;3:已过期</param> /// <param name="passflag">当type==2时,0:全部;1:通过;2:不通过</param> /// <param name="pageSize">每页显示的个数</param> /// <param name="pageIndex">当前页</param> /// <returns></returns> public JsonResult GetMyExamTestList(string examName = "", int type = 0, int passflag = 0, int pageSize = 20, int pageIndex = 1) { //获取我的考试信息 List <tbExamSendStudent> myTotalExamList = ExamTestBL.GetMyExamList(Session["userID"].StringToInt32()); //相关的考试 List <tbExamination> examlist = ExaminationBL.GetAllExamination(myTotalExamList.Select(p => p.RelationID)); //相关的试卷 List <tbExampaper> paperList = ExampaperBL.GetAllExampaper(examlist.Select(p => p.PaperID)); //筛选后的我的考试 var myExamListShow = new List <ExamTestShow>(); myTotalExamList.ForEach(p => { var exam = examlist.FirstOrDefault(pa => pa._id == p.RelationID); if (exam != null && exam.PublishedFlag == 1) { tbExampaper paper = paperList.FirstOrDefault(pa => pa._id == exam.PaperID); if (paper != null) { var toscore = paper.ExamType == 0 ? paper.QuestionList.Sum(pc => pc.QScore) : paper.ExampaperScore; if (toscore > 0) { myExamListShow.Add(new ExamTestShow { ExamUserID = p._id, ExampaperID = exam.PaperID, ExampaperSortID = paper.ExamSortID, ExamTitle = exam.ExaminationTitle, EndTime = exam.ExamEndTime.ToLocalTime(), ExamLength = exam.ExamLength, ExamTestTimes = p.TestTimes + "/" + exam.TestTimes, ExamScore = exam.PercentFlag == 0 ? (exam.PassScore + "/100") : (Convert.ToInt32(toscore * exam.PassScore / 100) + "/" + toscore), PassFlag = exam.PublishResult == 1 ? p.IsPass : 3, //未发布成绩时3 ScoreOrder = exam.PublishResult == 1 ? "-" : "--", //未发布成绩时"--",否则"-" StartTime = exam.ExamBeginTime.ToLocalTime(), DoExamStatus = p.DoExamStatus, ExamID = p.RelationID, GetScore = exam.PublishResult == 1 ? (exam.PercentFlag == 0 ? (p.StudentAnswerList.Sum(pa => pa.GetScore) * 100 / toscore + "") : (p.StudentAnswerList.Sum(pa => pa.GetScore) + "")) : "--", pFlag = passflag }); } } } }); myExamListShow = myExamListShow.Where(p => p.ExamTitle.Contains(examName) && type == p.examStatus).ToList(); IEnumerable <ExamTestShow> myExam = myExamListShow.OrderByDescending(p => p.ExamUserID).Skip((pageIndex - 1) * pageSize).Take(pageSize); //所有的参考人员 var allExamUser = new List <tbExamSendStudent>(); if (type == 1 || type == 2) { IEnumerable <int> examLists = myExam.ToList().Select(p => p.ExamID); allExamUser = ExamTestBL.GetExamSendStudentList(examLists); } foreach (ExamTestShow exam in myExam) { if (type == 0 || type == 3) { exam.ScoreOrder = "--"; } else { int score = allExamUser.FirstOrDefault(p => p._id == exam.ExamUserID).StudentAnswerList.Sum(p => p.GetScore); int order = allExamUser.Count( p => p.RelationID == exam.ExamID && p.StudentAnswerList.Sum(pa => pa.GetScore) > score); exam.ScoreOrder = exam.ScoreOrder == "-" ? (order + 1).ToString() : "--"; } } return(Json(new { result = 1, dataList = myExam.ToList(), recordCount = myExamListShow.Count }, JsonRequestBehavior.AllowGet)); }