예제 #1
0
        public bool DisplayLoadAccountInfo(Salesperson _salesperson, out bool maxAttemptsExceeded)
        {
            maxAttemptsExceeded = false;
            string userResponse;

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

            ConsoleUtil.DisplayMessage("");
            userResponse = ConsoleValidator.GetYesNoFromUser(maxAttempts, "Load account info?", out maxAttemptsExceeded);

            if (maxAttemptsExceeded)
            {
                ConsoleUtil.DisplayMessage("It appears you are having difficult, we will return you" +
                                           "to the main menu");
            }
            else
            {
                return(userResponse == "yes" ? true : false);
            }

            return(maxAttemptsExceeded);
        }
예제 #2
0
        /// <summary>
        /// prompts the user to load account and travel log infor
        /// </summary>
        /// <param name="maxAttemptsExceeded"></param>
        /// <returns></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 difficulties. You will return to the main menu.");
                return(false);
            }
            else
            {
                // note use of ternary operator (takes three arguments)
                return(userResponse == "YES" ? true : false);
            }
        }
예제 #3
0
        /// <summary>
        /// display the welcome screen
        /// </summary>

        public void DisplayWelcomeScreen()
        {
            StringBuilder sb = new StringBuilder();

            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("Written by Tyler Kirschke");
            ConsoleUtil.DisplayMessage("Northwestern Michigan College");
            ConsoleUtil.DisplayMessage("");

            sb.Clear();
            sb.AppendFormat("You are a traveling salesperson buying and selling widgets ");
            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 widgets.");
            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();
        }
예제 #4
0
        /// <summary>
        /// display current account details w/out continue prompt
        /// </summary>
        /// <param name="salesperson"></param>
        public void DisplayAccountDetails(Salesperson salesperson)
        {
            ConsoleUtil.DisplayMessage("First Name: " + salesperson.FirstName);
            ConsoleUtil.DisplayMessage("Last Name: " + salesperson.LastName);
            ConsoleUtil.DisplayMessage("Account ID: " + salesperson.AccountID);
            ConsoleUtil.DisplayMessage("Product Type: " + salesperson.Inventory.Type);
            ConsoleUtil.DisplayMessage("Current Inventory: " + salesperson.Inventory.NumberOfUnits);
            ConsoleUtil.DisplayMessage("Age:" + salesperson.Age);
            ConsoleUtil.DisplayMessage("Cities traveled:");

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

            if (salesperson.IsHockeyFan)
            {
                ConsoleUtil.DisplayMessage("Is a hockey fan, NICE.");
            }
            else
            {
                ConsoleUtil.DisplayMessage("Is not a hockey fan, LAME.");
            }
        }
예제 #5
0
        /// <summary>
        /// display backorder notification
        /// </summary>
        /// <param name="_salesperson"></param>
        /// <param name="Inventory"></param>

        public void DisplayBackOrderNotification(Salesperson _salesperson, int Inventory)
        {
            ConsoleUtil.DisplayMessage($"You have {Math.Abs(Inventory)} units on backorder. You should buy more.");
            ConsoleUtil.DisplayMessage("");
        }
예제 #6
0
        /// <summary>
        /// get the menu choice from the user
        /// </summary>

        public MenuOption DisplayGetUserMenuChoice()
        {
            MenuOption userMenuChoice = MenuOption.None;
            bool       usingMenu      = true;

            ConsoleUtil.HeaderText = "Main Menu";
            ConsoleUtil.DisplayReset();

            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. Setup Account" + Environment.NewLine +
                    "\t" + "2. Update Account Info" + Environment.NewLine +
                    "\t" + "3. Travel" + Environment.NewLine +
                    "\t" + "4. Display Cities" + Environment.NewLine +
                    "\t" + "5. Display Account Info" + Environment.NewLine +
                    "\t" + "6. Buy" + Environment.NewLine +
                    "\t" + "7. Sell" + Environment.NewLine +
                    "\t" + "8. Display Inventory" + Environment.NewLine +
                    "\t" + "9. Save Account Info" + Environment.NewLine +
                    "\t" + "0. Load 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.SetupAccount;
                    usingMenu      = false;
                    break;

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

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

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

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

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

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

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

                case '9':
                    userMenuChoice = MenuOption.SaveAccountInfo;
                    usingMenu      = false;
                    break;

                case '0':
                    userMenuChoice = MenuOption.LoadAccountInfo;
                    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);
        }
