SupplierDiscountSetServices.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq.Entity;
  6. using EMIS.ViewModel.TeachingMaterial;
  7. using EMIS.ViewModel;
  8. using EMIS.DataLogic.Common.TeachingMaterial;
  9. using System.Linq.Expressions;
  10. using EMIS.Entities;
  11. using Bowin.Common.Linq;
  12. namespace EMIS.CommonLogic.TeachingMaterial
  13. {
  14. public class SupplierDiscountSetServices : BaseServices, ISupplierDiscountSetServices
  15. {
  16. public SupplierDiscountSetDAL supplierDiscountSetDAL { get; set; }
  17. public IGridResultSet<SupplierDiscountSetView> GetSupplierDiscountSetViewGrid(ConfiguretView configuretView, bool? isDefault, int pageIndex, int pageSize)
  18. {
  19. Expression<Func<ET_SupplierDiscountSet, bool>> exp = (x => true);
  20. if (isDefault.HasValue)
  21. {
  22. exp = exp.And(x => x.IsDefault == isDefault);
  23. }
  24. var query = supplierDiscountSetDAL.GetSupplierDiscountSetGridView(exp);
  25. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  26. //return this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.CreateTime).ToGridResultSet<TeachersOrderView>(pageIndex, pageSize);
  27. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.SupplierDiscountSetID);
  28. var result = query.OrderBy(x => x.SupplierDiscountSetID).ToGridResultSet<SupplierDiscountSetView>(pageIndex, pageSize);
  29. return result;
  30. }
  31. public List<SupplierDiscountSetView> GetSupplierDiscountSetViewList(ConfiguretView configuretView, bool? isDefault, List<Guid?> supplierDiscountSetIDList)
  32. {
  33. Expression<Func<ET_SupplierDiscountSet, bool>> exp = (x => true);
  34. if (isDefault.HasValue)
  35. {
  36. exp = exp.And(x => x.IsDefault == isDefault);
  37. }
  38. if (supplierDiscountSetIDList != null)
  39. {
  40. exp = exp.And(x => supplierDiscountSetIDList.Contains(x.SupplierDiscountSetID));
  41. }
  42. var query = supplierDiscountSetDAL.GetSupplierDiscountSetGridView(exp);
  43. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  44. //return this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.CreateTime).ToGridResultSet<TeachersOrderView>(pageIndex, pageSize);
  45. query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.SupplierDiscountSetID);
  46. var result = query.OrderBy(x => x.UnitCode).ToList();
  47. return result;
  48. }
  49. public SupplierDiscountSetView GetSupplierDiscountSetView(Guid SupplierDiscountSetID)
  50. {
  51. return supplierDiscountSetDAL.GetSupplierDiscountSetGridView(x => x.SupplierDiscountSetID == SupplierDiscountSetID).FirstOrDefault();
  52. }
  53. public void SupplierDiscountSetViewEdit(SupplierDiscountSetView supplierDiscountSetView)
  54. {
  55. try
  56. {
  57. //查询数据库进行验证
  58. var supplierDiscountSetVerification = supplierDiscountSetDAL.supplierDiscountSetRepository
  59. .GetSingle(x => x.SupplierDiscountSetID != supplierDiscountSetView.SupplierDiscountSetID
  60. && x.PublishID == supplierDiscountSetView.PublishID
  61. && x.Discount == supplierDiscountSetView.Discount);
  62. if (supplierDiscountSetVerification == null)
  63. {
  64. if (supplierDiscountSetView.IsDefault == true)
  65. {//只允许一个供应商为默认
  66. List<ET_SupplierDiscountSet> supplierDiscountSetList = supplierDiscountSetDAL.supplierDiscountSetRepository.GetList(x => x.IsDefault == true).ToList();
  67. foreach (ET_SupplierDiscountSet sdset in supplierDiscountSetList)
  68. {
  69. sdset.IsDefault = false;//当新增或修改的供应商为默认时,将数据库中为默认的供应商改为false
  70. SetModifyStatus(sdset);
  71. }
  72. }
  73. if (supplierDiscountSetView.SupplierDiscountSetID != Guid.Empty)
  74. {
  75. var supplierDiscountSet = supplierDiscountSetDAL.supplierDiscountSetRepository
  76. .GetSingle(x => x.SupplierDiscountSetID == supplierDiscountSetView.SupplierDiscountSetID);
  77. //修改
  78. supplierDiscountSet.PublishID = supplierDiscountSetView.PublishID;
  79. supplierDiscountSet.Discount = supplierDiscountSetView.Discount;
  80. supplierDiscountSet.IsDefault = supplierDiscountSetView.IsDefault;
  81. SetModifyStatus(supplierDiscountSet);
  82. }
  83. else
  84. {
  85. //新增
  86. ET_SupplierDiscountSet supplierDiscountSet = new ET_SupplierDiscountSet();
  87. supplierDiscountSet.SupplierDiscountSetID = Guid.NewGuid();
  88. supplierDiscountSet.PublishID = supplierDiscountSetView.PublishID;
  89. supplierDiscountSet.Discount = supplierDiscountSetView.Discount;
  90. supplierDiscountSet.IsDefault = supplierDiscountSetView.IsDefault;
  91. SetNewStatus(supplierDiscountSet);
  92. UnitOfWork.Add(supplierDiscountSet);
  93. }
  94. }
  95. else
  96. {
  97. throw new Exception("已存在相同的供应商折扣率设置,请核查");
  98. }
  99. //事务提交
  100. UnitOfWork.Commit();
  101. }
  102. catch (Exception ex)
  103. {
  104. throw new Exception(ex.Message);
  105. }
  106. }
  107. /// <summary>
  108. /// 删除
  109. /// </summary>
  110. /// <param name="graduationCourseIDList"></param>
  111. /// <returns></returns>
  112. public void SupplierDiscountSetDelete(IList<Guid?> supplierDiscountSetIDList)
  113. {
  114. try
  115. {
  116. UnitOfWork.Delete<ET_SupplierDiscountSet>(x => supplierDiscountSetIDList.Contains(x.SupplierDiscountSetID));
  117. UnitOfWork.Commit();
  118. }
  119. catch (Exception ex)
  120. {
  121. throw new Exception(ex.Message);
  122. }
  123. }
  124. public decimal? GetDiscountByPublishID(Guid publishID)
  125. {
  126. decimal? discount = 1;
  127. if (supplierDiscountSetDAL.supplierDiscountSetRepository.GetSingle(x => x.PublishID == publishID) != null)
  128. {
  129. discount = supplierDiscountSetDAL.supplierDiscountSetRepository.GetSingle(x => x.PublishID == publishID).Discount;
  130. }
  131. return discount;
  132. }
  133. }
  134. }