/// <summary> /// 原材料库存相应更改 /// 规则:把所有筒仓同名的材料进行累计-修改 /// </summary> /// <param name="entity"></param> public void UpdateSiloContent(Silo entity, decimal beforeContent) { //添加盘点记录 SiloLedgerContent_InAndCheck slc = new SiloLedgerContent_InAndCheck(); slc.SiloID = entity.ID; slc.StuffID = entity.StuffID; slc.Action = "盘点"; slc.BaseStore = beforeContent; slc.Num = entity.Content; slc.Remaining = entity.Content; slc.ActionTime = DateTime.Now; slc.UserName = AuthorizationService.CurrentUserID; this.m_UnitOfWork.GetRepositoryBase <SiloLedgerContent_InAndCheck>().Add(slc); base.Update(entity, null); //累计所有筒仓的同名材料的库存修改材料的当前库存 string stuffId = entity.StuffID; var silolist = this.All(); decimal stuffAmount = 0; decimal allStuffAmount = 0; foreach (var psilo in silolist) { stuffAmount = stuffAmount + (psilo.StuffID == stuffId ? psilo.Content : 0); } allStuffAmount = stuffAmount; StuffInfoService stuffinfoService = new StuffInfoService(this.m_UnitOfWork); StuffInfo stuffinfo = stuffinfoService.Get(stuffId); stuffinfo.Inventory = allStuffAmount; stuffinfoService.Inventory(stuffinfo); }
/// <summary> /// 车辆加油--修改 /// </summary> /// <param name="entity"></param> /// <param name="form"></param> public override void Update(CarOil entity, System.Collections.Specialized.NameValueCollection form) { using (IGenericTransaction tx = this.m_UnitOfWork.BeginTransaction()) { try { //获取油料密度值 PublicService ps = new PublicService(); SysConfig config = ps.SysConfig.GetSysConfig(Model.Enums.SysConfigEnum.OilDensity); if (config == null) { config.ConfigValue = "0"; } //entity.TotalPrice = entity.Amount * entity.UnitPrice; entity.KiloMeter = entity.ThisKM - entity.LastKM; decimal newAmount = entity.Amount; var obj = this.Get(entity.ID); decimal subAmount = newAmount - obj.Amount * Convert.ToDecimal(config.ConfigValue); base.Update(entity, form); obj.StuffInfo.Inventory -= subAmount; StuffInfoService stuffService = new StuffInfoService(this.m_UnitOfWork); stuffService.Update(obj.StuffInfo, null); obj.Silo.Content -= subAmount; SiloService siloService = new SiloService(this.m_UnitOfWork); siloService.Update(obj.Silo, null); tx.Commit(); } catch { tx.Rollback(); throw; } } }
/// <summary> /// 车辆加油--增加 /// </summary> /// <param name="entity"></param> /// <returns></returns> public override CarOil Add(CarOil entity) { using (IGenericTransaction tx = this.m_UnitOfWork.BeginTransaction()) { try { //entity.TotalPrice = entity.Amount * entity.UnitPrice; entity.KiloMeter = entity.ThisKM - entity.LastKM; base.Add(entity); StuffInfoService stuffService = new StuffInfoService(this.m_UnitOfWork); var stuffInfo = stuffService.Get(entity.StuffID); //获取油料密度值 PublicService ps = new PublicService(); SysConfig config = ps.SysConfig.GetSysConfig(Model.Enums.SysConfigEnum.OilDensity); if (config == null) { config.ConfigValue = "0"; } //减少库存量(加油量*油料密度) stuffInfo.Inventory -= entity.Amount * Convert.ToDecimal(config.ConfigValue); stuffService.Update(stuffInfo, null); SiloService siloService = new SiloService(this.m_UnitOfWork); var siloInfo = siloService.Get(entity.SiloID); siloInfo.Content -= entity.Amount * Convert.ToDecimal(config.ConfigValue); siloService.Update(siloInfo, null); tx.Commit(); return(entity); } catch { tx.Rollback(); throw; } } }