コード例 #1
0
        /// <summary>
        /// 更新储位在库库存(收货、拣货移入)
        /// </summary>
        /// <param name="warehouseId"></param>
        /// <param name="productId"></param>
        /// <param name="locationFrom"></param>
        /// <param name="locationTo"></param>
        /// <param name="moveInQty"></param>
        /// <param name="isOpenTrans"></param>
        public bool UpdateInventoryByMoveIn(string warehouseId, InventoryLocationTransactionType type, string productId, string locationFrom, string locationTo, int moveInQty, DbTransaction isOpenTrans)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(@"SELECT * FROM dbo.Inventory_Location WHERE WarehouseId = @WarehouseId");
            strSql.Append(" AND ProductId = @ProductId");
            strSql.Append(" AND LocationCode = @LocationCode");

            var parameter = new List <DbParameter>
            {
                DbFactory.CreateDbParameter("@WarehouseId", warehouseId),
                DbFactory.CreateDbParameter("@ProductId", productId),
                DbFactory.CreateDbParameter("@LocationCode", locationTo)
            };

            InventoryLocationTransactionEntity locationTransaction = new InventoryLocationTransactionEntity();

            locationTransaction.Create();
            locationTransaction.Type         = (int)type;
            locationTransaction.WarehouseId  = warehouseId;
            locationTransaction.ProductId    = productId;
            locationTransaction.LocationFrom = locationFrom;
            locationTransaction.LocationTo   = locationTo;
            locationTransaction.Qty          = moveInQty;

            var isOK = new InventoryLocationTransactionBLL().InsertTransaction(locationTransaction, isOpenTrans);

            if (isOK)
            {
                var inventory = Repository().FindEntityBySql(strSql.ToString(), parameter.ToArray());
                if (string.IsNullOrEmpty(inventory?.InventoryId))
                {
                    inventory = new InventoryLocationEntity();
                    inventory.Create();
                    inventory.WarehouseId  = warehouseId;
                    inventory.ProductId    = productId;
                    inventory.LocationCode = locationTo;
                    inventory.QtyOnHand    = moveInQty;
                    return(Repository().Insert(inventory, isOpenTrans) > 0);
                }
                else
                {
                    StringBuilder strUpdateSql = new StringBuilder();
                    strUpdateSql.Append(@"UPDATE [Inventory_Location] SET QtyOnHand = QtyOnHand + @QtyOnHand WHERE InventoryId = @InventoryId ");

                    List <DbParameter> updateParameters = new List <DbParameter>
                    {
                        DbFactory.CreateDbParameter("@QtyOnHand", moveInQty),
                        DbFactory.CreateDbParameter("@InventoryId", inventory.InventoryId)
                    };
                    return(Repository().ExecuteBySql(strUpdateSql, updateParameters.ToArray(), isOpenTrans) > 0);
                }
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="warehouseId"></param>
        /// <param name="productId"></param>
        /// <param name="locationCode"></param>
        /// <param name="qtyReceipt"></param>
        /// <param name="isOpenTrans"></param>
        /// <returns></returns>
        public bool UpdateInventoryByUnReceive(string warehouseId, InventoryLocationTransactionType type, string productId, string locationCode, int qtyReceipt, DbTransaction isOpenTrans)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(@"UPDATE [Inventory_Location] SET QtyOnHand = QtyOnHand - @QtyReceipt ");
            strSql.Append(" WHERE ProductId = @ProductId");
            strSql.Append(" AND WarehouseId = @WarehouseId");
            strSql.Append(" AND LocationCode = @LocationCode ");
            strSql.Append(" AND QtyOnHand - @QtyReceipt >= 0");

            var updateParameters = new List <DbParameter>
            {
                DbFactory.CreateDbParameter("@WarehouseId", warehouseId),
                DbFactory.CreateDbParameter("@ProductId", productId),
                DbFactory.CreateDbParameter("@LocationCode", locationCode),
                DbFactory.CreateDbParameter("@QtyReceipt", qtyReceipt)
            };
            InventoryLocationTransactionEntity locationTransaction = new InventoryLocationTransactionEntity();

            locationTransaction.Create();
            locationTransaction.Type         = (int)type;
            locationTransaction.WarehouseId  = warehouseId;
            locationTransaction.ProductId    = productId;
            locationTransaction.LocationFrom = locationCode;
            locationTransaction.LocationTo   = "";
            locationTransaction.Qty          = -1 * qtyReceipt;

            var isOK = new InventoryLocationTransactionBLL().InsertTransaction(locationTransaction, isOpenTrans);

            if (isOK)
            {
                return(Repository().ExecuteBySql(strSql, updateParameters.ToArray(), isOpenTrans) > 0);
            }
            else
            {
                return(false);
            }
        }