Example #1
0
        private void EditOrder(string userDate, int userInt)
        {
            bool isValidState = true;
            decimal userDec;
            bool isValidArea = true;
            DisplayOrderToEdit(userDate, userInt);
            IOrderRepo repo = OrderRepoFactory.GetOrderRepository();
            var AllOrders = repo.GetOrders(userDate);

            foreach (var order in AllOrders)
            {
                if (userInt == order.OrderNumber)
                {
                    Console.Write("Customer's Name: ");
                    string userName = Console.ReadLine();
                    if (userName != "")
                    {
                        order.CustomerName = userName;
                    }

                    do
                    {
                        Console.Write("\nState: ");
                        string userState = Console.ReadLine().ToUpper();
                        if (userState != "")
                        {
                            TaxRateOperations taxOps = new TaxRateOperations();

                            if (taxOps.IsAllowedState(userState))

                            {
                                isValidState = true;
                                order.State = userState;
                            }
                            else
                            {
                                Console.Write("\nWe do not operate in that state.\n");
                                isValidState = false;
                            }
                        }
                    } while (!isValidState);

                    TaxRateOperations tops = new TaxRateOperations();
                    TaxRate t1 = tops.GetTaxRateFor(order.State);
                    order.TaxRate = t1.TaxPercent;

                    Console.Write("\nProduct Type: ");
                    string userType = Console.ReadLine();
                    if (userType != "")
                    {
                        order.ProductType = userType;
                    }

                    ProductOps p1 = new ProductOps();
                    Product prod1 = p1.GetProduct(order.ProductType);
                    order.CostPerSquareFoot = prod1.CostPerSquareFoot;
                    order.LaborCostPerSquareFoot = prod1.LaborCostPerSquareFoot;

                    do
                    {
                        Console.Write("\nArea: ");
                        string userArea = Console.ReadLine();
                        if (userArea != "")
                        {
                            if (decimal.TryParse(userArea, out userDec))
                            {
                                isValidArea = true;
                                order.Area = userDec;
                            }
                            else
                            {
                                Console.WriteLine("\nThat was not a valid number.");
                                isValidArea = false;
                            }
                        }
                    } while (!isValidArea);

                    order.LaborCost = (order.LaborCostPerSquareFoot * order.Area);
                    order.MaterialCost = (order.CostPerSquareFoot * order.Area);
                    order.Tax = ((order.LaborCost + order.MaterialCost) * (order.TaxRate / 100.0M));
                    order.Total = order.LaborCost + order.MaterialCost + order.Tax;

                    Console.WriteLine("\nThe order to be edited:\n");
                    Console.WriteLine("\nOrder Number: {0}", order.OrderNumber);
                    Console.WriteLine("Customer Name: {0}", order.CustomerName);
                    Console.WriteLine("State: {0}", order.State);
                    Console.WriteLine("Tax Rate:{0}", order.TaxRate);
                    Console.WriteLine("ProductType: {0}", order.ProductType);
                    Console.WriteLine("Area: {0}", order.Area);
                    Console.WriteLine("Cost Per Sq Ft: {0}", order.CostPerSquareFoot);
                    Console.WriteLine("Labor Cost Per Sq Ft: {0}", order.LaborCostPerSquareFoot);
                    Console.WriteLine("Labor Cost: {0}", order.LaborCost);
                    Console.WriteLine("Material Cost: {0}", order.MaterialCost);
                    Console.WriteLine("Tax: {0}", order.Tax);
                    Console.WriteLine("Total: {0}", order.Total);

                    Console.ReadLine();
                }

                //string[] NewOrders = new string[AllOrders.Count];
                //{
                //    NewOrders[order.OrderNumber - 1] = (order.OrderNumber + "," + newOrder.CustomerName + "," + newOrder.State + "," + newOrder.TaxRate + "," + newOrder.ProductType + "," + newOrder.Area + "," + newOrder.CostPerSquareFoot + "," + newOrder.LaborCostPerSquareFoot + "," + newOrder.MaterialCost + "," + newOrder.LaborCost + "," + newOrder.Tax + "," + newOrder.Total);
                //}
                //File.WriteAllLines(@"C:\MasteryProject\FlooringProgram\FlooringProgram.UI\Data\Orders_06012013.txt", NewOrders); //Teran File Path
            }

            string[] NewOrders = new string[AllOrders.Count()];
            foreach (var order in AllOrders)
            {
                NewOrders[order.OrderNumber - 1] = (order.OrderNumber + "," + order.CustomerName + "," + order.State + "," + order.TaxRate + "," + order.ProductType + "," + order.Area + "," + order.CostPerSquareFoot + "," + order.LaborCostPerSquareFoot + "," + order.MaterialCost + "," + order.LaborCost + "," + order.Tax + "," + order.Total);
            }
            File.WriteAllLines(@".\Data\Orders_06012013.txt", NewOrders); //Teran File Path
        }
Example #2
0
        private Order AskToAdd()
        {
            bool valid = false;
            bool isValidName = true;
            bool isValidState = false;
            bool isValidArea = false;
            decimal userDec;
            Order newOrder = new Order();

            do
            {
                Console.Clear();
                do
                {
                    Console.Write("Customer's Name: ");
                    newOrder.CustomerName = Console.ReadLine();
                    if (newOrder.CustomerName == "")
                    {
                        isValidName = false;
                    }
                    else
                    {
                        isValidName = true;
                    }
                } while (!isValidName);
                do
                {
                    Console.Write("\nState: ");
                    string userState = Console.ReadLine().ToUpper();
                    if (userState != "")
                    {
                        TaxRateOperations taxOps = new TaxRateOperations();

                        if (taxOps.IsAllowedState(userState))

                        {
                            isValidState = true;
                            newOrder.State = userState;
                        }
                        else
                        {
                            Console.Write("\nWe do not operate in that state.\n");
                        }
                    }
                } while (!isValidState);

                TaxRateOperations tops = new TaxRateOperations();
                TaxRate t1 = tops.GetTaxRateFor(newOrder.State);
                newOrder.TaxRate = t1.TaxPercent;

                newOrder.ProductType = setProductType();
                ProductOps p1 = new ProductOps();
                Product prod1 = p1.GetProduct(newOrder.ProductType);
                newOrder.CostPerSquareFoot = prod1.CostPerSquareFoot;
                newOrder.LaborCostPerSquareFoot = prod1.LaborCostPerSquareFoot;

                do
                {
                    Console.Write("\nArea: ");
                    string userArea = Console.ReadLine();

                    if (decimal.TryParse(userArea, out userDec))
                    {
                        isValidArea = true;
                        newOrder.Area = userDec;
                    }
                    else
                    {
                        Console.WriteLine("\nThat was not a valid number.");
                    }
                } while (!isValidArea);
                Console.WriteLine("\n====================");
                newOrder.LaborCost = (newOrder.LaborCostPerSquareFoot * newOrder.Area);
                newOrder.MaterialCost = (newOrder.CostPerSquareFoot * newOrder.Area);
                newOrder.Tax = ((newOrder.LaborCost + newOrder.MaterialCost) * (newOrder.TaxRate / 100.0M));
                newOrder.Total = newOrder.LaborCost + newOrder.MaterialCost + newOrder.Tax;

                Console.WriteLine("\nThe order to be added:\n");
                Console.WriteLine("Customer Name: {0}", newOrder.CustomerName);
                Console.WriteLine("State: {0}", newOrder.State);
                Console.WriteLine("Tax Rate: {0}", newOrder.TaxRate);
                Console.WriteLine("ProductType: {0}", newOrder.ProductType.ToUpper());
                Console.WriteLine("Area: {0}", newOrder.Area);
                Console.WriteLine("Cost Per Sq Ft: {0}", newOrder.CostPerSquareFoot);
                Console.WriteLine("Labor Cost Per Sq Ft: {0}", newOrder.LaborCostPerSquareFoot);
                Console.WriteLine("Labor Cost: {0}", newOrder.LaborCost);
                Console.WriteLine("Material Cost: {0}", newOrder.MaterialCost);
                Console.WriteLine("Tax: {0}", newOrder.Tax);
                Console.WriteLine("Total: {0}", newOrder.Total);

                Console.Write("\n\nCommit this order?(Y/N) ");
                string input = Console.ReadLine().ToUpper();

                if (input == "Y")
                {
                    valid = true;
                }
                else
                {
                    Console.WriteLine("\nPress enter to return to the main menu.");
                    //Console.ReadLine();
                    //MenuOps.displayMenu();
                }
              } while (!valid);

            return newOrder;
        }