Ejemplo n.º 1
0
        public static void editMeal(string mealstr)
        {
            var meal = Data.Meals.First(s => s.Name == mealstr);

            var ingrIN = Data.Ingredients.Select(s => s.ToSelectItem(meal.Ingredients.Any(s2 => s2 == s))).ToList();

            var ingredientKeys = SelectItemFromListBox.ShowDialog(
                "Select ingredients you want to have in the meal. remove all ingredients to delete meal all together", "question",
                ingrIN, true, 0);

            if (ingredientKeys == null)
            {
                return;
            }

            if (ingredientKeys.Count == 0)
            {
                Data.RemoveMeal(meal);
            }
            else
            {
                var ingredients = Data.GetIngredientsByKeys(ingredientKeys);
                meal.Ingredients = ingredients;
            }

            UpdateFormFromData(true);
        }
Ejemplo n.º 2
0
        public static void editIngredient()
        {
            var ingr = baseform.editingrbox.SelectedItem.ToString();

            var cat = Data.Ingredients.FirstOrDefault(s => s.Name == ingr);

            if (cat == null)
            {
                return;
            }

            var ingrs = Data.IngredientCategories.Select(s => s.ToSelectItem(cat.Categories.Any(s2 => s2.Name == s.Name))).ToList();

            var catreturn =
                SelectItemFromListBox.ShowDialog(
                    "Select categories you want to have the ingredient in. remove all categories to delete ingredient all together",
                    "question", ingrs, true, 0);

            if (catreturn == null || catreturn.Any() == false)
            {
                Data.Ingredients.Remove(cat);
            }
            else
            {
                var cats = Data.IngredientCategories.Where(s => catreturn.Contains(s.Name)).ToList();
                cat.Categories = cats;
            }

            UpdateFormFromData(true);
        }
Ejemplo n.º 3
0
        public static void addIngredient()
        {
            var gsb    = new GetStringBox();
            var option = gsb.ShowDialog("Enter name for new ingredient", "question");

            if (string.IsNullOrEmpty(option))
            {
                return;
            }

            if (Data.Ingredients.Any(s => s.Name == option))
            {
                MessageBox.Show("Error, an ingredient with that name already exists");
                return;
            }

            var catSI = Data.IngredientCategories.Select(s2 => s2.ToSelectItem()).ToList();

            var catreturn = SelectItemFromListBox.ShowDialog("Select categories that include this ingredient", "question", catSI, true,
                                                             1);

            if (catreturn == null || catreturn.Count == 0)
            {
                return;
            }

            var cats = Data.IngredientCategories.Where(s => catreturn.Contains(s.Name)).ToList();

            Data.AddIngredient(new Ingredient(option, cats));

            UpdateFormFromData(true);
        }
Ejemplo n.º 4
0
        public static void addMeal()
        {
            var gsb      = new GetStringBox();
            var mealname = gsb.ShowDialog("Enter name for new meal", "question");

            if (string.IsNullOrEmpty(mealname))
            {
                return;
            }

            var catreturn = SelectItemFromListBox.ShowDialog("Select category of this meal", "question", Data.MealCategories.Select(s => s.ToSelectItem()).ToList(), false, 1);

            if (catreturn == null || catreturn.Count == 0)
            {
                return;
            }
            var category = catreturn[0];

            if (Data.Meals.Any(s => s.Name == mealname))
            {
                MessageBox.Show("Error, meal with this name already exists in the category");
                return;
            }

            var ingredientKeys = SelectItemFromListBox.ShowDialog("Select ingredients in this meal", "question",
                                                                  Data.Ingredients.Select(s => s.ToSelectItem()).ToList(), true, 1);

            if (ingredientKeys == null || ingredientKeys.Count == 0)
            {
                Data.AddMeal(new Meal(mealname, category));
                return;
            }

            var ingredients = Data.GetIngredientsByKeys(ingredientKeys);

            Data.AddMeal(new Meal(mealname, category, ingredients));
            UpdateFormFromData(true);
        }
Ejemplo n.º 5
0
        public static void EditIngredientCategory()
        {
            const string cr   = "Create";
            const string ren  = "Rename";
            const string del  = "Delete";
            const string canc = "Cancel";
            //get options type

            var ls = new List <string>();

            ls.Add(cr);
            ls.Add(ren);
            ls.Add(del);
            ls.Add(canc);

            var mmb = new MultipleMessageBox("Edit Category", "Choose Mode", ls);

            mmb.ShowDialog();

            if (mmb.IsSet == false || mmb.Result == canc)
            {
                return;
            }

            var cats = Data.IngredientCategories.Select(s2 => s2.ToSelectItem()).ToList();

            if (mmb.Result.Equals(cr))
            {
                var gsb = new GetStringBox();
                var res = gsb.ShowDialog("Enter Category Name to create:", "Edit Category");
                if (string.IsNullOrWhiteSpace(res))
                {
                    return;
                }
                if (Data.IngredientCategories.Any(s => s.Name == res))
                {
                    MessageBox.Show("Error, a category with that name already exists");
                    return;
                }

                Data.IngredientCategories.Add(new IngredientCategory(res));
            }

            else if (mmb.Result.Equals(ren))
            {
                var res = SelectItemFromListBox.ShowDialog("Select category to rename", "Rename Category", cats, false,
                                                           1);
                if (res == null)
                {
                    return;
                }

                var rename = new GetStringBox();
                var res2   = rename.ShowDialog("Enter new category name", "Rename Category");

                if (string.IsNullOrWhiteSpace(res2))
                {
                    return;
                }

                if (Data.IngredientCategories.Any(s => s.Name == res2))
                {
                    MessageBox.Show("Error, a category with that name already exists");
                    return;
                }

                try
                {
                    var cat = Data.IngredientCategories.First(s => s.Name == res.First());
                    cat.Name = res2;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An error occured:" + ex);
                    return;
                }
            }

            else if (mmb.Result.Equals(del))
            {
                var res = SelectItemFromListBox.ShowDialog("Select category to delete", "Delete Category", cats, true, 1);
                if (res == null)
                {
                    return;
                }

                foreach (var cat in res)
                {
                    var cat1 = Data.IngredientCategories.First(s => s.Name == cat);
                    Data.RemoveIngredientCategory(cat1);
                }
            }

            UpdateFormFromData(true);
        }