public void PrintWineList() //method to read the entire list and print out every element { csvProcessor.ImportCSV("../../../datafiles/WineList.csv", wineItems); foreach (WineItem wineItem in wineItems) //loads the entire WineItem array { if (wineItem != null) //only reads a line in the array if an element is not null { Console.WriteLine(wineItem.ToString()); //converts the data in one element to a string wineItemsProcessed++; //accumulates the amount of each non-null element in the array } } }
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; } } }
static void Main(string[] args) { Console.WriteLine("Welcome to our wacky and wild wine list! \n"); int UserIn = UserInterface.GetUserInput(); // Assuming GetUserInput returns an integer of input // Well it still wants an integer? // Needed an extra = so it wasnt an assignment if (UserIn == 1) { // reading in the .CSV file // Find it using ../../../datafiles CSVProcessor csvProcessr = new CSVProcessor(); //Dont know why this isnt working? csvProcessr.ImportCSV("../../../datafiles.csv", allTheWines); } else if (UserIn == 2) { // add to the list // use a method created in the WineItemCollection Console.WriteLine(" We will now add a new Item to the list!"); } else if (UserIn == 3) { // loop through the array by the first index of a newly created WineItem with the input // as the first index and when they == each other // print out that array Console.WriteLine(" We will now look for an ID in the list!"); } else if (UserIn == 4) { Console.WriteLine(" We will see you later! "); Environment.Exit(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(); } }
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(); } }
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(); } }