/// <summary> /// 用于向 StockGoodsRegister EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToStockGoodsRegister(StockGoodsRegister stockGoodsRegister) { base.AddObject("StockGoodsRegister", stockGoodsRegister); }
public void InsertStockGoodsRegister(StockGoodsRegister objRegister) { StockGoodsAdapter.InsertStockGoodsRegister(objRegister); }
/// <summary> /// 创建新的 StockGoodsRegister 对象。 /// </summary> /// <param name="id">ID 属性的初始值。</param> /// <param name="stockDate">StockDate 属性的初始值。</param> /// <param name="goods">Goods 属性的初始值。</param> /// <param name="ownerSite">OwnerSite 属性的初始值。</param> /// <param name="number">Number 属性的初始值。</param> /// <param name="actionType">ActionType 属性的初始值。</param> /// <param name="valid">Valid 属性的初始值。</param> public static StockGoodsRegister CreateStockGoodsRegister(global::System.Int32 id, global::System.DateTime stockDate, global::System.String goods, global::System.String ownerSite, global::System.Int32 number, global::System.String actionType, global::System.Boolean valid) { StockGoodsRegister stockGoodsRegister = new StockGoodsRegister(); stockGoodsRegister.ID = id; stockGoodsRegister.StockDate = stockDate; stockGoodsRegister.Goods = goods; stockGoodsRegister.OwnerSite = ownerSite; stockGoodsRegister.Number = number; stockGoodsRegister.ActionType = actionType; stockGoodsRegister.Valid = valid; return stockGoodsRegister; }
/// <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); } }