Ejemplo n.º 1
0
        private void NewOrderTax()
        {
            bool isValidTax = false;

            while (isValidTax == false)
            {
                //display options
                io.DisplayStates(manager.TaxList());
                //get and verify string format for state abbreviation
                state = io.GetStringFromUser("Please enter State Abbreviation (OH format): ");
                if (state.Length != 2)
                {
                    Console.WriteLine("State Abbreviation must be 2 characters long.");
                }
                else
                {
                    state = state.ToUpper();
                }
                //verify state is on list
                taxResponse = manager.Tax(state);

                if (taxResponse.Success)
                {
                    isValidTax = true;
                }
                else
                {
                    Console.WriteLine("The provided abbreviation does not match a state in our service region.");
                }
            }
        }
        public void TaxTest(string state, bool expected)
        {
            TaxStateResponse actual = new TaxStateResponse();
            List <Tax>       taxes  = manager.TaxList();

            actual = manager.Tax(state);

            Assert.AreEqual(expected, actual.Success);
        }
        public TaxStateResponse Tax(string state)
        {
            TaxStateResponse response = new TaxStateResponse();

            foreach (var item in taxes) //TODO: replace with a while loop
            {
                if (state == item.StateAbbreviation)
                {
                    response.Message = "State Verified";
                    response.Success = true;
                    response.Tax     = item;
                    return(response);
                }
                else
                {
                    response.Message = "Not a valid state abbreviation.";
                    response.Success = false;
                }
            }
            return(response);
        }
Ejemplo n.º 4
0
        public string EditState()
        {
            string state   = "";
            bool   isValid = false;

            //display options
            io.DisplayStates(manager.TaxList());

            while (isValid == false)
            {
                //get state
                state = io.GetStringFromUser("Please enter new State Abbreviation or press Enter to skip: ");
                if (state == "")
                {
                    return(state);
                }
                if (state.Length != 2)
                {
                    Console.WriteLine("State Abbreviation must be 2 characters long.");
                }
                else
                {
                    state = state.ToUpper();
                }

                TaxStateResponse taxResponse = manager.Tax(state);

                if (taxResponse.Success)
                {
                    isValid = true;
                }
                else
                {
                    Console.WriteLine("The provided abbreviation does not match a state in our service region.");
                }
            }

            return(state);
        }
Ejemplo n.º 5
0
        public TaxStateResponse LoadTax()
        {
            TaxStateResponse   response = new TaxStateResponse();
            List <FlooringTax> taxes    = new List <FlooringTax>();

            StreamReader sr = null;

            try
            {
                sr = new StreamReader("Taxes.txt");
                sr.ReadLine();
                string row = "";
                while ((row = sr.ReadLine()) != null)
                {
                    FlooringTax t = TaxMapper.ToTax(row);
                    taxes.Add(t);
                }
                if (taxes.Count > 0)
                {
                    response.Success = true;
                    response.TaxRate = taxes;
                }
            }
            catch (FileNotFoundException fileNotFound)
            {
                response.Success = false;
                response.Message = "File was not found";
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }
            return(response);
        }
