예제 #1
0
        public static void Main(string[] args)
        {
            Customer[] customerArray = new Customer[30];
            int arrayIndex = 0;

            // Automobile customer
            Customer newCust = new Customer();
            newCust.FirstName = "Joe";
            newCust.LastName = "Smith";
            Order newOrder = new Order();
            newOrder.PlaceOrder(ModelName.BMW520);
            newOrder.ConfirmOrder(newCust, newOrder);
            customerArray[arrayIndex++] = newCust;

            newCust = new Customer();
            newCust.FirstName = "Tom";
            newCust.LastName = "Cruise";
            newOrder = new Order();
            newOrder.PlaceOrder(ModelName.BMW235, 28500, 1); // special offer
            newOrder.ConfirmOrder(newCust, newOrder);
            customerArray[arrayIndex++] = newCust;

            // Motocycle customer
            newCust = new Customer();
            newCust.FirstName = "Sally";
            newCust.LastName = "Jones";
            newOrder = new Order();
            newOrder.PlaceOrder(ModelName.HondaCruiser);
            newOrder.ConfirmOrder(newCust, newOrder);
            customerArray[arrayIndex++] = newCust;

            newCust = new Customer();
            newCust.FirstName = "Rick";
            newCust.LastName = "White";
            newOrder = new Order();
            newOrder.PlaceOrder(ModelName.HondaSport, 17500.0, 2); // special offer
            newOrder.ConfirmOrder(newCust, newOrder);
            customerArray[arrayIndex++] = newCust;

            // save and print the order history
            OrdersBackup orders = new OrdersBackup();
            foreach (var c in customerArray)
            {
                if ( c == null ) break;                     // question
                orders.SaveToFile(c);
            }

            Printer pr = new Printer();
            pr.PrintToConsole();

            orders.DeleteFile();  // for next test
        }
예제 #2
0
 public void ConfirmOrder(Customer customer, Order order)
 {
     for (int i = 0; i < customer.Orders.Length; i++)
     {
         if (customer.Orders[i] == null)
         {
             customer.Orders[i] = order;
             break;
         }
         else if (i == customer.Orders.Length - 1)
         {
             Console.WriteLine("Exceeds max. number of orders: 5");
             break;
         }
     }
 }