static void Main(string[] args)
        {
            WineItemCollection wineItemCollection = new WineItemCollection(); //Create a WineItemCollection object, this will be passed to and interacted with in multiple classes
            UserInterface UI = new UserInterface(wineItemCollection); //Create UI Object

            UI.loadWineList();
            UI.showMenu();
        }
示例#2
0
        static void Main(string[] args)
        {
            // this is the main

            // this starts the UserInterface class
            Console.Clear();
            UserInterface load = new UserInterface();
            load.MainMenu();
        }
示例#3
0
        static void Main(string[] args)
        {
            UserInterface userInterface = new UserInterface();
            CSVProcessor csvProcessor = new CSVProcessor();
            //WineItemCollection WineitemCollection = new WineItemCollection(CSVProcessor(string[400] WineArray));

            userInterface.MenuOptions();    //Displays user options
            userInterface.Choices();        //Allows user to select an option
        }
        static void Main(string[] args)
        {
            //creates a WineItemCollection object
            WineItemCollection wineItemCollection = new WineItemCollection();

            //creates a UserInterface object
            UserInterface userInterface = new UserInterface(wineItemCollection);

            //load the wine list upon startup, then display the UI menu
            userInterface.loadList();
            userInterface.displayTextMenu();
        }
示例#5
0
        static void Main(string[] args)
        {
            int windowheight = 60;
            int windowwidth = 160;

            UserInterface MainMenu = new UserInterface();

            Console.BufferHeight = 8000;
            Console.BufferWidth = 100;
            Console.SetWindowSize(windowwidth, windowheight);

            MainMenu.MainMenu();
        }
示例#6
0
        static void Main(string[] args)
        {                        
            bool beenThere = true;          //Boolean used to tell whether or not the csv file has been loaded

            WineItemCollection wineItemCollection = new WineItemCollection();             //Instantiate the other classes
            UserInterface ui = new UserInterface();
            int choice = ui.Interact();                 //Loads Menu
            while (choice != 5)                            //Validates Whether or not the user chose to exit
            {
                if(choice == 1)                          //Choice to load CSV file
                {
                    if(beenThere == true)                 //Validates whether or not it has been loaded
                    {
                        wineItemCollection.ProcessCSV();                     //Sends to record array so it can be added on to the array
                    }
                    else
                    {
                        ui.AlreadyDidThat();                               //Tells user that the file has already been loaded
                    }
                    beenThere = false;                                       //Tells program file has already been loaded
                }
                if (choice == 2)                                          //Prints the entire list
                {                   
                        string bigListString = wineItemCollection.PrintEntireList();                       //Gathers all data from the array class
                        ui.PrintAllOutput(bigListString);                                                   //Prints data into the console
                }
                if (choice == 3)                                                              //Search for an item by its ID number
                {
                    string searchIDNumber = ui.SearchForRecord();                             //Gets the ID number from the user
                    string SearchedWineItem = wineItemCollection.SearchForWineItem(searchIDNumber);        //Gets record(or lack thereof) from the array class
                    if(SearchedWineItem == null)                      //Validates whether the record was found or not
                    {
                        ui.WrongSearch(searchIDNumber);              //Output of incorrect ID number
                    }
                    else
                    {
                        ui.SuccessfulSearch(SearchedWineItem);          //Output of correct record
                    }
                }
                if (choice == 4)                                       //Adds a record to the array input by the user
                {
                    WineItem AddedWineItem = ui.InputRecord();           //Gets the record input from the user
                    wineItemCollection.AddRecord(AddedWineItem);         //Adds Record to the array
                }
                choice = ui.Interact();                                    //Resets loop for options until the user inputs the exit command
            }

            Console.WriteLine("Thank You For Using Our Program");             //Nice message to the user, may comment out later
            Console.ReadLine();                                               //Ends the program
        }
        /// <summary>
        /// Base Constructor to run program.
        /// </summary>
        public RunProgram()
        {
            wineItem = new WineItem();
            runProgramBool = true;
            processFiles = new CSVProcessor();
            loadListSizeInt = processFiles.LoadListSize;
            wineItemCollection = new WineItemCollection(loadListSizeInt);
            mainMenu = new UserInterface();

            wineItem = new WineItem();
            while (runProgramBool)
            {
                mainMenu.PrintUserMenu();
                UserSelection();
            }
        }
        static void Main(string[] args)
        {
            //Make a Menu object of UserInterface class
            UserInterface Menu = new UserInterface();

            //make a WineFile object of CSVProecessor class
            CSVProcessor WineFile = new CSVProcessor();

            //instantiate a list object of the WineItem class
            List<WineItem> wineList = new List<WineItem>();

            // call the DisplayMainMenu method from Menu object, passing WineFile object and wineList list object
            Menu.DisplayMainMenu(WineFile, wineList);

            // call the DisplaySubMenu method from Menu object, passing wineList list object
            Menu.DisplaySubMenu(wineList);
        }
示例#9
0
        static void Main(string[] args)
        {
            //Variables for windows size
            int windowheight = 60;
            int windowwidth = 160;

            //Create a new instance of the UserInterface class
            UserInterface MainMenu = new UserInterface();

            //Set window height and width large enough to see wine list
            Console.BufferHeight = 8000;
            Console.BufferWidth = 100;
            Console.SetWindowSize(windowwidth, windowheight);

            //Call MainMenu method from UI class to begin program
            MainMenu.MainMenu();
        }
示例#10
0
        static void Main(string[] args)
        {
            // Call UserInterface class to build menu and recieve user input.
            UserInterface newUser = new UserInterface();
            String input = Console.ReadLine();

            int choice = newUser.RecieveInput();

            // Call WineItemCollection class to create array.
            WineItemCollection wineItemCollection = new WineItemCollection();

            // While loop build to process user input.
            while (choice != 5)
            {
                if (choice == 1) // Option 1 loads the array.
                {
                    wineItemCollection.Collection();
                    Console.WriteLine();
                    Console.WriteLine("Done.");
                }
                else if (choice == 2) // Option 2 prints the array.
                {
                    wineItemCollection.Print();
                }
                else if (choice == 3) // Option 3 allows user to search for a specific
                {                    // Item in the array.
                    Console.WriteLine("Enter the item you wish to search for:");
                    wineItemCollection.SearchList();
                }
                else if (choice == 4) // Option 4 allows the user to add an item to the
                {                    // the array.
                    Console.WriteLine("Enter the item you wish to add:");
                    wineItemCollection.AddItem();
                }
                else if (choice == 5) // Option 5 stops the array, and allows the
                {                    // program to close.
                    Console.WriteLine("Have a nice day.");
                }
                input = Console.ReadLine();
                choice = newUser.RecieveInput();
            }

        }
