Beispiel #1
0
        public void FinishPaper(ExaminationPaper paper, LabContext context)
        {
            if (paper != null)
            {
                if (!paper.IsFinish)
                {
                    if (paper.LeaveExamTime <= 1.0)
                    {
                        paper.LeaveExamTime = 0;
                    }

                    paper.IsFinish = true;

                    if (String.IsNullOrEmpty(paper.Review))
                    {
                        paper.Review = "学生未作出评价!";
                    }
                    paper.Score = GetPaperScore(paper.PaperId, context);

                    Student student = context.Student.Find(paper.StudentId);


                    if (student != null)
                    {
                        if (paper.Score >= paper.PassScore)
                        {
                            student.IsPassExam = true;
                        }

                        double middle = Math.Round((paper.Score / paper.TotleScore) * 100, 1);

                        if (middle > student.MaxExamCount)
                        {
                            student.MaxExamScore = (float)middle;
                        }
                    }
                    else
                    {
                        context.LogPricipalOperations.Add(new LogPricipalOperation
                        {
                            PrincpalOperationStatus = PrincpalOperationStatus.Success,
                            AddTime = DateTime.Now,
                            PrincpalOperationCode    = PrincpalOperationCode.SystemRuntimeError,
                            OperationIp              = "系统运行产生!",
                            PrincpalOperationName    = $"试卷ID:{paper.PaperId} ,试卷所属学生学号:{paper.StudentId}",
                            PrincpalOperationContent = "完成试卷的时候发现学生已经被删除! 考试期间管理员删除了学生导致考试异常! 请查看."
                        });
                    }


                    context.SaveChanges();
                }
            }
        }
Beispiel #2
0
        public int DeleteTestPaper(string keyValue)
        {
            ExaminationPaper TestPaper = service.FindEntity(keyValue);

            if (TestPaper != null)
            {
                return(service.Delete(TestPaper));
            }
            else
            {
                return(0);
            }
        }
Beispiel #3
0
        public ActionResult CreateTestPaper(ExaminationPaper paper)
        {
            var result = testpaperApp.CreatePaper(paper);

            if (result == 1)
            {
                return(Success("操作成功"));
            }
            else
            {
                return(Error("操作失败"));
            }
        }
        public Boolean Edit(ExaminationPaper model)
        {
            try
            {
                olsEni.Entry(model).State = EntityState.Modified;
                olsEni.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                StaticHelper.RecordSystemLog(ex);
                return(false);
            }
        }
Beispiel #5
0
        public bool DeletePaper(ExaminationPaper ePaper, LabContext context)
        {
            if (ePaper != null && context.ExaminationPapers.Any(p => p.PaperId == ePaper.PaperId))
            {
                try
                {
                    context.Database.BeginTransaction();
                    context.Database.ExecuteSqlCommand("Delete from ExamJudgeChoices Where PaperId = @pid", new SqlParameter
                    {
                        Value         = ePaper.PaperId,
                        ParameterName = "@pid",
                        SqlDbType     = SqlDbType.Int
                    });

                    context.Database.ExecuteSqlCommand("Delete from ExamMultipleChoices Where PaperId = @pid", new SqlParameter
                    {
                        Value         = ePaper.PaperId,
                        ParameterName = "@pid",
                        SqlDbType     = SqlDbType.Int
                    });

                    context.Database.ExecuteSqlCommand("Delete from ExamSingleChoices Where PaperId = @pid", new SqlParameter
                    {
                        Value         = ePaper.PaperId,
                        ParameterName = "@pid",
                        SqlDbType     = SqlDbType.Int
                    });

                    context.ExaminationPapers.Remove(ePaper);
                    int result = context.SaveChanges();
                    context.Database.CommitTransaction();
                    return(result == 1);
                }
                catch (Exception e)
                {
                    context.Database.RollbackTransaction();
                    Console.WriteLine(e);
                    throw;
                }
            }
            else
            {
                return(false);
            }
        }
