StudentSelectCourseServices.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq.Entity;
  6. using EMIS.ViewModel;
  7. using EMIS.ViewModel.SelectCourse.SelectCourseResult;
  8. using EMIS.DataLogic.SelectCourse.SelectCourseResult;
  9. using EMIS.DataLogic.SystemDAL;
  10. using EMIS.DataLogic.SelectCourse;
  11. using EMIS.DataLogic.Common.Students;
  12. using EMIS.CommonLogic.SystemServices;
  13. using System.Linq.Expressions;
  14. using EMIS.Entities;
  15. using EMIS.DataLogic.EducationManage;
  16. using EMIS.DataLogic.Repositories;
  17. using EMIS.ViewModel.SelectCourse;
  18. using System.Transactions;
  19. namespace EMIS.CommonLogic.SelectCourse
  20. {
  21. public class StudentSelectCourseServices : BaseServices, IStudentSelectCourseServices
  22. {
  23. public Lazy<IParameterServices> ParameterServices { get; set; }
  24. public SelectCourseResultDAL SelectCourseResultDAL { get; set; }
  25. public TypeSettingDAL TypeSettingDAL { get; set; }
  26. public OpenControlSettingDAL OpenControlSettingDAL { get; set; }
  27. public StudentsDAL StudentsDAL { get; set; }
  28. public InSchoolSettingRepository inSchoolSettingRepository { get; set; }
  29. /// <summary>
  30. /// 学生进入选课页面
  31. /// </summary>
  32. /// <param name="userID"></param>
  33. /// <param name="pageIndex"></param>
  34. /// <param name="pageSize"></param>
  35. /// <returns></returns>
  36. public IGridResultSet<StudentSelectCourseView> GetStudentSelectCourseResultViewList(Guid userID, int? pageIndex, int? pageSize)
  37. {
  38. var student = StudentsDAL.StudentRepository.GetSingle(x => x.UserID == userID);
  39. var selectCourseResultList = this.SelectCourseResultDAL.GetStudentSelectCourseResultView(userID)
  40. .OrderBy(x => x.SelectCourseTypeID).ThenBy(x => x.CourseName)
  41. .ToGridResultSet(pageIndex, pageSize);
  42. var selectCourseTeacherQuery = this.SelectCourseResultDAL.GetStudentSelectCourseTeacherResultView(userID);
  43. if (selectCourseResultList.rows.Count <= 20)
  44. {
  45. var courseIDList = selectCourseResultList.rows.Select(x => x.SelectCourseID).ToList();
  46. selectCourseTeacherQuery = selectCourseTeacherQuery.Where(x => courseIDList.Contains(x.SelectCourseID));
  47. }
  48. var selectCourseTeacherList = selectCourseTeacherQuery.ToList();
  49. selectCourseResultList.rows.ForEach(x =>
  50. {
  51. var teacherList = selectCourseTeacherList.Where(w => w.SelectCourseID == x.SelectCourseID);
  52. x.TeacherNames = string.Join(",", teacherList.Select(w => w.Name));
  53. x.TeacherIDs = string.Join(",", teacherList.Select(w => w.UserID.ToString()));
  54. });
  55. var ExecutableFreeSelectionCouseIDList = selectCourseResultList.rows.Where(x => x.SelectCourseTypeID == (int)EM_SelectCourseType.FreeSelectionCouse).Select(x => x.ID).ToList();
  56. if (ExecutableFreeSelectionCouseIDList.Count > 0)
  57. {
  58. var ExecutableFreeSelectionCouseSchedulingList = SelectCourseResultDAL.GetScheduling(ExecutableFreeSelectionCouseIDList).ToList();
  59. var newList = GetWeekdayTimesSegmentName(ExecutableFreeSelectionCouseSchedulingList);
  60. selectCourseResultList.rows.ForEach(x =>
  61. {
  62. var list = newList.Where(w => w.ID == x.ID);
  63. x.WeekdayTimesSegmentName = string.Join(";", list.OrderBy(w => w.Weekday).Select(w => w.WeekdayTimesSegmentName));
  64. });
  65. }
  66. return selectCourseResultList;
  67. }
  68. /// <summary>
  69. /// 上课时间,将星期和节次合并
  70. /// </summary>
  71. /// <param name="SourceList">上课时间数据</param>
  72. /// <returns></returns>
  73. public List<ExecutableFreeSelectionCouseSchedulingView> GetWeekdayTimesSegmentName(List<ExecutableFreeSelectionCouseSchedulingView> SourceList)
  74. {
  75. List<ExecutableFreeSelectionCouseSchedulingView> newList = new List<ExecutableFreeSelectionCouseSchedulingView>();
  76. var idList = SourceList.Select(x => x.ID).Distinct().ToList();
  77. foreach (var id in idList)
  78. { //循环处理每个任选课的上课时间
  79. var list = SourceList.Where(x => x.ID == id).ToList();
  80. var weekdayList = list.Select(x => x.Weekday).Distinct().ToList();
  81. foreach (var weekday in weekdayList)
  82. { //先循环同一星期日期
  83. var tmpList = list.Where(x => x.Weekday == weekday).OrderBy(x => x.StartTimes).ToList();
  84. string WeekdayTimesSegmentName = tmpList.FirstOrDefault().WeekdayName + tmpList.FirstOrDefault().StartTimes;
  85. var array = tmpList.Select(x => new { x.StartTimes, x.EndTimes }).ToArray();
  86. for (int i = 0; i < array.Length; i++)
  87. { //将同一天的节次合并,相邻的节次用“-”将最开始节次和最后节次合并,例:1/2/3合并成“1-3”,
  88. //如果不是相邻的先用逗号隔开,再用“-”合并,例:1/2/3和5/6,合并成“1-3,5-6”
  89. if (i > 0 && (array[i].StartTimes > array[i - 1].EndTimes + 1))
  90. { //不相邻的先用逗号隔开,再用“-”合并
  91. WeekdayTimesSegmentName += "-" + array[i - 1].EndTimes + "节," + array[i].StartTimes;
  92. }
  93. if (i + 1 == array.Length)
  94. WeekdayTimesSegmentName += "-" + array[i].EndTimes + "节";
  95. }
  96. newList.Add(new ExecutableFreeSelectionCouseSchedulingView { ID = tmpList.FirstOrDefault().ID, WeekdayTimesSegmentName = WeekdayTimesSegmentName.Replace("星期", ""), Weekday = tmpList.FirstOrDefault().Weekday });
  97. }
  98. }
  99. return newList;
  100. }
  101. public StudentSelectCourseSummaryView GetStudentSelectCourseSummaryView(Guid userID)
  102. {
  103. StudentSelectCourseSummaryView result;
  104. var currentSchoolyearID = this.SelectCourseResultDAL.GetSelectCourseSchoolyear();
  105. //所有在校状态
  106. var inschoolStatusList = inSchoolSettingRepository.GetList(x => x.IsSelected == true).Select(x => x.InSchoolStatusID).ToList();
  107. result = new StudentSelectCourseSummaryView(this.SelectCourseResultDAL.GetStudentSelectCourseBaseView(userID));
  108. if (inschoolStatusList.Contains(result.InSchoolStatusID))
  109. result.isInSchool = true;
  110. else
  111. result.isInSchool = false;
  112. var typeSetting = TypeSettingDAL.GetTypeSettingView(x => x.SchoolyearID == currentSchoolyearID, (x => true));
  113. var openControlSetting = OpenControlSettingDAL.GetOpenControlSettingView(x => x.SchoolyearID == currentSchoolyearID, (x => true),
  114. (x => x.GrademajorID == result.GrademajorID)).FirstOrDefault();
  115. var opionalSetting = typeSetting.FirstOrDefault(x => x.SelectCourseTypeID == (int)EM_SelectCourseType.OptionalCourse);
  116. var freeSelectionCourseSetting = typeSetting.FirstOrDefault(x => x.SelectCourseTypeID == (int)EM_SelectCourseType.FreeSelectionCouse);
  117. //任选控制
  118. var freeSelectionCourseGradeYearSetting = SelectCourseResultDAL.FreeSelectionCourseGradeYearSettingRepository.GetSingle(x =>
  119. x.SchoolyearID == currentSchoolyearID && x.GradeYear == result.GrademajorYear);
  120. result.OptionalStartTime = (openControlSetting == null) ? (opionalSetting == null ? null : opionalSetting.StartTime) : openControlSetting.StartTime;
  121. result.OptionalEndTime = (openControlSetting == null) ? (opionalSetting == null ? null : opionalSetting.EndTime) : openControlSetting.EndTime;
  122. if (opionalSetting != null)
  123. {
  124. if (opionalSetting.StartTime > result.OptionalStartTime)
  125. {
  126. result.OptionalStartTime = opionalSetting.StartTime;
  127. }
  128. if (opionalSetting.EndTime < result.OptionalEndTime)
  129. {
  130. result.OptionalEndTime = opionalSetting.EndTime;
  131. }
  132. }
  133. result.OptionalMaxSelectCount = (openControlSetting == null) ? ((opionalSetting == null) ? 0 : opionalSetting.MaxSelectCount) : openControlSetting.MaxSelectCount;
  134. result.OptionalMinSelectCount = (openControlSetting == null) ? ((opionalSetting == null) ? 0 : opionalSetting.MinSelectCount) : openControlSetting.MinSelectCount;
  135. result.OptionalMaxCredit = (openControlSetting == null) ? ((opionalSetting == null) ? null : opionalSetting.MaxCredit) : openControlSetting.MaxCredit;
  136. result.OptionalMinCredit = (openControlSetting == null) ? ((opionalSetting == null) ? null : opionalSetting.MinCredit) : openControlSetting.MinCredit;
  137. result.FreeSelectCourseStartTime = (freeSelectionCourseGradeYearSetting == null) ? (freeSelectionCourseSetting == null ? null : freeSelectionCourseSetting.StartTime) : freeSelectionCourseGradeYearSetting.StartTime;
  138. result.FreeSelectCourseEndTime = (freeSelectionCourseGradeYearSetting == null) ? (freeSelectionCourseSetting == null ? null : freeSelectionCourseSetting.EndTime) : freeSelectionCourseGradeYearSetting.EndTime;
  139. if (freeSelectionCourseSetting != null)
  140. {
  141. if (freeSelectionCourseSetting.StartTime > result.FreeSelectCourseStartTime)
  142. {
  143. result.FreeSelectCourseStartTime = freeSelectionCourseSetting.StartTime;
  144. }
  145. if (freeSelectionCourseSetting.EndTime < result.OptionalEndTime)
  146. {
  147. result.FreeSelectCourseEndTime = freeSelectionCourseSetting.EndTime;
  148. }
  149. }
  150. result.FreeSelectCourseMaxSelectCount = (freeSelectionCourseGradeYearSetting == null) ? ((freeSelectionCourseSetting == null) ? null : freeSelectionCourseSetting.MaxSelectCount) : freeSelectionCourseGradeYearSetting.MaxSelectCount;
  151. result.FreeSelectCourseMinSelectCount = (freeSelectionCourseGradeYearSetting == null) ? ((freeSelectionCourseSetting == null) ? null : freeSelectionCourseSetting.MinSelectCount) : freeSelectionCourseGradeYearSetting.MinSelectCount;
  152. result.FreeSelectCourseMaxCredit = (freeSelectionCourseGradeYearSetting == null) ? ((freeSelectionCourseSetting == null) ? null : freeSelectionCourseSetting.MaxCredit) : freeSelectionCourseGradeYearSetting.MaxCredit;
  153. result.FreeSelectCourseMinCredit = (freeSelectionCourseGradeYearSetting == null) ? ((freeSelectionCourseSetting == null) ? null : freeSelectionCourseSetting.MinCredit) : freeSelectionCourseGradeYearSetting.MinCredit;
  154. //限选控制
  155. result.GrademajorStartTime = (openControlSetting == null) ? null : openControlSetting.StartTime;
  156. result.GrademajorEndTime = (openControlSetting == null) ? null : openControlSetting.EndTime;
  157. result.GrademajorMaxSelectCount = (openControlSetting == null) ? null : openControlSetting.MaxSelectCount;
  158. result.GrademajorMinSelectCount = (openControlSetting == null) ? null : openControlSetting.MinSelectCount;
  159. result.GrademajorMaxCredit = (openControlSetting == null) ? null : openControlSetting.MaxCredit;
  160. result.GrademajorMinCredit = (openControlSetting == null) ? null : openControlSetting.MinCredit;
  161. //任选控制
  162. result.GradeYearStartTime = (freeSelectionCourseGradeYearSetting == null) ? null : freeSelectionCourseGradeYearSetting.StartTime;
  163. result.GradeYearEndTime = (freeSelectionCourseGradeYearSetting == null) ? null : freeSelectionCourseGradeYearSetting.EndTime;
  164. result.GradeYearMaxSelectCount = (freeSelectionCourseGradeYearSetting == null) ? null : freeSelectionCourseGradeYearSetting.MaxSelectCount;
  165. result.GradeYearMinSelectCount = (freeSelectionCourseGradeYearSetting == null) ? null : freeSelectionCourseGradeYearSetting.MinSelectCount;
  166. result.GradeYearMaxCredit = (freeSelectionCourseGradeYearSetting == null) ? null : freeSelectionCourseGradeYearSetting.MaxCredit;
  167. result.GradeYearMinCredit = (freeSelectionCourseGradeYearSetting == null) ? null : freeSelectionCourseGradeYearSetting.MinCredit;
  168. return result;
  169. }
  170. /// <summary>
  171. /// 学生选修课程页面
  172. /// </summary>
  173. /// <param name="configuretView"></param>
  174. /// <param name="schoolYearID"></param>
  175. /// <param name="collegeID"></param>
  176. /// <param name="courseID"></param>
  177. /// <param name="courseTypeID"></param>
  178. /// <param name="selectCourseTypeID"></param>
  179. /// <param name="pageIndex"></param>
  180. /// <param name="pageSize"></param>
  181. /// <returns></returns>
  182. public IGridResultSet<StudentSelectCourseView> GetSelectedCourseViewList
  183. (ConfiguretView configuretView, Guid? schoolYearID, Guid? collegeID,
  184. Guid? courseID, int? courseTypeID, int? selectCourseTypeID, int pageIndex, int pageSize)
  185. {
  186. Expression<Func<EM_ExecutableOptionalCourse, bool>> eocExp = (x => true && x.CF_Student.Any(w => w.UserID == EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID));
  187. Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> efcExp = (x => true && x.CF_Student.Any(w => w.UserID == EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID));
  188. var query = SelectCourseResultDAL.GetStudentSelectedCourseResultView(eocExp, efcExp);
  189. var query1 = SelectCourseResultDAL.GetSelectCourseResultTeacher(eocExp, efcExp);
  190. var query2 = SelectCourseResultDAL.GetSelectCourseResultTeachingMode(eocExp, efcExp);
  191. //if (schoolYearID.HasValue)
  192. //{
  193. // query = query.Where(x => x.SchoolyearID == schoolYearID);
  194. // query1 = query1.Where(x => x.SchoolyearID == schoolYearID);
  195. //}
  196. //if (collegeID.HasValue)
  197. //{
  198. // query = query.Where(x => x.CollegeID == collegeID);
  199. //}
  200. //if (courseID.HasValue)
  201. //{
  202. // query = query.Where(x => x.CoursematerialID == courseID);
  203. //}
  204. //if (courseTypeID.HasValue)
  205. //{
  206. // query = query.Where(x => x.CourseTypeID == courseTypeID);
  207. // query1 = query1.Where(x => x.CourseTypeID == courseTypeID);
  208. //}
  209. //if (selectCourseTypeID.HasValue)
  210. //{
  211. // query = query.Where(x => x.SelectCourseType == selectCourseTypeID);
  212. // query1 = query1.Where(x => x.SelectCourseType == selectCourseTypeID);
  213. //}
  214. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  215. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  216. var result = query.OrderBy(x => x.SchoolYearCode).ThenBy(x => x.SelectCourseTypeID).ThenBy(x => x.CourseName).ToGridResultSet<StudentSelectCourseView>(null, null);
  217. var teacher = query1.ToList();
  218. var teachingMode = query2.ToList().OrderBy(x => x.SchoolYearCode).ThenBy(x => x.SelectCourseType).ThenBy(x => x.CourseName);
  219. result.rows.ForEach(x => x.TeacherNames = string.Join(",", teacher.Where(w => w.ID == x.ID).Select(w => w.TeacherName)));
  220. var ExecutableFreeSelectionCouseIDList = result.rows.Where(x => x.SelectCourseTypeID == (int)EM_SelectCourseType.FreeSelectionCouse).Select(x => x.ID).ToList();
  221. if (ExecutableFreeSelectionCouseIDList.Count > 0)
  222. {
  223. var ExecutableFreeSelectionCouseSchedulingList = SelectCourseResultDAL.GetScheduling(ExecutableFreeSelectionCouseIDList).ToList();
  224. var newList = GetWeekdayTimesSegmentName(ExecutableFreeSelectionCouseSchedulingList);
  225. result.rows.ForEach(x =>
  226. {
  227. var list = newList.Where(w => w.ID == x.ID);
  228. x.WeekdayTimesSegmentName = string.Join(";", list.OrderBy(w => w.Weekday).Select(w => w.WeekdayTimesSegmentName));
  229. });
  230. }
  231. return result;
  232. }
  233. public IGridResultSet<StudentSelectCourseView> GetCanceledCourseViewList
  234. (ConfiguretView configuretView, int pageIndex, int pageSize)
  235. {
  236. var userid = EMIS.Utility.FormValidate.CustomPrincipal.Current.UserID;
  237. Expression<Func<EM_ExecutableOptionalCourse, bool>> eocExp = (x => true && x.CF_Student.Any(w => w.UserID == userid
  238. && x.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate));
  239. Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> efcExp = (x => true && x.CF_Student.Any(w => w.UserID == userid
  240. && x.RecordStatus == (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate));
  241. var query = SelectCourseResultDAL.GetStudentSelectedCourseResultView(eocExp, efcExp);
  242. var query1 = SelectCourseResultDAL.GetSelectCourseResultTeacher(eocExp, efcExp);
  243. var query2 = SelectCourseResultDAL.GetSelectCourseResultTeachingMode(eocExp, efcExp);
  244. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  245. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  246. var result = query.OrderBy(x => x.SelectCourseTypeID).ToGridResultSet<StudentSelectCourseView>(null, null);
  247. var teacher = query1.ToList();
  248. var teachingMode = query2.ToList().OrderBy(x => x.SelectCourseType);
  249. result.rows.ForEach(x => x.TeacherNames = string.Join(",", teacher.Where(w => w.ID == x.ID).Select(w => w.TeacherName)));
  250. return result;
  251. }
  252. public void SelectCourse(Guid userID, Guid? grademajorID, Guid coursematerialID, int selectCourseTypeID, string teacherIDs, Guid ID)
  253. {
  254. //var teacherIDList = teacherIDs.Split(',')
  255. // .Where(x => !string.IsNullOrEmpty(x))
  256. // .Select(x => (Guid?)new Guid(x)).ToList();
  257. var isPeopleNumLimit = ParameterServices.Value.GetParameterValue<bool>(CF_ParameterType.SelectCourseNoLimit);
  258. var student = this.StudentsDAL.StudentRepository.GetSingle(x => x.UserID == userID, x => x.CF_Classmajor.CF_Grademajor);
  259. var studentSelectCourseSummary = this.GetStudentSelectCourseSummaryView(userID);
  260. var currentSchoolyearID = this.SelectCourseResultDAL.GetSelectCourseSchoolyear();
  261. var ExecutableFreeSelectionCouse = SelectCourseResultDAL.ExecutableFreeSelectionCouseRepository.GetList(x => x.SchoolyearID == currentSchoolyearID
  262. && x.EM_FreeSelectionCouse.CoursematerialID == coursematerialID
  263. && x.CF_Student.Any(w => w.UserID == userID)).FirstOrDefault();
  264. var ExecutableOptionalCourse = SelectCourseResultDAL.ExecutableOptionalCourseRepository.GetList(x => x.SchoolyearID == currentSchoolyearID
  265. && x.EM_OptionalCoursePlan.CoursematerialID == coursematerialID
  266. && x.CF_Student.Any(w => w.UserID == userID)).FirstOrDefault();
  267. if (ExecutableFreeSelectionCouse != null || ExecutableOptionalCourse != null)
  268. {
  269. throw new Exception("您已报名此门课程的选修,请勿重复报名!");
  270. }
  271. var score = SelectCourseResultDAL.FinallyScoreRepository.GetSingle(x => x.UserID == userID && x.CoursematerialID == coursematerialID);
  272. if (score != null)
  273. {
  274. throw new Exception("您已修过此门课程,并且有考试成绩,请勿重复报名!");
  275. }
  276. //限选
  277. if (selectCourseTypeID == (int)EM_SelectCourseType.OptionalCourse)
  278. {
  279. if (studentSelectCourseSummary.OptionalStartTime > DateTime.Now
  280. || studentSelectCourseSummary.GrademajorStartTime > DateTime.Now)
  281. {
  282. throw new Exception("该课程还未开始选课,不能选课。");
  283. }
  284. if (studentSelectCourseSummary.OptionalEndTime < DateTime.Now
  285. || studentSelectCourseSummary.GrademajorEndTime < DateTime.Now)
  286. {
  287. throw new Exception("该课程已过选课时间,不能选课。");
  288. }
  289. if ((studentSelectCourseSummary.OptionalMaxSelectCount ?? 0) != 0
  290. && (studentSelectCourseSummary.OptionalTotalSelectCount + 1) > studentSelectCourseSummary.OptionalMaxSelectCount)
  291. {
  292. throw new Exception("选课超出了限选课门数上限,不能选课。");
  293. }
  294. using (TransactionScope ts = new TransactionScope())
  295. {
  296. var optionalCourse = this.SelectCourseResultDAL.ExecutableOptionalCourseRepository.GetList(x =>
  297. x.ExecutableOptionalCourseID == ID,
  298. x => x.CF_Student,
  299. x => x.EM_ExecutableOptionalCourseTeachingSetting//,
  300. //x => x.EM_EducationMissionClass
  301. ).FirstOrDefault();
  302. if ((studentSelectCourseSummary.OptionalMaxCredit ?? 0) != 0
  303. && (studentSelectCourseSummary.OptionalTotalCredit + optionalCourse.EM_ExecutableOptionalCourseTeachingSetting.Credit ?? 0)
  304. > studentSelectCourseSummary.OptionalMaxCredit)
  305. {
  306. throw new Exception("选课超出了限选课学分上限,不能选课。");
  307. }
  308. if ((studentSelectCourseSummary.GrademajorMaxSelectCount ?? 0) != 0
  309. && (studentSelectCourseSummary.OptionalTotalSelectCount + 1) > studentSelectCourseSummary.GrademajorMaxSelectCount)
  310. {
  311. throw new Exception("选课超出了该限选控制" + student.CF_Classmajor.CF_Grademajor.SemesterID + "级门数上限,不能选课。");
  312. }
  313. if ((studentSelectCourseSummary.GrademajorMaxCredit ?? 0) != 0
  314. && (studentSelectCourseSummary.OptionalTotalCredit + optionalCourse.EM_ExecutableOptionalCourseTeachingSetting.Credit ?? 0)
  315. > studentSelectCourseSummary.GrademajorMaxCredit)
  316. {
  317. throw new Exception("选课超出了该限选控制" + student.CF_Classmajor.CF_Grademajor.SemesterID + "级学分上限,不能选课。");
  318. }
  319. if (optionalCourse != null)
  320. {
  321. //if (optionalCourse.EM_EducationMissionClass.Count > 0)
  322. //{
  323. // throw new Exception("该课程已经结束选课,并开始进行教学安排,不能选课。");
  324. //}
  325. if (isPeopleNumLimit == true && (optionalCourse.PeopleNumlimit ?? 0) != 0 && (optionalCourse.PeopleNumlimit ?? 0) < (optionalCourse.CF_Student.Count + 1))
  326. {
  327. throw new Exception("该课程选课人数已达上限,不能选课。");
  328. }
  329. if (!optionalCourse.CF_Student.Any(x => x.UserID == userID))
  330. {
  331. optionalCourse.CF_Student.Add(student);
  332. }
  333. }
  334. else
  335. {
  336. throw new Exception("找不到对应的限选课程。");
  337. }
  338. this.UnitOfWork.Commit();
  339. ts.Complete();
  340. }
  341. }
  342. //任选
  343. else if (selectCourseTypeID == (int)EM_SelectCourseType.FreeSelectionCouse)
  344. {
  345. if (studentSelectCourseSummary.FreeSelectCourseStartTime > DateTime.Now
  346. || studentSelectCourseSummary.GradeYearStartTime > DateTime.Now)
  347. {
  348. throw new Exception("该课程还未开始选课,不能选课。");
  349. }
  350. if (studentSelectCourseSummary.FreeSelectCourseEndTime < DateTime.Now
  351. || studentSelectCourseSummary.GradeYearEndTime < DateTime.Now)
  352. {
  353. throw new Exception("该课程已过选课时间,不能选课。");
  354. }
  355. //上课时间
  356. var schedulingList = SelectCourseResultDAL.GetSchedulingTime(ID).ToList();
  357. foreach (var scheduling in schedulingList)
  358. {
  359. var repeat = SelectCourseResultDAL.GetRepeatTime(userID, ID, scheduling.CoursesTimeID, scheduling.Weekday, scheduling.SchoolyearID, scheduling.StartWeeklyNum, scheduling.EndWeeklyNum).FirstOrDefault();
  360. if (repeat != null)
  361. {
  362. throw new Exception("此门课程的上课时间,与其它已报名选修有冲突!");
  363. }
  364. }
  365. if ((studentSelectCourseSummary.FreeSelectCourseMaxSelectCount ?? 0) != 0
  366. && (studentSelectCourseSummary.FreeSelectCourseTotalSelectCount + 1) > studentSelectCourseSummary.FreeSelectCourseMaxSelectCount)
  367. {
  368. throw new Exception("选课超出了任选课门数上限,不能选课。");
  369. }
  370. if ((studentSelectCourseSummary.GradeYearMaxSelectCount ?? 0) != 0
  371. && (studentSelectCourseSummary.FreeSelectCourseTotalSelectCount + 1) > studentSelectCourseSummary.GradeYearMaxSelectCount)
  372. {
  373. throw new Exception("选课超出了该任选控制" + student.CF_Classmajor.CF_Grademajor.GradeID + "级门数上限,不能选课。");
  374. }
  375. using (TransactionScope ts = new TransactionScope())
  376. {
  377. var freeSelectionCourse = this.SelectCourseResultDAL.ExecutableFreeSelectionCouseRepository.GetList(x =>
  378. x.ExecutableFreeSelectionCouseID == ID,
  379. x => x.CF_Student,
  380. x => x.EM_ExecutableFreeSelectionCouseTeachingSetting//,
  381. //x => x.EM_EducationMissionClass
  382. ).FirstOrDefault();
  383. if (freeSelectionCourse == null)
  384. throw new Exception("找不到对应的任选课程。");
  385. if ((studentSelectCourseSummary.FreeSelectCourseMaxCredit ?? 0) != 0
  386. && (studentSelectCourseSummary.FreeSelectCourseTotalCredit + freeSelectionCourse.EM_ExecutableFreeSelectionCouseTeachingSetting.Credit ?? 0)
  387. > studentSelectCourseSummary.FreeSelectCourseMaxCredit)
  388. {
  389. throw new Exception("选课超出了任选课学分上限,不能选课。");
  390. }
  391. if ((studentSelectCourseSummary.GradeYearMaxCredit ?? 0) != 0
  392. && (studentSelectCourseSummary.FreeSelectCourseTotalCredit + freeSelectionCourse.EM_ExecutableFreeSelectionCouseTeachingSetting.Credit ?? 0)
  393. > studentSelectCourseSummary.GradeYearMaxCredit)
  394. {
  395. throw new Exception("选课超出了该任选控制" + student.CF_Classmajor.CF_Grademajor.GradeID + "级学分上限,不能选课。");
  396. }
  397. //if (freeSelectionCourse.EM_EducationMissionClass.Count > 0)
  398. //{
  399. // throw new Exception("该课程已经结束选课,并开始进行教学安排,不能选课。");
  400. //}
  401. if (isPeopleNumLimit == true && (freeSelectionCourse.PeopleNumlimit ?? 0) != 0 && (freeSelectionCourse.PeopleNumlimit ?? 0) < (freeSelectionCourse.CF_Student.Count + 1))
  402. {
  403. throw new Exception("该课程选课人数已达上限,不能选课。");
  404. }
  405. //上面的判断不知道有什么用暂时放着
  406. if (freeSelectionCourse.PeopleNumlimit != null && (freeSelectionCourse.PeopleNumlimit < (freeSelectionCourse.CF_Student.Count + 1)))
  407. {
  408. throw new Exception("该课程选课人数已达上限,不能选课。");
  409. }
  410. if (!freeSelectionCourse.CF_Student.Any(x => x.UserID == userID))
  411. {
  412. freeSelectionCourse.CF_Student.Add(student);
  413. }
  414. this.UnitOfWork.Commit();
  415. ts.Complete();
  416. }
  417. }
  418. }
  419. public void CancelSelectCourse(Guid userID, Guid? grademajorID, Guid coursematerialID, int selectCourseTypeID, string teacherIDs, Guid ID)
  420. {
  421. var teacherIDList = teacherIDs.Split(',')
  422. .Where(x => !string.IsNullOrEmpty(x))
  423. .Select(x => (Guid?)new Guid(x)).ToList();
  424. var student = this.StudentsDAL.StudentRepository.GetSingle(x => x.UserID == userID);
  425. var studentSelectCourseSummary = this.GetStudentSelectCourseSummaryView(userID);
  426. if (selectCourseTypeID == (int)EM_SelectCourseType.OptionalCourse)
  427. {
  428. if (studentSelectCourseSummary.OptionalStartTime > DateTime.Now
  429. || studentSelectCourseSummary.GrademajorStartTime > DateTime.Now)
  430. {
  431. throw new Exception("该课程还未开始选课,不能取消选课。");
  432. }
  433. if (studentSelectCourseSummary.OptionalEndTime < DateTime.Now
  434. || studentSelectCourseSummary.GrademajorEndTime < DateTime.Now)
  435. {
  436. throw new Exception("该课程已过选课时间,不能取消选课。");
  437. }
  438. //var optionalCourse = this.SelectCourseResultDAL.GetCurrentExecutableOptionalCourse(student.ClassmajorID, grademajorID, coursematerialID, teacherIDList)
  439. // .FirstOrDefault();
  440. var optionalCourse = this.SelectCourseResultDAL.ExecutableOptionalCourseRepository.GetList(x =>
  441. x.ExecutableOptionalCourseID == ID,
  442. x => x.CF_Student,
  443. x => x.EM_ExecutableOptionalCourseTeachingSetting).FirstOrDefault();
  444. if (optionalCourse != null)
  445. {
  446. if (optionalCourse.RecordStatus == (int)EM_SelectCourseResultStatus.Created)
  447. {
  448. throw new Exception("该课程已经结束选课,并开始进行教学安排,不能取消选课。");
  449. }
  450. optionalCourse.CF_Student.RemoveWhere(x => x.UserID == userID);
  451. }
  452. else
  453. {
  454. throw new Exception("找不到对应的限选课程。");
  455. }
  456. }
  457. else if (selectCourseTypeID == (int)EM_SelectCourseType.FreeSelectionCouse)
  458. {
  459. if (studentSelectCourseSummary.FreeSelectCourseStartTime > DateTime.Now
  460. || studentSelectCourseSummary.GradeYearStartTime > DateTime.Now)
  461. {
  462. throw new Exception("该课程还未开始选课,不能取消选课。");
  463. }
  464. if (studentSelectCourseSummary.FreeSelectCourseEndTime < DateTime.Now
  465. || studentSelectCourseSummary.GradeYearEndTime < DateTime.Now)
  466. {
  467. throw new Exception("该课程已过选课时间,不能取消选课。");
  468. }
  469. //var freeSelectionCourse = this.SelectCourseResultDAL.GetCurrentExecutableFreeSelectionCourse(coursematerialID, teacherIDList)
  470. // .FirstOrDefault();
  471. var freeSelectionCourse = this.SelectCourseResultDAL.ExecutableFreeSelectionCouseRepository.GetList(x =>
  472. x.ExecutableFreeSelectionCouseID == ID,
  473. x => x.CF_Student,
  474. x => x.EM_ExecutableFreeSelectionCouseTeachingSetting).FirstOrDefault();
  475. if (freeSelectionCourse != null)
  476. {
  477. if (freeSelectionCourse.RecordStatus == (int)EM_SelectCourseResultStatus.Created)
  478. {
  479. throw new Exception("该课程已经结束选课,并开始进行教学安排,不能取消选课。");
  480. }
  481. freeSelectionCourse.CF_Student.RemoveWhere(x => x.UserID == userID);
  482. }
  483. else
  484. {
  485. throw new Exception("找不到对应的任选课程。");
  486. }
  487. }
  488. this.UnitOfWork.Commit();
  489. }
  490. }
  491. }