Ejemplo n.º 6
0
        public void Execute()
        {
            OrderManager manager = OrderManagerFactory.Create();

            Console.Clear();
            Console.WriteLine("Edit an order");
            Console.WriteLine("------------------------");
            bool     isValidDate = false;
            DateTime orderDate   = new DateTime();
            string   date1       = "";

            while (isValidDate == false)
            {
                date1 = io.GetDateFromUser("Please provide a date");

                orderDate = DateTime.ParseExact(date1, "MMddyyyy", CultureInfo.GetCultureInfo("en-us"));

                if (orderDate <= DateTime.Today)
                {
                    Console.WriteLine("Date must be later than today");
                }
                else
                {
                    isValidDate = true;
                }
            }

            DisplayOrderResponse response = manager.LoadOrders(date1);

            foreach (FlooringOrder order in response.Orders)
            {
                io.DisplayOrderDetails(order);
            }

            int  ordernumber   = -1;
            bool isValidNumber = false;

            while (isValidNumber == false)
            {
                string orderstring = io.GetStringFromUser("Please enter an order number.");
                if (!int.TryParse(orderstring, out ordernumber))
                {
                    Console.WriteLine("This did not work, please enter a number");
                }
                else
                {
                    foreach (var item in response.Orders)
                    {
                        if (item.OrderNumber == ordernumber)
                        {
                            newOrder = item;
                        }
                    }
                    isValidNumber = true;
                }
            }

            Console.WriteLine("");
            string newName = PromptUser("What would you like to change your name to?");

            if (newName != "")
            {
                while (!newName.All(c => Char.IsLetterOrDigit(c) || c == ',' || c == '_' || c == '.'))
                {
                    Console.WriteLine("Names must include either letters, numbers, spaces, periods, or commas (or any combonation thereof)");
                    newName = PromptUser("What is your name?");
                }
                newOrder.CustomerName = newName;
            }

            TaxStateResponse taxResponse = uo.LoadTax();
            FlooringTax      orderTax    = new FlooringTax();
            bool             isValidTax  = false;

            while (isValidTax == false)
            {
                foreach (FlooringTax tax in taxResponse.TaxRate)
                {
                    Console.WriteLine("  " + (taxResponse.TaxRate.IndexOf(tax) + 1) + ". " + tax.StateAbbreviation);
                }
                Console.WriteLine("Order is currently in " + newOrder.State);
                string newState = PromptUser("Enter a new state or press enter to continue.");
                if (newState != "")
                {
                    if (int.TryParse(newState, out int nation))
                    {
                        if (nation > 0 && nation <= taxResponse.TaxRate.Count)
                        {
                            newOrder.State   = taxResponse.TaxRate[nation - 1].StateAbbreviation;
                            newOrder.TaxRate = taxResponse.TaxRate[nation - 1].TaxRate;
                            isValidTax       = true;
                        }
                    }
                    else
                    {
                        Console.WriteLine("That state isn't in our region yet.");
                    }
                }
                else
                {
                    isValidTax = true;
                }
            }

            List <FlooringProduct> ProductList  = yo.LoadProducts();
            FlooringProduct        orderProduct = new FlooringProduct();
            bool isValidProduct = false;

            while (isValidProduct == false)
            {
                foreach (FlooringProduct prod in ProductList)
                {
                    Console.Write("  " + (ProductList.IndexOf(prod) + 1) + ". " + prod.ProductType);
                    Console.Write("   Cost per sqft $" + prod.CostPerSquareFoot);
                    Console.Write("   Cost for Labor per sqft $" + prod.LaborCostPerSquareFoot);
                    Console.WriteLine("\n");
                }
                Console.WriteLine("You have already chosen " + newOrder.ProductType);
                string newProduct = PromptUser("Please specifiy a different product or press enter to continue");
                if (newProduct != "")
                {
                    if (int.TryParse(newProduct, out int supply))
                    {
                        if (supply > 0 && supply <= ProductList.Count)
                        {
                            newOrder.ProductType            = ProductList[supply - 1].ProductType;
                            newOrder.LaborCostPerSquareFoot = ProductList[supply - 1].LaborCostPerSquareFoot;
                            newOrder.CostPerSquareFoot      = ProductList[supply - 1].CostPerSquareFoot;
                            isValidProduct = true;
                        }
                    }
                    else
                    {
                        Console.WriteLine("That product isn't available yet.");
                    }
                }
                else
                {
                    isValidProduct = true;
                }
            }

            decimal area1       = 0;
            bool    isValidArea = false;

            while (isValidArea == false)
            {
                area1 = newOrder.Area;
                string area = PromptUser("Please enter a new area or press enter to continue");

                if (area != "")
                {
                    if (decimal.TryParse(area, out area1))
                    {
                        if (area1 < 100)
                        {
                            Console.WriteLine("You must enter a positive amount above 100");
                            Console.WriteLine("Please enter a valid square footage.");
                        }
                        else
                        {
                            newOrder.Area = area1;
                            isValidArea   = true;
                        }
                    }
                }
                else
                {
                    isValidArea = true;
                }
            }

            //ask user for order number
            //if order exisits - ask user for each piece of order data && display exisiting data
            //if user presses Enter key without entering data - leave existing data in place

            //Only CustomerName, State, ProductType, Area can be changed
            //Order date may NOT change

            Console.Clear();
            io.DisplayOrderDetails(newOrder);

            bool isSave = false;

            while (isSave == false)
            {
                string place = PromptUser("Would you like to place this order? Please enter yes or no");
                if (place.ToLower() == "yes")
                {
                    EditOrderResponse editResponse = manager.EditOrder(date1, newOrder);  //still saving the new file even if selecting no
                    isSave = true;
                    // save final to file with approp date
                }
                else if (place.ToLower() == "no")
                {
                    isSave = true;
                    //return to main menu
                }
                else
                {
                    Console.WriteLine("Please enter yes or no");
                }
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Ejemplo n.º 7
0
        public void Execute()
        {
            OrderManager manager = OrderManagerFactory.Create();

            Console.Clear();

            Console.WriteLine("Add an order");
            Console.WriteLine("------------------------");
            bool     isValidDate = false;
            DateTime orderDate   = new DateTime();
            string   date1       = "";

            while (isValidDate == false)
            {
                date1 = io.GetDateFromUser("Please provide a date");

                orderDate = DateTime.ParseExact(date1, "MMddyyyy", CultureInfo.GetCultureInfo("en-us"));

                if (orderDate < DateTime.Today)
                {
                    Console.WriteLine("Date must be after today");
                }
                else
                {
                    isValidDate = true;
                }
            }

            // orderNumberResponse =  manager.NextOrderNumber(date1);

            string name = PromptUser("What is your name?");

            while (!name.All(c => Char.IsLetterOrDigit(c) || c == ',' || c == '_' || c == '.') || name.Trim() == "")
            {
                Console.WriteLine("Names must include either letters, numbers, spaces, periods, or commas (or any combonation thereof)");
                name = PromptUser("What is your name?");
            }

            TaxStateResponse taxResponse = uo.LoadTax();
            FlooringTax      orderTax    = new FlooringTax();
            bool             isValidTax  = false;

            while (isValidTax == false)
            {
                foreach (FlooringTax tax in taxResponse.TaxRate)
                {
                    Console.WriteLine("  " + (taxResponse.TaxRate.IndexOf(tax) + 1) + ". " + tax.StateAbbreviation);
                }
                string state = PromptUser("Please specify the number of the state you're planning on building in.");
                if (int.TryParse(state, out int nation))
                {
                    if (nation > 0 && nation <= taxResponse.TaxRate.Count)
                    {
                        orderTax   = taxResponse.TaxRate[nation - 1];
                        isValidTax = true;
                    }
                }
                else
                {
                    Console.WriteLine("That state isn't in our region yet.");
                }
            }

            List <FlooringProduct> ProductList  = yo.LoadProducts();
            FlooringProduct        orderProduct = new FlooringProduct();
            bool isValidProduct = false;

            while (isValidProduct == false)
            {
                foreach (FlooringProduct prod in ProductList)
                {
                    Console.Write("  " + (ProductList.IndexOf(prod) + 1) + ". " + prod.ProductType);
                    Console.Write("   Cost per sqft $" + prod.CostPerSquareFoot);
                    Console.Write("   Cost for Labor per sqft $" + prod.LaborCostPerSquareFoot);
                    Console.WriteLine("\n");
                }
                string product = PromptUser("Please specify which product you would like to use.");
                if (int.TryParse(product, out int supply))
                {
                    if (supply > 0 && supply <= ProductList.Count)
                    {
                        orderProduct   = ProductList[supply - 1];
                        isValidProduct = true;
                    }
                }
                else
                {
                    Console.WriteLine("That product isn't available yet.");
                }
            }

            //Need to select product, if not (product) then show an error and loop

            string  area = PromptUser("What is the square footage of the area you are looking to cover?");
            decimal area1;

            while (decimal.TryParse(area, out area1) && area1 < 100)
            {
                //if (area1 < 100)
                //{
                Console.WriteLine("You must enter a positive amount above 100");
                Console.WriteLine("Please enter a valid square footage.");
                area = PromptUser("What is the square footage of the area you are looking to cover?");
                //}
                //else
                //{
                //    area = area1.ToString();
                //}
            }

            Console.Clear();

            Console.WriteLine("");
            newOrder.Area                   = area1;
            newOrder.State                  = orderTax.StateAbbreviation;
            newOrder.TaxRate                = orderTax.TaxRate;
            newOrder.CustomerName           = name;
            newOrder.date                   = orderDate;
            newOrder.ProductType            = orderProduct.ProductType;
            newOrder.CostPerSquareFoot      = orderProduct.CostPerSquareFoot;
            newOrder.LaborCostPerSquareFoot = orderProduct.LaborCostPerSquareFoot;
            io.DisplayOrderDetails(newOrder);

            bool isSave = false;

            while (isSave == false)
            {
                string place = PromptUser("Would you like to place this order? Please enter yes or no");
                if (place.ToLower() == "yes")
                {
                    AddOrderResponse addResponse = manager.AddOrder(date1, newOrder);
                    isSave = true;
                    // save final to file with approps date
                }
                else if (place.ToLower() == "no")
                {
                    isSave = true;
                    //return to main menu
                }
                else
                {
                    Console.WriteLine("Please enter yes or no");
                }
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadLine();

            string PromptUser(string s)
            {
                Console.WriteLine(s);
                return(Console.ReadLine());
            }
        }