示例#1
0
        static void Main(string[] args)
        {
            // Set Console Window Size
            Console.BufferHeight = Int16.MaxValue - 1;
            Console.WindowHeight = 40;
            Console.WindowWidth  = 120;

            // Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            // Create an instance of the BeverageCollection class
            BeverageRepository beverageRepository = new BeverageRepository();

            // Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            // Display the Menu and get the response. Store the response in the choice integer
            // This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            // While the choice is not exit program
            while (choice != 6)
            {
                switch (choice)
                {
                case 1:
                    // PRINT THE ENTIRE LIST OF BEVERAGES

                    // Heading
                    userInterface.DisplayPrintListHeading();
                    // Call method to print the list
                    beverageRepository.PrintList();

                    break;

                case 2:
                    // SEARCH FOR BEVERAGE BY ID
                    string searchQuery = userInterface.GetSearchQuery();
                    //  Finds beverage and sets it to a string to test
                    string itemInformation = beverageRepository.FindById(searchQuery);
                    // Tests if it was found or not
                    if (itemInformation != null)
                    {
                        userInterface.DisplayItemFound(itemInformation);
                    }

                    break;

                case 3:
                    // ADD A NEW BEVERAGE TO THE DATABASE

                    // Create a new instance of Beverage
                    Beverage newBeverageToAdd = new Beverage();

                    // Gathers information for the beverage
                    newBeverageToAdd.id     = userInterface.GetNewIDInformation();
                    newBeverageToAdd.name   = userInterface.GetNewNameInformation();
                    newBeverageToAdd.pack   = userInterface.GetNewPackInformation();
                    newBeverageToAdd.price  = userInterface.GetNewPriceInformation();
                    newBeverageToAdd.active = userInterface.GetNewActiveInformation();

                    // Calls method and passes in the new beverage information
                    beverageRepository.AddNewBeverage(newBeverageToAdd.id,
                                                      newBeverageToAdd.name,
                                                      newBeverageToAdd.pack,
                                                      newBeverageToAdd.price,
                                                      newBeverageToAdd.active, newBeverageToAdd);
                    break;

                case 4:
                    // UPDATE THE BEVERAGE THAT WAS JUST ADDED
                    string value = userInterface.GetUpdateBeverageInformation();

                    // Calls method to update passing in the value of the previous method called
                    beverageRepository.UpdateBeverage(value);

                    break;

                case 5:
                    // DELETE A BEVERAGE

                    // User picks what droid to delete
                    string deletedValue = userInterface.GetDeleteBeverageInformation();

                    // Deletes beverage by calling method
                    beverageRepository.DeleteBeverage(deletedValue);
                    break;
                }

                // Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            // Set Console Window Size
            Console.BufferHeight = Int16.MaxValue - 1;
            Console.WindowHeight = 40;
            Console.WindowWidth  = 120;

            // Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            // Create an instance of the BeverageCollection class
            BeverageRepository _beverageRepository = new BeverageRepository();

            // Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            // Display the Menu and get the response. Store the response in the choice integer
            // This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            // While the choice is not exit program
            while (choice != 6)
            {
                switch (choice)
                {
                case 1:
                    // Display all of the items in the Database
                    userInterface.DisplayAllItems();
                    break;

                case 2:
                    // Make a new beverage in order to get the user information
                    Beverage beverageToAdd = new Beverage();
                    // Get the user information for the new beverage
                    userInterface.GetNewItemInformation(beverageToAdd);
                    // Adds the new beverage to the database based on the information submitted from the user

                    break;

                case 3:
                    // Make a new instance of beverage to hold the user information
                    Beverage beverageToUpdate = new Beverage();
                    // Get the information from the user about what they want to change
                    userInterface.UpdateItemInformation(beverageToUpdate);
                    // Change the beverage if it is found in the database

                    break;

                case 4:
                    // Gets the ID from the User of the beverage they want to search for
                    string searchQuery = userInterface.GetSearchQuery();
                    // Finds the beverage with the ID from the user and prints it out
                    userInterface.DisplayItemFound(searchQuery);
                    break;

                case 5:
                    // Gets the ID of what the user wants to delete
                    string searchToDelete = userInterface.GetSearchQuery();
                    // Uses the ID to find the beverage and delete it from the database
                    userInterface.DeleteBeverage(searchToDelete);
                    break;
                }

                // Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            // Set Console Window Size
            Console.BufferHeight = Int16.MaxValue - 1;
            Console.WindowHeight = 40;
            Console.WindowWidth  = 120;

            // Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            // Create an instance of the BeverageRepository class
            BeverageRepository beverageRepository = new BeverageRepository();

            // Display the Welcome Message to the user
            userInterface.DisplayWelcomeGreeting();

            // Display the Menu and get the response. Store the response in the choice integer
            // This is the 'primer' run of displaying and getting.
            int choice = userInterface.DisplayMenuAndGetResponse();

            // While the choice is not exit program
            while (choice != 6)
            {
                switch (choice)
                {
                case 1:
                    // Print Entire List Of Items
                    userInterface.DisplayAllItems();
                    break;

                case 2:
                    // Search For An Item
                    string searchQuery     = userInterface.GetSearchQuery();
                    string itemInformation = beverageRepository.FindById(searchQuery);
                    if (itemInformation != null)
                    {
                        userInterface.DisplayItemFound(itemInformation);
                    }
                    else
                    {
                        userInterface.DisplayItemFoundError();
                    }
                    break;

                case 3:
                    // Add A New Item To The List
                    string[] newItemInformation = userInterface.GetNewItemInformation();
                    if (beverageRepository.FindById(newItemInformation[0]) == null)
                    {
                        beverageRepository.AddNewItem(
                            newItemInformation[0],
                            newItemInformation[1],
                            newItemInformation[2],
                            decimal.Parse(newItemInformation[3]),
                            (newItemInformation[4] == "True")
                            );
                        userInterface.DisplayAddWineItemSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemAlreadyExistsError();
                    }
                    break;

                case 4:
                    // Update an item from the list
                    string[] updateItemInformation = userInterface.UpdateItemInformation();
                    if (beverageRepository.FindById(updateItemInformation[0]) != null)
                    {
                        beverageRepository.UpdateItem(
                            updateItemInformation[0],
                            updateItemInformation[1],
                            updateItemInformation[2],
                            decimal.Parse(updateItemInformation[3]),
                            (updateItemInformation[4] == "True")
                            );
                        userInterface.DisplayUpdateItemSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemFoundError();
                    }
                    break;

                case 5:
                    // Delete an item from the list
                    userInterface.DisplayDeleteItem();
                    string input = Console.ReadLine();
                    if (beverageRepository.FindById(input) != null)
                    {
                        beverageRepository.DeleteItem(input);
                        userInterface.DisplayDeleteItemSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemFoundError();
                    }
                    break;
                }

                // Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }