TeachingMaterialPoolDAL.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Repositories;
  6. using EMIS.ViewModel.TeachingMaterial;
  7. using EMIS.Entities;
  8. using System.Linq.Expressions;
  9. using EMIS.ViewModel;
  10. using System.Data;
  11. using EMIS.ViewModel.Cultureplan;
  12. using EMIS.DataLogic.Common.Cultureplan;
  13. namespace EMIS.DataLogic.Common.TeachingMaterial
  14. {
  15. public class TeachingMaterialPoolDAL
  16. {
  17. public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
  18. public UserRepository UserRepository { get; set; }
  19. public CoursematerialRepository CoursematerialRepository { get; set; }
  20. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  21. public PublishRepository PublishRepository { get; set; }
  22. public OptionalCoursePlanRepository OptionalCoursePlanRepository { get; set; }
  23. public StudentRepository StudentRepository { get; set; }
  24. public SpecialtyPlanRepository SpecialtyPlanRepository { get; set; }
  25. public GrademajorRepository GrademajorRepository { get; set; }
  26. public SpecialtyCourseRepository SpecialtyCourseRepository { get; set; }
  27. public Lazy<CoursematerialDAL> CoursematerialDAL { get; set; }
  28. /// <summary>
  29. /// 获取教材总库信息列表
  30. /// </summary>
  31. /// <param name="exp"></param>
  32. /// <returns></returns>
  33. public IQueryable<TeachingMaterialPoolView> GetTeachingMaterialPoolGridView(Expression<Func<CF_TeachingMaterialPool, bool>> exp)
  34. {
  35. var view = (from l in TeachingMaterialPoolRepository.Entities.Where(exp)
  36. //join d in DictionaryItemRepository.Entities
  37. //on new { l.TeachingMaterialTypeID, DictionaryCode = DictionaryItem.CF_TeachingMaterialType.ToString() } equals new { TeachingMaterialTypeID = d.Value, d.DictionaryCode }
  38. //into tdic
  39. //from tbdic in tdic.DefaultIfEmpty()
  40. join u in UserRepository.Entities on l.CreateUserID equals u.UserID
  41. join p in PublishRepository.Entities on l.PublishID equals p.PublishID
  42. into up
  43. from gup in up.DefaultIfEmpty()
  44. select new TeachingMaterialPoolView
  45. {
  46. Author = l.Author,
  47. ISBN = l.ISBN,
  48. CoursematerialEntityList = l.EM_Coursematerial,
  49. Price = l.Price,
  50. TeachingMaterialCode = l.TeachingMaterialCode,
  51. TeachingMaterialName = l.TeachingMaterialName,
  52. TeachingMaterialShorName = l.TeachingMaterialShorName,
  53. TeachingMaterialPoolID = l.TeachingMaterialPoolID,
  54. TeachingMaterialTypeID = l.TeachingMaterialTypeID,
  55. //TeachingMaterialTypeName = tbdic.Name,
  56. PublishID = l.PublishID,
  57. PublishName = gup.UnitName,
  58. PublishTime = l.PublishTime,
  59. CreateTime = l.CreateTime,
  60. CreateUserName = u.Name,
  61. Desc = l.Desc,
  62. IsLate = l.IsLate.Value,
  63. ModifyTime = l.ModifyTime,
  64. IsLateName = l.IsLate == true ? "是" : "否",
  65. OrderQty = 1
  66. });
  67. return view;
  68. }
  69. /// <summary>
  70. /// 获取教材总库
  71. /// </summary>
  72. /// <returns></returns>
  73. public TeachingMaterialPoolView GetSingleTeachingMaterialPool(Guid teachingMaterialPoolID)
  74. {
  75. var teachingMaterialPool = TeachingMaterialPoolRepository.GetSingle(x => x.TeachingMaterialPoolID == teachingMaterialPoolID,
  76. (x => x.EM_Coursematerial), (x => x.CF_Publish));
  77. var teachingMaterialPoolView = new TeachingMaterialPoolView()
  78. {
  79. Author = teachingMaterialPool.Author,
  80. IsLate = teachingMaterialPool.IsLate.GetValueOrDefault(),
  81. ISBN = teachingMaterialPool.ISBN,
  82. Price = teachingMaterialPool.Price,
  83. PublishID = teachingMaterialPool.PublishID,
  84. TeachingMaterialPoolID = teachingMaterialPool.TeachingMaterialPoolID,
  85. PublishTime = teachingMaterialPool.PublishTime,
  86. TeachingMaterialCode = teachingMaterialPool.TeachingMaterialCode,
  87. Desc = teachingMaterialPool.Desc,
  88. CoursematerialEntityList = teachingMaterialPool.EM_Coursematerial,
  89. WnningLevel = teachingMaterialPool.WnningLevel == null ? -1 : teachingMaterialPool.WnningLevel,
  90. TeachingMaterialTypeID = teachingMaterialPool.TeachingMaterialTypeID,
  91. TeachingMaterialShorName = teachingMaterialPool.TeachingMaterialShorName,
  92. TeachingMaterialName = teachingMaterialPool.TeachingMaterialName,
  93. MinInventory = teachingMaterialPool.MinInventory
  94. };
  95. return teachingMaterialPoolView;
  96. }
  97. /// <summary>
  98. /// 获取教材总库信息列表(用于学生征订)
  99. /// </summary>
  100. /// <param name="exp"></param>
  101. /// <returns></returns>
  102. public IQueryable<TeachingMaterialPoolForOrderView> GetTeachingMaterialPoolForOrder(Expression<Func<CF_TeachingMaterialPool, bool>> exp, Guid? coursematerialID)
  103. {
  104. var view = (from l in TeachingMaterialPoolRepository.Entities.Where(exp)
  105. join p in PublishRepository.Entities on l.PublishID equals p.PublishID
  106. into lp
  107. from slp in lp.DefaultIfEmpty()
  108. select new TeachingMaterialPoolForOrderView
  109. {
  110. Author = l.Author,
  111. ISBN = l.ISBN,
  112. CoursematerialEntityList = l.EM_Coursematerial,
  113. Price = l.Price,
  114. TeachingMaterialCode = l.TeachingMaterialCode,
  115. TeachingMaterialName = l.TeachingMaterialName,
  116. TeachingMaterialPoolID = l.TeachingMaterialPoolID,
  117. PublishID = l.PublishID,
  118. PublishName = slp.UnitName,
  119. PublishTime = l.PublishTime,
  120. OrderID = l.EM_Coursematerial.Any(x => x.CoursematerialID == coursematerialID) ? 0 : 1
  121. });
  122. return view;
  123. }
  124. public IQueryable<StudentTeachingMaterialView> GetStudentTeachingMaterialView(Expression<Func<CF_Student, bool>> studentExp)
  125. {
  126. var user = StudentRepository.GetSingle(studentExp, (x => x.CF_Classmajor.CF_Grademajor));
  127. var q = (from sc in
  128. (from gm in GrademajorRepository.GetList(x => x.GrademajorID == user.CF_Classmajor.CF_Grademajor.GrademajorID)
  129. join sp in SpecialtyPlanRepository.GetList(x => x.IsNeedMaterial == true) on gm.GrademajorID equals sp.GrademajorID
  130. select new { Schoolyear = sp.CF_Schoolyear, SpecialtyPlan = sp })
  131. //.Union(
  132. //from gm in GrademajorRepository.GetList(x => x.GrademajorID == user.CF_Classmajor.CF_Grademajor.GrademajorID)
  133. //join op in OptionalCoursePlanRepository.GetList(x => x.IsNeedMaterial == true) on gm.GrademajorID equals op.GrademajorID
  134. //join sc in SpecialtyCourseRepository.Entities on op.SpecialtyCourseID equals sc.SpecialtyCourseID
  135. //select new { Schoolyear = op.CF_Schoolyear, SpecialtyCourse = sc })
  136. from tmp in sc.SpecialtyPlan.EM_Coursematerial.CF_TeachingMaterialPool
  137. select new StudentTeachingMaterialView
  138. {
  139. SchoolYearID = sc.Schoolyear.SchoolyearID,
  140. SchoolYearCode = sc.Schoolyear.Code,
  141. SchoolYearValue = sc.Schoolyear.Value,
  142. CoursematerialID = sc.SpecialtyPlan.EM_Coursematerial.CoursematerialID,
  143. CourseName = sc.SpecialtyPlan.EM_Coursematerial.CourseName,
  144. TeachingMaterialPoolID = tmp.TeachingMaterialPoolID,
  145. TeachingMaterialName = tmp.TeachingMaterialName,
  146. PublishTime = tmp.PublishTime,
  147. ISBN = tmp.ISBN,
  148. PublishID = tmp.PublishID,
  149. PublishName = tmp.CF_Publish.UnitName,
  150. Price = tmp.Price
  151. }
  152. );
  153. return q;
  154. }
  155. /// <summary>
  156. /// 判断是否已经录入
  157. /// </summary>
  158. /// <param name="dataSource"></param>
  159. /// <param name="errorSource"></param>
  160. private void AddErrorAndExceptExistingDataRow(DataTable dataSource, DataTable errorSource)
  161. {
  162. //foreach (DataRow dr in dataSource.Rows)
  163. //{
  164. // string loginID = dr["学号"].ToString();
  165. // var user = listUser.Where(x => x.LoginID == loginID).FirstOrDefault();
  166. // if (user == null)
  167. // {
  168. // AddError(errorSource, dr, "该学号不存在当前录入班级,请检查!");
  169. // }
  170. //}
  171. }
  172. public IQueryable<CoursematerialView> GetTeachingMaterialPoolCoursematerialView(Expression<Func<CF_TeachingMaterialPool, bool>> exp)
  173. {
  174. var query = (from tmp in TeachingMaterialPoolRepository.GetList(exp)
  175. from cm in tmp.EM_Coursematerial
  176. join cmv in CoursematerialDAL.Value.GetCoursematerialViewQueryable(x => true)
  177. on cm.CoursematerialID equals cmv.CoursematerialID
  178. select cmv);
  179. return query;
  180. }
  181. }
  182. }