示例#11
0
        static void Main(string[] args)
        {
            WineItemCollection wineItemCollection = new WineItemCollection();    //instanciate WineItemCollection class

            CSVProcessor csvProcessor = new CSVProcessor();     //instanciate CSVProcessor class

            csvProcessor.ImportCSV("../../../datafiles/WineList.csv", wineItemCollection.WineItems);   //determine path of the CSV file

            UserInterface ui = new UserInterface();     //instanciate UserInterface class

            int choice = ui.FilePrompt();   //integer to determine which number the user chooses when the interface gives its prompt
            while (choice.ToString() != "4")    //runs intil the user chooses 4, which closes the program
            {
                switch (choice) //switch statement to determine what course of action to take, depending on how to user responds to the interface
                {
                    case 1:                                         //case 1 prints the entire wine array
                        wineItemCollection.WineItemsProcessed = 0;  //resets the integer so it won't accumulate with itself if the user prints the wine list more than once
                        wineItemCollection.PrintWineList();         //prints the wine list
                        Console.WriteLine();                        //inputs a blank line
                        choice = ui.FilePrompt();                   //reprompts the user to select an action from the interface
                        break;
                    case 2:                                     //case 2 allows the user to search for a wine by its ID
                        wineItemCollection.SearchWineList();    //method to search the entire wine list
                        Console.WriteLine();                    //inputs a blank line
                        choice = ui.FilePrompt();               //reprompts the user to select an action from the interface
                        break;
                    case 3:
                        wineItemCollection.AddWineToList();
                        Console.WriteLine();
                        choice = ui.FilePrompt();
                        break;
                    default:                                                        //default case that will only run if the user chooses an invalid response to the interface
                        Console.WriteLine("Error. Please select a valid option.");  //the user is told their response is invalid
                        Console.WriteLine();                                        //inputs a blank line
                        choice = ui.FilePrompt();                                   //reprompts the user to select an action from the interface
                        break;
                }
            }
        }
