Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // Making a new instance of UI class
            UserInterface ui = new UserInterface();

            // Making a new instance of the Beverage class
            Beverage beverageList = new Beverage("39171", "1221 Cabernet Cuvee", "6 / 750 ml", 70.1m, "TRUE");

            // Makes an array to hold instances in Beverage class
            Beverage[] beverages = new Beverage[3942];

            // Making a new instance of the BeverageCollection class
            BeverageCollection bevCollection = new BeverageCollection();

            // Make instance of CSVProcessor
            CSVProcessor csvProcessor = new CSVProcessor();

            // Makes an array to hold instances in BeverageCollection class
            BeverageCollection[] beveragesCollection = new BeverageCollection[3942];

            // Get input from the user
            int choice = ui.UserInput();

            // While the choice they selected is not 5, continue to do work
            while (choice != 5)
            {
                // Load the list
                if (choice == 1)
                {
                    // Make a string for the path to the csv file
                    string pathToCsv = "../../../datafiles/beverage_list.csv"; // starts at bin debug. Each .. goes back one folder

                    // Call the ImportCSV method sending over the path and the array to store the read in records to.
                    csvProcessor.ImportCsv(pathToCsv, beverages);
                }
                // Print out list
                if (choice == 2)
                {
                    // Create a string that can be concated t
                    string outputString = "";

                    //// Print out the beverages in an array
                    foreach (Beverage beverage in beverages)
                    {
                        // Check to ensure there is a beverage object to be able to access properties on
                        if (beverage != null)
                        {
                            outputString += beverage.ToString() + Environment.NewLine;
                        }
                    }

                    // Call UI method to output list
                    ui.OptionTwo(outputString);

                    Console.WriteLine(); // Empty space
                }
                // Search for beverage
                if (choice == 3)
                {
                    // Call the ImportCSV method sending over the array to search
                    csvProcessor.Search(beverages);

                    Console.WriteLine(); // Empty space
                }
                // Add a new beverage
                if (choice == 4)
                {
                    Console.WriteLine(); // Empty space
                }
                // Re-display for input
                choice = ui.UserInput();
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // Set Console Window Size
            Console.BufferHeight = Int16.MaxValue - 1;
            Console.WindowHeight = 40;
            Console.WindowWidth  = 120;

            // Set a constant for the size of the collection
            const int beverageCollectionSize = 4000;

            // Set a constant for the path to the CSV File
            const string pathToCSVFile = "../../../datafiles/beverage_list.csv";

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

            // Create an instance of the BeverageCollection class
            BeverageCollection beverageCollection = new BeverageCollection(beverageCollectionSize);

            // Create an instance of the CSVProcessor class
            CSVProcessor csvProcessor = new CSVProcessor();

            // 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 != 5)
            {
                switch (choice)
                {
                case 1:
                    // Load the CSV File
                    bool success = csvProcessor.ImportCSV(beverageCollection, pathToCSVFile);
                    if (success)
                    {
                        // Display Success Message
                        userInterface.DisplayImportSuccess();
                    }
                    else
                    {
                        // Display Fail Message
                        userInterface.DisplayImportError();
                    }
                    break;

                case 2:
                    // Print Entire List Of Items
                    string allItemsString = beverageCollection.ToString();
                    if (!String.IsNullOrWhiteSpace(allItemsString))
                    {
                        // Display all of the items
                        userInterface.DisplayAllItems(allItemsString);
                    }
                    else
                    {
                        // Display error message for all items
                        userInterface.DisplayAllItemsError();
                    }
                    break;

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

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

                // Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Main program entry point.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            const int sodaStandSize = 4000;
            string    pathToCSV     = "../../../datafiles/beverage_list.csv";
            string    menuChoice    = null;

            UserInterface      aMenu        = new UserInterface();
            BeverageCollection sodaStand    = new BeverageCollection(sodaStandSize);
            CSVProcessor       csvProcessor = new CSVProcessor();

            DisplayMenu();

            /// Displays the menu and calls HandleInput to deal with the user's response stored in the variable menuChoice.
            void DisplayMenu()
            {
                Console.Clear();
                Console.Write(aMenu.DisplayMenu());
                Console.Write("\n\n\t\t\t\t");
                menuChoice = Console.ReadLine();
                HandleInput(menuChoice);
            }

            /// Handles the user's input via a switch. Each menu function is encapsulated within each case.
            /// The work done on the user's choice is done in other classes; the output is handled by the
            /// UserInterface class.
            ///

            void HandleInput(string userSelection)
            {
                userSelection = userSelection.ToUpper();
                switch (userSelection)
                {
                // Loads the beverage list. Note that this is the only location we call ImportCSV() from.
                case "L":
                    Console.WriteLine(aMenu.LoadListMessage());
                    bool loadedSuccessfully = csvProcessor.ImportCSV(pathToCSV, sodaStand);
                    if (loadedSuccessfully)
                    {
                        Console.Write(aMenu.LoadSuccess());
                        aMenu.Pause();
                    }
                    else
                    {
                        // We don't want to try to reload the list again so we use the public boolean variable
                        // that is set from within the class. We use this in any situation where we don't want
                        // the user to do a thing until the list is loaded (add, search...).
                        if (csvProcessor.listIsLoaded)
                        {
                            Console.Write(aMenu.AlreadyLoaded());
                            aMenu.Pause();
                        }

                        else
                        {
                            Console.Write(aMenu.LoadFailure());
                        }
                        aMenu.Pause();
                    }

                    DisplayMenu();
                    break;

                case "P":
                    // Print the list. Burp if the list isn't loaded yet.
                    aMenu.PrintListMessage();
                    if (!csvProcessor.listIsLoaded)
                    {
                        Console.Write(aMenu.NothingToPrint());
                        aMenu.Pause();
                    }
                    else
                    {
                        string[] allBeverages = sodaStand.PrintTheBeveragesInventory();
                        aMenu.PrintBeverageList(allBeverages);
                    }
                    aMenu.Pause();
                    DisplayMenu();

                    break;

                case "S":
                    // Search the list. Burp if the list isn't loaded yet.
                    aMenu.SearchListMessage();
                    if (!csvProcessor.listIsLoaded)
                    {
                        Console.Write(aMenu.NothingToSearch());
                        aMenu.Pause();
                    }

                    else
                    {
                        Console.Write(aMenu.SearchBeverageList(sodaStand));
                    }
                    aMenu.Pause();
                    DisplayMenu();
                    break;

                case "A":
                    // Add to the list. Burp if the list isn't loaded yet.
                    if (!csvProcessor.listIsLoaded)
                    {
                        Console.Write(aMenu.CannotAddUntilLoaded());
                        aMenu.Pause();
                    }
                    else
                    {
                        string[] beverageToAdd = aMenu.AddABeverage();
                        if (sodaStand.FindBeverageById(beverageToAdd[0]) == null)
                        {
                            sodaStand.AddABeverage(beverageToAdd[0], beverageToAdd[1], beverageToAdd[2], decimal.Parse(beverageToAdd[3]), bool.Parse(beverageToAdd[4]));
                            Console.Write(aMenu.BeverageAdded());
                            aMenu.Pause();
                        }
                        else
                        {
                            Console.Write(aMenu.BeverageExists());
                            aMenu.Pause();
                        }
                    }
                    aMenu.Pause();
                    DisplayMenu();
                    break;

                // Quit the program. Quits regardless of whether the list is loaded. Never burps.
                case "Q":
                    Console.WriteLine(aMenu.QuitProgramMessage());
                    aMenu.Pause();
                    Environment.Exit(0);
                    break;

                // The default option is invoked for any choices not on the menu. This may be an invalid
                // entry or a blank entry. In either case, error is shown in red and the menu is simply redrawn.
                default:
                    aMenu.InvalidOptionMessage();
                    aMenu.Pause();
                    DisplayMenu();
                    break;
                }
            }
        }