コード例 #1
0
        public void AddOrderTestNewFile()
        {
            string mode = "File";
            string productPath = @"DataFiles\Orders\";
            var orderManager = new OrderManager(mode, productPath);

            Order order = new Order()
            {
                OrderNumber = 1,
                CustomerName = "Ringo",
                State = "OH",
                TaxRate = 0.0625m,
                ProductType = "Wood",
                Area = 100m,
                CostPerSqFt = 5.15m,
                LaborCostPerSqFt = 4.75m,
                TotalMaterialCost = 515m,
                TotalLaborCost = 475m,
                TotalTax = 61.88m,
                Total = 1051.88m
            };

            var result = orderManager.AddOrder(order,"06012013");

            Assert.AreEqual(result.Data.Count, 1);
            Assert.IsTrue(result.Success);
            Assert.AreEqual(result.Data[0].CustomerName, "Ringo");
        }
コード例 #2
0
        public void Execute()
        {
            var userQuestions = new UserQuestions();
            var orderManager = new OrderManager();
            var displayWF = new DisplayOrdersWF();

            var date = userQuestions.GetDateIfValidFile();

            var orderNumber = userQuestions.GetOrderNumberIfExists(date);

            var order = orderManager.LoadOrder(orderNumber, date);

            Console.WriteLine("This is the order you wish to remove:");
            Console.WriteLine("-----------------------------------");
            displayWF.PrintSingleOrder(order);

            bool wishToRemove = userQuestions.Confirmation("\nAre you sure you wish to delete this order?");

            if (wishToRemove)
            {
                orderManager.RemoveOrder(orderNumber, date);
                Console.WriteLine("You successfully removed the order.");
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("The order was not removed.");
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
        }
コード例 #3
0
        public void Execute()
        {
            var orderManager = new OrderManager();
            var userQuestions = new UserQuestions();

            do
            {
                var date = userQuestions.AskDate();
                var response = orderManager.DisplayOrders(date);

                if (response.Success)
                {
                    PrintOrders(response.Data);
                    Console.ReadLine();
                    break;
                }

                    Console.WriteLine("A file with that date does not exist. Please try again.");
                    Console.WriteLine("Press enter to continue, or (Q) to quit.");

                    var answer = Console.ReadLine();
                    if (answer.ToUpper() == "Q")
                       break;

                    Console.Clear();

            } while (true);
        }
コード例 #4
0
 public void EditOrderTest()
 {
     // arrange
     var date = "09222015";
     var order1 = new Order();
     var manager = new OrderManager();
     order1.orderNumber = 6;
     order1.customerName = "Wise";
     order1.stateName = "OH";
     order1.taxRate = 6.25M;
     order1.productType = "Wood";
     order1.Area = 100.00M;
     order1.CostPerSquareFoot = 5.15M;
     order1.LaborCostPerSquareFoot = 4.75M;
     order1.MaterialCost = 515.00M;
     order1.LaborCost = 475.00M;
     order1.Tax = 61.88M;
     order1.Total = 1051.88M;
     // act
     manager.AddOrder(order1, date);
     order1.customerName = "Dave";
     var response = manager.EditOrder(order1, date, 6);
     var newname = response.Data.Order.customerName;
     // assert
     Assert.AreNotEqual(newname, "Wise");
 }
コード例 #5
0
 public void DisplayOrderTest()
 {
     // arrange
     var manager = new OrderManager();
     var response = manager.DisplayOrders("09222015");
     // act
     var count = response.Data.Orders.Count;
     // assert
     Assert.AreEqual(count, 2);
 }
コード例 #6
0
        public void DeleteOrder()
        {
            string mode = "File";
            string productPath = @"DataFiles\Orders\";
            var orderManager = new OrderManager(mode, productPath);

            var repo = new OrderFileModeRepo(productPath);
            var order = repo.GetOne(2, "06012013");

            var result = orderManager.DeleteOrder(order, "06012013");

            Assert.AreEqual(result.Data.Count, 1);
            Assert.IsTrue(result.Success);
        }
コード例 #7
0
 public void RemoveOrderTest()
 {
     // arrange
     var manager = new OrderManager();
     var response = manager.DisplayOrders("09222015");
     // act
     var count = response.Data.Orders.Count;
     var orders = response.Data.Orders;
     var order1 = orders.Single(a => a.orderNumber == 1);
     manager.RemoveOrder(order1, "09222015", 1);
     var response2 = manager.DisplayOrders("09222015");
     var count2 = response2.Data.Orders.Count;
     // assert
     Assert.AreNotEqual(count, count2);
 }
コード例 #8
0
        public void Execute()
        {
            string date = HelperMethod.GetDate();
            var orderManager = new OrderManager(Program.Mode, Program.OrderPath);
            var result = orderManager.GetAllOrder(date);

            if (result.Success)
            {
                HelperMethod.displayOrders(result.Data);
            }
            else
            {
                Console.WriteLine(result.Message);
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
コード例 #9
0
        public void Execute()
        {
            var date = GetDate();
            var manager = new OrderManager();
            var response = manager.DisplayOrders(date);
            if (response.Success)
            {
                Console.Clear();
                Console.WriteLine("orderNumber  customerName  stateName  taxRate  productType  Area    CostPerSquareFoot LaborCostPerSquareFoot MaterialCost LaborCost Tax   Total");

                const string format = "{0,-10} {1,11} {2,6} {3,12} {4,14} {5,8:n2} {6,5:n2} {7,17:n2} {8,24:n2} {9,12:n2} {10,8:n2} {11,8:n2}";

                foreach (var order in response.Data.Orders)
                {
                    string line1 = string.Format(format, order.orderNumber,
                        order.customerName, order.stateName,
                        order.taxRate, order.productType,
                        order.Area, order.CostPerSquareFoot,
                        order.LaborCostPerSquareFoot,
                        order.MaterialCost, order.LaborCost,
                        order.Tax, order.Total);

                    Console.WriteLine(line1);

                }
                Console.Write("\nPress any key to continue... ");
                Console.ReadKey();
            }
            else
            {
                Console.Clear();
                Console.WriteLine(response.Message);
                Console.Write("\nPress any key to continue... ");
                Console.ReadKey();
            }
        }
コード例 #10
0
 public void AddOrderTest()
 {
     // arrange
     var manager = new OrderManager();
     // act
     var order1 = new Order();
     order1.orderNumber = 1;
     order1.customerName = "Wise";
     order1.stateName = "OH";
     order1.taxRate = 6.25M;
     order1.productType = "Wood";
     order1.Area = 100.00M;
     order1.CostPerSquareFoot = 5.15M;
     order1.LaborCostPerSquareFoot = 4.75M;
     order1.MaterialCost = 515.00M;
     order1.LaborCost = 475.00M;
     order1.Tax = 61.88M;
     order1.Total = 1051.88M;
     string num = "09222015";
     var response = manager.AddOrder(order1, num);
     var count = response.Data.Orders.Count;
     // assert
     Assert.AreEqual(count, 3);
 }
コード例 #11
0
        public void Execute()
        {
            var date = GetDate();
            var ordernumber = GetOrderNumber();
            var manager = new OrderManager();
            var response = manager.DisplayOrders(date);
            if (response.Data == null || response.Data.Orders.Count == 0)
            {
                Console.WriteLine();
                Console.WriteLine("Sorry! There are no orders at all for that particular date..");
                Console.Write("Press any key to continue... ");
                Console.ReadKey();
            }
            else
            {
                var ordertofind = response.Data.Orders.FirstOrDefault(a => a.orderNumber == ordernumber);
                if (ordertofind == null)
                {
                    Console.WriteLine();
                    Console.Write("Order#{0} was not found. Press any key to continue... ", ordernumber);
                    Console.ReadKey();
                }
                else
                {
                    // we found the correct order.
                    Console.Clear();
                    Console.WriteLine("EDIT ORDER SUMMARY");
                    Console.WriteLine("*****************");
                    Console.WriteLine("orderNumber  customerName  stateName  taxRate  productType  Area    CostPerSquareFoot LaborCostPerSquareFoot MaterialCost LaborCost Tax   Total");
                    const string formatordertofind = "{0,-10} {1,11} {2,6} {3,12} {4,14} {5,8:n2} {6,5:n2} {7,17:n2} {8,24:n2} {9,12:n2} {10,8:n2} {11,7:n2}";
                    string line2 = string.Format(formatordertofind, ordertofind.orderNumber, ordertofind.customerName, ordertofind.stateName,
                        ordertofind.taxRate, ordertofind.productType,
                        ordertofind.Area, ordertofind.CostPerSquareFoot,
                        ordertofind.LaborCostPerSquareFoot,
                        ordertofind.MaterialCost, ordertofind.LaborCost,
                        ordertofind.Tax, ordertofind.Total);

                    Console.WriteLine(line2);
                    Console.WriteLine();
                    Console.Write("\nPress ENTER to edit... ");
                    Console.ReadLine();
                    Console.WriteLine();

                    var ordertoedit = new Order();

                    //Update Customer Name
                    string inputname;
                    do
                    {
                        Console.Write("Enter customer name ({0}): ", ordertofind.customerName);
                        inputname = Console.ReadLine();
                    } while (inputname.Contains(",") || inputname.Contains("."));

                    if (inputname != "")
                    {
                        ordertoedit.customerName = inputname;
                    }
                    if (inputname == "")
                    {
                        ordertoedit.customerName = ordertofind.customerName;
                    }

                    // Update State Name
                    ordertoedit.stateName = GetStateName(ordertofind);

                    // Update Product Type
                    ordertoedit.productType = GetProductType(ordertofind);
                    ordertoedit.orderNumber = ordertofind.orderNumber;
                    // Update Area
                    do
                    {
                        Console.Write("Enter area greater than zero ({0}): ", ordertofind.Area);
                        string inputarea = Console.ReadLine();
                        decimal num;
                        bool test = decimal.TryParse(inputarea, out num);
                        if (inputarea == "")
                        {
                            ordertoedit.Area = ordertofind.Area;
                            break;
                        }
                        if (inputarea != "" && test && decimal.Parse(inputarea) > 0)
                        {
                            ordertoedit.Area = num;
                            break;
                        }
                    } while (true);

                    // confirm (y/n)
                    bool prompt = false;
                    string newgame = "";
                    while (prompt == false)
                    {
                        Console.Write("\nCommit new order? (Y/N): ");
                        newgame = Console.ReadLine();
                        if (newgame.ToUpper() == "Y" || newgame.ToUpper() == "YES"
                            || newgame.ToUpper() == "N" || newgame.ToUpper() == "NO")
                        {
                            prompt = true;
                        }
                    }
                    if (newgame.ToUpper() == "Y" || newgame.ToUpper() == "YES")
                    {

                        var response1 = manager.EditOrder(ordertoedit, date, ordernumber); // the order before it's been fully populated.
                        var editedorder = response1.Data.Order; // the one we get back after we load all data.

                        Console.Clear();
                        Console.WriteLine("(SUMMARY OF NEWLY EDITED ORDER)");
                        Console.WriteLine("*****************");
                        Console.WriteLine("orderNumber  customerName  stateName  taxRate  productType  Area    CostPerSquareFoot LaborCostPerSquareFoot MaterialCost LaborCost Tax   Total");
                        const string formateditorder = "{0,1} {1,19} {2,11} {3,12} {4,10} {5,8:n2} {6,9} {7,17} {8,24} {9,11} {10,8:n2} {11,7:n2}";
                        string line1 = string.Format(formateditorder, editedorder.orderNumber,
                            editedorder.customerName, editedorder.stateName,
                            editedorder.taxRate, editedorder.productType,
                            editedorder.Area, editedorder.CostPerSquareFoot,
                            editedorder.LaborCostPerSquareFoot,
                            editedorder.MaterialCost, editedorder.LaborCost,
                            editedorder.Tax, editedorder.Total);
                        Console.WriteLine(line1);
                        Console.WriteLine();
                        Console.Write("Order has been edited. Press any key to continue...");
                        Console.ReadKey();
                    }
                    else // user types no. Revert back to old order information.
                    {
                        manager.EditOrder(ordertofind, date, ordernumber);
                        Console.Write("Edited changes cancelled. Press any key to continue...");
                        Console.ReadKey();
                    }
                }
            }
        }
コード例 #12
0
        public void Execute()
        {
            Console.Clear();
            string date = HelperMethod.GetDate();
            Console.Clear();
            var orderManager = new OrderManager(Program.Mode, Program.OrderPath);

            var retrieve_result = orderManager.GetAllOrder(date);

            if (retrieve_result.Success)
            {
                HelperMethod.displayOrders(retrieve_result.Data);
                int id;

                while (true)
                {
                    id = HelperMethod.GetID();
                    if (id == 0)
                        break;
                    var success = retrieve_result.Data.Any(o => o.OrderNumber == id);

                    if (success)
                        break;

                    Console.WriteLine("Your input ID is not valid, press enter to continue...");
                    Console.ReadKey();
                }

                if (id == 0)
                    return;

                var orderFound = orderManager.GetOneOrder(id, date);
                if (orderFound.Success)
                {
                    Console.Clear();
                    HelperMethod.displayOrders(orderFound.Data);
                    do
                    {
                        Console.WriteLine("Delete order? Y/N");
                        var commit = Console.ReadLine().ToUpper();
                        if (commit == "Y" || commit == "YES")
                        {
                            var delete_Result = orderManager.DeleteOrder(orderFound.Data[0], date);

                            if (delete_Result.Success)
                            {
                                Console.Clear();
                                Console.WriteLine("Your order is now deleted!");
                                Console.WriteLine("Press any key to continue...");
                                Console.ReadKey();
                                break;
                            }
                            else
                            {
                                Console.Clear();
                                Console.WriteLine(delete_Result.Message);
                                Console.WriteLine("Press any key to continue...");
                                Console.ReadKey();
                                break;
                            }
                        }
                        else if (commit == "N" || commit == "NO")
                            break;
                        Console.Clear();
                        Console.WriteLine("Your input is invalid. Press any key to continue...");
                        Console.ReadKey();
                    } while (true);
                }

                else
                {
                    Console.Clear();
                    Console.WriteLine("That is not a valid Order ID. Press any key to continue ...");
                    Console.ReadKey();
                }
            }
            else
            {
                Console.Clear();
                Console.WriteLine("Order Date is not found! Press any key to continue ...");
                Console.ReadKey();
            }
        }
コード例 #13
0
        public int GetOrderNumberIfExists(DateTime date)
        {
            var orderManager = new OrderManager();

            do
            {
                int orderNumber = AskOrderNumber();

                var orderIsThere = orderManager.OrderExists(orderNumber, date);

                if (orderIsThere)
                {
                    return orderNumber;
                }
                else
                {
                    Console.WriteLine("Order does not exist.");
                    var answer = Confirmation("Would you like to try again?");

                    if (answer == true)
                    {
                        continue;
                    }
                    else
                    {
                        MainMenuWF mainMenu = new MainMenuWF();
                        mainMenu.Execute();
                    }
                }
            } while (true);
        }
コード例 #14
0
        public DateTime GetDateIfValidFile()
        {
            var orderManager = new OrderManager();
            DateTime date;

            do
            {
                date = AskDate();

                var fileIsThere = orderManager.FileExists(date);

                if (fileIsThere)
                {
                    return date;
                }
                else
                {
                    Console.WriteLine("File does not exist.");
                    var answer = Confirmation("Would you like to try again?");

                    if (answer == true)
                    {
                        continue;
                    }
                    else
                    {
                        MainMenuWF mainMenu = new MainMenuWF();
                        mainMenu.Execute();
                    }
                }
            } while (true);
        }
コード例 #15
0
        public string AskState(string originalState)
        {
            var repo = RepoFactory.GetRepo(ConfigurationManager.AppSettings["Mode"]);

            string stateInput;
            var orderManager = new OrderManager();
            var states = repo.LoadStates();
            bool isValidState = false;

            do
            {
                Console.Clear();
                Console.WriteLine("Existing state on file: {0}", originalState);

                Console.WriteLine("Please choose from the following States: \n");

                foreach (var s in states)
                {
                    Console.WriteLine(s.StateAbbreviation);
                }

                Console.WriteLine("Updated state of residence: ");
                stateInput = Console.ReadLine();

                if (stateInput == "")
                {
                    return originalState;
                }

                foreach (var s in states)
                {
                    if (s.StateAbbreviation == stateInput.ToUpper())
                        isValidState = true;
                }

                if (!isValidState)
                {
                    Console.WriteLine("Please enter a valid state. Press any key to continue.");
                    Console.ReadKey();
                }

            } while (!isValidState);

            return stateInput.ToUpper();
        }
コード例 #16
0
        public string AskProductType(string originalProductType)
        {
            var repo = RepoFactory.GetRepo(ConfigurationManager.AppSettings["Mode"]);

            string productInput;
            var orderManager = new OrderManager();
            var products = repo.LoadProducts();
            bool isValidProduct = false;

            do
            {
                Console.Clear();
                Console.WriteLine("Existing flooring material: {0} ", originalProductType);
                Console.WriteLine("Please choose from the following flooring materials: \n");

                foreach (var p in products)
                {
                    Console.WriteLine(p.ProductType);
                }

                Console.WriteLine("Enter the customer's product of choice: ");
                productInput = Console.ReadLine();

                if (productInput == "")
                {
                    return originalProductType;
                }

                foreach (var p in products)
                {
                    if (p.ProductType == productInput)
                    {
                        isValidProduct = true;
                    }
                }

                if (!isValidProduct)
                {
                    Console.WriteLine("Please enter a valid product. Press any key to continue.");
                    Console.ReadKey();
                }
            } while (!isValidProduct);

            return productInput;
        }
コード例 #17
0
        public void Execute()
        {
            Console.Clear();
            string Date = GetDate();
            Console.Clear();
            string CustomerName = GetCustomerName();
            Console.Clear();
            string StateName = GetStateName();
            Console.Clear();
            string ProductType = GetProductType();
            Console.Clear();
            decimal Area = GetArea();
            Console.Clear();
            var manager = new OrderManager();
            var order = new Order();
            order.customerName = CustomerName;
            order.stateName = StateName;
            order.productType = ProductType;
            order.Area = Area;

            var response = manager.AddOrder(order, Date);
            if (response.Data.Orders == null || response.Data.Orders.Count < 1)
            {
                Console.WriteLine("Blah...");
            }
            var neworder = response.Data.Order;
            Console.WriteLine();
            Console.WriteLine("NEW ORDER SUMMARY");
            Console.WriteLine("*****************");
            Console.WriteLine("orderNumber  customerName  stateName  taxRate  productType  Area    CostPerSquareFoot LaborCostPerSquareFoot MaterialCost LaborCost Tax    Total");
            const string formataddorder = "{0,1} {1,15} {2,11} {3,12} {4,10} {5,8:n2} {6,9} {7,17} {8,24} {9,11} {10,8:n2} {11,7:n2}";
            string line1 = string.Format(formataddorder, "#", neworder.customerName, neworder.stateName,
                                      neworder.taxRate, neworder.productType,
                                      neworder.Area, neworder.CostPerSquareFoot,
                                      neworder.LaborCostPerSquareFoot,
                                      neworder.MaterialCost, neworder.LaborCost,
                                      neworder.Tax, neworder.Total);

            Console.WriteLine(line1);
            Console.WriteLine();

            bool prompt = false;
            string newgame = "";
            while (prompt == false)
            {
                Console.Write("Commit new order? (Y/N): ");
                newgame = Console.ReadLine();
                if (newgame.ToUpper() == "Y" || newgame.ToUpper() == "YES"
                    || newgame.ToUpper() == "N" || newgame.ToUpper() == "NO")
                {
                    prompt = true;
                }
            }
            if (newgame.ToUpper() == "Y" || newgame.ToUpper() == "YES")
            {
                Console.Write("Order added to the system. Press any key to continue...");
                Console.ReadKey();
            }
            else
            {

                manager.RemoveOrder(neworder, Date, neworder.orderNumber);
                Console.Write("Order has been cancelled! Press any key to continue...");
                Console.ReadKey();
            }
        }
コード例 #18
0
        public void GetAllOrderTest()
        {
            string mode = "File";
            string productPath = @"DataFiles\Orders\";
            var orderManager = new OrderManager(mode, productPath);
            var result = orderManager.GetAllOrder("06012013");

            Assert.AreEqual(result.Data.Count, 2);
            Assert.IsTrue(result.Success);
            Assert.AreEqual(result.Data[1].OrderNumber,2);
        }
コード例 #19
0
        public void Execute()
        {
            var orderManager = new OrderManager(Program.Mode, Program.OrderPath);
            Console.Clear();
            //var name = getCustomerName();
            var _name = _helper.ValidCustomerName(getCustomerName());
            var _product = _helper.validProductRepo(getProductName());
            var _state = _helper.validStateRepo(getStateAbbrev());
            var _area = _helper.validArea(getArea());
            decimal _taxRate = _stateManager.getTaxRate(_state);
            decimal _laborCostPerSqFt = _productManager.GetLaborCostPerSqFt(_product);
            decimal _costPerSqFt = _productManager.GetCostPerSqFt(_product);
            decimal _totalLaborCost = orderManager.TotalLaborCostCal(_area, _laborCostPerSqFt);
            decimal _totalMaterialCost = orderManager.TotalMaterialCostCal(_area, _costPerSqFt);
            decimal _totalTax = orderManager.TotalTaxCal(_taxRate, _totalMaterialCost, _totalLaborCost);
            decimal _total = orderManager.TotalCal(_taxRate, _totalMaterialCost, _totalLaborCost);

            var newOrder = new List<Order>()
            { new Order()
                {
                    CustomerName = _name,
                    ProductType = _product,
                    State = _state,
                    TaxRate = _taxRate,
                    Area = _area,
                    LaborCostPerSqFt = _laborCostPerSqFt,
                    CostPerSqFt = _costPerSqFt,
                    TotalMaterialCost = _totalMaterialCost,
                    TotalLaborCost = _totalLaborCost,
                    TotalTax = _totalTax,
                    Total = _total
                 }
            };
            Console.Clear();
            Console.WriteLine("Here is your new order...");

            HelperMethod.displayOrders(newOrder);

            do
            {
                Console.WriteLine("Commit new order? Y/N");
                var commit = Console.ReadLine().ToUpper();
                if (commit == "Y" || commit == "YES")
                {
                    var result = orderManager.AddOrder(newOrder[0], _currentDate);

                    if (result.Success)
                    {
                        Console.WriteLine("You order is now added!");
                        HelperMethod.displayOrders(result.Data);
                        Console.WriteLine("Press any key to continue...");
                        Console.ReadKey();
                        break;
                    }
                    else
                    {
                        Console.WriteLine(result.Message);
                        Console.WriteLine("Press any key to continue...");
                        Console.ReadKey();
                        break;
                    }
                }
                else if (commit == "N" || commit == "NO")
                    break;
                Console.WriteLine("Your input is invalid. Press any key to continue...");
                Console.ReadKey();
            } while (true);
        }
コード例 #20
0
        public void GetAllOrderTestFailswithIncorrectDate()
        {
            string mode = "File";
            string productPath = @"DataFiles\Orders\";
            var orderManager = new OrderManager(mode, productPath);
            var result = orderManager.GetAllOrder("09012013");

            //Assert.AreEqual(result.Data, null);
            Assert.IsFalse(result.Success);
        }
コード例 #21
0
        public void EditOrder()
        {
            string mode = "File";
            string productPath = @"DataFiles\Orders\";
            var orderManager = new OrderManager(mode, productPath);

            var repo = new OrderFileModeRepo(productPath);
            var order = repo.GetOne(1, "06012013");
            order.State = "IN";
            order.TaxRate = 6.00m;

            var result = orderManager.EditOrder(order, "06012013");

            Assert.AreEqual(result.Data[0].State, "IN");
            Assert.AreEqual(result.Data[0].TaxRate, 6.00m);
            Assert.AreEqual(result.Data[0].TotalTax, 59.4m);
            Assert.IsTrue(result.Success);
        }
コード例 #22
0
        public void Execute()
        {
            var date = GetDate();
            var ordernumber = GetOrderNumber();
            var manager = new OrderManager();
            var response = manager.DisplayOrders(date);
            if (response.Data == null || response.Data.Orders.Count == 0)
            {
                Console.WriteLine();
                Console.WriteLine("Sorry! There are no orders to delete from that date...");
                Console.Write("Press any key to continue... ");
                Console.ReadKey();
            }
            else
            {
                var ordertofind = response.Data.Orders.FirstOrDefault(a => a.orderNumber == ordernumber);
                if (ordertofind == null)
                {
                    Console.WriteLine();
                    Console.Write("Order#{0} was not found. Press any key to continue... ", ordernumber);
                    Console.ReadKey();
                }
                else
                {
                    // we found the correct order to delete.
                    Console.Clear();
                    Console.WriteLine("DELETE ORDER SUMMARY");
                    Console.WriteLine("*****************");
                    Console.WriteLine("orderNumber  customerName  stateName  taxRate  productType  Area    CostPerSquareFoot LaborCostPerSquareFoot MaterialCost LaborCost Tax    Total");

                    const string formatremove = "{0,-10} {1,11} {2,6} {3,12} {4,14} {5,8:n2} {6,5:n2} {7,17:n2} {8,24:n2} {9,12:n2} {10,8:n2} {11,9:n2}";
                    string line1 = string.Format(formatremove, ordertofind.orderNumber,
                        ordertofind.customerName, ordertofind.stateName,
                        ordertofind.taxRate, ordertofind.productType,
                        ordertofind.Area, ordertofind.CostPerSquareFoot,
                        ordertofind.LaborCostPerSquareFoot,
                        ordertofind.MaterialCost, ordertofind.LaborCost,
                        ordertofind.Tax, ordertofind.Total);

                    Console.WriteLine(line1);
                    Console.WriteLine();

                    // Delete order (y/n)
                    bool prompt = false;
                    string newgame = "";
                    while (prompt == false)
                    {
                        Console.Write("\nDelete entire order. Are you sure? (Y/N): ");
                        newgame = Console.ReadLine();
                        if (newgame.ToUpper() == "Y" || newgame.ToUpper() == "YES"
                            || newgame.ToUpper() == "N" || newgame.ToUpper() == "NO")
                        {
                            prompt = true;
                        }
                    }
                    if (newgame.ToUpper() == "Y" || newgame.ToUpper() == "YES")
                    {

                        manager.RemoveOrder(ordertofind, date, ordernumber);
                        Console.Write("Order has been deleted. Press any key to continue...");
                        Console.ReadKey();
                    }
                    else
                    {
                        Console.Write("Order not deleted. Press any key to continue...");
                        Console.ReadKey();
                    }
                }
            }
        }
コード例 #23
0
        public void Execute()
        {
            Console.Clear();
            string date = HelperMethod.GetDate();
            Console.Clear();
            var orderManager = new OrderManager(Program.Mode, Program.OrderPath);
            var helper = new HelperMethod();

            var retrieve_result = orderManager.GetAllOrder(date);

            if (retrieve_result.Success)
            {
                HelperMethod.displayOrders(retrieve_result.Data);
                int id;

                while (true)
                {
                    id = HelperMethod.GetID();
                    if (id == 0)
                        break;
                    var success = retrieve_result.Data.Any(o => o.OrderNumber == id);

                    if (success)
                        break;

                    Console.WriteLine("Your input ID is not valid, press enter to continue...");
                    Console.ReadKey();
                }

                if (id == 0)
                    return;

                var orderFound = orderManager.GetOneOrder(id, date);

                Order newOrder = new Order();

                if (orderFound.Success)
                {
                    Console.Clear();
                    newOrder = orderFound.Data[0];
                    HelperMethod.displayOrders(orderFound.Data);
                    string name = getCustomerName(orderFound.Data[0].CustomerName);
                    if (name != "")
                    {
                        newOrder.CustomerName = helper.ValidCustomerName(name);
                    }
                    string stateAbbrev = getState(orderFound.Data[0].State);
                    if (stateAbbrev != "")
                    {
                        newOrder.State = helper.validStateRepo(stateAbbrev);
                    }
                    string product = getProduct(orderFound.Data[0].ProductType);
                    if (product != "")
                    {
                        newOrder.ProductType = helper.validProductRepo(product);
                    }
                    string area = getArea(orderFound.Data[0].Area);
                    if (area != "")
                    {
                        newOrder.Area = helper.validArea(area);
                    }
                    var response = orderManager.EditOrder(newOrder, date);

                    if (response.Success)
                    {
                        Console.WriteLine("\n\n\n");
                        Console.WriteLine("Your order has been edited, here is your edited order details. ");
                        HelperMethod.displayOrders(response.Data);
                        Console.WriteLine("Press any key to continue ...");
                        Console.ReadKey();
                    }
                }
                else
                {
                    Console.WriteLine("That is not a valid Order ID. Press any key to continue ... ");
                    Console.ReadKey();
                }

            }
            else
            {
                Console.WriteLine("There are no orders for that date. Press any key to continue ...");
                Console.ReadKey();
            }
        }