예제 #1
0
        public int DisplayGetNumberOfUnitsToSell(Product product)
        {
            ConsoleUtil.HeaderText = "Sell Inventory";
            ConsoleUtil.DisplayReset();


            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.");

                numberOfUnitsToSell = 0;
                DisplayContinuePrompt();
            }

            ConsoleUtil.DisplayReset();

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

            DisplayContinuePrompt();

            return(numberOfUnitsToSell);
        }
        public void DisplayClosingScreen()
        {
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("Thank you for using The Traveling Salesperson Application.");

            DisplayContinuePrompt();
        }
        public void DisplayInventory(Product product)
        {
            ConsoleUtil.HeaderText = "Current Inventory";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("Product type: " + product.Type.ToString());
            ConsoleUtil.DisplayMessage("Number of units: " + product.NumberOfUnits.ToString());
            ConsoleUtil.DisplayMessage("");

            DisplayContinuePrompt();
        }
        public string DisplayGetNextCity()
        {
            string nextCity = "";

            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayPromptMessage("Enter the name of the next city:");
            nextCity = Console.ReadLine();

            return(nextCity);
        }
        /// <summary>
        /// display the current account information
        /// </summary>
        public void DisplayAccountInfo()
        {
            ConsoleUtil.HeaderText = "Account Info";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("First Name: " + _salesperson.FirstName);
            ConsoleUtil.DisplayMessage("Last Name: " + _salesperson.LastName);
            ConsoleUtil.DisplayMessage("Account Number: " + _salesperson.AccountNumber);
             

            DisplayContinuePrompt();
        }
        /// <summary>
        /// 
        /// </summary>
        public void DisplayInventory()
        {
            ConsoleUtil.HeaderText = "Inventory";
            ConsoleUtil.DisplayReset();
            

            ConsoleUtil.DisplayMessage($"Widget type: {Enum.GetName(typeof(WidgetItemStock.WidgetType), _salesperson.CurrentStock.Type)}");


            ConsoleUtil.DisplayMessage($"Number of units: {_salesperson.CurrentStock.ProductUnits}");
            DisplayContinuePrompt();
        }
        /// <summary>
        /// get the next city to travel to from the user
        /// </summary>
        /// <returns>string City</returns>
        public string DisplayGetNextCity()
        {
            ConsoleUtil.HeaderText = "Travel";
            ConsoleUtil.DisplayReset();

            string nextCity = "";
            

            ConsoleUtil.DisplayPromptMessage("Next City of Travel: ");
            nextCity = Console.ReadLine();
            DisplayContinuePrompt();
            return nextCity;
        }
        /// <summary>
        /// display the Exit prompt on a clean screen
        /// </summary>
        public void DisplayExitPrompt()
        {
            ConsoleUtil.HeaderText = "Exit";
            ConsoleUtil.DisplayReset();

            Console.CursorVisible = false;

            Console.WriteLine();
            ConsoleUtil.DisplayMessage("Thank you for using the application. Press any key to Exit.");

            Console.ReadKey();

        }
        public void DisplayExitPrompt()
        {
            ConsoleUtil.DisplayReset();

            Console.CursorVisible = false;

            ConsoleUtil.DisplayMessage("");
            ConsoleUtil.DisplayMessage("Thank you for using the application. Press any key to Exit.");

            Console.ReadKey();

            System.Environment.Exit(1);
        }
예제 #10
0
        public void DisplayCitiesTraveled(Salesperson salesperson)
        {
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("You have traveled to the following cities.");
            ConsoleUtil.DisplayMessage("");

            foreach (string city in salesperson.CitiesVisited)
            {
                ConsoleUtil.DisplayMessage(city);
            }

            DisplayContinuePrompt();
        }
