예제 #1
0
파일: Edit.cs 프로젝트: mrosegger/Recipe
 public Edit(int currentRecipeID, ref bool RecipeChanged)
 {
     InitializeComponent();
     //currentRecipeID = currentRecipe;
     currentRecipe = getRecipe(currentRecipeID);
     init();
 }
예제 #2
0
 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);
                 }
             }
         }
     }
 }
예제 #3
0
 private void btn_AddRecipe_Click(object sender, EventArgs e)
 {
     Recipe.Recipe newRecipe = new Recipe.Recipe();
     newRecipe.Name = "new Recipe";
     if (txt_newIngredient.Text != "")
     {
         newRecipe.Name         = txt_newIngredient.Text;
         txt_newIngredient.Text = "";
     }
     rsStorage.AddRecipe(newRecipe);
     init();
 }
예제 #4
0
 private void btnDeleteRecipe_Click(object sender, EventArgs e)
 {
     Recipe.Recipe recipeToDelete = new Recipe.Recipe();
     foreach (Recipe.Recipe recipe in rsStorage.Recipes)
     {
         if (recipe.ID == recipIDs[lbxRecipe.SelectedIndex])
         {
             recipeToDelete = recipe;
         }
     }
     rsStorage.DeleteRecipe(recipeToDelete);
     init();
 }
예제 #5
0
파일: Edit.cs 프로젝트: mrosegger/Recipe
        //TODO Test if this works;; Also add one to wirte to the database
        private Recipe.Recipe getRecipe(int recipeID)
        {
            Recipe.Recipe fetchedRecipe = new Recipe.Recipe();

            foreach (Recipe.Recipe recipe in rsStorage.Recipes)
            {
                if (recipe.ID == recipeID)
                {
                    fetchedRecipe = recipe;
                }
            }

            return(fetchedRecipe);
        }
예제 #6
0
 public void AddRecipe(Recipe.Recipe recipe)
 {
     foreach (RecipeItem rcpItem in recipe.Items)
     {
         if (rcpItem.Ingredient.ID == 0)
         {
             AddIngredient(rcpItem.Ingredient);
         }
     }
     if (recipe.ID == 0)
     {
         recipe.ID = this.GetRcpId();
     }
     this._recipes.Add(recipe);
     this.StoreData();
 }
예제 #7
0
        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();
        }
예제 #8
0
        public void outputInLabel(int selectedElement)
        {
            string output;

            Recipe.Recipe selectedRecipe = new Recipe.Recipe();
            foreach (Recipe.Recipe recipe in rsStorage.Recipes)
            {
                if (recipe.ID == selectedElement)
                {
                    selectedRecipe = recipe;
                }
            }
            output  = $"{selectedRecipe.Name}: \n\n";
            output += "Zutaten: \n";
            foreach (RecipeItem item in selectedRecipe.Items)
            {
                output += $"{item.Count} {item.Unit} {item.Ingredient.Name}\n";
            }
            output        += $"\n{selectedRecipe.Text}";
            lblOutput.Text = output;
        }
예제 #9
0
 public void DeleteRecipe(Recipe.Recipe recipe)
 {
     _recipes.Remove(recipe);
     StoreData();
 }