Beispiel #1
0
        public void OrderProcessing()
        {
            Console.WriteLine("Dear Retailer Processing of your order has been started");

            //Get the order from cell buffer
            String OrderString = Program.buffercells.getOneCell();
            //Sending the string to decode
            Orders DecodedOrder = GetOrderObject(EncoderClass.decode(OrderString));

            Console.WriteLine("Hello Retailer {0}! Your order of {2} chickens has been placed, at the rate of ${1} per chicken.", DecodedOrder.getRetailerID(), DecodedOrder.getChickenPrice(), (int)(DecodedOrder.getAmount() / DecodedOrder.getChickenPrice()));
            if (DecodedOrder.getCreditCardNumber() > 5000 && DecodedOrder.getCreditCardNumber() < 7000)
            {
                float Tax             = 1.8F * DecodedOrder.getAmount();
                float ShippingCharges = 0.5F * DecodedOrder.getAmount();
                float TotalAmount     = DecodedOrder.getAmount() + (int)Tax + (int)ShippingCharges;
                //emit the order complete event
                if (OrderCompleted != null)
                {
                    // OrderComplete(int RetailerID, int NumberOfChickens, int ChickenPrice, int TotalAmount, int Tax, int ShippingCharges);
                    OrderCompleted(DecodedOrder.getRetailerID(), (int)(DecodedOrder.getAmount() / DecodedOrder.getChickenPrice()), DecodedOrder.getChickenPrice(), (int)TotalAmount, (int)Tax, (int)ShippingCharges);
                }
            }
            else
            {
                Console.WriteLine("Dear Retailer, Order Processing failed Due to Invalid card  Details");
            }
        }
Beispiel #2
0
        //function to place orders
        public void PlaceOrder(int NumberOfChickens, int RetailerID, int ChangedPrice)
        {
            lock (this)
            {
                Random rand = new Random();
                // Generate a credit card number.
                Int32 CreditCardNumber = rand.Next(5000, 7000);
                // Creating the pbject for order
                Orders ordersobject = new Orders();
                ordersobject.SetRetailerID(RetailerID);
                ordersobject.SetCreditCardNumber(CreditCardNumber);
                ordersobject.SetChickenPrice(ChangedPrice);
                ordersobject.SetTotalAmount(NumberOfChickens * ChangedPrice);

                // Sending the order object to Encoder
                String OrdersEncodedString = EncoderClass.Encode(ordersobject);
                //Write the order string into multibuffer cell
                Program.buffercells.setOneCell(OrdersEncodedString);
                Console.WriteLine("The order for RetailerID {0} has been placed.....", RetailerID);
                Console.WriteLine("Well will inform you once the order has been processed");
                //emit the place order event
                placeorder();
            }
        }