private void ParseData() { if (File.Exists(this._file_path)) { FileStream dataFile = File.OpenRead(this._file_path); using (StreamReader streamReader = new StreamReader(dataFile)) { this._ingredients.Clear(); while (streamReader.Peek() >= 0) { String line = streamReader.ReadLine(); var line_data = line.Split(','); if (line_data[0] == "I") { Ingredient tmpIng = new Ingredient(); tmpIng.ID = uint.Parse(line_data[1]); tmpIng.Name = line_data[2]; this._ingredients.Add(tmpIng); } else if (line_data[0] == "R") { uint count = 0; Recipe.Recipe tmpRecipe = new Recipe.Recipe(); while (++count < line_data.Length) { if (count == 1) { tmpRecipe.ID = uint.Parse(line_data[count]); } else if (count == 2) { tmpRecipe.Name = line_data[count]; } else if (count == 3) { tmpRecipe.Text = line_data[count]; } else { RecipeItem tmpItem = new RecipeItem(); var item_data = line_data[count].Split(';'); tmpItem.Count = uint.Parse(item_data[0]); tmpItem.Unit = item_data[1]; foreach (var tmpIngredient in this._ingredients) { if (tmpIngredient.ID == uint.Parse(item_data[2])) { tmpItem.Ingredient = tmpIngredient; } } tmpRecipe.addIngredient(tmpItem); } } this._recipes.Add(tmpRecipe); } } } } }
static void Main(string[] args) { RecipeDataProviderImpl rsStorage = new RecipeDataProviderImpl("test.csv"); if (rsStorage.Ingredients.Count == 0) { foreach (String ingName in TEST_ING_NAMES) { Ingredient tmpIng = new Ingredient(); tmpIng.Name = ingName; System.Console.WriteLine("Add Ingredient: " + tmpIng); rsStorage.AddIngredient(tmpIng); } } if (rsStorage.Recipes.Count == 0) { Recipe.Recipe kuchenRcp = new Recipe.Recipe(); kuchenRcp.Name = "Kuchen"; kuchenRcp.Text = "Zubereitung"; RecipeItem mehlItem = new RecipeItem(); mehlItem.Count = 1; mehlItem.Unit = "Tasse"; mehlItem.Ingredient = rsStorage.Ingredients[2]; RecipeItem backPulverItem = new RecipeItem(); backPulverItem.Count = 2; backPulverItem.Unit = "Messerspitze"; backPulverItem.Ingredient = new Ingredient(); backPulverItem.Ingredient.Name = "Backpulver"; kuchenRcp.addIngredient(mehlItem); kuchenRcp.addIngredient(backPulverItem); rsStorage.AddRecipe(kuchenRcp); System.Console.WriteLine("Add Recipe: " + kuchenRcp); } foreach (Ingredient ing in rsStorage.Ingredients) { System.Console.WriteLine("Got stored ingredient {0}", ing); } foreach (Recipe.Recipe rcp in rsStorage.Recipes) { System.Console.WriteLine("Got stored recipe {0}", rcp); } System.Console.ReadKey(); }
private void button1_Click(object sender, EventArgs e) { Ingredient newIngredient = new Ingredient(); newIngredient.Name = "new Ingredient"; if (txtnewIngredient.Text != "") { newIngredient.Name = txtnewIngredient.Text; txtnewIngredient.Text = ""; } rsStorage.AddIngredient(newIngredient); RecipeItem newRecipeItem = new RecipeItem(); newRecipeItem.Ingredient = newIngredient; newRecipeItem.Count = 0; newRecipeItem.Unit = ""; currentRecipe.addIngredient(newRecipeItem); init(); }