예제 #7
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();

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

            ConsoleUtil.DisplayPromptMessage("First Name: ");
            _salesperson.FirstName = UppercaseFirst(Console.ReadLine());
            ConsoleUtil.DisplayPromptMessage("Last Name: ");
            _salesperson.LastName = UppercaseFirst(Console.ReadLine());
            ConsoleUtil.DisplayPromptMessage("Account ID: ");
            _salesperson.AccountID = Console.ReadLine();
            if (!ConsoleValidator.TryGetIntegerFromUser(18, 100, 3, "Age", out int userInteger))
            {
                Console.WriteLine("Looks like you are having trouble with your age. Clearly you are old as dirt, setting age to 100.");
                _salesperson.Age = 100;
            }
            _salesperson.Age = userInteger;
            string userResponse = ConsoleValidator.GetYesNoFromUser(3, "Are you a hockey fan?", out bool maxAttemptsExceeded);

            if (maxAttemptsExceeded)
            {
                Console.WriteLine("Not valid answer. You must not be a hockey fan.");
            }
            if (userResponse == "yes")
            {
                _salesperson.IsHockeyFan = true;
            }
            else
            {
                _salesperson.IsHockeyFan = false;
            }

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

            //
            // list all product types
            //
            foreach (string productTypeName in Enum.GetNames(typeof(Product.ProductType)))
            {
                //
                // do not display the "NONE" enum value
                //
                if (productTypeName != Product.ProductType.None.ToString())
                {
                    ConsoleUtil.DisplayMessage(productTypeName);
                }
            }

            //
            // get product type, if invalid entry, set type to "None"
            //
            ConsoleUtil.DisplayMessage("");
            ConsoleUtil.DisplayPromptMessage("Enter the product type: ");
            Product.ProductType productType;
            if (Enum.TryParse <Product.ProductType>(UppercaseFirst(Console.ReadLine()), out productType))
            {
                _salesperson.Inventory.Type = productType;
            }
            else
            {
                _salesperson.Inventory.Type = Product.ProductType.None;
            }


            if (ConsoleValidator.TryGetIntegerFromUser(0, 100, 3, "units", out int numberOfUnits))
            {
                _salesperson.Inventory.AddProducts(numberOfUnits);
            }
            else
            {
                ConsoleUtil.DisplayMessage("You did not enter a valid number of units.");
                ConsoleUtil.DisplayMessage("We will set your intentory to 0");
            }

            _salesperson.Inventory.NumberOfUnits = numberOfUnits;

            ConsoleUtil.DisplayReset();
            ConsoleUtil.DisplayMessage("Your account is now setup");

            return(_salesperson);
        }
        /// <summary>
        /// helper method to get a valid integer from the user within a range
        /// </summary>
        /// <param name="minValue">inclusive minimum value</param>
        /// <param name="maxValue">inclusive maximum value</param>
        /// <param name="maxAttempts">maximum number of attempts</param>
        /// <param name="pluralName">plural name of item</param>
        /// <param name="validInput">indicates valid user input</param>
        /// <returns></returns>
        public static bool TryGetIntegerFromUser(int minValue, int maxValue, int maxAttempts, string pluralName, out int userInteger)
        {
            bool   validInput          = false;
            bool   maxAttemptsExceeded = false;
            string userResponse;
            string feedbackMessage = "";
            int    attempts        = 1;

            userInteger = 0;

            while (!validInput && !maxAttemptsExceeded)
            {
                //
                // more attempts available
                //
                if (attempts <= maxAttempts)
                {
                    ConsoleUtil.DisplayPromptMessage($"Enter the number, between {minValue} and {maxValue}, of {pluralName}:");
                    userResponse = Console.ReadLine();
                    ConsoleUtil.DisplayMessage("");

                    //
                    // input is an Integer
                    //
                    if (int.TryParse(userResponse, out userInteger))
                    {
                        //
                        // input is in range
                        //
                        if (userInteger >= minValue && userInteger <= maxValue)
                        {
                            validInput = true;
                        }
                        //
                        // input is not in range
                        //
                        else
                        {
                            feedbackMessage = $"The number {userInteger} is not in the specified range.";
                        }
                    }
                    //
                    // input is not an Integer
                    //
                    else
                    {
                        feedbackMessage = $"{userResponse} is not an integer.";
                    }

                    if (!validInput && attempts <= maxAttempts)
                    {
                        ConsoleUtil.DisplayMessage($"You entered: {userResponse}");
                        ConsoleUtil.DisplayMessage(feedbackMessage);

                        if (attempts < maxAttempts)
                        {
                            ConsoleUtil.DisplayMessage($"Please enter an integer between {minValue} and {maxValue}.");
                            ConsoleUtil.DisplayMessage("Press any key to try again.");
                            Console.ReadKey();
                        }
                        else
                        {
                            ConsoleUtil.DisplayMessage("It appears you have exceeded the maximum number of attempts allowed.");
                            ConsoleUtil.DisplayMessage("Press any key to continue.");
                            Console.ReadKey();
                        }

                        Console.Clear();
                    }
                    else
                    {
                        ConsoleUtil.DisplayMessage("");
                    }

                    attempts++;
                }
                else
                {
                    maxAttemptsExceeded = true;
                }
            }

            return(validInput);
        }
