示例#1
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);
            }
        }
示例#2
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);
        }