StockOutDetailDAL.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 StockOutDetailDAL
  13. {
  14. #region --0.0 定义--
  15. public StockOutRepository StockOutRepository { get; set; }
  16. public StockOutDetailRepository StockOutDetailRepository { get; set; }
  17. public SchoolyearRepository SchoolyearRepository { get; set; }
  18. public UserRepository UserRepository { get; set; }
  19. public StudentDistributeDAL StudentDistributeDAL { get; set; }
  20. public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
  21. public CoursematerialRepository CoursematerialRepository { get; set; }
  22. public PublishRepository PublishRepository { get; set; }
  23. public CollegeRepository CollegeRepository { get; set; }
  24. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  25. public TeachingMateriaInventoryRepository TeachingMateriaInventoryRepository { get; set; }
  26. public StudentDistributeRepository StudentDistributeRepository { get; set; }
  27. public LibraryRepository LibraryRepository { get; set; }
  28. #endregion
  29. #region 1.0 信息列表
  30. public IQueryable<StockOutView> GetStockOutDetailGridView(Expression<Func<ET_StockOut, bool>> exporder)
  31. {
  32. var viewList = (from a in StockOutRepository.Entities.Where(exporder)
  33. join b in SchoolyearRepository.Entities on a.SchoolyearID equals b.SchoolyearID
  34. join c in UserRepository.Entities on a.CreateUserID equals c.UserID
  35. join sd in UserRepository.Entities on a.RecipientUserID equals sd.UserID
  36. into cuser
  37. from tcuser in cuser.DefaultIfEmpty()
  38. join e in StockOutDetailRepository.Entities on a.StockOutID equals e.StockOutID
  39. //出库详情的书库ID均为空用作关联条件导致查询结果为空
  40. //join lib in LibraryRepository.Entities on e.LibraryID equals lib.LibraryID into libName
  41. //from name in libName
  42. join t in TeachingMaterialPoolRepository.Entities on e.TeachingMaterialPoolID equals t.TeachingMaterialPoolID
  43. join sct in DictionaryItemRepository.Entities on new { StockInType = a.StockOutType, DictionaryCode = DictionaryItem.CF_StockOutType.ToString() }
  44. equals new { StockInType = (int)sct.Value, sct.DictionaryCode } into tsct
  45. from csct in tsct.DefaultIfEmpty() //教材 折合价相同 即为一条
  46. join tm in TeachingMateriaInventoryRepository.Entities on new { e.TeachingMaterialPoolID, DiscountPrice = e.Discount } equals new { tm.TeachingMaterialPoolID, DiscountPrice = tm.DiscountPrice }
  47. into sttm
  48. from csttm in sttm.DefaultIfEmpty()
  49. select new StockOutView
  50. {
  51. //书库名称并没有用到,直接删除
  52. //LibraryName = name.LibraryName,
  53. StockOutDetailID = e.StockOutDetailID,
  54. SchoolyearName = b.Code,
  55. SchoolyearID = (Guid)a.SchoolyearID,
  56. StockOutNo = a.StockOutNo + "",
  57. TeachingMaterialCode = t.TeachingMaterialCode,
  58. TeachingMaterialName = t.TeachingMaterialName,
  59. PublishName = t.CF_Publish.UnitName,
  60. PublishTime = t.PublishTime,
  61. Author = t.Author,
  62. RecordStatusName = csct.Name,
  63. Quantity = e.StockOutQuantity,
  64. Price = t.Price,
  65. Discount = e.DiscountPrice,//折扣率
  66. DiscountPrice = e.Discount,//折合价
  67. TotalPrice = t.Price * e.StockOutQuantity,
  68. TotalDollar = e.Discount * e.StockOutQuantity,
  69. RecipientUserName = a.StockOutType == (int)CF_StockOutType.StudentBook ? tcuser.Name : a.GetBookNo,
  70. StockOutUserName = c.Name,
  71. StockOutID = a.StockOutID,
  72. StockOutTime = a.StockOutTime,
  73. GetBookNo = a.GetBookNo == null ? tcuser.Name : a.GetBookNo,
  74. RecordStatus = a.RecordStatus,
  75. Desc = a.Desc
  76. });
  77. return viewList;
  78. }
  79. #endregion
  80. #region 2.0 加载出库统计列表
  81. public IQueryable<StockOutView> GetStockOutStatisticsGridView(Expression<Func<ET_StockOut, bool>> exporder)
  82. {
  83. //var studentList = from a in StudentDistributeRepository.Entities.Where(x => x.StockOutType == (int)CF_StockOutType.StudentPutOut && x.RecordStatus == (int)CF_GeneralPurpose.IsYes)
  84. // join kc in TeachingMateriaInventoryRepository.Entities on a.TeachingMaterialPoolID equals kc.TeachingMaterialPoolID into kctmp
  85. // from kcmp in kctmp.DefaultIfEmpty()
  86. // select new
  87. // {
  88. // TeachingMaterialPoolID = (Guid)a.TeachingMaterialPoolID,
  89. // SchoolyearID = (Guid)a.EM_SpecialtyPlan.SchoolyearID,
  90. // Quantity = (int)a.DistributeQty - a.CF_Student.Count(),
  91. // StockOutType = (int)a.StockOutType
  92. // };
  93. var stockOutList = from a in StockOutRepository.Entities.Where(x => x.RecordStatus == (int)CF_GeneralPurpose.IsYes)
  94. join e in StockOutDetailRepository.Entities on a.StockOutID equals e.StockOutID
  95. select new
  96. {
  97. TeachingMaterialPoolID = (Guid)e.TeachingMaterialPoolID,
  98. SchoolyearID = (Guid)a.SchoolyearID,
  99. Quantity = (int)e.StockOutQuantity,
  100. StockOutType = (int)a.StockOutType,
  101. DiscountPrice = e.Discount,
  102. Discount = e.DiscountPrice
  103. };
  104. var viewList = (from a in stockOutList
  105. join b in SchoolyearRepository.Entities on a.SchoolyearID equals b.SchoolyearID
  106. // join c in UserRepository.Entities on a.RecipientUserID equals c.UserID
  107. join t in TeachingMaterialPoolRepository.Entities on a.TeachingMaterialPoolID equals t.TeachingMaterialPoolID
  108. join d in PublishRepository.Entities on t.PublishID equals d.PublishID
  109. join sct in DictionaryItemRepository.Entities on new { StockInType = a.StockOutType, DictionaryCode = DictionaryItem.CF_StockOutType.ToString() }
  110. equals new { StockInType = (int)sct.Value, sct.DictionaryCode } into tsct
  111. from csct in tsct.DefaultIfEmpty()
  112. //join kc in TeachingMateriaInventoryRepository.Entities on a.TeachingMaterialPoolID equals kc.TeachingMaterialPoolID into kctmp
  113. //from kcmp in kctmp.DefaultIfEmpty()
  114. group new { b, t, a, d, csct } by
  115. new
  116. {
  117. //kcmp.Discount,//折合价
  118. a.StockOutType,
  119. a.Discount,//折扣率
  120. a.DiscountPrice,//折合价
  121. StockOutTypeName = csct.Name,
  122. a.SchoolyearID,
  123. b.Code,
  124. d.UnitName,
  125. t.ISBN,
  126. t.PublishID,
  127. t.PublishTime,
  128. t.Author,
  129. t.TeachingMaterialCode,
  130. t.TeachingMaterialName,
  131. t.TeachingMaterialTypeID,
  132. t.TeachingMaterialPoolID,
  133. t.Price,
  134. } into h
  135. select new StockOutView
  136. {
  137. StockOutTypeName = h.Key.StockOutTypeName,
  138. StockOutTypeID = h.Key.StockOutType,
  139. //RecordStatusName = h.Key.Name,
  140. SchoolyearName = h.Key.Code,
  141. SchoolyearID = h.Key.SchoolyearID,
  142. TeachingMaterialPoolID = h.Key.TeachingMaterialPoolID,
  143. SupplierID = h.Key.PublishID,
  144. TeachingMaterialCode = h.Key.TeachingMaterialCode,
  145. TeachingMaterialName = h.Key.TeachingMaterialName,
  146. ISBN = h.Key.ISBN,
  147. PublishName = h.Key.UnitName,
  148. SupplierName = h.Key.UnitName,
  149. PublishTime = h.Key.PublishTime,
  150. Author = h.Key.Author,
  151. Quantity = h.Sum(x => x.a.Quantity),
  152. Price = h.Key.Price,
  153. Discount = h.Key.Discount, // h.Key.Price,//折扣率=折合价/单价
  154. DiscountPrice = h.Key.DiscountPrice,
  155. TotalPrice = h.Key.Price * h.Sum(x => x.a.Quantity),
  156. TotalDollar = h.Key.DiscountPrice * h.Sum(x => x.a.Quantity) == null ? 0 : h.Key.DiscountPrice * h.Sum(x => x.a.Quantity)
  157. //StockOutUserName =
  158. //StockOutTime =
  159. });
  160. return viewList;
  161. }
  162. #endregion
  163. }
  164. }