Ejemplo n.º 1
0
        public void addIngredientToRecipe(object sender, RoutedEventArgs e)
        {
            if (IngredientNameToAdd.Text == "")
            {
                //maybe add popup to add text
                return;
            }
            if (IngredientQuantityToAdd.Text == "")
            {
                return;
            }
            Measurement newMeasurement = new Measurement(int.Parse(IngredientQuantityToAdd.Text),
                                                         IngredientTypeToAdd.Text);

            Ingredient newIngredient = new Ingredient(newMeasurement,
                                                      IngredientDescriptionToAdd.Text,
                                                      IngredientNameToAdd.Text);

            m_recipe.Add_Ingredient(newIngredient);

            IngredientNameToAdd.Text        = "";
            IngredientQuantityToAdd.Text    = "";
            IngredientDescriptionToAdd.Text = "";
            IngredientTypeToAdd.Text        = "";

            Refresh();
        }
Ejemplo n.º 2
0
        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);
        }