// Written By : Matt Augsburger // Method displays the Choose Customer Menu // Accepts Argument of an instance of CustomerManager and dbUtilities // Lists Customers in the database // Sets selected Customer to _currentCustomer public static void ChooseCustomerMenu(CustomerManager cm, dbUtilities db) { var custList = cm.GetCustomerList(); Dictionary <int, Customer> custDictionary = new Dictionary <int, Customer>(); Console.Clear(); int counter = 1; Console.WriteLine("Please select a customer:"); foreach (Customer c in custList) { custDictionary.Add(counter, c); Console.WriteLine($"{counter}. {c.firstName} {c.lastName}"); counter++; } Console.ForegroundColor = ConsoleColor.Red; Console.Write("> "); Console.ResetColor(); int choiceInt = 0; while (!int.TryParse(Console.ReadLine(), out choiceInt)) { Console.WriteLine("Please Enter a valid numerical value!"); } foreach (KeyValuePair <int, Customer> kvp in custDictionary) { if (choiceInt == kvp.Key) { Console.Clear(); Console.WriteLine($"You selected {kvp.Value.firstName} {kvp.Value.lastName} as the current customer"); CustomerManager.currentCustomer = kvp.Value; Console.WriteLine("Press any key to continue."); Console.ReadKey(); } else if (choiceInt > custDictionary.Count) { Console.Clear(); Console.WriteLine("That is not a valid option for a current customer, try again!"); Console.ReadLine(); ChooseCustomer.ChooseCustomerMenu(cm, db); return; } } }
// Constructor method to establish a connection with the database, database conenction is passed in as an argument.. public PaymentTypeManager(dbUtilities db) { _cm = new CustomerManager(db); _db = db; }
// Constructor method to establish a connection with the database, database conenction is passed in as an argument.. public CustomerManager(dbUtilities db) { _db = db; }
// Constructor method to establish a connection with the database, database conenction is passed in as an argument.. public ProductTypeManager(dbUtilities db) { _db = db; }
// Constructor method to establish a connection with the database, database conenction is passed in as an argument.. public OrderManager(dbUtilities db) { _db = db; }
static void Main(string[] args) { // Seed the database if none exists dbUtilities db = new dbUtilities("BANGAZONCLI_DB"); CustomerManager cm = new CustomerManager(db); PaymentTypeManager paytm = new PaymentTypeManager(db); db.CheckCustomer(); db.CheckPaymentType(); db.CheckOrder(); db.CheckProductType(); db.CheckProduct(); db.CheckProductOrder(); db.SeedTables(); MainMenu menu = new MainMenu(); ProductManager pm = new ProductManager(db); ProductTypeManager ptm = new ProductTypeManager(db); OrderManager om = new OrderManager(db); int choice; do { // Show the Main Menu choice = menu.ShowMainMenu(); switch (choice) { case 1: // Displays the Create Customer Menu CreateCustomer.CreateCustomerMenu(cm); break; case 2: ChooseCustomer.ChooseCustomerMenu(cm, db); break; case 3: if (CustomerManager.currentCustomer == null) { ChooseCustomer.ChooseCustomerMenu(cm, db); } CreatePayment.CreatePaymentMenu(paytm); break; case 4: if (CustomerManager.currentCustomer == null) { ChooseCustomer.ChooseCustomerMenu(cm, db); } AddProductToSell.DoAction(pm, ptm); break; case 5: if (CustomerManager.currentCustomer == null) { ChooseCustomer.ChooseCustomerMenu(cm, db); } AddProductOrder.AddProductToOrder(cm, pm, om); break; case 6: if (CustomerManager.currentCustomer == null) { ChooseCustomer.ChooseCustomerMenu(cm, db); } CompleteOrder.CompleteOrderMenu(om, pm, paytm); break; case 7: if (CustomerManager.currentCustomer == null) { ChooseCustomer.ChooseCustomerMenu(cm, db); } RemoveProductToSell.RemoveProductToSellMenu(pm); break; case 8: if (CustomerManager.currentCustomer == null) { ChooseCustomer.ChooseCustomerMenu(cm, db); } UpdateProduct.UpdateProductMenu(pm); break; case 9: if (CustomerManager.currentCustomer == null) { ChooseCustomer.ChooseCustomerMenu(cm, db); } ShowStale.DoAction(om); break; case 10: if (CustomerManager.currentCustomer == null) { ChooseCustomer.ChooseCustomerMenu(cm, db); } RevenueReport.ShowRevenueReport(om); break; case 11: ProductPopularityReport.ProductPopularityReportMenu(pm); break; } } while(choice != 12); }