StockInDetailDAL.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 StockInDetailDAL
  13. {
  14. public TeachersOrderRepository TeachersOrderRepository { get; set; }
  15. public StockInRepository StockInRepository { get; set; }
  16. public StockInDetailRepository StockInDetailRepository { get; set; }
  17. public SchoolyearRepository SchoolyearRepository { get; set; }
  18. public UserRepository UserRepository { get; set; }
  19. public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
  20. public CoursematerialRepository CoursematerialRepository { get; set; }
  21. public PublishRepository PublishRepository { get; set; }
  22. public CollegeRepository CollegeRepository { get; set; }
  23. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  24. public IQueryable<StockInView> GetStockInDetailGridView(Expression<Func<ET_StockIn, bool>> exporder)
  25. {
  26. var viewList = (from a in StockInRepository.Entities.Where(exporder)
  27. join b in SchoolyearRepository.Entities on a.SchoolyearID equals b.SchoolyearID
  28. join c in UserRepository.Entities on a.HandlerUserID equals c.UserID
  29. into cdata
  30. from ctb in cdata.DefaultIfEmpty()
  31. join f in UserRepository.Entities on a.CreateUserID equals f.UserID
  32. into fdata
  33. from ftb in fdata.DefaultIfEmpty()
  34. join d in PublishRepository.Entities on a.SupplierID equals d.PublishID
  35. into ddata
  36. from dtb in ddata.DefaultIfEmpty()
  37. from e in a.ET_StockInDetail
  38. join t in TeachingMaterialPoolRepository.Entities on e.CF_TeachingMaterialPool.TeachingMaterialPoolID
  39. equals t.TeachingMaterialPoolID
  40. select new StockInView
  41. {
  42. StockInDocumentNo = a.StockInDocumentNo,
  43. StockInNumber = a.StockInNumber,
  44. SchoolyearName = b.Code,
  45. SchoolyearID = a.SchoolyearID,
  46. SupplierID = a.SupplierID,
  47. TeachingMaterialCode = t.TeachingMaterialCode,
  48. TeachingMaterialName = t.TeachingMaterialName,
  49. PublishName = dtb.UnitName,
  50. SupplierName = dtb.UnitName,
  51. HandlerUserName = ctb.Name,
  52. PublishTime = t.PublishTime,
  53. StockInUserName = ftb.Name,
  54. StockInTime = a.StockInTime,
  55. Author = t.Author,
  56. Quantity = e.Quantity == null ? 0 : e.Quantity,
  57. Price = t.Price,
  58. Discount = e.Discount == null ? 0 : e.Discount,
  59. DiscountPrice = (e.Discount * t.Price) == null ? 0 : (e.Discount * t.Price),
  60. TotalPrice = t.Price * e.Quantity,
  61. TotalDollar = (e.Discount * t.Price) * e.Quantity == null ? 0 : (e.Discount * t.Price) * e.Quantity,
  62. });
  63. return viewList;
  64. }
  65. #region 2.0 删除明细
  66. public void Delete(List<Guid> stockInDetailIDs)
  67. {
  68. try
  69. {
  70. if (stockInDetailIDs.Count > 0)
  71. {
  72. foreach (var stockInDetailID in stockInDetailIDs)
  73. {
  74. StockInDetailRepository.UnitOfWork.Delete<ET_StockInDetail>(x => x.StockInDetailID == stockInDetailID);
  75. }
  76. }
  77. }
  78. catch (Exception ex)
  79. {
  80. throw ex;
  81. }
  82. }
  83. #endregion
  84. #region 3.0 入库统计信息
  85. public IQueryable<StockInView> GetStockInStatisticsGridView(Expression<Func<ET_StockIn, bool>> exporder)
  86. {
  87. var viewList = (from a in StockInRepository.Entities.Where(exporder)
  88. join b in SchoolyearRepository.Entities on a.SchoolyearID equals b.SchoolyearID
  89. join c in UserRepository.Entities on a.HandlerUserID equals c.UserID
  90. join f in UserRepository.Entities on a.CreateUserID equals f.UserID
  91. join e in StockInDetailRepository.Entities on a.StockInID equals e.StockInID
  92. join t in TeachingMaterialPoolRepository.Entities on e.TeachingMaterialPoolID equals t.TeachingMaterialPoolID
  93. join d in PublishRepository.Entities on t.PublishID equals d.PublishID
  94. join s in PublishRepository.Entities on a.SupplierID equals s.PublishID
  95. into g
  96. from x in g.DefaultIfEmpty()//自动生成入库没有供应商信息
  97. group new { a, b, t, e, d } by
  98. new
  99. {
  100. e.Discount,
  101. e.DiscountPrice,
  102. a.StockInType,
  103. a.SchoolyearID,
  104. a.SupplierID,
  105. SupplierName=x.UnitName,
  106. b.Code,
  107. d.UnitName,
  108. t.PublishTime,
  109. t.TeachingMaterialTypeID,
  110. t.ISBN,
  111. t.Author,
  112. t.TeachingMaterialCode,
  113. t.TeachingMaterialName,
  114. t.TeachingMaterialPoolID,
  115. t.Price,
  116. t.PublishID
  117. } into h
  118. select new StockInView
  119. {
  120. SchoolyearName = h.Key.Code,
  121. SchoolyearID = h.Key.SchoolyearID,
  122. SupplierID = h.Key.PublishID,
  123. TeachingMaterialCode = h.Key.TeachingMaterialCode,
  124. TeachingMaterialName = h.Key.TeachingMaterialName,
  125. PublishName = h.Key.UnitName,
  126. SupplierName = h.Key.SupplierName,
  127. TeachingMaterialTypeID = h.Key.TeachingMaterialTypeID,
  128. PublishTime = h.Key.PublishTime,
  129. ISBN = h.Key.ISBN,
  130. TeachingMaterialPoolID = h.Key.TeachingMaterialPoolID,
  131. Author = h.Key.Author,
  132. Quantity = h.Sum(x => x.e.Quantity),
  133. Price = Math.Round((decimal)h.Key.Price,2),
  134. Discount = h.Key.Discount == null ? 0 : h.Key.Discount,
  135. DiscountPrice = h.Key.DiscountPrice == null ? 0 : h.Key.DiscountPrice,
  136. TotalPrice = (h.Key.Price * h.Sum(x => x.e.Quantity)),
  137. TotalDollar = h.Key.DiscountPrice * h.Sum(x => x.e.Quantity) == null ? 0 : (h.Key.DiscountPrice * h.Sum(x => x.e.Quantity))
  138. });
  139. return viewList;
  140. }
  141. #endregion
  142. }
  143. }