TeachersConfirmOrderDAL.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 System.Linq.Expressions;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel;
  10. namespace EMIS.DataLogic.Common.TeachingMaterial
  11. {
  12. public class TeachersConfirmOrderDAL
  13. {
  14. #region 0.0 --定义--
  15. public TeachersOrderRepository TeachersOrderRepository { get; set; }
  16. public TeachersConfirmOrderRepository TeachersConfirmOrderRepository { get; set; }
  17. public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
  18. public TeachersPreOrderRepository TeachersPreOrderRepository { get; set; }
  19. public UserRepository UserRepository { get; set; }
  20. public CoursematerialRepository CoursematerialRepository { get; set; }
  21. public PublishRepository PublishRepository { get; set; }
  22. public SchoolyearRepository SchoolyearRepository { get; set; }
  23. public CollegeRepository CollegeRepository { get; set; }
  24. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  25. #endregion
  26. #region 2.0 提取征订清单数据列表
  27. /// <summary>
  28. /// 获取征订清单数据列表
  29. /// 以学年跟教材编号分组
  30. /// </summary>
  31. /// <param name="exp"></param>
  32. /// <returns></returns>
  33. public IQueryable<TeachersConfirmOrderView> GetTeachersConfirmOrderGridView(Expression<Func<ET_TeachersOrder, bool>> exporder)
  34. {
  35. var query = from nto in
  36. (from to in TeachersOrderRepository.Entities.Where(exporder)
  37. group to by new { to.SchoolyearID, to.TeachingMaterialPoolID }
  38. into a
  39. select new
  40. {
  41. a.Key.SchoolyearID,
  42. a.Key.TeachingMaterialPoolID,
  43. sumOrderQty = a.Sum(x => x.OrderQty),
  44. DateTime = a.Max(x => x.OrderDate),
  45. })
  46. join tpo in TeachersPreOrderRepository.Entities
  47. on new { nto.SchoolyearID, nto.TeachingMaterialPoolID } equals new { tpo.SchoolyearID, tpo.TeachingMaterialPoolID }
  48. into b
  49. from ntpo in b.DefaultIfEmpty()
  50. join tmp in TeachingMaterialPoolRepository.Entities on nto.TeachingMaterialPoolID equals tmp.TeachingMaterialPoolID
  51. join tto in TeachersOrderRepository.Entities.Where(exporder)
  52. on new { nto.SchoolyearID, nto.TeachingMaterialPoolID, nto.DateTime.Value } equals new { tto.SchoolyearID, tto.TeachingMaterialPoolID, tto.OrderDate.Value }
  53. join u in UserRepository.Entities on tto.OrderUserID equals u.UserID
  54. join p in PublishRepository.Entities on tmp.PublishID equals p.PublishID
  55. join sl in SchoolyearRepository.Entities on tto.SchoolyearID equals sl.SchoolyearID
  56. join cr in CollegeRepository.Entities on tto.CollegeID equals cr.CollegeID
  57. //join tpo in TeachersPreOrderRepository.Entities
  58. //on new { nto.SchoolyearID, nto.TeachingMaterialPoolID } equals new { tpo.SchoolyearID, tpo.TeachingMaterialPoolID }
  59. //into b
  60. //from ntpo in b.DefaultIfEmpty()
  61. select new TeachersConfirmOrderView
  62. {
  63. OrderUserName = u.Name,
  64. SchoolyearID = tto.SchoolyearID,
  65. SchoolyearName = sl.Code,
  66. TeachingMaterialCode = tmp.TeachingMaterialCode,
  67. Author = tmp.Author,
  68. OrderDate = nto.DateTime,
  69. TeachingMaterialName = tmp.TeachingMaterialName,
  70. PublishTime = tmp.PublishTime,
  71. TeachingMaterialPoolID = nto.TeachingMaterialPoolID,
  72. PublishName = p.UnitName,
  73. OrderQty = nto.sumOrderQty,
  74. CoursematerialEntityList = tmp.EM_Coursematerial,
  75. PublishID = p.PublishID,
  76. ISBN = tmp.ISBN,
  77. PreAddedValue = ntpo.PreQty == null ? 0 : ntpo.PreQty,
  78. Price = tmp.Price,
  79. CountNumber = ntpo.PreQty == null ? (nto.sumOrderQty + 0) : (nto.sumOrderQty + ntpo.PreQty),
  80. };
  81. var view = (from to in TeachersOrderRepository.Entities.Where(exporder)
  82. join tm in TeachingMaterialPoolRepository.Entities on to.TeachingMaterialPoolID equals tm.TeachingMaterialPoolID
  83. join u in UserRepository.Entities on to.OrderUserID equals u.UserID
  84. join p in PublishRepository.Entities on tm.PublishID equals (Guid)p.PublishID
  85. join sl in SchoolyearRepository.Entities on to.SchoolyearID equals sl.SchoolyearID
  86. join cr in CollegeRepository.Entities on to.CollegeID equals cr.CollegeID
  87. join per in TeachersPreOrderRepository.Entities on new { to.TeachingMaterialPoolID, to.SchoolyearID } equals new
  88. {
  89. per.TeachingMaterialPoolID,
  90. per.SchoolyearID
  91. }
  92. into pers
  93. from perstb in pers.DefaultIfEmpty()
  94. group new { to, tm, sl, p, perstb } by new
  95. {
  96. u.Name,
  97. sl.SchoolyearID,
  98. sl.Code,
  99. tm.TeachingMaterialCode,
  100. tm.Author,
  101. tm.TeachingMaterialName,
  102. tm.PublishTime,
  103. to.TeachingMaterialPoolID,
  104. to.OrderDate,
  105. perstb.PreQty,
  106. p.UnitName,
  107. p.PublishID,
  108. tm.ISBN,
  109. tm.Price
  110. } into h
  111. join tm in TeachingMaterialPoolRepository.Entities on h.Key.TeachingMaterialPoolID equals tm.TeachingMaterialPoolID
  112. select new TeachersConfirmOrderView
  113. {
  114. OrderUserName = h.Key.Name,
  115. SchoolyearID = h.Key.SchoolyearID,
  116. SchoolyearName = h.Key.Code,
  117. TeachingMaterialCode = h.Key.TeachingMaterialCode,
  118. Author = h.Key.Author,
  119. OrderDate=h.Key.OrderDate,
  120. TeachingMaterialName = h.Key.TeachingMaterialName,
  121. PublishTime = h.Key.PublishTime,
  122. TeachingMaterialPoolID = h.Key.TeachingMaterialPoolID,
  123. PublishName = h.Key.UnitName,
  124. OrderQty = h.Sum(x => x.to.OrderQty) == null ? 0 : h.Sum(x => x.to.OrderQty),
  125. CoursematerialEntityList = tm.EM_Coursematerial,
  126. PublishID = h.Key.PublishID,
  127. ISBN = h.Key.ISBN,
  128. PreAddedValue = h.Key.PreQty == null ? 0 : h.Key.PreQty,
  129. Price = h.Key.Price,
  130. // CollegeID = h.Key.CollegeID,
  131. CountNumber = h.Key.PreQty == null ? (h.Sum(x => x.to.OrderQty) + 0) : ((h.Sum(x => x.to.OrderQty) + h.Key.PreQty))
  132. });//以教材编号及学年进行分组
  133. return query;
  134. }
  135. #endregion
  136. #region 3.0 查询征订信息列表
  137. /// <summary>
  138. /// 获取征订信息列表
  139. /// </summary>
  140. /// <param name="exp"></param>
  141. /// <returns></returns>
  142. public IQueryable<TeachersConfirmOrderView> GetTeachingOrderDetail(Expression<Func<ET_TeachersOrder, bool>> exporder)
  143. {
  144. var view = (from to in TeachersOrderRepository.Entities.Where(exporder)
  145. join tm in TeachingMaterialPoolRepository.Entities on to.TeachingMaterialPoolID equals tm.TeachingMaterialPoolID
  146. join u in UserRepository.Entities on to.OrderUserID equals u.UserID
  147. join p in PublishRepository.Entities on tm.PublishID equals (Guid)p.PublishID
  148. join sl in SchoolyearRepository.Entities on to.SchoolyearID equals sl.SchoolyearID
  149. join cr in CollegeRepository.Entities on to.CollegeID equals cr.CollegeID
  150. select new TeachersConfirmOrderView
  151. {
  152. SchoolyearID = sl.SchoolyearID,
  153. SchoolyearName = sl.Code,
  154. TeachingMaterialCode = tm.TeachingMaterialCode,
  155. Author = tm.Author,
  156. CollegeID = cr.CollegeID,
  157. CollegeName = cr.Name,
  158. TeachingMaterialName = tm.TeachingMaterialName,
  159. PublishTime = tm.PublishTime,
  160. TeachersOrderID = to.TeachersOrderID,
  161. TeachingMaterialPoolID = tm.TeachingMaterialPoolID,
  162. PublishName = p.UnitName,
  163. OrderUserName = u.Name,
  164. OrderDate = to.OrderDate,
  165. OrderQty = to.OrderQty,
  166. OrderDesc = to.OrderDesc,
  167. CoursematerialEntityList = tm.EM_Coursematerial,
  168. PublishID = p.PublishID,
  169. CreateTime = to.CreateTime,
  170. ISBN = tm.ISBN,
  171. Price = tm.Price,
  172. Desc = tm.Desc
  173. });
  174. return view;
  175. }
  176. #endregion
  177. }
  178. }