private StringCollection readOrderFromCustomer(Customer customer) { string nextLine; StringCollection results = new StringCollection(); nextLine = String.Format("{0}", customer.FirstName + ' ' + customer.LastName); results.Add(nextLine); foreach (var o in customer.Orders) { if (o == null) break; nextLine=String.Format("{0} - {1:C} - {2, 0:N1} (square feet)", o.OrderedVehicle.Description, o.Price, o.OrderedVehicle.CargoCapacity()); results.Add(nextLine); nextLine = String.Format("Quantity: {0} - Model Name: {1} - Horse Power: {2}", o.Quantity, o.Model, o.OrderedVehicle.HorsePower); results.Add(nextLine); } return results; }
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 }
public void SaveToFile(Customer customer) { StringCollection linesCollection = readOrderFromCustomer(customer); string[] linesArray = new string[linesCollection.Count]; linesCollection.CopyTo(linesArray,0); StreamWriter sw = new StreamWriter(OrderHistoryFile, true); // create file if not existed, append foreach (var oneLine in linesArray) sw.WriteLine(oneLine); sw.Close(); }
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; } } }