private void saveCustBtn_Click(object sender, EventArgs e) { connection.InitConnection(); List <TextBox> requiredInputs = new List <TextBox> { custNameTextBox, addressLine1, cityTextBox, postalCodeTextbox, phoneTextBox }; /* * Lamba used here to determine if any of the required textboxes are empty or contain only whitespace * If so the name of the textbox is pushed to a string to display in a message box along with some error text. * This is more efficient than using a for-loop to loop through the list of required textboxes and determine if they are empty: * to do so would require multiple lines of code, whereas the use of a lambda and some methods on the textboxes allows for the * same to be accomplished in three lines of code. */ var checkFields = requiredInputs.Where(input => String.IsNullOrWhiteSpace(input.Text)) .Select(input => input.AccessibleName) .ToArray(); var checkedFields = checkFields; if (checkedFields.Length > 0) { string InvalidFields = ""; foreach (var inputName in checkedFields) { InvalidFields += inputName + " cannot be blank.\n"; } MessageBox.Show(InvalidFields.ToString(), "Invalid data in form"); } else { string customerName = custNameTextBox.Text; string address1 = addressLine1.Text; string address2 = addressLine2.Text; string cityName = cityTextBox.Text; string postalCode = postalCodeTextbox.Text; string phone = phoneTextBox.Text; string country = countrySelectBox.Text; newCustomer.AddCustomer(customerName, address1, address2, cityName, postalCode, phone, country, User.displayName, connection.GetConnection()); this.Close(); } try { } catch (Exception) { throw; } connection.CloseConnection(); }
public void Show() { view.Clear(); if (orders.Count == 0) { view.ShowMessage("No currently active orders.\n\n"); } else { view.ShowView(); for (int o = 0; o < orders.Count; o++) { view.ShowOrder(o, orders[o].TableNumber(), orders[o].OpenedFor(), orders[o].FormattedItemsOnOrder(), orders[o].GetOrderCost()); } } while (true) { // main command input loop view.ShowMessage("Enter 'n' for a new order, 'e' to perform actions on an existing order, or 'p' to mark an order as paid.\n.Enter 'm' to go back to the main menu."); string input = Console.ReadLine(); if (input == "e" && orders.Count <= 0) { view.ShowError("There are no active orders to edit."); } else if (input == "p" && orders.Count <= 0) { view.ShowError("There are no active orders to mark as paid."); } else if (input == "e") { // EDIT ORDER int numb; while (true) { numb = -1; view.ShowMessage("enter the number of the order to edit"); input = Console.ReadLine(); if (!int.TryParse(input, out (numb))) { view.ShowError("Please enter only numbers."); } if (numb >= orders.Count || numb < 0) { view.ShowError("Please enter a valid number in range"); } else { view.ShowMessage("TODO"); EditOrder(orders[numb]); } } } else if (input == "p") { // PAY FOR ORDER int numb = -1; while (true) { view.ShowMessage("enter the number of the order to mark as paid."); input = Console.ReadLine(); int.TryParse(input, out (numb)); if (numb >= orders.Count || numb < 0) { view.ShowError("Please enter a valid number in range"); } else { view.ShowMessage("Are you sure you wish to mark order " + numb.ToString() + "as paid, for a cost of $" + orders[numb].GetOrderCost().ToString() + "? (y/n)"); input = Console.ReadLine(); if (input == "y") { view.ShowMessage("Marking order as paid, and saving to DB..."); DBManager.SaveOrder(orders[numb]); // order should be successfully written to DB, so we can delete the order now orders.Remove(orders[numb]); view.ShowMessage("Done! Press enter to go back to the main menu."); Console.ReadLine(); MenuHolder.GetMenuController().Show(); } else { Show(); } } } } else if (input == "n") { // NEW ORDER view.ShowMessage("Input 'd' for dine-in, 't' for takeaway"); input = Console.ReadLine(); while (true) { if (input == "d") { view.Clear(); view.ShowMessage("Please enter the customers phone number:"); string ph = Console.ReadLine(); while (true) { if (ph.Length < 8 || ph.Length > 10) { view.ShowError("Please enter a valid phone number"); ph = Console.ReadLine(); } else { break; } } // we have a phone number. look up in DB, create user if doesn't exist. int custId = DBManager.LookupCustomer(ph); if (custId == -1) { view.ShowMessage("New customer. Enter a name (optional)"); string name = ""; name = Console.ReadLine(); view.ShowMessage("Enter an address (optional)"); string address = ""; address = Console.ReadLine(); // get the next avail custID int newId = DBManager.GetNextCustomerId(); // create the customer, and write to DB Customer cust = new Customer(newId, name, ph, address, DateTime.Now); DBManager.AddCustomer(cust); // find the table view.ShowMessage("Enter the table number customer is seated at:"); int tableNumber = int.Parse(Console.ReadLine()); // look that table up from the tableManager Table orderTable = tableManager.GetTable(tableNumber); // now lets make the order NewDineInOrder(cust, orderTable); } else { view.ShowMessage("existing customer found."); // find the table view.ShowMessage("Enter the table number customer is seated at:"); int tableNumber = int.Parse(Console.ReadLine()); // look that table up from the tableManager Table orderTable = tableManager.GetTable(tableNumber); // now lets make the order NewDineInOrder(DBManager.GetCustomer(custId), orderTable); } } else if (input == "t") { // take-away view.Clear(); view.ShowMessage("Please enter the customers phone number:"); string ph = Console.ReadLine(); while (true) { if (ph.Length < 8 || ph.Length > 10) { view.ShowError("Please enter a valid phone number"); ph = Console.ReadLine(); } else { break; } } // we have a phone number. look up in DB, create user if doesn't exist. int custId = DBManager.LookupCustomer(ph); if (custId == -1) { view.ShowMessage("New customer. Enter a name (optional)"); string name = ""; name = Console.ReadLine(); view.ShowMessage("Enter an address (optional)"); string address = ""; address = Console.ReadLine(); // get the next avail custID int newId = DBManager.GetNextCustomerId(); // create the customer, and write to DB Customer cust = new Customer(newId, name, ph, address, DateTime.Now); DBManager.AddCustomer(cust); NewTakeAwayOrder(cust); } else { // now lets make the order NewTakeAwayOrder(DBManager.GetCustomer(custId)); } } else { view.ShowError("Please enter d or t"); } } } else if (input == "m") { MenuHolder.GetMenuController().Show(); } else { view.ShowError("Please only enter 'n', 'e', 'p', or 'm'."); } } }