예제 #11
0
        public void DisplayBackorderNotification(Product product, int numberOfUnitsSold)
        {
            ConsoleUtil.HeaderText = "Inventory Backorder Notification";
            ConsoleUtil.DisplayReset();

            int numberOfUnitsBackordered = Math.Abs(product.NumberOfUnits);
            int numberOfUnitsShipped     = numberOfUnitsSold - numberOfUnitsBackordered;

            ConsoleUtil.DisplayMessage("Products Sold: " + numberOfUnitsSold);
            ConsoleUtil.DisplayMessage("Products Shipped: " + numberOfUnitsShipped);
            ConsoleUtil.DisplayMessage("Products on Backorder: " + numberOfUnitsBackordered);

            DisplayContinuePrompt();
        }
        public void DisplayCities()
        {
            ConsoleUtil.HeaderText = "Current City and Cities Visited";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage($"Current City: {_salesperson.CurrentCity}");
            Console.WriteLine();

            ConsoleUtil.DisplayMessage($"List of cities visited:");
            foreach (string city in _salesperson.CitiesVisited)
            {
                ConsoleUtil.DisplayMessage(city);
            }
            
            DisplayContinuePrompt();
            ConsoleUtil.DisplayReset();
        }
        /// <summary>
        /// display the welcome screen
        /// </summary>
        public void DisplayWelcomeScreen()
        {
            StringBuilder sb = new StringBuilder();

            ConsoleUtil.HeaderText = "Welcome to your Control Panel";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("Welcome to your Control Panel");
            Console.WriteLine();

            sb.Clear();
            sb.AppendFormat("Your first task will be to set up your account details. ");
            sb.AppendFormat("Good luck with your sales.");
            ConsoleUtil.DisplayMessage(sb.ToString());

            DisplayContinuePrompt();
        }
        /// <summary>
        /// get the number of widget units to sell from the user
        /// </summary>
        /// <returns></returns>
        public int DisplayGetNumberOfUnitsToSell()
        {
            int numberOfUnitsToSell = 0;

            ConsoleUtil.HeaderText = "Sell Inventory";
            ConsoleUtil.DisplayReset();

            
            try
            {
                ConsoleUtil.DisplayPromptMessage("How many do you want to sell? ");
                numberOfUnitsToSell = int.Parse(Console.ReadLine());
            }
            catch (FormatException)
            {
                ConsoleUtil.DisplayMessage("You did not enter an integer.");
            }
            catch (OverflowException)
            {
                ConsoleUtil.DisplayMessage("Your integer was too large.");
            }
            catch (Exception)
            {
                ConsoleUtil.DisplayMessage("An error occurred.");
            }

            if (_salesperson.CurrentStock.ProductUnits - numberOfUnitsToSell < 0)
            {
                ConsoleUtil.DisplayMessage("You cannot sell more units than you have in inventory.");
                numberOfUnitsToSell = 0;
                DisplayContinuePrompt();

            }
            else
            {
                ConsoleUtil.DisplayPromptMessage($"{numberOfUnitsToSell} units successfully sold.");
                DisplayContinuePrompt();
            }

            

            return numberOfUnitsToSell;
        }
예제 #15
0
        public void DisplayWelcomeScreen()
        {
            StringBuilder sb = new StringBuilder();

            ConsoleUtil.DisplayReset();

            sb.Clear();
            sb.AppendFormat("You are a traveling salesperson buying and selling products ");
            sb.AppendFormat("around the country. You will be prompted regarding which city ");
            sb.AppendFormat("you wish to travel to and will then be asked whether you wish to buy ");
            sb.AppendFormat("or sell products.");
            ConsoleUtil.DisplayMessage(sb.ToString());
            ConsoleUtil.DisplayMessage("");

            sb.Clear();
            sb.AppendFormat("Your first task will be to set up your account details.");
            ConsoleUtil.DisplayMessage(sb.ToString());

            DisplayContinuePrompt();
        }
예제 #16
0
        /// <summary>
        /// display the current account information
        /// </summary>
        public void DisplayAccountInfo(Salesperson salesperson)
        {
            ConsoleUtil.HeaderText = "Account Info";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("First Name: " + salesperson.FirstName);
            ConsoleUtil.DisplayMessage("Last Name: " + salesperson.LastName);
            ConsoleUtil.DisplayMessage("Account ID: " + salesperson.AccountID);
            ConsoleUtil.DisplayMessage("Product Type: " + salesperson.CurrentStock.Type);
            if (!salesperson.CurrentStock.OnBackorder)
            {
                ConsoleUtil.DisplayMessage("Units of Products in Inventory: " + salesperson.CurrentStock.NumberOfUnits);
            }
            else
            {
                ConsoleUtil.DisplayMessage("Units of Products on Backorder: " + Math.Abs(salesperson.CurrentStock.NumberOfUnits));
            }

            DisplayContinuePrompt();
        }