示例#12
0
        static void Main(string[] args)
        {
            //Expands the console for easier viewing
            Console.SetWindowSize(150, 40);

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

            //Create an instance of the wine database
            BeverageJAckermanEntities beverageEntities = new BeverageJAckermanEntities();

            //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 (choice != 6)
            {
                beverageEntities.SaveChanges();
                switch (choice)
                {
                    case 1:
                        //Print Entire List Of Items
                        userInterface.DisplayAllItems(beverageEntities);
                        break;

                    case 2:
                        //Search For An Item
                        string searchQuery = userInterface.GetSearchQuery();
                        Beverage foundWine = beverageEntities.Beverages.Find(searchQuery);
                        if (foundWine != null)
                        {
                            Console.WriteLine("");
                            Console.WriteLine("");
                            Console.WriteLine("Here is the wine with that ID:");
                            Console.WriteLine(foundWine.id + " " + foundWine.name + " " + foundWine.pack + " " + foundWine.price);
                        }
                        else
                        {
                            Console.WriteLine("Sorry, no wine with that ID could be found. the ID you entered may be incorrect or does not exist in the database.");
                        }

                        break;

                    case 3:
                        //Add A New Item To The List
                        string ID;
                        string Name;
                        decimal Price;
                        string Pack;

                        //Instead of passing the values to the method, we take them out of the method after it's finished
                        userInterface.GetNewItemInformation(out ID, out Name, out Price, out Pack);

                        bool WineAddedBool = false;

                        while (WineAddedBool == false)
                        {
                            //Creates an instance of beverage that will be used to see if the ID the user wants to use already exists
                            Beverage IDCheck = beverageEntities.Beverages.Find(ID);

                            if (IDCheck == null)
                            {
                                //Create an instance of beverage to eventually add to the database
                                Beverage newWine = new Beverage();

                                newWine.id = ID;
                                newWine.name = Name;
                                newWine.pack = Pack;
                                newWine.price = Price;

                                beverageEntities.Beverages.Add(newWine);
                                WineAddedBool = true;
                            }
                            else
                            {
                                Console.WriteLine("Sorry, a wine with this ID already exists. Would you like to enter a new ID?");
                                Console.WriteLine("y/n?");
                                string input = "nothing";
                                while (input != "y")
                                {
                                    input = Console.ReadLine();
                                    if (input == "y")
                                    {
                                        ID = userInterface.GetNewID();
                                    }
                                    else if (input == "n")
                                    {
                                        return;
                                    }
                                    else
                                    {
                                        Console.WriteLine("Sorry, you entered something other than a y or an n");
                                    }
                                }

                            }
                        }

                        break;

                    case 4:
                        //Delete an item from the list
                        string IDToDelete = userInterface.GetDeleteQuery();
                        Beverage deleteWine = beverageEntities.Beverages.Find(IDToDelete);

                        if(deleteWine != null)
                        {
                            beverageEntities.Beverages.Remove(deleteWine);
                            userInterface.DisplayDeleteSuccess();
                        }
                        else
                        {
                            Console.WriteLine("Error, the ID you entered does not corrospond to any Wine currently in the database.");
                        }
                        break;
                    case 5:
                        //Update an item from the database
                        string IDToUpdate = userInterface.GetUpdateQuery();
                        Beverage updateBeverage = beverageEntities.Beverages.Find(IDToUpdate);

                        if(updateBeverage != null)
                        {
                            Console.WriteLine("Would you like to change the ID of the wine?");
                            Console.WriteLine("y/n?");
                            string userInput = Console.ReadLine();
                            if(userInput == "y")
                            {
                                Console.WriteLine("What is the new ID you would like to assign to the wine?");

                                userInput = Console.ReadLine();

                                updateBeverage.id = userInput;
                            }
                            Console.WriteLine("Would you like to change the name of the wine?");
                            Console.WriteLine("y/n?");
                            userInput = Console.ReadLine();
                            if (userInput == "y")
                            {
                                Console.WriteLine("What is the new name you would like to assign to the wine?");

                                userInput = Console.ReadLine();

                                updateBeverage.name = userInput;
                            }
                            Console.WriteLine("Would you like to change the price of the wine?");
                            Console.WriteLine("y/n?");
                            userInput = Console.ReadLine();
                            if (userInput == "y")
                            {
                                Console.WriteLine("What is the new price you would like to assign to the wine?");

                                userInput = Console.ReadLine();

                                updateBeverage.price = decimal.Parse(userInput);
                            }
                            Console.WriteLine("Would you like to change the pack of the wine?");
                            Console.WriteLine("y/n?");
                            userInput = Console.ReadLine();
                            if (userInput == "y")
                            {
                                Console.WriteLine("What is the new pack you would like to assign to the wine?");

                                userInput = Console.ReadLine();

                                updateBeverage.pack = userInput;
                            }

                            userInterface.DisplayUpdateSuccess();
                        }
                        else
                        {
                            userInterface.DisplayUpdateFailure();
                        }
                        break;
                    case 6:

                        break;
                }

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

            beverageEntities.SaveChanges();
        }
示例#13
0
        //Establishes a StreamReader, Random Number, UserInterface.
        //Establishes the WineItem & WineItemCollection class arrays bases on the size of the input file.
        //Reads the input file into the WineItem array.
        //Directs the program based on user input.
        static void Main(string[] args)
        {
            StreamReader  wineList     = new StreamReader("../../../datafiles/WineList.csv");
            Random        randomNumber = new Random();
            UserInterface ui           = new UserInterface();

            Int32 arrayCount      = CSVProcessor.Processor(wineList);
            Int32 addToArrayCount = arrayCount;

            WineItem[]           wineItems   = new WineItem[arrayCount + 5];
            WineItemCollection[] collections = new WineItemCollection[arrayCount + 5];
            CSVProcessor.ReadFile(wineItems, wineList);

            Int32 selection1_Int32 = 0;

            //While the user has not chosen to exit the program.
            while (selection1_Int32 != 5)
            {
                selection1_Int32 = ui.InputMenu1();
                String output;

                switch (selection1_Int32)
                {
                //Displays the output as found in the input file.
                //This will display the array in a sorted order if it has already been sorted (if choice 2 or 3 has already been selected).
                case 1:
                {
                    output = WineItem.CreateString(wineItems);
                    ui.PrintAllOutput(output);
                    break;
                }

                //Displays the output in ascending or descending order with item location.
                case 2:
                {
                    Int32 selection2_Int32 = 0;
                    selection2_Int32 = ui.InputMenu2();
                    WineItemCollection.SetLocation(wineItems, collections, randomNumber);
                    output = WineItem.CreateLongString(wineItems, collections, selection2_Int32);
                    ui.PrintAllOutput(output);
                    selection2_Int32 = 0;
                    break;
                }

                //Prompts the user for input and searches the file for matching items.
                //Prompts the user for a search method as well.
                //Dispays a message for successful and unsuccessful searches.
                case 3:
                {
                    Int32  foundLocation    = -1;
                    String temp             = ui.SearchId();
                    Int32  selection3_Int32 = ui.InputMenu3();
                    foundLocation = WineItem.SearchType(wineItems, temp, selection3_Int32, arrayCount);
                    if (foundLocation == -1)
                    {
                        ui.NotFound(temp);
                    }
                    break;
                }

                //Allows the user to add items to the wine directory (up to 5 items).
                case 4:
                {
                    addToArrayCount = ui.UserAddWine(wineItems, addToArrayCount);
                    //addToArrayCount++;
                    break;
                }

                //Exit loop selection
                case 5:
                {
                    //Do Nothing - proceed to close the program.
                    break;
                }
                }
            }
        }
        /// <summary>
        /// Method to search any of the Bevarage properties for the data specified by the user
        /// and then delete those items if the user specifed deletion.
        /// </summary>
        /// <param name="searchFor">string</param>
        /// <param name="propertyName">string</param>
        /// <param name="delete">bool</param>
        /// <returns>string</returns>
        public string SearchByAndPossiblyDelete(string searchFor, string propertyName, bool delete)
        {
            try
            {
                //Open the database
                BeverageJMartinEntities beveageEntities = new BeverageJMartinEntities();
                //Create an empty list to hold the Beverages
                List <Beverage> queryBeverages = null;

                //Bool of if anything is found in the search starts out as false
                bool found = false;
                //Create the string to hold the found list
                string listString = "*************************************************************************************************" + Environment.NewLine;
                //From the property name create a search to be done
                switch (propertyName)
                {
                case nameof(Beverage.id):
                    queryBeverages = beveageEntities.Beverages.Where(
                        bev => bev.id.ToLower() == searchFor.ToLower()
                        ).ToList();
                    break;

                case nameof(Beverage.name):
                    queryBeverages = beveageEntities.Beverages.Where(
                        bev => bev.name.ToLower().Contains(searchFor.ToLower())
                        ).ToList();
                    break;

                case nameof(Beverage.pack):
                    queryBeverages = beveageEntities.Beverages.Where(
                        bev => bev.pack.ToLower().Contains(searchFor.ToLower())
                        ).ToList();
                    break;

                case nameof(Beverage.price):
                    decimal searchForDec = 0;
                    //create a decimal value from the string value for the search
                    if (Decimal.TryParse(searchFor, out searchForDec))
                    {
                        queryBeverages = beveageEntities.Beverages.Where(
                            bev => bev.price == searchForDec
                            ).ToList();
                    }
                    break;

                case nameof(Beverage.active):
                    bool tempBool;
                    //Create a bool value from the string value to be used for the search
                    if (searchFor == "True")
                    {
                        tempBool = true;
                    }
                    else
                    {
                        tempBool = false;
                    }
                    queryBeverages = beveageEntities.Beverages.Where(
                        bev => bev.active == tempBool
                        ).ToList();
                    break;
                }

                //Find out if anything was found in the search
                if (queryBeverages != null)
                {
                    //As something was found, return the formated beverage information for each beverage found
                    //and make the found bool true.
                    foreach (Beverage beverage in queryBeverages)
                    {
                        listString += FormatBeverageSting(beverage) + Environment.NewLine;
                        found       = true;
                    }
                }
                if (!found)
                {
                    //As nothing was found return searched for term was not found.
                    listString += searchFor + " was not found." + Environment.NewLine;
                }
                else
                {
                    //if somthing was found and you want to delete the items ask to confirm than
                    //delete the items.
                    if (delete)
                    {
                        //Make an instance of UserInterface
                        UserInterface ui = new UserInterface();
                        //Output to the user the list of items found
                        ui.OutputAString(listString);
                        //Find out if the user is sure to delete the list of items found.
                        if (ui.AreYouSure())
                        {
                            //Call the method to delete the list an inform the user if it was deleted or not.
                            if (DeleteItem(queryBeverages))
                            {
                                listString += Environment.NewLine + "The list was deleted" + Environment.NewLine;
                            }
                            else
                            {
                                listString += Environment.NewLine + "The list was NOT deleted do to an error with the database!" + Environment.NewLine;
                            }
                        }
                        else
                        {
                            //As the user does not want to delete the items exit out and return a blank list.
                            listString = "Not deleted";
                        }
                    }
                    listString += "*************************************************************************************************" + Environment.NewLine;
                }
                return(listString);
            }
            catch (Exception e)
            {
                UserInterface ui = new UserInterface();
                ui.OutputAString(e.ToString() + " " + e.StackTrace);
                return(null);
            }
        }
示例#15
0
        static void Main(string[] args)
        {
            int choiceInt = 1;
            string idString;

            UserInterface ui = new UserInterface();
            CSVProcessor csvp = new CSVProcessor();
            WineItemCollection WIC = new WineItemCollection();

            while (choiceInt != 0)
            {
                bool error = false;
                ui.DisplayMenu();
                try
                {
                    choiceInt = Convert.ToInt32(ui.ReadLine());

                }
                catch
                {
                    ui.InvalidEntry();
                    error = true;
                }

                if (!error)
                {
                    switch (choiceInt)
                    {
                        case 0:

                            break;
                        case 1: //Load the file
                            if (csvp.Loaded)
                                ui.FilesAlreadyLoaded();
                            else
                            {
                                csvp.LoadFiles();
                                ui.FilesLoaded();
                            }
                            break;

                        case 2: //Display all files
                            if (csvp.Loaded)
                                ui.DisplayFiles();
                            else
                                ui.FilesNotLoaded();
                            break;

                        case 3: //Find item by id
                            if (csvp.Loaded)
                            {
                                ui.ItemSearchMessage();
                                idString = ui.ReadLine();
                                ui.ItemSearchResult(WIC.FindItem(idString));
                            }
                            else
                                ui.FilesNotLoaded();
                            break;

                        case 4: //Add item
                            if (csvp.Loaded)
                            {
                                WineItem temp = new WineItem(ui.NewItemId(), ui.NewItemDescription(), ui.NewItemPack());

                                ui.DisplayText(WIC.AddItem(temp));

                            }
                            else
                                ui.FilesNotLoaded();
                            break;

                        default:
                            ui.AnotherNumber();
                            break;
                    }
                }
            }
        }
示例#16
0
        static void Main(string[] args)
        {
            //Set a constant for the size of the collection
            //const int wineItemCollectionSize = 4000;

            //Create an Instance of the Database
            BeveragePBathEntities beveregeEntity = new BeveragePBathEntities();

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

            //Create an instance of the WineItemCollection class
            IWineCollection wineItemCollection = new WineItemCollection();

            //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 (choice != 6)
            {
                switch (choice)
                {
                case 1:
                    // Print All
                    foreach (Beverage bev in beveregeEntity.Beverages)
                    {
                        Console.WriteLine("Printing all in the Database! \n");
                        Console.WriteLine("The ID is: " + bev.id);
                        Console.WriteLine("The Name is: " + bev.name);
                        Console.WriteLine("The Pack is: " + bev.pack);
                        Console.WriteLine("The Price is: " + bev.price);
                    }
                    break;

                case 2:
                    //Search for a specific ID
                    string searchQuery     = userInterface.GetSearchQuery();
                    string itemInformation = wineItemCollection.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 (wineItemCollection.FindById(newItemInformation[0]) == null)
                    {
                        wineItemCollection.AddNewItem(newItemInformation[0], newItemInformation[1], newItemInformation[2], Convert.ToDecimal(newItemInformation[3]));
                        userInterface.DisplayAddWineItemSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemAlreadyExistsError();
                    }
                    break;

                case 4:
                    // Modify Item
                    string[] modifyItem = userInterface.GetInfoToUpdate();

                    if (wineItemCollection.FindById(modifyItem[0]).Equals(true))
                    {
                        wineItemCollection.Update(modifyItem[0], modifyItem[1], modifyItem[2], Convert.ToDecimal(modifyItem[3]));
                    }

                    else
                    {
                        userInterface.DisplayItemFoundError();
                    }

                    break;

                case 5:
                    //Delete a Wine item by ID
                    string deleteItem = userInterface.GetIDToDelete();

                    if (wineItemCollection.FindById(deleteItem).Equals(true))
                    {
                        wineItemCollection.Delete(deleteItem);
                    }

                    else
                    {
                        userInterface.DisplayItemFoundError();
                    }

                    break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
        /// <summary>
        /// Updates a single wine
        /// </summary>
        /// <param name="id">string</param>
        public void UpdateWine(string id)
        {
            try
            {
                //Open database
                BeverageJMartinEntities beverageEntities = new BeverageJMartinEntities();
                //Create an instance of the UserInterface
                UserInterface ui = new UserInterface();
                //Create a beverage that will hold the one to be updated by the id passed in
                Beverage beverageToUpdate = beverageEntities.Beverages.Find(id);

                string inputString = " ";
                //Continue to loop until the user choose 5 to save and exit.
                while (inputString != "5")
                {
                    //Output the beveragtToUpdate to the user
                    ui.PrintLine();
                    ui.ColorLineNoEnter(FormatBeverageSting(beverageToUpdate));
                    ui.PrintLine();
                    //Ouput the Edit Menu
                    ui.ColorLineNoEnter(ui.PrintEditMenu(id));
                    //Get the users choice of which menu item to do
                    inputString = ui.InputCharReturnString();
                    //Loop until valid input from the user
                    while (inputString != "1" && inputString != "2" && inputString != "3" && inputString != "4" && inputString != "5")
                    {
                        ui.ColorLineNoEnter(ui.WriteInvalidEntry());
                        ui.ColorLineNoEnter(FormatBeverageSting(beverageToUpdate));
                        ui.ColorLineNoEnter(ui.PrintEditMenu(id));
                        inputString = ui.InputCharReturnString();
                    }
                    //Ouput a blank line
                    ui.OutputAString(" ");
                    //Get the information needed from the user to update the property of the
                    //property type the user just chose.
                    switch (inputString)
                    {
                    case "1":
                        beverageToUpdate.name = ui.GetTheNameOfTheWine();
                        break;

                    case "2":
                        beverageToUpdate.pack = ui.GetTheWinePack();
                        break;

                    case "3":
                        beverageToUpdate.price = ui.GetThePrice();
                        break;

                    case "4":
                        beverageToUpdate.active = ui.GetIfWineIsActive();
                        break;
                    }
                }
                //Save the changes to the database
                beverageEntities.SaveChanges();
            }
            catch (Exception e)
            {
                UserInterface ui = new UserInterface();
                ui.OutputAString(e.ToString() + " " + e.StackTrace);
            }
        }
示例#18
0
        //Establishes a StreamReader, Random Number, UserInterface.
        //Establishes the WineItem & WineItemCollection class arrays bases on the size of the input file.
        //Reads the input file into the WineItem array.
        //Directs the program based on user input.
        static void Main(string[] args)
        {
            StreamReader wineList = new StreamReader("../../../datafiles/WineList.csv");
            Random randomNumber = new Random();
            UserInterface ui = new UserInterface();

            Int32 arrayCount = CSVProcessor.Processor(wineList);
            Int32 addToArrayCount = arrayCount;
            WineItem[] wineItems = new WineItem[arrayCount + 5];
            WineItemCollection[] collections = new WineItemCollection[arrayCount + 5];
            CSVProcessor.ReadFile(wineItems, wineList);

            Int32 selection1_Int32 = 0;
            
            //While the user has not chosen to exit the program.
            while (selection1_Int32 != 5)
            {
                selection1_Int32 = ui.InputMenu1();
                String output;
                
                switch (selection1_Int32)
                {
                    //Displays the output as found in the input file.
                    //This will display the array in a sorted order if it has already been sorted (if choice 2 or 3 has already been selected).
                    case 1:
                        {
                            output = WineItem.CreateString(wineItems);
                            ui.PrintAllOutput(output);
                            break;
                        }
                    //Displays the output in ascending or descending order with item location.
                    case 2:
                        {
                            Int32 selection2_Int32 = 0;
                            selection2_Int32 = ui.InputMenu2();
                            WineItemCollection.SetLocation(wineItems, collections, randomNumber);
                            output = WineItem.CreateLongString(wineItems, collections, selection2_Int32);
                            ui.PrintAllOutput(output);
                            selection2_Int32 = 0;
                            break;
                        }
                    //Prompts the user for input and searches the file for matching items.
                    //Prompts the user for a search method as well.
                    //Dispays a message for successful and unsuccessful searches.
                    case 3:
                        {
                            Int32 foundLocation = -1;
                            String temp = ui.SearchId();
                            Int32 selection3_Int32 = ui.InputMenu3();
                            foundLocation = WineItem.SearchType(wineItems, temp, selection3_Int32, arrayCount);
                            if (foundLocation == -1)
                            {
                                ui.NotFound(temp);
                            }
                            break;
                        }
                    //Allows the user to add items to the wine directory (up to 5 items).
                    case 4:
                        {
                            addToArrayCount = ui.UserAddWine(wineItems, addToArrayCount);
                            //addToArrayCount++;
                            break;
                        }
                    //Exit loop selection
                    case 5:
                        {
                            //Do Nothing - proceed to close the program.
                            break;
                        }
                }

            }
        }
示例#19
0
        /// <summary>
        /// Initializes the data that the program will be working with.
        /// </summary>
        private static void initializeData()
        {
            // TODO: This data technically has to do with the user interface, but it's specific to this program only - hence why I put it in Program.cs.
            //       The User Interface class is meant to be extremely generic so that it can be utilized more dynamically, so all specific data that
            //       only applies to this single program was written in Program.cs.

            // Object initialization
            userInterface = new UserInterface();
            beverageDatabaseHook = new BeverageZDwyerEntities();

            // Data initialization (don't have to do it here, technically, but figured might as well)
            greeting = "Welcome to the beverage database management system.";
            dontAddBeveragesWithTheSameID = true;                                   // Should we add beverages to the database that have a duplicate id?

            /* MENU ITEM SET INITIALIZATION */
            /* (MenuItemSet objects are used by the DisplayMenuAndGetResponse method in UserInterface to draw a menu) */
            /* (The MenuItemSet constructor can take a variable amount of strings with the params argument specifier I just found out about a few minutes ago lol) */

            // Main menu
            mainMenuItemsSet = new MenuItemsSet
            (
                "Print all beverages",
                "Retreive beverage by property or ID",
                "Add a new beverage",
                "Update an existing beverage",
                "Delete a beverage",
                "Exit program"
            );

            // Find item by property menu
            findItemByWhatMenuItemsSet = new MenuItemsSet
            (
                "ID",
                "Name",
                "Pack",
                "Price",
                "Active status",
                "(Back to main menu)"
            );

            // Find beverages with a price that is... menu
            priceMenuItemsSet = new MenuItemsSet
            (
                "...less than or equal to a given value",
                "...equal to a given value",
                "...more than or equal to a given value"
            );

            // Find by active status menu
            findItemByActiveStatus = new MenuItemsSet
            (
                "Is active",
                "Is not active"
            );
        }
示例#20
0
        static void Main(string[] args)
        {
            // Launch introUI
            UserInterface introUI = new UserInterface();
            int uiChoice = introUI.IntroInput();
            // While choice isn't EXIT
            while (uiChoice != 2)
            {
                // Load new instance of the CSV Processor
                CSVProcessor csvProcessor = new CSVProcessor();
                // !!! SET THIS FILE PATH MANUALLY !!!
                csvProcessor.ImportCSV(@"..\datafiles\WineList.csv");
                // load wineItems locally
                List<WineItem> wineItems = csvProcessor.GetWineItems();
                // While user makes any choice in the main UI
                while (uiChoice == 1 || uiChoice == 2 || uiChoice == 3)
                {
                    // New instance of the main UI
                    UserInterface mainUI = new UserInterface();
                    uiChoice = mainUI.MainInput();
                    // Set up the case statement for the main UI
                    int uiSwitch = uiChoice;
                    switch (uiSwitch)
                    {
                        case 1:
                            // Print out the entire list of items with a for loop
                            for (int i = 0; i <= wineItems.Count - 1; i++)
                            {
                                Console.WriteLine(wineItems[i].ToString());
                            }
                            break;
                        case 2:
                            // Allow user to search for items in the List
                                Console.WriteLine("ENTER ITEM ID TO SEARCH FOR:");
                                string userInput = Console.ReadLine();
                                bool flag = false;
                            // for loop to search for entered text in the entire list
                                for(int i = 0; i <= wineItems.Count - 1; i++)
                                {
                                    if (wineItems[i].ItemID.Equals(userInput) && wineItems[i] != null)
                                    {
                                        Console.WriteLine("MATCHING ITEM ID FOUND:" + Environment.NewLine +
                                            wineItems[i].ToString());
                                        flag = true;
                                    }
                                }
                            // show no results
                                if (flag == false)
                                {
                                    Console.WriteLine("NO MATCHING ITEM ID");
                                }
                                break;
                        case 3:
                            // Allow user to enter an item
                                string enteredID, enteredDescription, enteredPack;
                                Console.WriteLine("ENTER NEW ID:");
                                enteredID = Console.ReadLine();
                                Console.WriteLine("ENTER NEW DESCRIPTION");
                                enteredDescription = Console.ReadLine();
                                Console.WriteLine("ENTER NEW PACK");
                                enteredPack = Console.ReadLine();
                            // Add item to WineItem list
                                wineItems.Add(new WineItem(enteredID, enteredDescription, enteredPack));
                                Console.WriteLine(wineItems[wineItems.Count -1].ToString());
                                break;
                        default:
                                break;
                    }

                }
                uiChoice = introUI.IntroInput();
            }
        }
示例#21
0
        static void Main(string[] args)
        {
            //Creates a new connection to the Database
            BeverageJKoehlerEntities bevEntities = new BeverageJKoehlerEntities();

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

            //Create an instance of the WineItemCollection class
            IWineCollection wineItemCollection = new WineItemCollection(bevEntities);


            //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 (choice != 7)
            {
                switch (choice)
                {
                case 1:
                    //Check the Database Connection.

                    if (bevEntities != null)
                    {
                        //Display Success Message
                        userInterface.DisplayImportSuccess();
                    }
                    else
                    {
                        //Display Fail Message
                        userInterface.DisplayImportError();
                    }
                    break;

                case 2:
                    //Print Entire List Of Items
                    string[] allItems = wineItemCollection.GetPrintStringsForAllItems();
                    if (allItems.Length > 0)
                    {
                        //Display all of the items
                        userInterface.DisplayAllItems(allItems);
                    }
                    else
                    {
                        //Display error message for all items
                        userInterface.DisplayAllItemsError();
                    }
                    break;

                case 3:
                    //Search For An Item
                    string searchQuery     = userInterface.GetSearchQuery();
                    string itemInformation = wineItemCollection.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 (wineItemCollection.FindById(newItemInformation[0]) == null)
                    {
                        wineItemCollection.AddNewItem(newItemInformation[0], newItemInformation[1], newItemInformation[2], newItemInformation [3],
                                                      newItemInformation[4]);
                        userInterface.DisplayAddWineItemSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemAlreadyExistsError();
                    }
                    break;

                //Update an existing item in the database
                case 5:
                    string[] updatedItemInformation = userInterface.GetNewItemInformation();
                    if (wineItemCollection.FindById(updatedItemInformation[0]) == null)
                    {
                        userInterface.DisplayItemFoundError();
                    }
                    else
                    {
                        wineItemCollection.UpdateItem(updatedItemInformation[0], updatedItemInformation[1], updatedItemInformation[2],
                                                      updatedItemInformation[3], updatedItemInformation[4]);
                    }
                    break;

                //Remove an existing item from the database
                case 6:
                    string itemToRemove = userInterface.DisplayItemRemovalDialogue();

                    wineItemCollection.RemoveItem(itemToRemove);

                    break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
        static void Main(string[] args)
        {
            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Import the database and show import message (This is done on startup by default)
            BeverageACullenEntities beverageACullenEntities = new BeverageACullenEntities();
            userInterface.DisplayImportSuccess();

            //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 (choice != 6)
            {
                switch (choice)
                {
                    case 1:

                        //Display entire list of beverages
                        userInterface.DisplayAllItems(beverageACullenEntities);
                        break;

                    case 2:
                        //Search the list for a beverage by ID
                        string searchQuery = userInterface.GetSearchQuery();

                        Beverage searchBeverage = beverageACullenEntities.Beverages.Find(searchQuery);

                        if (searchBeverage != null)
                        {
                            userInterface.DisplayItemFound();
                            userInterface.DisplayItem(searchBeverage);
                        }
                        else
                        {
                            userInterface.DisplayItemFoundError();
                        }
                        break;

                    case 3:
                        //Add a beverage item to the list

                        //Get values from user
                        string[] addItemInfo = userInterface.GetItemInformation(false,"");

                        //Make sure the user entered ID is not already on the list
                        if (beverageACullenEntities.Beverages.Find(addItemInfo[0]) == null)
                        {
                            //Create a new beverage and import values from user input
                            Beverage addBeverage = new Beverage();
                            addBeverage.id = addItemInfo[0];
                            addBeverage.name = addItemInfo[1];
                            addBeverage.pack = addItemInfo[2];
                            addBeverage.price = Convert.ToDecimal(addItemInfo[3]);
                            addBeverage.active = Convert.ToBoolean(addItemInfo[4]);

                            //Add the beverage to the database
                            beverageACullenEntities.Beverages.Add(addBeverage);
                            beverageACullenEntities.SaveChanges();
                            userInterface.DisplayAddItemSuccess();
                            userInterface.DisplayItem(addBeverage);

                        }
                        else
                        {
                            userInterface.DisplayItemAlreadyExistsError();
                        }
                        break;

                    case 4:
                        //Update a beverage item in the database

                        //Get search item ID from user
                        string updateQuery = userInterface.GetSearchQuery();

                        //Find the item by its ID
                        Beverage updateBeverage = beverageACullenEntities.Beverages.Find(updateQuery);

                        //If found...
                        if (updateBeverage != null)
                        {
                            //Display the item and directions for user reference
                            userInterface.DisplayItemFound();
                            userInterface.DisplayItem(updateBeverage);
                            userInterface.DisplayUpdateDirections();

                            //get updated values from user
                            string[] updateItemInfo = userInterface.GetItemInformation(true, updateBeverage.id);
                            updateBeverage.name = updateItemInfo[1];
                            updateBeverage.pack = updateItemInfo[2];
                            updateBeverage.price = Convert.ToDecimal(updateItemInfo[3]);
                            updateBeverage.active = Convert.ToBoolean(updateItemInfo[4]);

                            beverageACullenEntities.SaveChanges();

                            userInterface.DisplayUpdateSuccess();
                            userInterface.DisplayItem(updateBeverage);

                        }
                        else //if not found...
                        {
                            userInterface.DisplayItemFoundError();
                        }
                        break;

                    case 5:
                        //Delete beverage from database
                        string deleteQuery = userInterface.GetSearchQuery();
                        Beverage deleteBeverage = beverageACullenEntities.Beverages.Find(deleteQuery);

                        if (deleteBeverage != null)
                        {
                            userInterface.DisplayItemFound();
                            userInterface.DisplayItem(deleteBeverage);

                            beverageACullenEntities.Beverages.Remove(deleteBeverage);
                            beverageACullenEntities.SaveChanges();

                            userInterface.DisplayDeleteMessage();

                        }
                        else
                        {
                            userInterface.DisplayItemFoundError();
                        }

                        break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
示例#23
0
        static void Main(string[] args)
        {
            bool isLoadedCSV = false;
            UserInterface ui = new UserInterface();
            WineItem wineItem = new WineItem();
            WineItemCollections wineItemCollection = new WineItemCollections();
            CSVProcessor file = new CSVProcessor();


            int choice = ui.GetUserInput();

            while (choice != 5) // exits program if user selects 5, otherwise menu keeps displaying
            {
                switch (choice)
                {
                    case 1:
                        {
                            if (!isLoadedCSV) // loads file first time, afterward displays that it's already been loaded
                            {
                                file.ImportCSV("../../../datafiles/WineList.csv", wineItemCollection);
                                Console.WriteLine("File successfully loaded.");
                                Console.WriteLine();
                                isLoadedCSV = true;
                            }
                            else
                            {
                                Console.WriteLine("File has already been loaded.");
                                Console.WriteLine();
                            }
                            break;
                        }
                    case 2:
                        {
                            // displays all wine items
                            Console.WriteLine(wineItemCollection.ToString());
                            Console.WriteLine();
                            break;
                        }

                    case 3:
                        {
                            // allows user to search for wine by ID and displays wine info or that wine does not exist
                            Console.WriteLine("Enter the ID you wish to search for: ");
                            string searchWineItemID = Console.ReadLine();
                            WineItem wineItemResult = wineItemCollection.SearchWine(searchWineItemID);
                            if (wineItemResult != null)
                            {
                                Console.WriteLine(wineItemResult.ToString());
                            }
                            else
                            {
                                Console.WriteLine("The ID was not found in the database.");
                            }
                            Console.WriteLine();
                            break;
                        }

                    case 4:
                        {
                            // allows user to add wine item to array if the ID is not already in the database


                            Console.WriteLine("Please enter the wine ID: ");
                            string userID = Console.ReadLine();
                            WineItem wineItemResult = wineItemCollection.SearchWine(userID);
                            if (wineItemResult != null) 
                            {
                                Console.WriteLine("That ID is already in the database.");
                            }
                            else
                            {
                                Console.WriteLine("Please enter the wine description: ");
                                string userDescription = Console.ReadLine();

                                Console.WriteLine("Please enter the wine pack: ");
                                string userPack = Console.ReadLine();

                                WineItem userWineItem = new WineItem(userID, userDescription, userPack);
                                wineItemCollection.AddWineItem(userWineItem);

                                Console.WriteLine();
                                Console.WriteLine(userWineItem.ToString() + " successfully added.");
                                Console.WriteLine();
                            }

                            
                        }

                        break;
                }

                choice = ui.GetUserInput();
            }

            
        }
示例#24
0
        static void Main(string[] args)
        {
            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

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

            //import from the database
            BeverageYWangEntities beverageYWangEntities = new BeverageYWangEntities();

            while (choice != 7)
            {
                switch (choice)
                {
                    case 1:
                        //Gain access to the database
                        Beverage beverage = new Beverage();

                       /*
                        if (beverage != null)
                        {
                            //Display Success Message
                            userInterface.DisplayImportSuccess();
                        }
                        else
                        {
                            //Display Fail Message
                            userInterface.DisplayImportError();
                        }
                       */
                        break;

                    case 2:
                        //Print Entire List Of Items

                        userInterface.DisplayAllItems(beverageYWangEntities);

                        break;

                    case 3:
                        //Search For An Item
                        string searchQuery = userInterface.GetSearchQuery();

                        Beverage foundBeverage = beverageYWangEntities.Beverages.Find(searchQuery);

                        if (foundBeverage != null)
                        {
                            userInterface.DisplayItemFound(foundBeverage);
                        }
                        else
                        {
                            userInterface.DisplayItemFoundError();
                        }
                        break;

                    case 4:
                        //Add A New Item To The List
                        string[] newItemInformation = userInterface.GetNewItemInformation();
                        if (beverageYWangEntities.Beverages.Find(newItemInformation[0]) == null)
                        {
                            Beverage newBeverage = new Beverage();

                            newBeverage.id = newItemInformation[0];
                            newBeverage.name = newItemInformation[1];
                            newBeverage.pack = newItemInformation[2];
                            newBeverage.price = Convert.ToDecimal(newItemInformation[3]);
                            newBeverage.active = Convert.ToBoolean(newItemInformation[4]);

                            //Add to the database
                            beverageYWangEntities.Beverages.Add(newBeverage);
                            //Save Changes to the database
                            beverageYWangEntities.SaveChanges();

                            //Successful add
                            userInterface.DisplayAddWineItemSuccess();

                        }
                        else
                        {
                            userInterface.DisplayItemAlreadyExistsError();
                        }

                        break;
                    case 5:
                        //Update Item to Database
                        string updateQuery = userInterface.GetSearchQuery();
                        //locate the item by Id
                        Beverage beverageForUpdate = beverageYWangEntities.Beverages.Find(updateQuery);

                        if (beverageForUpdate != null)
                        {
                            string[] updateItemInformation = userInterface.GetUpdateItemInformation();

                                beverageForUpdate.name = updateItemInformation[0];
                                beverageForUpdate.pack = updateItemInformation[1];
                                beverageForUpdate.price = Convert.ToDecimal(updateItemInformation[2]);
                                beverageForUpdate.active = Convert.ToBoolean(updateItemInformation[3]);

                                //update to the database
                                beverageYWangEntities.Beverages.Add(beverageForUpdate);
                                //Save Changes to the database
                                beverageYWangEntities.SaveChanges();

                                //Successful update
                                userInterface.DisplayAddWineItemSuccess();
                        }
                        else
                        {
                            userInterface.DisplayItemFoundError();
                        }

                        break;
                    case 6:
                        //Delete Item from Database
                        string deleteQuery = userInterface.GetSearchQuery();
                        Beverage beverageForDelete = beverageYWangEntities.Beverages.Find(deleteQuery);

                        if (beverageForDelete != null)
                        {
                            userInterface.DisplayItemFound(beverageForDelete);
                            //Delete the Record
                            beverageYWangEntities.Beverages.Remove(beverageForDelete);
                            //Save changes to database
                            beverageYWangEntities.SaveChanges();
                        }
                        else
                        {
                            userInterface.DisplayItemFoundError();
                        }

                        break;

                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
示例#25
0
        static void Main(string[] args)
        {
            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Create an instance of the WineItemCollection class
            WineItemCollection wineItemCollection = new WineItemCollection();

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

            Console.BufferHeight = 5000;
            Console.BufferWidth  = 150;

            //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 (choice != 7)
            {
                switch (choice)
                {
                case 1:
                    userInterface.DisplayImportSuccess();
                    break;

                case 2:
                    //Print Entire List Of Items
                    string[] allItems = wineItemCollection.GetPrintStringsForAllItems();
                    if (allItems.Length > 0)
                    {
                        //Display all of the items
                        userInterface.DisplayAllItems(allItems);
                    }
                    else
                    {
                        //Display error message for all items
                        userInterface.DisplayAllItemsError();
                    }
                    break;

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

                case 4:
                    // Add A New Item To The List
                    string[] newItemInformation = userInterface.GetItemInformation();
                    // Convert the price to a decimal:
                    decimal price = Convert.ToDecimal(newItemInformation[3]);
                    // Set a boolean to hold whether the item is active:
                    bool active = false;
                    // If the input was Y for yes, set active to true:
                    if (newItemInformation[4] == "Y")
                    {
                        active = true;
                    }
                    // Send info to WineItemCollection to add a new item:
                    if (wineItemCollection.AddNewItem(newItemInformation[0], newItemInformation[1], newItemInformation[2], price, active))
                    {
                        userInterface.DisplayAddWineItemSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemAlreadyExistsError();
                    }
                    break;

                case 5:
                    // Update an item in the list:
                    string idUpdate = userInterface.GetUpdateId();
                    if (wineItemCollection.UpdateBeverageItem(idUpdate))
                    {
                        userInterface.DisplayItemUpdateSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemUpdateError();
                    }
                    break;

                case 6:
                    // Delete an item from the list:
                    string idDelete = userInterface.GetDeleteId();
                    if (wineItemCollection.DeleteBeverageItem(idDelete))
                    {
                        userInterface.DisplayItemDeleteSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemDeleteError();
                    }
                    break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
示例#26
0
        static void Main(string[] args)
        {
            //Set a constant for the size of the collection
            const int wineItemCollectionSize = 4000;

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

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

            //Create an instance of the WineItemCollection class
            IWineCollection wineItemCollection = new WineItemCollection(wineItemCollectionSize);

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

                    case 2:
                        //Print Entire List Of Items
                        string[] allItems = wineItemCollection.GetPrintStringsForAllItems();
                        if (allItems.Length > 0)
                        {
                            //Display all of the items
                            userInterface.DisplayAllItems(allItems);
                        }
                        else
                        {
                            //Display error message for all items
                            userInterface.DisplayAllItemsError();
                        }
                        break;

                    case 3:
                        //Search For An Item
                        string searchQuery = userInterface.GetSearchQuery();
                        string itemInformation = wineItemCollection.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 (wineItemCollection.FindById(newItemInformation[0]) == null)
                        {
                            wineItemCollection.AddNewItem(newItemInformation[0], newItemInformation[1], newItemInformation[2]);
                            userInterface.DisplayAddWineItemSuccess();
                        }
                        else
                        {
                            userInterface.DisplayItemAlreadyExistsError();
                        }
                        break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
示例#27
0
        static void Main(string[] args)
        {
            //Create an instance of the UserInterface class
            UserInterface userInterface = new UserInterface();

            //Create and instance of the BeverageAPI
            BeverageAPI beverageAPI = new BeverageAPI();

            //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 user choice is not 6 we will continue to display the menu
            while (choice != 6)
            {
                switch (choice)
                {
                case 1:
                    //Print Entire List Of Items
                    beverageAPI.PrintAllBeverages();
                    break;

                case 2:
                    //Search For An Item
                    //Create the string that will be used to search for and item
                    string searchQuery = userInterface.GetSearchQuery();

                    //Find the beverage item using the searchQuery string
                    string itemInformation = beverageAPI.FindById(searchQuery);

                    //See if there is an item in the string. If the string is null then the item does not exist
                    if (itemInformation != null)
                    {
                        userInterface.DisplayItemFound(itemInformation);
                    }
                    else
                    {
                        userInterface.DisplayItemFoundError();
                    }
                    break;

                case 3:
                    //Add A New Item To The List
                    //Create the string for the new item
                    string[] newItemInformation = userInterface.GetNewItemInformation();

                    //Check to see if the item already exists in the collection
                    //If the item exist display the message that it does
                    if (beverageAPI.FindById(newItemInformation[0]) == null)
                    {
                        beverageAPI.AddNewItem(newItemInformation[0], newItemInformation[1], newItemInformation[2]);
                        userInterface.DisplayAddWineItemSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemAlreadyExistsError();
                    }
                    break;

                case 4:
                    //Update An Existing item
                    //Create the string for the updated item
                    string updateID = userInterface.GetUpdateString();

                    //Find the item that will be updated to display for the user
                    string updateItemInformation = beverageAPI.FindById(updateID);

                    //If the item exist in the collection it will be displayed for the user to update
                    //If no item exist display the error message that it was not found
                    if (updateItemInformation != null)
                    {
                        string[] updateInformation = userInterface.DisplayUpdateString(updateItemInformation);
                        beverageAPI.UpdateItem(updateID, updateInformation[0], updateInformation[1], updateInformation[2]);
                    }
                    else
                    {
                        userInterface.DisplayItemFoundError();
                    }

                    break;

                case 5:
                    //Delete An Existing item
                    string deleteString = userInterface.GetDeleteString();
                    beverageAPI.DeleteItem(deleteString);
                    break;
                }

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