// >Methods
        //
        // >Try to read in a CVS file and add the data to a collection.
        public bool LoadCVSIntoCollection(string filePath, WineItemCollection collection)
        {
            try
            {
                // >Assign the file.
                streamReader = new StreamReader(filePath);
                // >Change the file path to the new one.
                _filePath = filePath;
                // >Find the number of lines in the new file.
                _fileLineCount = File.ReadLines(_filePath).Count();

                // >Make the collections array have the same amount of elements as lines in the file. add 400 to be able to add wines.
                collection.wineItemArray = new WineItem[(_fileLineCount + 400)];

                string line;// >String to hold what is read in.

                int count = 0;// >The current file line number.
                while (!streamReader.EndOfStream)
                {
                    // >Read a line.
                    line = streamReader.ReadLine();
                    // >Split the data.
                    string[] temp = line.Split(',');

                    // >Create an WineItem.
                    collection.wineItemArray[count] = new WineItem();

                    // >Set data for the wine item at the current collection element.
                    collection.wineItemArray[count].WineId = temp[0];
                    collection.wineItemArray[count].WineDescription = temp[1];
                    collection.wineItemArray[count].PackType = temp[2];

                    // >Increase the count.
                    count += 1;
                }
                // >Mark the next available position.
                collection.emptySpot = count;
                // >Mark the file as have being read.
                _hasFileBeenRead = true;
                // >If successful return true.
                return true;
            }
            catch (Exception e)
            {
                StaticUserInterface.WriteToScreen("*******************  !!!!!!!!!!!!!  *******************");
                StaticUserInterface.WriteToScreen("File does not exist or is not in a CVS readable format!");
                StaticUserInterface.WriteToScreen(e.ToString());
                StaticUserInterface.WriteToScreen("*******************  !!!!!!!!!!!!!  *******************");
                return false;
            }
            finally
            {
                if (streamReader != null)
                {
                    // >Close the file.
                    streamReader.Close();
                }
            }

        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        //---------------------------------------------------
        //Public Methods
        //---------------------------------------------------
        //Public method to Import the CSV
        public bool ImportCSV(WineItemCollection wineItems, string pathToCSVFile)
        {
            //Declare the streamreader
            StreamReader streamReader = null;

            //If it hasn't already been imported
            if (!hasBeenImported)
            {
                try
                {
                    //declare a string for the line
                    string line;

                    //Declare and instanciage a new StreamReader class
                    streamReader = new StreamReader(pathToCSVFile);

                    //While still reading a line from the file
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        //Process the line
                        this.processLine(line, wineItems);
                    }
                    //Set hasBeenImported to true now that it is imported
                    hasBeenImported = true;

                    //Return true to represent success
                    return true;
                }
                catch (Exception e)
                {
                    //Output the Error that occured. This is the only output that is NOT being done in the UI class
                    Console.WriteLine(e.ToString());
                    Console.WriteLine();
                    Console.WriteLine(e.StackTrace);

                    //Return false to signify that it failed
                    return false;
                }
                finally
                {
                    //If the stream reader was instanciated, make sure it is closed before exiting.
                    if (streamReader != null)
                    {
                        streamReader.Close();
                    }
                }

            }
            //It has already been imported. No need to do it again.
            else
            {
                //return false
                return false;
            }
        }
