public static void Execute() { bool leave = false; while (!leave) { Console.WriteLine("Database Manager"); Console.WriteLine("alpha test version"); Console.WriteLine("1: Display order directory"); Console.WriteLine("2: Write order directory to file"); Console.WriteLine("3: exit to main menu"); Console.WriteLine("Please enter a selection"); int userInt = UserIO.GetIntegerFromUser(); switch (userInt) { case 1: Console.Clear(); UserIO.Displaydictionary(); Console.ReadKey(); break; case 2: Console.Clear(); UserIO.Displaydictionary(); FileIO.WriteOrdersDatabase(); Console.ReadKey(); break; case 3: leave = true; break; } } }
public Product GetProductByIndex(List <Product> Products) { bool realProduct = false; while (!realProduct) { Console.WriteLine("Enter the number of the product you wish to select"); int userchoice = UserIO.GetIntegerFromUser() - 1; if (userchoice < Products.Count() && userchoice >= 0) { Product myproduct = Products[userchoice]; return(myproduct); } } return(null); }
public State GetStateByIndex(List <State> States, int userinput) { bool realState = false; int userchoice = userinput - 1; while (!realState) { if (userchoice < States.Count && userchoice >= 0) { State myState = States[userchoice]; return(myState); } else { Console.WriteLine("Enter the number of the product you wish to select"); userchoice = UserIO.GetIntegerFromUser() - 1; } } return(null); }
public State GetStateByIndex(List <State> States) { bool realState = false; while (!realState) { Console.WriteLine("Enter the number of the sales zone you wish to select"); int userchoice = UserIO.GetIntegerFromUser() - 1; if (userchoice < States.Count && userchoice >= 0) { State myState = States[userchoice]; realState = true; return(myState); } else { Console.WriteLine("Please select a valid zone"); realState = false; } } return(null); }
//------------------------------------------------------------------------------------------------------------------------------------- public void RemoveOrder() { string date = PseudoDateSelect(); string filename = "Orders_" + date + ".txt"; string path = @"C:\repos\chris-williams-individual-work\FlooringMasteryV5\Data\Orders\" + filename; List <Order> CurrentOrders = new List <Order>(); if (!File.Exists(path)) { Console.WriteLine("Invalid date"); Console.WriteLine("Press any key to continue"); Console.ReadKey(); return; } try { LoadOrders current = new LoadOrders(); CurrentOrders = current.ParseFileData(filename); } catch { Console.WriteLine("Could not open specified file"); return; } Console.Clear(); Console.WriteLine($"Orders on {date}"); Console.WriteLine("Order#, Customer name, State, product type, area, total cost"); foreach (Order order in CurrentOrders) { Console.WriteLine($"{order.OrderNumber}, {order.CustomerName}, {order.State}, {order.Product}, {order.Area}, {order.Total:C}"); } bool GoodOrder = false; int todelete = 0; int maxOrderNumber = CurrentOrders[CurrentOrders.Count - 1].OrderNumber; while (!GoodOrder) { Console.WriteLine("Please enter the order number of the order you wish to delete"); int selection = UserIO.GetIntegerFromUser(); if (selection > maxOrderNumber || selection < 1) { GoodOrder = false; Console.WriteLine("Please enter a valid order number"); } else { GoodOrder = true; todelete = selection; break; } } foreach (Order order in CurrentOrders) { if (order.OrderNumber == todelete) { CurrentOrders.Remove(order); break; } } if (CurrentOrders.Count < 1) { File.Delete(path); Console.WriteLine("Date file deleted"); } else { try { using (StreamWriter sw = new StreamWriter(path)) { sw.WriteLine("OrderNumber,CustomerName,State,TaxRate,ProductType,Area,CostPerSquareFoot,LaborCostPerSquareFoot,MaterialCost,LaborCost,Tax,Total"); foreach (Order MyOrder in CurrentOrders) { sw.WriteLine($"{MyOrder.OrderNumber},\"{MyOrder.CustomerName}\",{MyOrder.State},{MyOrder.TaxRate},{MyOrder.Product},{MyOrder.Area},{MyOrder.CostPerSquareFoot},{MyOrder.LaborCostPerSquareFoot},{MyOrder.MaterialCost},{MyOrder.LaborCost},{MyOrder.Tax},{MyOrder.Total}"); } } } catch { Console.WriteLine("Could not write updated order to file"); return; } } Console.WriteLine("Order deleted"); Console.ReadLine(); }
//-------------------------------------------------------------------------------------------------------------------------------------- public void EditOrder() { List <Product> Products = new List <Product>(); try { Products = LoadProducts.LoadAllProducts(); } catch { Console.WriteLine("Could not load product data"); } List <State> States = new List <State>(); try { States = LoadStates.LoadAllStates(); } catch { Console.WriteLine("Could not load sales tax data"); } string date = PseudoDateSelect(); string filename = "Orders_" + date + ".txt"; //enusre write-ability string path = @"C:\repos\chris-williams-individual-work\FlooringMasteryV5\Data\Orders\" + filename; List <Order> CurrentOrders = new List <Order>(); if (!File.Exists(path)) { Console.WriteLine("Invalid date"); Console.WriteLine("Press any key to continue"); Console.ReadKey(); return; } try { LoadOrders current = new LoadOrders(); CurrentOrders = current.ParseFileData(filename); } catch { Console.WriteLine("Could not open specified file"); return; } Console.Clear(); Console.WriteLine($"Orders on {date}"); Console.WriteLine("Order#, Customer name, State, product type, area, total cost"); foreach (Order order in CurrentOrders) { Console.WriteLine($"{order.OrderNumber}, {order.CustomerName}, {order.State}, {order.Product}, {order.Area}, {order.Total:C}"); } bool GoodOrder = false; Order OrderToEdit = new Order(); while (!GoodOrder) { Console.WriteLine("Please enter the order number of the order you wish to edit"); int selection = UserIO.GetIntegerFromUser(); Order chosen = CurrentOrders.Where(o => o.OrderNumber == selection).FirstOrDefault(); if (chosen != null) { OrderToEdit = chosen; GoodOrder = true; break; } else { Console.WriteLine("Enter a valid order number"); } } Console.WriteLine($"The current Customer name is {OrderToEdit.CustomerName}"); Console.WriteLine("Enter a new name, or leave the field blank to retain the current name"); string namechange = Console.ReadLine(); // will need this to be better, maybe seperate into change name function if (namechange != "") { if (namechange[0].ToString() != " ") { OrderToEdit.CustomerName = namechange; Console.WriteLine($"Customer name changed to {OrderToEdit.CustomerName}"); } else { Console.WriteLine($"Customer name reamins {OrderToEdit.CustomerName}"); } } else { Console.WriteLine($"Customer name remains {OrderToEdit.CustomerName}"); } Console.WriteLine($"The current state is {OrderToEdit.State}"); UserIO.DisplayStates(); Console.WriteLine("Please enter the number associated with the customer's updated state"); string statechange = Console.ReadLine(); State Mystate = null; if (statechange != "") { if (statechange[0].ToString() != " ") { Mystate = EditState(States, statechange); OrderToEdit.State = Mystate.StateCode; OrderToEdit.TaxRate = Mystate.TaxRate; } else { Console.WriteLine($"State remains {OrderToEdit.State}"); Mystate = GetState(OrderToEdit.State, States); } } else { Console.WriteLine($"State remains {OrderToEdit.State}"); Mystate = GetState(OrderToEdit.State, States); } Console.Clear(); UserIO.DisplayProducts(); Console.WriteLine($"The current product selected is {OrderToEdit.Product}"); Console.WriteLine("please enter the new product, or leave the field empty to continue"); Product changedproduct = null; string productchange = Console.ReadLine(); if (productchange != "") { if (productchange[0].ToString() != " ") { bool isFinished = false; int productchangeIndex = 0; while (!isFinished) { bool goodInt = int.TryParse(productchange, out productchangeIndex); if (goodInt) { changedproduct = GetProductByIndex(productchangeIndex, Products); OrderToEdit.Product = changedproduct.ProductName; OrderToEdit.LaborCostPerSquareFoot = changedproduct.LaborCost; OrderToEdit.CostPerSquareFoot = changedproduct.CostperSquare; Console.WriteLine($"The product has been updated to {OrderToEdit.Product} with a material cost of of {OrderToEdit.CostPerSquareFoot:C}/ft^2, \nand a labor cost of {OrderToEdit.LaborCostPerSquareFoot:C}"); isFinished = true; } else { Console.WriteLine($"Please enter a valid index number in the range of 1 to {Products.Count}"); productchange = Console.ReadLine(); } } } else { Console.WriteLine($"Product remains {OrderToEdit.Product}"); changedproduct = GetMyProduct(OrderToEdit.Product, Products); } } else { Console.WriteLine($"Product remains {OrderToEdit.Product}"); changedproduct = GetMyProduct(OrderToEdit.Product, Products); } Console.WriteLine($"The current area is {OrderToEdit.Area}"); Console.WriteLine("please enter the new area, or leave the field empty to continue"); string areachange = Console.ReadLine(); if (areachange != "") { if (areachange[0].ToString() != " ") { OrderToEdit.Area = GetArea(areachange); Console.WriteLine($"The new area is {OrderToEdit.Area}"); } else { Console.WriteLine($"The area remains {OrderToEdit.Area}"); } } else { Console.WriteLine($"The area remains {OrderToEdit.Area}"); } OrderToEdit.ComputOrderValues(changedproduct, Mystate); Console.WriteLine($"The order now stands at:\n{ OrderToEdit.CustomerName}, in {OrderToEdit.State}, for {OrderToEdit.Area}ft^2 {OrderToEdit.Product} for a total of {OrderToEdit.Total:C}"); Console.WriteLine("Do you wish to save these these changes?"); Console.WriteLine("enter \'N\' to discard changes or any other key to keep changes?"); string SaveChoice = Console.ReadLine().ToUpper(); if (SaveChoice == "N") { Console.WriteLine("Changes Discared"); return; } else { try { using (StreamWriter sw = new StreamWriter(path)) { sw.WriteLine("OrderNumber,CustomerName,State,TaxRate,ProductType,Area,CostPerSquareFoot,LaborCostPerSquareFoot,MaterialCost,LaborCost,Tax,Total"); foreach (Order MyOrder in CurrentOrders) { sw.WriteLine($"{MyOrder.OrderNumber},\"{MyOrder.CustomerName}\",{MyOrder.State},{MyOrder.TaxRate},{MyOrder.Product},{MyOrder.Area},{MyOrder.CostPerSquareFoot},{MyOrder.LaborCostPerSquareFoot},{MyOrder.MaterialCost},{MyOrder.LaborCost},{MyOrder.Tax},{MyOrder.Total}"); } } } catch { Console.WriteLine("Could not write updated order to file"); return; } Console.WriteLine("Order edited"); } }