Пример #1
0
        // CSV FILE PROCESSOR - READ IN
        public CSVProcessor()
        {
            WineItemCollection.wineList = new string[6000];
            index = 0;

            // WHILE THERE IS STILL DATA TO BE READ IN..CONTINUE LOOP
            while (!reader.EndOfStream)
            {
                // READ DATA LINE INTO VARIABLE: 'LINE'
                var line = reader.ReadLine();
                // 'VALUES' VARIABLE WILL SPLIT DATA IN 'LINE' VARIABLE
                var values = line.Split(',');

                // ADD DATA TO LISTS
                idList.Add(values[0]);
                descriptionList.Add(values[1]);
                packList.Add(values[2]);
                
                WineItem wineItem = new WineItem(values[0], values[1], values[2]);
                index++;
            }

            // ARBITRARY MSG TO DISPLAY ONCE FILE LOAD IS COMPLETE
            Console.WriteLine("100%...File Load Complete!");
            Console.WriteLine(Environment.NewLine);
            // ADJUST FILE LOAD HANDLE
            fileLoaded = true;
            // REPROMPT USER FOR INPUT
            Program.MainPrompt();
        }
Пример #2
0
        public bool ImportCSV(string pathToCSVFile, WineItem[] wineItems)
        {
            StreamReader streamReader = null;   //sets up a null StreamReader variable

            try
            {
                string line;                                    //null string to store the contents of the current line in the array

                streamReader = new StreamReader(pathToCSVFile); //locates the CSV file

                int counter = 0;                                //sets up a counter to use for reference in the while loop

                while((line = streamReader.ReadLine()) != null) //runs the loop until a null string is found
                {
                    processLine(line, wineItems, counter++);    //records the contents of each line that is being read
                }

                return true;                                    //returns true if the entire file was succesfully read
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());                //throws an error message to the user if the file was not completely read
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                if (streamReader != null)
                {
                    streamReader.Close();                       //closes the CSV file when it no longer needs to be read
                }
            }
            return false;                                       //returns false if the file was not correctly read all the way through
        }
        public void addNewItem(WineItem wineItem)
        {
            //this method adds a wine item to the list array
            wineItemList[arrayLength] = wineItem;

            arrayLength += 1;
        }
        // The process used to swap two arrays.
        private static void Swap(ref WineItem greater, ref WineItem less)
        {
            WineItem temp_String = greater;

            greater = less;
            less    = temp_String;
        }
       //Method to add Items to the array.
        public void Add_To(String id_Numer, String description, String packaging, Int32 index)
        {

            WineItem newItem = new WineItem(id_Numer, description, packaging);
            collection[index] = newItem;

        }
Пример #6
0
        static void Main(string[] args)
        {
            WineItem myWineItem = new WineItem();

            //3964 is the number of current items in the list
            //Create an array of type WineItem to hold a bunch of wineItems
            WineItem[] wineItems = new WineItem[3964];

            //call CSV Processor to Load File while allowing user to choose the file
            Console.WriteLine("What is the name of the CSV file that you would like to load?");
            String pathToCsvFile = Console.ReadLine();

            ImportCSV(pathToCsvFile, wineItems);

            //Instantiate a new UI Class to call methods after processing CSV File and reading contents.
            userInterface ui = new userInterface();

            IList <WineItem> collectionOfWine = new List <WineItem>(wineItems);



            //Get users input choice
            int choice = ui.GetUserInput();

            while (choice != 4)
            {
                //If the chioce they made is 1, Print the entire list of wine items
                if (choice == 1)
                {
                    //Create a string to concat the output
                    string allOutput = "";

                    //Loop through all the wine Items to concat them together.
                    foreach (WineItem wine in wineItems)
                    {
                        if (wine != null)
                        {
                            allOutput += wine.ToString() +
                                         Environment.NewLine;
                        }
                    }
                    //Once the concat is done, have the UI class print out the result
                    ui.PrintAllOutput(allOutput);
                }

                //If the choice they made is 2, search for item id provided by user and if found print it out
                if (choice == 2)
                {
                    collectionOfWine.Add(myWineItem);
                }
                //If the choice they made is 3, allow user to add a new wine item to the list
                if (choice == 3)
                {
                }

                //Get the next choice from the user.
                choice = ui.GetUserInput();
            }
        }
