示例#1
0
 public Recipe(string name, List <string> ingredients, List <string> instructions, RecipeType type)
 {
     this.Name         = name;
     this.Ingredients  = ingredients;
     this.Instructions = instructions;
     this.Type         = type;
 }
示例#2
0
        public static List <RecipeType> GetRecipeType()
        {
            List <RecipeType> recipesTypes = new List <RecipeType>();
            string            filePath     = @"..\..\TextFiles\RecipeTypes.txt";
            string            line;

            try
            {
                using (StreamReader reader = new StreamReader(filePath))
                {
                    while ((line = reader.ReadLine()) != null)
                    {
                        string[] recipeTypeArray = line.Split(',');

                        foreach (string recipeType in recipeTypeArray)
                        {
                            RecipeType type = new RecipeType(recipeType);

                            recipesTypes.Add(type);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler error = new ErrorHandler(ex);
                error.LogException();
            }

            return(recipesTypes);
        }
示例#3
0
        public static List <Recipe> GetRecipes()
        {
            List <Recipe> recipes  = new List <Recipe>();
            string        filePath = @"..\..\TextFiles\Recepies.txt";
            string        line;

            try
            {
                using (StreamReader reader = new StreamReader(filePath))
                {
                    while ((line = reader.ReadLine()) != null)
                    {
                        string[] recipeArray = line.Split('#');

                        RecipeType type   = new RecipeType(recipeArray[3]);
                        Recipe     recipe = new Recipe(recipeArray[0], recipeArray[1].Split('-').ToList(), recipeArray[2].Split('-').ToList(), type);

                        recipes.Add(recipe);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler error = new ErrorHandler(ex);
                error.LogException();
            }

            return(recipes);
        }
示例#4
0
        public static void AddRecipeType(RecipeType recipeType)
        {
            StringBuilder sbRecipeType = new StringBuilder();
            string        filePath     = @"..\..\TextFiles\RecipeTypes.txt";
            string        line;
            bool          recpieTypeExist = false;

            try
            {
                using (StreamReader reader = new StreamReader(filePath))
                {
                    while ((line = reader.ReadLine()) != null)
                    {
                        string[] recipeTypeArray = line.Split(',');

                        foreach (string type in recipeTypeArray)
                        {
                            if (type == recipeType.Type)
                            {
                                recpieTypeExist = true;
                                break;
                            }
                            else
                            {
                                sbRecipeType.Append(type + ",");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler error = new ErrorHandler(ex);
                error.LogException();
            }

            if (recpieTypeExist)
            {
                MessageBox.Show("En recepttype med det namnet finns redan.");
            }
            else
            {
                try
                {
                    sbRecipeType.Append(recipeType.Type);

                    using (StreamWriter writer = new StreamWriter(filePath))
                    {
                        writer.Write(sbRecipeType.ToString());
                    }
                }
                catch (Exception ex)
                {
                    ErrorHandler error = new ErrorHandler(ex);
                    error.LogException();
                }
            }
        }
示例#5
0
        public static void UpdateRecipe(string headline, List <string> ingredients, List <string> instructions, RecipeType type)
        {
            StringBuilder sb          = new StringBuilder();
            List <string> updatedList = new List <string>();
            string        filePath    = @"..\..\TextFiles\Recepies.txt";
            string        line;

            try
            {
                using (StreamReader reader = new StreamReader(filePath))
                {
                    while ((line = reader.ReadLine()) != null)
                    {
                        string[] recipeCheck = line.Split('#');

                        if (recipeCheck[0] == headline)
                        {
                            sb.Append(headline);

                            sb.Append("#");
                            foreach (string ingredient in ingredients)
                            {
                                sb.Append(ingredient + "-");
                            }

                            sb.Append("#");
                            foreach (string instruction in instructions)
                            {
                                sb.Append(instruction + "-");
                            }

                            sb.Append(type.Type);

                            updatedList.Add(sb.ToString());
                        }
                        else
                        {
                            updatedList.Add(line);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler error = new ErrorHandler(ex);
                error.LogException();
            }

            try
            {
                using (StreamWriter writer = new StreamWriter(filePath))
                {
                    foreach (string recipe in updatedList)
                    {
                        writer.WriteLine(recipe);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler error = new ErrorHandler(ex);
                error.LogException();
            }
        }