public wineItem findWine(String id) { wineItem returnWine = new wineItem(id); for (int i = 0; i < collectionList.Count; i++) { if (collectionList[i].Equals(returnWine)) return collectionList[i]; } return null; }
//removes the wine from the csv file public void RemoveWine(wineItem removedWine) { List<String> newWineList = new List<String>(); StreamReader wineReader = new StreamReader(pathString); String readLineString; //reads in all wines besides the specified wine while(!wineReader.EndOfStream) { readLineString = wineReader.ReadLine(); if(!readLineString.Split(',')[0].Equals(removedWine.WineId)) { newWineList.Add(readLineString); } } wineReader.Close(); //writes the read in lines to the csv after eracing it StreamWriter newFileWriter = new StreamWriter(File.Open(pathString, FileMode.Create)); foreach (string s in newWineList) newFileWriter.WriteLine(s); newFileWriter.Close(); }
/// <summary> /// checks to see if the peramiters are valid then adds the wine to the wine list /// </summary> /// <param name="peramitersStrings"></param> private void addWineItem(String[] peramitersStrings) { //if peramiters are vallid if (peramitersStrings.Length == 3) { if (collectedWineItems.findWine(peramitersStrings[0]) == null) { // add wine item wineItem addWine = new wineItem(peramitersStrings[0], peramitersStrings[1], peramitersStrings[2]); collectedWineItems.AddWine(addWine); processCSV.AddWine(addWine); } else { Console.WriteLine("Error: " + peramitersStrings[0] + " matches a wine ID already in the database"); } } else if (peramitersStrings.Length > 3) Console.WriteLine("Error: to many parameters"); else Console.WriteLine("Error: to few parameters"); }
//adds a wine to the csv list public void AddWine(wineItem addedWine) { StreamWriter wineWriter = File.AppendText(pathString); wineWriter.WriteLine(addedWine.WineId + "," + addedWine.WineDescription + "," + addedWine.WinePack); wineWriter.Close(); }
/// <summary> /// removes the wine item matching the input wine item from the list /// </summary> /// <param name="removealItem"></param> public void removeWine(wineItem removealItem) { collectionList.Remove(removealItem); }
public void AddWine(wineItem addedWine) { collectionList.Add(addedWine); }