//获取考生的某次考试的考试记录 public StuExam GetStuExamByExamId(string sId, string examId) { try { //获取去该次考试的Id string theExamId = db.Exam.First(t => t.ExamId == decimal.Parse(examId)).TheExamId.ToString(); string sql = " select * from StuExam where StudentId = {0} " + "and PaperId in (select PaperId from Paper where ExamId in " + "(select ExamId from Exam where TheExamId = {1}))"; List <StuExam> stuExams = db.ExecuteQuery <StuExam>(sql, new Object[] { sId, theExamId }).ToList(); StuExam stuExam = null; if (stuExams.Count() > 0) { stuExam = stuExams.First(); } return(stuExam); } catch (Exception e) { return(null); } }
//考生开始考试 返回考生的试卷编号 public int StuBeginExam(string sId, string examId) { int res = 0; using (TransactionScope scope = new TransactionScope()) { try { ExamBLL examBll = new ExamBLL(); Student stu = db.Student.First(t => t.StudentId == sId); StuExam stuExam = GetStuExamByExamId(sId, examId); db.SubmitChanges(); int paperId = int.Parse(stuExam.PaperId.ToString()); //考生第一次登陆 if (stu.StuExamState == (int)StudentBLL.StudentExamState.AdmitExam) { stuExam.BeginExamTIme = DateTime.Now.ToLocalTime();//开始答题时间 //初始化考生答案 List <Decimal> topicIds = db.PaperDetail.Where(t => t.PaperId == paperId).Select(t => t.TopicId).ToList(); stuExam.Score = 0; foreach (var item in topicIds) { StuPaper stuPaper = new StuPaper() { TopicId = item, StudentId = sId, StuAnswer = "", ExamId = decimal.Parse(examId) }; db.StuPaper.InsertOnSubmit(stuPaper); } } //修改考生考试状态 开始时间 ip地址 stu.StuExamState = (int)StudentBLL.StudentExamState.Default; stuExam.IPAddress = GetComputerIp(); db.SubmitChanges(); res = paperId; scope.Complete(); } catch (Exception e) { res = 0; } } return(res); }
//考生交卷 public int StuSubmitPaper(string sId, string examId) { int res = 0; using (TransactionScope scope = new TransactionScope()) { try { string sql = " select * from StuPaper, Topic, Sort where Topic.SortId = Sort.SortId " + " and StuPaper.TopicId = Topic.TopicId and " + " StudentId = {0} and ExamId = {1} "; List <StuExamTopic> topics = db.ExecuteQuery <StuExamTopic>(sql, new Object[] { sId, examId }).ToList(); int score = 0; int totalScore = 0; foreach (var item in topics) { totalScore += item.TopicSortScore; if (item.StuAnswer != null) { if (FormatAnswer(item.StuAnswer) == FormatAnswer(item.TitleAnswer)) { score += item.TopicSortScore; } } } float floatScore = float.Parse(score.ToString()); float temp = floatScore / totalScore * 100; score = (int)temp; StuExam stuExam = GetStuExamByExamId(sId, examId); stuExam.Score = score; stuExam.ReplyEndTime = DateTime.Now.ToLocalTime(); db.SubmitChanges(); scope.Complete(); res = 1; } catch (Exception e) { res = 0; } } return(res); }
//更新实践考试成绩 public string GetStuExamByTheExamId(string tId, string theExamId, int score) { int oldScore = 0; try { string sql = "select * from stuexam where studentId = {0} and paperId in (select paperId from paper" + " where examid in (select examId from exam where theExamId = {1}))"; StuExam exam = db.ExecuteQuery <StuExam>(sql, new Object[] { tId, theExamId }).First(); oldScore = int.Parse(exam.Score.ToString()); exam.Score = score; db.SubmitChanges(); return("success"); } catch (Exception e) { return(oldScore.ToString()); } }