Ejemplo n.º 4
0
        //---------------------------------------------------
        //Public Methods
        //---------------------------------------------------

        //Public method to Import the CSV
        public bool ImportCSV(WineItemCollection wineItems, string pathToCSVFile)
        {
            //Declare the streamreader
            StreamReader streamReader = null;

            //If it hasn't already been imported
            if (!hasBeenImported)
            {
                try
                {
                    //declare a string for the line
                    string line;

                    //Declare and instanciage a new StreamReader class
                    streamReader = new StreamReader(pathToCSVFile);

                    //While still reading a line from the file
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        //Process the line
                        this.processLine(line, wineItems);
                    }
                    //Set hasBeenImported to true now that it is imported
                    hasBeenImported = true;

                    //Return true to represent success
                    return(true);
                }
                catch (Exception e)
                {
                    //Output the Error that occured. This is the only output that is NOT being done in the UI class
                    Console.WriteLine(e.ToString());
                    Console.WriteLine();
                    Console.WriteLine(e.StackTrace);

                    //Return false to signify that it failed
                    return(false);
                }
                finally
                {
                    //If the stream reader was instanciated, make sure it is closed before exiting.
                    if (streamReader != null)
                    {
                        streamReader.Close();
                    }
                }
            }
            //It has already been imported. No need to do it again.
            else
            {
                //return false
                return(false);
            }
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
        //---------------------------------------------------
        //Private Methods
        //---------------------------------------------------

        private void processLine(string line, WineItemCollection wineItemCollection)
        {
            //declare array of parts that will contian the results of splitting the read in string
            string[] parts = line.Split(',');

            //Assign each part to a variable
            string id          = parts[0];
            string description = parts[1];
            string pack        = parts[2];

            //Add a new wine item into the collection with the properties of what was read in.
            wineItemCollection.AddNewItem(id, description, pack);
        }
Ejemplo n.º 7
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
        }
Ejemplo n.º 8
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
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            Console.WindowWidth  = 100;
            Console.WindowHeight = 30;

            var                System         = new string[4000, 3];     //Instantiates an empty 2d array named System
            UserInterface      ui             = new UserInterface();     //Creates the navigation menu
            CSVProcessorClass  csvProcess     = new CSVProcessorClass(); //Instantiates CSV processor class
            WineItemCollection wineCollection = new WineItemCollection();
            WineItem           searchWine     = new WineItem();


            int choice = ui.GetUserInput();

            while (choice != 5)
            {
                switch (choice)
                {
                case 1:         //Load array from CSV file
                    csvProcess.loadWineArray(System);

                    break;

                case 2:         //Search wine list

                    searchWine.searchWineList(System);
                    ui.DisplaySearchResults(searchWine.ToString());     //Demonstrate override method

                    break;

                case 3:         //Add new wine

                    wineCollection.addWineToArray(System);
                    break;

                case 4:         //Print entire list
                    //ui.printFullArray(System);
                    ui.PrintAllOutput(System);

                    break;

                case 5:
                    Environment.Exit(-1);    //Exits program
                    break;
                }
                choice = ui.GetUserInput();
            }
        }
Ejemplo n.º 10
0
        /// <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();
            }
        }
