Beispiel #1
0
        private static void DisplayProductTypes(bool displayAllProducts)
        {
            List <ProductType> productTypes = ProductTypeOperations.GetAllProductTypes();

            const int prodNameWidth  = -12;
            const int prodCostWidth  = -15;
            const int prodLaborWidth = -10;

            //Console.ForegroundColor = EmphasisColor;
            Console.WriteLine("\t\t    CURRENT PRODUCTS");
            Console.WriteLine();
            Console.ResetColor();
            Console.Write("\t{0," + prodNameWidth + "}", "Name");
            Console.WriteLine("{0," + prodCostWidth + "}{1," + prodLaborWidth + "}", "Cost/Sq Ft", "Labor Cost/Sq Ft");

            if (displayAllProducts)
            {
                for (int i = 0; i < productTypes.Count; i++)
                {
                    Console.ForegroundColor = EmphasisColor;
                    Console.Write("\t{0," + prodNameWidth + "}", productTypes[i].Type);
                    Console.ResetColor();
                    Console.WriteLine("  {0," + prodCostWidth + ":C}     {1," + prodLaborWidth + ":C}", productTypes[i].CostPerSquareFoot, productTypes[i].LaborCostPerSquareFoot);
                }
            }
            else //They should only see the first 10, with the option to see the rest
            {
                for (int i = 0; i <= 10 && i < productTypes.Count; i++)
                {
                    Console.ForegroundColor = EmphasisColor;
                    Console.Write("\t{0," + prodNameWidth + "}", productTypes[i].Type);
                    Console.ResetColor();
                    Console.WriteLine("  {0," + (prodCostWidth + 2) + ":C}     {1," + prodLaborWidth + ":C}", productTypes[i].CostPerSquareFoot, productTypes[i].LaborCostPerSquareFoot);
                }

                //now we've displayed up to 10 products. If there are more. . .
                if (productTypes.Count > 10)
                {
                    Console.WriteLine("\tContinued... (Press enter to display all current product types)");
                }
            }
            Console.WriteLine();
        }
        public void GetAllProductTypesTest()
        {
            var result = ProductTypeOperations.GetAllProductTypes();

            Assert.AreEqual(result.Count(), 2);
        }
Beispiel #3
0
        private static ProductType PromptForValidProductType(string prompt, bool extraInfo = false)
        {
            ProductType        productType  = null;
            List <ProductType> productTypes = ProductTypeOperations.GetAllProductTypes();
            string             userInput    = "";
            bool validProduct         = false;
            bool error                = false;
            bool displayedAllProducts = false;

            while (!validProduct)
            {
                if (!displayedAllProducts && (!extraInfo || error))
                {
                    OffsetTop();
                }

                //display 10 current products and give them the chance to see all of them
                if (!displayedAllProducts)
                {
                    DisplayProductTypes(false);
                }

                //if there was an error in the last time through the loop
                if (error)
                {
                    Console.ForegroundColor = ErrorColor;
                    Console.WriteLine("\tInvalid Product.");
                    Console.WriteLine();
                }

                //get the user input
                Console.ForegroundColor = PromptColor;
                Console.Write("\t" + prompt);
                Console.ForegroundColor = EmphasisColor;
                userInput = Console.ReadLine().Trim();
                Console.ResetColor();
                Console.Clear();

                if (userInput == "") //they want to display all product types
                {
                    OffsetTop();
                    DisplayProductTypes(true);
                    displayedAllProducts = true;
                }
                else if (ProductTypeOperations.IsProductType(userInput))
                {
                    productType = ProductTypeOperations.GetProductType(userInput);
                    Console.Clear();

                    if (extraInfo)
                    {
                        OffsetTop();
                        Console.WriteLine("\t{0} cost per square foot: {1:C}", productType.Type, productType.CostPerSquareFoot);
                        Console.WriteLine("\t{0} labor cost per square foot: {1:C}", productType.Type, productType.LaborCostPerSquareFoot);
                        Console.WriteLine("\t----------------------------------------");
                        Console.WriteLine();
                    }

                    validProduct = true;
                }
                else
                {
                    error = true;
                    if (displayedAllProducts) //the console was just cleared, so we don't want the error list to go away
                    {
                        OffsetTop();
                        DisplayProductTypes(true);
                    }
                }
            }
            return(productType);
        }