コード例 #1
0
        /// <summary>
        /// Encoder Method for Coverting Order Object to String
        /// </summary>
        /// <param name="CurrentOrder">Instance of Order Object</param>
        /// <returns>String with order information separated by '-'</returns>
        public String Encoder(OrderClass CurrentOrder)
        {
            String OrderToString = null;

            if (CurrentOrder != null)
            {
                OrderToString = CurrentOrder.getSenderID() + "-" + CurrentOrder.getNoOfRooms() + "-" + CurrentOrder.getCardNo() + "-" + CurrentOrder.getReceiverID() + "-" + CurrentOrder.getNoOfDays();
            }
            return(OrderToString);
        }
コード例 #2
0
        /// <summary>
        /// Decodes the Order Information String and re-constructs it into a object of type Order Class
        /// </summary>
        /// <param name="CurrentOrder"></param>
        /// <returns></returns>
        private OrderClass Decoder(String CurrentOrder)
        {
            OrderClass OrderObject = new OrderClass();

            if (CurrentOrder != null)
            {
                String[] arr = CurrentOrder.Split('-');

                OrderObject.setSenderID(arr[0]);
                OrderObject.setNoOfRooms(Convert.ToInt32(arr[1]));
                OrderObject.setCardNo(arr[2]);
                OrderObject.setReceieverID(arr[3]);
                OrderObject.setNoOfDays(Convert.ToInt32(arr[4]));
            }
            return(OrderObject);
        }
