Example #1
0
        public static RecipeManagerData LoadData(string path)
        {
            using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var serializer = new XmlSerializer(typeof(RecipeManagerData));
                var starage    = (RecipeManagerData)serializer.Deserialize(fileStream);

                List <Recipe> tmpRecipes = new List <Recipe>();
                foreach (var itemRecipe in starage.Recipes)
                {
                    IngredientStorage ingredients = new IngredientStorage();
                    Ingredient        tmpIngredient;
                    foreach (var itemIngredient in itemRecipe.Ingredients)
                    {
                        tmpIngredient = starage.Ingredients.FindLast(t => t.Name == itemIngredient.Name);
                        ingredients.Add(tmpIngredient);
                    }
                    DishCategory group  = starage.Groups.FindLast(t => t.Name == itemRecipe.Group.Name);
                    Recipe       recipe = Recipe.Create(itemRecipe.Description, group, ingredients, itemRecipe.RecipeSteps).Value;
                    tmpRecipes.Add(recipe);
                }
                starage.Recipes = tmpRecipes;
                return(starage);
            }
        }
        private void addButton_Click(object sender, System.EventArgs e)
        {
            AddIngredientForm formIngr = new AddIngredientForm(_storage.GetIngredient());

            formIngr.ShowDialog();

            if (formIngr.DialogResult == System.Windows.Forms.DialogResult.OK)
            {
                if (formIngr.Ingredient != null)
                {
                    for (int i = 0; i < formIngr.Ingredient.Length; i++)
                    {
                        _ingredient.Add(formIngr.Ingredient[i]);
                    }
                }
            }
        }