FreeSelectionCourseApplyServices.cs 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using System.Data.Entity;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.ViewModel.SelectCourse;
  10. using EMIS.ViewModel;
  11. using EMIS.Entities;
  12. using EMIS.DataLogic.SelectCourse;
  13. using EMIS.DataLogic.Repositories;
  14. using EMIS.CommonLogic.SystemServices;
  15. using EMIS.Utility.FormValidate;
  16. using EMIS.ViewModel.EnrollManage.SpecialtyManage;
  17. using System.Transactions;
  18. namespace EMIS.CommonLogic.SelectCourse
  19. {
  20. public class FreeSelectionCourseApplyServices : BaseWorkflowServices<EM_FreeSelectionCouseApply>, IFreeSelectionCourseApplyServices
  21. {
  22. public ExecutableFreeSelectionCouseDAL ExecutableFreeSelectionCouseDAL { get; set; }
  23. public FreeSelectionCoursePlanDAL FreeSelectionCoursePlanDAL { get; set; }
  24. public FreeSelectionCourseDAL FreeSelectionCourseDAL { get; set; }
  25. public IStudentSelectCourseServices IStudentSelectCourseServices { get; set; }
  26. public FreeSelectionCouseTeachingModeRepository FreeSelectionCouseTeachingModeRepository { get; set; }
  27. public StaffRepository staffRepository { get; set; }
  28. public UserRepository userRepository { get; set; }
  29. private IGridResultSet<FreeSelectionCourseApplyView> GetFreeSelectionCourseApplyView(ConfiguretView configuretView,
  30. Expression<Func<EM_FreeSelectionCouseApply, bool>> exp, int? pageIndex = null, int? pageSize = null, bool? isApproveView = false)
  31. {
  32. var freeSelectionCourseView = FreeSelectionCoursePlanDAL.GetFreeSelectionCourseApplyViewQueryable(exp);
  33. var teacherView = FreeSelectionCoursePlanDAL.GetFreeSelectionCourseApplyTeacherViewQueryable(exp);
  34. var schedulingView = FreeSelectionCoursePlanDAL.GetScheduling(exp).ToList();
  35. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  36. {
  37. freeSelectionCourseView = freeSelectionCourseView.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  38. }
  39. freeSelectionCourseView = this.GetQueryByDataRangeByCollege(freeSelectionCourseView);
  40. IGridResultSet<FreeSelectionCourseApplyView> result;
  41. IList<FreeSelectionCourseApplyTeacherListView> teacherViewList;
  42. if (pageIndex.HasValue && pageSize.HasValue)
  43. {
  44. if (isApproveView == true)
  45. {
  46. result = this.QueryByPendingJob(freeSelectionCourseView, CustomPrincipal.Current.UserID,
  47. (x => x.FreeSelectionCouseApplyID), (x => x.CreateTime), true, pageIndex, pageSize);
  48. }
  49. else
  50. {
  51. result = freeSelectionCourseView.OrderByDescending(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize);
  52. }
  53. //由于分页后数据量较少,可以考虑用Contains方法在数据库端筛选一下,不分页的情况就不要了
  54. var freeSelectionCourseIDList = result.rows.Select(x => x.FreeSelectionCouseApplyID).ToList();
  55. teacherViewList = teacherView.Where(x => freeSelectionCourseIDList.Contains(x.FreeSelectionCourseApplyID)).ToList();
  56. }
  57. else
  58. {
  59. var list = freeSelectionCourseView.ToList();
  60. if (isApproveView == true)
  61. {
  62. result = this.QueryByPendingJob(freeSelectionCourseView, CustomPrincipal.Current.UserID,
  63. (x => x.FreeSelectionCouseApplyID), (x => x.CreateTime), true);
  64. }
  65. else
  66. {
  67. result = new GridResultSet<FreeSelectionCourseApplyView>() { rows = list, total = list.Count };
  68. }
  69. teacherViewList = teacherView.ToList();
  70. }
  71. var statusViewList = this.GetStatusViewList();
  72. result.rows.ForEach(x =>
  73. {
  74. x.Teachers = new HashSet<FreeSelectionCourseApplyTeacherListView>(teacherViewList
  75. .Where(w => x.FreeSelectionCouseApplyID == w.FreeSelectionCourseApplyID));
  76. x.ApprovalStatusName = statusViewList.Where(w => w.ID == x.ApprovalStatus)
  77. .Select(w => w.Name).FirstOrDefault();
  78. });
  79. if (schedulingView.Count > 0)
  80. {
  81. var schedulingList = IStudentSelectCourseServices.GetWeekdayTimesSegmentName(schedulingView);
  82. result.rows.ForEach(x =>
  83. {
  84. var list = schedulingList.Where(w => w.ID == x.FreeSelectionCouseApplyID);
  85. x.WeekdayTimesSegmentName = string.Join(";", list.OrderBy(w => w.Weekday).Select(w => w.WeekdayTimesSegmentName));
  86. });
  87. }
  88. return result;
  89. }
  90. public EM_FreeSelectionCouse GetFreeSelectionCourse(Guid? freeSelectionCourseID)
  91. {
  92. System.Linq.Expressions.Expression<Func<EM_FreeSelectionCouse, bool>> expression =
  93. (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  94. expression = (x => x.FreeSelectionCouseID == freeSelectionCourseID);
  95. return FreeSelectionCourseDAL.FreeSelectionCouseRepository.GetSingle(expression, (x => x.CF_Department), (x => x.EM_Coursematerial));
  96. }
  97. public FreeSelectionCourseView GetFreeSelectionCourseView(Guid? freeSelectionCourseID)
  98. {
  99. var query = FreeSelectionCourseDAL.GetFreeSelectionCourseViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  100. return query.Where(x => x.FreeSelectionCouseID == freeSelectionCourseID).FirstOrDefault();
  101. }
  102. public EM_FreeSelectionCouseTeachingSetting GetFreeSelectionCourseTeachingSetting(Guid? freeSelectionCourseID)
  103. {
  104. //查询条件
  105. System.Linq.Expressions.Expression<Func<EM_FreeSelectionCouseTeachingSetting, bool>> expression = (x => true);
  106. expression = (x => x.FreeSelectionCouseID == freeSelectionCourseID);
  107. return FreeSelectionCourseDAL.FreeSelectionCouseTeachingSettingRepository.GetSingle(expression);
  108. }
  109. private bool TeachingModeTypeAdd(List<int> list, Guid? freeSelectionCourseApplyID)
  110. {
  111. try
  112. {
  113. if (list.Count > 0)
  114. {
  115. UnitOfWork.Delete<EM_FreeSelectionCouseApplyTeachingMode>(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyID);
  116. foreach (var i in list)
  117. {
  118. EM_FreeSelectionCouseApplyTeachingMode teachingModeType = new EM_FreeSelectionCouseApplyTeachingMode();
  119. teachingModeType.FreeSelectionCouseApplyTeachingModeID = Guid.NewGuid();
  120. teachingModeType.FreeSelectionCouseApplyID = freeSelectionCourseApplyID;
  121. teachingModeType.TeachingModeID = i;
  122. this.SetNewStatus(teachingModeType);
  123. UnitOfWork.Add(teachingModeType);
  124. }
  125. }
  126. return true;
  127. }
  128. catch (Exception)
  129. {
  130. throw;
  131. }
  132. }
  133. /// <summary>
  134. /// 根据任选开课获取授课方式
  135. /// </summary>
  136. /// <param name="freeSelectionCourseApplyID"></param>
  137. /// <returns></returns>
  138. public List<int> GetCourseApplyTeachingModeType(Guid? FreeSelectionCouseApplyID)
  139. {
  140. var list = FreeSelectionCoursePlanDAL.GetTeachingModeType(x => x.FreeSelectionCouseApplyID == FreeSelectionCouseApplyID)
  141. .Select(x => x.Value ?? 0).ToList();
  142. if (list.Count > 0)
  143. list.Add((int)EMIS.ViewModel.CF_TeachingMode.Theory);
  144. return list;
  145. }
  146. /// <summary>
  147. /// 根据任选开课获取授课方式
  148. /// </summary>
  149. /// <param name="freeSelectionCourseApplyID"></param>
  150. /// <returns></returns>
  151. public List<int> GetCourseApplyGradeYear(Guid? FreeSelectionCouseApplyID)
  152. {
  153. List<int> list = new List<int>();
  154. return FreeSelectionCoursePlanDAL.GetGradeYear(x => x.FreeSelectionCouseApplyID == FreeSelectionCouseApplyID)
  155. .Select(x => x.Value ?? 0).ToList();
  156. }
  157. public EM_FreeSelectionCouse GetFreeSelectionCourseCourse(Guid? coursematerialID)
  158. {
  159. //查询条件
  160. System.Linq.Expressions.Expression<Func<EM_FreeSelectionCouse, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  161. expression = (x => x.CoursematerialID == coursematerialID);
  162. return FreeSelectionCourseDAL.FreeSelectionCouseRepository.GetSingle(expression, (x => x.CF_Department), (x => x.EM_Coursematerial));
  163. }
  164. public IGridResultSet<FreeSelectionCourseApplyView> GetFreeSelectionCoursePlanViewGrid(ConfiguretView configuretView,
  165. Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? departmentID, int? approvalStatus, int pageIndex, int pageSize)
  166. {
  167. Expression<Func<EM_FreeSelectionCouseApply, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  168. if (schoolyearID.HasValue)
  169. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  170. if (campusID.HasValue)
  171. exp = exp.And(x => x.CF_Department.CF_College.CampusID == campusID);
  172. if (collegeID.HasValue)
  173. exp = exp.And(x => x.CF_Department.CollegeID == collegeID);
  174. if (departmentID.HasValue)
  175. exp = exp.And(x => x.DepartmentID == departmentID);
  176. if (approvalStatus.HasValue)
  177. exp = exp.And(x => x.ApprovalStatus == approvalStatus);
  178. return this.GetFreeSelectionCourseApplyView(configuretView, exp, pageIndex, pageSize);
  179. }
  180. public List<FreeSelectionCourseApplyView> GetFreeSelectionCoursePlanViewList(ConfiguretView configuretView,
  181. Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? departmentID, int? approvalStatus)
  182. {
  183. Expression<Func<EM_FreeSelectionCouseApply, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  184. if (schoolyearID.HasValue)
  185. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  186. if (campusID.HasValue)
  187. exp = exp.And(x => x.CF_Department.CF_College.CampusID == campusID);
  188. if (collegeID.HasValue)
  189. exp = exp.And(x => x.CF_Department.CollegeID == collegeID);
  190. if (departmentID.HasValue)
  191. exp = exp.And(x => x.DepartmentID == departmentID);
  192. if (approvalStatus.HasValue)
  193. exp = exp.And(x => x.ApprovalStatus == approvalStatus);
  194. return this.GetFreeSelectionCourseApplyView(configuretView, exp).rows;
  195. }
  196. public IGridResultSet<FreeSelectionCourseApplyView> GetFreeSelectionCoursePlanApprovalViewGrid(ConfiguretView configuretView,
  197. Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? departmentID, int? approvalStatus, int pageIndex, int pageSize)
  198. {
  199. List<int?> approveStatusList = this.GetApproveStatusViewList().Where(x => x.Description.Contains("[AP]")).Select(x => x.ID).ToList();
  200. Expression<Func<EM_FreeSelectionCouseApply, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  201. && approveStatusList.Contains(x.ApprovalStatus));
  202. if (schoolyearID.HasValue)
  203. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  204. if (campusID.HasValue)
  205. exp = exp.And(x => x.CF_Department.CF_College.CampusID == campusID);
  206. if (collegeID.HasValue)
  207. exp = exp.And(x => x.CF_Department.CollegeID == collegeID);
  208. if (departmentID.HasValue)
  209. exp = exp.And(x => x.DepartmentID == departmentID);
  210. if (approvalStatus.HasValue)
  211. exp = exp.And(x => x.ApprovalStatus == approvalStatus);
  212. if (approveStatusList.Count > 0)
  213. exp = exp.And(x => approveStatusList.Contains(x.ApprovalStatus));
  214. return this.GetFreeSelectionCourseApplyView(configuretView, exp, pageIndex, pageSize, true);
  215. }
  216. public List<FreeSelectionCourseApplyView> GetFreeSelectionCoursePlanApprovalView(ConfiguretView configuretView,
  217. Guid? schoolyearID, Guid? campusID, Guid? collegeID, Guid? departmentID, int? approvalStatus)
  218. {
  219. List<int?> approveStatusList = this.GetApproveStatusViewList().Where(x => x.Description.Contains("[AP]")).Select(x => x.ID).ToList();
  220. Expression<Func<EM_FreeSelectionCouseApply, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  221. && approveStatusList.Contains(x.ApprovalStatus));
  222. if (schoolyearID.HasValue)
  223. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  224. if (campusID.HasValue)
  225. exp = exp.And(x => x.CF_Department.CF_College.CampusID == campusID);
  226. if (collegeID.HasValue)
  227. exp = exp.And(x => x.CF_Department.CollegeID == collegeID);
  228. if (departmentID.HasValue)
  229. exp = exp.And(x => x.DepartmentID == departmentID);
  230. if (approvalStatus.HasValue)
  231. exp = exp.And(x => x.ApprovalStatus == approvalStatus);
  232. if (approveStatusList.Count > 0)
  233. exp = exp.And(x => approveStatusList.Contains(x.ApprovalStatus));
  234. return this.GetFreeSelectionCourseApplyView(configuretView, exp, null, null, true).rows;
  235. }
  236. public FreeSelectionCourseApplyView GetFreeSelectionCourseApplyView(Guid? freeSelectionCourseApplyID)
  237. {
  238. return FreeSelectionCoursePlanDAL.GetFreeSelectionCourseApplyViewQueryable(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyID)
  239. .FirstOrDefault();
  240. }
  241. public EM_FreeSelectionCouseApply GetFreeSelectionCourseApply(Guid? freeSelectionCourseApplyID)
  242. {
  243. //查询条件
  244. System.Linq.Expressions.Expression<Func<EM_FreeSelectionCouseApply, bool>> expression =
  245. (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  246. expression = (x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyID);
  247. return FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyRepository.GetSingle(expression);
  248. }
  249. /// <summary>
  250. /// 提交申请
  251. /// </summary>
  252. /// <param name="planApplicationIDs">申请ID</param>
  253. /// <param name="userID">提交人</param>
  254. /// <param name="comment">备注</param>
  255. public void Submit(List<Guid> freeSelectionCourseApplyIDs, Guid userID, string comment = "")
  256. {
  257. try
  258. {
  259. var startStatus = this.GetStartStatus();
  260. List<int?> approveStatusList = this.GetApproveStatusViewList().Where(x => x.Description.Contains("[AP]")).Select(x => x.ID).ToList();
  261. var freeSelectionCouseApplyList = FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyRepository.GetList(x => freeSelectionCourseApplyIDs.Contains(x.FreeSelectionCouseApplyID)).ToList();
  262. List<Guid> submitIDList = new List<Guid>();
  263. List<Guid> approveIDList = new List<Guid>();
  264. if (freeSelectionCouseApplyList.Count > 0)
  265. {
  266. for (int i = 0; i < freeSelectionCouseApplyList.Count; i++)
  267. {
  268. if (freeSelectionCouseApplyList[i].ApprovalStatus == startStatus)
  269. {
  270. submitIDList.Add(freeSelectionCouseApplyList[i].FreeSelectionCouseApplyID);
  271. }
  272. else if (approveStatusList.Contains(freeSelectionCouseApplyList[i].ApprovalStatus))
  273. {
  274. throw new Exception("数据已提交申请,不能重复提交");
  275. }
  276. else
  277. {
  278. approveIDList.Add(freeSelectionCouseApplyList[i].FreeSelectionCouseApplyID);
  279. }
  280. }
  281. approveIDList = approveIDList.Where(x => !submitIDList.Contains(x)).ToList();
  282. if (submitIDList.Count > 0)
  283. {
  284. StartUp(submitIDList, userID, "");
  285. }
  286. if (approveIDList.Count > 0)
  287. {
  288. Approve(approveIDList, userID, Guid.Empty, comment);
  289. }
  290. }
  291. }
  292. catch (Exception)
  293. {
  294. throw;
  295. }
  296. }
  297. public void Approved(List<Guid> FreeSelectionCouseApplyIDList, Guid userID)
  298. {
  299. var freeSelectionCourseApplyList = FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyRepository.GetList(x =>
  300. FreeSelectionCouseApplyIDList.Contains(x.FreeSelectionCouseApplyID),
  301. x => x.EM_FreeSelectionCouse,
  302. x => x.EM_FreeSelectionCouseApplyGradeYear,
  303. x => x.EM_FreeSelectionCouseApplyTeachingSetting,
  304. x => x.EM_FreeSelectionCouseApplyTeachingMode,
  305. x => x.EM_FreeSelectionCouseApplyGradeYear,
  306. x => x.EM_FreeSelectionCouseApplySpecialty,
  307. x => x.EM_FreeSelectionCouseApplyScheduling,
  308. x => x.EM_FreeSelectionCouseApplyTeacher).ToList();
  309. foreach (var freeSelectionCourseApply in freeSelectionCourseApplyList)
  310. {
  311. //任选课开课申请表
  312. EM_ExecutableFreeSelectionCouse executableFreeSelectionCouse = new EM_ExecutableFreeSelectionCouse();
  313. executableFreeSelectionCouse.ExecutableFreeSelectionCouseID = Guid.NewGuid();
  314. executableFreeSelectionCouse.FreeSelectionCouseID = freeSelectionCourseApply.FreeSelectionCouseID;
  315. executableFreeSelectionCouse.SchoolyearID = freeSelectionCourseApply.SchoolyearID;
  316. executableFreeSelectionCouse.DefaultClassName = freeSelectionCourseApply.DefaultClassName;
  317. executableFreeSelectionCouse.DepartmentID = freeSelectionCourseApply.DepartmentID;
  318. executableFreeSelectionCouse.CourseStructureID = freeSelectionCourseApply.CourseStructureID;
  319. executableFreeSelectionCouse.CourseCategoryID = freeSelectionCourseApply.CourseCategoryID;
  320. executableFreeSelectionCouse.CourseTypeID = freeSelectionCourseApply.CourseTypeID;
  321. executableFreeSelectionCouse.CourseQualityID = freeSelectionCourseApply.CourseQualityID;
  322. executableFreeSelectionCouse.PracticeTypeID = freeSelectionCourseApply.PracticeTypeID;
  323. executableFreeSelectionCouse.ExaminationModeID = freeSelectionCourseApply.ExaminationModeID;
  324. executableFreeSelectionCouse.TeachinglanguageID = freeSelectionCourseApply.TeachinglanguageID;
  325. executableFreeSelectionCouse.IsNeedMaterial = freeSelectionCourseApply.IsNeedMaterial;
  326. executableFreeSelectionCouse.PeopleNumlower = freeSelectionCourseApply.PeopleNumlower;
  327. executableFreeSelectionCouse.PeopleNumlimit = freeSelectionCourseApply.PeopleNumlimit;
  328. executableFreeSelectionCouse.HandleModeID = freeSelectionCourseApply.HandleModeID;
  329. executableFreeSelectionCouse.ResultTypeID = freeSelectionCourseApply.ResultTypeID;
  330. executableFreeSelectionCouse.Remarks = freeSelectionCourseApply.Remarks;
  331. this.SetNewStatus(executableFreeSelectionCouse);
  332. UnitOfWork.Add(executableFreeSelectionCouse);
  333. //任选课开课申请教学设置表
  334. EM_ExecutableFreeSelectionCouseTeachingSetting executableFreeSelectionCouseTeachingSetting = new EM_ExecutableFreeSelectionCouseTeachingSetting();
  335. executableFreeSelectionCouseTeachingSetting.ExecutableFreeSelectionCouseID = executableFreeSelectionCouse.ExecutableFreeSelectionCouseID;
  336. executableFreeSelectionCouseTeachingSetting.Credit = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.Credit;
  337. executableFreeSelectionCouseTeachingSetting.TheoryCourse = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.TheoryCourse;
  338. executableFreeSelectionCouseTeachingSetting.Practicehours = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.Practicehours;
  339. executableFreeSelectionCouseTeachingSetting.Trialhours = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.Trialhours;
  340. executableFreeSelectionCouseTeachingSetting.WeeklyNum = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.WeeklyNum;
  341. executableFreeSelectionCouseTeachingSetting.TheoryWeeklyNum = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.TheoryWeeklyNum;
  342. executableFreeSelectionCouseTeachingSetting.PracticeWeeklyNum = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.PracticeWeeklyNum;
  343. executableFreeSelectionCouseTeachingSetting.TrialWeeklyNum = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.TrialWeeklyNum;
  344. executableFreeSelectionCouseTeachingSetting.StartWeeklyNum = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.StartWeeklyNum;
  345. executableFreeSelectionCouseTeachingSetting.EndWeeklyNum = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.EndWeeklyNum;
  346. executableFreeSelectionCouseTeachingSetting.WeeklyHours = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingSetting.WeeklyHours;
  347. //SetNewStatus(freeSelectionCourseTeachingSetting);
  348. UnitOfWork.Add(executableFreeSelectionCouseTeachingSetting);
  349. //任选课开课申请课程表
  350. if (freeSelectionCourseApply.EM_FreeSelectionCouseApplyScheduling != null)
  351. {
  352. //首先查出至少一个教室
  353. var firstClassroomID = freeSelectionCourseApply.EM_FreeSelectionCouseApplyScheduling.Select(x => x.ClassroomID).FirstOrDefault();
  354. freeSelectionCourseApply.EM_FreeSelectionCouseApplyScheduling.ToList().ForEach(x =>
  355. {
  356. var scheduling = new EM_ExecutableFreeSelectionCouseScheduling
  357. {
  358. ExecutableFreeSelectionCouseSchedulingID = Guid.NewGuid(),
  359. ExecutableFreeSelectionCouseID = executableFreeSelectionCouse.ExecutableFreeSelectionCouseID,
  360. ClassroomID = x.ClassroomID != null ? x.ClassroomID : firstClassroomID, //这一行没有教室时,填查询到的其它行的教室,如果都没有就为空
  361. CoursesTimeID = x.CoursesTimeID,
  362. Weekday = x.Weekday,
  363. };
  364. this.SetNewStatus(scheduling);
  365. this.UnitOfWork.Add(scheduling);
  366. });
  367. //var freeSelectionCouseApplyScheduling = freeSelectionCourseApply.EM_FreeSelectionCouseApplyScheduling.FirstOrDefault();
  368. //EM_ExecutableFreeSelectionCouseScheduling executableFreeSelectionCouseScheduling = new EM_ExecutableFreeSelectionCouseScheduling();
  369. //executableFreeSelectionCouseScheduling.ExecutableFreeSelectionCouseSchedulingID = Guid.NewGuid();
  370. //executableFreeSelectionCouseScheduling.ExecutableFreeSelectionCouseID = executableFreeSelectionCouse.ExecutableFreeSelectionCouseID;
  371. //executableFreeSelectionCousefreeSelectionCourseApply.ClassroomID = freeSelectionCouseApplyfreeSelectionCourseApply.ClassroomID;
  372. //executableFreeSelectionCouseScheduling.CoursesTimeID = freeSelectionCouseApplyScheduling.CoursesTimeID;
  373. //executableFreeSelectionCouseScheduling.Weekday = freeSelectionCouseApplyScheduling.Weekday;
  374. //SetNewStatus(executableFreeSelectionCouseScheduling);
  375. //UnitOfWork.Add(executableFreeSelectionCouseScheduling);
  376. }
  377. //任选课开课申请授课方式表
  378. if (freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingMode != null)
  379. {
  380. var list = freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeachingMode;
  381. if (list.Count > 0)
  382. {
  383. //UnitOfWork.Delete<EM_FreeSelectionCouseTeachingMode>(x => x.FreeSelectionCouseID == freeSelectionCourseApply.freeSelectionCourseID);
  384. foreach (var i in list)
  385. {
  386. EM_ExecutableFreeSelectionCouseTeachingMode teachingModeType = new EM_ExecutableFreeSelectionCouseTeachingMode();
  387. teachingModeType.ExecutableFreeSelectionCouseTeachingModeID = Guid.NewGuid();
  388. teachingModeType.ExecutableFreeSelectionCouseID = executableFreeSelectionCouse.ExecutableFreeSelectionCouseID;
  389. teachingModeType.TeachingModeID = i.TeachingModeID;
  390. //this.SetNewStatus(teachingModeType);
  391. UnitOfWork.Add(teachingModeType);
  392. }
  393. }
  394. }
  395. //任选课开课申请年级范围表
  396. if (freeSelectionCourseApply.EM_FreeSelectionCouseApplyGradeYear != null)
  397. {
  398. var list = freeSelectionCourseApply.EM_FreeSelectionCouseApplyGradeYear;
  399. if (list.Count > 0)
  400. {
  401. //UnitOfWork.Delete<EM_FreeSelectionCouseTeachingMode>(x => x.FreeSelectionCouseID == freeSelectionCourseApply.freeSelectionCourseID);
  402. foreach (var i in list)
  403. {
  404. EM_ExecutableFreeSelectionCouseGradeYear gradeYear = new EM_ExecutableFreeSelectionCouseGradeYear();
  405. gradeYear.ExecutableFreeSelectionCouseGradeYearID = Guid.NewGuid();
  406. gradeYear.ExecutableFreeSelectionCouseID = executableFreeSelectionCouse.ExecutableFreeSelectionCouseID;
  407. gradeYear.GradeYear = i.GradeYear;
  408. this.SetNewStatus(gradeYear);
  409. UnitOfWork.Add(gradeYear);
  410. }
  411. }
  412. }
  413. //任选课开课申请专业范围表
  414. if (freeSelectionCourseApply.EM_FreeSelectionCouseApplySpecialty != null)
  415. {
  416. //UnitOfWork.Delete<EM_FreeSelectionCouseTeachingMode>(x => x.FreeSelectionCouseID == freeSelectionCourseApply.freeSelectionCourseID);
  417. foreach (var i in freeSelectionCourseApply.EM_FreeSelectionCouseApplySpecialty)
  418. {
  419. EM_ExecutableFreeSelectionCouseSpecialty specialty = new EM_ExecutableFreeSelectionCouseSpecialty();
  420. specialty.ExecutableFreeSelectionCouseSpecialtyID = Guid.NewGuid();
  421. specialty.ExecutableFreeSelectionCouseID = executableFreeSelectionCouse.ExecutableFreeSelectionCouseID;
  422. specialty.SpecialtyID = i.SpecialtyID;
  423. this.SetNewStatus(specialty);
  424. UnitOfWork.Add(specialty);
  425. }
  426. }
  427. //任选课开课申请教师表
  428. if (freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeacher != null)
  429. {
  430. freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeacher.ToList().ForEach(x =>
  431. {
  432. var freeSelectionTeacher = new EM_ExecutableFreeSelectionCouseTeacher
  433. {
  434. ExecutableFreeSelectionCouseStaffID = Guid.NewGuid(),
  435. ExecutableFreeSelectionCouseID = executableFreeSelectionCouse.ExecutableFreeSelectionCouseID,
  436. UserID = x.UserID,
  437. TeachingMethod = x.TeachingMethod
  438. };
  439. this.SetNewStatus(freeSelectionTeacher);
  440. this.UnitOfWork.Add(freeSelectionTeacher);
  441. });
  442. }
  443. executableFreeSelectionCouse.RecordStatus = (int)EMIS.ViewModel.EM_SelectCourseResultStatus.NotOpen;
  444. }
  445. UnitOfWork.Commit();
  446. ////任选课开课申请教学设置表
  447. //EM_FreeSelectionCouseApplyTeachingSetting freeSelectionCourseTeachingSetting = FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyTeachingSettingRepository.Entities.Where(x => x.FreeSelectionCouseApplyID == FreeSelectionCouseApplyID).FirstOrDefault();
  448. ////任选课开课申请课程表
  449. //EM_FreeSelectionCouseApplyScheduling freeSelectionCouseApplyScheduling = FreeSelectionCoursePlanDAL.FreeSelectionCouseApplySchedulingRepository.Entities.Where(x => x.FreeSelectionCouseApplySchedulingID == FreeSelectionCouseApplyID).FirstOrDefault();
  450. ////任选课开课申请授课方式表
  451. //EM_FreeSelectionCouseApplyTeachingMode
  452. // EM_FreeSelectionCouseApplyGradeYear
  453. // EM_FreeSelectionCouseApplySpecialty
  454. // EM_FreeSelectionCouseApplyScheduling
  455. }
  456. public bool FreeSelectionCourseApplyAdd(FreeSelectionCourseApplyView freeSelectionCourseApply, IList<FreeSelectionCourseApplyTeacherListView> teacherList, IList<FreeSelectionCourseApplySpecialtyListView> specialtyList, IList<ExecutableFreeSelectionCouseSchedulingView> schedulingList, out int? type)
  457. {
  458. try
  459. {
  460. var StartStatus = this.GetStartStatus();
  461. var EndStatus = this.GetCorrectEndStatus();
  462. //schedulingList = schedulingList.Where(x => x.CoursesTimeID != null && x.Weekday != null && x.ClassroomID != null).ToList();
  463. if (schedulingList.Where(x => x.CoursesTimeID == null || x.Weekday == null).ToList().Count > 0)
  464. {
  465. throw new Exception("排课信息不能为空");
  466. }
  467. //else
  468. //{
  469. // var repeat = schedulingList.GroupBy(x => new { x.Weekday, x.CoursesTimeID }).Max().ToList();
  470. // if (repeat.Count > 1)
  471. // throw new Exception("上课时间不能重复");
  472. //}
  473. var SpecialtyIDList = specialtyList.Select(x => x.SpecialtyID).ToList();
  474. var freeSelectionCourse = this.GetFreeSelectionCourseView(freeSelectionCourseApply.FreeSelectionCouseID);
  475. if (this.FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyRepository
  476. .GetList(x => x.FreeSelectionCouseID == freeSelectionCourseApply.FreeSelectionCouseID
  477. && x.SchoolyearID == freeSelectionCourseApply.SchoolyearID
  478. && x.DefaultClassName == freeSelectionCourseApply.DefaultClassName
  479. && x.DepartmentID == freeSelectionCourseApply.DepartmentID
  480. && x.CourseTypeID == freeSelectionCourseApply.CourseTypeID
  481. && x.EM_FreeSelectionCouseApplySpecialty.Any(w => SpecialtyIDList.Contains(w.SpecialtyID))
  482. ).Count() > 0)
  483. {
  484. throw new Exception(freeSelectionCourse.CourseName + "对应的" + freeSelectionCourseApply.DefaultClassName + "在该学期已经申请过了,无需重复申请。");
  485. }
  486. if (this.ExecutableFreeSelectionCouseDAL.ExecutableFreeSelectionCouseRepository
  487. .GetList(x => x.FreeSelectionCouseID == freeSelectionCourseApply.FreeSelectionCouseID
  488. && x.SchoolyearID == freeSelectionCourseApply.SchoolyearID
  489. && x.DefaultClassName == freeSelectionCourseApply.DefaultClassName
  490. && x.DepartmentID == freeSelectionCourseApply.DepartmentID
  491. && x.CourseTypeID == freeSelectionCourseApply.CourseTypeID
  492. && x.EM_ExecutableFreeSelectionCouseSpecialty.Any(w => SpecialtyIDList.Contains(w.SpecialtyID))
  493. ).Count() > 0)
  494. {
  495. throw new Exception(freeSelectionCourse.CourseName + "对应的" + freeSelectionCourseApply.DefaultClassName + "在该学期存在相同的任选设定。");
  496. }
  497. //如果IsNeedVerify为false时,不验证冲突
  498. if (freeSelectionCourseApply.IsNeedVerify != false)
  499. {
  500. //判断教室和教室冲突
  501. foreach (var scheduling in schedulingList)
  502. {
  503. if (freeSelectionCourseApply.ClassroomID != null)
  504. {
  505. //任选设定冲突
  506. var repeatExecutableClassroom = ExecutableFreeSelectionCouseDAL.GetRepeatExecutableFreeSelectionCouseClassroom(scheduling.CoursesTimeID, freeSelectionCourseApply.ClassroomID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum).FirstOrDefault();
  507. if (repeatExecutableClassroom != null)
  508. {
  509. type = 1;
  510. throw new Exception(repeatExecutableClassroom.WeekdayName + "第" + repeatExecutableClassroom.StartTimes + "节时间段教室与任选设定【" + repeatExecutableClassroom.DefaultClassName + "】有冲突");
  511. }
  512. //任选申请冲突
  513. var repeatApplyClassroom = ExecutableFreeSelectionCouseDAL.GetRepeatFreeSelectionCouseApplyClassroom(scheduling.CoursesTimeID, freeSelectionCourseApply.ClassroomID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum, EndStatus).FirstOrDefault();
  514. if (repeatApplyClassroom != null)
  515. {
  516. type = 1;
  517. throw new Exception(repeatApplyClassroom.WeekdayName + "第" + repeatApplyClassroom.StartTimes + "节时间段教室与开课申请【" + repeatApplyClassroom.DefaultClassName + "】有冲突");
  518. }
  519. //教学任务冲突
  520. var repeatEducationClassroom = ExecutableFreeSelectionCouseDAL.GetRepeatEducationMissionClassroom(scheduling.CoursesTimeID, freeSelectionCourseApply.ClassroomID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum).FirstOrDefault();
  521. if (repeatEducationClassroom != null)
  522. {
  523. type = 1;
  524. throw new Exception("该设定上课时间段教室与教学任务班【" + repeatEducationClassroom.DefaultClassName + "】有冲突");
  525. }
  526. }
  527. //任选设定冲突
  528. var repeatExecutableTeacher = ExecutableFreeSelectionCouseDAL.GetRepeatExecutableFreeSelectionCouseTeacher(teacherList.Select(x => x.UserID).ToList(), scheduling.CoursesTimeID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum).FirstOrDefault();
  529. if (repeatExecutableTeacher != null)
  530. {
  531. type = 1;
  532. throw new Exception(repeatExecutableTeacher.WeekdayName + "第" + repeatExecutableTeacher.StartTimes + "节时间段教师与任选设定【" + repeatExecutableTeacher.DefaultClassName + "】有冲突");
  533. }
  534. //任选申请冲突
  535. var repeatApplyTeacher = ExecutableFreeSelectionCouseDAL.GetRepeatFreeSelectionCouseApplyTeacher(teacherList.Select(x => x.UserID).ToList(), scheduling.CoursesTimeID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum, EndStatus).FirstOrDefault();
  536. if (repeatApplyTeacher != null)
  537. {
  538. type = 1;
  539. throw new Exception(repeatApplyTeacher.WeekdayName + "第" + repeatApplyTeacher.StartTimes + "节时间段教师与开课申请【" + repeatApplyTeacher.DefaultClassName + "】有冲突");
  540. }
  541. //教学任务冲突
  542. var repeatEducationTeacher = ExecutableFreeSelectionCouseDAL.GetRepeatEducationMissionTeacher(teacherList.Select(x => x.UserID).ToList(), scheduling.CoursesTimeID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum).FirstOrDefault();
  543. if (repeatEducationTeacher != null)
  544. {
  545. type = 1;
  546. throw new Exception("该设定上课时间段教师与教学任务班【" + repeatEducationTeacher.DefaultClassName + "】有冲突");
  547. }
  548. }
  549. }
  550. using (TransactionScope ts = new TransactionScope())
  551. {
  552. //任选课开课申请表
  553. EM_FreeSelectionCouseApply freeSelectionCourseApplyEntity = new EM_FreeSelectionCouseApply();
  554. freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID = Guid.NewGuid();
  555. freeSelectionCourseApplyEntity.FreeSelectionCouseID = freeSelectionCourseApply.FreeSelectionCouseID;
  556. freeSelectionCourseApplyEntity.SchoolyearID = freeSelectionCourseApply.SchoolyearID;
  557. freeSelectionCourseApplyEntity.DefaultClassName = freeSelectionCourseApply.DefaultClassName;
  558. //freeSelectionCourseApplyEntity.DefaultClassName = freeSelectionCourse.DepartmentName + "-"
  559. // + freeSelectionCourse.CourseName + "班(任选)";
  560. freeSelectionCourseApplyEntity.DepartmentID = freeSelectionCourseApply.DepartmentID;
  561. freeSelectionCourseApplyEntity.CourseStructureID = freeSelectionCourseApply.CourseStructureID;
  562. freeSelectionCourseApplyEntity.CourseCategoryID = freeSelectionCourseApply.CourseCategoryID;
  563. freeSelectionCourseApplyEntity.CourseTypeID = freeSelectionCourseApply.CourseTypeID;
  564. freeSelectionCourseApplyEntity.CourseQualityID = freeSelectionCourseApply.CourseQualityID;
  565. freeSelectionCourseApplyEntity.PracticeTypeID = freeSelectionCourseApply.PracticeTypeID;
  566. freeSelectionCourseApplyEntity.ExaminationModeID = freeSelectionCourseApply.ExaminationModeID;
  567. freeSelectionCourseApplyEntity.TeachinglanguageID = freeSelectionCourseApply.TeachinglanguageID;
  568. freeSelectionCourseApplyEntity.IsNeedMaterial = freeSelectionCourseApply.IsNeedMaterial;
  569. freeSelectionCourseApplyEntity.PeopleNumlower = freeSelectionCourseApply.PeopleNumlower;
  570. freeSelectionCourseApplyEntity.PeopleNumlimit = freeSelectionCourseApply.PeopleNumlimit;
  571. freeSelectionCourseApplyEntity.HandleModeID = freeSelectionCourseApply.HandleModeID;
  572. freeSelectionCourseApplyEntity.IsOpened = freeSelectionCourseApply.IsOpened;
  573. freeSelectionCourseApplyEntity.ApprovalStatus = StartStatus;
  574. freeSelectionCourseApplyEntity.ResultTypeID = freeSelectionCourseApply.ResultTypeID;
  575. freeSelectionCourseApplyEntity.Remarks = freeSelectionCourseApply.Remarks;
  576. this.SetNewStatus(freeSelectionCourseApplyEntity);
  577. UnitOfWork.Add(freeSelectionCourseApplyEntity);
  578. //任选课开课申请教学设置表
  579. EM_FreeSelectionCouseApplyTeachingSetting freeSelectionCourseTeachingSetting;
  580. freeSelectionCourseTeachingSetting = new EM_FreeSelectionCouseApplyTeachingSetting();
  581. freeSelectionCourseTeachingSetting.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID;
  582. freeSelectionCourseTeachingSetting.Credit = freeSelectionCourseApply.Credit;
  583. freeSelectionCourseTeachingSetting.TheoryCourse = freeSelectionCourseApply.TheoryCourse;
  584. freeSelectionCourseTeachingSetting.Practicehours = freeSelectionCourseApply.Practicehours;
  585. freeSelectionCourseTeachingSetting.Trialhours = freeSelectionCourseApply.Trialhours;
  586. freeSelectionCourseTeachingSetting.WeeklyNum = freeSelectionCourseApply.WeeklyNum;
  587. freeSelectionCourseTeachingSetting.TheoryWeeklyNum = freeSelectionCourseApply.TheoryWeeklyNum;
  588. freeSelectionCourseTeachingSetting.PracticeWeeklyNum = freeSelectionCourseApply.PracticeWeeklyNum;
  589. freeSelectionCourseTeachingSetting.TrialWeeklyNum = freeSelectionCourseApply.TrialWeeklyNum;
  590. freeSelectionCourseTeachingSetting.StartWeeklyNum = freeSelectionCourseApply.StartWeeklyNum;
  591. freeSelectionCourseTeachingSetting.EndWeeklyNum = freeSelectionCourseApply.EndWeeklyNum;
  592. freeSelectionCourseTeachingSetting.WeeklyHours = freeSelectionCourseApply.WeeklyHours;
  593. //SetNewStatus(freeSelectionCourseTeachingSetting);
  594. UnitOfWork.Add(freeSelectionCourseTeachingSetting);
  595. //任选设定课程表
  596. schedulingList.Where(x => x.CoursesTimeID != null && x.Weekday != null).ToList().ForEach(x =>
  597. {
  598. var scheduling = new EM_FreeSelectionCouseApplyScheduling
  599. {
  600. FreeSelectionCouseApplySchedulingID = Guid.NewGuid(),
  601. FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID,
  602. ClassroomID = freeSelectionCourseApply.ClassroomID, //这一行没有教室时,填查询到的其它行的教室,如果都没有就为空
  603. CoursesTimeID = x.CoursesTimeID,
  604. Weekday = x.Weekday,
  605. };
  606. this.SetNewStatus(scheduling);
  607. this.UnitOfWork.Add(scheduling);
  608. });
  609. //任选课开课申请授课方式表,没有时默认为理论
  610. if (freeSelectionCourseApply.TeachingModeID != null)
  611. {
  612. var list = freeSelectionCourseApply.TeachingModeID;
  613. if (list.Count > 0)
  614. {
  615. //UnitOfWork.Delete<EM_FreeSelectionCouseTeachingMode>(x => x.FreeSelectionCouseID == freeSelectionCourseApply.freeSelectionCourseID);
  616. foreach (var i in list)
  617. {
  618. EM_FreeSelectionCouseApplyTeachingMode teachingModeType = new EM_FreeSelectionCouseApplyTeachingMode();
  619. teachingModeType.FreeSelectionCouseApplyTeachingModeID = Guid.NewGuid();
  620. teachingModeType.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID;
  621. teachingModeType.TeachingModeID = i;
  622. //this.SetNewStatus(teachingModeType);
  623. UnitOfWork.Add(teachingModeType);
  624. }
  625. }
  626. }
  627. else
  628. {
  629. EM_FreeSelectionCouseApplyTeachingMode teachingModeType = new EM_FreeSelectionCouseApplyTeachingMode();
  630. teachingModeType.FreeSelectionCouseApplyTeachingModeID = Guid.NewGuid();
  631. teachingModeType.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID;
  632. teachingModeType.TeachingModeID = (int)EMIS.ViewModel.CF_TeachingMode.Theory;
  633. UnitOfWork.Add(teachingModeType);
  634. }
  635. //任选课开课申请年级范围表
  636. if (freeSelectionCourseApply.GradeYear != null)
  637. {
  638. var list = freeSelectionCourseApply.GradeYear;
  639. if (list.Count > 0)
  640. {
  641. //UnitOfWork.Delete<EM_FreeSelectionCouseTeachingMode>(x => x.FreeSelectionCouseID == freeSelectionCourseApply.freeSelectionCourseID);
  642. foreach (var i in list)
  643. {
  644. EM_FreeSelectionCouseApplyGradeYear gradeYear = new EM_FreeSelectionCouseApplyGradeYear();
  645. gradeYear.FreeSelectionCouseApplyGradeYearID = Guid.NewGuid();
  646. gradeYear.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID;
  647. gradeYear.GradeYear = i;
  648. this.SetNewStatus(gradeYear);
  649. UnitOfWork.Add(gradeYear);
  650. }
  651. }
  652. }
  653. //任选课开课申请专业范围表
  654. if (specialtyList.Count > 0)
  655. {
  656. //UnitOfWork.Delete<EM_FreeSelectionCouseTeachingMode>(x => x.FreeSelectionCouseID == freeSelectionCourseApply.freeSelectionCourseID);
  657. foreach (var i in specialtyList)
  658. {
  659. EM_FreeSelectionCouseApplySpecialty specialty = new EM_FreeSelectionCouseApplySpecialty();
  660. specialty.FreeSelectionCouseApplySpecialtyID = Guid.NewGuid();
  661. specialty.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID;
  662. specialty.SpecialtyID = i.SpecialtyID;
  663. this.SetNewStatus(specialty);
  664. UnitOfWork.Add(specialty);
  665. }
  666. }
  667. //任选课开课申请教师表,没有授课老师时,默认为申请人
  668. if (teacherList.Count > 0)
  669. {
  670. var ids = teacherList.Select(w => w.UserID).ToList();
  671. var noExistStaff = userRepository.GetList(x => ids.Contains(x.UserID) && x.CF_Staff == null).FirstOrDefault();
  672. if (noExistStaff != null)
  673. throw new Exception(noExistStaff.Name + "账号不是教职工账号,不能设为授课老师");
  674. teacherList.ToList().ForEach(x =>
  675. {
  676. var freeSelectionTeacher = new EM_FreeSelectionCouseApplyTeacher
  677. {
  678. FreeSelectionCouseApplyStaffID = Guid.NewGuid(),
  679. FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID,
  680. UserID = x.UserID,
  681. TeachingMethod = x.TeachingMethod
  682. };
  683. this.SetNewStatus(freeSelectionTeacher);
  684. this.UnitOfWork.Add(freeSelectionTeacher);
  685. });
  686. }
  687. else
  688. {
  689. if (CustomPrincipal.Current.StaffID == null)
  690. throw new Exception("当前账号不是教职工账号,不能设为授课老师");
  691. var freeSelectionTeacher = new EM_FreeSelectionCouseApplyTeacher();
  692. freeSelectionTeacher.FreeSelectionCouseApplyStaffID = Guid.NewGuid();
  693. freeSelectionTeacher.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID;
  694. freeSelectionTeacher.UserID = CustomPrincipal.Current.UserID;
  695. freeSelectionTeacher.TeachingMethod = (int)EMIS.ViewModel.EM_TeachingMethod.Lecturer;
  696. this.SetNewStatus(freeSelectionTeacher);
  697. this.UnitOfWork.Add(freeSelectionTeacher);
  698. }
  699. UnitOfWork.Commit();
  700. ts.Complete();
  701. }
  702. type = 0;
  703. return true;
  704. }
  705. catch (Exception)
  706. {
  707. throw;
  708. }
  709. }
  710. public bool FreeSelectionCourseApplyUpdate(FreeSelectionCourseApplyView freeSelectionCourseApply, IList<FreeSelectionCourseApplyTeacherListView> teacherList, IList<FreeSelectionCourseApplySpecialtyListView> specialtyList, IList<ExecutableFreeSelectionCouseSchedulingView> schedulingList, out int? type)
  711. {
  712. try
  713. {
  714. var ApprovalStatus = this.GetCorrectEndStatus();
  715. //schedulingList = schedulingList.Where(x => x.CoursesTimeID != null && x.Weekday != null && x.ClassroomID != null).ToList();
  716. if (schedulingList.Where(x => x.CoursesTimeID == null || x.Weekday == null).ToList().Count > 0)
  717. {
  718. throw new Exception("排课信息不能为空");
  719. }
  720. //else
  721. //{
  722. // var repeat = schedulingList.GroupBy(x => new { x.Weekday, x.CoursesTimeID }).Max().ToList();
  723. // if (repeat.Count > 1)
  724. // throw new Exception("上课时间不能重复");
  725. //}
  726. var SpecialtyIDList = specialtyList.Select(x => x.SpecialtyID).ToList();
  727. var freeSelectionCourse = this.GetFreeSelectionCourseView(freeSelectionCourseApply.FreeSelectionCouseID);
  728. List<int?> approveStatusList = this.GetApproveStatusViewList().Where(x => x.Description.Contains("[AP]")).Select(x => x.ID).ToList();
  729. approveStatusList.Add(this.GetCorrectEndStatus());
  730. if (approveStatusList.Contains(freeSelectionCourseApply.ApprovalStatus))
  731. throw new Exception("数据已进入审核环节,不能修改。");
  732. if (this.FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyRepository
  733. .GetList(x => x.FreeSelectionCouseID == freeSelectionCourseApply.FreeSelectionCouseID
  734. && x.SchoolyearID == freeSelectionCourseApply.SchoolyearID
  735. && x.FreeSelectionCouseApplyID != freeSelectionCourseApply.FreeSelectionCouseApplyID
  736. && x.DefaultClassName == freeSelectionCourseApply.DefaultClassName
  737. && x.DepartmentID == freeSelectionCourseApply.DepartmentID
  738. && x.CourseTypeID == freeSelectionCourseApply.CourseTypeID
  739. && x.EM_FreeSelectionCouseApplySpecialty.Any(w => SpecialtyIDList.Contains(w.SpecialtyID))
  740. ).Count() > 0)
  741. {
  742. throw new Exception(freeSelectionCourse.CourseName + "对应的" + freeSelectionCourseApply.DefaultClassName + "在该学期已经申请过了,无需重复申请。");
  743. }
  744. if (this.ExecutableFreeSelectionCouseDAL.ExecutableFreeSelectionCouseRepository
  745. .GetList(x => x.FreeSelectionCouseID == freeSelectionCourseApply.FreeSelectionCouseID
  746. && x.SchoolyearID == freeSelectionCourseApply.SchoolyearID
  747. && x.DefaultClassName == freeSelectionCourseApply.DefaultClassName
  748. && x.DepartmentID == freeSelectionCourseApply.DepartmentID
  749. && x.CourseTypeID == freeSelectionCourseApply.CourseTypeID
  750. && x.EM_ExecutableFreeSelectionCouseSpecialty.Any(w => SpecialtyIDList.Contains(w.SpecialtyID))
  751. ).Count() > 0)
  752. {
  753. throw new Exception(freeSelectionCourse.CourseName + "对应的" + freeSelectionCourseApply.DefaultClassName + "在该学期存在相同的任选设定。");
  754. }
  755. if (freeSelectionCourseApply.IsNeedVerify != false)
  756. {
  757. //判断教室和教师冲突
  758. foreach (var scheduling in schedulingList)
  759. {
  760. if (freeSelectionCourseApply.ClassroomID != null)
  761. {
  762. //任选设定冲突
  763. var repeatExecutableClassroom = ExecutableFreeSelectionCouseDAL.GetRepeatExecutableFreeSelectionCouseClassroom(scheduling.CoursesTimeID, freeSelectionCourseApply.ClassroomID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum).FirstOrDefault();
  764. if (repeatExecutableClassroom != null)
  765. {
  766. type = 1;
  767. throw new Exception(repeatExecutableClassroom.WeekdayName + "第" + repeatExecutableClassroom.StartTimes + "节时间段教室与任选设定【" + repeatExecutableClassroom.DefaultClassName + "】有冲突");
  768. }
  769. //任选申请冲突
  770. var repeatApplyClassroom = ExecutableFreeSelectionCouseDAL.GetRepeatFreeSelectionCouseApplyClassroom(scheduling.CoursesTimeID, freeSelectionCourseApply.ClassroomID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum, ApprovalStatus)
  771. .Where(x => x.ID != freeSelectionCourseApply.FreeSelectionCouseApplyID).FirstOrDefault();
  772. if (repeatApplyClassroom != null)
  773. {
  774. type = 1;
  775. throw new Exception(repeatApplyClassroom.WeekdayName + "第" + repeatApplyClassroom.StartTimes + "节时间段教室与开课申请【" + repeatApplyClassroom.DefaultClassName + "】有冲突");
  776. }//教学任务冲突
  777. var repeatEducationClassroom = ExecutableFreeSelectionCouseDAL.GetRepeatEducationMissionClassroom(scheduling.CoursesTimeID, freeSelectionCourseApply.ClassroomID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum).FirstOrDefault();
  778. if (repeatEducationClassroom != null)
  779. {
  780. type = 1;
  781. throw new Exception("该设定上课时间段教室与教学任务班【" + repeatEducationClassroom.DefaultClassName + "】有冲突");
  782. }
  783. }
  784. //任选设定冲突
  785. var repeatExecutableTeacher = ExecutableFreeSelectionCouseDAL.GetRepeatExecutableFreeSelectionCouseTeacher(teacherList.Select(x => x.UserID).ToList(), scheduling.CoursesTimeID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum).FirstOrDefault();
  786. if (repeatExecutableTeacher != null)
  787. {
  788. type = 1;
  789. throw new Exception(repeatExecutableTeacher.WeekdayName + "第" + repeatExecutableTeacher.StartTimes + "节时间段教师与任选设定【" + repeatExecutableTeacher.DefaultClassName + "】有冲突");
  790. }
  791. //任选申请冲突
  792. var repeatApplyTeacher = ExecutableFreeSelectionCouseDAL.GetRepeatFreeSelectionCouseApplyTeacher(teacherList.Select(x => x.UserID).ToList(), scheduling.CoursesTimeID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum, ApprovalStatus)
  793. .Where(x => x.ID != freeSelectionCourseApply.FreeSelectionCouseApplyID).FirstOrDefault();
  794. if (repeatApplyTeacher != null)
  795. {
  796. type = 1;
  797. throw new Exception(repeatApplyTeacher.WeekdayName + "第" + repeatApplyTeacher.StartTimes + "节时间段教师与开课申请【" + repeatApplyTeacher.DefaultClassName + "】有冲突");
  798. }
  799. //教学任务冲突
  800. var repeatEducationTeacher = ExecutableFreeSelectionCouseDAL.GetRepeatEducationMissionTeacher(teacherList.Select(x => x.UserID).ToList(), scheduling.CoursesTimeID, scheduling.Weekday, freeSelectionCourseApply.SchoolyearID, freeSelectionCourseApply.StartWeeklyNum, freeSelectionCourseApply.EndWeeklyNum).FirstOrDefault();
  801. if (repeatEducationTeacher != null)
  802. {
  803. type = 1;
  804. throw new Exception("该设定上课时间段教师与教学任务班【" + repeatEducationTeacher.DefaultClassName + "】有冲突");
  805. }
  806. }
  807. }
  808. using (TransactionScope ts = new TransactionScope())
  809. {
  810. EM_FreeSelectionCouseApply freeSelectionCourseApplyEntity = GetFreeSelectionCourseApply(freeSelectionCourseApply.FreeSelectionCouseApplyID);
  811. freeSelectionCourseApplyEntity.FreeSelectionCouseID = freeSelectionCourseApply.FreeSelectionCouseID;
  812. freeSelectionCourseApplyEntity.SchoolyearID = freeSelectionCourseApply.SchoolyearID;
  813. freeSelectionCourseApplyEntity.DefaultClassName = freeSelectionCourseApply.DefaultClassName;
  814. //freeSelectionCourseApplyEntity.DefaultClassName = freeSelectionCourse.DepartmentName + "-"
  815. // + freeSelectionCourse.CourseName + "班(任选)";
  816. freeSelectionCourseApplyEntity.DepartmentID = freeSelectionCourseApply.DepartmentID;
  817. freeSelectionCourseApplyEntity.CourseStructureID = freeSelectionCourseApply.CourseStructureID;
  818. freeSelectionCourseApplyEntity.CourseCategoryID = freeSelectionCourseApply.CourseCategoryID;
  819. freeSelectionCourseApplyEntity.CourseTypeID = freeSelectionCourseApply.CourseTypeID;
  820. freeSelectionCourseApplyEntity.CourseQualityID = freeSelectionCourseApply.CourseQualityID;
  821. freeSelectionCourseApplyEntity.PracticeTypeID = freeSelectionCourseApply.PracticeTypeID;
  822. freeSelectionCourseApplyEntity.ExaminationModeID = freeSelectionCourseApply.ExaminationModeID;
  823. freeSelectionCourseApplyEntity.TeachinglanguageID = freeSelectionCourseApply.TeachinglanguageID;
  824. freeSelectionCourseApplyEntity.IsNeedMaterial = freeSelectionCourseApply.IsNeedMaterial;
  825. freeSelectionCourseApplyEntity.PeopleNumlower = freeSelectionCourseApply.PeopleNumlower;
  826. freeSelectionCourseApplyEntity.PeopleNumlimit = freeSelectionCourseApply.PeopleNumlimit;
  827. freeSelectionCourseApplyEntity.HandleModeID = freeSelectionCourseApply.HandleModeID;
  828. freeSelectionCourseApplyEntity.IsOpened = freeSelectionCourseApply.IsOpened;
  829. freeSelectionCourseApplyEntity.ResultTypeID = freeSelectionCourseApply.ResultTypeID;
  830. //freeSelectionCourseApplyEntity.ApprovalStatus = freeSelectionCourseApply.ApprovalStatus;//(int)EMIS.ViewModel.CF_PlanApplicationStatus.NotSubmitted;
  831. freeSelectionCourseApplyEntity.Remarks = freeSelectionCourseApply.Remarks;
  832. //任选课开课申请教学设置表
  833. EM_FreeSelectionCouseApplyTeachingSetting freeSelectionCourseTeachingSetting = FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyTeachingSettingRepository.Entities.Where(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApply.FreeSelectionCouseApplyID).FirstOrDefault();
  834. //freeSelectionCourseTeachingSetting = new EM_FreeSelectionCouseApplyTeachingSetting();
  835. freeSelectionCourseTeachingSetting.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID;
  836. freeSelectionCourseTeachingSetting.Credit = freeSelectionCourseApply.Credit;
  837. freeSelectionCourseTeachingSetting.TheoryCourse = freeSelectionCourseApply.TheoryCourse;
  838. freeSelectionCourseTeachingSetting.Practicehours = freeSelectionCourseApply.Practicehours;
  839. freeSelectionCourseTeachingSetting.Trialhours = freeSelectionCourseApply.Trialhours;
  840. freeSelectionCourseTeachingSetting.WeeklyNum = freeSelectionCourseApply.WeeklyNum;
  841. freeSelectionCourseTeachingSetting.TheoryWeeklyNum = freeSelectionCourseApply.TheoryWeeklyNum;
  842. freeSelectionCourseTeachingSetting.PracticeWeeklyNum = freeSelectionCourseApply.PracticeWeeklyNum;
  843. freeSelectionCourseTeachingSetting.TrialWeeklyNum = freeSelectionCourseApply.TrialWeeklyNum;
  844. freeSelectionCourseTeachingSetting.StartWeeklyNum = freeSelectionCourseApply.StartWeeklyNum;
  845. freeSelectionCourseTeachingSetting.EndWeeklyNum = freeSelectionCourseApply.EndWeeklyNum;
  846. freeSelectionCourseTeachingSetting.WeeklyHours = freeSelectionCourseApply.WeeklyHours;
  847. //SetNewStatus(freeSelectionCourseTeachingSetting);
  848. //任选课开课申请课程表
  849. this.UnitOfWork.Delete<EM_FreeSelectionCouseApplyScheduling>(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID);
  850. //首先查出至少一个教室
  851. var firstClassroomID = schedulingList.Select(x => x.ClassroomID).FirstOrDefault();
  852. schedulingList.Where(x => x.CoursesTimeID != null && x.Weekday != null).ToList().ForEach(x =>
  853. {
  854. var scheduling = new EM_FreeSelectionCouseApplyScheduling
  855. {
  856. FreeSelectionCouseApplySchedulingID = Guid.NewGuid(),
  857. FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID,
  858. ClassroomID = freeSelectionCourseApply.ClassroomID, //这一行没有教室时,填查询到的其它行的教室,如果都没有就为空
  859. CoursesTimeID = x.CoursesTimeID,
  860. Weekday = x.Weekday,
  861. };
  862. this.SetNewStatus(scheduling);
  863. this.UnitOfWork.Add(scheduling);
  864. });
  865. //任选课开课申请授课方式表
  866. if (freeSelectionCourseApply.TeachingModeID != null)
  867. {
  868. TeachingModeTypeAdd(freeSelectionCourseApply.TeachingModeID, freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID);
  869. }
  870. this.SetModifyStatus(freeSelectionCourseApplyEntity);
  871. //
  872. UnitOfWork.Delete<EM_FreeSelectionCouseApplyGradeYear>(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID);
  873. if (freeSelectionCourseApply.GradeYear != null)
  874. {
  875. foreach (var i in freeSelectionCourseApply.GradeYear)
  876. {
  877. EM_FreeSelectionCouseApplyGradeYear gradeYear = new EM_FreeSelectionCouseApplyGradeYear();
  878. gradeYear.FreeSelectionCouseApplyGradeYearID = Guid.NewGuid();
  879. gradeYear.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID;
  880. gradeYear.GradeYear = i;
  881. this.SetNewStatus(gradeYear);
  882. UnitOfWork.Add(gradeYear);
  883. }
  884. }
  885. //
  886. if (specialtyList.Count > 0)
  887. {
  888. UnitOfWork.Delete<EM_FreeSelectionCouseApplySpecialty>(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID);
  889. foreach (var i in specialtyList)
  890. {
  891. EM_FreeSelectionCouseApplySpecialty specialty = new EM_FreeSelectionCouseApplySpecialty();
  892. specialty.FreeSelectionCouseApplySpecialtyID = Guid.NewGuid();
  893. specialty.FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID;
  894. specialty.SpecialtyID = i.SpecialtyID;
  895. this.SetNewStatus(specialty);
  896. UnitOfWork.Add(specialty);
  897. }
  898. }
  899. this.UnitOfWork.Delete<EM_FreeSelectionCouseApplyTeacher>(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID);
  900. teacherList.ToList().ForEach(x =>
  901. {
  902. var freeSelectionTeacher = new EM_FreeSelectionCouseApplyTeacher
  903. {
  904. FreeSelectionCouseApplyStaffID = Guid.NewGuid(),
  905. FreeSelectionCouseApplyID = freeSelectionCourseApplyEntity.FreeSelectionCouseApplyID,
  906. UserID = x.UserID,
  907. TeachingMethod = x.TeachingMethod
  908. };
  909. this.SetNewStatus(freeSelectionTeacher);
  910. this.UnitOfWork.Add(freeSelectionTeacher);
  911. });
  912. this.SetModifyStatus(freeSelectionCourseApplyEntity);
  913. UnitOfWork.Commit();
  914. ts.Complete();
  915. }
  916. type = 0;
  917. return true;
  918. }
  919. catch (Exception)
  920. {
  921. throw;
  922. }
  923. }
  924. public bool FreeSelectionCourseApplyUpdate(IList<FreeSelectionCourseApplyView> freeSelectionCourseApplyList)
  925. {
  926. try
  927. {
  928. foreach (var freeSelectionCourseApply in freeSelectionCourseApplyList)
  929. {
  930. EM_FreeSelectionCouseApply freeSelectionCourseApplyEntity = GetFreeSelectionCourseApply(freeSelectionCourseApply.FreeSelectionCouseApplyID);
  931. freeSelectionCourseApplyEntity.PeopleNumlower = freeSelectionCourseApply.PeopleNumlower;
  932. freeSelectionCourseApplyEntity.PeopleNumlimit = freeSelectionCourseApply.PeopleNumlimit;
  933. freeSelectionCourseApplyEntity.IsOpened = freeSelectionCourseApply.IsOpened;
  934. freeSelectionCourseApplyEntity.IsNeedMaterial = freeSelectionCourseApply.IsNeedMaterial;
  935. this.SetModifyStatus(freeSelectionCourseApplyEntity);
  936. }
  937. UnitOfWork.Commit();
  938. return true;
  939. }
  940. catch (Exception)
  941. {
  942. throw;
  943. }
  944. }
  945. public bool FreeSelectionCourseApplyDelete(List<Guid?> freeSelectionCourseApplyIDs)
  946. {
  947. try
  948. {
  949. if (freeSelectionCourseApplyIDs.Count > 0)
  950. {
  951. var statusList = this.GetStatusViewList();
  952. var startStatus = this.GetStartStatus();
  953. //所有审核环节
  954. var status = statusList.Where(x =>x.Description.Contains("[AP]") && x.ID != startStatus || x.ID == this.GetCorrectEndStatus()).Select(x => x.ID).ToList();
  955. foreach (var freeSelectionCourseApplyID in freeSelectionCourseApplyIDs)
  956. {
  957. EM_FreeSelectionCouseApply freeSelectionCourseApply = GetFreeSelectionCourseApply(freeSelectionCourseApplyID);
  958. if (freeSelectionCourseApply.ApprovalStatus == startStatus) //未提交状态
  959. {
  960. UnitOfWork.Remove<EM_FreeSelectionCouseApplyScheduling>(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApply.FreeSelectionCouseApplyID);
  961. UnitOfWork.Remove<EM_FreeSelectionCouseApplyTeachingSetting>(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApply.FreeSelectionCouseApplyID);
  962. UnitOfWork.Remove<EM_FreeSelectionCouseApplyTeachingMode>(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApply.FreeSelectionCouseApplyID);
  963. UnitOfWork.Remove<EM_FreeSelectionCouseApplyTeacher>(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApply.FreeSelectionCouseApplyID);
  964. UnitOfWork.Remove<EM_FreeSelectionCouseApplyGradeYear>(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApply.FreeSelectionCouseApplyID);
  965. UnitOfWork.Remove<EM_FreeSelectionCouseApplySpecialty>(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApply.FreeSelectionCouseApplyID);
  966. UnitOfWork.Remove(freeSelectionCourseApply);
  967. }
  968. else if (!status.Contains(freeSelectionCourseApply.ApprovalStatus))
  969. {
  970. ModifyProcessState(freeSelectionCourseApply.FreeSelectionCouseApplyID, "D", "");
  971. UnitOfWork.Remove(freeSelectionCourseApply);
  972. }
  973. else
  974. {
  975. throw new Exception("数据已进入审核环节,不能删除");
  976. //不属于以上两种情况不能删除
  977. }
  978. }
  979. this.UnitOfWork.Commit();
  980. return true;
  981. }
  982. return false;
  983. }
  984. catch (Exception)
  985. {
  986. throw;
  987. }
  988. }
  989. public Entities.CF_Staff GetStaff(Guid? userID)
  990. {
  991. //查询条件
  992. System.Linq.Expressions.Expression<Func<CF_Staff, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  993. expression = (x => x.UserID == userID);
  994. return staffRepository.GetSingle(expression, (x => x.CF_StaffManageCampus), (x => x.CF_StaffManageCollege), (x => x.CF_StaffProfile), (x => x.Sys_User));
  995. }
  996. public List<FreeSelectionCourseApplyTeacherListView> GetFreeSelectionCourseApplyTeacherListView(Guid freeSelectionCourseApplyID)
  997. {
  998. var teacherView = FreeSelectionCoursePlanDAL.GetFreeSelectionCourseApplyTeacherViewQueryable(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyID).ToList();
  999. if (teacherView.Count == 0)
  1000. {
  1001. var staff = GetStaff(CustomPrincipal.Current.UserID);
  1002. FreeSelectionCourseApplyTeacherListView teacherList = new FreeSelectionCourseApplyTeacherListView();
  1003. teacherList.UserID = staff.UserID;
  1004. teacherList.TeachingMethod = (int)EMIS.ViewModel.EM_TeachingMethod.Lecturer;
  1005. }
  1006. return teacherView;
  1007. }
  1008. //查询专业范围
  1009. public List<SpecialtyView> GetFreeSelectionCourseApplySpecialtyListView(Guid freeSelectionCourseApplyID)
  1010. {
  1011. var specialtyView = FreeSelectionCoursePlanDAL.GetFreeSelectionCourseApplySpecialtyViewQueryable(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyID);
  1012. return specialtyView.ToList();
  1013. }
  1014. public void SaveFreeSelectionCourseTeachers(Guid freeSelectionCourseApplyID, IList<FreeSelectionCourseApplyTeacherListView> teacherList)
  1015. {
  1016. var freeSelectionCourseApply = this.FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyRepository
  1017. .GetSingle(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyID, (x => x.EM_FreeSelectionCouseApplyTeacher));
  1018. freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeacher.ToList().ForEach(x => this.UnitOfWork.Remove(x));
  1019. //teacherList.ToList().ForEach(x =>
  1020. //{
  1021. // var freeSelectionCourseApplyStaffEntity = new EM_FreeSelectionCouseApplyStaff
  1022. // {
  1023. // FreeSelectionCouseApplyStaffID = Guid.NewGuid(),
  1024. // FreeSelectionCouseApplyID = freeSelectionCourseApplyID,
  1025. // UserID = x.UserID,
  1026. // TeachingMethod = x.TeachingMethod
  1027. // };
  1028. // this.SetNewStatus(freeSelectionCourseApplyStaffEntity);
  1029. // this.UnitOfWork.Add(freeSelectionCourseApplyStaffEntity);
  1030. //});
  1031. this.UnitOfWork.Commit();
  1032. }
  1033. /// <summary>
  1034. /// 根据起止周次定义班号顺序
  1035. /// </summary>
  1036. /// <param name="SchoolyearID"></param>
  1037. /// <param name="freeSelectionCourseID"></param>
  1038. /// <param name="StartWeeklyNum"></param>
  1039. /// <param name="EndWeeklyNum"></param>
  1040. /// <returns></returns>
  1041. public string DefaultClassNo(Guid SchoolyearID, Guid freeSelectionCourseID, string StartWeeklyNum, string EndWeeklyNum)
  1042. {
  1043. if (StartWeeklyNum != "" && EndWeeklyNum != "")
  1044. {
  1045. //var freeSelectionCouseApply = FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyRepository.GetList(x => x.SchoolyearID == SchoolyearID && x.FreeSelectionCouseID == freeSelectionCourseID, x => x.EM_FreeSelectionCouseApplyTeachingSetting).ToList();
  1046. var FreeSelectionCouseApplyTeachingSetting = FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyTeachingSettingRepository.GetList(x => x.EM_FreeSelectionCouseApply.SchoolyearID == SchoolyearID && x.EM_FreeSelectionCouseApply.FreeSelectionCouseID == freeSelectionCourseID);
  1047. var list = FreeSelectionCouseApplyTeachingSetting.Select(x => new { WeeklyNum = x.StartWeeklyNum.Value + x.EndWeeklyNum.Value }).ToList();
  1048. List<int> l = new List<int> { Convert.ToInt32(StartWeeklyNum) + Convert.ToInt32(EndWeeklyNum) };
  1049. list.ForEach(x => l.Add(x.WeeklyNum));
  1050. l.Sort();
  1051. int index = l.IndexOf(Convert.ToInt32(StartWeeklyNum) + Convert.ToInt32(EndWeeklyNum)) + 1;
  1052. return index.ToString();
  1053. }
  1054. return "";
  1055. }
  1056. public List<ExecutableFreeSelectionCouseSchedulingView> GetSchedulingView(Guid FreeSelectionCouseApplyID)
  1057. {
  1058. //2016年12月1日15:28:47
  1059. //TODO :调整教学任务课程进度统计规则[将原按教学任务获取该教学任务下所对应的教学任务班课程进度信息调整为按对应教学任务班进行统计]
  1060. //var courseViewList = this.educationMissionClassDAL.GetCourseProcessView(x => x.EducationMissionID == educationMissionID)
  1061. // .OrderBy(x => x.Week).ToList();
  1062. var courseViewList = this.FreeSelectionCoursePlanDAL.GetSchedulingView(x => x.FreeSelectionCouseApplyID == FreeSelectionCouseApplyID)
  1063. .OrderBy(x => x.Weekday).ToList();
  1064. return courseViewList;
  1065. }
  1066. }
  1067. }