Пример #7
0
        static bool ImportCSV(string pathToCsvFile, WineItem[] wineItems)
        {
            // Declare a variable for the stream reader.Not going to instanciate it yet.
            StreamReader streamReader = null;

            //Start a try since the path to the file could be incorrect, and thus
            //throw an exception
            try
            {
                //Declare a string for each line we will read in.
                string line;
                
                //Instanciate the streamReader. If the path to file is incorrect it will
                //throw an exception that we can catch
                streamReader = new StreamReader(pathToCsvFile);

                //Setup a counter that we aren't using yet.
                int counter = 0;

                //While there is a line to read, read the line and put it in the line var.
                while ((line = streamReader.ReadLine()) != null)
                {
                    //Call the process line method and send over the read in line,
                    //the wineItems array (which is passed by reference automatically),
                    //and the counter, which will be used as the index for the array.
                    //We are also incrementing the counter after we send it in with the ++ operator.
                    processLine(line, wineItems, counter++);
                }

                //All the reads are successful, return true.
                return true;
            }
            catch (Exception e)
            {
                //Output the exception string, and the stack trace.
                //The stack trace is all of the method calls that lead to
                //where the exception occured.
                Console.WriteLine(e.ToString());
                Console.WriteLine();
                Console.WriteLine(e.StackTrace);

                //Return false, reading failed
                return false;
            }
            //Used to ensure the the code within it gets executed regardless of whether the
            //try succeeds or the catch gets executed.
            finally
            {
                //Check to make sure that the streamReader is actually instantiated before
                //trying to call a method on it. 
                if (streamReader != null)
                {
                    //Close the streamReader because its the right thing to do.
                    streamReader.Close();
                }

            }

        }
Пример #8
0
        // processes file - splits line at commas into 3-element array, each element is then
        // passed to wineItem and then added to wineItemCollection array. 
        public void ProcessLine(string line, WineItemCollections wineItemCollection)
        {
            string[] fileArray = line.Split(',');

            WineItem wineItem = new WineItem(fileArray[0], fileArray[1], fileArray[2]);
            wineItemCollection.AddWineItem(wineItem);

        }
Пример #9
0
        // Private method created to assign values to array.
        private void compileList(string wineList, WineItem[] wine, int index)
        {
            string[] collumns = wineList.Split(',');

            int idInteger = wineList[0];
            string desctriptionString = wineList[1].ToString();
            string packString = wineList[2].ToString();

            wine[index] = new WineItem(idInteger, desctriptionString, wineList);
        }
Пример #10
0
        public static void processLine(string line, WineItem[] Winelist, int i)
        {
            string[] elements = line.Split(',');

            string id      = elements[0];
            string type    = elements[1];
            string ammount = elements[2];

            Winelist[i] = new WineItem(id, type, ammount);
        }
Пример #11
0
        private void processLine(string line, WineItem[] wineItems, int index)  //stores the properties of each wine in the file
        {
            string[] parts = line.Split(',');                                   //tells the program that each property is separated by a comma in the file

            string id = parts[0];                                               //the first property is the ID
            string description = parts[1];                                      //the second property is the description
            string pack = parts[2];                                             //the third property is the pack

            wineItems[index] = new WineItem(id, description, pack);             //sends all three properties to the array
        }
Пример #12
0
        // Private method created to assign values to array.
        private void compileList(string wineList, WineItem[] wine, int index)
        {
            string[] collumns = wineList.Split(',');

            int    idInteger          = wineList[0];
            string desctriptionString = wineList[1].ToString();
            string packString         = wineList[2].ToString();

            wine[index] = new WineItem(idInteger, desctriptionString, wineList);
        }
Пример #13
0
        private void processLine(string line, WineItem[] wineItems, int index)  //stores the properties of each wine in the file
        {
            string[] parts = line.Split(',');                                   //tells the program that each property is separated by a comma in the file

            string id          = parts[0];                                      //the first property is the ID
            string description = parts[1];                                      //the second property is the description
            string pack        = parts[2];                                      //the third property is the pack

            wineItems[index] = new WineItem(id, description, pack);             //sends all three properties to the array
        }
Пример #14
0
       private void ProcessRecord(string line,WineItem[] wineItemList, int index)
        {
            string[] parts = line.Split(',');

            string idNumberString = parts[0];
            string itemNameString = parts[1];
            string quantityString = parts[2];



           wineItemList[index] = new WineItem(idNumberString, itemNameString, quantityString);
        }