예제 #17
0
        public void DisplayWelcomeScreen()
        {
            StringBuilder sb = new StringBuilder();

            ConsoleUtil.DisplayReset();

            sb.Clear();
            sb.AppendFormat("The Sales Tracker App is here to help! ");
            sb.AppendFormat("After entering your Account info. Sales Tracker will keep ");
            sb.AppendFormat("track of all the cities you have visited and the buying and ");
            sb.AppendFormat("selling of your inventory stock.");
            ConsoleUtil.DisplayMessage(sb.ToString());
            ConsoleUtil.DisplayMessage("");

            sb.Clear();
            sb.AppendFormat("Please set up your account details.");
            ConsoleUtil.DisplayMessage(sb.ToString());

            DisplayContinuePrompt();
        }
예제 #18
0
        public int DisplayGetNumberOfUnitsToBuy(Product product)
        {
            ConsoleUtil.HeaderText = "Buy Inventory";
            ConsoleUtil.DisplayReset();


            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("Please set the number of products you would like to buy.");
                numberOfUnitsToBuy = 0;
                DisplayContinuePrompt();
            }

            ConsoleUtil.DisplayReset();

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

            DisplayContinuePrompt();

            return(numberOfUnitsToBuy);
        }
예제 #19
0
        /// <summary>
        /// get the menu choice from the user
        /// </summary>
        public MenuOption DisplayGetUserMenuChoice()
        {
            MenuOption userMenuChoice = MenuOption.None;
            bool       usingMenu      = true;

            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. Travel" + Environment.NewLine +
                    "\t" + "2. Buy" + Environment.NewLine +
                    "\t" + "3. Sell" + Environment.NewLine +
                    "\t" + "4. Display Inventory" + Environment.NewLine +
                    "\t" + "5. Display Cities" + Environment.NewLine +
                    "\t" + "6. Display Account Info" + Environment.NewLine +
                    "\t" + "E. Exit" + 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':
                    userMenuChoice = MenuOption.Travel;
                    usingMenu      = false;
                    break;

                case '2':
                    userMenuChoice = MenuOption.Buy;
                    usingMenu      = false;
                    break;

                case '3':
                    userMenuChoice = MenuOption.Sell;
                    usingMenu      = false;
                    break;

                case '4':
                    userMenuChoice = MenuOption.DisplayInventory;
                    usingMenu      = false;
                    break;

                case '5':
                    userMenuChoice = MenuOption.DisplayCities;
                    usingMenu      = false;
                    break;

                case '6':
                    userMenuChoice = MenuOption.DisplayAccountInfo;
                    usingMenu      = false;
                    break;

                case 'E':
                case 'e':
                    userMenuChoice = MenuOption.Exit;
                    usingMenu      = false;
                    break;

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

                    userResponse = Console.ReadKey(true);
                    if (userResponse.Key == ConsoleKey.Escape)
                    {
                        usingMenu = false;
                    }
                    break;
                }
            }
            Console.CursorVisible = true;

            return(userMenuChoice);
        }
        public void DisplayUpdateAccountInfo()
        {
            
            bool updatingAccountInfo = true;

            while (updatingAccountInfo)
            {
                ConsoleUtil.HeaderText = "Update Account Info";
                ConsoleUtil.DisplayReset();
                Console.CursorVisible = false;

                ConsoleUtil.DisplayMessage("Select the attribute you wish to update:");
                Console.WriteLine();
                Console.WriteLine(
                    "\t" + "1. First Name" + Environment.NewLine +
                     "\t" + "2. Last Name" + Environment.NewLine +
                    "\t" + "3. Account Number" + Environment.NewLine +
                    "\t" + "4. Widget Type" + Environment.NewLine +
                    "\t" + "E. Exit" + Environment.NewLine);

                ConsoleKeyInfo userResponse = Console.ReadKey(true);
                ConsoleUtil.DisplayReset();
                switch (userResponse.KeyChar)
                {
                    case '1':
                        ConsoleUtil.DisplayPromptMessage("Enter the new first name: ");
                        _salesperson.FirstName = Console.ReadLine();
                        DisplayContinuePrompt();
                        break;
                    case '2':
                        ConsoleUtil.DisplayPromptMessage("Enter the new last name: ");
                        _salesperson.LastName = Console.ReadLine();
                        DisplayContinuePrompt();
                        break;
                    case '3':
                        ConsoleUtil.DisplayPromptMessage("Enter the new account number: ");
                        try
                        {
                            _salesperson.AccountNumber = int.Parse(Console.ReadLine());
                        }
                        catch (FormatException)
                        {
                            ConsoleUtil.DisplayMessage("You did not enter an integer.");
                        }
                        catch (OverflowException)
                        {
                            ConsoleUtil.DisplayMessage("Your integer was too large.");
                        }
                        catch (Exception)
                        {
                            ConsoleUtil.DisplayMessage("An error occurred.");
                        }
                        DisplayContinuePrompt();
                        break;
                    case '4':
                        ConsoleUtil.DisplayPromptMessage("Enter the new widget type: ");
                        try
                        {
                            _salesperson.CurrentStock.Type = (WidgetItemStock.WidgetType)Enum.Parse(typeof(WidgetItemStock.WidgetType), Console.ReadLine(), true);
                            int widgetAsInt = (int)_salesperson.CurrentStock.Type;
                            if (widgetAsInt < 1 || widgetAsInt > 3)
                            {
                                throw new IndexOutOfRangeException();
                            }
                        }
                        catch (ArgumentException e)
                        {
                            ConsoleUtil.DisplayMessage("You did not enter a valid widget type.");
                            
                        }
                        //using one of the predefined exception types for when the user enters a number, say '0' or '4' that does not correspond to a widget type
                        catch (IndexOutOfRangeException)
                        {
                            ConsoleUtil.DisplayMessage("You did not enter a valid widget type.");
                            
                        }
                        catch (Exception e)
                        {
                            ConsoleUtil.DisplayMessage("An error occurred.");
                            
                        }
                        DisplayContinuePrompt();
                        break;
                    case 'E':
                    case 'e':
                        updatingAccountInfo = false;
                        DisplayContinuePrompt();
                        break;
                    default:
                        ConsoleUtil.DisplayMessage("You did not enter a valid input.");
                        DisplayContinuePrompt();
                        break;

                }
            }


            
        }
