diff --git a/assignment1/CSVProcessor.cs b/assignment1/CSVProcessor.cs index 3c69fc2e8b1e51dcd31bb14d8c27ef1358af4a2e..44615848813db0201c5a444bb9952dab295e387d 100644 --- a/assignment1/CSVProcessor.cs +++ b/assignment1/CSVProcessor.cs @@ -11,6 +11,9 @@ namespace assignment1 { #region Variables + // Classes + private WineItemCollection wineItemCollection; + // Input Variables private int wineIDInt; private string wineDescriptionString; @@ -19,6 +22,7 @@ namespace assignment1 // Working Variables private bool hasLoadedBool = false; private int wineListSizeInt; + private int indexInt; private StreamReader inputFile; @@ -28,9 +32,21 @@ namespace assignment1 #region Constructors + /// <summary> + /// Base Constructor. + /// </summary> public CSVProcessor() { + GetListSize(); + } + /// <summary> + /// Constructor to read from file. + /// </summary> + /// <param name="wineItemCollection">The current instance of WineItemCollection Class.</param> + public CSVProcessor(WineItemCollection wineItemCollection) + { + Collection = wineItemCollection; } #endregion @@ -39,6 +55,22 @@ namespace assignment1 #region Properties + public WineItemCollection Collection + { + set + { + this.wineItemCollection = value; + } + } + + public int WineListSize + { + get + { + return wineListSizeInt; + } + } + public int WineID { get @@ -69,16 +101,39 @@ namespace assignment1 #region Methods - private void ReadFile() + /// <summary> + /// Deterimines size of items to handle. + /// </summary> + private void GetListSize() + { + while (inputFile.EndOfStream == false) + { + wineListSizeInt++; + } + } + + /// <summary> + /// Reads from file to create WineItemCollection. + /// </summary> + public void ReadFile() { try { + indexInt = 0; - while (inputFile.EndOfStream == false) + while (indexInt > wineListSizeInt) { + string inputString = inputFile.ReadLine(); + var flds = inputString.Split(','); + + WineItem wineItem = new WineItem(); + wineItem.WineID = Convert.ToInt32(flds[0].Trim()); + wineItem.WineDescription = flds[1].Trim(); + wineItem.WineSize = flds[2].Trim(); + wineItemCollection.LoadWineItem(wineItem, indexInt); - wineListSizeInt++; + indexInt++; } } catch (Exception errmsg) diff --git a/assignment1/Program.cs b/assignment1/Program.cs index 47fc4e3ff41cc24485ac0c2a14809123beba5cb2..de133576718802ed280bcc6ab34eb722b525ee5b 100644 --- a/assignment1/Program.cs +++ b/assignment1/Program.cs @@ -10,6 +10,15 @@ namespace assignment1 { static void Main(string[] args) { + CSVProcessor processFiles = new CSVProcessor(); + + int wineListSizeInt = processFiles.WineListSize; + + + + UserInterface mainMenu = new UserInterface(); + WineItemCollection wineItemCollection = new WineItemCollection(wineListSizeInt); + } } } diff --git a/assignment1/UserInterface.cs b/assignment1/UserInterface.cs index 5037536fd15e5f4471105f3a93a476569e8f9905..ea375d1ecc9d45ed72819fd93d3f7f143f109813 100644 --- a/assignment1/UserInterface.cs +++ b/assignment1/UserInterface.cs @@ -35,6 +35,21 @@ namespace assignment1 #region Methods + /// <summary> + /// Main loop to keep user in program until exit. + /// </summary> + private void RunMenu() + { + while (runProgramBool) + { + DisplayMainMenu(); + UserSelection(); + } + } + + /// <summary> + /// Reusable menu to display to user. + /// </summary> private void DisplayMainMenu() { Console.WriteLine("Choose an Option:" + Environment.NewLine + @@ -45,11 +60,29 @@ namespace assignment1 "5) Exit" + Environment.NewLine); } - private void RunMenu() + /// <summary> + /// Reads user input and takes appropriate action. + /// </summary> + private void UserSelection() { - while (runProgramBool == true) - { + string userSelectionString = Console.ReadLine().Trim(); + switch (userSelectionString) + { + case "1": + break; + case "2": + break; + case "3": + break; + case "4": + break; + case "5": + runProgramBool = false; + break; + default: + Console.WriteLine("Invalid Selection. Please enter a number between 1 and 5."); + break; } } diff --git a/assignment1/WineItem.cs b/assignment1/WineItem.cs index e21fad969cbf1a699df25434924f827455dd5d91..0557c53042863a5b78a518cb09e6b1d211cd89df 100644 --- a/assignment1/WineItem.cs +++ b/assignment1/WineItem.cs @@ -10,6 +10,7 @@ namespace assignment1 { #region Variables + // Input Variables private int wineIDInt; private string wineDescriptionString; private string wineSizeString; diff --git a/assignment1/WineItemCollection.cs b/assignment1/WineItemCollection.cs index 4da39ad63d770222a10c8fa6458bfd5d8293dc98..9cac3a3434ac6e96381c0388c613f2966e0a059e 100644 --- a/assignment1/WineItemCollection.cs +++ b/assignment1/WineItemCollection.cs @@ -10,6 +10,15 @@ namespace assignment1 { #region Variables + // Classes + WineItem wineItem; + + // Input Variables + private int lengthOfArrayInt; + private int indexInt; + + private WineItem[] wineItemArray; + #endregion @@ -21,6 +30,12 @@ namespace assignment1 } + public WineItemCollection(int wineListSize) + { + lengthOfArrayInt = wineListSize; + wineItemArray = new WineItem[lengthOfArrayInt+(lengthOfArrayInt/2)]; + } + #endregion @@ -33,6 +48,24 @@ namespace assignment1 #region Methods + public void AddWineItem(WineItem wineItem) + { + if (lengthOfArrayInt > wineItemArray.Length) + { + wineItemArray[lengthOfArrayInt] = wineItem; + lengthOfArrayInt++; + } + else + { + + } + } + + public void LoadWineItem(WineItem wineItem, int indexInt) + { + wineItemArray[indexInt] = wineItem; + } + #endregion } }