Beispiel #6
0
        public IActionResult Detail([Required] int pId)
        {
            if (ModelState.IsValid)
            {
                ExaminationPaper paper = _context.ExaminationPapers.Find(pId);
                if (paper == null)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "请求的试卷不存在!或者已经被删除了!"
                    }));
                }
                else
                {
                    vStatisticJudgeMap judge =
                        _context.VStatisticJudgeMaps.FirstOrDefault(j => j.PaperId == paper.PaperId);
                    vStatisticMultipleMap multiple =
                        _context.VStatisticMultipleMaps.FirstOrDefault(m => m.PaperId == paper.PaperId);
                    vStatisticSingleMap single =
                        _context.VStatisticSingleMaps.FirstOrDefault(m => m.PaperId == paper.PaperId);

                    return(Json(new
                    {
                        isOk = true,
                        title = "提示",
                        message = "加载成功",
                        judge = judge,
                        multiple = multiple,
                        single = single,
                        review = paper.Review
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    title = "错误提示",
                    message = "参数错误"
                }));
            }
        }
Beispiel #7
0
        public float GetPaperScore(int paperId, LabContext context)
        {
            ExaminationPaper paper = context.ExaminationPapers.Find(paperId);

            if (paper == null)
            {
                return(-100.0f);
            }
            else
            {
                float judgeScore = context.ExamJudgeChoices.Where(p => p.PaperId == paper.PaperId)
                                   .Where(p => p.RealAnswer == p.StudentAnswer).Sum(p => p.Score);
                float singleScore = context.ExamSingleChoices.Where(p => p.PaperId == paper.PaperId)
                                    .Where(p => p.RealAnswer == p.StudentAnswer).Sum(p => p.Score);
                float multipleScore = context.ExamMultipleChoices.Where(p => p.PaperId == paper.PaperId)
                                      .Where(p => p.RealAnswer == p.StudentAnswer).Sum(p => p.Score);

                return(judgeScore + singleScore + multipleScore);
            }
        }
        public Boolean Create(ExaminationPaper model)
        {
            try
            {
                Int32 id;

                id = GetEPId();

                model.EP_Id = id;
                olsEni.ExaminationPapers.Add(model);
                olsEni.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                StaticHelper.RecordSystemLog(ex);
                return(false);
            }
        }
        public void Init(SubjectEnum subjectEnum)
        {
            Examination = new ExaminationPaper()
            {
                SubjectEnum  = subjectEnum,
                Student      = AppSetting.Student,
                CompleteTime = null
            };
            Examination.LoadTopics(read);

            if (subjectEnum == SubjectEnum.Net)
            {
                this.lblTitle.Text = "Net试题";
            }
            else if (subjectEnum == SubjectEnum.Java)
            {
                this.lblTitle.Text = "Java试题";
            }

            SetTopic(null);
        }
        public ExaminationPaper GetNew(Int32 userId)
        {
            ExaminationPaper model;
            User             u;

            u = olsEni.Users.Single(m =>
                                    m.U_Id == userId &&
                                    m.U_Status == (Byte)Status.Available);

            model = new ExaminationPaper()
            {
                EP_Id       = 0,
                EP_UserId   = userId,
                EP_UserName = u.U_Name,
                EP_Remark   = "",
                EP_AddTime  = DateTime.Now,
                EP_Status   = (Byte)Status.Available
            };

            return(model);
        }
