//退课
 public bool DropCourse(int studentId, int courseId)
 {
     ICourseDao courseDao = new CourseDao(sessionFactory);
     Course selectedCourse = courseDao.Get(courseId);
     ISelectionDao selectionDao = new SelectionDao(sessionFactory);
     SelectionID selectionID = new SelectionID {
         selectionStudentID=studentId,
         selectionCourseID=courseId,
         selectionStudyYear=selectedCourse.courseStudyYear,
          selectionTerm=selectedCourse.courseTerm
     };
     Selection selection=selectionDao.Get(selectionID);
     if (null != selection)
     {
         try
         {
             selectionDao.Delete(selection);
             return true;
         }
         catch (Exception e) {
             return false;
         }
     }
     else {
         return false;
     }
 }
        public IList<Course> GetAllSelectableCourse(string className, string grade,int studentId)
        {
            IClassGradeCourseDao classGradeCourseDao = new ClassGradeCourseDao(sessionFactory);
            IList<ClassGradeCourse> classGradeCourseList = classGradeCourseDao.GetAllSelectableClassGradeCourse(className, grade);
            ICourseDao courseDao=new CourseDao(sessionFactory);
            for (int i = 0; i < classGradeCourseList.Count; i++) {
                Course closeCourse = courseDao.Get(classGradeCourseList[i].ID.classGradeCourseCourseId);
                //如果这一门课是关闭了,就去掉这个选课关联项
                if (false == closeCourse.courseOpenCloseFlag) {
                    classGradeCourseList.RemoveAt(i);
                    continue;
                }

                //再去掉已经选择的课程,有courseID,年级,专业,课,这门课就不用显示了
                ISelectionDao selectionDao = new SelectionDao(sessionFactory);
                IList<Selection> selectionList = selectionDao.GetSelectionByStudentId(studentId);

                for (int j = 0; j < selectionList.Count; j++)
                {
                    if (selectionList[j].ID.selectionCourseID == classGradeCourseList[i].ID.classGradeCourseCourseId)
                    {
                        classGradeCourseList.RemoveAt(i);
                        continue;
                    }
                }
            }

            IList<Course> selectableCourseList = new List<Course>();

            for (int j = 0; j < classGradeCourseList.Count; j++) {
                Course selectableCourse =courseDao.Get(classGradeCourseList[j].ID.classGradeCourseCourseId);
                selectableCourseList.Add(selectableCourse);
            }
            return selectableCourseList;
        }
 //选课,生成一个Selection
 public bool SelectCourse(int studentId, int courseId)
 {
     //IStudentDao studentDao = new StudentDao(sessionFactory);
     ICourseDao courseDao = new CourseDao(sessionFactory);
     Course selectedCourse = courseDao.Get(courseId);
     Selection newSelection = new Selection
     {
         ID = new SelectionID {
             selectionStudentID=studentId,
             selectionCourseID=selectedCourse.courseID,
             selectionStudyYear=selectedCourse.courseStudyYear,
             selectionTerm=selectedCourse.courseTerm
         },
         selectionScorePermit=false,
         selectionScore =-1
     };
     ISelectionDao selectionDao = new SelectionDao(sessionFactory);
     if (null != selectionDao.Save(newSelection))
     {
         return true;
     }
     else {
         return false;
     }
 }
 public IList<Course> GetAllSelectedCourse(int studentId)
 {
     ISelectionDao selectionDao = new SelectionDao(sessionFactory);
     IList<Selection> selectedSelectionList=selectionDao.GetSelectionByStudentId(studentId);
     ICourseDao courseDao = new CourseDao(sessionFactory);
     IList<Course> selectedCourseList = new List<Course>();
     for (int i = 0; i < selectedSelectionList.Count;i++ )
     {
         Course selectedCourse=courseDao.Get(selectedSelectionList[i].ID.selectionCourseID);
         selectedCourseList.Add(selectedCourse);
     }
     return selectedCourseList;
 }
 public void Save(Selection newSelection)
 {
     ISelectionDao selectionDao = new SelectionDao(sessionFactory);
     selectionDao.Save(newSelection);
 }
 public int GetStudentScore(object selectionID)
 {
     ISelectionDao selectionDao= new SelectionDao(sessionFactory);
     try
     {
         Selection selection= selectionDao.Get(selectionID);
         return selection.selectionScore;
     }
     catch (Exception e)
     {
         return -1;
     }
 }
 public bool ScoreStudentCourse(Selection selectedSelection)
 {
     ISelectionDao selectionDao = new SelectionDao(sessionFactory);
     try
     {
         selectionDao.Update(selectedSelection);
         return true;
     }
     catch (Exception e) {
         return false;
     }
 }
        public Selection GetSelectionByID(SelectionID selectionId)
        {
            ISelectionDao selectionDao = new SelectionDao(sessionFactory);
            try
            {
                return selectionDao.Get(selectionId);

            }
            catch (Exception e)
            {
                return null;
            }
        }
 public IList<Selection> GetSelectedCourseStudentNum(int courseID)
 {
     ISelectionDao selectionDao = new SelectionDao(sessionFactory);
     IList<Selection> studentSelection = selectionDao.GetSelectionByCourseId(courseID);
     return studentSelection;
 }
        //得到选择课程的学生表,是当前学年学期的选课的学生,往年的要专门查询查Selecion表
        public IList<Student> GetSelectCourseStudent(int courseId)
        {
            ICourseDao courseDao = new CourseDao(sessionFactory);
            Course selectedCourse = courseDao.Get(courseId);
            string studyYear = selectedCourse.courseStudyYear;
            string term = selectedCourse.courseTerm;
            ISelectionDao selectionDao = new SelectionDao(sessionFactory);
            //Selection表,是否为空?否则就是NullException
            IList<Selection> selectionList=selectionDao.GetSelectionByCourse(courseId,studyYear,term);

            //IList<Student> studentList=null;
            //(还未分配空间,一定要分配了空间给一个对象才可以用其实例方法)
            IList<Student> studentList =new List<Student>();
            IStudentDao studentDao = new StudentDao(sessionFactory);
            for (int i = 0; i < selectionList.Count; i++) {
                studentList.Add(studentDao.Get(selectionList[i].ID.selectionStudentID));
            }
            return studentList;
        }
 public void ScoreAStudent()
 {
     int score = 60;
     string studyYear = "2012~2013";
     string term = "上";
     int courseId =1000;
     int studentId = 10000002;
     ISelectionDao selectionDao = new SelectionDao(sessionFactory);
     SelectionID seletionID = new SelectionID {
          selectionStudentID=studentId,
          selectionCourseID= courseId,
          selectionStudyYear=studyYear,
          selectionTerm=term
     };
     Selection selectedSelection = selectionDao.Get(seletionID);
     bool success;
     if (true == selectedSelection.selectionScorePermit)
     {
         selectedSelection.selectionScore = score;
         success = teacherController.ScoreStudentCourse(selectedSelection);
     }
     else {
         success=false;
     }
     Assert.AreEqual(true, success);
 }
 //允许对某一学年,有一学期,的学生打分
 public bool PermitScoreStudent(string studyYear, string term)
 {
     ISelectionDao selectionDao = new SelectionDao(sessionFactory);
     try
     {
         IList<Selection> selectionList = selectionDao.PermitSeletionScorePermit(studyYear,term);
         for (int i = 0; i < selectionList.Count; i++)
         {
             selectionList[i].selectionScorePermit = true;
             selectionDao.Update(selectionList[i]);
         }
         return true;
     }
     catch (Exception e) {
         return false;
     }
 }