using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.TeachingMaterial; using EMIS.ViewModel; using EMIS.DataLogic.Common.TeachingMaterial; using System.Linq.Expressions; using EMIS.Entities; using Bowin.Common.Linq; namespace EMIS.CommonLogic.TeachingMaterial { public class SupplierDiscountSetServices : BaseServices, ISupplierDiscountSetServices { public SupplierDiscountSetDAL supplierDiscountSetDAL { get; set; } public IGridResultSet GetSupplierDiscountSetViewGrid(ConfiguretView configuretView, bool? isDefault, int pageIndex, int pageSize) { Expression> exp = (x => true); if (isDefault.HasValue) { exp = exp.And(x => x.IsDefault == isDefault); } var query = supplierDiscountSetDAL.GetSupplierDiscountSetGridView(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) //return this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize); query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.SupplierDiscountSetID); var result = query.OrderBy(x => x.SupplierDiscountSetID).ToGridResultSet(pageIndex, pageSize); return result; } public List GetSupplierDiscountSetViewList(ConfiguretView configuretView, bool? isDefault, List supplierDiscountSetIDList) { Expression> exp = (x => true); if (isDefault.HasValue) { exp = exp.And(x => x.IsDefault == isDefault); } if (supplierDiscountSetIDList != null) { exp = exp.And(x => supplierDiscountSetIDList.Contains(x.SupplierDiscountSetID)); } var query = supplierDiscountSetDAL.GetSupplierDiscountSetGridView(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) //return this.GetQueryByDataRangeByCollege(query).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize); query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.SupplierDiscountSetID); var result = query.OrderBy(x => x.UnitCode).ToList(); return result; } public SupplierDiscountSetView GetSupplierDiscountSetView(Guid SupplierDiscountSetID) { return supplierDiscountSetDAL.GetSupplierDiscountSetGridView(x => x.SupplierDiscountSetID == SupplierDiscountSetID).FirstOrDefault(); } public void SupplierDiscountSetViewEdit(SupplierDiscountSetView supplierDiscountSetView) { try { //查询数据库进行验证 var supplierDiscountSetVerification = supplierDiscountSetDAL.supplierDiscountSetRepository .GetSingle(x => x.SupplierDiscountSetID != supplierDiscountSetView.SupplierDiscountSetID && x.PublishID == supplierDiscountSetView.PublishID && x.Discount == supplierDiscountSetView.Discount); if (supplierDiscountSetVerification == null) { if (supplierDiscountSetView.IsDefault == true) {//只允许一个供应商为默认 List supplierDiscountSetList = supplierDiscountSetDAL.supplierDiscountSetRepository.GetList(x => x.IsDefault == true).ToList(); foreach (ET_SupplierDiscountSet sdset in supplierDiscountSetList) { sdset.IsDefault = false;//当新增或修改的供应商为默认时,将数据库中为默认的供应商改为false SetModifyStatus(sdset); } } if (supplierDiscountSetView.SupplierDiscountSetID != Guid.Empty) { var supplierDiscountSet = supplierDiscountSetDAL.supplierDiscountSetRepository .GetSingle(x => x.SupplierDiscountSetID == supplierDiscountSetView.SupplierDiscountSetID); //修改 supplierDiscountSet.PublishID = supplierDiscountSetView.PublishID; supplierDiscountSet.Discount = supplierDiscountSetView.Discount; supplierDiscountSet.IsDefault = supplierDiscountSetView.IsDefault; SetModifyStatus(supplierDiscountSet); } else { //新增 ET_SupplierDiscountSet supplierDiscountSet = new ET_SupplierDiscountSet(); supplierDiscountSet.SupplierDiscountSetID = Guid.NewGuid(); supplierDiscountSet.PublishID = supplierDiscountSetView.PublishID; supplierDiscountSet.Discount = supplierDiscountSetView.Discount; supplierDiscountSet.IsDefault = supplierDiscountSetView.IsDefault; SetNewStatus(supplierDiscountSet); UnitOfWork.Add(supplierDiscountSet); } } else { throw new Exception("已存在相同的供应商折扣率设置,请核查"); } //事务提交 UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } /// /// 删除 /// /// /// public void SupplierDiscountSetDelete(IList supplierDiscountSetIDList) { try { UnitOfWork.Delete(x => supplierDiscountSetIDList.Contains(x.SupplierDiscountSetID)); UnitOfWork.Commit(); } catch (Exception ex) { throw new Exception(ex.Message); } } public decimal? GetDiscountByPublishID(Guid publishID) { decimal? discount = 1; if (supplierDiscountSetDAL.supplierDiscountSetRepository.GetSingle(x => x.PublishID == publishID) != null) { discount = supplierDiscountSetDAL.supplierDiscountSetRepository.GetSingle(x => x.PublishID == publishID).Discount; } return discount; } } }