コード例 #3
0
        public void RoomsPriceCut(Int32 price, String HotelName)
        {
            Console.WriteLine();
            Console.WriteLine("{0} rooms are on sale with a low price  ${1} ", HotelName, price);
            Console.WriteLine("No. of Rooms Available at {0} are: {1}", HotelName, HotelSupplier.getRoomsAvailable(HotelName));
            Console.WriteLine();

            if (HotelName.Equals("HotelSupplier1"))
            {
                OrderClass CurrentOrder1 = new OrderClass();
                CurrentOrder1.setSenderID("TravelAgency1");
                CurrentOrder1.setReceieverID(HotelName);
                CurrentOrder1.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder1.setNoOfDays(2);
                CurrentOrder1.setCardNo(CreditCards[0]);
                CardinalMain.TravelAgency1.setCurrentOrder(CurrentOrder1);

                OrderClass CurrentOrder2 = new OrderClass();
                CurrentOrder2.setSenderID("TravelAgency2");
                CurrentOrder2.setReceieverID(HotelName);
                CurrentOrder2.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder2.setNoOfDays(4);
                CurrentOrder2.setCardNo(CreditCards[1]);
                CardinalMain.TravelAgency2.setCurrentOrder(CurrentOrder2);


                OrderClass CurrentOrder3 = new OrderClass();
                CurrentOrder3.setSenderID("TravelAgency3");
                CurrentOrder3.setReceieverID(HotelName);
                CurrentOrder3.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder3.setNoOfDays(3);
                CurrentOrder3.setCardNo(CreditCards[2]);
                CardinalMain.TravelAgency3.setCurrentOrder(CurrentOrder3);


                OrderClass CurrentOrder4 = new OrderClass();
                CurrentOrder4.setSenderID("TravelAgency4");
                CurrentOrder4.setReceieverID(HotelName);
                CurrentOrder4.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder4.setNoOfDays(4);
                CurrentOrder4.setCardNo(CreditCards[3]);
                CardinalMain.TravelAgency4.setCurrentOrder(CurrentOrder4);

                OrderClass CurrentOrder5 = new OrderClass();
                CurrentOrder5.setSenderID("TravelAgency5");
                CurrentOrder5.setReceieverID(HotelName);
                CurrentOrder5.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder5.setNoOfDays(5);
                CurrentOrder5.setCardNo(CreditCards[4]);
                CardinalMain.TravelAgency5.setCurrentOrder(CurrentOrder5);
                i = 1;
            }
            else if (HotelName.Equals("HotelSupplier2"))
            {
                OrderClass CurrentOrder1 = new OrderClass();
                CurrentOrder1.setSenderID("TravelAgency1");
                CurrentOrder1.setReceieverID(HotelName);
                CurrentOrder1.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder1.setNoOfDays(4);
                CurrentOrder1.setCardNo(CreditCards[0]);
                CardinalMain.HTravelAgency1.setCurrentOrder(CurrentOrder1);


                OrderClass CurrentOrder2 = new OrderClass();
                CurrentOrder2.setSenderID("TravelAgency2");
                CurrentOrder2.setReceieverID(HotelName);
                CurrentOrder2.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder2.setNoOfDays(2);
                CurrentOrder2.setCardNo(CreditCards[1]);
                CardinalMain.HTravelAgency2.setCurrentOrder(CurrentOrder2);

                OrderClass CurrentOrder3 = new OrderClass();
                CurrentOrder3.setSenderID("TravelAgency3");
                CurrentOrder3.setReceieverID(HotelName);
                CurrentOrder3.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder3.setNoOfDays(4);
                CurrentOrder3.setCardNo(CreditCards[2]);
                CardinalMain.HTravelAgency3.setCurrentOrder(CurrentOrder3);

                OrderClass CurrentOrder4 = new OrderClass();
                CurrentOrder4.setSenderID("TravelAgency4");
                CurrentOrder4.setReceieverID(HotelName);
                CurrentOrder4.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder4.setNoOfDays(3);
                CurrentOrder4.setCardNo(CreditCards[3]);
                CardinalMain.HTravelAgency4.setCurrentOrder(CurrentOrder4);

                OrderClass CurrentOrder5 = new OrderClass();
                CurrentOrder5.setSenderID("TravelAgency5");
                CurrentOrder5.setReceieverID(HotelName);
                CurrentOrder5.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder5.setNoOfDays(3);
                CurrentOrder5.setCardNo(CreditCards[4]);
                CardinalMain.HTravelAgency5.setCurrentOrder(CurrentOrder5);
                i = 2;
            }
            else if (HotelName.Equals("HotelSupplier3"))
            {
                OrderClass CurrentOrder1 = new OrderClass();
                CurrentOrder1.setSenderID("TravelAgency1");
                CurrentOrder1.setReceieverID(HotelName);
                CurrentOrder1.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder1.setNoOfDays(5);
                CurrentOrder1.setCardNo(CreditCards[0]);
                CardinalMain.STravelAgency1.setCurrentOrder(CurrentOrder1);

                OrderClass CurrentOrder2 = new OrderClass();
                CurrentOrder2.setSenderID("TravelAgency2");
                CurrentOrder2.setReceieverID(HotelName);
                CurrentOrder2.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder2.setNoOfDays(2);
                CurrentOrder2.setCardNo(CreditCards[1]);
                CardinalMain.STravelAgency2.setCurrentOrder(CurrentOrder2);

                OrderClass CurrentOrder3 = new OrderClass();
                CurrentOrder3.setSenderID("TravelAgency3");
                CurrentOrder3.setReceieverID(HotelName);
                CurrentOrder3.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder3.setNoOfDays(6);
                CurrentOrder3.setCardNo(CreditCards[2]);
                CardinalMain.STravelAgency3.setCurrentOrder(CurrentOrder3);

                OrderClass CurrentOrder4 = new OrderClass();
                CurrentOrder4.setSenderID("TravelAgency4");
                CurrentOrder4.setReceieverID(HotelName);
                CurrentOrder4.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder4.setNoOfDays(3);
                CurrentOrder4.setCardNo(CreditCards[3]);
                CardinalMain.STravelAgency4.setCurrentOrder(CurrentOrder4);

                OrderClass CurrentOrder5 = new OrderClass();
                CurrentOrder5.setSenderID("TravelAgency5");
                CurrentOrder5.setReceieverID(HotelName);
                CurrentOrder5.setNoOfRooms(calculateNoOfRooms(price));//Calulates Rooms Required
                CurrentOrder5.setNoOfDays(5);
                CurrentOrder5.setCardNo(CreditCards[4]);
                CardinalMain.STravelAgency5.setCurrentOrder(CurrentOrder5);
                i = 3;
            }
            {
                //All Travel Agencies Start Placing Orders to the Hotel Supplier which generated an Event
                CardinalMain.startOrders(i);
            }
        }
