Пример #1
0
        /// <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);
        }
Пример #2
0
        /// <summary>
        /// 显示做题结果
        /// </summary>
        /// <param name="busId"></param>
        /// <param name="resultId"></param>
        /// <param name="stuId"></param>
        /// <returns></returns>
        public dynamic GetPracticeResult(int busId, int resultId, string stuId)
        {
            ExamResults Results = new ExamResults();

            Results.List = new List <Question>();
            Results.List = SqlMapper.QueryForList <Question>("GetPracticeResult", new { busId, resultId, stuId }).OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList();
            W_DoExamResult theResult = Orm.Single <W_DoExamResult>(x => x.ID == resultId);

            Results.TotalTime = theResult != null ? (theResult.EndTime - theResult.BeginTime).TotalSeconds : 0.00;
            if (Results.List.Count > 0)
            {
                List <ResultSummary>  list     = new List <ResultSummary>();
                List <W_QuestionNote> NoteList = Orm.Select <W_QuestionNote>(x => x.StuID == stuId).ToList();//题目笔记列表
                foreach (Question q in Results.List)
                {
                    ResultSummary temp = list.FirstOrDefault(x => x.TypeID == q.QuestionType_ID);
                    if (temp == null)
                    {
                        temp             = new ResultSummary();
                        temp.TypeID      = q.QuestionType_ID;
                        temp.TypeName    = q.QuestionType_Name;
                        temp.TotalCounts = 1;
                        if (!string.IsNullOrEmpty(q.MyAnswer))
                        {
                            temp.AlreadyCounts = 1;
                            if (q.Judge == 1)
                            {
                                temp.CorrectCounts = 1;
                            }
                            else
                            {
                                temp.ErrorCounts = 1;
                            }
                        }
                        temp.YetCounts   = temp.TotalCounts - temp.AlreadyCounts;
                        temp.CorrectRate = ((float)temp.CorrectCounts / temp.TotalCounts * 100).ToString("f2");
                        list.Add(temp);
                    }
                    else
                    {
                        temp.TypeID       = q.QuestionType_ID;
                        temp.TypeName     = q.QuestionType_Name;
                        temp.TotalCounts += 1;
                        if (!string.IsNullOrEmpty(q.MyAnswer))
                        {
                            temp.AlreadyCounts += 1;
                            if (q.Judge == 1)
                            {
                                temp.CorrectCounts += 1;
                            }
                            else
                            {
                                temp.ErrorCounts += 1;
                            }
                        }
                        temp.YetCounts   = temp.TotalCounts - temp.AlreadyCounts;
                        temp.CorrectRate = ((float)temp.CorrectCounts / temp.TotalCounts * 100).ToString("f2");
                    }
                    q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null;
                }
                Results.Result = list;
            }
            return(Results);
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
        /// <summary>
        /// 继续做题     做题记录页面进来,继续/重新做题    继续做题:继续原来未完成的做题记录   重新做题:开始新的做题记录,题目和原做题记录题目一致(刷新页面确保逻辑一致)
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="stuId"></param>
        /// <returns></returns>
        public dynamic ContinueChapterPractice(int ID, string stuId)
        {
            PracticeModel     rtn = new PracticeModel();
            W_ChapterPractice cp  = Orm.Single <W_ChapterPractice>(x => x.ID == ID);

            if (cp == null)
            {
                throw new ApiException("练习记录不存在或已删除");
            }
            rtn.practiceId = cp.ID;
            W_DoExamResult        result   = Orm.Single <W_DoExamResult>(x => x.BusType == 1 && x.BusID == cp.ID);
            List <Question>       list     = SqlMapper.QueryForList <Question>("GetChapterPracticeDetailQuestion", new { chapterPracticeID = cp.ID, stuId = stuId }).ToList();
            List <W_QuestionNote> NoteList = Orm.Select <W_QuestionNote>(x => x.StuID == stuId).ToList();            //题目笔记列表

            if (result.Valid == 1)                                                                                   //重新做题
            {
                W_ChapterPractice cp2 = Orm.Single <W_ChapterPractice>(x => x.Source == cp.Source && x.Status == 0); //重新做题页面刷新
                if (cp2 == null)
                {
                    string[] str = cp.Source.Split('_');
                    if (str.Length != 6)
                    {
                        throw new ApiException("练习记录数据有误");
                    }


                    W_ChapterPractice model = new W_ChapterPractice();
                    model.QuestionStore_ID = int.Parse(str[0]);
                    model.AddTime          = DateTime.Now;
                    model.StuId            = stuId;
                    //第一步,创建章节练习表W_ChapterPractice
                    W_Chapter chapter = Orm.Select <W_Chapter>(x => x.ID.ToString() == str[1]).FirstOrDefault();
                    model.Title  = chapter != null ? chapter.Name + "章节练习" + model.AddTime.ToString("yyyyMMddHHmmssfff") : "未知章节练习";
                    model.Source = cp.Source;
                    int practiceId = (int)Orm.Insert <W_ChapterPractice>(model, true);

                    //第二步,创建明细表w_chapterpractice_detail
                    foreach (Question q in list)
                    {
                        Orm.Insert <W_ChapterPractice_Detail>(new W_ChapterPractice_Detail()
                        {
                            ChapterPractice_ID = practiceId,
                            Question_ID        = q.ID
                        });
                        q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null;
                    }
                    // 第三步,创建学生做题记录主表,保存开始做题时间
                    W_DoExamResult res = new W_DoExamResult();
                    res.StuId     = model.StuId;
                    res.BusType   = 1;//章节练习
                    res.BusID     = practiceId;
                    res.BeginTime = model.AddTime;
                    res.EndTime   = model.AddTime;
                    int resultId = (int)Orm.Insert <W_DoExamResult>(res, true);

                    rtn.practiceId = practiceId;
                    rtn.resultId   = resultId;
                    rtn.list       = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList();
                }
                else
                {
                    W_DoExamResult result2 = Orm.Single <W_DoExamResult>(x => x.BusType == 1 && x.BusID == cp2.ID); if (result == null)
                    {
                        throw new ApiException("练习记录不存在或已删除");
                    }
                    rtn.resultId = result2.ID;
                    foreach (Question q in list)
                    {
                        q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null;
                    }
                    rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList();
                    //更新做题记录时间
                    result2.BeginTime = DateTime.Now;
                    Orm.Update <W_DoExamResult>(result2);
                }
            }
            else
            {
                if (result == null)
                {
                    throw new ApiException("练习记录不存在或已删除");
                }
                rtn.resultId = result.ID;
                foreach (Question q in list)
                {
                    q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null;
                }
                rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList();
                //更新做题记录时间
                result.BeginTime = DateTime.Now;
                Orm.Update <W_DoExamResult>(result);
            }
            return(rtn);
        }
Пример #5
0
        /// <summary>
        /// 创建章节练习
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public PracticeModel CreateChapterPractice(W_ChapterPractice model, int chapterId, string questionType, int questionCount, int questionSource)
        {
            PracticeModel rtn = new PracticeModel();

            List <W_QuestionNote> NoteList = Orm.Select <W_QuestionNote>(x => x.StuID == model.StuId).ToList();//题目笔记列表

            //判断是重新生成章节练习还是继续之前的章节练习
            W_ChapterPractice cp = Orm.Single <W_ChapterPractice>(x => x.Source == model.QuestionStore_ID + "_" + chapterId + "_" + questionType + "_" + questionCount + "_" + questionSource + "_" + model.StuId && x.Status == 0);

            if (cp != null)//继续做题
            {
                rtn.practiceId = cp.ID;
                W_DoExamResult result = Orm.Single <W_DoExamResult>(x => x.BusType == 1 && x.BusID == cp.ID);
                if (result == null)
                {
                    throw new ApiException("练习有误,请刷新重试");
                }
                rtn.resultId = result.ID;
                List <Question> list = SqlMapper.QueryForList <Question>("GetChapterPracticeDetailQuestion", new { chapterPracticeID = cp.ID, stuId = model.StuId }).ToList();
                foreach (Question q in list)
                {
                    q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null;
                }
                rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList();
                //更新做题记录时间
                result.BeginTime = model.AddTime;
                Orm.Update <W_DoExamResult>(result);
            }
            else//重新生成
            {
                List <Question> list = SqlMapper.QueryForList <Question>("GetChapterPracticeQuestion", new { chapterId, questionType, questionCount, questionSource, stuId = model.StuId }).ToList();
                if (list.Count == 0)
                {
                    throw new ApiException("没有更多的试题");
                }

                //第一步,创建章节练习表W_ChapterPractice
                W_Chapter chapter = Orm.Select <W_Chapter>(x => x.ID == chapterId).FirstOrDefault();
                model.Title  = chapter != null ? chapter.Name + "章节练习" + model.AddTime.ToString("yyyyMMddHHmmssfff") : "未知章节练习";
                model.Source = model.QuestionStore_ID + "_" + chapterId + "_" + questionType + "_" + questionCount + "_" + questionSource + "_" + model.StuId;
                int practiceId = (int)Orm.Insert <W_ChapterPractice>(model, true);

                //第二步,创建明细表w_chapterpractice_detail
                foreach (Question q in list)
                {
                    Orm.Insert <W_ChapterPractice_Detail>(new W_ChapterPractice_Detail()
                    {
                        ChapterPractice_ID = practiceId,
                        Question_ID        = q.ID
                    });
                    q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null;
                }
                // 第三步,创建学生做题记录主表,保存开始做题时间
                W_DoExamResult result = new W_DoExamResult();
                result.StuId     = model.StuId;
                result.BusType   = 1;//章节练习
                result.BusID     = practiceId;
                result.BeginTime = model.AddTime;
                result.EndTime   = model.AddTime;
                int resultId = (int)Orm.Insert <W_DoExamResult>(result, true);

                rtn.practiceId = practiceId;
                rtn.resultId   = resultId;
                rtn.list       = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList();
            }

            return(rtn);
        }
Пример #6
0
        /// <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);
        }