예제 #9
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();

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

            //
            // list all product types
            //
            foreach (string productTypeName in Enum.GetNames(typeof(Product.ProductType)))
            {
                //
                // do not display the "NONE" enum value
                //
                if (productTypeName != Product.ProductType.None.ToString())
                {
                    ConsoleUtil.DisplayMessage(productTypeName);
                }
            }

            //
            // get product type, if invalid entry, set type to "None"
            //
            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;
            }

            int numberOfUnits;

            //
            // get number of products in inventory
            //
            if (ConsoleValidator.TryGetIntegerFromUser(0, 100, 3, "products", out 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 is setup");

            DisplayContinuePrompt();

            return(salesperson);
        }
예제 #10
0
 private void DisplayAccountDetail(Salesperson salesperson)
 {
     ConsoleUtil.DisplayMessage("First Name: " + salesperson.FirstName);
     ConsoleUtil.DisplayMessage("Last Name: " + salesperson.LastName);
     ConsoleUtil.DisplayMessage("Account ID: " + salesperson.AccountID);
 }
예제 #11
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();

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

            // list all types of products available
            // Enum.GetNames retrieves an array of the names in ProductType
            foreach (string productName in Enum.GetNames(typeof(Product.ProductType)))
            {
                // do not display "None" product type
                if (productName != "None")
                {
                    ConsoleUtil.DisplayMessage(productName);
                }
            }

            // get product type from user, if input is invalid: product type will be set to "None"
            ConsoleUtil.DisplayMessage("");
            ConsoleUtil.DisplayPromptMessage("Enter product: ");

            // new variable for product type
            //Product.ProductType productType;
            if (Enum.TryParse <Product.ProductType>(UppercaseFirst(Console.ReadLine()), out Product.ProductType productType))
            {
                // set type of current stock to selected product type
                salesperson.CurrentStock.Type = productType;
            }
            else
            {
                // sets type of current stock to "none" product type
                salesperson.CurrentStock.Type = Product.ProductType.None;
            }

            // get number of products
            if (ConsoleValidator.TryGetIntegerFromUser(MINIMUM_BUYSELL_AMOUNT, MAXIMUM_BUYSELL_AMOUNT, MAXIMUM_ATTEMPTS, "products", out int numberOfUnits))
            {
                // add products to current stock
                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 0.");
                salesperson.CurrentStock.AddProducts(0);
                DisplayContinuePrompt();
            }

            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("Your account is setup");
            ConsoleUtil.DisplayMessage(numberOfUnits + " units of " + productType + " have been added to your inventory.");

            DisplayContinuePrompt();

            return(salesperson);
        }
예제 #12
0
        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(
                        "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);
        }
        // Display Account Edit screen
        public MenuOption DisplayGetAccountInfoToEdit()
        {
            MenuOption userMenuChoice = MenuOption.None;

            bool usingMenu = true;

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

                //
                // display the menu
                //
                ConsoleUtil.DisplayMessage("Please type the number of the account info you would like to edit:");
                ConsoleUtil.DisplayMessage("");
                Console.Write(
                    "\t" + "1. First Name" + Environment.NewLine +
                    "\t" + "2. Last Name" + Environment.NewLine +
                    "\t" + "3. Account ID" + Environment.NewLine +
                    "\t" + "4. Age" + Environment.NewLine +
                    "\t" + "5. Gender" + 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.EditFirstName;
                    usingMenu      = false;
                    break;

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

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

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

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

                case 'E':
                case 'e':
                    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);
        }