コード例 #4
0
 public void setCurrentOrder(OrderClass CurrentOrder)
 {
     this.CurrentOrder = CurrentOrder;
 }
コード例 #5
0
        /// <summary>
        /// Once the Hotel Supplier Receives the Order process order is called for processing the order
        /// and sends back the result to the travel agency
        /// </summary>
        public void processOrder()
        {
            while (OrderProcessingQueue.Count != 0)
            {
                String result = "";
                try
                {
                    OrderClass currentOrder = OrderProcessingQueue.Dequeue();

                    if (currentOrder.getReceiverID().Equals("HotelSupplier1"))
                    {
                        int roomsRequired = currentOrder.getNoOfRooms();
                        if (roomsRequired <= H1RoomCount)
                        {
                            //Total Cost Inclusive of 15 Percent Tax + 2 Percent Location Charges
                            double amount = (roomsRequired * H1RoomPrice) + ((roomsRequired * H1RoomPrice) * 0.15) + ((roomsRequired * H1RoomPrice) * 0.02);
                            if (BankService.verifyaccount(currentOrder.getSenderID(), currentOrder.getCardNo()))
                            {
                                H1RoomCount = H1RoomCount - roomsRequired;
                                result      = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + ":|";
                                result      = result + "Required No. of rooms are booked by " + currentOrder.getSenderID() + " at " + currentOrder.getReceiverID() + ": " + currentOrder.getNoOfRooms() + " Rooms |";
                                result      = result + "Total Cost of Booking (including taxes+location charges): $" + amount + " |";
                                result      = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                            else
                            {
                                result = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + ":|";
                                result = "Invalid Credit Card Number for: " + currentOrder.getSenderID() + "|";
                                result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                        }
                        else
                        {
                            result = "Sorry HotelSupplier1 Rooms are full.. Not Enough rooms Available!!! |" + "Order from " + currentOrder.getSenderID() + " could not be processed. |";
                            result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                        }
                    }

                    else if (currentOrder.getReceiverID().Equals("HotelSupplier2"))
                    {
                        int roomsRequired = currentOrder.getNoOfRooms();
                        if (roomsRequired <= H2RoomCount)
                        {
                            //Total Cost Inclusive of 17 Percent Tax + 3 Percent Location Charges
                            double amount = (roomsRequired * H2RoomPrice) + ((roomsRequired * H2RoomPrice) * 0.17) + ((roomsRequired * H2RoomPrice) * 0.03);
                            if (BankService.verifyaccount(currentOrder.getSenderID(), currentOrder.getCardNo()))
                            {
                                H2RoomCount = H2RoomCount - roomsRequired;
                                result      = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + " :|";
                                result      = result + "Required No. of rooms are booked by " + currentOrder.getSenderID() + " at " + currentOrder.getReceiverID() + ": " + currentOrder.getNoOfRooms() + " Rooms |";
                                result      = result + "Total Cost of Booking (including taxes+location charges): $" + amount + " |";
                                result      = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                            else
                            {
                                result = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + ":|";
                                result = "Invalid Credit Card Number for: " + currentOrder.getSenderID() + "|";
                                result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                        }
                        else
                        {
                            result = "Sorry HotelSupplier2 Rooms are full.. Not Enough rooms Available!!! |" + "Order from " + currentOrder.getSenderID() + " could not be processed. |";
                            result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                        }
                    }

                    else if (currentOrder.getReceiverID().Equals("HotelSupplier3"))
                    {
                        int roomsRequired = currentOrder.getNoOfRooms();
                        if (roomsRequired <= H3RoomCount)
                        {
                            //Total Cost Inclusive of 14 Percent Tax + 4 percent Location Charges
                            double amount = (roomsRequired * H3RoomPrice) + ((roomsRequired * H3RoomPrice) * 0.14) + ((roomsRequired * H3RoomPrice) * 0.04);
                            if (BankService.verifyaccount(currentOrder.getSenderID(), currentOrder.getCardNo()))
                            {
                                H3RoomCount = H3RoomCount - roomsRequired;
                                result      = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + ":|";
                                result      = result + "Required No. of rooms are booked by " + currentOrder.getSenderID() + " at " + currentOrder.getReceiverID() + ": " + currentOrder.getNoOfRooms() + " Rooms |";
                                result      = result + "Total Cost of Booking (including taxes+location charges): $" + amount + " |";
                                result      = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                            else
                            {
                                result = "Order Status from " + currentOrder.getReceiverID() + " sent back to " + currentOrder.getSenderID() + ":|";
                                result = "Invalid Credit Card Number for: " + currentOrder.getSenderID() + "|";
                                result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                            }
                        }
                        else
                        {
                            result = "Sorry HotelSupplier3 Rooms are full.. Not Enough rooms Available!!! |" + "Order from " + currentOrder.getSenderID() + " could not be processed. |";
                            result = result + "Processed At: " + DateTime.Now.ToString() + " |";
                        }
                    }
                    //Sends back the order to Travel Agency using a separate buffer cell
                    if (Monitor.TryEnter(CardinalMain.n4))
                    {
                        try
                        {
                            CardinalMain.n4.setOneCell(result);//Order Status Sent to Travel Agency
                        }
                        finally
                        {
                            result = "";
                            Monitor.Exit(CardinalMain.n4);
                        }
                    }
                }
                finally
                {
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// This method receives the order placed by the travel agencies. The orders are read from the multi-cell
        /// buffer
        /// </summary>
        public void receiveOrder()
        {
            Boolean[] arr = new Boolean[5];
            int       i   = 15;

            while (i != 0)
            {
                if (Thread.CurrentThread.Name.Equals("H1"))
                {
                    if (Monitor.TryEnter(CardinalMain.n1))
                    {
                        try
                        {
                            OrderClass OrderObject = Decoder(CardinalMain.n1.getOneCell());
                            Console.WriteLine("Order Object Received by " + OrderObject.getReceiverID() + " from: " + OrderObject.getSenderID());
                            OrderProcessingQueue.Enqueue(OrderObject);
                            Console.WriteLine();
                        }
                        finally
                        {
                            i--;
                            Monitor.Exit(CardinalMain.n1);
                        }
                    }
                }
                else if (Thread.CurrentThread.Name.Equals("H2"))
                {
                    if (Monitor.TryEnter(CardinalMain.n2))
                    {
                        try
                        {
                            OrderClass OrderObject = Decoder(CardinalMain.n2.getOneCell());
                            Console.WriteLine("Order Object Received by " + OrderObject.getReceiverID() + " from: " + OrderObject.getSenderID());
                            OrderProcessingQueue.Enqueue(OrderObject);
                            Console.WriteLine();
                        }
                        finally
                        {
                            i--;
                            Monitor.Exit(CardinalMain.n2);
                        }
                    }
                }
                else if (Thread.CurrentThread.Name.Equals("H3"))
                {
                    if (Monitor.TryEnter(CardinalMain.n3))
                    {
                        try
                        {
                            OrderClass OrderObject = Decoder(CardinalMain.n3.getOneCell());
                            Console.WriteLine("Order Object Received by " + OrderObject.getReceiverID() + " from: " + OrderObject.getSenderID());
                            OrderProcessingQueue.Enqueue(OrderObject);
                            Console.WriteLine();
                        }
                        finally
                        {
                            i--;
                            Monitor.Exit(CardinalMain.n3);
                        }
                    }
                }

                //Order Processing Block
                {
                    HotelSupplier OrderProcessingObject = new HotelSupplier();
                    TravelAgency  OrderStatusObject     = new TravelAgency();
                    Thread        OrderProcessingThread = new Thread(new ThreadStart(OrderProcessingObject.processOrder));
                    Thread        OrderStatusThread     = new Thread(new ThreadStart(OrderStatusObject.receiveOrderConfirmation));

                    OrderProcessingThread.Start();
                    OrderStatusThread.Start();
                    OrderStatusThread.Join();
                    OrderProcessingThread.Join();
                }
            }
        }