private void addOrder() { int customerID = 0, productID = 0, quantity = 0; string ordreDato; Customer customer; Product product; newCustomerId: try { Console.WriteLine("What customer ID?"); customerID = int.Parse(Console.ReadLine()); customer = findCustomerWithIndexX(customerID); if (customer == null) { Console.WriteLine("There is no such customer"); goto newCustomerId; } } catch (Exception) { goto newCustomerId; } newProductId: try { Console.WriteLine("What product ID?"); productID = int.Parse(Console.ReadLine()); product = findProductId(productID); if (product == null) { Console.WriteLine("There is no such product"); goto newProductId; } } catch (Exception) { goto newProductId; } quantity: try { Console.WriteLine("How many?"); quantity = int.Parse(Console.ReadLine()); } catch (Exception) { goto quantity; } date: try { Console.WriteLine("When?"); ordreDato = Console.ReadLine(); } catch (Exception) { goto date; } Order order = new Order(ordreDato, quantity, customer, product); customer.AddOrderToList(order); }
private void load() { StreamReader sr = new StreamReader("../../Customers.txt"); StreamReader sr2 = new StreamReader("../../Products.txt"); StreamReader sr3 = new StreamReader("../../Orders.txt"); while (sr.EndOfStream == false) { Customer customer = new Customer(sr.ReadLine()); customerList.Add(customer); } while (sr2.EndOfStream == false) { Product product = new Product(sr2.ReadLine()); productList.Add(product); } while (sr3.EndOfStream == false) { string[] str = sr3.ReadLine().Split(';'); Customer customer = new Customer(int.Parse(str[2]), str[3], str[4], int.Parse(str[5])); Product product = new Product(int.Parse(str[6]), str[7], int.Parse(str[8])); Order order = new Order(str[0], int.Parse(str[1]), customer, product); Customer customer2 = findCustomerWithIndexX(customer.CustomerId1); customerList.Remove(customer2); customer2.AddOrderToList(order); customerList.Add(customer2); Console.WriteLine(); } Console.WriteLine("Press enter to continue"); Console.ReadLine(); sr.Close(); sr2.Close(); sr3.Close(); }
public void AddOrderToList(Order order) { ordreList.Add(order); }