Beispiel #11
0
        public int CreatePaper(ExaminationPaper paper)
        {
            ExaminationPaper model = new ExaminationPaper();

            model.Create();
            model.CourseID     = paper.CourseID;
            model.QuesetionNum = paper.QuesetionNum;
            model.SelectNum    = paper.SelectNum;
            model.TFNum        = paper.TFNum;
            model.TFScore      = paper.TFScore;
            model.SelectScore  = paper.SelectScore;
            model.FullMark     = paper.FullMark;
            model.PassMark     = paper.PassMark;
            model.DeleteMark   = false;

            int selectscore = paper.SelectScore == null?0:int.Parse(paper.SelectScore);
            int tfscore     = paper.TFScore == null?0:int.Parse(paper.TFScore);

            var        selectList    = select_service.IQueryable().Where(x => x.Score == selectscore && (x.DeleteMark == null ? false : x.DeleteMark) != true).ToList();
            var        TFList        = TF_service.IQueryable().Where(x => x.Score == tfscore && (x.DeleteMark == null ? false : x.DeleteMark) != true).ToList();
            List <int> SelecltOrders = GetRandom(0, selectList.Count, paper.SelectNum);
            List <int> TFOrders      = GetRandom(0, TFList.Count, paper.SelectNum);

            for (int i = 0; i < SelecltOrders.Count; i++)
            {
                var index = SelecltOrders[i];
                InsertSelectNum(model.ID, selectList[index].ID, "1");
            }
            for (int j = 0; j < TFOrders.Count; j++)
            {
                var item = TFOrders[j];
                InsertSelectNum(model.ID, TFList[item].ID, "1");
            }
            int result = service.Insert(model);

            return(result);
        }
