protected void btn_ReUpload_Click(object sender, EventArgs e) { ASSEntities assen_repost = new ASSEntities(); //处理已上传的文件 int relatedupAssID = int.Parse(ddl_reload.SelectedValue); var result = (from s in assen.UpAssignments where s.UpAssID == relatedupAssID select s).First(); string OldFilenameWithPath = Server.MapPath(@"../Uploads/Students/" + stuID.ToString() + @"/") + result.FileName; try { File.Delete(OldFilenameWithPath); } catch (Exception ex) { throw new Exception(ex.ToString() + "原有提交的作业不存在"); } //处理上传(重新上传) string fileExt; string FileNameWithExt; string FileUrl; if (file_repost.HasFile) { fileExt = Path.GetExtension(file_repost.FileName); if (fileExt == ".rar" || fileExt == ".zip") { try { file_repost.SaveAs(Server.MapPath(@"..\Uploads\Students\") + stuID.ToString() + @"\" + file_repost.FileName); FileNameWithExt = Path.GetFileName(file_repost.FileName); FileUrl = @"../Uploads/Students/" + stuID.ToString() + @"/" + file_repost.FileName; //重新上传完毕,将修改信息保存到数据库 var final = assen_repost.UpAssignments.Where(ua => ua.UpAssID == relatedupAssID).First(); final.FileName = FileNameWithExt; final.FileUrl = FileUrl; assen_repost.SaveChanges(); lb_ReSuccess.Text = "重新上传成功!"; } catch (Exception ex) { lb_ReSuccess.Text = "发生错误:" + ex.Message.ToString(); } } else { lb_ReSuccess.Text = "只允许上传rar、zip文件!"; } } else { lb_ReSuccess.Text = "没有选择要上传的文件!"; } }
protected void btn_EvaOk_Click(object sender, EventArgs e) { int uid = int.Parse(hfupaid.Value); ASSEntities upass = new ASSEntities(); UpAssignments ua = upass.UpAssignments.Where(u => u.UpAssID == uid).First(); ua.Marks = int.Parse(tb_scores.Text); ua.Result = tb_py.Text; upass.SaveChanges(); pnl_Eva.Visible = false; pnl_NotPost.Visible = true; }
protected void btnRePost_Click(object sender, EventArgs e) { if (FilePath != "") { try { File.Delete(FilePath); } catch { throw new Exception("原题目文件不存在!"); } } //处理上传 string fileExt; if (FileUpload1.HasFile) { fileExt = Path.GetExtension(FileUpload1.FileName); if (fileExt == ".rar" || fileExt == ".zip") { try { FileUpload1.SaveAs(Server.MapPath(@"..\Uploads\Teachers") + @"\" + FileUpload1.FileName); string FileNameWithExt = Path.GetFileName(FileUpload1.FileName); string FileSavePath = @"../Uploads/Teachers/" + teaID.ToString() + @"/" + FileUpload1.FileName; //信息插入数据库 var result = assen.Assignments.Where(a => a.AssID == HouseworkNum).First(); result.QuesFileName = FileNameWithExt; result.QuesFileUrl = FileSavePath; assen.SaveChanges(); //成功了 lb_Success.Text = "重新提交作业成功!"; } catch (Exception ex) { lb_Success.Text = "发生错误:" + ex.Message.ToString(); } } else { lb_Success.Text = "只允许上传rar、zip文件!"; } } else { lb_Success.Text = "没有选择要上传的文件!"; } panel_edit.Visible = false; }
protected void Button1_Click(object sender, EventArgs e) { if (TextBox2.Text == "") { return; } string[] arrcourse = TextBox2.Text.Split(','); ASSEntities assen = new ASSEntities(); foreach (string course in arrcourse) { Courses c = new Courses(); c.CourseName = course; assen.AddToCourses(c); } assen.SaveChanges(); }
protected void Button1_Click(object sender, EventArgs e) { if (TextBox1.Text == "" || TextBox2.Text == "") { return; } string[] arrclass = TextBox2.Text.Split(','); ASSEntities assen = new ASSEntities(); foreach (string classsh in arrclass) { string classname = TextBox1.Text + classsh; Classes c = new Classes(); c.ClassName = classname; assen.AddToClasses(c); } assen.SaveChanges(); }
protected void btn_givesc_Click(object sender, EventArgs e) { if (tb_class.Text == "" || tb_course.Text == "" || tb_teaer.Text == "") { Exception ex = new Exception(); ex.Data["tbnull"] = "数据不完整。"; throw ex; } ASSEntities assen = new ASSEntities(); SetCourses sc = new SetCourses(); int ncint = int.Parse(tb_class.Text); int ncoint = int.Parse(tb_course.Text); int ntint = int.Parse(tb_teaer.Text); var newclass = (from nc in assen.Classes where nc.ClassID == ncint select nc).First(); var newcourse = (from nco in assen.Courses where nco.CourseID == ncoint select nco).First(); var newteacher = (from nt in assen.Teachers where nt.TeaID == ntint select nt).First(); sc.SCID = 1; sc.Classes = newclass; sc.Courses = newcourse; sc.Teachers = newteacher; if (tb_semester.Text != "") { sc.Semester = tb_semester.Text; } else { sc.Semester = Session["schoolsemester"].ToString(); } assen.AddToSetCourses(sc); assen.SaveChanges(); }
protected void btn_change_Click(object sender, EventArgs e) { if (tb_change.Text == "") { return; } string[] inf = tb_change.Text.Split(','); string inf_1 = inf[1].Trim(); int inf_2 = int.Parse(inf[0].Trim()); ASSEntities assen = new ASSEntities(); var teacher = (from t in assen.Teachers where t.TeaName == inf_1 select t).First(); var setcourse = (from sc in assen.SetCourses where sc.SCID == inf_2 select sc).First(); setcourse.Teachers = teacher; assen.SaveChanges(); }
protected void btn_Post_Click(object sender, EventArgs e) { //判断是否具备发布条件 if (!upass.HasFile || ckbox_couses.SelectedItem == null || tb_Title.Text == "" || tb_Descr.Text == "" || tb_Deadline.Text == "") { throw new Exception("有未填项目。"); } //获取选项 string AssName = tb_Title.Text; string AssDes = tb_Descr.Text; DateTime dl = DateTime.Parse(tb_Deadline.Text); List <SetCourses> arr = new List <SetCourses>(); foreach (ListItem li in ckbox_couses.Items) { if (li.Selected) { int i = int.Parse(li.Value); var result = (from s in assen.SetCourses where s.Semester == semester && s.Teachers.TeaName == teaName && s.SCID == i select s).First(); arr.Add(result); } } //处理上传并获取文件名 string fileExt; fileExt = Path.GetExtension(upass.FileName); if (fileExt == ".rar" || fileExt == ".zip") { try { //确定当前教师文件存储的位置 string FilePath = Server.MapPath(@"..\Uploads\Teachers\" + teaID.ToString() + @"\"); if (!Directory.Exists(FilePath)) { Directory.CreateDirectory(FilePath); } upass.SaveAs(FilePath + @"\" + upass.FileName); //获取文件名 string FileNameWithExt = Path.GetFileName(upass.FileName); //确定文件路径 string FullFilePath = @"../Uploads/Teachers/" + teaID.ToString() + @"/" + FileNameWithExt; //将信息保存到数据库中 foreach (SetCourses item in arr) { Assignments ass = new Assignments(); ass.AssName = AssName; ass.AssDes = AssDes; ass.SetCourses = item; ass.Deadline = dl; ass.QuesFileName = FileNameWithExt; ass.QuesFileUrl = FullFilePath; assen.AddToAssignments(ass); assen.SaveChanges(); } //成功 lb_Success.Text = "发布成功!"; } catch (Exception ex) { lb_Success.Text = "发生错误:" + ex.Message.ToString(); } } else { lb_Success.Text = "只允许上传rar、zip文件!"; } }