using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq.Entity; using EMIS.ViewModel; using EMIS.ViewModel.SelectCourse.SelectCourseResult; using EMIS.DataLogic.SelectCourse.SelectCourseResult; using EMIS.DataLogic.SystemDAL; using EMIS.DataLogic.SelectCourse; using EMIS.DataLogic.Common.Students; using EMIS.CommonLogic.SystemServices; using System.Linq.Expressions; using EMIS.Entities; using EMIS.DataLogic.EducationManage; using EMIS.DataLogic.Repositories; using EMIS.ViewModel.SelectCourse; using System.Transactions; namespace EMIS.CommonLogic.SelectCourse { public class StudentSelectCourseServices : BaseServices, IStudentSelectCourseServices { public Lazy ParameterServices { get; set; } public SelectCourseResultDAL SelectCourseResultDAL { get; set; } public TypeSettingDAL TypeSettingDAL { get; set; } public OpenControlSettingDAL OpenControlSettingDAL { get; set; } public StudentsDAL StudentsDAL { get; set; } public InSchoolSettingRepository inSchoolSettingRepository { get; set; } /// /// 学生进入选课页面 /// /// /// /// /// public IGridResultSet GetStudentSelectCourseResultViewList(Guid userID, int? pageIndex, int? pageSize) { var student = StudentsDAL.StudentRepository.GetSingle(x => x.UserID == userID); var selectCourseResultList = this.SelectCourseResultDAL.GetStudentSelectCourseResultView(userID) .OrderBy(x => x.SelectCourseTypeID).ThenBy(x => x.CourseName) .ToGridResultSet(pageIndex, pageSize); var selectCourseTeacherQuery = this.SelectCourseResultDAL.GetStudentSelectCourseTeacherResultView(userID); if (selectCourseResultList.rows.Count <= 20) { var courseIDList = selectCourseResultList.rows.Select(x => x.SelectCourseID).ToList(); selectCourseTeacherQuery = selectCourseTeacherQuery.Where(x => courseIDList.Contains(x.SelectCourseID)); } var selectCourseTeacherList = selectCourseTeacherQuery.ToList(); selectCourseResultList.rows.ForEach(x => { var teacherList = selectCourseTeacherList.Where(w => w.SelectCourseID == x.SelectCourseID); x.TeacherNames = string.Join(",", teacherList.Select(w => w.Name)); x.TeacherIDs = string.Join(",", teacherList.Select(w => w.UserID.ToString())); }); var ExecutableFreeSelectionCouseIDList = selectCourseResultList.rows.Where(x => x.SelectCourseTypeID == (int)EM_SelectCourseType.FreeSelectionCouse).Select(x => x.ID).ToList(); if (ExecutableFreeSelectionCouseIDList.Count > 0) { var ExecutableFreeSelectionCouseSchedulingList = SelectCourseResultDAL.GetScheduling(ExecutableFreeSelectionCouseIDList).ToList(); var newList = GetWeekdayTimesSegmentName(ExecutableFreeSelectionCouseSchedulingList); selectCourseResultList.rows.ForEach(x => { var list = newList.Where(w => w.ID == x.ID); x.WeekdayTimesSegmentName = string.Join(";", list.OrderBy(w => w.Weekday).Select(w => w.WeekdayTimesSegmentName)); }); } return selectCourseResultList; } /// /// 上课时间,将星期和节次合并 /// /// 上课时间数据 /// public List GetWeekdayTimesSegmentName(List SourceList) { List newList = new List(); var idList = SourceList.Select(x => x.ID).Distinct().ToList(); foreach (var id in idList) { //循环处理每个任选课的上课时间 var list = SourceList.Where(x => x.ID == id).ToList(); var weekdayList = list.Select(x => x.Weekday).Distinct().ToList(); foreach (var weekday in weekdayList) { //先循环同一星期日期 var tmpList = list.Where(x => x.Weekday == weekday).OrderBy(x => x.StartTimes).ToList(); string WeekdayTimesSegmentName = tmpList.FirstOrDefault().WeekdayName + tmpList.FirstOrDefault().StartTimes; var array = tmpList.Select(x => new { x.StartTimes, x.EndTimes }).ToArray(); for (int i = 0; i < array.Length; i++) { //将同一天的节次合并,相邻的节次用“-”将最开始节次和最后节次合并,例:1/2/3合并成“1-3”, //如果不是相邻的先用逗号隔开,再用“-”合并,例:1/2/3和5/6,合并成“1-3,5-6” if (i > 0 && (array[i].StartTimes > array[i - 1].EndTimes + 1)) { //不相邻的先用逗号隔开,再用“-”合并 WeekdayTimesSegmentName += "-" + array[i - 1].EndTimes + "节," + array[i].StartTimes; } if (i + 1 == array.Length) WeekdayTimesSegmentName += "-" + array[i].EndTimes + "节"; } newList.Add(new ExecutableFreeSelectionCouseSchedulingView { ID = tmpList.FirstOrDefault().ID, WeekdayTimesSegmentName = WeekdayTimesSegmentName.Replace("星期", ""), Weekday = tmpList.FirstOrDefault().Weekday }); } } return newList; } public StudentSelectCourseSummaryView GetStudentSelectCourseSummaryView(Guid userID) { StudentSelectCourseSummaryView result; var currentSchoolyearID = this.SelectCourseResultDAL.GetSelectCourseSchoolyear(); //所有在校状态 var inschoolStatusList = inSchoolSettingRepository.GetList(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList(); result = new StudentSelectCourseSummaryView(this.SelectCourseResultDAL.GetStudentSelectCourseBaseView(userID)); if (inschoolStatusList.Contains(result.InSchoolStatusID)) result.isInSchool = true; else result.isInSchool = false; var typeSetting = TypeSettingDAL.GetTypeSettingView(x => x.SchoolyearID == currentSchoolyearID, (x => true)); var openControlSetting = OpenControlSettingDAL.GetOpenControlSettingView(x => x.SchoolyearID == currentSchoolyearID, (x => true), (x => x.GrademajorID == result.GrademajorID)).FirstOrDefault(); var opionalSetting = typeSetting.FirstOrDefault(x => x.SelectCourseTypeID == (int)EM_SelectCourseType.OptionalCourse); var freeSelectionCourseSetting = typeSetting.FirstOrDefault(x => x.SelectCourseTypeID == (int)EM_SelectCourseType.FreeSelectionCouse); //任选控制 var freeSelectionCourseGradeYearSetting = SelectCourseResultDAL.FreeSelectionCourseGradeYearSettingRepository.GetSingle(x => x.SchoolyearID == currentSchoolyearID && x.GradeYear == result.GrademajorYear); result.OptionalStartTime = (openControlSetting == null) ? (opionalSetting == null ? null : opionalSetting.StartTime) : openControlSetting.StartTime; result.OptionalEndTime = (openControlSetting == null) ? (opionalSetting == null ? null : opionalSetting.EndTime) : openControlSetting.EndTime; if (opionalSetting != null) { if (opionalSetting.StartTime > result.OptionalStartTime) { result.OptionalStartTime = opionalSetting.StartTime; } if (opionalSetting.EndTime < result.OptionalEndTime) { result.OptionalEndTime = opionalSetting.EndTime; } } result.OptionalMaxSelectCount = (openControlSetting == null) ? ((opionalSetting == null) ? 0 : opionalSetting.MaxSelectCount) : openControlSetting.MaxSelectCount; result.OptionalMinSelectCount = (openControlSetting == null) ? ((opionalSetting == null) ? 0 : opionalSetting.MinSelectCount) : openControlSetting.MinSelectCount; result.OptionalMaxCredit = (openControlSetting == null) ? ((opionalSetting == null) ? null : opionalSetting.MaxCredit) : openControlSetting.MaxCredit; result.OptionalMinCredit = (openControlSetting == null) ? ((opionalSetting == null) ? null : opionalSetting.MinCredit) : openControlSetting.MinCredit; result.FreeSelectCourseStartTime = (freeSelectionCourseGradeYearSetting == null) ? (freeSelectionCourseSetting == null ? null : freeSelectionCourseSetting.StartTime) : freeSelectionCourseGradeYearSetting.StartTime; result.FreeSelectCourseEndTime = (freeSelectionCourseGradeYearSetting == null) ? (freeSelectionCourseSetting == null ? null : freeSelectionCourseSetting.EndTime) : freeSelectionCourseGradeYearSetting.EndTime; if (freeSelectionCourseSetting != null) { if (freeSelectionCourseSetting.StartTime > result.FreeSelectCourseStartTime) { result.FreeSelectCourseStartTime = freeSelectionCourseSetting.StartTime; } if (freeSelectionCourseSetting.EndTime < result.OptionalEndTime) { result.FreeSelectCourseEndTime = freeSelectionCourseSetting.EndTime; } } result.FreeSelectCourseMaxSelectCount = (freeSelectionCourseGradeYearSetting == null) ? ((freeSelectionCourseSetting == null) ? null : freeSelectionCourseSetting.MaxSelectCount) : freeSelectionCourseGradeYearSetting.MaxSelectCount; result.FreeSelectCourseMinSelectCount = (freeSelectionCourseGradeYearSetting == null) ? ((freeSelectionCourseSetting == null) ? null : freeSelectionCourseSetting.MinSelectCount) : freeSelectionCourseGradeYearSetting.MinSelectCount; result.FreeSelectCourseMaxCredit = (freeSelectionCourseGradeYearSetting == null) ? ((freeSelectionCourseSetting == null) ? null : freeSelectionCourseSetting.MaxCredit) : freeSelectionCourseGradeYearSetting.MaxCredit; result.FreeSelectCourseMinCredit = (freeSelectionCourseGradeYearSetting == null) ? ((freeSelectionCourseSetting == null) ? null : freeSelectionCourseSetting.MinCredit) : freeSelectionCourseGradeYearSetting.MinCredit; //限选控制 result.GrademajorStartTime = (openControlSetting == null) ? null : openControlSetting.StartTime; result.GrademajorEndTime = (openControlSetting == null) ? null : openControlSetting.EndTime; result.GrademajorMaxSelectCount = (openControlSetting == null) ? null : openControlSetting.MaxSelectCount; result.GrademajorMinSelectCount = (openControlSetting == null) ? null : openControlSetting.MinSelectCount; result.GrademajorMaxCredit = (openControlSetting == null) ? null : openControlSetting.MaxCredit; result.GrademajorMinCredit = (openControlSetting == null) ? null : openControlSetting.MinCredit; //任选控制 result.GradeYearStartTime = (freeSelectionCourseGradeYearSetting == null) ? null : freeSelectionCourseGradeYearSetting.StartTime; result.GradeYearEndTime = (freeSelectionCourseGradeYearSetting == null) ? null : freeSelectionCourseGradeYearSetting.EndTime; result.GradeYearMaxSelectCount = (freeSelectionCourseGradeYearSetting == null) ? null : freeSelectionCourseGradeYearSetting.MaxSelectCount; result.GradeYearMinSelectCount = (freeSelectionCourseGradeYearSetting == null) ? null : freeSelectionCourseGradeYearSetting.MinSelectCount; result.GradeYearMaxCredit = (freeSelectionCourseGradeYearSetting == null) ? null : freeSelectionCourseGradeYearSetting.MaxCredit; result.GradeYearMinCredit = (freeSelectionCourseGradeYearSetting == null) ? null : freeSelectionCourseGradeYearSetting.MinCredit; return result; } /// /// 学生选修课程页面 /// /// /// /// /// /// /// /// /// /// public IGridResultSet GetSelectedCourseViewList (ConfiguretView configuretView, Guid? schoolYearID, Guid? collegeID, Guid? courseID, int? courseTypeID, int? selectCourseTypeID, int pageIndex, int pageSize) { Expression> eocExp = (x => true && x.CF_Student.Any(w => w.UserID == EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID)); Expression> efcExp = (x => true && x.CF_Student.Any(w => w.UserID == EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID)); var query = SelectCourseResultDAL.GetStudentSelectedCourseResultView(eocExp, efcExp); var query1 = SelectCourseResultDAL.GetSelectCourseResultTeacher(eocExp, efcExp); var query2 = SelectCourseResultDAL.GetSelectCourseResultTeachingMode(eocExp, efcExp); //if (schoolYearID.HasValue) //{ // query = query.Where(x => x.SchoolyearID == schoolYearID); // query1 = query1.Where(x => x.SchoolyearID == schoolYearID); //} //if (collegeID.HasValue) //{ // query = query.Where(x => x.CollegeID == collegeID); //} //if (courseID.HasValue) //{ // query = query.Where(x => x.CoursematerialID == courseID); //} //if (courseTypeID.HasValue) //{ // query = query.Where(x => x.CourseTypeID == courseTypeID); // query1 = query1.Where(x => x.CourseTypeID == courseTypeID); //} //if (selectCourseTypeID.HasValue) //{ // query = query.Where(x => x.SelectCourseType == selectCourseTypeID); // query1 = query1.Where(x => x.SelectCourseType == selectCourseTypeID); //} if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); var result = query.OrderBy(x => x.SchoolYearCode).ThenBy(x => x.SelectCourseTypeID).ThenBy(x => x.CourseName).ToGridResultSet(null, null); var teacher = query1.ToList(); var teachingMode = query2.ToList().OrderBy(x => x.SchoolYearCode).ThenBy(x => x.SelectCourseType).ThenBy(x => x.CourseName); result.rows.ForEach(x => x.TeacherNames = string.Join(",", teacher.Where(w => w.ID == x.ID).Select(w => w.TeacherName))); var ExecutableFreeSelectionCouseIDList = result.rows.Where(x => x.SelectCourseTypeID == (int)EM_SelectCourseType.FreeSelectionCouse).Select(x => x.ID).ToList(); if (ExecutableFreeSelectionCouseIDList.Count > 0) { var ExecutableFreeSelectionCouseSchedulingList = SelectCourseResultDAL.GetScheduling(ExecutableFreeSelectionCouseIDList).ToList(); var newList = GetWeekdayTimesSegmentName(ExecutableFreeSelectionCouseSchedulingList); result.rows.ForEach(x => { var list = newList.Where(w => w.ID == x.ID); x.WeekdayTimesSegmentName = string.Join(";", list.OrderBy(w => w.Weekday).Select(w => w.WeekdayTimesSegmentName)); }); } return result; } public IGridResultSet GetCanceledCourseViewList (ConfiguretView configuretView, int pageIndex, int pageSize) { var userid = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID; Expression> eocExp = (x => true && x.CF_Student.Any(w => w.UserID == userid && x.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate)); Expression> efcExp = (x => true && x.CF_Student.Any(w => w.UserID == userid && x.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate)); var query = SelectCourseResultDAL.GetStudentSelectedCourseResultView(eocExp, efcExp); var query1 = SelectCourseResultDAL.GetSelectCourseResultTeacher(eocExp, efcExp); var query2 = SelectCourseResultDAL.GetSelectCourseResultTeachingMode(eocExp, efcExp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); var result = query.OrderBy(x => x.SelectCourseTypeID).ToGridResultSet(null, null); var teacher = query1.ToList(); var teachingMode = query2.ToList().OrderBy(x => x.SelectCourseType); result.rows.ForEach(x => x.TeacherNames = string.Join(",", teacher.Where(w => w.ID == x.ID).Select(w => w.TeacherName))); return result; } public void SelectCourse(Guid userID, Guid? grademajorID, Guid coursematerialID, int selectCourseTypeID, string teacherIDs, Guid ID) { //var teacherIDList = teacherIDs.Split(',') // .Where(x => !string.IsNullOrEmpty(x)) // .Select(x => (Guid?)new Guid(x)).ToList(); var isPeopleNumLimit = ParameterServices.Value.GetParameterValue(CF_ParameterType.SelectCourseNoLimit); var student = this.StudentsDAL.StudentRepository.GetSingle(x => x.UserID == userID, x => x.CF_Classmajor.CF_Grademajor); var studentSelectCourseSummary = this.GetStudentSelectCourseSummaryView(userID); var currentSchoolyearID = this.SelectCourseResultDAL.GetSelectCourseSchoolyear(); var ExecutableFreeSelectionCouse = SelectCourseResultDAL.ExecutableFreeSelectionCouseRepository.GetList(x => x.SchoolyearID == currentSchoolyearID && x.EM_FreeSelectionCouse.CoursematerialID == coursematerialID && x.CF_Student.Any(w => w.UserID == userID)).FirstOrDefault(); var ExecutableOptionalCourse = SelectCourseResultDAL.ExecutableOptionalCourseRepository.GetList(x => x.SchoolyearID == currentSchoolyearID && x.EM_OptionalCoursePlan.CoursematerialID == coursematerialID && x.CF_Student.Any(w => w.UserID == userID)).FirstOrDefault(); if (ExecutableFreeSelectionCouse != null || ExecutableOptionalCourse != null) { throw new Exception("您已报名此门课程的选修,请勿重复报名!"); } var score = SelectCourseResultDAL.FinallyScoreRepository.GetSingle(x => x.UserID == userID && x.CoursematerialID == coursematerialID); if (score != null) { throw new Exception("您已修过此门课程,并且有考试成绩,请勿重复报名!"); } //限选 if (selectCourseTypeID == (int)EM_SelectCourseType.OptionalCourse) { if (studentSelectCourseSummary.OptionalStartTime > DateTime.Now || studentSelectCourseSummary.GrademajorStartTime > DateTime.Now) { throw new Exception("该课程还未开始选课,不能选课。"); } if (studentSelectCourseSummary.OptionalEndTime < DateTime.Now || studentSelectCourseSummary.GrademajorEndTime < DateTime.Now) { throw new Exception("该课程已过选课时间,不能选课。"); } if ((studentSelectCourseSummary.OptionalMaxSelectCount ?? 0) != 0 && (studentSelectCourseSummary.OptionalTotalSelectCount + 1) > studentSelectCourseSummary.OptionalMaxSelectCount) { throw new Exception("选课超出了限选课门数上限,不能选课。"); } using (TransactionScope ts = new TransactionScope()) { var optionalCourse = this.SelectCourseResultDAL.ExecutableOptionalCourseRepository.GetList(x => x.ExecutableOptionalCourseID == ID, x => x.CF_Student, x => x.EM_ExecutableOptionalCourseTeachingSetting//, //x => x.EM_EducationMissionClass ).FirstOrDefault(); if ((studentSelectCourseSummary.OptionalMaxCredit ?? 0) != 0 && (studentSelectCourseSummary.OptionalTotalCredit + optionalCourse.EM_ExecutableOptionalCourseTeachingSetting.Credit ?? 0) > studentSelectCourseSummary.OptionalMaxCredit) { throw new Exception("选课超出了限选课学分上限,不能选课。"); } if ((studentSelectCourseSummary.GrademajorMaxSelectCount ?? 0) != 0 && (studentSelectCourseSummary.OptionalTotalSelectCount + 1) > studentSelectCourseSummary.GrademajorMaxSelectCount) { throw new Exception("选课超出了该限选控制" + student.CF_Classmajor.CF_Grademajor.SemesterID + "级门数上限,不能选课。"); } if ((studentSelectCourseSummary.GrademajorMaxCredit ?? 0) != 0 && (studentSelectCourseSummary.OptionalTotalCredit + optionalCourse.EM_ExecutableOptionalCourseTeachingSetting.Credit ?? 0) > studentSelectCourseSummary.GrademajorMaxCredit) { throw new Exception("选课超出了该限选控制" + student.CF_Classmajor.CF_Grademajor.SemesterID + "级学分上限,不能选课。"); } if (optionalCourse != null) { //if (optionalCourse.EM_EducationMissionClass.Count > 0) //{ // throw new Exception("该课程已经结束选课,并开始进行教学安排,不能选课。"); //} if (isPeopleNumLimit == true && (optionalCourse.PeopleNumlimit ?? 0) != 0 && (optionalCourse.PeopleNumlimit ?? 0) < (optionalCourse.CF_Student.Count + 1)) { throw new Exception("该课程选课人数已达上限,不能选课。"); } if (!optionalCourse.CF_Student.Any(x => x.UserID == userID)) { optionalCourse.CF_Student.Add(student); } } else { throw new Exception("找不到对应的限选课程。"); } this.UnitOfWork.Commit(); ts.Complete(); } } //任选 else if (selectCourseTypeID == (int)EM_SelectCourseType.FreeSelectionCouse) { if (studentSelectCourseSummary.FreeSelectCourseStartTime > DateTime.Now || studentSelectCourseSummary.GradeYearStartTime > DateTime.Now) { throw new Exception("该课程还未开始选课,不能选课。"); } if (studentSelectCourseSummary.FreeSelectCourseEndTime < DateTime.Now || studentSelectCourseSummary.GradeYearEndTime < DateTime.Now) { throw new Exception("该课程已过选课时间,不能选课。"); } //上课时间 var schedulingList = SelectCourseResultDAL.GetSchedulingTime(ID).ToList(); foreach (var scheduling in schedulingList) { var repeat = SelectCourseResultDAL.GetRepeatTime(userID, ID, scheduling.CoursesTimeID, scheduling.Weekday, scheduling.SchoolyearID, scheduling.StartWeeklyNum, scheduling.EndWeeklyNum).FirstOrDefault(); if (repeat != null) { throw new Exception("此门课程的上课时间,与其它已报名选修有冲突!"); } } if ((studentSelectCourseSummary.FreeSelectCourseMaxSelectCount ?? 0) != 0 && (studentSelectCourseSummary.FreeSelectCourseTotalSelectCount + 1) > studentSelectCourseSummary.FreeSelectCourseMaxSelectCount) { throw new Exception("选课超出了任选课门数上限,不能选课。"); } if ((studentSelectCourseSummary.GradeYearMaxSelectCount ?? 0) != 0 && (studentSelectCourseSummary.FreeSelectCourseTotalSelectCount + 1) > studentSelectCourseSummary.GradeYearMaxSelectCount) { throw new Exception("选课超出了该任选控制" + student.CF_Classmajor.CF_Grademajor.GradeID + "级门数上限,不能选课。"); } using (TransactionScope ts = new TransactionScope()) { var freeSelectionCourse = this.SelectCourseResultDAL.ExecutableFreeSelectionCouseRepository.GetList(x => x.ExecutableFreeSelectionCouseID == ID, x => x.CF_Student, x => x.EM_ExecutableFreeSelectionCouseTeachingSetting//, //x => x.EM_EducationMissionClass ).FirstOrDefault(); if (freeSelectionCourse == null) throw new Exception("找不到对应的任选课程。"); if ((studentSelectCourseSummary.FreeSelectCourseMaxCredit ?? 0) != 0 && (studentSelectCourseSummary.FreeSelectCourseTotalCredit + freeSelectionCourse.EM_ExecutableFreeSelectionCouseTeachingSetting.Credit ?? 0) > studentSelectCourseSummary.FreeSelectCourseMaxCredit) { throw new Exception("选课超出了任选课学分上限,不能选课。"); } if ((studentSelectCourseSummary.GradeYearMaxCredit ?? 0) != 0 && (studentSelectCourseSummary.FreeSelectCourseTotalCredit + freeSelectionCourse.EM_ExecutableFreeSelectionCouseTeachingSetting.Credit ?? 0) > studentSelectCourseSummary.GradeYearMaxCredit) { throw new Exception("选课超出了该任选控制" + student.CF_Classmajor.CF_Grademajor.GradeID + "级学分上限,不能选课。"); } //if (freeSelectionCourse.EM_EducationMissionClass.Count > 0) //{ // throw new Exception("该课程已经结束选课,并开始进行教学安排,不能选课。"); //} if (isPeopleNumLimit == true && (freeSelectionCourse.PeopleNumlimit ?? 0) != 0 && (freeSelectionCourse.PeopleNumlimit ?? 0) < (freeSelectionCourse.CF_Student.Count + 1)) { throw new Exception("该课程选课人数已达上限,不能选课。"); } //上面的判断不知道有什么用暂时放着 if (freeSelectionCourse.PeopleNumlimit != null && (freeSelectionCourse.PeopleNumlimit < (freeSelectionCourse.CF_Student.Count + 1))) { throw new Exception("该课程选课人数已达上限,不能选课。"); } if (!freeSelectionCourse.CF_Student.Any(x => x.UserID == userID)) { freeSelectionCourse.CF_Student.Add(student); } this.UnitOfWork.Commit(); ts.Complete(); } } } public void CancelSelectCourse(Guid userID, Guid? grademajorID, Guid coursematerialID, int selectCourseTypeID, string teacherIDs, Guid ID) { var teacherIDList = teacherIDs.Split(',') .Where(x => !string.IsNullOrEmpty(x)) .Select(x => (Guid?)new Guid(x)).ToList(); var student = this.StudentsDAL.StudentRepository.GetSingle(x => x.UserID == userID); var studentSelectCourseSummary = this.GetStudentSelectCourseSummaryView(userID); if (selectCourseTypeID == (int)EM_SelectCourseType.OptionalCourse) { if (studentSelectCourseSummary.OptionalStartTime > DateTime.Now || studentSelectCourseSummary.GrademajorStartTime > DateTime.Now) { throw new Exception("该课程还未开始选课,不能取消选课。"); } if (studentSelectCourseSummary.OptionalEndTime < DateTime.Now || studentSelectCourseSummary.GrademajorEndTime < DateTime.Now) { throw new Exception("该课程已过选课时间,不能取消选课。"); } //var optionalCourse = this.SelectCourseResultDAL.GetCurrentExecutableOptionalCourse(student.ClassmajorID, grademajorID, coursematerialID, teacherIDList) // .FirstOrDefault(); var optionalCourse = this.SelectCourseResultDAL.ExecutableOptionalCourseRepository.GetList(x => x.ExecutableOptionalCourseID == ID, x => x.CF_Student, x => x.EM_ExecutableOptionalCourseTeachingSetting).FirstOrDefault(); if (optionalCourse != null) { if (optionalCourse.RecordStatus == (int)EM_SelectCourseResultStatus.Created) { throw new Exception("该课程已经结束选课,并开始进行教学安排,不能取消选课。"); } optionalCourse.CF_Student.RemoveWhere(x => x.UserID == userID); } else { throw new Exception("找不到对应的限选课程。"); } } else if (selectCourseTypeID == (int)EM_SelectCourseType.FreeSelectionCouse) { if (studentSelectCourseSummary.FreeSelectCourseStartTime > DateTime.Now || studentSelectCourseSummary.GradeYearStartTime > DateTime.Now) { throw new Exception("该课程还未开始选课,不能取消选课。"); } if (studentSelectCourseSummary.FreeSelectCourseEndTime < DateTime.Now || studentSelectCourseSummary.GradeYearEndTime < DateTime.Now) { throw new Exception("该课程已过选课时间,不能取消选课。"); } //var freeSelectionCourse = this.SelectCourseResultDAL.GetCurrentExecutableFreeSelectionCourse(coursematerialID, teacherIDList) // .FirstOrDefault(); var freeSelectionCourse = this.SelectCourseResultDAL.ExecutableFreeSelectionCouseRepository.GetList(x => x.ExecutableFreeSelectionCouseID == ID, x => x.CF_Student, x => x.EM_ExecutableFreeSelectionCouseTeachingSetting).FirstOrDefault(); if (freeSelectionCourse != null) { if (freeSelectionCourse.RecordStatus == (int)EM_SelectCourseResultStatus.Created) { throw new Exception("该课程已经结束选课,并开始进行教学安排,不能取消选课。"); } freeSelectionCourse.CF_Student.RemoveWhere(x => x.UserID == userID); } else { throw new Exception("找不到对应的任选课程。"); } } this.UnitOfWork.Commit(); } } }