예제 #21
0
        public Salesperson DisplaySetupAccount()
        {
            Salesperson salesperson = new Salesperson();

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

            ConsoleUtil.DisplayMessage("Setup your account now.");
            ConsoleUtil.DisplayMessage("");

            ConsoleUtil.DisplayPromptMessage("Enter your first name: ");
            salesperson.FirstName = Console.ReadLine();
            ConsoleUtil.DisplayMessage("");

            ConsoleUtil.DisplayPromptMessage("Enter your last name: ");
            salesperson.LastName = Console.ReadLine();
            ConsoleUtil.DisplayMessage("");

            ConsoleUtil.DisplayPromptMessage("Enter your account ID: ");
            salesperson.AccountID = Console.ReadLine();
            ConsoleUtil.DisplayMessage("");

            ConsoleUtil.DisplayMessage("Product Types");
            ConsoleUtil.DisplayMessage("");


            foreach (string productTypeName in Enum.GetNames(typeof(Product.ProductType)))
            {
                if (productTypeName != Product.ProductType.None.ToString())
                {
                    ConsoleUtil.DisplayMessage(productTypeName);
                }
            }


            ConsoleUtil.DisplayMessage("");
            ConsoleUtil.DisplayPromptMessage("Enter the product type: ");
            Product.ProductType productType;
            if (Enum.TryParse <Product.ProductType>(UppercaseFirst(Console.ReadLine()), out productType))
            {
                salesperson.CurrentStock.Type = productType;
            }
            else
            {
                salesperson.CurrentStock.Type = Product.ProductType.None;
            }


            if (ConsoleValidator.TryGetIntegerFromUser(0, 100, 3, "products", out int numberOfUnits))
            {
                salesperson.CurrentStock.AddProducts(numberOfUnits);
            }
            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 zero.");
                salesperson.CurrentStock.AddProducts(0);
                DisplayContinuePrompt();
            }

            ConsoleUtil.DisplayMessage("");

            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("Your account has been setup");

            DisplayContinuePrompt();

            return(salesperson);
        }
        /// <summary>
        /// get the menu choice from the user
        /// </summary>
        public MenuOption DisplayGetUserMenuChoice()
        {
            MenuOption userMenuChoice = MenuOption.None;
            bool usingMenu = true;

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

                //
                // display the menu
                //
                ConsoleUtil.DisplayMessage("Please type the number of your menu choice.");
                Console.WriteLine();
                Console.WriteLine(
                    "\t" + "1. Buy Widgets" + Environment.NewLine +
                     "\t" + "2. Sell Widgets" + Environment.NewLine +
                    "\t" + "3. Display Inventory" + Environment.NewLine +
                    "\t" + "4. Display Cities Visited and Current City" + Environment.NewLine +
                    "\t" + "5. Travel" + Environment.NewLine + 
                    "\t" + "6. Display Account Info" + Environment.NewLine +
                    "\t" + "7. Update Account Info" + Environment.NewLine +
                    "\t" + "E. Exit" + 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':
                        userMenuChoice = MenuOption.Buy;
                        usingMenu = false;
                        break;
                    case '2':
                        userMenuChoice = MenuOption.Sell;
                        usingMenu = false;
                        break;
                    case '3':
                        userMenuChoice = MenuOption.DisplayInventory;
                        usingMenu = false;
                        break;
                    case '4':
                        userMenuChoice = MenuOption.DisplayCities;
                        usingMenu = false;
                        break;
                    case '5':
                        userMenuChoice = MenuOption.Travel;
                        usingMenu = false;
                        break;
                    case '6':
                        userMenuChoice = MenuOption.DisplayAccountInfo;
                        usingMenu = false;
                        break;
                    case '7':
                        userMenuChoice = MenuOption.UpdateAccountInfo;
                        usingMenu = false;
                        break;
                    case 'E':
                    case 'e':
                        userMenuChoice = MenuOption.Exit;
                        usingMenu = false;
                        break;
                    default:
                        ConsoleUtil.DisplayMessage("You did not enter a valid input.");
                        DisplayContinuePrompt();
                        ConsoleUtil.DisplayReset();
                        break;
                }
            }
            Console.CursorVisible = true;

            return userMenuChoice;
        }
        /// <summary>
        /// setup the new salesperson object with the initial data and validate the 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 void DisplaySetupAccount()
        {
            
            ConsoleUtil.HeaderText = "Account Setup";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("Setup your account now.");
            Console.WriteLine();

            ConsoleUtil.DisplayPromptMessage("Enter your first name:  ");
            _salesperson.FirstName = Console.ReadLine();
            Console.WriteLine();

            ConsoleUtil.DisplayPromptMessage("Enter your last name: ");
            _salesperson.LastName = Console.ReadLine();
            Console.WriteLine();

            //validating account number
            bool validAccountNumber = false;
            
            while (!validAccountNumber)
            {
                //indicates whether or not an exception was thrown
                string exceptionMessage = "";

                try
                {
                    ConsoleUtil.DisplayPromptMessage("Enter your account number: ");
                    _salesperson.AccountNumber = int.Parse(Console.ReadLine());
                    
                }
                catch (FormatException e)
                {
                    ConsoleUtil.DisplayMessage("You did not enter an integer.");
                    exceptionMessage = e.Message;
                }
                catch (OverflowException e)
                {
                    ConsoleUtil.DisplayMessage("Your number was too large.");
                    exceptionMessage = e.Message;
                }
                catch (Exception e)
                {
                    ConsoleUtil.DisplayMessage("An error occurred.");
                    exceptionMessage = e.Message;
                }
                finally
                {
                    Console.WriteLine();
                }
                if (exceptionMessage == "")
                {
                    validAccountNumber = true;
                }
            }


            //validating widget type
            bool validWidgetType = false;
            while (!validWidgetType)
            {
                //indicates whether or not an exception was thrown
                string exceptionMessage = "";

                try
                {
                    ConsoleUtil.DisplayPromptMessage("Enter the type of widget you will be selling: ");
                    string userResponse = Console.ReadLine();
                    _salesperson.CurrentStock.Type = (WidgetItemStock.WidgetType)Enum.Parse(typeof(WidgetItemStock.WidgetType), userResponse, true);
                    int widgetAsInt = (int)_salesperson.CurrentStock.Type;
                    if (widgetAsInt < 1 || widgetAsInt > 3)
                    {
                        throw new IndexOutOfRangeException();
                    }
                }
                catch (ArgumentException e)
                {
                    ConsoleUtil.DisplayMessage("You did not enter a valid widget type.");
                    exceptionMessage = e.Message;
                }
                catch (IndexOutOfRangeException)
                {
                    ConsoleUtil.DisplayMessage("You did not enter a valid widget type.");
                    exceptionMessage = "Not within the enum or user selected type none.";
                }
                catch (Exception e)
                {
                    ConsoleUtil.DisplayMessage("An error occurred.");
                    exceptionMessage = e.Message;
                }
                finally
                {
                    Console.WriteLine();
                }

                if (exceptionMessage == "")
                {
                    validWidgetType = true;
                }
            }

            //validating number of widgets
            bool validWidgetCount = false;

            while (!validWidgetCount)
            {
                //indicates whether or not an exception was thrown
                string exceptionMessage = "";

                try
                {
                    ConsoleUtil.DisplayPromptMessage("Enter the number of widgets: ");
                    _salesperson.CurrentStock.AddUnits(int.Parse(Console.ReadLine()));

                }
                catch (FormatException e)
                {
                    ConsoleUtil.DisplayMessage("You did not enter an integer.");
                    exceptionMessage = e.Message;
                }
                catch (OverflowException e)
                {
                    ConsoleUtil.DisplayMessage("Your number was too large.");
                    exceptionMessage = e.Message;
                }
                catch (Exception e)
                {
                    ConsoleUtil.DisplayMessage("An error occurred.");
                    exceptionMessage = e.Message;
                }
                finally
                {
                    Console.WriteLine();
                }
                if (exceptionMessage == "")
                {
                    validWidgetCount = true;
                }
            }
            
            
            
            DisplayContinuePrompt();
        }