Пример #15
0
 public WineItem InputRecord()                                  //Prompts user to Input ID number, item name, and item quantity for the record they wish to add
 {
     WineItem MadeRecord = new WineItem();
     Console.WriteLine("Please Input the ID Number");
     MadeRecord.IDNumberString = Console.ReadLine();
     Console.WriteLine("Please Input the item Name");
     MadeRecord.ItemNameString = Console.ReadLine();
     Console.WriteLine("Please Input the Quantity It Sells In");
     MadeRecord.QuantityString = Console.ReadLine();
     Console.WriteLine("Your Record has been added");
     return MadeRecord;
 }
        public void itemAdd()
        {
            Console.WriteLine("Please enter the ID of the new item:" + Environment.NewLine);
            string newID = getInput(Console.ReadLine().ToString(), "ID");
            Console.WriteLine("Please enter the desciption of the new item:" + Environment.NewLine);
            string newDesc = getInput(Console.ReadLine().ToString(), "description");
            Console.WriteLine("Please enter the pack of the new item:" + Environment.NewLine);
            string newPack = getInput(Console.ReadLine().ToString(), "pack");

            WineItem newItem = new WineItem(newID, newDesc, newPack);
            wineItemCollection.addWineItem(newItem, true);
        }
 public void AddRecord(WineItem addedRecord)             //Adds record to end of full array using a for loop
 {
     int counter = 0;
     for(counter = 0; counter < wineItemList.Length; counter++)
     {
         if(wineItemList[counter] == null)
         {
             wineItemList[counter] = addedRecord;
             return;
         }
     }            
 }
Пример #18
0
        private void ProcessRecord(string line, WineItem[] wineItemList, int index)
        {
            string[] parts = line.Split(',');

            string idNumberString = parts[0];
            string itemNameString = parts[1];
            string quantityString = parts[2];



            wineItemList[index] = new WineItem(idNumberString, itemNameString, quantityString);
        }
        public void AddRecord(WineItem addedRecord)             //Adds record to end of full array using a for loop
        {
            int counter = 0;

            for (counter = 0; counter < wineItemList.Length; counter++)
            {
                if (wineItemList[counter] == null)
                {
                    wineItemList[counter] = addedRecord;
                    return;
                }
            }
        }
        public void AddWine(WineItem wineItem)
        {
            int winePosition = wineItemArray.Count(x => x != null) + 1; //Finds the length of the array minus all the null slots.

            if(wineItemArray[winePosition-1] == null) //This is a failsafe incase the .CSV hasn't been loaded in.
            {                                         //Without it, the added wine would end up in slot 1 with slot 0 being null still, causing problems.
                winePosition = winePosition - 1;
            }

            lengthOfArray++;

            wineItemArray[winePosition] = wineItem;
        }
Пример #21
0
        //accecpts data and breaks it into the parts needed to define a WineItem
        private void Process_Data(String raw_Data, WineItem[] collection, Int32 index)
        {
            //Holder for the split data
            String[] spliter = raw_Data.Split(',');

            //local holder for each data part
            String id_number   = spliter[0];
            String description = spliter[1];
            String packaging   = spliter[2];

            //Fill array with WineItems
            collection[index] = new WineItem(id_number, description, packaging);
        }
Пример #22
0
        public WineItem InputRecord()                                  //Prompts user to Input ID number, item name, and item quantity for the record they wish to add
        {
            WineItem MadeRecord = new WineItem();

            Console.WriteLine("Please Input the ID Number");
            MadeRecord.IDNumberString = Console.ReadLine();
            Console.WriteLine("Please Input the item Name");
            MadeRecord.ItemNameString = Console.ReadLine();
            Console.WriteLine("Please Input the Quantity It Sells In");
            MadeRecord.QuantityString = Console.ReadLine();
            Console.WriteLine("Your Record has been added");
            return(MadeRecord);
        }
