//Order History User Interface //Displays total order history of user //total, date/time, amount of pizzas, type of pizza, size, crust, and location for each order public static void historyUI() { while (true) { string address; Console.Clear(); Console.WriteLine("Order History"); Console.WriteLine(); Console.WriteLine(" Total Date/Time Amount of Pizzas Type of Pizza Size Crust Location"); Console.WriteLine("-----------------------------------------------------------------------------------------------------------------"); Entity db = AccessDb.acc(); //Singleton used to access data var records = Repository.GetRecordsReverse(db); foreach (var rec in records) { if (rec.UserId == PCustomer.Id) // runs through record and check if user id matches foreign key in records, then displays history { TypeChange type = new TypeChange(); address = type.returnLocation(rec.LocatId); decimal?value = rec.Total; decimal total = value ?? 0; total = Math.Round(total, 2); Console.WriteLine(String.Format("{0,5:C} {1,22} {2,7} {3,-12} {4,-6} {5,-11} {6,0}" , total, rec.DateT, rec.AmountP, rec.PizzaType, rec.Size, rec.Crust, address)); } } Console.WriteLine(); Console.WriteLine("Press any key to return to other options"); Console.ReadKey(); optionsUI(); break; } }
//Single Store Order History User Interface //Displays userId, total cost, data/time, amount of pizzas, type of pizza, size, and crust for each order public static void singlestoreUI() { Console.WriteLine($"Store ID: {Location.Id}"); Console.WriteLine($"Store Address: {Location.Locat}"); Console.WriteLine(); Console.WriteLine("UserId Total Date/Time Amount of Pizzas Type of Pizza Size Crust"); Console.WriteLine("-----------------------------------------------------------------------------------------"); Entity db = AccessDb.acc(); //Singleton used to access data var records = Repository.GetRecordsReverse(db); decimal monthTotal = 0; foreach (var rec in records) { if (rec.LocatId == Location.Id) // runs through records table and displays only order information from that location { decimal?value = rec.Total; decimal total = value ?? 0; total = Math.Round(total, 2); Console.WriteLine(String.Format("{0,4} {1,9:C} {2,22} {3,7} {4,-12} {5,-7} {6,-10}" , rec.UserId, total, rec.DateT, rec.AmountP, rec.PizzaType, rec.Size, rec.Crust)); monthTotal = total + monthTotal; } } Console.WriteLine(); Console.WriteLine($"Total Month Sales: ${monthTotal}"); Console.WriteLine(); Console.WriteLine("Press any key to return to store locations"); Console.ReadKey(); storelocationUI(); // returns to locations options }
static public bool checkDT() //checks if last order meets time and date conditions for current order { DateTime now = DateTime.Now; Entity db = AccessDb.acc(); var records = Repository.GetRecordsReverse(db); foreach (var rec in records) // { if (rec.UserId == PCustomer.Id && rec.LocatId == Location.Id) { TimeSpan interval = now - rec.DateT; // Timespan struct to calculate the interval between the two dates. if (interval.TotalDays < 1) // If totaldays less than 1, does not allow purchace { Console.WriteLine("Must wait 24 hours before next purchase at this location"); Console.WriteLine($"Last order here on {rec.DateT}"); return(false); } } else if (rec.UserId == PCustomer.Id) { TimeSpan interval = now - rec.DateT; // Timespan struct to calculate the interval between the two dates. if (interval.TotalHours < 2) // If totalhours less than 2, does not allow purchace { Console.WriteLine("Must wait 2 hours before next purchase in general"); Console.WriteLine($"Last order on {rec.DateT}"); return(false); } } } return(true); }
public double calculateCostCustom(int amount, string pizzaSize, string toppings, int pizzaId) // amount of pizzas, size of crust, and size of pizza(s) { int toppn = 0; // check how many toppings are in the string foreach (char c in toppings) { if (c == ',') { toppn++; } } int totalToppings = toppn * 1; Entity db = AccessDb.acc(); var pizzas = Repository.GetPizza(db); foreach (var pie in pizzas) // finds the pizza of choice and checks the menu in the database for standard price { if (pie.Id == pizzaId) { switch (pizzaSize) { case "small": decimal?value = pie.Small; decimal value2 = value ?? 0; pizzaPrice = Convert.ToDouble(value2); break; case "medium": decimal?value3 = pie.Med; decimal value4 = value3 ?? 0; pizzaPrice = Convert.ToDouble(value4); break; case "large": decimal?value5 = pie.Large; decimal value6 = value5 ?? 0; pizzaPrice = Convert.ToDouble(value6); break; default: Console.WriteLine("Shouldn't Happen"); break; } } } // Calculating total with tax total = (total + (pizzaPrice * amount)) + totalToppings; taxTotal = (total * tax); total = taxTotal + total; total = Math.Round((Double)total, 2); return(total); }
public string returnLocation(int?locationID) // converts location ID to location Address for user history view { string locAddress = "Location Unknown"; Entity db = AccessDb.acc(); var locations = Repository.GetLocations(db); foreach (var loc in locations) { if (loc.Id == locationID) { locAddress = loc.Locat; } } return(locAddress); }
//Employee Login User Interface //prompts employee user to login //checks if username and password entered is present in the database public static void empLoginUI() { while (true) { Console.Clear(); string Id; string passWord; Console.WriteLine("Store Login"); Console.Write("Username: "******"Password: "******"Invalid Username or Password"); Console.WriteLine("Press 'b' to return to last page or any other key to try again"); ConsoleKeyInfo key; key = Console.ReadKey(); Console.WriteLine(); switch (key.Key) { case ConsoleKey.B: MainUI.startupUI(); break; default: empLoginUI(); break; } } }
//Login User Interface //prompts user to login //checks if username and password entered is present in the database public static void loginUI() { while (true) { Console.Clear(); string userName; string passWord; Console.WriteLine("Welcome to Marquez's Pizzaria"); Console.Write("Username: "******"Password: "******"Invalid Username or Password"); Console.WriteLine("Press 'b' to return to last page or any other key to try again"); ConsoleKeyInfo key; key = Console.ReadKey(); Console.WriteLine(); switch (key.Key) { case ConsoleKey.B: MainUI.startupUI(); break; default: loginUI(); break; } } }
public string returnPizza(string pizType) //converts user input to pizzaType { int pizza = Convert.ToInt32(pizType); Entity db = AccessDb.acc(); var pizzas = Repository.GetPizza(db); foreach (var pie in pizzas) { if (pie.Id == pizza) { pizType = pie.PizzaType; } } return(pizType); }
//Total Stores Order History User Interface //Displays storeId, userId, total cost, data/time, amount of pizzas, type of pizza, size, and crust for each order public static void totstoreUI() { Console.WriteLine(); Console.WriteLine("StoreId UserId Total Date/Time Amount of Pizzas Type of Pizza Size Crust"); Console.WriteLine("------------------------------------------------------------------------------------------------"); Entity db = AccessDb.acc(); //Singleton used to access data var records = Repository.GetRecordsReverse(db); foreach (var rec in records) // runs throgh records and prints total order history { decimal?value = rec.Total; decimal total = value ?? 0; total = Math.Round(total, 2); Console.WriteLine(String.Format("{0,4} {1,6} {2,9:C} {3,22} {4,7} {5,-12} {6,-7} {7,-10}" , rec.LocatId, rec.UserId, total, rec.DateT, rec.AmountP, rec.PizzaType, rec.Size, rec.Crust)); } Console.WriteLine(); Console.WriteLine("Press any key to return to store locations"); Console.ReadKey(); storelocationUI(); }
//Location User Interface //promps the user to choose a location for order //location information is stored for future references public static void locationUI() { while (true) { Console.Clear(); string location; int locat; int counter = 0; Console.WriteLine("Hello {0}", PCustomer.firstname); Console.WriteLine(); Entity db = AccessDb.acc(); //Singleton used to access data var locations = Repository.GetLocations(db); //gets all locations from the location table foreach (var loc in locations) { Console.WriteLine($"{loc.Id}. {loc.Locat}"); counter++; // counter used to see how many locations are in the system, can add more locations if needed } Console.WriteLine(); Console.Write("Please Select a Location: "); location = Console.ReadLine(); int value; if (int.TryParse(location, out value)) // location id and address is stored for record purposes { locat = Convert.ToInt32(location); if (locat <= counter && locat > 0) { foreach (var loc in locations) { if (loc.Id == locat) { Location.Id = loc.Id; // stores location information Location.Locat = loc.Locat; } } optionsUI(); break; } else { Console.WriteLine("Invalid Input"); Console.WriteLine("Press 'b' to return to Main Menu or any other key to try again"); ConsoleKeyInfo key; key = Console.ReadKey(); Console.WriteLine(); switch (key.Key) { case ConsoleKey.B: MainUI.startupUI(); //return to Main Menu break; default: break; } } } else { Console.WriteLine("Invalid Input"); Console.WriteLine("Press 'b' to return to Main Menu or any other key to try again"); ConsoleKeyInfo key; key = Console.ReadKey(); Console.WriteLine(); switch (key.Key) { case ConsoleKey.B: MainUI.startupUI(); break; default: break; } } } }
//Order User Interface //Allows user to order both preset and custom pizzas //Allows multiple orders before comfirmation //Allows resetting of order for convenience public static void orderUI() { bool flag = false; while (true) { Console.Clear(); string pizza; int pizzaAmount; Entity db = AccessDb.acc(); var pizzas = Repository.GetPizza(db); Console.WriteLine("Large Medium Small Pizzas"); // prints all pizzas and menus prices on console for user Console.WriteLine("----------------------------------"); foreach (var pie in pizzas) { double small = Math.Round((Double)pie.Small, 2); double medium = Math.Round((Double)pie.Med, 2); double large = Math.Round((Double)pie.Large, 2); if (pie.PizzaType == "Custom") { Console.WriteLine($"${large} ${medium} ${small} {pie.PizzaType}"); } else { Console.WriteLine($"${large} ${medium} ${small} {pie.PizzaType}"); } } Console.WriteLine(); Console.WriteLine("1. Hawaiian o. Options"); Console.WriteLine("2. Meat Lovers c. Clear Order"); Console.WriteLine("3. Supreme"); Console.WriteLine("4. Custom"); Console.WriteLine(); Console.WriteLine(); if (flag == true) { double preTotal = 0; Console.WriteLine("Current Order:"); foreach (var piz in PizzaLt.PizzaList) //prints current order of user { Console.WriteLine($" {piz.Amount} {piz.PizzaType} {piz.Size} {piz.Crust} crust pizza(s) {piz.Topping}"); preTotal = piz.Total + preTotal; } Console.WriteLine($"Current Total ${preTotal}"); // prints current total } Console.WriteLine(); Console.Write("Please select a type of Pizza, Clear Order, or Return to User Option: "); pizza = Console.ReadLine(); Console.WriteLine(); string toppings = ""; if (pizza == "4") { toppings = customUI(); // returs the toppings chosen from user } if (pizza == "1" || pizza == "2" || pizza == "3" || pizza == "4") { Console.Write("How many pizzas would you like? "); string pizzaAm; pizzaAm = Console.ReadLine(); int value; if (int.TryParse(pizzaAm, out value)) // checks if user type was an integer { pizzaAmount = Convert.ToInt32(pizzaAm); if (pizzaAmount > 99) // if user asks for 100 pizzas or more, the program will not allow it { Console.WriteLine("Cannot purchase more than 99 pizzas"); Console.WriteLine("Please Press any key to continue your order"); Console.ReadKey(); orderUI(); } string crust; string size; Console.WriteLine(); Console.WriteLine("Select Crust and Size"); Console.Write("t for thin, h for handtossed, p for pan: "); crust = (Console.ReadLine()); if (crust == "t" || crust == "h" || crust == "p") { Console.Write("s for small, m for medium, and l for large: "); size = Console.ReadLine(); if (size == "s" || size == "m" || size == "l") { int pizzaId = Convert.ToInt32(pizza); // converting user input to pizza Id TypeChange tc = new TypeChange(); // converting user input to string equivalents pizza = tc.returnPizza(pizza); crust = tc.returnCrust(crust); size = tc.returnSize(size); double total; Console.WriteLine(); if (pizzaId == 4) { Calculate cal = new Calculate(); total = cal.calculateCostCustom(pizzaAmount, size, toppings, pizzaId); //send to a pizza cost method custom } else { Calculate cal = new Calculate(); total = cal.calculateCostPreset(pizzaAmount, size, pizzaId); //send to a pizza cost method preset } double currentTotal = total; if (total > 250) // total cost cannot be more than 250 { Console.WriteLine("Cannot spend more than 250!"); Console.WriteLine("Press any key to restart your order"); Console.ReadKey(); PizzaLt.PizzaList.Clear(); orderUI(); } if (flag == true) { foreach (var piz in PizzaLt.PizzaList) // runs through the list of objects to display order on console { Console.WriteLine($"{piz.Amount} {piz.PizzaType} {piz.Size} {piz.Crust} crust pizza(s) {piz.Topping}"); total = total + piz.Total; if (total > 250) { Console.WriteLine("Cannot spend more than 250!"); Console.WriteLine("Press any key to restart your order"); Console.ReadKey(); PizzaLt.PizzaList.Clear(); orderUI(); } } } total = Math.Round(total, 2); Console.WriteLine($"{pizzaAmount} {pizza} {size} {crust} crust pizza(s) {toppings}"); // displays current order Console.WriteLine($"Your total is ${total}"); string confirm; Console.WriteLine(); Console.WriteLine("y. Confirm and purchase order"); Console.WriteLine("a. Add to your current order"); Console.WriteLine(); Console.Write("Or enter anything else to clear and restart order: "); confirm = Console.ReadLine(); if (confirm == "y") // confirming order begins the process to store user order { PizzaLt.PizzaList.Add(new Pizzas(PCustomer.Id, currentTotal, pizzaAmount, pizza, size, crust, toppings)); decimal tot; foreach (var piz in PizzaLt.PizzaList) // goes through the list of objects and stores them to the records table { tot = Convert.ToDecimal(piz.Total); tot = Math.Round(tot, 2); DateTime dateTime = DateTime.Now; Records records = new Records() { UserId = piz.UserID, Total = tot, DateT = dateTime, AmountP = piz.Amount, PizzaType = piz.PizzaType, Size = piz.Size, Crust = piz.Crust, LocatId = Location.Id }; Repository.AddRecords(db, records); } Console.WriteLine("Thank You for your purchase"); Thread.Sleep(2000); optionsUI(); } else if (confirm == "a") // adding will allow user to add another pizza to their order { flag = true; // will show total order for user by running through the List of orders PizzaLt.PizzaList.Add(new Pizzas(PCustomer.Id, currentTotal, pizzaAmount, pizza, size, crust, toppings)); // stores the current order to a generic list Console.WriteLine("Please Press any key to continue your order"); Console.ReadKey(); } else { PizzaLt.PizzaList.Clear(); Console.WriteLine("Please Press any key to restart your order"); Console.ReadKey(); } } else { Console.WriteLine("Invalid Choice"); Console.WriteLine("Please Press any key to continue your order"); Console.ReadKey(); } } else { Console.WriteLine("Invalid Choice"); Console.WriteLine("Please Press any key to continue your order"); Console.ReadKey(); } } else { Console.WriteLine("Invalid Choice"); Console.WriteLine("Please Press any key to continue your order"); Console.ReadKey(); } } else if (pizza == "o") // will clear the list of objects and return to user interface { PizzaLt.PizzaList.Clear(); optionsUI(); } else if (pizza == "c") // will clear the list of objects to reset order { PizzaLt.PizzaList.Clear(); } else { Console.WriteLine("Invalid Choice"); Console.WriteLine("Please Press any key to continue your order"); Console.ReadKey(); } } }
//Store Location User Interface //Allows employee to view order histoy of every location //Allows employee to view total order history of all locations public static void storelocationUI() { while (true) { Console.Clear(); string location; int locat; int counter = 0; Console.WriteLine("Hello Employee {0}", Pemployee.firstname); Console.WriteLine(); Entity db = AccessDb.acc(); //Singleton used to access data var locations = Repository.GetLocations(db); foreach (var loc in locations) { Console.WriteLine($"{loc.Id}. {loc.Locat}"); counter++; // counter used to see how many locations are in the system } Console.WriteLine(); Console.WriteLine("a. All Locations"); Console.WriteLine("s. Sign Out"); Console.WriteLine(); Console.Write("Please Select a Location to view order history: "); location = Console.ReadLine(); Console.WriteLine(); int value; if (int.TryParse(location, out value)) // location id and address is stored for record purposes { locat = Convert.ToInt32(location); if (locat <= counter && locat > 0) { foreach (var loc in locations) { if (loc.Id == locat) // stores location for future reference { Location.Id = loc.Id; Location.Locat = loc.Locat; } } singlestoreUI(); // displays location store order history break; } else { Console.WriteLine("Invalid Input"); Console.WriteLine("Press 'b' to return to Main Menu or any other key to try again"); ConsoleKeyInfo key; key = Console.ReadKey(); Console.WriteLine(); switch (key.Key) { case ConsoleKey.B: MainUI.startupUI(); break; default: break; } } } else if (location == "a") // displays total order history { totstoreUI(); } else if (location == "s") { MainUI.startupUI(); } else { Console.WriteLine("Invalid Input"); Console.WriteLine("Press 'b' to return to Main Menu or any other key to try again"); ConsoleKeyInfo key; key = Console.ReadKey(); Console.WriteLine(); switch (key.Key) { case ConsoleKey.B: MainUI.startupUI(); break; default: break; } } } }
// Register User Interface // Promts user to enter firstname, lastname, username, and password // Prevents user from creating an account with repeated username public static void registerUI() { while (true) { Console.Clear(); string newId; string newPassword; string nameFirst; string nameLast; Console.WriteLine("Create an Account"); Console.WriteLine(); Console.Write("First Name: "); nameFirst = Console.ReadLine(); Console.Write("Last Name: "); nameLast = Console.ReadLine(); Console.Write("Username: "******"Password: "******"No null values allowed when creating an account"); Console.WriteLine("Press 'b' to return to last page or any other key to try again"); ConsoleKeyInfo key1; key1 = Console.ReadKey(); Console.WriteLine(); switch (key1.Key) { case ConsoleKey.B: MainUI.startupUI(); break; default: registerUI(); break; } } Entity db = AccessDb.acc(); //Singleton used to access data var customers = Repository.GetCustomer(db); foreach (var cus in customers) { if (cus.Uname == newId) // checks if entered username is already stored in database { Console.WriteLine($"Invalid username. There is already an account with the username '{newId}'"); Console.WriteLine("Press 'b' to return to last page or any other key to try again"); ConsoleKeyInfo key; key = Console.ReadKey(); Console.WriteLine(); switch (key.Key) { case ConsoleKey.B: MainUI.startupUI(); break; default: registerUI(); Thread.Sleep(2000); break; } } } Console.Write("Are you sure you want to create an account with this information? y/n: "); string confirm; confirm = Console.ReadLine(); if (confirm == "y") { Customer customer = new Customer() { Fname = nameFirst, Lname = nameLast, Uname = newId, Pword = newPassword }; Repository.AddCustomer(db, customer); // adds customer to customer table Console.WriteLine("Success! Your account has been created"); Thread.Sleep(2000); MainUI.startupUI(); } else if (confirm == "n") { Console.WriteLine("Press 'b' to return to last page or any other key to try again"); ConsoleKeyInfo key1; key1 = Console.ReadKey(); Console.WriteLine(); switch (key1.Key) { case ConsoleKey.B: MainUI.startupUI(); break; default: registerUI(); break; } } else { Console.WriteLine("Incorrect Input"); Console.WriteLine("Press 'b' to return to last page or any other key to try again"); ConsoleKeyInfo key1; key1 = Console.ReadKey(); Console.WriteLine(); switch (key1.Key) { case ConsoleKey.B: MainUI.startupUI(); break; default: registerUI(); break; } } } }