Beispiel #1
0
        /// <summary>
        /// display confirmation that a salesperson account was successfully loaded
        /// </summary>
        /// <param name="maxAttemptsExceeded"></param>
        /// <returns>bool</returns>
        public bool DisplayLoadAccountInfo(out bool maxAttemptsExceeded)
        {
            string userResponse;

            maxAttemptsExceeded = false;

            ConsoleUtil.HeaderText = "Load Account";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("");
            userResponse = ConsoleValidator.GetYesNoFromUser(MAXIMUM_ATTEMPTS,
                                                             "Load the account information?", out maxAttemptsExceeded);

            if (maxAttemptsExceeded)
            {
                ConsoleUtil.DisplayMessage("It appears you are having difficulty.  You will " +
                                           "return to the main menu.");
                return(false);
            }
            else
            {
                //
                // note use of ternary operator
                //
                return(userResponse == "YES" ? true : false);
            }
        }
        /// <summary>
        /// prompts the user to save account and travel log
        /// </summary>
        /// <param name="salesperson"></param>
        /// <param name="maxAttemptsExceeded"></param>
        /// <returns></returns>
        public bool DisplaySaveAccountInfo(Salesperson salesperson, out bool maxAttemptsExceeded)
        {
            string userResponse;

            maxAttemptsExceeded = false;

            ConsoleUtil.HeaderText = "Save Account";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("The current account information.");
            DisplayAccountDetail(salesperson);

            ConsoleUtil.DisplayMessage("");
            userResponse = ConsoleValidator.GetYesNoFromUser(MAXIMUM_ATTEMPTS, "Save the account information?", out maxAttemptsExceeded);

            if (maxAttemptsExceeded)
            {
                ConsoleUtil.DisplayMessage("It appears you are having difficulties. You will return to the main menu.");
                return(false);
            }
            else
            {
                // note use of ternary operator (takes three arguments)
                return(userResponse == "YES" ? true : false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// get the number of units to sell for a product
        /// </summary>
        /// <returns>int numberOfUnitsToSell</returns>
        public int DisplayGetNumberOfUnitsToSell(Product product)
        {
            ConsoleUtil.HeaderText = "Sell Inventory";
            ConsoleUtil.DisplayReset();

            if (product == null)
            {
                ConsoleUtil.DisplayMessage("No product has been selected");
                DisplayContinuePrompt();
                return(0);
            }
            else
            {
                //
                // get number of units to buy
                //
                ConsoleUtil.DisplayMessage("Selling " + product.Type.ToString() + " products.");
                ConsoleUtil.DisplayMessage("");

                if (!ConsoleValidator.TryGetIntegerFromUser(MINIMUM_BUYSELL_AMOUNT, MAXIMUM_BUYSELL_AMOUNT, MAXIMUM_ATTEMPTS, "products", out int numberOfUnitsToSell))
                {
                    ConsoleUtil.DisplayMessage("It appears you are having difficulty setting the number of products to sell.");
                    ConsoleUtil.DisplayMessage("By default, the number of products to sell will be set to zero.");
                    numberOfUnitsToSell = 0;
                    DisplayContinuePrompt();
                }
                ConsoleUtil.DisplayReset();

                ConsoleUtil.DisplayMessage(numberOfUnitsToSell + " " + product.Type.ToString() + " products have been subtracted from the Inventory.");

                DisplayContinuePrompt();

                return(numberOfUnitsToSell);
            }
        }
Beispiel #4
0
        /// <summary>
        /// get the number of units to buy for a product
        /// </summary>
        /// <returns>int numberOfUnitsToBuy</returns>
        public int DisplayGetNumberOfUnitsToBuy(Product product)
        {
            ConsoleUtil.HeaderText = "Buy Inventory";
            ConsoleUtil.DisplayReset();

            //
            // get number of units to buy
            //
            ConsoleUtil.DisplayMessage("Buying " + product.Type.ToString() + " products.");
            ConsoleUtil.DisplayMessage("");

            if (!ConsoleValidator.TryGetIntegerFromUser(MINIMUM_BUYSELL_AMOUNT, MAXIMUM_BUYSELL_AMOUNT, MAXIMUM_ATTEMPTS, "products", out int numberOfUnitsToBuy))
            {
                ConsoleUtil.DisplayMessage("It appears you are having difficulty setting the number of products to buy.");
                ConsoleUtil.DisplayMessage("By default, the number of products to buy will be set to zero.");
                numberOfUnitsToBuy = 0;
                DisplayContinuePrompt();
            }
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage(numberOfUnitsToBuy + " " + product.Type.ToString() + " products have been added to the Inventory.");

            DisplayContinuePrompt();

            return(numberOfUnitsToBuy);
        }
        /// <summary>
        /// the user is prompted to enter the number of units to sell
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        public int GetNumberOfUnitsToSell()
        {
            // validate get number of units from user
            if (!ConsoleValidator.TryGetIntegerFromUser(MINIMUM_BUYSELL_AMOUNT, MAXIMUM_BUYSELL_AMOUNT, MAXIMUM_ATTEMPTS, "Product", out int numberOfUnitsToSell))
            {
                ConsoleUtil.DisplayMessage("It appears you are having difficulties setting the number of units to buy.");
                ConsoleUtil.DisplayMessage("The number of units to sell will be set to it's default value of 0.");

                numberOfUnitsToSell = 0;
                DisplayContinuePrompt();
            }

            DisplayContinuePrompt();

            return(numberOfUnitsToSell);
        }
        /// <summary>
        /// This methods prompts the user for products and adds them to the list
        /// </summary>
        /// <param name="salesperson"></param>
        /// <returns></returns>
        public List <Product> DisplayGetProducts(Salesperson salesperson)
        {
            // initialize new list of products
            salesperson.CurrentStock = new List <Product>();

            bool   keepAdding = true;
            string userResponse;
            bool   maxAttemptsExceeded = false;

            Product.ProductType productType;

            while (keepAdding)
            {
                productType = GetTypeOfProduct(salesperson, "add", out bool notInStock);

                // checks to see if product already exist in inventory or is set to type none
                if (!notInStock && productType != Product.ProductType.None)
                {
                    // get number of products
                    if (ConsoleValidator.TryGetIntegerFromUser(MINIMUM_BUYSELL_AMOUNT, MAXIMUM_BUYSELL_AMOUNT, MAXIMUM_ATTEMPTS, productType.ToString(), out int numberOfUnits))
                    {
                        // add product to current stock list
                        salesperson.CurrentStock.Add(new Product(productType, numberOfUnits, false));

                        userResponse = ConsoleValidator.GetYesNoFromUser(MAXIMUM_ATTEMPTS, "Do you wish to continue adding products?", out maxAttemptsExceeded);
                        ConsoleUtil.DisplayReset();

                        if (maxAttemptsExceeded || userResponse == "NO")
                        {
                            // exit the while loop
                            keepAdding = false;
                        }
                        else
                        {
                            //display available products to user
                            DisplayAvailableProducts();
                            ConsoleUtil.DisplayMessage("");
                        }
                    }
                    else
                    {
                        ConsoleUtil.DisplayMessage("It appears you are having difficulty setting the number of products in your stock.");
                        ConsoleUtil.DisplayMessage("By default, the number of products in your inventory are now set to 0.");

                        // add product to current stock list with default number of units set to 0
                        salesperson.CurrentStock.Add(new Product(productType, 0, false));

                        userResponse = ConsoleValidator.GetYesNoFromUser(MAXIMUM_ATTEMPTS, "Do you wish to continue adding products?", out maxAttemptsExceeded);
                        ConsoleUtil.DisplayReset();

                        if (maxAttemptsExceeded || userResponse == "NO")
                        {
                            // exit the while loop
                            keepAdding = false;
                        }
                        else
                        {
                            //display available products to user
                            DisplayAvailableProducts();
                            ConsoleUtil.DisplayMessage("");
                        }
                    }
                }
                else
                {
                    ConsoleUtil.DisplayMessage(productType.ToString() + " already exist in your inventory.");

                    userResponse = ConsoleValidator.GetYesNoFromUser(MAXIMUM_ATTEMPTS, "Do you wish to continue adding products?", out maxAttemptsExceeded);
                    ConsoleUtil.DisplayReset();

                    if (maxAttemptsExceeded || userResponse == "NO")
                    {
                        // exit the while loop
                        keepAdding = false;
                    }
                    else
                    {
                        //display available products to user
                        DisplayAvailableProducts();
                        ConsoleUtil.DisplayMessage("");
                    }
                }

                if (productType == Product.ProductType.None)
                {
                    salesperson.CurrentStock.Add(new Product(Product.ProductType.None, 0, false));

                    // exit while loop
                    keepAdding = false;
                }
            }

            return(salesperson.CurrentStock);
        }
Beispiel #7
0
        /// <summary>
        /// display a list of product types and return the selected product with cost
        /// </summary>
        public void DisplayProductUserSelection(Salesperson salesperson)
        {
            bool usingMenu           = true;
            int  maxAttempts         = 3;
            bool maxAttemptsExceeded = false;

            Product product = new Product();

            Product.ProductType productType = new Product.ProductType();

            productType = Product.ProductType.None;

            //
            // set up display area
            //
            ConsoleUtil.DisplayReset();
            ConsoleUtil.HeaderText = "Select a Product";
            Console.CursorVisible  = false;

            while (usingMenu)
            {
                //
                // set up display area
                //
                ConsoleUtil.DisplayReset();
                Console.CursorVisible = false;

                //
                // display the menu
                //
                ConsoleUtil.DisplayMessage("Please type the number of your menu choice.");
                ConsoleUtil.DisplayMessage("");
                Console.Write(
                    "\t" + "1. Furry" + Environment.NewLine +
                    "\t" + "2. Spotted" + Environment.NewLine +
                    "\t" + "3. Dancing" + Environment.NewLine);

                //
                // get and process the user's response
                // note: ReadKey argument set to "true" disables the echoing of the key press
                //
                ConsoleKeyInfo userResponse = Console.ReadKey(true);
                switch (userResponse.KeyChar)
                {
                case '1':
                    productType = Product.ProductType.Furry;
                    usingMenu   = false;
                    break;

                case '2':
                    productType = Product.ProductType.Spotted;
                    usingMenu   = false;
                    break;

                case '3':
                    productType = Product.ProductType.Dancing;
                    usingMenu   = false;
                    break;

                default:
                    ConsoleUtil.DisplayMessage(
                        "It appears you have selected an incorrect choice." + Environment.NewLine +
                        "Press any key to continue.");

                    userResponse = Console.ReadKey(true);
                    if (userResponse.Key == ConsoleKey.Escape)
                    {
                        usingMenu = false;
                    }
                    break;
                }
                product.Type = productType;
            }
            Console.Clear();

            if (!string.IsNullOrEmpty(product.Type.ToString()))
            {
                product.Cost = ConsoleValidator.TestForDouble(maxAttempts, $"{product.Type} Product Cost:", out maxAttemptsExceeded);
            }

            Console.CursorVisible    = true;
            salesperson.CurrentStock = product;
            //return product;
        }
Beispiel #8
0
        /// <summary>
        /// setup the new salesperson object with the initial data
        /// Note: To maintain the pattern of only the Controller changing the data this method should
        ///       return a Salesperson object with the initial data to the controller. For simplicity in
        ///       this demo, the ConsoleView object is allowed to access the Salesperson object's properties.
        /// </summary>
        public Salesperson DisplaySetupAccount()
        {
            Salesperson salesperson = new Salesperson();
            int         maxAttempts = 3;
            string      firstName;
            string      lastName;
            string      accountId;
            string      city;
            bool        maxAttemptsExceeded = false;

            ConsoleUtil.HeaderText = "Account Setup";
            ConsoleUtil.DisplayReset();

            firstName = ConsoleValidator.TestForEmpty(maxAttempts, "First Name:", out maxAttemptsExceeded);

            if (!string.IsNullOrEmpty(firstName))
            {
                salesperson.FirstName = firstName;
                maxAttemptsExceeded   = false;
            }
            else
            {
                return(salesperson);
            }

            lastName = ConsoleValidator.TestForEmpty(maxAttempts, "Last Name:", out maxAttemptsExceeded);

            if (!string.IsNullOrEmpty(lastName))
            {
                salesperson.LastName = lastName;
                maxAttemptsExceeded  = false;
            }
            else
            {
                return(salesperson);
            }

            accountId = ConsoleValidator.TestForEmpty(maxAttempts, "Account ID:", out maxAttemptsExceeded);

            if (!string.IsNullOrEmpty(accountId))
            {
                salesperson.AccountID = accountId;
                maxAttemptsExceeded   = false;
            }
            else
            {
                return(salesperson);
            }

            city = ConsoleValidator.TestForEmpty(maxAttempts, "City:", out maxAttemptsExceeded);

            if (!string.IsNullOrEmpty(city))
            {
                salesperson.CitiesVisited.Add(city);
                maxAttemptsExceeded = false;
            }
            else
            {
                return(salesperson);
            }

            return(salesperson);
        }