/// <summary> /// 修改试卷 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool UpdateExamPaper(W_ExamPaper model) { if (string.IsNullOrEmpty(model.Title)) { throw new ApiException("试卷名称不能为空"); } W_ExamPaper exam = Orm.Single <W_ExamPaper>(x => x.ID == model.ID); if (exam == null) { throw new ApiException("该试卷不存在或者已删除"); } if (exam.Valid == 1) { throw new ApiException("该试卷已审核,不能修改"); } model.AddPerson = exam.AddPerson; model.AddTime = exam.AddTime; model.System_Station_ID = exam.System_Station_ID; model.DoCount = exam.DoCount; if (model.QuestionStore_ID != exam.QuestionStore_ID) { List <W_ExamPaperDetail_Detail> list = Orm.Select <W_ExamPaperDetail_Detail>(x => x.ExamPaper_ID == model.ID); if (list.Count > 0) { throw new ApiException("试卷已配置题目,请先删除再修改所属题库"); } } return(Orm.Update(model) > 0); }
/// <summary> /// 审核试卷 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool UpdateExamPaperValid(W_ExamPaper model) { if (model.ID <= 0) { throw new ApiException("无效参数,请重试!"); } W_ExamPaper Exammodel = Orm.Single <W_ExamPaper>(x => x.ID == model.ID); if (Exammodel == null) { throw new ApiException("未找到对应数据,请刷新重试!"); } List <ContrastQuestionNumModel> list = SqlMapper.QueryForList <ContrastQuestionNumModel>("ContrastQuestionNum", new { examPaperId = model.ID }).ToList(); if (list.Count == 0) { throw new ApiException("审核失败,请添加好题目再试!"); } foreach (ContrastQuestionNumModel item in list) { if (item.Num != item.HasCount) { throw new ApiException("审核失败,题目数量不匹配,请添加好题目再试!"); } } if (Exammodel.Valid == 1) { throw new ApiException("该试卷已审核,请勿重复审核!"); } Exammodel.Valid = 1; return(Orm.Update(Exammodel) > 0); }
/// <summary> /// 自动组卷 /// </summary> /// <param name="examPaperId"></param> /// <returns></returns> public bool CombinationExamPaper(int examPaperId) { W_ExamPaper paper = Orm.Single <W_ExamPaper>(x => x.ID == examPaperId); if (paper == null) { throw new ApiException("试卷不存在或者已删除"); } //查出试卷所有题型 List <W_ExamPaperDetail> paperDetails = Orm.Select <W_ExamPaperDetail>(x => x.ExamPaper_ID == examPaperId).ToList(); if (paperDetails.Sum(x => x.Sorce * x.Num) < paper.PassScore) { throw new ApiException("试卷及格分数大于所有试卷题型总分,不符合大自然规律,请确保试卷题型总分大于及格分数再组卷"); } //根据试卷题库ID查出题目 List <W_Question> questions = Orm.Select <W_Question>(x => x.QuestionStore_ID == paper.QuestionStore_ID).ToList(); SqlMapper.BeginTransaction(); try { //删除原先已组好的试题 Orm.Delete <W_ExamPaperDetail_Detail>(x => x.ExamPaper_ID == paper.ID); //依据试卷题型的题目类型与题目数量组成试卷 foreach (W_ExamPaperDetail pd in paperDetails) { List <W_Question> tempList; if (pd.QuestionType_ID != 7) { tempList = questions.Where(x => x.QuestionType_ID == pd.QuestionType_ID && x.QuestionData_ID == 0).OrderBy(x => Guid.NewGuid()).Take(pd.Num).ToList(); } else//组合题 { tempList = questions.Where(x => x.QuestionData_ID > 0).OrderBy(x => x.QuestionData_ID).Take(pd.Num).ToList(); } if (tempList.Count < pd.Num) { throw new ApiException("组卷失败:" + pd.QuestionType_Name + "题目不够"); } foreach (W_Question question in tempList) { Orm.Insert <W_ExamPaperDetail_Detail>(new W_ExamPaperDetail_Detail() { ExamPaper_ID = paper.ID, ExamPaper_Detail_ID = pd.ID, Question_ID = question.ID }); } } SqlMapper.CommitTransaction(); } catch (Exception ex) { SqlMapper.RollBackTransaction(); throw new ApiException(ex.Message); } return(true); }
public dynamic UpdateExamPaper(W_ExamPaper model) { bool flag = false; if (model != null && model.ID > 0) { flag = mapper.UpdateExamPaper(model); } return(Success(flag ? "操作成功" : "操作失败")); }
/// <summary> /// 显示试卷做题结果 /// </summary> /// <param name="examPaperId"></param> /// <param name="resultId"></param> /// <param name="System_Station_ID"></param> /// <param name="stuId"></param> /// <returns></returns> public dynamic GetExamPaperResult(int examPaperId, int resultId, int System_Station_ID, string stuId) { W_ExamPaper paper = Orm.Single <W_ExamPaper>(x => x.ID == examPaperId && x.System_Station_ID == System_Station_ID); if (paper == null) { throw new ApiException("试卷不存在或者已删除"); } //查出试卷所有题型 List <W_ExamPaperDetail> paperDetails = Orm.Select <W_ExamPaperDetail>(x => x.ExamPaper_ID == examPaperId).ToList(); //根据试卷ID查出题目 //List<W_ExamPaperDetail_Detail> dList = Orm.Select<W_ExamPaperDetail_Detail>(x => x.ExamPaper_ID == paper.ID); //if (dList == null || dList.Count == 0) // throw new ApiException("试卷有误,请重试"); List <Question> qList = SqlMapper.QueryForList <Question>("GetExamResult", new { busId = examPaperId, resultId, stuId }).ToList(); List <W_QuestionData> dataList = SqlMapper.QueryForList <W_QuestionData>("GetExamQuestionData", new { examPaperId }).ToList(); List <W_QuestionNote> NoteList = Orm.Select <W_QuestionNote>(x => x.StuID == stuId).ToList();//题目笔记列表 List <ExamQuestionType> list = new List <ExamQuestionType>(); decimal TotalScore = 0; foreach (W_ExamPaperDetail item in paperDetails) { ExamQuestionType QuestionType = new ExamQuestionType(); QuestionType.TypeInfo = item; QuestionType.Question = qList.Where(x => x.ExamPaper_Detail_ID == item.ID).OrderBy(x => x.Sort).OrderBy(x => x.ID).ToList(); foreach (Question q in QuestionType.Question) { if (item.QuestionType_ID == 7)//组合题 { W_QuestionData temp = dataList.FirstOrDefault(x => x.ID == q.QuestionData_ID); q.QuestionData = temp != null ? temp.Content : ""; } q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } list.Add(QuestionType); TotalScore += item.Num * item.Sorce; } W_DoExamResult theResult = Orm.Single <W_DoExamResult>(x => x.ID == resultId); ExamPaperQuestion model = new ExamPaperQuestion(); model.PaperInfo = paper; model.ResultId = resultId; model.TotalScore = TotalScore; model.TotalTime = theResult != null ? (theResult.EndTime - theResult.BeginTime).TotalSeconds : 0.00; model.QuestionType = list; return(model); }
public dynamic AddExamPaper(W_ExamPaper model) { bool flag = false; if (model != null) { model.System_Station_ID = this.System_Station_ID; model.AddPerson = this.AccountID; model.AddTime = DateTime.Now; flag = mapper.AddExamPaper(model); } return(Success(flag ? "操作成功" : "操作失败")); }
/// <summary> /// 取消审核试卷 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool CancelExamPaperValid(W_ExamPaper model) { if (model.ID <= 0) { throw new ApiException("无效参数,请重试!"); } W_ExamPaper Exammodel = Orm.Single <W_ExamPaper>(x => x.ID == model.ID); if (Exammodel == null) { throw new ApiException("未找到对应数据,请刷新重试!"); } Exammodel.Valid = 0; return(Orm.Update(Exammodel) > 0); }
/// <summary> /// 禁用题库信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool DisableQuestionStore(W_QuestionStore model) { W_Question questionModel = Orm.Single <W_Question>(x => x.QuestionStore_ID == model.ID); if (questionModel != null) { throw new ApiException("题库里面存在题目,不能禁用"); } W_ExamPaper examModel = Orm.Single <W_ExamPaper>(x => x.QuestionStore_ID == model.ID); if (examModel != null) { throw new ApiException("题库里面存在试卷,不能禁用"); } return(Orm.Update(model) > 0); }
/// <summary> /// 给试卷题型添加题目 /// </summary> /// <returns></returns> public bool AddPaperDetailQuestions(ExamPaperPostModel model) { W_ExamPaper paper = Orm.Single <W_ExamPaper>(x => x.ID == model.examPaperId); if (paper == null) { throw new ApiException("试卷不存在或者已删除"); } W_ExamPaperDetail paperDetail = Orm.Single <W_ExamPaperDetail>(x => x.ID == model.examPaperDetailId); if (paperDetail == null) { throw new ApiException("试卷题型不存在或者已删除"); } if (paperDetail.ExamPaper_ID != paper.ID) { throw new ApiException("试卷题型与试卷不匹配"); } List <W_ExamPaperDetail_Detail> list = Orm.Select <W_ExamPaperDetail_Detail>(x => x.ExamPaper_ID == model.examPaperId && x.ExamPaper_Detail_ID == model.examPaperDetailId).ToList(); if (list.Count + model.questionIds.Length > paperDetail.Num) { throw new ApiException("选择的题目不能超过配置的数目"); } SqlMapper.BeginTransaction(); try { foreach (int questionId in model.questionIds) { Orm.Insert <W_ExamPaperDetail_Detail>(new W_ExamPaperDetail_Detail() { ExamPaper_ID = model.examPaperId, ExamPaper_Detail_ID = model.examPaperDetailId, Question_ID = questionId }); } SqlMapper.CommitTransaction(); } catch { SqlMapper.RollBackTransaction(); return(false); } return(true); }
/// <summary> /// 查询未选的题目列表总条数 /// </summary> /// <param name="request"></param> /// <returns></returns> public int GetNonExamPaperQuestionTotalCount(QuestionRequest request) { W_ExamPaper paper = Orm.Single <W_ExamPaper>(x => x.ID == request.ExamPaperID); if (paper == null) { throw new ApiException("试卷不存在或者已删除"); } W_ExamPaperDetail paperDetail = Orm.Single <W_ExamPaperDetail>(x => x.ID == request.ExamPaperDetailID); if (paperDetail == null) { throw new ApiException("试卷题型不存在或者已删除"); } if (paperDetail.ExamPaper_ID != paper.ID) { throw new ApiException("试卷题型与试卷不匹配"); } return(SqlMapper.QueryForObject <int>("GetNonExamPaperQuestionTotalCount", new { examPaperId = request.ExamPaperID, examPaperDetailId = request.ExamPaperDetailID, type = paperDetail.QuestionType_ID, store = paper.QuestionStore_ID, title = request.Title, level = request.Level, pageStatus = 0 })); }
/// <summary> /// 查询未选的题目列表 /// </summary> /// <param name="request"></param> /// <returns></returns> public IList GetNonExamPaperQuestionList(QuestionRequest request) { W_ExamPaper paper = Orm.Single <W_ExamPaper>(x => x.ID == request.ExamPaperID); if (paper == null) { throw new ApiException("试卷不存在或者已删除"); } W_ExamPaperDetail paperDetail = Orm.Single <W_ExamPaperDetail>(x => x.ID == request.ExamPaperDetailID); if (paperDetail == null) { throw new ApiException("试卷题型不存在或者已删除"); } if (paperDetail.ExamPaper_ID != paper.ID) { throw new ApiException("试卷题型与试卷不匹配"); } return(QueryForList("GetNonExamPaperQuestionList", new { examPaperId = request.ExamPaperID, examPaperDetailId = request.ExamPaperDetailID, type = paperDetail.QuestionType_ID, store = paper.QuestionStore_ID, title = request.Title, level = request.Level, pageIndex = (request.PageIndex - 1) * request.PageSize, pageSize = request.PageSize, pageStatus = request.PageStatus })); }
/// <summary> /// 添加试卷 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool AddExamPaper(W_ExamPaper model) { if (string.IsNullOrEmpty(model.Title)) { throw new ApiException("试卷名称不能为空"); } if (model.Time < 0) { throw new ApiException("考试时间必须大于等于0"); } if (model.PassScore < 0) { throw new ApiException("合格分数必须大于等于0"); } W_QuestionStore store = Orm.Single <W_QuestionStore>(x => x.ID == model.QuestionStore_ID); if (store.Valid == 0) { throw new ApiException("选择的题库已被禁用,请重试"); } return(Orm.Insert(model, true) > 0); }
public dynamic DeleteExamPaper(W_ExamPaper model) { return(Success(mapper.DeleteExamPaper(model.ID) ? "操作成功" : "操作失败")); }
/// <summary> /// 交卷 /// </summary> /// <param name="model"></param> /// <param name="stuId"></param> /// <returns></returns> public bool SubmitPractice(PracticeModel model, string stuId) { W_DoExamResult result = Orm.Select <W_DoExamResult>(x => x.ID == model.resultId).FirstOrDefault(); if (result == null) { throw new ApiException("对象错误"); } else if (string.IsNullOrEmpty(stuId) || result.StuId != stuId) { throw new ApiException("登陆超时,请重新登陆"); } result.EndTime = DateTime.Now; result.Valid = 1;//交卷 SqlMapper.BeginTransaction(); try { //获取试卷题型对应的分数 List <W_ExamPaperDetail> detailList = null; if (result.BusType == 0)//试卷模式 { //更新试卷测试次数 W_ExamPaper paper = Orm.Single <W_ExamPaper>(x => x.ID == result.BusID); paper.DoCount += 1; Orm.Update <W_ExamPaper>(paper); //试卷题型对应得分 detailList = Orm.Select <W_ExamPaperDetail>(x => x.ExamPaper_ID == result.BusID).ToList(); } else//更改章节练习状态 { W_ChapterPractice cp = Orm.Single <W_ChapterPractice>(x => x.ID == result.BusID); cp.Status = 1; Orm.Update <W_ChapterPractice>(cp); } //保存做题记录明细 foreach (Question question in model.list) { decimal sorce = 0; if (result.BusType == 0)//试卷模式 { W_ExamPaperDetail temp = detailList.FirstOrDefault(x => x.QuestionType_ID == question.QuestionType_ID); sorce = temp != null ? temp.Sorce : 0; } Orm.Insert <W_DoExamResult_Detail>(new W_DoExamResult_Detail() { DoExamResult_ID = result.ID, Question_ID = question.ID, StuID = result.StuId, MyAnswer = question.MyAnswer, Judge = question.Judge, Sorce = sorce, UpdateTime = result.EndTime }); //更新题目信息 SqlMapper.Update("UpdateQuestion", new { ID = question.ID, Judge = question.Judge, EasyWrongAnswer = question.MyAnswer }); } //修改做题记录主表 Orm.Update <W_DoExamResult>(result); SqlMapper.CommitTransaction(); } catch { SqlMapper.RollBackTransaction(); return(false); } return(true); }
public dynamic UpdateExamPaperValid(W_ExamPaper model) { return(Success(mapper.UpdateExamPaperValid(model))); }
public dynamic CancelExamPaperValid(W_ExamPaper model) { return(Success(mapper.CancelExamPaperValid(model))); }
public dynamic CombinationExamPaper(W_ExamPaper paper) { return(Success(mapper.CombinationExamPaper(paper.ID) ? "操作成功" : "操作失败")); }
/// <summary> /// 获取试卷题目信息 /// </summary> /// <param name="examPaperId"></param> /// <returns></returns> public dynamic GetExamPaperQuestions(int examPaperId, int System_Station_ID, string stuId) { W_ExamPaper paper = Orm.Single <W_ExamPaper>(x => x.ID == examPaperId && x.System_Station_ID == System_Station_ID); if (paper == null) { throw new ApiException("试卷不存在或者已删除"); } //查出试卷所有题型 List <W_ExamPaperDetail> paperDetails = Orm.Select <W_ExamPaperDetail>(x => x.ExamPaper_ID == examPaperId).ToList(); List <Question> qList = SqlMapper.QueryForList <Question>("GetExamQuestion", new { examPaperId }).ToList(); List <W_QuestionData> dataList = SqlMapper.QueryForList <W_QuestionData>("GetExamQuestionData", new { examPaperId }).ToList(); List <ExamQuestionType> list = new List <ExamQuestionType>(); decimal TotalScore = 0; foreach (W_ExamPaperDetail item in paperDetails) { ExamQuestionType QuestionType = new ExamQuestionType(); QuestionType.TypeInfo = item; QuestionType.Question = qList.Where(x => x.ExamPaper_Detail_ID == item.ID).OrderBy(x => x.Sort).OrderBy(x => x.ID).ToList(); if (item.QuestionType_ID == 7)//组合题 { foreach (Question q in QuestionType.Question) { W_QuestionData temp = dataList.FirstOrDefault(x => x.ID == q.QuestionData_ID); q.QuestionData = temp != null ? temp.Content : ""; } } list.Add(QuestionType); TotalScore += item.Num * item.Sorce; } W_DoExamResult er = Orm.Single <W_DoExamResult>(x => x.BusID == examPaperId && x.BusType == 0 && x.StuId == stuId && x.Valid == 0); int resultId; if (er == null)//重新做题 { // 创建学生做题记录主表,保存开始做题时间 W_DoExamResult result = new W_DoExamResult(); result.StuId = stuId; result.BusType = 0;//试卷 result.BusID = examPaperId; result.BeginTime = DateTime.Now; result.EndTime = DateTime.Now; resultId = (int)Orm.Insert <W_DoExamResult>(result, true); } else //继续做题 { resultId = er.ID; er.BeginTime = DateTime.Now; Orm.Update <W_DoExamResult>(er); } ExamPaperQuestion model = new ExamPaperQuestion(); model.PaperInfo = paper; model.ResultId = resultId; model.TotalScore = TotalScore; model.QuestionType = list; return(model); }