protected void AddCourseSureButton_Click(object sender, EventArgs e) { tea = (Teacher)Session["teacher"]; Course newcourse = new Course(); if (cournumTextBox.Text == "") CoursenumLabel.Visible = true; else if (cournameTextBox.Text == "") { CoursenumLabel.Visible = false; CoursenameLabel.Visible = true; } else { newcourse.teacher = tea.username; newcourse.name = cournameTextBox.Text; newcourse.num = cournumTextBox.Text; DateTime start = Convert.ToDateTime(courstart_timeTextBox.Text + " 00:00:00"); newcourse.start_time = start; DateTime end = Convert.ToDateTime(courend_timeTextBox.Text + " 23:59:59"); newcourse.end_time = end; CourMan.AddCourse(newcourse); Response.Write("<script>alert('成功添加!');location.href='AddCourse.aspx';</script>"); //Response.Redirect("AddCourse.aspx"); } }
//添加课程 public bool AddCourse(Course course) { DataClassesDataContext da = new DataClassesDataContext(); da.Course.InsertOnSubmit(course); da.SubmitChanges(); return true; }
//删除课程 public bool DeleteCourse(Course course) { DataClassesDataContext da = new DataClassesDataContext(); var c=from s in da.Course where s.teacher==course.teacher && s.name==course.name select s; var cin = from s in da.Student_Course where s.course == c.First().num select s; var ca = from s in da.Assignment where s.course == c.First().num select s; if (ca.Count() > 0) { foreach (var n in ca) { var p = from s in da.Problem where s.assignment == n.id select s; if (p.Count() > 0) { var answer = from s in da.Answer where s.problem == p.First().id select s; if (answer.Count() > 0) { da.Answer.DeleteAllOnSubmit(answer); //删除answer } } var accessory = from s in da.Accessory where s.assignment == n.id select s; if (accessory.Count() > 0) da.Accessory.DeleteAllOnSubmit(accessory); da.Problem.DeleteAllOnSubmit(p); //删除Problem } da.Assignment.DeleteAllOnSubmit(ca); //删除assignment } if (cin.Count() > 0) { da.Student_Course.DeleteAllOnSubmit(cin); //删除student_course } da.Course.DeleteAllOnSubmit(c); //删除Course da.SubmitChanges(); return true; }
protected void dcnameTextBox_TextChanged(object sender, EventArgs e) { tea = (Teacher)Session["teacher"]; Course deletecourse = new Course(); List<Course> courseforteacher = CourMan.GetCourseForTeacher(tea.username); foreach (var c in courseforteacher) { if (c.name == dcnameTextBox.Text.ToString()) { deletecourse = c; break; } } Session["deletecourse"] = deletecourse; dcnumTextBox.Text = deletecourse.num; dcstart_timeLabel.Text = deletecourse.start_time.ToString(); dcend_timeLabel.Text = deletecourse.end_time.ToString(); }
protected void Page_Load(object sender, EventArgs e) { if (Session["UserRole"] == null || Session["UserRole"].ToString() != "Teacher") { Response.Write("<Script language='javascript'>alert('您无权访问此页面,请重新登录!');window.history.go(-1);</Script>"); return; } //获取课程信息 tea = (Teacher)Session["teacher"]; courseforteacher = CourMan.GetCourseForTeacher(tea.username); Session["courselist"] = courseforteacher; foreach (var c in courseforteacher) { if (c.num == Request.QueryString["Coursenum"]) { course = c; break; } } allassigncoursenameLabel.Text = course.name; }
partial void DeleteCourse(Course instance);
partial void UpdateCourse(Course instance);
partial void InsertCourse(Course instance);
private void detach_Course(Course entity) { this.SendPropertyChanging(); entity.Teacher1 = null; }
private void attach_Course(Course entity) { this.SendPropertyChanging(); entity.Teacher1 = this; }
protected void Page_Load(object sender, EventArgs e) { if (Session["UserRole"] == null || Session["UserRole"].ToString() != "Teacher") { Response.Write("<Script language='javascript'>alert('您无权访问此页面,请重新登录!');window.history.go(-1);</Script>"); return; } //获取课程信息 tea = (Teacher)Session["teacher"]; List<Course> courseforteacher = CourMan.GetCourseForTeacher(tea.username); foreach (var c in courseforteacher) { if (c.num == Request.QueryString["Coursenum"]) { course = c; break; } } //显示课程名 coursenameLabel.Text = course.name; //删除问题时弹窗 DeletePro.Attributes.Add("onclick", "return confirm('确定要删吗?');"); }