public static List <Recipe> Load_Recipes() { List <Recipe> recipeList = new List <Recipe>(); using (var stream = new FileStream("KitchenData.csv", FileMode.OpenOrCreate)) { using (var streamReader = new StreamReader(stream)) { string sReadInLine; do { sReadInLine = streamReader.ReadLine(); if (sReadInLine == "R") { //Read in next line and parse sReadInLine = streamReader.ReadLine(); string[] parsedLine = sReadInLine.Split(','); Recipe newRecipe = new Recipe(); newRecipe.Name = parsedLine[0]; newRecipe.Description = parsedLine[1]; //Read in next line for steps sReadInLine = streamReader.ReadLine(); parsedLine = sReadInLine.Split(','); foreach (string s in parsedLine) { if (s != "") { newRecipe.Add_Step(s); } } sReadInLine = streamReader.ReadLine(); parsedLine = sReadInLine.Split(','); //Read in ingredients while (sReadInLine != "Z") { Measurement newMeasurement = new Measurement(float.Parse(parsedLine[2]), parsedLine[3]); Ingredient newIngredient = new Ingredient(newMeasurement, parsedLine[1], parsedLine[0]); newRecipe.Add_Ingredient(newIngredient); sReadInLine = streamReader.ReadLine(); parsedLine = sReadInLine.Split(','); } //Add new recipe to the list recipeList.Add(newRecipe); } } while ((sReadInLine != "STOP") && (sReadInLine != null)); } } return(recipeList); }
public void addStepToRecipe(object sender, RoutedEventArgs e) { if (StepToAdd.Text == "") { return; } string step = StepToAdd.Text; m_recipe.Add_Step(step); StepToAdd.Text = ""; Refresh(); }