Ejemplo n.º 11
0
 //string CSVFile;
 //loads csv file from driectory
 public void load(WineItemCollection WineList)
 {
     if (!list)
     {
         InputFile = File.OpenText("WineList.csv");
         while (!InputFile.EndOfStream)
         {
             split = InputFile.ReadLine().Split(',');
             //CSVFile = InputFile.ReadLine();
             //Console.WriteLine(CSVFile);
             WineItem Wine = new WineItem(split[0], split[1], split[2]);
             WineList.AddWine(Wine);
         }
        InputFile.Close();
     }
     list = true;
 }
        //Generates a 3 part location for where the item is supposably stored
        public static void SetLocation(WineItem[] wineItems, WineItemCollection[] collection, Random randomNumber)
        {
            Int32 anothercounter = 0;

            foreach (WineItem wineItem in wineItems)
            {
                String aisle1 = "";
                String row1   = "";
                String shelf1 = "";
                if (wineItem != null)
                {
                    Int32 locationCounter;

                    //Generates the aisle location of the item (4 digits)
                    for (locationCounter = 0; locationCounter < 4; locationCounter++)
                    {
                        Int32  low   = 0;
                        Int32  high  = 10;
                        Int32  temp  = RandomGenerator(low, high, randomNumber);
                        String temp2 = temp.ToString();
                        aisle1 += temp2;
                    }
                    //Generates the row location of the item (2 uppercase alpha characters)
                    for (locationCounter = 0; locationCounter < 2; locationCounter++)
                    {
                        Int32  low   = 65;
                        Int32  high  = 91;
                        Int32  temp1 = RandomGenerator(low, high, randomNumber);
                        String temp2 = ConvertToAscii(temp1);
                        row1 += temp2;
                    }
                    //Generates the shelf location of the item (3 digits)
                    for (locationCounter = 0; locationCounter < 3; locationCounter++)
                    {
                        Int32  low   = 0;
                        Int32  high  = 10;
                        Int32  temp  = RandomGenerator(low, high, randomNumber);
                        String temp2 = temp.ToString();
                        shelf1 += temp2;
                    }
                    collection[anothercounter] = new WineItemCollection(aisle1, row1, shelf1);
                }
                anothercounter++;
            }
        }
        //Generates a 3 part location for where the item is supposably stored
        public static void SetLocation(WineItem[] wineItems, WineItemCollection[] collection, Random randomNumber)
        {
            Int32 anothercounter = 0;
            foreach (WineItem wineItem in wineItems)
            {
                String aisle1 = "";
                String row1 = "";
                String shelf1 = "";
                if (wineItem != null)
                {
                    Int32 locationCounter;

                    //Generates the aisle location of the item (4 digits)
                    for(locationCounter = 0; locationCounter < 4; locationCounter++)
                    {
                        Int32 low = 0;
                        Int32 high = 10;
                        Int32 temp = RandomGenerator(low, high, randomNumber);
                        String temp2 = temp.ToString();
                        aisle1 += temp2;
                    }
                    //Generates the row location of the item (2 uppercase alpha characters)
                    for (locationCounter = 0; locationCounter < 2; locationCounter++)
                    {
                        Int32 low = 65;
                        Int32 high = 91;
                        Int32 temp1 = RandomGenerator(low, high, randomNumber);
                        String temp2 = ConvertToAscii(temp1);
                        row1 += temp2;
                    }
                    //Generates the shelf location of the item (3 digits)
                    for (locationCounter = 0; locationCounter < 3; locationCounter++)
                    {
                        Int32 low = 0;
                        Int32 high = 10;
                        Int32 temp = RandomGenerator(low, high, randomNumber);
                        String temp2 = temp.ToString();
                        shelf1 += temp2;
                    }
                    collection[anothercounter] = new WineItemCollection(aisle1, row1, shelf1);
                }
                anothercounter++;
            }
        }
Ejemplo n.º 14
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();
            }

        }
Ejemplo n.º 15
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;
                }
            }
        }
Ejemplo n.º 16
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();
            }
        }
        public void load(WineItemCollection collection)
        {
            if (!listLoaded)//Make sure the list can only be loaded once
            {
                StreamReader reader = new StreamReader("..\\..\\..\\datafiles\\WineList.csv");//Create parser object
                string[] lineSplit;

                while (!reader.EndOfStream)
                {
                    lineSplit = reader.ReadLine().Split(','); //Splits the line, using commas as delimiters

                    WineItem item = new WineItem(lineSplit[0], lineSplit[1], lineSplit[2]);//Create the WineItem using the information from the line
                    collection.addWineItem(item, false);//Load the item into the collection

                }

                listLoaded = true;

            }
        }
        //methods
        public void loadList(WineItemCollection wICollection)
        {
            //this method reads the csv file and splits items at each comma, saving values as WineItem values
            if (!loadFinished)  //ensures the list is only loaded once
            {
                StreamReader streamreader = new StreamReader("..\\..\\..\\datafiles\\WineList.csv");

                string[] splitter;

                while (!streamreader.EndOfStream)
                {
                    splitter = streamreader.ReadLine().Split(',');

                    WineItem wineItem = new WineItem(splitter[0], splitter[1], splitter[2]);
                    wICollection.addNewItem(wineItem);
                }

                loadFinished = true;    //marks the list as loaded

            }
        }
Ejemplo n.º 19
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;
                }
            }
        }
Ejemplo n.º 20
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;
                    }
                }
            }
        }
