コード例 #1
0
 public override void AdjustStock(StockQuantity quantity)
 {
     if (quantity is PrePackedStockQuantity)
     {
         PrePackedStockQuantity quan = quantity as PrePackedStockQuantity;
         _StoredStock += quan.Quantity;
     }
 }
コード例 #2
0
        public override bool Purchase(StockQuantity quantity, out Item item)
        {
            PrePackedStockQuantity quan = quantity as PrePackedStockQuantity;
            double targetQuantity       = 1;

            if (quantity != null)
            {
                if (quan.Quantity > _ShelfStock)
                {
                    targetQuantity = _ShelfStock;
                }
                else if (_ShelfStock >= quan.Quantity)
                {
                    targetQuantity = quan.Quantity;
                }
            }
            else if (quantity == null)
            {
                if (_ShelfStock > 0)
                {
                    targetQuantity = 1;
                }
                if (_ShelfStock <= 0)
                {
                    targetQuantity = 0;
                }
            }

            // Calculations
            _ShelfStock -= targetQuantity;
            // ^^^^^

            if (targetQuantity == 0)
            {
                item = null;
                return(false);
            }
            else
            {
                item = new Item((Convert.ToInt32(targetQuantity)), (Line.Description), (targetQuantity * calculateweight));
            }
            return(true);
        }