SelectCourseResultDAL.cs 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using System.Data.Entity;
  7. using EMIS.DataLogic.SystemDAL;
  8. using EMIS.ViewModel;
  9. using EMIS.DataLogic.Common.CalendarManage;
  10. using EMIS.DataLogic.Repositories;
  11. using EMIS.Entities;
  12. using EMIS.ViewModel.SelectCourse.SelectCourseResult;
  13. using EMIS.ViewModel.SelectCourse;
  14. using EMIS.ViewModel.Students;
  15. namespace EMIS.DataLogic.SelectCourse.SelectCourseResult
  16. {
  17. public class SelectCourseResultDAL
  18. {
  19. public FinallyScoreRepository FinallyScoreRepository { get; set; }
  20. public StudentRepository StudentRepository { get; set; }
  21. public ClassmajorRepository ClassmajorRepository { get; set; }
  22. public GrademajorRepository GrademajorRepository { get; set; }
  23. public FacultymajorRepository FacultymajorRepository { get; set; }
  24. public SpecialtyRepository SpecialtyRepository { get; set; }
  25. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  26. public SchoolyearRepository schoolyearRepository { get; set; }
  27. public SelectCourseTypeSettingRepository SelectCourseTypeSettingRepository { get; set; }
  28. public SelectCourseOpenControlSettingRepository SelectCourseOpenControlSettingRepository { get; set; }
  29. public Lazy<ParameterDAL> ParamterDAL { get; set; }
  30. public Lazy<SchoolYearDAL> SchoolYearDAL { get; set; }
  31. public CampusRepository campusRepository { get; set; }
  32. public CollegeRepository collegeRepository { get; set; }
  33. public DepartmentRepository departmentRepository { get; set; }
  34. public CoursematerialRepository CoursematerialRepository { get; set; }
  35. public ExecutableOptionalCourseRepository ExecutableOptionalCourseRepository { get; set; }//限选设定
  36. public ExecutableFreeSelectionCouseRepository ExecutableFreeSelectionCouseRepository { get; set; }//任选设定
  37. public OptionalCoursePlanRepository OptionalCoursePlanRepository { get; set; } //限修计划
  38. public FreeSelectionCourseGradeYearSettingRepository FreeSelectionCourseGradeYearSettingRepository { get; set; } //任选控制表
  39. public ExecutableOptionalCourseTeacherRepository ExecutableOptionalCourseTeacherRepository { get; set; } //限选设定任课老师表
  40. public ExecutableOptionalCourseTeachingModeRepository ExecutableOptionalCourseTeachingModeRepository { get; set; } //限选设定授课方式表
  41. public ExecutableOptionalCourseTeachingSettingRepository ExecutableOptionalCourseTeachingSettingRepository { get; set; } //限选设定教学设置表
  42. public ExecutableFreeSelectionCouseTeacherRepository ExecutableFreeSelectionCouseTeacherRepository { get; set; } //任选课程教师表
  43. public ExecutableFreeSelectionCouseTeachingModeRepository ExecutableFreeSelectionCouseTeachingModeRepository { get; set; } //任选设定授课方式表
  44. public ExecutableFreeSelectionCouseTeachingSettingRepository ExecutableFreeSelectionCouseTeachingSettingRepository { get; set; } //任选设定教学设置表
  45. public ExecutableFreeSelectionCouseSpecialtyRepository ExecutableFreeSelectionCouseSpecialtyRepository { get; set; }
  46. public ExecutableFreeSelectionCouseGradeYearRepository ExecutableFreeSelectionCouseGradeYearRepository { get; set; }
  47. public ExecutableFreeSelectionCouseSchedulingRepository ExecutableFreeSelectionCouseSchedulingRepository { get; set; }
  48. public CoursesTimeRepository coursesTimeRepository { get; set; }
  49. public ClassroomRepository ClassroomRepository { get; set; }
  50. /// <summary>
  51. /// 查询选课结果,0为限选,1为任选
  52. /// </summary>
  53. /// <param name="eocExp"></param>
  54. /// <param name="efsExp"></param>
  55. /// <returns></returns>
  56. public IQueryable<SelectCourseResultView> GetSelectCourseResultViewQueryable(Expression<Func<EM_ExecutableOptionalCourse, bool>>
  57. eocExp, Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> efsExp)
  58. {
  59. //1.0 获取限选设定的所有学生数据
  60. var executableOptionalCourseResult = (from eoc in ExecutableOptionalCourseRepository.GetList(eocExp)
  61. //from eoct in eoc.EM_ExecutableOptionalCourseTeacher
  62. //join a in(ExecutableOptionalCourseTeacherRepository.Entities.Where(x=>x.EM_ExecutableOptionalCourse=))
  63. //join eoct in ExecutableOptionalCourseTeacherRepository.Entities on eoc.ExecutableOptionalCourseID equals eoct.ExecutableOptionalCourseID
  64. //into tmp1
  65. //join eoctm in ExecutableOptionalCourseTeachingModeRepository.Entities on eoc.ExecutableOptionalCourseID equals eoctm.ExecutableOptionalCourseID
  66. //into tmp
  67. //from eoctm1 in tmp.DefaultIfEmpty()
  68. //join eocts in ExecutableOptionalCourseTeachingSettingRepository.Entities on eoc.ExecutableOptionalCourseID equals eocts.ExecutableOptionalCourseID
  69. //into tmp1 from eocts1 in tmp1.DefaultIfEmpty()
  70. select new SelectCourseResultView
  71. {
  72. ClassroomName = "",
  73. ID = eoc.ExecutableOptionalCourseID,
  74. StudentTotalNum = eoc.CF_Student.Count(),
  75. PeopleNumlower = eoc.PeopleNumlower,
  76. PeopleNumlimit = eoc.PeopleNumlimit,
  77. SchoolyearID = eoc.SchoolyearID,
  78. SchoolYearCode = null,
  79. CollegeID = eoc.CF_Grademajor.CF_Facultymajor.CollegeID,
  80. DepartmentID = eoc.DepartmentID,
  81. DepartmentName = eoc.EM_OptionalCoursePlan.CF_Department.Name,
  82. DefaultClassName = eoc.DefaultClassName,
  83. CoursematerialID = eoc.EM_OptionalCoursePlan.CoursematerialID,
  84. CourseCode = eoc.EM_OptionalCoursePlan.EM_Coursematerial.CourseCode,
  85. CourseName = eoc.EM_OptionalCoursePlan.EM_Coursematerial.CourseName,
  86. CourseTypeID = eoc.CourseTypeID,
  87. //CourseTypeName = "",
  88. CourseQualityID = eoc.CourseQualityID,
  89. SelectCourseType = 0,
  90. TheoryCourse = eoc.EM_ExecutableOptionalCourseTeachingSetting.TheoryCourse ?? 0,
  91. Practicehours = eoc.EM_ExecutableOptionalCourseTeachingSetting.Practicehours ?? 0,
  92. Trialhours = eoc.EM_ExecutableOptionalCourseTeachingSetting.Trialhours ?? 0,
  93. Credit = eoc.EM_ExecutableOptionalCourseTeachingSetting.Credit ?? 0,
  94. StartWeeklyNum = eoc.EM_ExecutableOptionalCourseTeachingSetting.StartWeeklyNum ?? 0,
  95. EndWeeklyNum = eoc.EM_ExecutableOptionalCourseTeachingSetting.EndWeeklyNum ?? 0,
  96. //StartEndWeeklyNum = eoc.EM_ExecutableOptionalCourseTeachingSetting.StartWeeklyNum != null && eoc.EM_ExecutableOptionalCourseTeachingSetting.EndWeeklyNum != null ? eoc.EM_ExecutableOptionalCourseTeachingSetting.StartWeeklyNum + "-" + eoc.EM_ExecutableOptionalCourseTeachingSetting.EndWeeklyNum : "",
  97. //TheoryCourse = eocts1.TheoryCourse,
  98. //Practicehours = eocts1.Practicehours,
  99. //Trialhours = eocts1.Trialhours,
  100. //Credit = eocts1.Credit??0,
  101. SchoolcodeID = eoc.EM_OptionalCoursePlan.SchoolcodeID,
  102. TeacherUserID = null,
  103. TeacherName = "",//eoct.CF_Staff.Sys_User.Name,
  104. //TeachingModeID = eoctm1.TeachingModeID,
  105. RecordStatus = eoc.RecordStatus,
  106. IsOpened = eoc.IsOpened.Value,
  107. });
  108. //2.0 获取任选设定的所有学生数据
  109. var executableFreeSelectionCouseResult = (from efs in ExecutableFreeSelectionCouseRepository.GetList(efsExp)
  110. join Scheduling in
  111. (from sc in ExecutableFreeSelectionCouseSchedulingRepository.Entities
  112. //join b in coursesTimeRepository.Entities on sc.CoursesTimeID equals b.CoursesTimeID
  113. //join c in DictionaryItemRepository.Entities on new { b.TimesSegment, DictionaryCode = "CF_TimesSegment" }
  114. //equals new { TimesSegment = c.Value.Value, c.DictionaryCode } into gbsta
  115. //from gicbsta in gbsta.DefaultIfEmpty()
  116. join d in ClassroomRepository.Entities on sc.ClassroomID equals d.ClassroomID
  117. group d by new { sc.ExecutableFreeSelectionCouseID } into g
  118. select new
  119. {
  120. ExecutableFreeSelectionCouseID = g.Key.ExecutableFreeSelectionCouseID,
  121. ClassroomName = g.Select(x => x.Name).FirstOrDefault(),
  122. }) on efs.ExecutableFreeSelectionCouseID equals Scheduling.ExecutableFreeSelectionCouseID
  123. into lj
  124. from Scheduling in lj.DefaultIfEmpty()
  125. //from efsct in efs.EM_ExecutableFreeSelectionCouseTeacher
  126. //join efsct in ExecutableFreeSelectionCouseTeacherRepository.Entities on efs.ExecutableFreeSelectionCouseID equals efsct.ExecutableFreeSelectionCouseID
  127. //into tmp1 from efsct in tmp1.DefaultIfEmpty()
  128. //join efsctm in ExecutableFreeSelectionCouseTeachingModeRepository.Entities on efs.ExecutableFreeSelectionCouseID equals efsctm.ExecutableFreeSelectionCouseID
  129. //into tmp
  130. //from efsctm1 in tmp.DefaultIfEmpty()
  131. //join efscts in ExecutableFreeSelectionCouseTeachingSettingRepository.Entities on efs.ExecutableFreeSelectionCouseID equals efscts.ExecutableFreeSelectionCouseID
  132. //into tmp1 from efscts1 in tmp1.DefaultIfEmpty()
  133. select new SelectCourseResultView
  134. {
  135. ClassroomName = Scheduling.ClassroomName,
  136. ID = efs.ExecutableFreeSelectionCouseID,
  137. StudentTotalNum = efs.CF_Student.Count(),
  138. PeopleNumlower = efs.PeopleNumlower,
  139. PeopleNumlimit = efs.PeopleNumlimit,
  140. SchoolyearID = efs.SchoolyearID,
  141. SchoolYearCode = null,
  142. CollegeID = efs.CF_Department.CollegeID,
  143. DepartmentID = efs.DepartmentID,
  144. DepartmentName = efs.EM_FreeSelectionCouse.CF_Department.Name,
  145. DefaultClassName = efs.DefaultClassName,
  146. CoursematerialID = efs.EM_FreeSelectionCouse.CoursematerialID,
  147. CourseCode = efs.EM_FreeSelectionCouse.EM_Coursematerial.CourseCode,
  148. CourseName = efs.EM_FreeSelectionCouse.EM_Coursematerial.CourseName,
  149. CourseTypeID = efs.CourseTypeID,
  150. //CourseTypeName = "",
  151. CourseQualityID = efs.CourseQualityID,
  152. SelectCourseType = 1,
  153. TheoryCourse = efs.EM_ExecutableFreeSelectionCouseTeachingSetting.TheoryCourse ?? 0,
  154. Practicehours = efs.EM_ExecutableFreeSelectionCouseTeachingSetting.Practicehours ?? 0,
  155. Trialhours = efs.EM_ExecutableFreeSelectionCouseTeachingSetting.Trialhours ?? 0,
  156. Credit = efs.EM_ExecutableFreeSelectionCouseTeachingSetting.Credit ?? 0,
  157. StartWeeklyNum = efs.EM_ExecutableFreeSelectionCouseTeachingSetting.StartWeeklyNum ?? 0,
  158. EndWeeklyNum = efs.EM_ExecutableFreeSelectionCouseTeachingSetting.EndWeeklyNum ?? 0,
  159. //StartEndWeeklyNum = efs.EM_ExecutableFreeSelectionCouseTeachingSetting.StartWeeklyNum != null && efs.EM_ExecutableFreeSelectionCouseTeachingSetting.EndWeeklyNum != null ? efs.EM_ExecutableFreeSelectionCouseTeachingSetting.StartWeeklyNum + "-" + efs.EM_ExecutableFreeSelectionCouseTeachingSetting.EndWeeklyNum : "",
  160. //TheoryCourse = efscts1.TheoryCourse,
  161. //Practicehours = efscts1.Practicehours,
  162. //Trialhours = efscts1.Trialhours,
  163. //Credit = efscts1.Credit??0,
  164. SchoolcodeID = efs.EM_FreeSelectionCouse.SchoolcodeID,
  165. TeacherUserID = null,
  166. TeacherName = "",//efsct.CF_Staff.Sys_User.Name,
  167. //TeachingModeID = efsctm1.TeachingModeID,
  168. RecordStatus = efs.RecordStatus,
  169. IsOpened = true,
  170. });
  171. //3.0 合并限选/任选
  172. var result = from a in executableOptionalCourseResult.Concat(executableFreeSelectionCouseResult)
  173. join s in schoolyearRepository.Entities on a.SchoolyearID equals s.SchoolyearID
  174. //join dis in DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(CF_CourseType).Name) on a.CourseTypeID equals dis.Value into ddis
  175. //from edis in ddis.DefaultIfEmpty()
  176. //join c in CoursematerialRepository.Entities on a.CourseCode equals c.CourseCode
  177. select new SelectCourseResultView
  178. {
  179. ClassroomName = a.ClassroomName,
  180. ID = a.ID,
  181. StudentTotalNum = a.StudentTotalNum,
  182. PeopleNumlower = a.PeopleNumlower,
  183. PeopleNumlimit = a.PeopleNumlimit,
  184. SchoolyearID = a.SchoolyearID,
  185. SchoolYearCode = s.Code,
  186. CollegeID = a.CollegeID,
  187. DepartmentID = a.DepartmentID,
  188. DepartmentName = a.DepartmentName,
  189. DefaultClassName = a.DefaultClassName,
  190. CoursematerialID = a.CoursematerialID,
  191. CourseCode = a.CourseCode,
  192. CourseName = a.CourseName,
  193. CourseTypeID = a.CourseTypeID,
  194. //CourseTypeName = a.CourseTypeName,
  195. CourseQualityID = a.CourseQualityID,
  196. SelectCourseType = a.SelectCourseType,
  197. TheoryCourse = a.TheoryCourse ?? 0,
  198. Practicehours = a.Practicehours ?? 0,
  199. Trialhours = a.Trialhours ?? 0,
  200. Credit = a.Credit ?? 0,
  201. StartWeeklyNum = a.StartWeeklyNum ?? 0,
  202. EndWeeklyNum = a.EndWeeklyNum ?? 0,
  203. //StartEndWeeklyNum = a.StartEndWeeklyNum,
  204. SchoolcodeID = a.SchoolcodeID,
  205. TeacherUserID = null,
  206. TeacherName = a.TeacherName,
  207. //TeachingModeID = a.TeachingModeID,
  208. RecordStatus = a.RecordStatus,
  209. IsOpened = a.IsOpened,
  210. //TeachingModeName = GetSelectCourseResultTeachingMode1(a.ID)
  211. };
  212. return result;
  213. }
  214. public IQueryable<SelectCourseResultView> GetSelectCourseResultTeacher(Expression<Func<EM_ExecutableOptionalCourse, bool>>
  215. eocExp, Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> efsExp)
  216. {
  217. //1.0 获取限选设定数据
  218. var executableOptionalCourseResult = (from eoc in ExecutableOptionalCourseRepository.Entities
  219. from eoct in eoc.EM_ExecutableOptionalCourseTeacher
  220. group eoc by new
  221. {
  222. ID = eoc.ExecutableOptionalCourseID,
  223. SchoolyearID = eoc.SchoolyearID,
  224. CourseTypeID = eoc.CourseTypeID,
  225. //eoct.CF_Staff.UserID,
  226. eoct.CF_Staff.Sys_User.Name,
  227. RecordStatus = eoc.RecordStatus,
  228. } into g
  229. select new SelectCourseResultView
  230. {
  231. ID = g.Key.ID,
  232. SchoolyearID = g.Key.SchoolyearID,
  233. CourseTypeID = g.Key.CourseTypeID,
  234. SelectCourseType = 0,
  235. //TeacherUserID = g.Key.UserID,
  236. TeacherName = g.Key.Name,
  237. RecordStatus = g.Key.RecordStatus,
  238. });
  239. //2.0 获取任选设定数据
  240. var executableFreeSelectionCouseResult = executableOptionalCourseResult.Concat(
  241. from efs in ExecutableFreeSelectionCouseRepository.Entities
  242. from efsct in efs.EM_ExecutableFreeSelectionCouseTeacher
  243. group efs by new
  244. {
  245. ID = efs.ExecutableFreeSelectionCouseID,
  246. SchoolyearID = efs.SchoolyearID,
  247. CourseTypeID = efs.CourseTypeID,
  248. //efsct.CF_Staff.UserID,
  249. efsct.CF_Staff.Sys_User.Name,
  250. RecordStatus = efs.RecordStatus,
  251. } into g
  252. select new SelectCourseResultView
  253. {
  254. ID = g.Key.ID,
  255. SchoolyearID = g.Key.SchoolyearID,
  256. CourseTypeID = g.Key.CourseTypeID,
  257. SelectCourseType = 1,
  258. //TeacherUserID = g.Key.UserID,
  259. TeacherName = g.Key.Name,
  260. RecordStatus = g.Key.RecordStatus,
  261. });
  262. return executableFreeSelectionCouseResult;
  263. }
  264. public string GetSelectCourseResultTeachingMode1(Guid? ID)
  265. {
  266. var query = (from eoc in ExecutableOptionalCourseRepository.Entities.Where(x => x.ExecutableOptionalCourseID == ID)
  267. from eoct in eoc.EM_ExecutableOptionalCourseTeachingMode
  268. select new
  269. {
  270. //ID = eoc.ExecutableOptionalCourseID,
  271. //SchoolyearID = g.Key.SchoolyearID,
  272. //CourseTypeID = g.Key.CourseTypeID,
  273. //SelectCourseType = 0,
  274. //TeacherUserID = g.Key.UserID,
  275. TeachingModeID = eoct.TeachingModeID
  276. }).ToList();
  277. string a = string.Join(",", query);
  278. return a;
  279. }
  280. public IQueryable<SelectCourseResultView> GetSelectCourseResultTeachingMode(Expression<Func<EM_ExecutableOptionalCourse, bool>>
  281. eocExp, Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> efsExp)
  282. {
  283. //1.0 获取限选设定数据
  284. var executableOptionalCourseResult = (from eoc in ExecutableOptionalCourseRepository.Entities
  285. from eoct in eoc.EM_ExecutableOptionalCourseTeachingMode
  286. group eoc by new
  287. {
  288. ID = eoc.ExecutableOptionalCourseID,
  289. //SchoolyearID = eoc.SchoolyearID,
  290. //CourseTypeID = eoc.CourseTypeID,
  291. TeachingModeID = eoct.TeachingModeID,
  292. RecordStatus = eoc.RecordStatus,
  293. } into g
  294. select new SelectCourseResultView
  295. {
  296. ID = g.Key.ID,
  297. //SchoolyearID = g.Key.SchoolyearID,
  298. //CourseTypeID = g.Key.CourseTypeID,
  299. SelectCourseType = 0,
  300. //TeacherUserID = g.Key.UserID,
  301. TeachingModeID = g.Key.TeachingModeID,
  302. RecordStatus = g.Key.RecordStatus,
  303. });
  304. //2.0 获取任选设定数据
  305. var executableFreeSelectionCouseResult = executableOptionalCourseResult.Concat(
  306. from efs in ExecutableFreeSelectionCouseRepository.Entities
  307. from efsct in efs.EM_ExecutableFreeSelectionCouseTeachingMode
  308. group efs by new
  309. {
  310. ID = efs.ExecutableFreeSelectionCouseID,
  311. //SchoolyearID = efs.SchoolyearID,
  312. //CourseTypeID = efs.CourseTypeID,
  313. //efsct.CF_Staff.UserID,
  314. //efsct.CF_Staff.Sys_User.Name,
  315. TeachingModeID = efsct.TeachingModeID,
  316. RecordStatus = efs.RecordStatus,
  317. } into g
  318. select new SelectCourseResultView
  319. {
  320. ID = g.Key.ID,
  321. //SchoolyearID = g.Key.SchoolyearID,
  322. //CourseTypeID = g.Key.CourseTypeID,
  323. SelectCourseType = 1,
  324. //TeacherUserID = g.Key.UserID,
  325. //TeacherName = g.Key.Name,
  326. TeachingModeID = g.Key.TeachingModeID,
  327. RecordStatus = g.Key.RecordStatus,
  328. });
  329. return executableFreeSelectionCouseResult;
  330. }
  331. public Guid GetSelectCourseSchoolyear()
  332. {
  333. var selectCourseSchoolyear = ParamterDAL.Value.ParameterRepository.GetSingle(x => x.ParameterTypeID == (int)CF_ParameterType.SelectCourseSchoolyear);
  334. if (selectCourseSchoolyear != null && selectCourseSchoolyear.Value != null)
  335. {
  336. return new Guid(selectCourseSchoolyear.Value);
  337. }
  338. else
  339. {
  340. return this.SchoolYearDAL.Value.GetSchoolYearQueryable(x => x.IsCurrent).FirstOrDefault().SchoolYearID.Value;
  341. }
  342. }
  343. public IQueryable<StudentSelectCourseView> GetStudentSelectCourseResultView(Guid userID)
  344. {
  345. DateTime nowTime = DateTime.Now;
  346. var selectCourseSchoolyearID = this.GetSelectCourseSchoolyear();
  347. var student = GetBaseStudentViewQueryable(userID, selectCourseSchoolyearID).FirstOrDefault();
  348. List<int?> OptionalCourseStatus = new List<int?> { (int)EM_SelectCourseResultStatus.Opened };
  349. var q = (
  350. from s in StudentRepository.GetList(x => x.UserID == userID)
  351. join eoc in ExecutableOptionalCourseRepository.Entities on s.CF_Classmajor.GrademajorID equals eoc.GrademajorID
  352. join eocts in ExecutableOptionalCourseTeachingSettingRepository.Entities on eoc.ExecutableOptionalCourseID equals eocts.ExecutableOptionalCourseID
  353. into tmp
  354. from ecots1 in tmp.DefaultIfEmpty()
  355. join depart in departmentRepository.Entities on eoc.DepartmentID equals depart.DepartmentID into tmp2
  356. from de1 in tmp2.DefaultIfEmpty()
  357. join college in collegeRepository.Entities on de1.CollegeID equals college.CollegeID into tmp3
  358. from co1 in tmp3.DefaultIfEmpty()
  359. join campus in campusRepository.Entities on co1.CampusID equals campus.CampusID into tmp4
  360. from ca1 in tmp4.DefaultIfEmpty()
  361. from eoccc in eoc.CF_Classmajor.Where(x => x.ClassmajorID == s.ClassmajorID).DefaultIfEmpty()
  362. //from efsc in ExecutableFreeSelectionCouseRepository.Entities
  363. join scts in SelectCourseTypeSettingRepository
  364. .GetList(x => x.SchoolyearID == selectCourseSchoolyearID) on (int)EM_SelectCourseType.OptionalCourse equals scts.SelectCourseTypeID into dscts
  365. from scts in dscts.DefaultIfEmpty()
  366. join scocs in SelectCourseOpenControlSettingRepository
  367. .GetList(x => x.SchoolyearID == selectCourseSchoolyearID) on eoc.GrademajorID equals scocs.GrademajorID
  368. into dscocs
  369. from escocs in dscocs.DefaultIfEmpty()
  370. from eoccs in eoc.CF_Student.Where(x => x.UserID == userID).DefaultIfEmpty()
  371. join eoccs1 in
  372. (
  373. from eoc in ExecutableOptionalCourseRepository.Entities
  374. from eoccs in eoc.CF_Student
  375. group eoc by eoc.ExecutableOptionalCourseID into g
  376. select new { ExecutableOptionalCourseID = g.Key, StudentCount = g.Count() }
  377. ) on eoc.ExecutableOptionalCourseID equals eoccs1.ExecutableOptionalCourseID into deoccs1
  378. from eeoccs1 in deoccs1.DefaultIfEmpty()
  379. where eoc.SchoolyearID == selectCourseSchoolyearID
  380. //&& eoc.IsOpened == true
  381. && OptionalCourseStatus.Contains(eoc.RecordStatus)
  382. && eoccc.ClassmajorID != null
  383. //&& scts.StartTime <= nowTime && scts.EndTime >= nowTime
  384. //&& ((escocs.SelectCourseOpenControlSettingID == null) || (escocs.StartTime <= nowTime && escocs.EndTime >= nowTime))
  385. //|| eoccs.UserID != null
  386. select new StudentSelectCourseView
  387. {
  388. ClassroomName = "",
  389. ID = eoc.ExecutableOptionalCourseID,
  390. CampusName = ca1.Name,
  391. DepartmentID = eoc.DepartmentID,
  392. DepartmentName = de1.Name,
  393. StartWeeklyNum = ecots1.StartWeeklyNum ?? 0,
  394. EndWeeklyNum = ecots1.EndWeeklyNum ?? 0,
  395. StartTime=scts.StartTime,
  396. EndTime=scts.EndTime,
  397. //IsNeedMaterial = efsc.IsNeedMaterial ?? false,
  398. SelectCourseID = eoc.ExecutableOptionalCourseID,
  399. CoursematerialID = eoc.EM_OptionalCoursePlan.CoursematerialID ?? Guid.Empty,
  400. CourseName = eoc.EM_OptionalCoursePlan.EM_Coursematerial.CourseName,
  401. Credit = eoc.EM_ExecutableOptionalCourseTeachingSetting.Credit,
  402. ClassName = eoc.DefaultClassName,
  403. SelectCourseTypeID = (int)EM_SelectCourseType.OptionalCourse,
  404. SelectCourseTypeOrderID = 0,
  405. SelectCourseTypeName = "限选课",
  406. PeopleNumlimit = eoc.PeopleNumlimit,
  407. StudentCount = (eeoccs1.ExecutableOptionalCourseID == null ? 0 : eeoccs1.StudentCount),
  408. IsSelected = (eoccs.UserID != null)
  409. }
  410. );
  411. //任选
  412. q = q.Concat(from efsc in ExecutableFreeSelectionCouseRepository.Entities
  413. join scts in SelectCourseTypeSettingRepository
  414. .GetList(x => x.SchoolyearID == selectCourseSchoolyearID) on (int)EM_SelectCourseType.FreeSelectionCouse equals scts.SelectCourseTypeID into dscts
  415. from scts in dscts.DefaultIfEmpty()
  416. from efsccs in efsc.CF_Student.Where(x => x.UserID == userID).DefaultIfEmpty()
  417. join efsccs1 in
  418. (
  419. from efsc in ExecutableFreeSelectionCouseRepository.Entities
  420. from efsccs in efsc.CF_Student
  421. group efsc by efsc.ExecutableFreeSelectionCouseID into g
  422. select new { ExecutableFreeSelectionCouseID = g.Key, StudentCount = g.Count() }
  423. ) on efsc.ExecutableFreeSelectionCouseID equals efsccs1.ExecutableFreeSelectionCouseID into defsccs1
  424. from eefsccs1 in defsccs1.DefaultIfEmpty()
  425. join eocts in ExecutableFreeSelectionCouseTeachingSettingRepository.Entities on efsc.ExecutableFreeSelectionCouseID equals eocts.ExecutableFreeSelectionCouseID
  426. into tmp
  427. from ecots1 in tmp.DefaultIfEmpty()
  428. join de in departmentRepository.Entities on efsc.DepartmentID equals de.DepartmentID into tmp2
  429. from de1 in tmp2.DefaultIfEmpty()
  430. join college in collegeRepository.Entities on de1.CollegeID equals college.CollegeID into tmp3
  431. from co1 in tmp3.DefaultIfEmpty()
  432. join campus in campusRepository.Entities on co1.CampusID equals campus.CampusID into tmp4
  433. from ca1 in tmp4.DefaultIfEmpty()
  434. join Scheduling in
  435. (from sc in ExecutableFreeSelectionCouseSchedulingRepository.Entities
  436. //join b in coursesTimeRepository.Entities on sc.CoursesTimeID equals b.CoursesTimeID
  437. //join c in DictionaryItemRepository.Entities on new { b.TimesSegment, DictionaryCode = "CF_TimesSegment" }
  438. //equals new { TimesSegment = c.Value.Value, c.DictionaryCode } into gbsta
  439. //from gicbsta in gbsta.DefaultIfEmpty()
  440. join d in ClassroomRepository.Entities on sc.ClassroomID equals d.ClassroomID
  441. group d by new { sc.ExecutableFreeSelectionCouseID } into g
  442. select new
  443. {
  444. ExecutableFreeSelectionCouseID = g.Key.ExecutableFreeSelectionCouseID,
  445. ClassroomName = g.Select(x => x.Name).FirstOrDefault(),
  446. }) on efsc.ExecutableFreeSelectionCouseID equals Scheduling.ExecutableFreeSelectionCouseID
  447. into lj
  448. from Scheduling in lj.DefaultIfEmpty()
  449. //任选设定可选专业表
  450. join efscs in ExecutableFreeSelectionCouseSpecialtyRepository.Entities on new { efsc.ExecutableFreeSelectionCouseID, student.SpecialtyID }
  451. equals new { ExecutableFreeSelectionCouseID = efscs.ExecutableFreeSelectionCouseID.Value, SpecialtyID = efscs.SpecialtyID }
  452. into tmp1
  453. from efscs in tmp1.DefaultIfEmpty()
  454. //任选设定可选年级表
  455. join efscgy in ExecutableFreeSelectionCouseGradeYearRepository.Entities on new { ExecutableFreeSelectionCouseID = efsc.ExecutableFreeSelectionCouseID, student.GradeYear } equals new { ExecutableFreeSelectionCouseID = efscgy.ExecutableFreeSelectionCouseID.Value, efscgy.GradeYear }
  456. into tmp5
  457. from efscgy in tmp5.DefaultIfEmpty()
  458. where efsc.SchoolyearID == selectCourseSchoolyearID
  459. && OptionalCourseStatus.Contains(efsc.RecordStatus)
  460. //&& efsc.IsOpened == true
  461. //&& ((scts.SelectCourseTypeSettingID == null) || (scts.StartTime <= nowTime && scts.EndTime >= nowTime))
  462. && (efsc.EM_ExecutableFreeSelectionCouseSpecialty.Count == 0 || efscs.SpecialtyID == student.SpecialtyID)
  463. && (efsc.EM_ExecutableFreeSelectionCouseGradeYear.Count == 0 || efscgy.GradeYear == student.GradeYear)
  464. //|| efsccs.UserID != null
  465. select new StudentSelectCourseView
  466. {
  467. ClassroomName = Scheduling.ClassroomName,
  468. ID = efsc.ExecutableFreeSelectionCouseID,
  469. CampusName = ca1.Name,
  470. DepartmentID = efsc.DepartmentID,
  471. DepartmentName = de1.Name,
  472. StartWeeklyNum = ecots1.StartWeeklyNum ?? 0,
  473. EndWeeklyNum = ecots1.EndWeeklyNum ?? 0,
  474. StartTime = scts.StartTime,
  475. EndTime = scts.EndTime,
  476. //IsNeedMaterial = efsc.IsNeedMaterial ?? false,
  477. SelectCourseID = efsc.ExecutableFreeSelectionCouseID,
  478. CoursematerialID = efsc.EM_FreeSelectionCouse.CoursematerialID ?? Guid.Empty,
  479. CourseName = efsc.EM_FreeSelectionCouse.EM_Coursematerial.CourseName,
  480. Credit = efsc.EM_ExecutableFreeSelectionCouseTeachingSetting.Credit,
  481. ClassName = efsc.DefaultClassName,
  482. SelectCourseTypeID = (int)EM_SelectCourseType.FreeSelectionCouse,
  483. SelectCourseTypeOrderID = (int)EM_SelectCourseType.FreeSelectionCouse,
  484. SelectCourseTypeName = "任选课",
  485. PeopleNumlimit = efsc.PeopleNumlimit,
  486. StudentCount = (eefsccs1.ExecutableFreeSelectionCouseID == null ? 0 : eefsccs1.StudentCount),
  487. IsSelected = (efsccs.UserID != null)
  488. });
  489. //if (student.InSchoolStatusID != (int)EMIS.ViewModel.CF_InschoolStatus.InSchool)//不是在校状态的直接null,不显示
  490. // throw new Exception("不是在校状态不能选课");
  491. return q;
  492. }
  493. public IQueryable<StudentSelectCourseView> GetStudentSelectedCourseResultView(Expression<Func<EM_ExecutableOptionalCourse, bool>>
  494. eocExp, Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> efsExp)
  495. {
  496. //1.0 获取限选设定的所有学生数据
  497. var executableOptionalCourseResult = (from eoc in ExecutableOptionalCourseRepository.GetList(eocExp)
  498. //from eoct in eoc.EM_ExecutableOptionalCourseTeacher
  499. //join a in(ExecutableOptionalCourseTeacherRepository.Entities.Where(x=>x.EM_ExecutableOptionalCourse=))
  500. //join eoct in ExecutableOptionalCourseTeacherRepository.Entities on eoc.ExecutableOptionalCourseID equals eoct.ExecutableOptionalCourseID
  501. //into tmp1
  502. //join eoctm in ExecutableOptionalCourseTeachingModeRepository.Entities on eoc.ExecutableOptionalCourseID equals eoctm.ExecutableOptionalCourseID
  503. //into tmp
  504. //from eoctm1 in tmp.DefaultIfEmpty()
  505. //join eocts in ExecutableOptionalCourseTeachingSettingRepository.Entities on eoc.ExecutableOptionalCourseID equals eocts.ExecutableOptionalCourseID
  506. //into tmp1 from eocts1 in tmp1.DefaultIfEmpty()
  507. select new StudentSelectCourseView
  508. {
  509. ID = eoc.ExecutableOptionalCourseID,
  510. //StudentTotalNum = eoc.CF_Student.Count(),
  511. //PeopleNumlower = eoc.PeopleNumlower,
  512. //PeopleNumlimit = eoc.PeopleNumlimit,
  513. SchoolyearID = eoc.SchoolyearID,
  514. SchoolYearCode = null,
  515. CampusName = eoc.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.Name,
  516. CollegeID = eoc.CF_Grademajor.CF_Facultymajor.CollegeID,
  517. DefaultClassName = eoc.DefaultClassName,
  518. CoursematerialID = eoc.EM_OptionalCoursePlan.CoursematerialID,
  519. CourseCode = eoc.EM_OptionalCoursePlan.EM_Coursematerial.CourseCode,
  520. CourseName = eoc.EM_OptionalCoursePlan.EM_Coursematerial.CourseName,
  521. CourseTypeID = eoc.CourseTypeID,
  522. //CourseTypeName = "",
  523. CourseQualityID = eoc.CourseQualityID,
  524. SelectCourseTypeID = (int)EM_SelectCourseType.OptionalCourse,
  525. SelectCourseTypeName = "限选课",
  526. TheoryCourse = eoc.EM_ExecutableOptionalCourseTeachingSetting.TheoryCourse ?? 0,
  527. Practicehours = eoc.EM_ExecutableOptionalCourseTeachingSetting.Practicehours ?? 0,
  528. Trialhours = eoc.EM_ExecutableOptionalCourseTeachingSetting.Trialhours ?? 0,
  529. Credit = eoc.EM_ExecutableOptionalCourseTeachingSetting.Credit ?? 0,
  530. WeeklyNum = eoc.EM_ExecutableOptionalCourseTeachingSetting.WeeklyNum,
  531. StartWeeklyNum = eoc.EM_ExecutableOptionalCourseTeachingSetting.StartWeeklyNum ?? 0,
  532. EndWeeklyNum = eoc.EM_ExecutableOptionalCourseTeachingSetting.EndWeeklyNum ?? 0,
  533. //TheoryCourse = eocts1.TheoryCourse,
  534. //Practicehours = eocts1.Practicehours,
  535. //Trialhours = eocts1.Trialhours,
  536. //Credit = eocts1.Credit??0,
  537. //CoursesTimeID = null,
  538. //CoursesTimeName = "",
  539. //ClassroomID = null,
  540. ClassroomName = "",
  541. SchoolcodeID = eoc.EM_OptionalCoursePlan.SchoolcodeID,
  542. TeacherUserID = null,
  543. TeacherName = "",//eoct.CF_Staff.Sys_User.Name,
  544. //TeachingModeID = eoctm1.TeachingModeID,
  545. RecordStatus = eoc.RecordStatus,
  546. IsOpened = eoc.IsOpened.Value,
  547. });
  548. //2.0 获取任选设定的所有学生数据
  549. var executableFreeSelectionCouseResult = (from efs in ExecutableFreeSelectionCouseRepository.GetList(efsExp)
  550. join Scheduling in
  551. (from sc in ExecutableFreeSelectionCouseSchedulingRepository.Entities
  552. //join b in coursesTimeRepository.Entities on sc.CoursesTimeID equals b.CoursesTimeID
  553. //join c in DictionaryItemRepository.Entities on new { b.TimesSegment, DictionaryCode = "CF_TimesSegment" }
  554. //equals new { TimesSegment = c.Value.Value, c.DictionaryCode } into gbsta
  555. //from gicbsta in gbsta.DefaultIfEmpty()
  556. join d in ClassroomRepository.Entities on sc.ClassroomID equals d.ClassroomID
  557. group d by new { sc.ExecutableFreeSelectionCouseID } into g
  558. select new
  559. {
  560. ExecutableFreeSelectionCouseID = g.Key.ExecutableFreeSelectionCouseID,
  561. ClassroomName = g.Select(x => x.Name).FirstOrDefault(),
  562. }) on efs.ExecutableFreeSelectionCouseID equals Scheduling.ExecutableFreeSelectionCouseID
  563. into lj
  564. from Scheduling in lj.DefaultIfEmpty()
  565. //from efsct in efs.EM_ExecutableFreeSelectionCouseTeacher
  566. //join efsct in ExecutableFreeSelectionCouseTeacherRepository.Entities on efs.ExecutableFreeSelectionCouseID equals efsct.ExecutableFreeSelectionCouseID
  567. //into tmp1 from efsct in tmp1.DefaultIfEmpty()
  568. //join efsctm in ExecutableFreeSelectionCouseTeachingModeRepository.Entities on efs.ExecutableFreeSelectionCouseID equals efsctm.ExecutableFreeSelectionCouseID
  569. //into tmp
  570. //from efsctm1 in tmp.DefaultIfEmpty()
  571. //join efscts in ExecutableFreeSelectionCouseTeachingSettingRepository.Entities on efs.ExecutableFreeSelectionCouseID equals efscts.ExecutableFreeSelectionCouseID
  572. //into tmp1 from efscts1 in tmp1.DefaultIfEmpty()
  573. select new StudentSelectCourseView
  574. {
  575. ID = efs.ExecutableFreeSelectionCouseID,
  576. //StudentTotalNum = efs.CF_Student.Count(),
  577. //PeopleNumlower = efs.PeopleNumlower,
  578. //PeopleNumlimit = efs.PeopleNumlimit,
  579. SchoolyearID = efs.SchoolyearID,
  580. SchoolYearCode = null,
  581. CampusName = efs.CF_Department.CF_College.CF_Campus.Name,
  582. CollegeID = efs.CF_Department.CollegeID,
  583. DefaultClassName = efs.DefaultClassName,
  584. CoursematerialID = efs.EM_FreeSelectionCouse.CoursematerialID,
  585. CourseCode = efs.EM_FreeSelectionCouse.EM_Coursematerial.CourseCode,
  586. CourseName = efs.EM_FreeSelectionCouse.EM_Coursematerial.CourseName,
  587. CourseTypeID = efs.CourseTypeID,
  588. //CourseTypeName = "",
  589. CourseQualityID = efs.CourseQualityID,
  590. SelectCourseTypeID = (int)EM_SelectCourseType.FreeSelectionCouse,
  591. SelectCourseTypeName = "任选课",
  592. TheoryCourse = efs.EM_ExecutableFreeSelectionCouseTeachingSetting.TheoryCourse ?? 0,
  593. Practicehours = efs.EM_ExecutableFreeSelectionCouseTeachingSetting.Practicehours ?? 0,
  594. Trialhours = efs.EM_ExecutableFreeSelectionCouseTeachingSetting.Trialhours ?? 0,
  595. Credit = efs.EM_ExecutableFreeSelectionCouseTeachingSetting.Credit ?? 0,
  596. WeeklyNum = efs.EM_ExecutableFreeSelectionCouseTeachingSetting.WeeklyNum,
  597. StartWeeklyNum = efs.EM_ExecutableFreeSelectionCouseTeachingSetting.StartWeeklyNum ?? 0,
  598. EndWeeklyNum = efs.EM_ExecutableFreeSelectionCouseTeachingSetting.EndWeeklyNum ?? 0,
  599. //TheoryCourse = efscts1.TheoryCourse,
  600. //Practicehours = efscts1.Practicehours,
  601. //Trialhours = efscts1.Trialhours,
  602. //Credit = efscts1.Credit??0,
  603. //CoursesTimeID = Scheduling.CoursesTimeID,
  604. //CoursesTimeName = Scheduling.EM_CoursesTime.StartHour.ToString() + ":" + se.EM_CoursesTime.StartMinutes.ToString() + "-" + se.EM_CoursesTime.EndHour.ToString() + ":" + se.EM_CoursesTime.EndMinutes.ToString(),
  605. //ClassroomID = Scheduling.ClassroomID,
  606. ClassroomName = Scheduling.ClassroomName,
  607. SchoolcodeID = efs.EM_FreeSelectionCouse.SchoolcodeID,
  608. TeacherUserID = null,
  609. TeacherName = "",//efsct.CF_Staff.Sys_User.Name,
  610. //TeachingModeID = efsctm1.TeachingModeID,
  611. RecordStatus = efs.RecordStatus,
  612. IsOpened = true,
  613. });
  614. //3.0 合并限选/任选
  615. var result = from a in executableOptionalCourseResult.Concat(executableFreeSelectionCouseResult)
  616. join s in schoolyearRepository.Entities on a.SchoolyearID equals s.SchoolyearID
  617. //join dis in DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(CF_CourseType).Name) on a.CourseTypeID equals dis.Value into ddis
  618. //from edis in ddis.DefaultIfEmpty()
  619. //join c in CoursematerialRepository.Entities on a.CourseCode equals c.CourseCode
  620. select new StudentSelectCourseView
  621. {
  622. ID = a.ID,
  623. //StudentTotalNum = a.StudentTotalNum,
  624. //PeopleNumlower = a.PeopleNumlower,
  625. //PeopleNumlimit = a.PeopleNumlimit,
  626. SchoolyearID = a.SchoolyearID,
  627. SchoolYearCode = s.Code,
  628. CampusName = a.CampusName,
  629. CollegeID = a.CollegeID,
  630. DefaultClassName = a.DefaultClassName,
  631. CoursematerialID = a.CoursematerialID,
  632. CourseCode = a.CourseCode,
  633. CourseName = a.CourseName,
  634. CourseTypeID = a.CourseTypeID,
  635. //CourseTypeName = a.CourseTypeName,
  636. CourseQualityID = a.CourseQualityID,
  637. SelectCourseTypeID = a.SelectCourseTypeID,
  638. SelectCourseTypeName = a.SelectCourseTypeName,
  639. TheoryCourse = a.TheoryCourse ?? 0,
  640. Practicehours = a.Practicehours ?? 0,
  641. Trialhours = a.Trialhours ?? 0,
  642. Credit = a.Credit ?? 0,
  643. WeeklyNum = a.WeeklyNum,
  644. StartWeeklyNum = a.StartWeeklyNum ?? 0,
  645. EndWeeklyNum = a.EndWeeklyNum ?? 0,
  646. //CoursesTimeID = a.CoursesTimeID,
  647. //CoursesTimeName = a.CoursesTimeName,
  648. //ClassroomID = a.ClassroomID,
  649. ClassroomName = a.ClassroomName,
  650. SchoolcodeID = a.SchoolcodeID,
  651. TeacherUserID = null,
  652. TeacherName = a.TeacherName,
  653. //TeachingModeID = a.TeachingModeID,
  654. RecordStatus = a.RecordStatus,
  655. IsOpened = a.IsOpened,
  656. //TeachingModeName = GetSelectCourseResultTeachingMode1(a.ID)
  657. };
  658. return result;
  659. }
  660. public IQueryable<StudentCourseTeacherView> GetStudentSelectCourseTeacherResultView(Guid userID)
  661. {
  662. DateTime nowTime = DateTime.Now;
  663. Guid selectCourseSchoolyearID = this.GetSelectCourseSchoolyear();
  664. List<int?> OptionalCourseStatus = new List<int?> { (int)EM_SelectCourseResultStatus.Opened };
  665. var studentOpenControl = (from s in StudentRepository.GetList(x => x.UserID == userID)
  666. join scocs in SelectCourseOpenControlSettingRepository
  667. .GetList(x => x.SchoolyearID == selectCourseSchoolyearID) on s.CF_Classmajor.GrademajorID equals scocs.GrademajorID
  668. select scocs).FirstOrDefault();
  669. var q = (from s in StudentRepository.GetList(x => x.UserID == userID)
  670. join eoc in ExecutableOptionalCourseRepository.Entities on s.CF_Classmajor.GrademajorID equals eoc.GrademajorID
  671. from eoccc in eoc.CF_Classmajor.Where(x => x.ClassmajorID == s.ClassmajorID).DefaultIfEmpty()
  672. join scts in SelectCourseTypeSettingRepository
  673. .GetList(x => x.SchoolyearID == selectCourseSchoolyearID) on (int)EM_SelectCourseType.OptionalCourse equals scts.SelectCourseTypeID
  674. join scocs in SelectCourseOpenControlSettingRepository
  675. .GetList(x => x.SchoolyearID == selectCourseSchoolyearID) on eoc.GrademajorID equals scocs.GrademajorID
  676. into dscocs
  677. from escocs in dscocs.DefaultIfEmpty()
  678. from eoccs in eoc.CF_Student.Where(x => x.UserID == userID).DefaultIfEmpty()
  679. from eoct in eoc.EM_ExecutableOptionalCourseTeacher.Where(x => x.UserID != null)
  680. where eoc.SchoolyearID == selectCourseSchoolyearID
  681. //&& eoc.IsOpened == true
  682. && OptionalCourseStatus.Contains(eoc.RecordStatus)
  683. && eoccc.ClassmajorID != null
  684. && scts.StartTime <= nowTime && scts.EndTime >= nowTime
  685. && ((escocs.SelectCourseOpenControlSettingID == null) || (escocs.StartTime <= nowTime && escocs.EndTime >= nowTime))
  686. || eoccs.UserID != null
  687. group eoc by new
  688. {
  689. SelectCourseID = eoc.ExecutableOptionalCourseID,
  690. eoct.CF_Staff.UserID,
  691. eoct.CF_Staff.Sys_User.Name
  692. } into g
  693. select new StudentCourseTeacherView
  694. {
  695. SelectCourseID = g.Key.SelectCourseID,
  696. UserID = g.Key.UserID,
  697. Name = g.Key.Name
  698. });
  699. q = q.Concat(from efsc in ExecutableFreeSelectionCouseRepository.Entities
  700. join scts in SelectCourseTypeSettingRepository
  701. .GetList(x => x.SchoolyearID == selectCourseSchoolyearID) on (int)EM_SelectCourseType.FreeSelectionCouse equals scts.SelectCourseTypeID
  702. from efsccs in efsc.CF_Student.Where(x => x.UserID == userID).DefaultIfEmpty()
  703. from efsct in efsc.EM_ExecutableFreeSelectionCouseTeacher.Where(x => x.UserID != null)
  704. where efsc.SchoolyearID == selectCourseSchoolyearID
  705. //&& efsc.IsOpened == true
  706. && ((scts.SelectCourseTypeSettingID == null) || (scts.StartTime <= nowTime && scts.EndTime >= nowTime))
  707. || efsccs.UserID != null
  708. group efsc by new
  709. {
  710. SelectCourseID = efsc.ExecutableFreeSelectionCouseID,
  711. efsct.CF_Staff.UserID,
  712. efsct.CF_Staff.Sys_User.Name
  713. } into g
  714. select new StudentCourseTeacherView
  715. {
  716. SelectCourseID = g.Key.SelectCourseID,
  717. UserID = g.Key.UserID,
  718. Name = g.Key.Name
  719. });
  720. return q;
  721. }
  722. public StudentSelectCourseBaseView GetStudentSelectCourseBaseView(Guid userID)
  723. {
  724. Guid selectCourseSchoolyearID = this.GetSelectCourseSchoolyear();
  725. var q = (from s in StudentRepository.GetList(x => x.UserID == userID)
  726. from eoc in s.EM_ExecutableOptionalCourse.Where(x => x.RecordStatus != (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate
  727. && x.SchoolyearID == selectCourseSchoolyearID)
  728. group eoc by new
  729. {
  730. s.InSchoolStatusID,
  731. s.UserID,
  732. s.Sys_User.Name,
  733. s.ClassmajorID,
  734. ClassmajorName = s.CF_Classmajor.Name,
  735. s.CF_Classmajor.GrademajorID,
  736. GrademajorName = s.CF_Classmajor.CF_Grademajor.Name,
  737. GrademajorYear = s.CF_Classmajor.CF_Grademajor.GradeID
  738. } into g
  739. select new StudentSelectCourseBaseView
  740. {
  741. UserID = g.Key.UserID,
  742. Name = g.Key.Name,
  743. ClassmajorID = g.Key.ClassmajorID,
  744. ClassmajorName = g.Key.ClassmajorName,
  745. GrademajorID = g.Key.GrademajorID,
  746. GrademajorName = g.Key.GrademajorName,
  747. GrademajorYear = g.Key.GrademajorYear,
  748. OptionalTotalSelectCount = g.Count(),
  749. OptionalTotalCredit = g.Sum(x => x.EM_ExecutableOptionalCourseTeachingSetting.Credit),
  750. FreeSelectCourseTotalSelectCount = 0,
  751. FreeSelectCourseTotalCredit = 0,
  752. InSchoolStatusID = g.Key.InSchoolStatusID
  753. }).Concat(
  754. from s in StudentRepository.GetList(x => x.UserID == userID)
  755. from efsc in s.EM_ExecutableFreeSelectionCouse.Where(x => x.RecordStatus != (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate
  756. && x.SchoolyearID == selectCourseSchoolyearID)
  757. group efsc by new
  758. {
  759. s.InSchoolStatusID,
  760. s.UserID,
  761. s.Sys_User.Name,
  762. s.ClassmajorID,
  763. ClassmajorName = s.CF_Classmajor.Name,
  764. s.CF_Classmajor.GrademajorID,
  765. GrademajorName = s.CF_Classmajor.CF_Grademajor.Name,
  766. GrademajorYear = s.CF_Classmajor.CF_Grademajor.GradeID
  767. } into g
  768. select new StudentSelectCourseBaseView
  769. {
  770. UserID = g.Key.UserID,
  771. Name = g.Key.Name,
  772. ClassmajorID = g.Key.ClassmajorID,
  773. ClassmajorName = g.Key.ClassmajorName,
  774. GrademajorID = g.Key.GrademajorID,
  775. GrademajorName = g.Key.GrademajorName,
  776. GrademajorYear = g.Key.GrademajorYear,
  777. OptionalTotalSelectCount = 0,
  778. OptionalTotalCredit = 0,
  779. FreeSelectCourseTotalSelectCount = g.Count(),
  780. FreeSelectCourseTotalCredit = g.Sum(x => x.EM_ExecutableFreeSelectionCouseTeachingSetting.Credit),
  781. InSchoolStatusID = g.Key.InSchoolStatusID
  782. });
  783. var groupQuery = (from s in StudentRepository.GetList(x => x.UserID == userID)
  784. join sc in q on s.UserID equals sc.UserID into dsc
  785. from esc in dsc.DefaultIfEmpty()
  786. group esc by new
  787. {
  788. s.InSchoolStatusID,
  789. s.UserID,
  790. s.Sys_User.Name,
  791. s.ClassmajorID,
  792. ClassmajorName = s.CF_Classmajor.Name,
  793. s.CF_Classmajor.GrademajorID,
  794. GrademajorName = s.CF_Classmajor.CF_Grademajor.Name,
  795. GrademajorYear = s.CF_Classmajor.CF_Grademajor.GradeID,
  796. } into g
  797. select new StudentSelectCourseBaseView
  798. {
  799. UserID = g.Key.UserID,
  800. Name = g.Key.Name,
  801. ClassmajorID = g.Key.ClassmajorID,
  802. ClassmajorName = g.Key.ClassmajorName,
  803. GrademajorID = g.Key.GrademajorID,
  804. GrademajorName = g.Key.GrademajorName,
  805. GrademajorYear = g.Key.GrademajorYear,
  806. OptionalTotalSelectCount = g.Sum(x => x.OptionalTotalSelectCount ?? 0),
  807. OptionalTotalCredit = g.Sum(x => x.OptionalTotalCredit ?? 0),
  808. FreeSelectCourseTotalSelectCount = g.Sum(x => x.FreeSelectCourseTotalSelectCount ?? 0),
  809. FreeSelectCourseTotalCredit = g.Sum(x => x.FreeSelectCourseTotalCredit ?? 0),
  810. InSchoolStatusID = g.Key.InSchoolStatusID
  811. });
  812. return groupQuery.FirstOrDefault();
  813. }
  814. public IQueryable<BaseStudentView> GetBaseStudentViewQueryable(Guid UserID, Guid selectCourseSchoolyearID)
  815. {
  816. var Schoolyear = schoolyearRepository.Entities.Where(x => x.SchoolyearID == selectCourseSchoolyearID).FirstOrDefault();
  817. var query = from stud in StudentRepository.GetList(x => x.UserID == UserID)
  818. join clas in ClassmajorRepository.Entities on stud.ClassmajorID equals clas.ClassmajorID
  819. join grad in GrademajorRepository.Entities on clas.GrademajorID equals grad.GrademajorID
  820. join faul in FacultymajorRepository.Entities on grad.FacultymajorID equals faul.FacultymajorID
  821. join spec in SpecialtyRepository.Entities on new { faul.StandardID, faul.LearningformID, faul.LearnSystem, faul.EducationID }
  822. equals new { spec.StandardID, spec.LearningformID, spec.LearnSystem, spec.EducationID }
  823. join startYear in schoolyearRepository.Entities on new { SchoolyearID = grad.GradeID.Value, SchoolcodeID = grad.SemesterID.Value } equals new { SchoolyearID = startYear.Years, startYear.SchoolcodeID }
  824. select new BaseStudentView
  825. {
  826. UserID = stud.UserID,
  827. SpecialtyID = spec.SpecialtyID,
  828. FacultymajorID = faul.FacultymajorID,
  829. GrademajorID = grad.GrademajorID,
  830. ClassmajorID = clas.ClassmajorID,
  831. GradeYear = (Schoolyear.Value - startYear.Value - (grad.SemesterID == Schoolyear.SchoolcodeID ? 0 : 1)) / 2 + 1
  832. };
  833. return query;
  834. }
  835. //查询任选设定的具体上课时间
  836. public IQueryable<ExecutableFreeSelectionCouseSchedulingView> GetScheduling(List<Guid> IDList)
  837. {
  838. var query = from a in ExecutableFreeSelectionCouseRepository.GetList(x => IDList.Contains(x.ExecutableFreeSelectionCouseID))
  839. join b in ExecutableFreeSelectionCouseSchedulingRepository.Entities on a.ExecutableFreeSelectionCouseID equals b.ExecutableFreeSelectionCouseID
  840. //join c in ExecutableFreeSelectionCouseTeachingSettingRepository.Entities on a.ExecutableFreeSelectionCouseID equals c.ExecutableFreeSelectionCouseID
  841. join c in coursesTimeRepository.Entities on b.CoursesTimeID equals c.CoursesTimeID
  842. join d in DictionaryItemRepository.Entities on new { c.TimesSegment, DictionaryCode = "CF_TimesSegment" }
  843. equals new { TimesSegment = d.Value.Value, d.DictionaryCode } into gbsta
  844. from d in gbsta.DefaultIfEmpty()
  845. //join e in DictionaryItemRepository.Entities on new { b.Weekday, DictionaryCode = "ES_WeekDay" }
  846. //equals new { Weekday = e.Value, e.DictionaryCode } into gbsta1
  847. //from e in gbsta1.DefaultIfEmpty()
  848. select new ExecutableFreeSelectionCouseSchedulingView
  849. {
  850. SchoolyearID = a.SchoolyearID,
  851. DefaultClassName = a.DefaultClassName,
  852. SchedulingID = b.ExecutableFreeSelectionCouseSchedulingID,
  853. ID = a.ExecutableFreeSelectionCouseID,
  854. CourseCollegeID = a.CF_Department.CollegeID,
  855. ClassroomID = b.ClassroomID,
  856. ClassroomName = b.CF_Classroom.Name,
  857. CoursesTimeID = b.CoursesTimeID,
  858. Weekday = b.Weekday,
  859. TimesSegmentName = d.Name,
  860. StartTimes = c.StartTimes,
  861. EndTimes = c.EndTimes
  862. //StartWeeklyNum = c.StartWeeklyNum,
  863. //EndWeeklyNum = c.EndWeeklyNum
  864. };
  865. return query;
  866. }
  867. //查询任选设定的具体上课时间
  868. public IQueryable<ExecutableFreeSelectionCouseSchedulingView> GetSchedulingTime(Guid? ID)
  869. {
  870. var query = from a in ExecutableFreeSelectionCouseRepository.GetList(x => x.ExecutableFreeSelectionCouseID == ID)
  871. join b in ExecutableFreeSelectionCouseSchedulingRepository.Entities on a.ExecutableFreeSelectionCouseID equals b.ExecutableFreeSelectionCouseID
  872. join c in ExecutableFreeSelectionCouseTeachingSettingRepository.Entities on a.ExecutableFreeSelectionCouseID equals c.ExecutableFreeSelectionCouseID
  873. select new ExecutableFreeSelectionCouseSchedulingView
  874. {
  875. SchoolyearID = a.SchoolyearID,
  876. DefaultClassName = a.DefaultClassName,
  877. SchedulingID = b.ExecutableFreeSelectionCouseSchedulingID,
  878. ID = a.ExecutableFreeSelectionCouseID,
  879. CourseCollegeID = a.CF_Department.CollegeID,
  880. ClassroomID = b.ClassroomID,
  881. ClassroomName = b.CF_Classroom.Name,
  882. CoursesTimeID = b.CoursesTimeID,
  883. Weekday = b.Weekday,
  884. StartWeeklyNum = c.StartWeeklyNum,
  885. EndWeeklyNum = c.EndWeeklyNum
  886. };
  887. return query;
  888. }
  889. /// <summary>
  890. /// 查询任选设定的具体上课时间,选课结果和任选设定页面查询
  891. /// </summary>
  892. /// <param name="efsExp"></param>
  893. /// <returns></returns>
  894. public IQueryable<ExecutableFreeSelectionCouseSchedulingView> GetScheduling(Expression<Func<EM_ExecutableFreeSelectionCouse, bool>> efsExp)
  895. {
  896. var query = from a in ExecutableFreeSelectionCouseRepository.GetList(efsExp)
  897. join b in ExecutableFreeSelectionCouseSchedulingRepository.Entities on a.ExecutableFreeSelectionCouseID equals b.ExecutableFreeSelectionCouseID
  898. //join c in ExecutableFreeSelectionCouseTeachingSettingRepository.Entities on a.ExecutableFreeSelectionCouseID equals c.ExecutableFreeSelectionCouseID
  899. join c in coursesTimeRepository.Entities on b.CoursesTimeID equals c.CoursesTimeID
  900. join d in DictionaryItemRepository.Entities on new { c.TimesSegment, DictionaryCode = "CF_TimesSegment" }
  901. equals new { TimesSegment = d.Value.Value, d.DictionaryCode } into gbsta
  902. from d in gbsta.DefaultIfEmpty()
  903. //join e in DictionaryItemRepository.Entities on new { b.Weekday, DictionaryCode = "ES_WeekDay" }
  904. //equals new { Weekday = e.Value, e.DictionaryCode } into gbsta1
  905. //from e in gbsta1.DefaultIfEmpty()
  906. select new ExecutableFreeSelectionCouseSchedulingView
  907. {
  908. SchoolyearID = a.SchoolyearID,
  909. DefaultClassName = a.DefaultClassName,
  910. SchedulingID = b.ExecutableFreeSelectionCouseSchedulingID,
  911. ID = a.ExecutableFreeSelectionCouseID,
  912. CourseCollegeID = a.CF_Department.CollegeID,
  913. ClassroomID = b.ClassroomID,
  914. ClassroomName = b.CF_Classroom.Name,
  915. CoursesTimeID = b.CoursesTimeID,
  916. Weekday = b.Weekday,
  917. TimesSegmentName = d.Name,
  918. StartTimes = c.StartTimes,
  919. EndTimes = c.EndTimes
  920. //StartWeeklyNum = c.StartWeeklyNum,
  921. //EndWeeklyNum = c.EndWeeklyNum
  922. };
  923. return query;
  924. }
  925. //任选设定判断教室冲突
  926. public IQueryable<ExecutableFreeSelectionCouseSchedulingView> GetRepeatTime(Guid? UserID, Guid? ID, Guid? CoursesTimeID, int? Weekday, Guid? SchoolyearID, int? StartWeeklyNum, int? EndWeeklyNum)
  927. {
  928. var query = from a in ExecutableFreeSelectionCouseSchedulingRepository.GetList(x => x.CoursesTimeID == CoursesTimeID && x.Weekday == Weekday)
  929. join b in ExecutableFreeSelectionCouseRepository.GetList(x =>
  930. x.SchoolyearID == SchoolyearID
  931. // && x.RecordStatus != (int)EMIS.ViewModel.EM_SelectCourseResultStatus.CancleCreate
  932. //&& x.CF_Student.Any(w => w.UserID == UserID))
  933. ) on a.ExecutableFreeSelectionCouseID equals b.ExecutableFreeSelectionCouseID
  934. from st in b.CF_Student.Where(x => x.UserID == UserID)
  935. join c in coursesTimeRepository.Entities on a.CoursesTimeID equals c.CoursesTimeID
  936. join d in DictionaryItemRepository.Entities on new { c.TimesSegment, DictionaryCode = "CF_TimesSegment" }
  937. equals new { TimesSegment = d.Value.Value, d.DictionaryCode } into gbsta
  938. from gicbsta in gbsta.DefaultIfEmpty()
  939. join s in ExecutableFreeSelectionCouseTeachingSettingRepository.GetList(x =>
  940. (x.StartWeeklyNum >= StartWeeklyNum && StartWeeklyNum <= x.EndWeeklyNum) ||
  941. (x.StartWeeklyNum >= EndWeeklyNum && EndWeeklyNum <= x.EndWeeklyNum) ||
  942. (StartWeeklyNum <= x.StartWeeklyNum && x.StartWeeklyNum <= EndWeeklyNum) ||
  943. (StartWeeklyNum <= x.EndWeeklyNum && x.EndWeeklyNum <= EndWeeklyNum)
  944. ) on b.ExecutableFreeSelectionCouseID equals s.ExecutableFreeSelectionCouseID
  945. select new ExecutableFreeSelectionCouseSchedulingView
  946. {
  947. DefaultClassName = b.DefaultClassName,
  948. SchedulingID = a.ExecutableFreeSelectionCouseSchedulingID,
  949. ID = a.ExecutableFreeSelectionCouseID,
  950. CourseCollegeID = a.EM_ExecutableFreeSelectionCouse.CF_Department.CollegeID,
  951. ClassroomID = a.ClassroomID,
  952. ClassroomName = a.CF_Classroom.Name,
  953. CoursesTimeID = a.CoursesTimeID,
  954. TimesSegment = c.TimesSegment,
  955. TimesSegmentName = gicbsta.Name,
  956. Weekday = a.Weekday,
  957. RecordStatus = b.RecordStatus,
  958. CreateTime = b.CreateTime,
  959. CreateUserID = b.CreateUserID,
  960. ModifyTime = b.ModifyTime,
  961. ModifyUserID = b.ModifyUserID
  962. };
  963. return query;
  964. }
  965. public IQueryable<SelectCourseResultView> GetCheckEnouthNumSelectCourseResult(IList<Guid?> IDs)
  966. {
  967. //1.0 获取限选设定的所有学生数据
  968. var executableOptionalCourseResult = (from eoc in ExecutableOptionalCourseRepository.GetList(x => IDs.Contains(x.ExecutableOptionalCourseID))
  969. select new SelectCourseResultView
  970. {
  971. ID = eoc.ExecutableOptionalCourseID,
  972. StudentTotalNum = eoc.CF_Student.Count(),
  973. PeopleNumlower = eoc.PeopleNumlower,
  974. PeopleNumlimit = eoc.PeopleNumlimit,
  975. });
  976. //2.0 获取任选设定的所有学生数据
  977. var executableFreeSelectionCouseResult = (from efs in ExecutableFreeSelectionCouseRepository.GetList(x => IDs.Contains(x.ExecutableFreeSelectionCouseID))
  978. select new SelectCourseResultView
  979. {
  980. ID = efs.ExecutableFreeSelectionCouseID,
  981. StudentTotalNum = efs.CF_Student.Count(),
  982. PeopleNumlower = efs.PeopleNumlower,
  983. PeopleNumlimit = efs.PeopleNumlimit,
  984. });
  985. //3.0 合并限选/任选
  986. var result = from a in executableOptionalCourseResult.Concat(executableFreeSelectionCouseResult)
  987. select new SelectCourseResultView
  988. {
  989. ID = a.ID,
  990. StudentTotalNum = a.StudentTotalNum,
  991. PeopleNumlower = a.PeopleNumlower,
  992. PeopleNumlimit = a.PeopleNumlimit,
  993. };
  994. return result;
  995. }
  996. }
  997. }