Ejemplo n.º 21
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
            WineItemCollection 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();
            }
        }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            Console.WriteLine("Must load csv file first to print");
            Console.WriteLine("type load to Load the list");
            Console.WriteLine("Type list to print list");
            Console.WriteLine("type seach to search list");
            Console.WriteLine("type add to add wine ");
            Console.WriteLine("Exit");

            Console.Write("Choose an option: ");
            UserInputMenu = Console.ReadLine(); //user input

            //objects from diffent classes
            WineItemCollection wineCollection = new WineItemCollection();
            CSVProcessor listWine = new CSVProcessor();
            WineItemCollection wineAdd = new WineItemCollection();
            WineItemCollection searchWine = new WineItemCollection();

            //whlie loops that keep going until users hit exit
             while (UserInputMenu != "exit")
             {
             //loads csv file
               if (UserInputMenu == "load")

              {
              //loadWine();
              listWine.load(wineCollection);
              loadMenu();
              }
               //print csv file
              else if (UserInputMenu == "list")
            {
              //  printWine();

                Console.Write("You typed in list");

                   Console.WriteLine(wineCollection.getWineCollection());
                   loadMenu();

            }
               //seach csv file
            else if (UserInputMenu == "search")
            {

                string wineIdInput = string.Empty;

                Console.Write("You typed in search");
                Console.WriteLine("Enter wine id");
                wineIdInput = Console.ReadLine();
                Console.WriteLine( searchWine.searchId(wineIdInput));
                loadMenu();
            }
               //add to the csv file
            else if (UserInputMenu == "add")
            {
                Console.WriteLine("You typed in add");
                wineAdd.WineAdd();
                loadMenu();
            }

            else if (UserInputMenu == "exit")
            {
                End();
            }
            else //if(UserInputMenu != "eixt" || UserInputMenu != "list" || UserInputMenu != "load" || UserInputMenu != "search")
            {
                Console.WriteLine(UserInputMenu +" is not an option");
                Console.WriteLine("please enter one the following");
                loadMenu();
            }
             }
        }
Ejemplo n.º 23
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;
                }
                }
            }
        }
Ejemplo n.º 24
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();
            }
        }
Ejemplo n.º 25
0
        // display the sub  menu for the user
        public void DisplaySubMenu(List <WineItem> wineList)
        {
            bool quitSubBoolean = false;

            WineItemCollection Collection = new WineItemCollection();

            // do while loop keeps showing the sub menu for the user until user hits exit
            do
            {
                Console.WriteLine("\n");
                Console.WriteLine("Enter the number corresponding which action you wish to perform: ");
                Console.WriteLine("\n");
                Console.WriteLine("1. Print the entire csv file of WineList.");
                Console.WriteLine("2. Search wine by ID number.");
                Console.WriteLine("3. Add a new wine to the list.");
                Console.WriteLine("4. Exit the program.");

                string inputString = Console.ReadLine();

                // "if" statement is used in case user doesn't input anything and press enter.
                if (inputString.Trim() != string.Empty)
                {
                    //try catch is for invalid user input in case they don't input integer.
                    try
                    {
                        int inputInt = int.Parse(inputString);

                        switch (inputInt)
                        {
                        case 1:
                            for (int i = 0; i < wineList.Count; i++)
                            {
                                Console.WriteLine(wineList[i]);
                            }
                            break;

                        case 2:
                            Console.WriteLine("\n");
                            Collection.SearchById(wineList);
                            break;

                        case 3:
                            Collection.AddWine(wineList);
                            break;

                        case 4:
                            // jump out of the loop
                            quitSubBoolean = true;
                            Environment.Exit(0);
                            break;

                        default:
                            Console.WriteLine("Invalid Input");
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        //Console.WriteLine("Invalid data. Please enter an integer.");
                        Console.WriteLine(e);
                    }
                }
                else
                {
                    Console.WriteLine("No data entered");
                }
            } while (quitSubBoolean != true);
        }
 public UserInterface(WineItemCollection collection)
 {
     this.wineItemCollection = collection;
 }
Ejemplo n.º 27
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();
            }
        }
Ejemplo n.º 28
0
        //---------------------------------------------------
        //Private Methods
        //---------------------------------------------------
        private void processLine(string line, WineItemCollection wineItemCollection)
        {
            //declare array of parts that will contian the results of splitting the read in string
            string[] parts = line.Split(',');

            //Assign each part to a variable
            string id = parts[0];
            string description = parts[1];
            string pack = parts[2];

            //Add a new wine item into the collection with the properties of what was read in.
            wineItemCollection.AddNewItem(id, description, pack);
        }
