/// <summary> /// Method to populateCustomers list /// </summary> private void populateCustomers() { try { string provinceFilter = Console.ReadLine(); int selection; bool isNumber = int.TryParse(provinceFilter, out selection); customers = CustomertRepository.GetCustomers(selection); if (customers != null && customers.Count() > NULL_CUSTOMERS) { if (selection > 0 && selection <= provinces.Count) { ConsolePrinter.Print(customers, selection); } else { Console.WriteLine("Error please pick a number between 1 to {0}", provinces.Count); } } else { Console.WriteLine("No customers to print"); } } catch (SqlException ex) { Console.WriteLine("Data Access Error\n\n{0}", ex.Message); } catch (Exception ex) { Console.WriteLine("Processing Error\n\n{0}", ex.Message); } }
/// <summary> /// Method to populate province selection list /// </summary> private void populateSelectionList() { try { provinces = new CustomerRepository().GetProvince(); Console.WriteLine("Select province filter:"); if (provinces != null && provinces.Count() > NULL_PROVINCES) { int count = COUNT_START; foreach (Customer selectionList in provinces) { Console.WriteLine("{0,11} {1,2}", count++ + ":", selectionList.Province); } Console.WriteLine("{0,15}", count + ": ALL"); } } catch (SqlException ex) { Console.WriteLine("Data Access Error\n\n{0}", ex.Message); } catch (Exception ex) { Console.WriteLine("Processing Error\n\n{0}", ex.Message); } }
/// <summary> /// Method to populates the customers list /// </summary> private void populateCustomers() { try { filterByProvince = Console.ReadLine(); customers = CustomerRepository.GetCustomers(); if (customers != null && customers.Count() > NULL_CUSTOMERS) { if (filterByProvince.Equals("1")) { ConsolePrinter.Print(customers, "AB"); } else if (filterByProvince.Equals("2")) { ConsolePrinter.Print(customers, "BC"); } else if (filterByProvince.Equals("3")) { ConsolePrinter.Print(customers, "ON"); } else if (filterByProvince.Equals("4")) { ConsolePrinter.Print(customers, "SK"); } else if (filterByProvince.Equals("5")) { ConsolePrinter.Print(customers, "ALL"); } else { Console.WriteLine("Error please pick a number between 1 to {0}", provinces.Count + COUNT_START); } } else { Console.WriteLine("No customers to print"); } } catch (SqlException ex) { Console.WriteLine("Data Access Error\n\n{0}", ex.Message); } catch (Exception ex) { Console.WriteLine("Processing Error\n\n{0}", ex.Message); } }
/// <summary> /// Method to populateCustomers list through populateSelectionList method /// </summary> private void populateCustomers() { int selection = SELECTION_START; do { try { populateSelectionList(); string provinceFilter = Console.ReadLine(); bool isNumber = int.TryParse(provinceFilter, out selection); customers = CustomertRepository.GetCustomers(selection); if (selection > 0 && selection <= provinces.Count - ELEMENT) { if (customers != null && customers.Count() > NULL_CUSTOMERS) { ConsolePrinter.Print(customers, selection); } else { Console.WriteLine("No customers to print"); Environment.Exit(EXIT_CODE); } } else if (selection == provinces.Count) { Console.WriteLine("COMP2614Assign04 will now exit . . ."); Environment.Exit(EXIT_CODE); } } catch (SqlException ex) { Console.WriteLine("Data Access Error\n\n{0}", ex.Message); } catch (Exception) { Console.WriteLine("**********INVALID SELECTION**********\nPlease select a number between 1 to {0}\n\n", provinces.Count); } } while (selection >= SELECTION_START); }