예제 #1
0
 public override void AdjustStock(StockQuantity quantity)
 {
     if (quantity is DiscreteStockQuantity)
     {
         DiscreteStockQuantity quan = quantity as DiscreteStockQuantity;
         _StoredStock += quan.Quantity;
     }
 }
예제 #2
0
        public override bool Purchase(StockQuantity quantity, out Item item)
        {
            DiscreteStockQuantity quan = quantity as DiscreteStockQuantity;
            int 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((targetQuantity), Line.Description, (targetQuantity * WeightPerItem));
            }
            return(true);

            // OLD CODE THAT DIDN'T WORK - KEEPING IT FOR REFERENCE //

            /* if (quantity is DiscreteStockQuantity)
             *   {
             *       QuantityIsDiscrete = true;
             *   }
             *   else if (quantity is VolumeStockQuantity || quantity == null)
             *   {
             *       QuantityIsDiscrete = false;
             *   }
             *
             *
             *   if (QuantityIsDiscrete == true)
             *   {
             *        if (quan.Quantity > _ShelfStock)
             *        {
             *           int maxshelf = quan.Quantity;
             *           _ShelfStock -= maxshelf;
             *        }
             *        else if (_ShelfStock >= quan.Quantity)
             *        {
             *           _ShelfStock -= quan.Quantity;
             *        }
             *    }
             *   else if (QuantityIsDiscrete == false)
             *   {
             *           if (_ShelfStock > 0)
             *           {
             *               _ShelfStock -= 1;
             *           }
             *
             * }
             * if(quantity == null)
             * {
             *   item = null;
             *   return false;
             * }
             * else
             * item = new Item((quan.Quantity), Line.Description, (quan.Quantity * WeightPerItem));
             * return true; */
        }