コード例 #1
0
        //validation method to prevent invalid integers
        private int DisplayGetIntegerInRange(int min, int max, string prompt)
        {
            int integer = 0;

            bool validAge = false;

            while (!validAge)
            {
                ConsoleUtil.DisplayPromptMessage(prompt);
                if (int.TryParse(Console.ReadLine(), out integer))
                {
                    if (integer > min && integer < max)
                    {
                        validAge = true;
                    }
                    else
                    {
                        Console.WriteLine("Thats not within the range! Try Again");
                        DisplayContinuePrompt();
                    }
                }
                else
                {
                    Console.WriteLine("That's not an integer!");
                    DisplayContinuePrompt();
                }
            }

            return(integer);
        }
コード例 #2
0
        /// <summary>
        /// get the number of widget units to sell from the user
        /// </summary>
        /// <returns>int number of units to buy</returns>
        public int DisplayGetNumberOfUnitsToSell()
        {
            int numberOfUnitsToSell = 0;

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

            ConsoleUtil.DisplayPromptMessage($"How many {_salesperson.Item.Type} do you want to sell? ");
            bool validResponse = int.TryParse(Console.ReadLine(), out numberOfUnitsToSell);

            while (!validResponse)
            {
                ConsoleUtil.DisplayMessage($"You didn't enter how many {_salesperson.Item.Type} you wanted to sell. Please try again.");
                ConsoleUtil.DisplayMessage("");

                ConsoleUtil.DisplayPromptMessage($"How many {_salesperson.Item.Type} do you want to sell? ");
                validResponse = int.TryParse(Console.ReadLine(), out numberOfUnitsToSell);
            }

            if (_salesperson.Item.NumberOfUnits < numberOfUnitsToSell)
            {
                ConsoleUtil.DisplayMessage($"You don't have enough {_salesperson.Item.Type} to sell! Please select fewer {_salesperson.Item.Type} to sell.");
                ConsoleUtil.DisplayMessage("");

                ConsoleUtil.DisplayPromptMessage($"How many {_salesperson.Item.Type} do you want to sell? ");
                validResponse = int.TryParse(Console.ReadLine(), out numberOfUnitsToSell);
            }

            DisplayContinuePrompt();

            return(numberOfUnitsToSell);
        }
コード例 #3
0
        /// <summary>
        /// get the next city to travel to from the user
        /// </summary>
        /// <returns>string City</returns>
        public string DisplayGetNextCity()
        {
            string nextCity = "";

            ConsoleUtil.HeaderText = "Next City of Travel";
            ConsoleUtil.DisplayReset();
            ConsoleUtil.DisplayPromptMessage("Enter the next city:");
            nextCity = Console.ReadLine();
            DisplayContinuePrompt();
            return(nextCity);
        }
コード例 #4
0
 /// <summary>
 /// get the number of product units to sell from the user
 /// </summary>
 /// <returns>int number of units to sell</returns>
 public int DisplayGetNumberOfUnitsToSell()
 {
     _salesperson.NumberOfUnitsToSell = 0;
     ConsoleUtil.HeaderText           = "Sell Inventory";
     ConsoleUtil.DisplayReset();
     ConsoleUtil.DisplayPromptMessage($"Enter the number of {_salesperson.ProductName} to sell:  ");
     _salesperson.NumberOfUnitsToSell = int.Parse(Console.ReadLine());
     ConsoleUtil.DisplayReset();
     ConsoleUtil.DisplayMessage(_salesperson.NumberOfUnitsToSell + $" {_salesperson.ProductName } have been subtracted from your inventory ");
     DisplayContinuePrompt();
     return(_salesperson.NumberOfUnitsToSell);
 }
コード例 #5
0
 /// <summary>
 /// get the number of product units to buy from the user
 /// </summary>
 /// <returns>int number of units to buy</returns>
 public int DisplayGetNumberOfUnitsToBuy()
 {
     _salesperson.NumberOfUnitsToAdd = 0;
     ConsoleUtil.HeaderText          = "Buy Inventory";
     ConsoleUtil.DisplayReset();
     ConsoleUtil.DisplayPromptMessage($"Enter the number of {_salesperson.ProductName} to buy:  ");
     _salesperson.NumberOfUnitsToAdd = int.Parse(Console.ReadLine());
     ConsoleUtil.DisplayReset();
     ConsoleUtil.DisplayMessage(_salesperson.NumberOfUnitsToAdd + $" {_salesperson.ProductName } have been added to your inventory ");
     DisplayContinuePrompt();
     return(_salesperson.NumberOfUnitsToAdd);
 }
