示例#1
0
        public void MakeASale(Sale sale)
        {
            /// Gates available quantity..
            Observer  list  = _observers.Find(element => element.GetType().Equals(typeof(Available)));
            Available table = (Available)list;
            int       q     = ((Product)table.Table[sale.ProductName]).Quantity;

            if (q > sale.Quantity)
            {
                this.Sale = sale;
                _isSold   = true;
                notifyAll();
            }
            else
            {
                Console.WriteLine(" Your request for " + sale.Quantity + " units of '" + sale.ProductName + "' can not be executed!");
                Console.WriteLine(" Available from stock '" + sale.ProductName + "' are: " + q);
            }
        }
示例#2
0
        static void Main(string [] args)
        {
            warehouse     = new Warehouse();
            supply        = new SupplyList(warehouse);
            availableList = new Available(warehouse);
            sales         = new SalesList(warehouse);

            Console.WriteLine("Before delivery..");
            showAvailable();

            warehouse.MakeDelivery(new Delivery("Firm1", "Product 1", 1000));
            warehouse.MakeDelivery(new Delivery("Firm2", "Product 1", 2000));
            warehouse.MakeDelivery(new Delivery("Firm1", "Product 1", 3000));
            warehouse.MakeDelivery(new Delivery("Firm3", "Product 1", 1));
            warehouse.MakeDelivery(new Delivery("Firm1", "Product 1", 20));
            warehouse.MakeDelivery(new Delivery("Firm1", "Product 1", 300));
            warehouse.MakeDelivery(new Delivery("Firm3", "Product 3", 100));
            warehouse.MakeDelivery(new Delivery("Firm1", "Product 3", 200));
            warehouse.MakeDelivery(new Delivery("Firm1", "Product 3", 300));


            Console.WriteLine("After delivery..");
            showDeliveryes();
            showAvailable();

            Console.WriteLine("Available : ");
            showAvailable();

            warehouse.MakeASale(new Sale("random client", "Product 1", 259));
            warehouse.MakeASale(new Sale("random client2", "Product 1", 1000));
            warehouse.MakeASale(new Sale("random client3", "Product 1", 10));
            warehouse.MakeASale(new Sale("random client4", "Product 3", 1000));


            Console.WriteLine("Sold : ");
            showSales();

            Console.WriteLine("Available AFTER SOLD: ");
            showAvailable();
        }