//Method we use to trigger from Main Menu public void Execute() { DisplayHeader(); //the orderdate is equal to whatever date is returned from this method orderDate = GetOrderDate(); //the list is storing the list returned from LoadOrders allOrders = _myOrderManager.LoadOrders(orderDate); //Display the orders with the list passed in DisplayOrders(allOrders); //The orderNumber is equal to whatever number they are prompted for orderNumber = GetOrderNumber(); //store the new order newOrder = SelectandReviseOrder(); //calculate the fields that need to be generated _myOrderManager.Calculator(newOrder); //save the order to the file _myOrderManager.SaveEditedOrder(allOrders, newOrder, orderNumber, orderDate); }
public void WriteToFileTest() { string fake = "fake"; var saveInput = new List<Order>(); var testOrder = new Order(); testOrder.OrderNumber = 1; testOrder.Name = "Smith"; testOrder.State = "OH"; testOrder.TaxRate = .10M; testOrder.ProductType = "Carpet"; testOrder.Area = 10M; testOrder.CostPerSquareFoot = 2M; testOrder.LaborCostPerSquareFoot = 5M; // normally this is where we would stop entering data and // and the Calculator would be called to finish computing the // last four values for the order testOrder.MaterialCost = testOrder.Area * testOrder.CostPerSquareFoot; testOrder.LaborCost = testOrder.LaborCostPerSquareFoot * testOrder.Area; testOrder.Tax = testOrder.TaxRate * testOrder.MaterialCost; testOrder.Total = testOrder.MaterialCost + testOrder.LaborCost + testOrder.Tax; saveInput.Add(testOrder); var fm = new OrderManager(new OrderRepository()); fm.SaveOrdersToFile(saveInput,fake); }
private void DeleteOrder(Order choice) { Console.Clear(); string userConfirm; do { Console.WriteLine("{0} {1} {2} {3}\n",choice.OrderNumber, choice.Name, choice.ProductType, choice.Total); Console.WriteLine("Confirm deletion of order? (Y/N)"); userConfirm = Console.ReadLine(); } while (!(userConfirm=="Y" || userConfirm=="N")); switch (userConfirm) { case "Y": OrdersToDisplay.Remove(choice); SaveUpdatedFile(); break; case "N": break; } }
//adds the order to the orderRepository public void AddNewOrder(Order order, string orderDate) { var allOrders = _orderRepository.LoadOrders(orderDate); order.OrderNumber = GetNextOrderNumber(allOrders); allOrders.Add(order); _orderRepository.AddOrderToFile(order, orderDate); }
private List<Order> OrderListFromArray(string[] allLines) { var orders = new List<Order>(); foreach (string line in allLines.Skip(1)) { string[] columns = line.Split('|'); Order order = new Order(); order.OrderNumber = int.Parse(columns[0]); order.Name = columns[1]; order.State = columns[2]; order.TaxRate = decimal.Parse(columns[3]); order.ProductType = columns[4]; order.Area = decimal.Parse(columns[5]); order.CostPerSquareFoot = decimal.Parse(columns[6]); order.LaborCostPerSquareFoot = decimal.Parse(columns[7]); order.MaterialCost = decimal.Parse(columns[8]); order.LaborCost = decimal.Parse(columns[9]); order.Tax = decimal.Parse(columns[10]); order.Total = decimal.Parse(columns[11]); orders.Add(order); } return orders; }
private void GetOrderName(Order order) { do { Console.Write("Name: "); order.Name = Console.ReadLine(); } while (string.IsNullOrWhiteSpace(order.Name)); }
public void CalculateValues(Order newOrder, Product product) { newOrder.MaterialCost = newOrder.Area*newOrder.CostPerSquareFoot; newOrder.LaborCost = newOrder.Area*newOrder.LaborCostPerSquareFoot; newOrder.Tax = newOrder.TaxRate*newOrder.MaterialCost*.01M; newOrder.Total = newOrder.MaterialCost + newOrder.LaborCost + newOrder.Tax; }
public void AddOrder(Order newOrder, Product chosenProduct, TaxRate taxRateForCustomerState, string orderDate) { //Calculates the fields necessary to store in the Order newOrder.CostPerSquareFoot = chosenProduct.CostPerSquareFoot; newOrder.MaterialCost = newOrder.CostPerSquareFoot*newOrder.Area; newOrder.LaborCost = newOrder.Area * chosenProduct.LaborCostPerSquareFoot; newOrder.Tax = (newOrder.LaborCost + newOrder.MaterialCost) * taxRateForCustomerState.TaxPercent; newOrder.Total = newOrder.LaborCost + newOrder.MaterialCost + newOrder.Tax; newOrder.LaborCostPerSquareFoot = chosenProduct.LaborCostPerSquareFoot; }
public void CalcuateValues(Order newOrder) { newOrder.MaterialCost = (newOrder.Area*newOrder.CostPerSquareFoot); newOrder.LaborCost = (newOrder.Area*newOrder.LaborCostPerSquareFoot); newOrder.Tax = (newOrder.TaxRate*newOrder.MaterialCost*.01M); newOrder.Total = (newOrder.MaterialCost + newOrder.LaborCost + newOrder.Tax); }
private void EditOrder(Order choice) { Console.WriteLine("Enter a new value for each field, or press enter to keep current info: "); Console.WriteLine(); Console.Write("Name ({0})", choice.Name); string userInput = Console.ReadLine(); if (!string.IsNullOrEmpty(userInput)) choice.Name = userInput; Console.Write("State ({0})", choice.State); userInput = Console.ReadLine(); if (!string.IsNullOrEmpty(userInput)) { choice.State = userInput; UpdateTaxRate(choice); UpdateCosts(choice); } Console.Write("Product Type ({0})", choice.ProductType); userInput = Console.ReadLine(); if (!string.IsNullOrEmpty(userInput)) { choice.ProductType = userInput; UpDateProductInfo(choice); UpdateCosts(choice); } Console.Write("Area ({0})", choice.Area); userInput = Console.ReadLine(); if (!string.IsNullOrEmpty(userInput)) { bool res; decimal userNum; do { res = decimal.TryParse(userInput, out userNum); if (!res) { Console.WriteLine("Invalid choice\n"); Console.Write("Area ({0})", choice.Area); userInput = Console.ReadLine(); res = decimal.TryParse(userInput, out userNum); } } while (!res); choice.Area = userNum; UpdateCosts(choice); } ConfirmAndUpdateOrder(choice); }
public void Calculator(Order newOrder) { //second newOrder Edit Functions //just passes in Order and calculates the rest. //Needs to have the specific Tax percent and relevant costs correct previously newOrder.MaterialCost = newOrder.CostPerSquareFoot * newOrder.Area; newOrder.LaborCost = newOrder.Area * newOrder.LaborCostPerSquareFoot; newOrder.Tax = (newOrder.LaborCost + newOrder.MaterialCost) * newOrder.TaxRate; newOrder.Total = newOrder.LaborCost + newOrder.MaterialCost + newOrder.Tax; }
public void CaluclatorTest() { string taxFile = "Taxes"; string productFile = "Products"; string testFIle = "testFile"; var saveInput = new List<Order>(); var testOrder = new Order(); var tax = new TaxRepository(); var taxList = tax.LoadTaxesAndStatesFromFile(); }
private void GetOrderArea(Order order) { decimal temp; Console.Write("Area (square ft): "); string userInput = Console.ReadLine(); while (!decimal.TryParse(userInput, out temp)) { Console.WriteLine("Invalid input"); } order.Area = temp; }
private void GetTaxRate(Order order) { string userInput; var taxList = _taxRateManager.GetAllTaxRates(); do { Console.Write("State (OH, PA, MI, IN): "); userInput = Console.ReadLine(); } while (taxList.All(s => s.State != userInput)); order.State = userInput; // this sets the tax rate based on the current state chosen order.TaxRate = taxList.First(x => x.State == order.State).TaxPercent; }
//Saves edited order public void SaveEditedOrder(List<Order> allOrders, Order order, int orderNumber, string orderDate) { order.OrderNumber = orderNumber; //creating a new Order object called update where order number is equal to the order number the user entered Order Update = allOrders.FirstOrDefault(x => x.OrderNumber == orderNumber); //in the new Order object you set the values equal to the order info passed in Update.CustomerName = order.CustomerName; Update.ProductType = order.ProductType; Update.Area = order.Area; Update.State = order.State; //use the order repository to save the file _orderRepository.SaveFile(allOrders, orderDate); }
public List<Order> LoadOrdersFromFile(string fileName) { var orders = new List<Order>(); var order = new Order(); order.OrderNumber = 1; //int order.Name = "Becky"; order.State = "VT"; order.TaxRate = 10M;//decimal order.ProductType = "Trees"; order.Area = 100M;//decimal order.CostPerSquareFoot = 5M;//decimal order.LaborCostPerSquareFoot = 2M;//decimal order.MaterialCost = 500M;//decimal order.LaborCost = 200M;//decimal order.Tax = 50M;//decimal order.Total = 750M;//decimal orders.Add(order); return orders; // erics fake order: "Orders_06012013.txt" //string[] mockLines = File.ReadAllLines(fileName); //foreach (string line in mockLines.Skip(1)) //{ // string[] columns = line.Split('|'); // Order order = new Order(); // order.OrderNumber = int.Parse(columns[0]); // order.Name = columns[1]; // order.State = columns[2]; // order.TaxRate = decimal.Parse(columns[3]); // order.ProductType = columns[4]; // order.Area = decimal.Parse(columns[5]); // order.CostPerSquareFoot = decimal.Parse(columns[6]); // order.LaborCostPerSquareFoot = decimal.Parse(columns[7]); // order.MaterialCost = decimal.Parse(columns[8]); // order.LaborCost = decimal.Parse(columns[9]); // order.Tax = decimal.Parse(columns[10]); // order.Total = decimal.Parse(columns[11]); // orders.Add(order); //} //return orders; }
private void addOrders_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtName.Text)) { MessageBox.Show("Please enter a customer name."); return; } Order o = new Order(); { o.OrderNumber = 1; //make this 1 for now o.Name = txtName.Text; o.State = cmbState.SelectedItem.ToString(); o.TaxRate = _myTaxRateManager.GetAllTaxRates().FirstOrDefault(x => x.State == o.State).TaxPercent; o.ProductType = cmbProdType.SelectedItem.ToString(); o.Area = upDownArea.Value; o.CostPerSquareFoot = _myProductManager.GetAllProducts() .FirstOrDefault(x => x.ProductType == o.ProductType) .CostPerSquareFoot; o.LaborCostPerSquareFoot = _myProductManager.GetAllProducts() .FirstOrDefault(x => x.ProductType == o.ProductType) .LaborCostPerSquareFoot; o.MaterialCost = o.Area * o.CostPerSquareFoot; o.LaborCost = o.Area * o.LaborCostPerSquareFoot; o.Tax = o.MaterialCost * o.TaxRate; o.Total = o.MaterialCost + o.LaborCost + o.Tax; _currentLoadedOrders.Add(o); }; DialogResult result = MessageBox.Show("Are you sure you want to add this order?", "Confirm Order", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { _myOrderManger.SaveOrdersToFile(_currentLoadedOrders, _filename); RefreshOrdersView(); } }
public void TestOrderNumAssignment() { var testOrder = new Order(); testOrder.Name = "Smith"; testOrder.State = "OH"; testOrder.TaxRate = 0.10M; testOrder.ProductType = "Carpet"; testOrder.Area = 5M; testOrder.CostPerSquareFoot = 2M; testOrder.LaborCostPerSquareFoot = 1M; testOrder.MaterialCost = 4M; testOrder.LaborCost = 10M; testOrder.Tax = 10M; testOrder.Total = 10M; AddOrder p = new AddOrder(); var list = p.GetTodaysOrders(); int n = p.GetNextOrderNumber(list); Assert.IsTrue(n == 1); }
private Order ChooseOrderRemove() { bool res; int userNum; Order emptyOrder = new Order(); //helps user break out of workflow do { Console.Write("\nChoose order# to remove or M to exit: "); string userChoice = Console.ReadLine(); res = int.TryParse(userChoice, out userNum); if (userChoice == "M" || userChoice == "m") return emptyOrder; if (!res ||!_ordersToDisplay.Exists(o => o.OrderNumber == userNum)) Console.WriteLine("\nInvalid choice!"); } while (!res || !_ordersToDisplay.Exists(o => o.OrderNumber == userNum)); var choice = _ordersToDisplay.FirstOrDefault(o => o.OrderNumber == userNum); return choice; }
public void DisplayData(Order newOrder) { //pass in the created order and display it to the user Console.WriteLine("Name: {0}", newOrder.CustomerName); Console.WriteLine("State: {0}", newOrder.State); Console.WriteLine("Tax Rate: {0:P}", newOrder.TaxRate); Console.WriteLine("Product Type: {0}", newOrder.ProductType); Console.WriteLine("Area: {0}", newOrder.Area); Console.WriteLine("Cost per square ft: {0:C}", newOrder.CostPerSquareFoot); Console.WriteLine("Labor cost per square ft: {0:C}", newOrder.LaborCostPerSquareFoot); Console.WriteLine("Material cost: {0:C}", newOrder.MaterialCost); Console.WriteLine("Labor cost: {0:C}", newOrder.LaborCost); Console.WriteLine("Tax: {0:C}", newOrder.Tax); Console.WriteLine("TOTAL COST: {0:C}", newOrder.Total); Console.WriteLine(); //Get confirmation from the user that they want to save the file string result = GetConfirmation(); //if they do want to save teh file, then reference the order manager and add the order to the file if (result == "Y") _myOrderManager.AddNewOrder(newOrder, orderDate); }
public void WriteToFile() { string fake = "fake"; var saveInput = new List<Order>(); var testOrder = new Order(); testOrder.OrderNumber = 1; testOrder.Name = "Smith"; testOrder.State = "OH"; testOrder.TaxRate = .0235M; testOrder.ProductType = "Carpet"; testOrder.Area = 2M; testOrder.LaborCostPerSquareFoot = 1.50M; testOrder.LaborCostPerSquareFoot = 3.25M; testOrder.MaterialCost = testOrder.Area * testOrder.CostPerSquareFoot; testOrder.LaborCost = testOrder.LaborCostPerSquareFoot*testOrder.Area; testOrder.Tax = testOrder.TaxRate*testOrder.MaterialCost; testOrder.Total = testOrder.MaterialCost + testOrder.LaborCost + testOrder.Tax; saveInput.Add(testOrder); var fm = new OrderRepository(); fm.SaveOrdersToFile(saveInput, fake); }
public void UpdateOrderInformation(Order selectedOrder) { Console.WriteLine( "To edit the order, enter a new value for each field or leave blank to keep the existing one..."); Console.WriteLine(); Console.Write("First Name ({0})", selectedOrder.Name); //UpdateName method string userInput = Console.ReadLine(); if (!string.IsNullOrEmpty(userInput)) selectedOrder.Name = userInput; bool isValidState = false; // UpdateState method do { Console.Write("State ({0})", selectedOrder.State); userInput = Console.ReadLine().ToUpper(); var taxLoader = new TaxRepository(); List<Tax> taxList = taxLoader.LoadTaxesAndStatesFromFile(); if (!string.IsNullOrEmpty(userInput)&&(taxList.Exists(t=>t.State==userInput))) { isValidState = true; selectedOrder.State = userInput; UpdateTaxRate(selectedOrder); UpdateCosts(selectedOrder); } else if (string.IsNullOrEmpty(userInput)) { break; } else { Console.WriteLine("{0} is not a valid entry for State. We operate in:", userInput); foreach (var tax in taxList) { Console.WriteLine("{0}", tax.State); } } } while (!isValidState); bool isValidProduct = false; //update Product Method do { Console.Write("Product Type ({0})", selectedOrder.ProductType); userInput = Console.ReadLine(); var productLoader = new ProductRespository(); List<Product> productList = productLoader.LoadProductsFromFile(); if (!string.IsNullOrEmpty(userInput) && (productList.Exists(p => p.ProductType.ToUpper() == userInput.ToUpper()))) { isValidProduct = true; selectedOrder.ProductType = userInput; UpdateProductInfo(selectedOrder); UpdateCosts(selectedOrder); } else if (string.IsNullOrEmpty(userInput)) { break; } else { Console.WriteLine("{0} is not in our inventory. We carry the following products: ", userInput); foreach (var product in productList) { Console.WriteLine("{0}",product.ProductType ); } } } while (!isValidProduct); Console.Write("Area - ({0}):", selectedOrder.Area); //updateArea method userInput = Console.ReadLine(); if (!string.IsNullOrEmpty(userInput)) { bool res; decimal userArea; do { // Console.Write("Area: ({0})", selectedOrder.Area); // userInput = Console.ReadLine(); res = decimal.TryParse(userInput, out userArea); if (!res) { Console.WriteLine("Invalid choice"); Console.Write("Area - ({0}):", selectedOrder.Area); userInput = Console.ReadLine(); res = decimal.TryParse(userInput, out userArea); } } while (!res); selectedOrder.Area = userArea; UpdateCosts(selectedOrder); } ConfirmAndUpdateOrder(selectedOrder); }
/// <summary> /// Gets the user Order info /// </summary> public void GetUserOrderInfo() { Order newOrder = new Order(); // 1. Ask user for customer name newOrder.CustomerName = GetCustomerName(); // 2. Ask user for product type var chosenProduct = GetProduct(); newOrder.ProductType = chosenProduct.ProductType; // 3. Ask user for area of flooring newOrder.Area = GetArea(); // 3. Ask user for state for taxes var chosenTaxRate = GetState(); newOrder.State = chosenTaxRate.State; newOrder.TaxRate = chosenTaxRate.TaxPercent/100; //Get user date orderDate = GetOrderDate(); // 5. Ask Order Manager to calculate and save (pass order, product, and tax rate to order manager) _myOrderManager.AddOrder(newOrder, chosenProduct, chosenTaxRate, orderDate); DisplayData(newOrder); }
private string ConvertOrderToPipeSV(Order order) { return string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}", order.OrderNumber, order.Name, order.State, order.TaxRate, order.ProductType, order.Area, order.CostPerSquareFoot, order.LaborCostPerSquareFoot, order.MaterialCost, order.LaborCost, order.Tax, order.Total); }
private void AddNewOrder(Order order) { var allOrders = GetTodaysOrders(); order.OrderNumber = GetNextOrderNumber(allOrders); allOrders.Add(order); _orderManager.SaveOrdersToFile(allOrders, Filename); }
private Product GetOrderProduct(Order order) { string userInput; var prodList = _productManager.GetAllProducts(); do { Console.Write("Product Type (Carpet, Laminate, Tile, Wood): "); userInput = Console.ReadLine(); } while (prodList.All(p => p.ProductType != userInput)); order.ProductType = userInput; return prodList.First(p => p.ProductType == userInput); }
private void DisplaySummary(Order order) { Console.WriteLine("Name: {0}", order.Name); Console.WriteLine("State: {0}", order.State); Console.WriteLine("Product Type: {0}", order.ProductType); Console.WriteLine("Area: {0}", order.Area); Console.WriteLine("Cost per square ft: {0:C}", order.CostPerSquareFoot); Console.WriteLine("Labor cost per square ft: {0:C}", order.LaborCostPerSquareFoot); Console.WriteLine("Material cost: {0:C}", order.MaterialCost); Console.WriteLine("Labor cost: {0:C}", order.LaborCost); Console.WriteLine("Tax: {0:C}", order.Tax); Console.WriteLine("TOTAL COST: {0:C}", order.Total); Console.WriteLine(); string result = GetConfirmation(); switch (result) { case "Y": AddNewOrder(order); break; case "N": break; } }
private void UpdateTaxRate(Order choice) { var taxList = _taxRateManager.GetAllTaxRates(); var res = taxList.Find(p => p.State == choice.State); choice.TaxRate = res.TaxPercent; }
private void UpdateCosts(Order choice) { var prodList = _productManager.GetAllProducts(); var prod = prodList.Find(y => y.ProductType == choice.ProductType); var c = new Calculator(); c.CalculateValues(choice, prod); }
private void UpDateProductInfo(Order choice) { var prodList = _productManager.GetAllProducts(); var prod = prodList.Find(y => y.ProductType == choice.ProductType); choice.CostPerSquareFoot = prod.CostPerSquareFoot; choice.LaborCostPerSquareFoot = prod.LaborCostPerSquareFoot; var c = new Calculator(); c.CalculateValues(choice, prod); }