123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530 |
- 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<IParameterServices> 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; }
- /// <summary>
- /// 学生进入选课页面
- /// </summary>
- /// <param name="userID"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<StudentSelectCourseView> 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;
- }
- /// <summary>
- /// 上课时间,将星期和节次合并
- /// </summary>
- /// <param name="SourceList">上课时间数据</param>
- /// <returns></returns>
- public List<ExecutableFreeSelectionCouseSchedulingView> GetWeekdayTimesSegmentName(List<ExecutableFreeSelectionCouseSchedulingView> SourceList)
- {
- List<ExecutableFreeSelectionCouseSchedulingView> newList = new List<ExecutableFreeSelectionCouseSchedulingView>();
- 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;
- }
- /// <summary>
- /// 学生选修课程页面
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="schoolYearID"></param>
- /// <param name="collegeID"></param>
- /// <param name="courseID"></param>
- /// <param name="courseTypeID"></param>
- /// <param name="selectCourseTypeID"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<StudentSelectCourseView> GetSelectedCourseViewList
- (ConfiguretView configuretView, Guid? schoolYearID, Guid? collegeID,
- Guid? courseID, int? courseTypeID, int? selectCourseTypeID, int pageIndex, int pageSize)
- {
- Expression<Func<EM_ExecutableOptionalCourse, bool>> eocExp = (x => true && x.CF_Student.Any(w => w.UserID == EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID));
- Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> 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<StudentSelectCourseView>(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<StudentSelectCourseView> GetCanceledCourseViewList
- (ConfiguretView configuretView, int pageIndex, int pageSize)
- {
- var userid = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID;
- Expression<Func<EM_ExecutableOptionalCourse, bool>> eocExp = (x => true && x.CF_Student.Any(w => w.UserID == userid
- && x.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate));
- Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> 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<StudentSelectCourseView>(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<bool>(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();
- }
- }
- }
|