FreeSelectionCourseServices.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. namespace EMIS.CommonLogic.SelectCourse
  18. {
  19. public class FreeSelectionCourseServices : BaseWorkflowServices<EM_FreeSelectionCouseApply>, IFreeSelectionCourseServices
  20. {
  21. public FreeSelectionCoursePlanDAL FreeSelectionCoursePlanDAL { get; set; }
  22. public FreeSelectionCourseDAL FreeSelectionCourseDAL { get; set; }
  23. public FreeSelectionCouseTeachingModeRepository FreeSelectionCouseTeachingModeRepository { get; set; }
  24. public IGridResultSet<FreeSelectionCourseView> GetFreeSelectionCourseViewGrid(ConfiguretView configuretView,
  25. Guid? coursematerialID,Guid? departmentID, int? schoolcodeID, int? starttermID, int? isEnable, int pageIndex, int pageSize)
  26. {
  27. List<FreeSelectionCourseView> list = new List<FreeSelectionCourseView>();
  28. var query = FreeSelectionCourseDAL.GetFreeSelectionCourseViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  29. var queryTeachingModeType = FreeSelectionCourseDAL.GetTeachingModeTypeViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  30. if (coursematerialID.HasValue)
  31. {
  32. query = query.Where(x => x.CoursematerialID == coursematerialID);
  33. queryTeachingModeType = queryTeachingModeType.Where(x => x.CoursematerialID == coursematerialID);
  34. }
  35. if (departmentID.HasValue)
  36. {
  37. query = query.Where(x => x.DepartmentID == departmentID);
  38. queryTeachingModeType = queryTeachingModeType.Where(x => x.DepartmentID == departmentID);
  39. }
  40. //if (schoolcodeID.HasValue)
  41. //{
  42. // query = query.Where(x => x.SchoolcodeID == schoolcodeID);
  43. // queryTeachingModeType = queryTeachingModeType.Where(x => x.SchoolcodeID == schoolcodeID);
  44. //}
  45. //if (starttermID.HasValue)
  46. //{
  47. // query = query.Where(x => x.StarttermID == starttermID);
  48. // queryTeachingModeType = queryTeachingModeType.Where(x => x.StarttermID == starttermID);
  49. //}
  50. if (isEnable.HasValue)
  51. {
  52. query = query.Where(x => x.IsEnable == (isEnable == 1 ? true : false));
  53. queryTeachingModeType = queryTeachingModeType.Where(x => x.IsEnable == (isEnable == 1 ? true : false));
  54. }
  55. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  56. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
  57. var result=this.GetQueryByDataRangeByCollege(query).OrderBy(x => x.CreateTime).ToGridResultSet<FreeSelectionCourseView>(pageIndex, pageSize);
  58. result.rows.ForEach(x => x.TeachingModeName = string.Join(",", queryTeachingModeType.Where(w => w.FreeSelectionCouseID == x.FreeSelectionCouseID).Select(w => w.TeachingModeName)));
  59. return result;
  60. }
  61. public List<FreeSelectionCourseView> GetFreeSelectionCourseViewList(ConfiguretView configuretView,
  62. Guid? coursematerialID,Guid? departmentID, int? schoolcodeID, int? starttermID, int? isEnable)
  63. {
  64. List<FreeSelectionCourseView> list = new List<FreeSelectionCourseView>();
  65. var query = FreeSelectionCourseDAL.GetFreeSelectionCourseViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  66. var queryTeachingModeType = FreeSelectionCourseDAL.GetTeachingModeTypeViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  67. if (coursematerialID.HasValue)
  68. {
  69. query = query.Where(x => x.CoursematerialID == coursematerialID);
  70. queryTeachingModeType = queryTeachingModeType.Where(x => x.CoursematerialID == coursematerialID);
  71. }
  72. if (departmentID.HasValue)
  73. {
  74. query = query.Where(x => x.DepartmentID == departmentID);
  75. queryTeachingModeType = queryTeachingModeType.Where(x => x.DepartmentID == departmentID);
  76. }
  77. if (schoolcodeID.HasValue)
  78. {
  79. query = query.Where(x => x.SchoolcodeID == schoolcodeID);
  80. queryTeachingModeType = queryTeachingModeType.Where(x => x.SchoolcodeID == schoolcodeID);
  81. }
  82. if (starttermID.HasValue)
  83. {
  84. query = query.Where(x => x.StarttermID == starttermID);
  85. queryTeachingModeType = queryTeachingModeType.Where(x => x.StarttermID == starttermID);
  86. }
  87. if (isEnable.HasValue)
  88. {
  89. query = query.Where(x => x.IsEnable == (isEnable == 1 ? true : false));
  90. queryTeachingModeType = queryTeachingModeType.Where(x => x.IsEnable == (isEnable == 1 ? true : false));
  91. }
  92. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  93. list = this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).ToList();
  94. else
  95. list = this.GetQueryByDataRangeByCollege(query).ToList();
  96. list.ForEach(x => x.TeachingModeName = string.Join(",", queryTeachingModeType.Where(w => w.FreeSelectionCouseID == x.FreeSelectionCouseID).Select(w => w.TeachingModeName)));
  97. return list.OrderBy(x => x.CreateTime).ToList();
  98. }
  99. public EM_FreeSelectionCouse GetFreeSelectionCourse(Guid? freeSelectionCourseID)
  100. {
  101. System.Linq.Expressions.Expression<Func<EM_FreeSelectionCouse, bool>> expression =
  102. (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  103. expression = (x => x.FreeSelectionCouseID == freeSelectionCourseID);
  104. return FreeSelectionCourseDAL.FreeSelectionCouseRepository.GetSingle(expression, (x => x.CF_Department), (x => x.EM_Coursematerial));
  105. }
  106. public FreeSelectionCourseView GetFreeSelectionCourseView(Guid? freeSelectionCourseID)
  107. {
  108. var query = FreeSelectionCourseDAL.GetFreeSelectionCourseViewQueryable(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  109. return query.Where(x => x.FreeSelectionCouseID == freeSelectionCourseID).FirstOrDefault();
  110. }
  111. public EM_FreeSelectionCouseTeachingSetting GetFreeSelectionCourseTeachingSetting(Guid? freeSelectionCourseID)
  112. {
  113. //查询条件
  114. System.Linq.Expressions.Expression<Func<EM_FreeSelectionCouseTeachingSetting, bool>> expression = (x => true);
  115. expression = (x => x.FreeSelectionCouseID == freeSelectionCourseID);
  116. return FreeSelectionCourseDAL.FreeSelectionCouseTeachingSettingRepository.GetSingle(expression);
  117. }
  118. private string GetFreeSelectionCourseNo(EM_FreeSelectionCouse freeSelectionCourse)
  119. {
  120. var course = this.FreeSelectionCourseDAL.CoursematerialDAL.Value.CoursematerialRepository.GetSingle(x => x.CoursematerialID == freeSelectionCourse.CoursematerialID);
  121. if (course == null)
  122. {
  123. throw new Exception("找不到所选的课程资料。");
  124. }
  125. string code = course.CourseCode + "-" + (freeSelectionCourse.SchoolyearNumID ?? 0).ToString() + "-" + (freeSelectionCourse.SchoolcodeID ?? 0).ToString();
  126. return code;
  127. }
  128. public bool FreeSelectionCourseAdd(FreeSelectionCourseView freeSelectionCourseView)
  129. {
  130. EM_FreeSelectionCouse freeSelectionCourse;
  131. EM_FreeSelectionCouseTeachingSetting freeSelectionCourseTeachingSetting;
  132. try
  133. {
  134. if (this.FreeSelectionCourseDAL.FreeSelectionCouseRepository .GetList(
  135. x => x.CoursematerialID == freeSelectionCourseView.CoursematerialID
  136. && x.DepartmentID == freeSelectionCourseView.DepartmentID
  137. && x.CourseTypeID == freeSelectionCourseView.CourseTypeID).Count() > 0)
  138. {
  139. throw new Exception("该教研室对应的课程已经存在,请重新输入。");
  140. }
  141. freeSelectionCourse = new EM_FreeSelectionCouse();
  142. freeSelectionCourse.FreeSelectionCouseID = Guid.NewGuid();
  143. freeSelectionCourse.DepartmentID = freeSelectionCourseView.DepartmentID;
  144. freeSelectionCourse.CoursematerialID = freeSelectionCourseView.CoursematerialID;
  145. freeSelectionCourse.CourseStructureID = freeSelectionCourseView.CourseStructureID;
  146. freeSelectionCourse.CourseCategoryID = freeSelectionCourseView.CourseCategoryID;
  147. freeSelectionCourse.CourseTypeID = freeSelectionCourseView.CourseTypeID;
  148. freeSelectionCourse.CourseQualityID = freeSelectionCourseView.CourseQualityID;
  149. freeSelectionCourse.PracticeTypeID = freeSelectionCourseView.PracticeTypeID;
  150. freeSelectionCourse.ExaminationModeID = freeSelectionCourseView.ExaminationModeID;
  151. freeSelectionCourse.TeachinglanguageID = freeSelectionCourseView.TeachinglanguageID;
  152. freeSelectionCourse.SchoolyearNumID = freeSelectionCourseView.SchoolyearNumID;
  153. freeSelectionCourse.SchoolcodeID = freeSelectionCourseView.SchoolcodeID;
  154. //freeSelectionCourse.StarttermID = freeSelectionCourseView.StarttermID;
  155. freeSelectionCourse.IsEnable = freeSelectionCourseView.IsEnable;
  156. freeSelectionCourse.ResultTypeID = freeSelectionCourseView.ResultTypeID;
  157. freeSelectionCourse.Remark = freeSelectionCourseView.Remark;
  158. //最后计算选课编号
  159. //freeSelectionCourse.No = this.GetFreeSelectionCourseNo(freeSelectionCourse);
  160. this.SetNewStatus(freeSelectionCourse);
  161. freeSelectionCourseTeachingSetting = new EM_FreeSelectionCouseTeachingSetting();
  162. freeSelectionCourseTeachingSetting.FreeSelectionCouseID = freeSelectionCourse.FreeSelectionCouseID;
  163. freeSelectionCourseTeachingSetting.Credit = freeSelectionCourseView.Credit;
  164. freeSelectionCourseTeachingSetting.TheoryCourse = freeSelectionCourseView.TheoryCourse;
  165. freeSelectionCourseTeachingSetting.Practicehours = freeSelectionCourseView.Practicehours;
  166. freeSelectionCourseTeachingSetting.Trialhours = freeSelectionCourseView.Trialhours;
  167. freeSelectionCourseTeachingSetting.WeeklyNum = freeSelectionCourseView.WeeklyNum;
  168. freeSelectionCourseTeachingSetting.TheoryWeeklyNum = freeSelectionCourseView.TheoryWeeklyNum;
  169. freeSelectionCourseTeachingSetting.PracticeWeeklyNum = freeSelectionCourseView.PracticeWeeklyNum;
  170. freeSelectionCourseTeachingSetting.TrialWeeklyNum = freeSelectionCourseView.TrialWeeklyNum;
  171. freeSelectionCourseTeachingSetting.StartWeeklyNum = freeSelectionCourseView.StartWeeklyNum;
  172. freeSelectionCourseTeachingSetting.EndWeeklyNum = freeSelectionCourseView.EndWeeklyNum;
  173. freeSelectionCourseTeachingSetting.WeeklyHours = freeSelectionCourseView.WeeklyHours;
  174. if (freeSelectionCourseView.TeachingModeID != null)
  175. {
  176. TeachingModeTypeAdd(freeSelectionCourseView.TeachingModeID, freeSelectionCourse.FreeSelectionCouseID);
  177. }
  178. UnitOfWork.Add(freeSelectionCourse);
  179. UnitOfWork.Add(freeSelectionCourseTeachingSetting);
  180. UnitOfWork.Commit();
  181. return true;
  182. }
  183. catch (Exception)
  184. {
  185. throw;
  186. }
  187. }
  188. public bool FreeSelectionCourseUpdate(FreeSelectionCourseView freeSelectionCourseView)
  189. {
  190. EM_FreeSelectionCouse freeSelectionCourse;
  191. EM_FreeSelectionCouseTeachingSetting freeSelectionCourseTeachingSetting;
  192. try
  193. {
  194. if (this.FreeSelectionCourseDAL.FreeSelectionCouseRepository.GetList(
  195. x => x.CoursematerialID == freeSelectionCourseView.CoursematerialID
  196. && x.DepartmentID == freeSelectionCourseView.DepartmentID
  197. && x.CourseTypeID == freeSelectionCourseView.CourseTypeID
  198. && x.FreeSelectionCouseID != freeSelectionCourseView.FreeSelectionCouseID).Count() > 0)
  199. {
  200. throw new Exception("该课程已经存在,请重新输入。");
  201. }
  202. freeSelectionCourse = GetFreeSelectionCourse(freeSelectionCourseView.FreeSelectionCouseID);
  203. freeSelectionCourseTeachingSetting = GetFreeSelectionCourseTeachingSetting(freeSelectionCourseView.FreeSelectionCouseID);
  204. freeSelectionCourse.FreeSelectionCouseID = freeSelectionCourseView.FreeSelectionCouseID;
  205. freeSelectionCourse.DepartmentID = freeSelectionCourseView.DepartmentID;
  206. freeSelectionCourse.CoursematerialID = freeSelectionCourseView.CoursematerialID;
  207. freeSelectionCourse.CourseStructureID = freeSelectionCourseView.CourseStructureID;
  208. freeSelectionCourse.CourseCategoryID = freeSelectionCourseView.CourseCategoryID;
  209. freeSelectionCourse.CourseTypeID = freeSelectionCourseView.CourseTypeID;
  210. freeSelectionCourse.CourseQualityID = freeSelectionCourseView.CourseQualityID;
  211. freeSelectionCourse.PracticeTypeID = freeSelectionCourseView.PracticeTypeID;
  212. freeSelectionCourse.ExaminationModeID = freeSelectionCourseView.ExaminationModeID;
  213. freeSelectionCourse.TeachinglanguageID = freeSelectionCourseView.TeachinglanguageID;
  214. freeSelectionCourse.SchoolyearNumID = freeSelectionCourseView.SchoolyearNumID;
  215. freeSelectionCourse.SchoolcodeID = freeSelectionCourseView.SchoolcodeID;
  216. //freeSelectionCourse.StarttermID = freeSelectionCourseView.StarttermID;
  217. freeSelectionCourse.IsEnable = freeSelectionCourseView.IsEnable;
  218. freeSelectionCourse.ResultTypeID = freeSelectionCourseView.ResultTypeID;
  219. freeSelectionCourse.Remark = freeSelectionCourseView.Remark;
  220. this.SetModifyStatus(freeSelectionCourse);
  221. freeSelectionCourseTeachingSetting.Credit = freeSelectionCourseView.Credit;
  222. freeSelectionCourseTeachingSetting.TheoryCourse = freeSelectionCourseView.TheoryCourse;
  223. freeSelectionCourseTeachingSetting.Practicehours = freeSelectionCourseView.Practicehours;
  224. freeSelectionCourseTeachingSetting.Trialhours = freeSelectionCourseView.Trialhours;
  225. freeSelectionCourseTeachingSetting.WeeklyNum = freeSelectionCourseView.WeeklyNum;
  226. freeSelectionCourseTeachingSetting.TheoryWeeklyNum = freeSelectionCourseView.TheoryWeeklyNum;
  227. freeSelectionCourseTeachingSetting.PracticeWeeklyNum = freeSelectionCourseView.PracticeWeeklyNum;
  228. freeSelectionCourseTeachingSetting.TrialWeeklyNum = freeSelectionCourseView.TrialWeeklyNum;
  229. freeSelectionCourseTeachingSetting.StartWeeklyNum = freeSelectionCourseView.StartWeeklyNum;
  230. freeSelectionCourseTeachingSetting.EndWeeklyNum = freeSelectionCourseView.EndWeeklyNum;
  231. freeSelectionCourseTeachingSetting.WeeklyHours = freeSelectionCourseView.WeeklyHours;
  232. if (freeSelectionCourseView.TeachingModeID != null)
  233. {
  234. TeachingModeTypeAdd(freeSelectionCourseView.TeachingModeID, freeSelectionCourse.FreeSelectionCouseID);
  235. }
  236. UnitOfWork.Update(freeSelectionCourse);
  237. UnitOfWork.Update(freeSelectionCourseTeachingSetting);
  238. UnitOfWork.Commit();
  239. return true;
  240. }
  241. catch (Exception)
  242. {
  243. throw;
  244. }
  245. }
  246. private bool TeachingModeTypeAdd(List<int> list, Guid? freeSelectionCourseID)
  247. {
  248. try
  249. {
  250. if (list.Count > 0)
  251. {
  252. UnitOfWork.Delete<EM_FreeSelectionCouseTeachingMode>(x => x.FreeSelectionCouseID == freeSelectionCourseID);
  253. foreach (var i in list)
  254. {
  255. EM_FreeSelectionCouseTeachingMode teachingModeType = new EM_FreeSelectionCouseTeachingMode();
  256. teachingModeType.FreeSelectionCouseTeachingModeID = Guid.NewGuid();
  257. teachingModeType.FreeSelectionCouseID = freeSelectionCourseID;
  258. teachingModeType.TeachingModeID = i;
  259. this.SetNewStatus(teachingModeType);
  260. UnitOfWork.Add(teachingModeType);
  261. }
  262. }
  263. return true;
  264. }
  265. catch (Exception)
  266. {
  267. throw;
  268. }
  269. }
  270. public bool FreeSelectionCourseDelete(List<Guid?> freeSelectionCourseIDs)
  271. {
  272. try
  273. {
  274. if (freeSelectionCourseIDs.Count > 0)
  275. {
  276. UnitOfWork.Delete<EM_FreeSelectionCouseTeachingSetting>(x => freeSelectionCourseIDs.Contains(x.FreeSelectionCouseID));
  277. UnitOfWork.Delete<EM_FreeSelectionCouseTeachingMode>(x => freeSelectionCourseIDs.Contains(x.FreeSelectionCouseID));
  278. UnitOfWork.Delete<EM_FreeSelectionCouse>(x => freeSelectionCourseIDs.Contains(x.FreeSelectionCouseID));
  279. UnitOfWork.Commit();
  280. }
  281. return true;
  282. }
  283. catch (Exception)
  284. {
  285. throw;
  286. }
  287. }
  288. /// <summary>
  289. /// 根据任选课程获取授课方式
  290. /// </summary>
  291. /// <param name="freeSelectionCourseID"></param>
  292. /// <returns></returns>
  293. public List<int> GetTeachingModeType(Guid? freeSelectionCourseID)
  294. {
  295. List<int> list = new List<int>();
  296. return FreeSelectionCourseDAL.GetTeachingModeType(x => x.FreeSelectionCouseID == freeSelectionCourseID)
  297. .Select(x => x.Value ?? 0).ToList();
  298. }
  299. public EM_FreeSelectionCouse GetFreeSelectionCourseCourse(Guid? coursematerialID)
  300. {
  301. //查询条件
  302. System.Linq.Expressions.Expression<Func<EM_FreeSelectionCouse, bool>> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  303. expression = (x => x.CoursematerialID == coursematerialID);
  304. return FreeSelectionCourseDAL.FreeSelectionCouseRepository.GetSingle(expression, (x => x.CF_Department), (x => x.EM_Coursematerial));
  305. }
  306. public void SaveFreeSelectionCourseTeachers(Guid freeSelectionCourseApplyID, IList<FreeSelectionCourseApplyTeacherListView> teacherList)
  307. {
  308. var freeSelectionCourseApply = this.FreeSelectionCoursePlanDAL.FreeSelectionCouseApplyRepository
  309. .GetSingle(x => x.FreeSelectionCouseApplyID == freeSelectionCourseApplyID, (x => x.EM_FreeSelectionCouseApplyTeacher));
  310. freeSelectionCourseApply.EM_FreeSelectionCouseApplyTeacher.ToList().ForEach(x => this.UnitOfWork.Remove(x));
  311. //teacherList.ToList().ForEach(x =>
  312. //{
  313. // var freeSelectionCourseApplyStaffEntity = new EM_FreeSelectionCouseApplyStaff
  314. // {
  315. // FreeSelectionCouseApplyStaffID = Guid.NewGuid(),
  316. // FreeSelectionCouseApplyID = freeSelectionCourseApplyID,
  317. // UserID = x.UserID,
  318. // TeachingMethod = x.TeachingMethod
  319. // };
  320. // this.SetNewStatus(freeSelectionCourseApplyStaffEntity);
  321. // this.UnitOfWork.Add(freeSelectionCourseApplyStaffEntity);
  322. //});
  323. this.UnitOfWork.Commit();
  324. }
  325. }
  326. }