Esempio n. 1
0
        public void OrderToStringTests()
        {
            FlooringProduct product = new FlooringProduct
            {
                ProductType            = "Wood",
                CostPerSquareFoot      = 5.15m,
                LaborCostPerSquareFoot = 4.75m
            };
            FlooringTax tax = new FlooringTax
            {
                TaxRate           = 6.25m,
                StateAbbreviation = "OH"
            };
            FlooringOrder order = new FlooringOrder()
            {
                OrderNumber            = 1,
                date                   = new DateTime(2013, 6, 1, 0, 00, 00),
                CustomerName           = "Wise",
                TaxRate                = tax.TaxRate,
                State                  = "OH",
                ProductType            = product.ProductType,
                Area                   = 100.00m,
                CostPerSquareFoot      = 5.15m,
                LaborCostPerSquareFoot = 4.75m
            };
            string actual   = OrderMapper.ToString(order);
            string expected = "1||6/1/2013 12:00:00 AM||Wise||OH||6.25||Wood||100.00||5.15||4.75||515.00||475.00||61.88||1051.88";

            Assert.AreEqual(expected, actual);
        }
Esempio n. 2
0
        public static FlooringTax ToTax(string row)
        {
            FlooringTax t = new FlooringTax();

            string[] fields = row.Split(',');

            t.StateAbbreviation = fields[0];
            t.StateName         = fields[1];
            t.TaxRate           = decimal.Parse(fields[2]);

            return(t);
        }
Esempio n. 3
0
        public void TaxFromStringTest(string row, string abbreviation, string name, decimal taxRate)
        {
            FlooringTax actual   = TaxMapper.ToTax(row);
            FlooringTax expected = new FlooringTax
            {
                StateAbbreviation = abbreviation,
                StateName         = name,
                TaxRate           = taxRate,
            };

            Assert.AreEqual(expected.StateName, actual.StateName);
            Assert.AreEqual(expected.StateAbbreviation, actual.StateAbbreviation);
            Assert.AreEqual(expected.TaxRate, actual.TaxRate);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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();
        }
Esempio n. 6
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());
            }
        }