コード例 #6
0
        /// <summary>
        /// get the next city to travel to from the user
        /// </summary>
        /// <returns>string City</returns>
        public string DisplayGetNextCity()
        {
            string nextCity = "";

            ConsoleUtil.HeaderText = "Next City of Travel";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayPromptMessage("Enter the city you wish to travel to: ");
            nextCity = Console.ReadLine();

            _salesperson.CitiesVisited.Add(nextCity);

            return(nextCity);
        }
コード例 #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 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();

            ConsoleUtil.DisplayPromptMessage("Enter the type of the item: ");
            Console.WriteLine();
            foreach (WidgetItemStock.WidgetType type in Enum.GetValues(typeof(WidgetItemStock.WidgetType)))
            {
                ConsoleUtil.DisplayMessage(type.ToString());
            }
            // complicated enum validation
            WidgetItemStock.WidgetType itemType;
            Enum.TryParse <WidgetItemStock.WidgetType>(Console.ReadLine(), out itemType);
            _salesperson.Item.Type = itemType;

            int numberOfItem;

            //int response;
            ConsoleUtil.DisplayPromptMessage($"Enter the number of {itemType} currently in stock: ");

            bool validResponse = int.TryParse(Console.ReadLine(), out numberOfItem);

            while (!validResponse)
            {
                ConsoleUtil.DisplayMessage("You didn't enter a number. Please try again.");
                Console.WriteLine();

                ConsoleUtil.DisplayPromptMessage($"Enter the number of {itemType} currently in stock: ");
                validResponse = int.TryParse(Console.ReadLine(), out numberOfItem);
            }

            _salesperson.Item.AddWidgets(numberOfItem);

            DisplayContinuePrompt();
        }
コード例 #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 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();

            //
            // TODO prompt the user to input all of the required account information
            //

            DisplayContinuePrompt();
        }
コード例 #9
0
        /// <summary>
        /// displays updating your account
        /// </summary>
        public void DisplayUpdateAccount()
        {
            ConsoleUtil.HeaderText = "Account Update";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("Update 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();

            DisplayContinuePrompt();
        }
コード例 #10
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 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();
     ConsoleUtil.DisplayPromptMessage("Enter your Last Name: ");
     _salesperson.LastName  = Console.ReadLine();
     _salesperson.Age       = DisplayGetIntegerInRange(1, 130, "Enter your Age: ");
     _salesperson.AccountID = DisplayGetIntegerInRange(1, 10000, "Enter your Account ID: ");
     ConsoleUtil.DisplayPromptMessage("Enter a Product: ");
     _salesperson.ProductName  = Console.ReadLine();
     _salesperson.ProductUnits = DisplayGetIntegerInRange(1, 10000, "Enter the number of Products: ");
     Console.WriteLine();
     DisplayContinuePrompt();
 }
コード例 #11
0
        /// <summary>
        /// get the number of widget units to buy from the user
        /// </summary>
        /// <returns>int number of units to buy</returns>
        public int DisplayGetNumberOfUnitsToBuy()
        {
            int numberOfUnitsToAdd = 0;

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

            ConsoleUtil.DisplayPromptMessage($"How many {_salesperson.Item.Type} do you want to buy? ");
            bool validResponse = int.TryParse(Console.ReadLine(), out numberOfUnitsToAdd);

            // validation loop, created by Velis
            while (!validResponse)
            {
                ConsoleUtil.DisplayMessage($"You didn't enter how many {_salesperson.Item.Type} you wanted to buy. Please try again.");
                ConsoleUtil.DisplayMessage("");

                ConsoleUtil.DisplayPromptMessage($"How many {_salesperson.Item.Type} do you want to buy? ");
                validResponse = int.TryParse(Console.ReadLine(), out numberOfUnitsToAdd);
            }

            return(numberOfUnitsToAdd);
        }