Пример #23
0
        static void Main(string[] args)
        {
            bool beenThere = true;                                            //Boolean used to tell whether or not the csv file has been loaded

            WineItemCollection wineItemCollection = new WineItemCollection(); //Instantiate the other classes
            UserInterface      ui = new UserInterface();
            int choice            = ui.Interact();                            //Loads Menu

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

            Console.WriteLine("Thank You For Using Our Program");             //Nice message to the user, may comment out later
            Console.ReadLine();                                               //Ends the program
        }
        /// <summary>
        /// Insert the given WineItem into the collection
        /// </summary>
        /// <param name="wineItem">The WineItem object</param>
        /// <returns>The id of the added item, or null if not added</returns>
        public string Add(WineItem wineItem)
        {
            string id = null;

            // only is successfull if there is enough room in array
            if (_length < _wineItems.Length)
            {
                _wineItems[_length++] = wineItem;

                id = wineItem.Id;
            }

            return id;
        }
Пример #25
0
        static void processLine(string line, WineItem[] wineItems, int index)
        {
            //declare a string array and assign the split line to it.
            string[] parts = line.Split(',');

            //Assign the parts to local variables that mean something
            string id          = parts[0];
            string description = parts[1];
            string pack        = parts[2];

            //Use the variables to instanciate a new Employee and assign it to
            //the spot in the employees array indexed by the index that was passed in.
            wineItems[index] = new WineItem(id, description, pack);
        }
Пример #26
0
        static void Main(string[] args)
        {
            User_Interface UI  = new User_Interface();
            CSV_Processor  cSV = new CSV_Processor();


            String file_Selection = string.Empty;
            Int32  user_Choice    = 0;
            String search_Term    = string.Empty;

            //creating an array of WineItems
            //I know this should be in a class, but I cannot make it work.
            //Something is usually better than nothing.
            WineItem[] collection = new WineItem[4000];
            Int32      i          = 0;


            //Have user select the file to read from.
            UI.Load_File_Dialog(out file_Selection);

            cSV.Load_CSV(file_Selection, collection);

            UI.Query_User(out user_Choice);



            switch (user_Choice)
            {
            case 1:
            {
                foreach (WineItem item in collection)
                {
                    if (collection != null)
                    {
                        Console.WriteLine((collection[i]));
                        i++;
                    }
                }
                Console.ReadLine();
                UI.Query_User(out user_Choice);
                break;
            }

            case 2:
            {
                UI.Search_Menu(out search_Term);
                break;
            }
            }
        }
Пример #27
0
 //Reads each line of the input file and passes the information to populate an array.
 public static void ReadFile(WineItem[] wineItems, StreamReader wineList)
 {
     foreach (WineItem wineItem in wineItems)
     {
         Int32 count2 = 0;
         while (!wineList.EndOfStream)
         {
             String[] Temp = wineList.ReadLine().Split(',');
             AddToArray(wineItems, count2, Temp);
             count2++;
         }
     }
     wineList.Close();
 }
Пример #28
0
        public bool ImportCSV(string pathToCSVFile, WineItem[] allTheWines)
        {
            StreamReader streaming = null;

            try
            {
                //declare a string to represent a line we read
                string line;

                //Create a new instance of the StreamReader class
                streaming = new StreamReader(pathToCSVFile);

                //Create a counter to know what index to place the new object
                int counter = 0;

                //This line is doing a bunch of stuff. It is reading a line from
                //the file. It is assigning that info to the 'line' variable, and
                //lastly it is making sure that what it just read was not null.
                //if it is null, we are done reading the file and we can exit the
                //loop.
                while ((line = streaming.ReadLine()) != null)
                {
                    // In this section isnt the counter useless?
                    // Why do we need to keep track of it?
                    processLine(line, allTheWines, counter++);
                }

                return true;
            }

            catch (Exception e)
            {
                //Spit out the errors that occured
                Console.WriteLine(e.ToString());
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                //If an instance of the streamreader was made, we want to ensure
                //that we close it. The finally block is a perfect spot to put it
                //since it will get called regardless of whether or not the try
                //succeeded
                if (streaming != null)
                {
                    streaming.Close();
                }
            }
            return false;
        }
Пример #29
0
        //accecpts data and breaks it into the parts needed to define a WineItem
        private void Process_Data(String raw_Data, WineItem[] collection, Int32 index)
        {
            //Holder for the split data
            String[] spliter = raw_Data.Split(',');

            //local holder for each data part
            String id_number = spliter[0];
            String description = spliter[1];
            String packaging = spliter[2];

            //Fill array with WineItems
            collection[index] = new WineItem(id_number, description, packaging);
            

        }
