Exemplo n.º 1
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();
            }
        }