Example #1
0
        private void RemoveAnOrder()
        {
            Console.Clear();
            string path = GetOrderPath();
            if (path == null)
                return;
            Console.Clear();
            List<Orders> orderList = null;
            try
            {
                orderList = o.LoadInMem(path);
            }
            catch
            {
                return;
            }
            int numb1 = 0;
            bool isIntParse = false;
            bool isUserChoice = false;
            List<Orders> oldOrder = new List<Orders>();
            var min = orderList.Min(x => x.OrderNumber);
            var max = orderList.Max(x => x.OrderNumber);
            Orders orderToRemove = new Orders();
            do
            {

                Console.WriteLine("Select a order number to be removed");
                Console.Write("Order numbers {0} ----> {1}       ", min, max);
                var input = Console.ReadLine();
                bool toParse = int.TryParse(input, out numb1);
                if (numb1 >= min && numb1 <= max && toParse)
                {

                    oldOrder = orderList.Where(x => x.OrderNumber == numb1).ToList();
                    orderToRemove = orderList.FirstOrDefault(x => x.OrderNumber == numb1);
                    if (orderToRemove == null)
                    {
                        Console.WriteLine("That order does not exist. Order was previously removed");
                    }
                    isIntParse = true;
                }
                else Console.WriteLine("Invalid Input");
                _orders.ShowNewOrder(oldOrder);
            } while (!isIntParse || orderToRemove == null);
            do
            {
                Console.WriteLine("Are you sure you want to remove Order? Y/N      ");
                var userChoice = Console.ReadLine().ToUpper();
                if (userChoice == "Y")
                {
                    orderList.RemoveAll(x => x.OrderNumber == numb1);
                    isUserChoice = true;
                    o.SaveFromMem(orderList, path);

                }
                else if (userChoice == "N")
                {
                    isUserChoice = true;
                }
                else Console.WriteLine("Invalid Input");
            } while (!isUserChoice);
            Console.Clear();
        }
Example #2
0
        private void EditAnOrder()
        {
            Console.Clear();
            string path = GetOrderPath();
            if (path == null)
                return;
            Console.Clear();
            List<Orders> orderData = null;
            try
            {
                orderData = o.LoadInMem(path);
            }
            catch
            {
                return;
            }
            bool isIntParse = false;
            bool isStateTrue = false;
            bool isProductTrue = false;
            int numb1 = 0;
            decimal txRate = 0.00m;
            string changeProductType = "";
            decimal changeArea = 0.00m;
            decimal subTotal = 0.00m;
            string changeState = "";
            int changeOrderNumber = 0;
            string changeCustomerName = "";
            decimal changeCostPerSquareFoot = 0.00m;
            decimal changeLaborCostPerSquareFoot = 0.00m;
            decimal changeMaterialCost = 0.00m;
            decimal changeLaborCost = 0.00m;
            decimal changeTaxTotal = 0.00m;
            decimal changeTotal = 0.00m;
            List<Orders> listToEdit = new List<Orders>();
            Orders oldOrder = new Orders();
            var min = orderData.Min(x => x.OrderNumber);
            var max = orderData.Max(x => x.OrderNumber);
            _orders.ShowNewOrder(orderData);
            do
            {

                Console.WriteLine("Select a order number to be edited");
                Console.Write("Order numbers {0} ----> {1}       ",min,max);
                var input = Console.ReadLine();
                bool toParse = int.TryParse(input, out numb1);
                if (numb1 >= min && numb1 <= max && toParse)
                {

                    listToEdit = orderData.Where(x => x.OrderNumber == numb1).ToList();
                    _orders.ShowNewOrder(listToEdit);
                    oldOrder = listToEdit.FirstOrDefault(or => or.OrderNumber == numb1);
                    if (oldOrder == null)
                    {
                        Console.WriteLine("That order does not exist. Order was previously removed");

                    }
                    isIntParse = true;
                }
                else
                    Console.WriteLine("Invalid input");
            } while (!isIntParse || oldOrder == null);
            Console.Clear();

            changeOrderNumber = oldOrder.OrderNumber;
            Console.Write("Current customer name: {0}       ", oldOrder.CustomerName);
            changeCustomerName = Console.ReadLine();
            Console.WriteLine("");
            if (changeCustomerName == "")
            {
                changeCustomerName = oldOrder.CustomerName;
            }
            do
            {
                Console.Write("Current State: {0}      ", oldOrder.State);
                changeState = Console.ReadLine().ToUpper();
                Console.WriteLine("");
                var txRateTru = t.IsAllowedState(changeState);
                if (txRateTru)
                {
                    txRate = t.GetTaxRateFor(changeState).TaxPercent;
                    isStateTrue = true;
                }
                else if (changeState == "")
                {
                    changeState = oldOrder.State;
                    txRate = t.GetTaxRateFor(changeState).TaxPercent;
                    isStateTrue = true;
                }
                else Console.WriteLine("Invalid Input");
            } while (!isStateTrue);
            do
            {
                Console.Write("Current product type: {0}       ", oldOrder.ProductType);
                changeProductType = Console.ReadLine();
                var orProTrue = p.IsAllowedProduct(changeProductType);
                if (orProTrue)
                {
                    changeProductType = p.GetProductFor(changeProductType).ProductType;
                    isProductTrue = true;
                }
                else if (changeProductType == "")
                {
                    changeProductType = oldOrder.ProductType;
                    isProductTrue = true;
                }
                else Console.WriteLine("Invalid Input");
            } while (!isProductTrue);
            Console.WriteLine("");
            Console.Write("Current area: {0} Sqft       ", oldOrder.Area);
            var areaInput = Console.ReadLine();
            if (areaInput == "")
            {
                changeArea = oldOrder.Area;
            }
            else if (areaInput != "")
            {
                changeArea = decimal.Parse(areaInput);
            }
            else
                Console.WriteLine("Invalid Input");
            changeCostPerSquareFoot = p.GetProductFor(changeProductType).CostPerSquareFoot;
            changeLaborCostPerSquareFoot = p.GetProductFor(changeProductType).LaborCostPerSquareFoot;
            changeMaterialCost = c.MaterialTotalCalc(changeArea, changeCostPerSquareFoot);
            changeLaborCost = c.LaborTotalCalc(changeArea, changeLaborCostPerSquareFoot);
            subTotal = changeLaborCost + changeMaterialCost;
            changeTaxTotal = c.TaxTotalCalc(txRate, subTotal);
            changeTotal = c.TotalOrderCalc(subTotal, changeTaxTotal);

            oldOrder.OrderNumber = changeOrderNumber;
            oldOrder.CustomerName = changeCustomerName;
            oldOrder.State = changeState;
            oldOrder.TaxRate = txRate;
            oldOrder.ProductType = changeProductType;
            oldOrder.Area = changeArea;
            oldOrder.CostPerSquareFoot = changeCostPerSquareFoot;
            oldOrder.LaborCostPerSquareFoot = changeLaborCostPerSquareFoot;
            oldOrder.MaterialCost = changeMaterialCost;
            oldOrder.LaborCost = changeLaborCost;
            oldOrder.Tax = changeTaxTotal;
            oldOrder.Total = changeTotal;

            o.SaveFromMem(orderData, path);
            Console.WriteLine();
            Console.WriteLine();
            _orders.ShowNewOrder(listToEdit);
            Console.WriteLine("Press enter to continue");
            Console.ReadLine();
            Console.Clear();
        }