Пример #30
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();
            }
        }
Пример #31
0
        // This is the private method we use in this class to add a read in WineItem into the array of allTheWines
        private void processLine(string line, WineItem[] allTheWines, int index)
        {
            //Split the line into parts, and assign the parts to a string array
            string[] parts = line.Split(',');

            //Create some local variables and assign the various parts to them.
            int id = int.Parse(parts[0]);
            string description = parts[1];
            decimal pack = decimal.Parse(parts[2]);

            //Now we just need to add a new WineItem to the array and use the parts
            //we parsed out. If you had a collection class, I would hope that it has
            //a method that you made called 'add' that would then do the work of
            //adding a new WineItem to the collection.
            allTheWines[index] = new WineItem(id, description, pack);
        }
Пример #32
0
        //loads the files to WineItemCollection
        public void LoadFiles()
        {
            reader = File.OpenText("../../../datafiles/WineList.csv");
            int counter = 0;

            while (!reader.EndOfStream)
            {
                var fields = reader.ReadLine().Split(',');
                tempWine = new WineItem(fields[0], fields[1], fields[2]);
                WIC[counter] = tempWine;
                counter++;
            }
            reader.Close();
            WIC.Length = counter;
            loaded = true;
        }
Пример #33
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();
            }
        }
        /// <summary>
        /// Resize the collection to a new size.
        /// 
        /// If the size is lower than the number of items already in the collection,
        /// items are lost.
        /// </summary>
        /// <param name="size">The new size of the collection</param>
        public void Resize(int size)
        {
            WineItem[] wineItems = new WineItem[size];

            // If size has shrunk, limit new _length
            if (size < _length)
                _length = size;

            // Copy old items into new array
            for (int i=0; i < _length; ++i)
            {
                wineItems[i] = _wineItems[i];
            }

            _wineItems = wineItems;
        }
        public void addItem()
        {
            //this method walks the user through the addition of an item
            Console.WriteLine("{0}Enter the new item's ID:{0}", Environment.NewLine);
            string addItemID = Console.ReadLine().ToString();

            Console.WriteLine("{0}Enter the new item's name:{0}", Environment.NewLine);
            string addItemName = Console.ReadLine().ToString();

            Console.WriteLine("{0}Enter the new item's pack/volume:{0}", Environment.NewLine);
            string addItemPack = Console.ReadLine().ToString();

            WineItem addedItem = new WineItem(addItemID, addItemName, addItemPack);
            wineItemCollection.addNewItem(addedItem);

            Console.WriteLine("{0}Item added succesfully!", Environment.NewLine);
        }
Пример #36
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++;
            }
        }
        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;

            }
        }
 public void addWineItem(WineItem item, bool manEntry)
 {
     if (!manEntry) //If we are loading a list for the first time, don't bother checking for IDs
     {
         wineItems[lengthOfArray] = item;
         lengthOfArray++;
     }
     else
     {               //If the user is manually entering a new item, we should check and make sure the ID doesn't already exist
         if (!idExists(item.ID))
         {                   //If it doesn't exist, go ahead and add it.
             wineItems[lengthOfArray] = item;
             lengthOfArray++;
         }
         else
         {                   //If it does exist, let the user know, the item will not be added.
             Console.WriteLine("Item already exists with ID " + item.ID);
         }
     }
 }
Пример #40
0
        public bool Load_CSV(String path_CSV, WineItem[] collection)
        {

            //StreamReader
            StreamReader streamreader = null;

            try
            {
                //Used to read in data 
                String raw_Data = String.Empty;

                //Create new StreamReader
                streamreader = new StreamReader(path_CSV);

                //Counter for indexing
                Int32 counter = 0;

                //Read in data, and stop when a null is found
                while((raw_Data = streamreader.ReadLine()) != null)
                {
                    Process_Data(raw_Data, collection, counter);
                    counter++;
                }
                return true;
            }
            catch (Exception ex)
            {
                //Print any exceptions thrown
                Console.WriteLine(ex.ToString());
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                if(streamreader != null)
                {
                    //close streamReader 
                    streamreader.Close();
                }
            }
            return false;
        }
        //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

            }
        }
