Example #1
0
        /// <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;
                }
            }
        }
Example #2
0
        /// <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;
                }
            }
        }