コード例 #1
0
 public TravelAgency(int id, Hotel [] h)
 {
     this.h = h;
     for (int i = 0; i < 3; i++)
     {
         currentPrice[i] = h[i].getRoomPrice();
     }
     cardNo         = BankService.getCreditCardNo();
     agencyId       = id;
     pendingReciept = 0;
 }
コード例 #2
0
        //processes the order by checking the available rooms and validating credit card with BankService
        void processOrder(Object x)
        {
            try
            {
                float price1 = roomPrice;
                Order o      = (Order)x;
                encryptionService.ServiceClient encrypt = new encryptionService.ServiceClient();
                int    orderID      = o.getOrderId();
                int    agencyID     = o.getAgencyId();
                int    hotelID      = o.getHotelId();
                int    roomsOrdered = o.getRooms();
                float  quotedPrice  = o.getQuotePrice();
                float  totalPrice   = quotedPrice * roomsOrdered;
                String cardNo       = o.getCardNo();

                String success = "Order " + orderID + " booked with " + hotelID + " for " + roomsOrdered + " rooms was processed successfully with a total of $" + totalPrice;
                //String failure = "Order " + orderID + " for Agency " + agencyID + " failed to proccess";


                lock (this)
                {
                    //Console.WriteLine("Thread{2} : Orderporcess ..{0}..,{1}", quotedPrice, roomPrice,Thread.CurrentThread.ManagedThreadId);
                    //Console.WriteLine("OrderProcess***********" + this);
                    if (BankService.validateCard(encrypt.Encrypt(cardNo)) == false)
                    {
                        ReceiptBuffer.setBuffer(agencyID, "The card number for Order " + orderID + " booked with Hotel " + hotelID + " is invalid");
                    }
                    else if (roomsOrdered > roomsAvailable)
                    {
                        ReceiptBuffer.setBuffer(agencyID, "The number of rooms ordered in Order " + orderID + " booked with " + hotelID + " is greater than the available rooms");
                    }
                    else if ((int)quotedPrice != (int)price1)
                    {
                        //Console.WriteLine("Thread:"+Thread.CurrentThread.ManagedThreadId+" Orderporcess ..The quoted price for Order " + orderID + " for Agency " + agencyID + " of $" + quotedPrice + " does not match the current price of $" + roomPrice);
                        ReceiptBuffer.setBuffer(agencyID, "The quoted price for Order " + orderID + " booked with Hotel " + hotelID + " of $" + quotedPrice + " does not match the current price of $" + price1);
                    }
                    else
                    {
                        roomsAvailable = roomsAvailable - roomsOrdered;
                        ReceiptBuffer.setBuffer(agencyID, success);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }