//-------------------------------------------------------------------------------------------------------------------------------------- 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"); } }
//-------------------------------------------------------------------------------------------------------------------------------------- public void AddOrder() { 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"); } int ordernumber = FileIO.ReturnHighestOrderNumber() + 1; string date = DateSelect(); 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)) { LoadOrders current = new LoadOrders(); CurrentOrders = current.ParseFileData(filename); } if (!File.Exists(path)) { using (StreamWriter sw = new StreamWriter(path, true)) { sw.WriteLine("OrderNumber,CustomerName,State,TaxRate,ProductType,Area,CostPerSquareFoot,LaborCostPerSquareFoot,MaterialCost,LaborCost,Tax,Total"); } } string name = GetName(); Console.Clear(); Console.WriteLine("Please enter the number associated with the customer's sales zone"); UserIO.DisplayStates(); State state = GetStateByIndex(States); Console.Clear(); UserIO.DisplayProducts(); Product myProduct = GetProductByIndex(Products); decimal area = GetArea(); Order MyOrder = new Order(ordernumber, name, state, myProduct, area, date); Console.WriteLine($"The order for {name} in {state.StateName} is {area}ft^2 of {myProduct.ProductName}"); Console.WriteLine($"The cost/ft^2 for material is{MyOrder.CostPerSquareFoot}, and the labor cost/ft^2 is{MyOrder.LaborCostPerSquareFoot}"); Console.WriteLine($"Total material cost: {MyOrder.MaterialCost:C} \nTotal labor cost: {MyOrder.LaborCost:C}\nTaxes: {MyOrder.Tax:C}\nTotal cost: {MyOrder.Total:C}"); Console.WriteLine("Do you wish to submit this order? Enter \"n\" to discard order"); string input = Console.ReadLine().ToUpper(); if (input != "N") { try { using (StreamWriter sw = new StreamWriter(path, true)) { 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("System Error: order not submitted"); Console.WriteLine("Press any key to continue"); Console.ReadKey(); return; } } else { Console.WriteLine("Order terminated"); Console.WriteLine("Press any key to continue"); Console.ReadKey(); return; } Console.WriteLine("Order entry complete"); }