/// <summary>
 /// 创建新的 StockGoods 对象。
 /// </summary>
 /// <param name="goods">Goods 属性的初始值。</param>
 /// <param name="ownerSite">OwnerSite 属性的初始值。</param>
 /// <param name="number">Number 属性的初始值。</param>
 public static StockGoods CreateStockGoods(global::System.String goods, global::System.String ownerSite, global::System.Int32 number)
 {
     StockGoods stockGoods = new StockGoods();
     stockGoods.Goods = goods;
     stockGoods.OwnerSite = ownerSite;
     stockGoods.Number = number;
     return stockGoods;
 }
 /// <summary>
 /// 用于向 StockGoods EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToStockGoods(StockGoods stockGoods)
 {
     base.AddObject("StockGoods", stockGoods);
 }
Beispiel #3
0
        /// <summary>
        /// 入库登记
        /// </summary>
        public static void InsertStockGoodsRegister(StockGoodsRegister objRegister)
        {
            try
            {
                LDLLogisticsEntities context = new LDLLogisticsEntities();
                StockGoods objGoods = context.StockGoods.FirstOrDefault(obj => obj.OwnerSite == objRegister.OwnerSite && obj.Goods == objRegister.Goods);
                bool isExists = objGoods != null;

                //报损报废和调拨的数量超过库存是报错
                if (objRegister.ActionType == "报损报废" || objRegister.ActionType == "调拨")
                {
                    if (!isExists || objRegister.Number > objGoods.Number)
                        throw new Exception(string.Format("{0}数量({1})超出库存数量({2})", objRegister.ActionType,
                            objRegister.Number, objGoods == null ? 0 : objGoods.Number));
                }

                if (!isExists)
                {
                    objGoods = new StockGoods();
                    objGoods.OwnerSite = objRegister.OwnerSite;
                    objGoods.Goods = objRegister.Goods;
                    objGoods.Price = objRegister.Price;
                    objGoods.Number = objRegister.Number;
                }
                else
                {
                    if (objRegister.Price.HasValue && objRegister.ActionType == "入库")
                        objGoods.Price = objRegister.Price.Value;
                    if (objRegister.ActionType == "入库")
                        objGoods.Number += objRegister.Number;
                    else //报损报废和调拨 扣掉总数
                        objGoods.Number -= objRegister.Number;
                }

                context.StockGoodsRegister.AddObject(objRegister);    //新增入库登记
                if (!isExists)
                    context.StockGoods.AddObject(objGoods);           //新增或更新库存记录
                context.SysOperationLog.AddObject(SysOperationLogAdapter.GetOperationtLog("StockGoodsAdapter01", Define.Insert, objRegister));   //记录日志
                context.SaveChanges();  //提交保存
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }
        }