Beispiel #12
0
        public void ChangeTest()
        {
            Int32                                   id, epId, epqId;
            DateTime                                now, startTime;
            ExaminationTask                         et;
            ExaminationPaperTemplate                ept;
            UExaminationTask                        uet;
            GeneratePaperTemplate_Accessor          gpt    = new GeneratePaperTemplate_Accessor();
            ChangePaperStatus                       target = new ChangePaperStatus();
            ResponseJson                            resJson;
            ExaminationPaper                        ep;
            ExaminationPaperQuestion                epq;
            Object                                  expected, actual;
            List <ExaminationPaperTemplateQuestion> eptqs;

            #region 部署测试数据

            now = DateTime.Now;
            uet = new UExaminationTask();

            startTime = new DateTime(1970, 1, 1, now.AddHours(1).Hour, now.Minute, 0);
            id        = new Utility().GetETId();
            et        = new ExaminationTask
            {
                ET_Id      = id,
                ET_Name    = "单元测试每日任务" + id,
                ET_Enabled = (Byte)ExaminationTaskStatus.Enabled,
                ET_Type    = (Byte)ExaminationTaskType.Examination,
                ET_ParticipatingDepartment = "[6,9]",
                ET_Attendee              = "[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,39,40,41,42,43,44,45]",
                ET_StatisticType         = (Byte)StatisticType.Score,
                ET_TotalScore            = 100,
                ET_TotalNumber           = 10,
                ET_Mode                  = (Byte)ExaminationTaskMode.Auto,
                ET_AutoType              = (Byte)AutoType.Day,
                ET_AutoOffsetDay         = 0,
                ET_DifficultyCoefficient = 0,
                ET_AutoClassifies        = "[\"综合、公文、绩效知识(90题)\",\"所得税知识(180题)\",\"营业税知识(60题)\",\"其他地方税知识(180题)\",\"税收征管法、相关法律法规及征管制度(253题)\",\"规费知识(130题)\",\"纳税服务知识(95题)\"]",
                ET_AutoRatio             = "[{\"type\":\"单选题\",\"percent\":0.2},{\"type\":\"多选题\",\"percent\":0.2},{\"type\":\"判断题\",\"percent\":0.2},{\"type\":\"公文改错题\",\"percent\":0},{\"type\":\"计算题\",\"percent\":0},{\"type\":\"案例分析题\",\"percent\":0},{\"type\":\"问答题\",\"percent\":0}]",
                ET_StartTime             = startTime,
                ET_EndTime               = startTime,
                ET_TimeSpan              = 0,
                ET_PaperTemplates        = "[]",
                ET_Questions             = "[]",
                ET_Remark                = "",
                ET_AddTime               = now,
                ET_Status                = (Byte)Status.Available
            };
            olsEni.Entry(et).State = EntityState.Added;

            if (0 == olsEni.SaveChanges())
            {
                Assert.Fail("部署测试数据失败1。");
            }

            // 生成试卷模板数据
            uet     = new UExaminationTask();
            resJson = gpt.Generate();
            if (ResponseStatus.Error == resJson.status || resJson.message != "")
            {
                Assert.Fail("部署测试数据失败3。" + resJson.message);
            }

            Thread.Sleep(10 * 1000);

            ept = olsEni.ExaminationPaperTemplates.SingleOrDefault(m => m.ET_Id == id);
            if (null == ept)
            {
                Assert.Fail("部署测试数据失败4。");
            }

            ept.EPT_PaperTemplateStatus = (Byte)PaperTemplateStatus.Done;

            if (0 == olsEni.SaveChanges())
            {
                Assert.Fail("部署测试数据失败2。");
            }

            // 添加试卷
            epId = new Utility().GetEPId();
            ep   = new ExaminationPaper
            {
                EP_Id          = epId,
                ET_Id          = ept.ET_Id,
                EPT_Id         = ept.EPT_Id,
                EP_PaperStatus = (Byte)PaperStatus.Doing,
                EP_EndTime     = ept.EPT_EndTime,
                EP_TimeSpan    = ept.EPT_TimeSpan,
                EP_UserId      = 1,
                EP_UserName    = "",
                EP_Score       = -1,
                EP_Remark      = "",
                EP_AddTime     = now,
                EP_Status      = (Byte)Status.Available
            };

            olsEni.Entry(ep).State = EntityState.Added;
            olsEni.SaveChanges();

            // 添加答题数据
            epqId = new Utility().GetEPQId();
            eptqs = olsEni.ExaminationPaperTemplateQuestions.Where(m => m.EPT_Id == ept.EPT_Id).ToList();

            foreach (var eptq in eptqs)
            {
                epq = new ExaminationPaperQuestion
                {
                    EPQ_Id        = epqId,
                    EPQ_Answer    = eptq.EPTQ_ModelAnswer,
                    EPQ_Exactness = (Byte)AnswerStatus.Unset,
                    EPQ_Critique  = null,
                    EPQ_AddTime   = now,
                    EP_Id         = epId,
                    EPTQ_Id       = eptq.EPTQ_Id
                };
                olsEni.Entry(epq).State = EntityState.Added;

                epqId += 1;
            }
            olsEni.SaveChanges();
            #endregion

            expected = ResponseStatus.Success;
            actual   = target.Change();

            Assert.AreEqual(expected, ((ResponseJson)actual).status);

            olsEni.Entry(ep).State = EntityState.Detached;
            ep = null;

            ep = olsEni.ExaminationPapers.Single(m => m.EP_Id == epId);

            expected = (Byte)PaperStatus.Done;
            actual   = ep.EP_PaperStatus;

            Assert.AreEqual(expected, actual);

            expected = 100;
            actual   = ep.EP_Score;

            Assert.AreEqual(expected, actual);
        }
        private ResponseJson addExaminationPaper(ExaminationPaperTemplate ept, Int32 uId)
        {
            Int32            epId, epqId;
            ExaminationPaper ep;
            ResponseJson     resJson;
            List <ExaminationPaperTemplateQuestion> eptqs;

            resJson = new ResponseJson(ResponseStatus.Error, now);

            // 添加试卷
            epId = GetEPId();

            ep = new ExaminationPaper
            {
                EP_Id          = epId,
                ET_Id          = ept.ET_Id,
                EPT_Id         = ept.EPT_Id,
                EP_PaperStatus = (Byte)PaperStatus.Doing,
                EP_EndTime     = now.AddMinutes(ept.EPT_TimeSpan), // 进入考试时开始计算考试时间
                EP_TimeSpan    = ept.EPT_TimeSpan,
                EP_UserId      = uId,
                EP_UserName    = "",
                EP_Score       = -1,
                EP_Remark      = "",
                EP_AddTime     = now,
                EP_Status      = (Byte)Status.Available
            };

            // 添加试卷试题数据
            eptqs =
                olsEni.ExaminationPaperTemplateQuestions
                .Where(m =>
                       m.EPT_Id == ept.EPT_Id &&
                       m.EPTQ_Status == (Byte)Status.Available)
                .ToList();
            epqId = GetEPQId();
            foreach (var eptq in eptqs)
            {
                var epq = new ExaminationPaperQuestion
                {
                    EPQ_Id        = epqId,
                    EP_Id         = epId,
                    EPTQ_Id       = eptq.EPTQ_Id,
                    EPQ_Answer    = "",
                    EPQ_Exactness = 0,
                    EPQ_Critique  = "",
                    EPQ_AddTime   = now
                };
                olsEni.Entry(epq).State = EntityState.Added;
                epqId += 1;
            }

            olsEni.Entry(ep).State = EntityState.Added;
            if (0 == olsEni.SaveChanges())
            {
                resJson.message = ResponseMessage.SaveChangesError;
                return(resJson);
            }

            resJson.status = ResponseStatus.Success;
            resJson.data   = epId;
            return(resJson);
        }
        /// <summary>
        /// 计算成绩
        /// </summary>
        /// <param name="ep"></param>
        public String GradePaper(ExaminationPaper ep)
        {
            Int32  score, number, eptqCount;
            Double ratio;
            ExaminationPaperTemplateQuestion eptq;
            ExaminationTask et;
            List <ExaminationPaperQuestion> epqs;
            String scoreString;

            score       = 0;
            number      = 0;
            scoreString = "";

            epqs = olsEni.ExaminationPaperQuestions.Where(m => m.EP_Id == ep.EP_Id).ToList();
            foreach (var epq in epqs)
            {
                eptq = olsEni.ExaminationPaperTemplateQuestions.Single(m => m.EPTQ_Id == epq.EPTQ_Id);
                switch (eptq.EPTQ_Type)
                {
                case "单选题":
                case "多选题":
                case "判断题":

                    if (eptq.EPTQ_ModelAnswer == epq.EPQ_Answer)
                    {
                        epq.EPQ_Exactness = (Byte)AnswerStatus.Exactness;
                        score            += eptq.EPTQ_Score;
                        number           += 1;
                    }
                    else
                    {
                        epq.EPQ_Exactness = (Byte)AnswerStatus.Wrong;
                    }
                    break;

                default:
                    break;
                }
            }

            // 如果试题只有单选题、多选题、判断题,则自动设置分数
            eptqCount =
                olsEni
                .ExaminationPaperTemplateQuestions
                .Where(m =>
                       m.EPT_Id == ep.EPT_Id &&
                       m.EPTQ_Type != "单选题" &&
                       m.EPTQ_Type != "多选题" &&
                       m.EPTQ_Type != "判断题" &&
                       m.EPTQ_Status == (Byte)Status.Available)
                .Count();
            et = olsEni.ExaminationTasks.Single(m => m.ET_Id == ep.ET_Id);

            if ((Byte)StatisticType.Score == et.ET_StatisticType && eptqCount == 0)
            {
                ep.EP_Score            = score;
                olsEni.Entry(ep).State = EntityState.Modified;
                scoreString            = score + "分";
            }
            else if ((Byte)StatisticType.Number == et.ET_StatisticType && eptqCount == 0)
            {
                ratio                  = Math.Round((Double)number / (Double)et.ET_TotalNumber, 2, MidpointRounding.AwayFromZero);
                ep.EP_Score            = (Int32)(ratio * 100);
                olsEni.Entry(ep).State = EntityState.Modified;
                scoreString            = score + "%";
            }

            return(scoreString);
        }