Ejemplo n.º 29
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;
                        }
                }

            }
        }
Ejemplo n.º 30
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();
            }
        }
Ejemplo n.º 31
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();
            }
        }
Ejemplo n.º 32
0
        static void Main(string[] args)
        {
            //Set a constant for the size of the collection
            const int wineItemCollectionSize = 4000;

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

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

            //Get access to the collection of tables
            BeverageBCampbellEntities beverageEntities = new BeverageBCampbellEntities();

            //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:
                    //Load the CSV File
                    //bool success = csvProcessor.ImportCSV(wineItemCollection, pathToCSVFile);
                    bool success;

                    try
                    {
                        foreach (Beverage bev in beverageEntities.Beverages)
                        {
                            wineItemCollection.AddNewItem(bev.id, bev.name, bev.pack);
                        }
                        success = true;
                    }
                    catch
                    {
                        success = false;
                    }

                    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
                    //ID Description Pack
                    string[] newItemInformation = userInterface.GetNewItemInformation();
                    if (wineItemCollection.FindById(newItemInformation[0]) == null)
                    {
                        wineItemCollection.AddNewItem(newItemInformation[0], newItemInformation[1], newItemInformation[2]);
                        userInterface.DisplayAddWineItemSuccess();
                    }
                    else
                    {
                        userInterface.DisplayItemAlreadyExistsError();
                    }
                    break;

                case 5:
                    //Update an existing item
                    searchQuery     = userInterface.GetSearchQuery();
                    itemInformation = wineItemCollection.FindById(searchQuery);
                    if (itemInformation != null)
                    {
                        userInterface.DisplayItemFound(itemInformation);
                        string[] replaceItemInformation = userInterface.GetNewItemInformation();
                        wineItemCollection.Overwrite(searchQuery, replaceItemInformation[0], replaceItemInformation[1], replaceItemInformation[2]);
                    }
                    else
                    {
                        userInterface.DisplayItemFoundError();
                    }


                    break;

                case 6:
                    //Delete an existing item
                    searchQuery = userInterface.GetSearchQuery();
                    wineItemCollection.Delete(searchQuery);
                    break;
                }

                //Get the new choice of what to do from the user
                choice = userInterface.DisplayMenuAndGetResponse();
            }
        }
Ejemplo n.º 33
0
        /// <summary>
        /// For debugging/testing purposes. Bypasses UserInterface class and tests individual classes directly.
        /// </summary>
        private void Testing()
        {
            #region WineItemTest

            Console.WriteLine(Environment.NewLine + "******************************" + Environment.NewLine +
                "Test For WineItem functionality." + Environment.NewLine +
                "******************************" + Environment.NewLine);

            string ID1 = "12345";
            string ID2 = "67890";
            string aDesc1 = "aDesc";
            string aDesc2 = "OtherDesc";
            string aSize1 = "Size 1";
            string aSize2 = "Size 500";

            WineItem WineTest1 = new WineItem(ID1, aDesc1, aSize1);
            WineItem WineTest2 = new WineItem(ID2, aDesc2, aSize2);

            Console.WriteLine("TEST- ForcePrint:" + Environment.NewLine +
                WineTest1.WineID + " " + WineTest1.WineDescription + " " + WineTest1.WineSize + Environment.NewLine);

            Console.WriteLine("TEST- ToString():");
            Console.WriteLine(WineTest1.ToString());
            Console.WriteLine(WineTest2.ToString());

            Console.WriteLine(Environment.NewLine);

            #endregion

            #region WineItemCollectionTest

            Console.WriteLine(Environment.NewLine + "******************************" + Environment.NewLine +
                "Test For Collection functionality." + Environment.NewLine +
                "******************************" + Environment.NewLine);

            WineItemCollection collectionTest = new WineItemCollection(5);
            collectionTest.LoadWineItem(WineTest1, 0, 1);
            collectionTest.LoadWineItem(WineTest2, 1, 1);

            Console.WriteLine("TEST- Above items added to collection and displayed:");
            Console.WriteLine(collectionTest.GetCollectionToString());

            #endregion

            #region CSVProcessorTest

            Console.WriteLine(Environment.NewLine + "******************************"
             + Environment.NewLine + "Test For CSVProcessor functionality." + Environment.NewLine +
             "******************************" + Environment.NewLine);

            CSVProcessor loadThings = new CSVProcessor();

            int ArraySize = loadThings.LoadListSize;
            Console.WriteLine("TEST- # of Items loaded: " + Environment.NewLine + ArraySize + Environment.NewLine);

            WineItemCollection wineCollection = new WineItemCollection(ArraySize);
            loadThings = new CSVProcessor(wineCollection, 0);

            Console.WriteLine("TEST- Collection Contents After Load:");
            Console.WriteLine(wineCollection.GetCollectionToString());

            #endregion
        }
