Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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);
        }