//删除实践题目 public string DeletePracTopic(string tId) { PracticalTopic topic = db.PracticalTopic.First(t => t.Tid == decimal.Parse(tId)); List <PaperDetail> paperDetails = db.PaperDetail.Where(t => t.TopicId == decimal.Parse(tId)).ToList(); if (paperDetails.Count() > 0) { StringBuilder res = new StringBuilder(); res.Append("该题目已加入到以下考试中 "); string sql = "select * from theExam where theExamId in ( select theExamId from exam where examId in " + "( select examId from paper where paperId in ( select paperId from paperdetail where topicId = {0} ) ))"; List <TheExam> theExams = db.ExecuteQuery <TheExam>(sql, new Object[] { tId }).ToList(); if (theExams.Count() > 0) { foreach (var item in theExams) { res.Append(item.TheExamName + " "); } } return(res.ToString()); } else { return("success"); } }
//获取考生的实践题目 public PracticalTopic GetStuPracTopicByExamId(string sId, string examId) { string getSql = "select * from practicalTopic where tId in " + "(select topicId from paperDetail where paperId in " + "(select paperId from stuexam where studentId = {0} and paperId in (select paperId from paper where examid = {1})))"; PracticalTopic topic = db.ExecuteQuery <PracticalTopic>(getSql, new Object[] { sId, examId }).First(); return(topic); }
////修改实践题目选中状态 public int ChangePracTopicChose(string tId) { int res = 0; try { PracticalTopic topic = db.PracticalTopic.First(t => t.Tid == int.Parse(tId)); topic.Chose = topic.Chose == 1 ? 0 : 1; db.SubmitChanges(); res = 1; } catch { res = -1; } return(res); }
// 上传实践题目 public int AddPracticalTopic(PracticalTopic topic) { try { PracticalTopic newTopic = new PracticalTopic() { TopicPath = topic.TopicPath, TopicDesc = topic.TopicDesc, TopicName = topic.TopicName, TopicUpTime = topic.TopicUpTime, Chose = 0 }; db.PracticalTopic.InsertOnSubmit(newTopic); db.SubmitChanges(); return(1); } catch (Exception e) { return(0); } }
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 = "已提交答案"; } }
//导入题目 protected void btnImport_Click(object sender, EventArgs e) { try { if (FileUpload1.PostedFile.FileName == "" || FileUpload1.HasFile == false) { ClientScript.RegisterStartupScript(this.GetType(), "error", "<script>window.alert('要导入的文件不存在!');</script>"); return; } else { string filePath = FileUpload1.PostedFile.FileName; string filename = filePath.Substring(filePath.LastIndexOf("\\") + 1); string realName = filePath.Substring(filePath.LastIndexOf("\\") + 1, filePath.LastIndexOf(".") - filePath.LastIndexOf("\\") - 1); string fileExt = filename.Substring(filename.LastIndexOf(".")); if (!(fileExt == ".doc" || fileExt == ".docx")) { ClientScript.RegisterStartupScript(this.GetType(), "error", "<script>window.alert('文件格式不正确!');</script>"); return; } if (FileUpload1.PostedFile.ContentLength > 51200000) { ClientScript.RegisterStartupScript(this.GetType(), "error", "<script>window.alert('文件不能大于50MB!');</script>"); return; } StringBuilder sname = new StringBuilder(DateTime.Now.Year + "_"); sname.Append(DateTime.Now.Month + "_"); sname.Append(DateTime.Now.Day); DirectoryInfo di = new DirectoryInfo(Server.MapPath(@"~\PracticalTopic\Topics\" + sname.ToString())); if (!di.Exists) { di.Create(); } sname.Append("\\" + DateTime.Now.Hour + "_"); sname.Append(DateTime.Now.Minute + "_"); sname.Append(DateTime.Now.Second + "_"); sname.Append(filename); FileUpload1.PostedFile.SaveAs(Server.MapPath(@"~\PracticalTopic\Topics\") + sname.ToString()); string path = "\\PracticalTopic\\Topics\\" + sname.ToString(); PracticalTopic topic = new PracticalTopic() { TopicPath = path, TopicDesc = TextBox1.Text.Trim(), TopicName = realName, TopicUpTime = DateTime.Now.ToLocalTime() }; if (topicBll.AddPracticalTopic(topic) == 1) { TextBox1.Text = ""; Response.Write("<script>alert('上传成功!')</script>"); } else { Response.Write("<script>alert('上传失败!')</script>"); } } } catch (Exception ex) { ClientScript.RegisterStartupScript(this.GetType(), "error", "<script>window.alert('" + ex.Message.ToString() + "');</script>"); return; } }