//考生提交实践题答案 public int StuPutPracAns(string sId, string examId, string path) { try { StuPaper stuPaper = db.StuPaper.First(t => t.StudentId == sId && t.ExamId == decimal.Parse(examId)); if (stuPaper.stuAnsPath != null) { System.Web.HttpServerUtility server = System.Web.HttpContext.Current.Server; string phth = server.MapPath(@stuPaper.stuAnsPath); if (File.Exists(server.MapPath(@stuPaper.stuAnsPath))) { File.Delete(server.MapPath(stuPaper.stuAnsPath)); } } stuPaper.stuAnsPath = path; db.SubmitChanges(); return(1); } catch { return(-1); } }
//考生开始考试 返回考生的试卷编号 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 UpdateStuAns(string sId, string examId, string topicId, string stuAns) { int res = 0; try { StuPaper stuPaper = db.StuPaper.First(t => t.StudentId == sId && t.ExamId == decimal.Parse(examId) && t.TopicId == decimal.Parse(topicId)); stuPaper.StuAnswer = stuAns.Trim(); db.SubmitChanges(); res = 1; } catch (Exception e) { res = 0; } return(res); }
protected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["examId"] == null || Request.Cookies["sId"] == null) { Response.Redirect("StuLogIn.aspx"); } else { studentId = Request.Cookies["sId"].Value.ToString(); examId = Request.Cookies["examId"].Value.ToString(); if (examBll.StueIsHaveSumbitPaper(studentId, examId)) { alert("该考生已交卷", "StuLogIn.aspx"); } } studentId = Request.Cookies["sId"].Value.ToString(); topic = stuExamBll.GetStuPracTopicByExamId(studentId, examId); //考生的题目 bindHeadLine(); //绑定试卷标题 bindStuInfo(); //绑定学生信息 //判断考是否已提交答案 StuPaper stuPaper = db.StuPaper.First(t => t.StudentId == studentId && t.ExamId == decimal.Parse(examId)); if (stuPaper.stuAnsPath == null || stuPaper.stuAnsPath.Trim() == "") { Label1.Text = "未提交答案"; } else { Label1.Text = "已提交答案"; } }