Ejemplo n.º 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);
        }
Ejemplo n.º 2
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
                {
                }
            }
        }