Ejemplo n.º 34
0
        static void Main(string[] args)
        {
            int Prompt = UserInterface.GetUserInput();

            //Declare Array
            WineItem[] Winelist = new WineItem[4000];

            //Textfile
            string CSV = "../../../datafiles/WineList.csv";

            ProcessArrayExecuted = true;



            if (Prompt == 1)
            {
                WineItemCollection Loaded = new WineItemCollection();
                Loaded.ArrayLoaded();


                Prompt = UserInterface.GetUserInput();
            }
            if (Prompt == 2)
            {
                WineItemCollection csvdisplay = new WineItemCollection();

                csvdisplay.WineCSV(CSV, Winelist);

                string outputString = "";


                foreach (WineItem Wine in Winelist)
                {
                    if (Wine != null)
                    {
                        outputString += Wine.ToString() +
                                        Environment.NewLine;
                    }
                }

                UserInterface.Output(outputString);
                Prompt = UserInterface.GetUserInput();
            }

            if (Prompt == 3)
            {
                WineItemCollection Locate = new WineItemCollection();
                Locate.Search();
                Prompt = UserInterface.GetUserInput();
            }

            if (Prompt == 4)
            {
                //add record to text file
                Winelist[3964] = new WineItem("52562", "123 Westnedge ave", "700 ml");
                Added          = true;

                WineItemCollection RecordAdded = new WineItemCollection();
                RecordAdded.Add();
                Prompt = UserInterface.GetUserInput();
            }
            if (Prompt == 5)
            {
                exit();
            }



            //re-promp the user for input
            Prompt = UserInterface.GetUserInput();
        }
        // display the sub  menu for the user
        public void DisplaySubMenu(List<WineItem> wineList)
        {
            bool quitSubBoolean = false;

            WineItemCollection Collection = new WineItemCollection();

            // do while loop keeps showing the sub menu for the user until user hits exit
            do
            {
                Console.WriteLine("\n");
                Console.WriteLine("Enter the number corresponding which action you wish to perform: ");
                Console.WriteLine("\n");
                Console.WriteLine("1. Print the entire csv file of WineList.");
                Console.WriteLine("2. Search wine by ID number.");
                Console.WriteLine("3. Add a new wine to the list.");
                Console.WriteLine("4. Exit the program.");

                string inputString = Console.ReadLine();

                // "if" statement is used in case user doesn't input anything and press enter.
                if (inputString.Trim() != string.Empty)
                {
                    //try catch is for invalid user input in case they don't input integer.
                    try
                    {
                        int inputInt = int.Parse(inputString);

                        switch (inputInt)
                        {
                            case 1:
                                for (int i = 0; i < wineList.Count; i++)
                                {
                                    Console.WriteLine(wineList[i]);
                                }
                                break;
                            case 2:
                                Console.WriteLine("\n");
                                Collection.SearchById(wineList);
                                break;
                            case 3:
                                Collection.AddWine(wineList);
                                break;
                            case 4:
                                // jump out of the loop
                                quitSubBoolean = true;
                                Environment.Exit(0);
                                break;
                            default:
                                Console.WriteLine("Invalid Input");
                                break;
                        }
                    }
                    catch (Exception e)
                    {
                        //Console.WriteLine("Invalid data. Please enter an integer.");
                        Console.WriteLine(e);
                    }
                }
                else
                {
                    Console.WriteLine("No data entered");
                }

            } while (quitSubBoolean != true);
        }