예제 #24
0
        /// <summary>
        /// get the menu choice from the user
        /// </summary>
        public MenuOption DisplayGetUserMenuChoice()
        {
            MenuOption userMenuChoice = MenuOption.None;
            bool       usingMenu      = true;

            while (usingMenu)
            {
                ConsoleUtil.DisplayReset();
                Console.CursorVisible = false;


                ConsoleUtil.DisplayMessage("Please type the number of your menu choice.");
                ConsoleUtil.DisplayMessage("");
                Console.Write(
                    "\t" + "1. Travel" + Environment.NewLine +
                    "\t" + "2. Buy" + Environment.NewLine +
                    "\t" + "3. Sell" + Environment.NewLine +
                    "\t" + "4. Display Inventory" + Environment.NewLine +
                    "\t" + "5. Display Cities" + Environment.NewLine +
                    "\t" + "6. Display Account Info" + Environment.NewLine +
                    "\t" + "E. Exit" + Environment.NewLine);


                ConsoleKeyInfo userResponse = Console.ReadKey(true);
                switch (userResponse.KeyChar)
                {
                case '1':
                    userMenuChoice = MenuOption.Travel;
                    usingMenu      = false;
                    break;

                case '2':
                    userMenuChoice = MenuOption.Buy;
                    usingMenu      = false;
                    break;

                case '3':
                    userMenuChoice = MenuOption.Sell;
                    usingMenu      = false;
                    break;

                case '4':
                    userMenuChoice = MenuOption.DisplayInventory;
                    usingMenu      = false;
                    break;

                case '5':
                    userMenuChoice = MenuOption.DisplayCities;
                    usingMenu      = false;
                    break;

                case '6':
                    userMenuChoice = MenuOption.DisplayAccountInfo;
                    usingMenu      = false;
                    break;

                case 'E':
                case 'e':
                    userMenuChoice = MenuOption.Exit;
                    usingMenu      = false;
                    break;

                default:
                    ConsoleUtil.DisplayMessage(
                        "That is not a valid imput. Please enter a valid input." + Environment.NewLine +
                        "Press any key to continue or the E key to quit the application.");

                    userResponse = Console.ReadKey(true);
                    if (userResponse.Key == ConsoleKey.Escape)
                    {
                        usingMenu = false;
                    }
                    break;
                }
            }
            Console.CursorVisible = true;

            return(userMenuChoice);
        }