public void Delete(ClassGradeCourse entity)
 {
     using (ISession session = sessionFactory.OpenSession())
     {
         session.Delete(entity);
         session.Flush();
     }
 }
 public bool AddClassGradeCourse(ClassGradeCourse classGradeCourse)
 {
     IClassGradeCourseDao classGradeCourseDao = new ClassGradeCourseDao(sessionFactory);
     try
     {
         classGradeCourseDao.Save(classGradeCourse);
         return true;
     }
     catch (Exception e) {
         return false;
     }
 }
 public bool DeleteClassGradeCourse(ClassGradeCourse classGradeCourse)
 {
     IClassGradeCourseDao cgc = new ClassGradeCourseDao(sessionFactory);
     try
     {
         cgc.Delete(classGradeCourse);
         return true;
     }
     catch (Exception e)
     {
         return false;
     }
 }
        public void AddCourse()
        {
            //int ID = 1001;
            string name = "离散数学";
            string startTime ="1";
            string endTime = "18";
            string weekTime = "周三";
            string dayTime = "1节2节";
            string location = "C213";
            string info = "nixisdkjksdfjkdsdkjsdkdffjdskfj";
            bool openCloseFlag = true;
            bool selectable = false;
            bool required = true;
            int teacherID = 100000;
            string studyYear = "2012~2013";
            string term = "上";
            string[] courseFaceClassName = { "计算机科学与技术", "软件工程" };
            string[] courseFaceGrade = { "2009", "2010" };
            Course newCourse=new Course{

               //courseID=ID,
               courseName=name,
               courseStartTime=startTime,
               courseEndTime=endTime,
                courseLocation=location,
                 courseInfo=info,
               courseOpenCloseFlag=openCloseFlag,
               courseTeacherID=teacherID,
               courseWeekTime=weekTime,
               courseDayTime=dayTime,
               courseRequired = required,
               courseSelectable = selectable,
               courseStudyYear=studyYear,
                courseTerm=term
            };
            int courseID= teacherController.AddCourse(newCourse);
            Assert.AreNotEqual(0,courseID);
            if(courseID!=0)
            {
            for (int i = 0; i < courseFaceClassName.Length; i++) {
                for (int j = 0; j < courseFaceGrade.Length; j++) {
                    ClassGradeCourse classGradeCourse = new ClassGradeCourse
                    {
                        ID = new ClassGradeCourseID {
                            classGradeCourseClassName=courseFaceClassName[i],
                            classGradeCourseGrade=courseFaceGrade[j],
                            classGradeCourseCourseId = courseID
                        }

                    };
                  bool success=teacherController.AddClassGradeCourse(classGradeCourse);
                  Assert.AreEqual(true, success);
                }

            }
              }
        }
        protected void modifyCourseButtonClick(object sender, EventArgs e)
        {
            string name = courseName.Text;
            string startTime = courseStartTimeDropDownList.Items[courseStartTimeDropDownList.SelectedIndex].Text;
            string endTime = courseEndTimeDropDownList.Items[courseEndTimeDropDownList.SelectedIndex].Text;
            string weekTime = courseWeekTimeDropDownList.Items[courseWeekTimeDropDownList.SelectedIndex].Text;
            string maxStudentNum = CourseMaxStudentNum.Text;
            //取得课程一天上的节课string dayTime = "1节2节";
            //IList<string> courseDayTimeCheckBoxList = new List<string>();
            string courseDayTimeList="";
            foreach (ListItem it in courseDayTimeCheckBoxList.Items)
            {
                if (it.Selected)
                {
                    courseDayTimeList=courseDayTimeList+it.Text+" ";
                }
            }

            string location = courseLocationTextBox.Text;
            //string info = "nixisdkjksdfjkdsdkjsdkdffjdskfj";
            bool openCloseFlag = true;
            string selectableRequired =seltctableRequiredDropDownList.Items[seltctableRequiredDropDownList.SelectedIndex].Text;
            bool selectable=false;
            bool required=true;
            if (selectableRequired == "必修")
            {
                selectable = false;
                required = true;
            }
            else if (selectableRequired =="专业选修") {
                selectable = true;
                required = false;
            }
            int teacherID=-1;
            if (null != Session["userID"])
            {
                teacherID =Convert.ToInt32( Session["userID"].ToString());
            }
            string studyYear = courseStudyYearDropDownList.Items[courseStudyYearDropDownList.SelectedIndex].Text;
            string term = courseTermDropDownList.Items[courseTermDropDownList.SelectedIndex].Text;
            //取得课程面向的专业
            IList<string> courseFaceClassName=new List<string>();
            foreach(ListItem it in classCourseListCheckBoxList.Items)
            {
                if(it.Selected){
                    courseFaceClassName.Add(it.Text);
                }
            }
            //取得课程面向的年级string[] courseFaceGrade = { "2009", "2010" };
            IList<string> courseFaceGrade = new List<string>();
            foreach (ListItem it in gradeListCheckBoxList.Items)
            {
                if (it.Selected)
                {
                    courseFaceGrade.Add(it.Text);
                }
            }

            TeacherController teacherController=null;
            Course updateCourse=null;
            if (Session["teacherController"] != null)
            {
                teacherController = (TeacherController)Session["teacherController"];
            }
            if (Session["courseID"] != null)
            {
                int courseId =Convert.ToInt32( Session["courseID"].ToString());
                updateCourse = teacherController.GetCourseById(courseId);
            }
                updateCourse.courseName = name;
                updateCourse.courseStartTime = startTime;
                updateCourse.courseEndTime = endTime;
                updateCourse.courseLocation = location;
                updateCourse.courseDayTime=courseDayTimeList;
                updateCourse.courseOpenCloseFlag = openCloseFlag;
                updateCourse.courseTeacherID = teacherID;
                updateCourse.courseWeekTime = weekTime;
                updateCourse.courseRequired = required;
                updateCourse.courseSelectable = selectable;
                updateCourse.courseStudyYear = studyYear;
                updateCourse.courseTerm = term;
                updateCourse.courseMaxStudentNum=maxStudentNum;

            if (teacherController.UpdateCourse(updateCourse))
            {
                //取得原来的ClassGradeCourseList,然后删除
                IList<ClassGradeCourse> ClassGradeCourseList = teacherController.GetCourseFaceToClassNameAndGrade(updateCourse.courseID);
                for (int i = 0; i < ClassGradeCourseList.Count; i++) {
                    teacherController.DeleteClassGradeCourse((ClassGradeCourse)ClassGradeCourseList[i]);

                }
                //新建
                for (int i = 0; i < courseFaceClassName.Count; i++)
                {
                    for (int j = 0; j < courseFaceGrade.Count; j++)
                    {
                        ClassGradeCourse classGradeCourse = new ClassGradeCourse
                        {
                            ID = new ClassGradeCourseID
                            {
                                classGradeCourseClassName = courseFaceClassName[i],
                                classGradeCourseGrade = courseFaceGrade[j],
                                classGradeCourseCourseId = updateCourse.courseID
                            }

                        };
                       teacherController.AddClassGradeCourse(classGradeCourse);

                    }

                }
                //最后跳转
                Response.Redirect("MyCoursesPage.aspx");
            }
        }
        protected void AddCourseButtonClick(object sender, EventArgs e)
        {
            string name = courseName.Text;
            string startTime = courseStartTimeDropDownList.Items[courseStartTimeDropDownList.SelectedIndex].Text;
            string endTime = courseEndTimeDropDownList.Items[courseEndTimeDropDownList.SelectedIndex].Text;
            string weekTime = courseWeekTimeDropDownList.Items[courseWeekTimeDropDownList.SelectedIndex].Text;
            string maxStudentNum = CourseMaxStudentNum.Text;
            //取得课程一天上的节课string dayTime = "1节2节";
            //IList<string> courseDayTimeCheckBoxList = new List<string>();
            string courseDayTimeList="";
            foreach (ListItem it in courseDayTimeCheckBoxList.Items)
            {
                if (it.Selected)
                {
                    courseDayTimeList=courseDayTimeList+it.Text+" ";
                }
            }

            string location = courseLocationTextBox.Text;
            //string info = "nixisdkjksdfjkdsdkjsdkdffjdskfj";
            bool openCloseFlag = true;
            string selectableRequired =seltctableRequiredDropDownList.Items[seltctableRequiredDropDownList.SelectedIndex].Text;
            bool selectable=false;
            bool required=true;
            if (selectableRequired == "必修")
            {
                selectable = false;
                required = true;
            }
            else if (selectableRequired =="专业选修") {
                selectable = true;
                required = false;
            }
            int teacherID=-1;
            if (null != Session["userID"])
            {
                teacherID =Convert.ToInt32( Session["userID"].ToString());
            }
            string studyYear = courseStudyYearDropDownList.Items[courseStudyYearDropDownList.SelectedIndex].Text;
            string term = courseTermDropDownList.Items[courseTermDropDownList.SelectedIndex].Text;
            //取得课程面向的专业
            IList<string> courseFaceClassName=new List<string>();
            foreach(ListItem it in classCourseListCheckBoxList.Items)
            {
                if(it.Selected){
                    courseFaceClassName.Add(it.Text);
                }
            }
            //取得课程面向的年级string[] courseFaceGrade = { "2009", "2010" };
            IList<string> courseFaceGrade = new List<string>();
            foreach (ListItem it in gradeListCheckBoxList.Items)
            {
                if (it.Selected)
                {
                    courseFaceGrade.Add(it.Text);
                }
            }
            Course newCourse = new Course
            {
                courseName = name,
                courseStartTime = startTime,
                courseEndTime = endTime,
                courseLocation = location,
                courseDayTime=courseDayTimeList,
                courseOpenCloseFlag = openCloseFlag,
                courseTeacherID = teacherID,
                courseWeekTime = weekTime,
                courseRequired = required,
                courseSelectable = selectable,
                courseStudyYear = studyYear,
                courseTerm = term,
                courseMaxStudentNum=maxStudentNum
            };
            TeacherController teacherController=null;
            if (Session["teacherController"] != null)
            {
                teacherController = (TeacherController)Session["teacherController"];
            }
            int courseID = teacherController.AddCourse(newCourse);
            if (courseID != 0)
            {
                for (int i = 0; i < courseFaceClassName.Count; i++)
                {
                    for (int j = 0; j < courseFaceGrade.Count; j++)
                    {
                        ClassGradeCourse classGradeCourse = new ClassGradeCourse
                        {
                            ID = new ClassGradeCourseID
                            {
                                classGradeCourseClassName = courseFaceClassName[i],
                                classGradeCourseGrade = courseFaceGrade[j],
                                classGradeCourseCourseId = courseID
                            }

                        };
                        bool success = teacherController.AddClassGradeCourse(classGradeCourse);

                    }

                }
            }
        }
 public object Save(ClassGradeCourse entity)
 {
     using (ISession session = sessionFactory.OpenSession())
     {
         var id = session.Save(entity);
         session.Flush();
         return id;
     }
 }