Пример #42
0
        // searches array for user-input ID and prints out wine information if found
        // loops through array and converts each element into string, splits at spaces, 
        // then gets the ID (first entry) and compares that to what the user entered.
        // returns the wineItem if found in the array, otherwise returns null.
        public WineItem SearchWine(string wineIDToFind)
        {
            string tempString = string.Empty;
            string[] tempArray;

            for (int counter = 0; counter < index; counter++)
            {

                tempString = wineItems[counter].ToString();
                tempArray = tempString.Split(' ');
                tempString = tempArray[0];
                if (tempString.Equals(wineIDToFind))
                {
                    tempString = wineItems[counter].ToString();
                    WineItem wineItemResult = new WineItem(tempString);
                    return wineItemResult;
                }
            }

            return null;
        }
Пример #43
0
        /* ADD WINE ITEM TO THE LIST */
        public void Add(WineItem wineItem)
        {
            // If this item won't fit in the array, throw an exception.
            // Example, if we're trying to fit a WineItem into position 12, but there's only 11 spaces in the wineItems array, throw an exception
            // (-1 on the wineItems.Length value since its maximum index is 1 less than its length)

            if (nextArrayPosition > (wineItems.Length - 1))     // Is the next array position more than the last index of the wineItems array?
            {
                // Make the list larger
                WineItem[] newWineItemList = new WineItem[(wineItems.Length + 1)];                  // Make a wineItemList the size of the old one, but one more larger.

                for (int index = 0; index < wineItems.Length; index++) {                            // Copy all of the wineItems into the new wineItems array
                    newWineItemList[index] = wineItems[index];
                }

                wineItems = newWineItemList;                                                        // Give the old wineItems array a new, bigger wineItemList
            }

            wineItems[nextArrayPosition] = wineItem;        // Add the given WineItem to the wineItems array
            nextArrayPosition++;                            // Increment the array so it's ready for the next time a WineItem is added
            Debug.WriteLine("WineItem added: " + wineItem.ToString());
        }
        //Directs the program to run the selected search type
        public static Int32 SearchType(WineItem[] wineItems, String temp, Int32 selection3_Int32, Int32 arrayCount)
        {
            Int32 foundLocation = -1;

            switch (selection3_Int32)
            {
            case 1:
            {
                foundLocation = SequentialSearch(wineItems, temp);
                break;
            }

            case 2:
            {
                WineItem.BubbleSort(wineItems);
                foundLocation = BinarySearch(wineItems, temp, arrayCount);
                break;
            }
            }

            return(foundLocation);
        }
Пример #45
0
        public void SearchById(List <WineItem> wineList)
        {
            WineItem result = null;

            do
            {
                Console.WriteLine("Search Records:");
                Console.Write("Enter Id to search for:");

                userInputString = Console.ReadLine();

                result = wineList.Find(x => x.WINEID == userInputString);

                if (result == null)
                {
                    Console.WriteLine("Invalid Value");
                }
            } while (result == null);

            Console.WriteLine("ID        Name                                    Amount");
            Console.WriteLine("-----------------------------------------------------------------");
            Console.WriteLine(result.ToString());
        }
        public void Collection() // Option 1
        {
            // Call WineItems class
            WineItem[] wineItems = new WineItem[3964];

            // Call CSVProcessor class
            CSVProcessor wineList = new CSVProcessor();

            // Load CSV file into an array with the fields from WineItem class
            wineList.AccessCSVFile("../data/WineList.csv", wineItems);

            int index = 0;

            // Foreach loop fills collection array
            foreach (WineItem item in wineItems)
            {
                if (item != null)
                {
                    collection[index] = item.ToString();
                }
                index++;
            }
        }
Пример #47
0
 //Populates an array with the information being passed.
 public static void AddToArray(WineItem[] wineItems, Int32 location, String[] Temp)
 {
     wineItems[location] = new WineItem(Temp[0], Temp[1], Temp[2]);
 }
Пример #48
0
 //Add a new item to the collection
 public void AddNewItem(string id, string description, string pack)
 {
     //Add a new WineItem to the collection. Increase the Length variable.
     wineItems[wineItemsLength] = new WineItem(id, description, pack);
     wineItemsLength++;
 }
        //Method to add Items to the array.
        public void Add_To(String id_Numer, String description, String packaging, Int32 index)
        {
            WineItem newItem = new WineItem(id_Numer, description, packaging);

            collection[index] = newItem;
        }
Пример #50
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();
        }
Пример #51
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;
                }
                }
            }
        }