Exemplo n.º 1
0
        //END OF MAIN --

        private static int GetItemNumberFromUser(Register register, bool clearConsole)
        {
            Console.WriteLine($"Menu: Choose an Item # or [: + search term] to search"); //ask user to choose an item number from the list
            Menu.DisplayMainMenu(register, clearConsole);                                //displays the list of items in the register
            var userItemNumber = -1;

            do
            {
                var userItemAsString = Console.ReadLine(); //get users input as a string
                if (userItemAsString.StartsWith(":"))      //parses out user input, if it starts with a : then send the string to the search function instead
                {
                    register.SearchForProduct(userItemAsString.Substring(1), register);
                }
                else if (userItemAsString.StartsWith("~"))
                {
                    register.WriteToInventoryProductList(register.filePath, userItemAsString);
                    break;
                }
                else // otherwise, it must be a integer...try parsing it to an int, and hopefully  dont break anything...
                {
                    if (ValidateInput.GetIsInteger(userItemAsString))  //check, is it an integer??  yes?
                    {
                        userItemNumber = int.Parse(userItemAsString) - 1; //parse that to an integer then
                        //move to validation class?
                        break;                                            //no need to check anything else, leave the if statement
                    }
                    else
                    {
                        Console.WriteLine("Please input a valid integer.");  //otherwise, you done messed up sir, let them know.
                    }
                }
            } while (true);         //keep asking until they get really annoyed or they put in the correct input

            return(userItemNumber); //should never, ever get here, but the compiler seems to think I need to  return  something  just  in case.
        }
Exemplo n.º 2
0
        public static int GetUserItemQuantity()
        {
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.WriteLine("Enter Quantity:");
            var takeUserQuantity = Console.ReadLine();

            if (ValidateInput.GetIsInteger(takeUserQuantity))
            {
                return(int.Parse(takeUserQuantity));
            }
            Console.WriteLine("Something went wrong");
            return(GetUserItemQuantity());
        }