Beispiel #1
0
        //Handles saving the newly created Recipe
        private void BTN_SaveRecipe(object sender, RoutedEventArgs e)
        {
            RecipeDef NewRecipeDef = new RecipeDef();

            NewRecipeDef.TimeTags = new List <string>();
            NewRecipeDef.UserTags = new List <string>();

            if (!string.IsNullOrWhiteSpace(US_NameInput.Text) && !string.IsNullOrWhiteSpace(BG_NameInput.Text))
            {
                NewRecipeDef.USName = US_NameInput.Text.ToString();
                NewRecipeDef.BGName = BG_NameInput.Text.ToString();
            }

            if (!string.IsNullOrWhiteSpace(US_Directions.Text) && !string.IsNullOrWhiteSpace(BG_Directions.Text))
            {
                NewRecipeDef.USDirections = US_Directions.Text.ToString();
                NewRecipeDef.BGDirections = BG_Directions.Text.ToString();
            }

            if (!string.IsNullOrWhiteSpace(TB_ImageNameInput.Text))
            {
                NewRecipeDef.ImageFile = TB_ImageNameInput.Text.ToString() + ".jpg";
            }

            if (CB_Breakfast.IsChecked == true)
            {
                NewRecipeDef.TimeTags.Add(RecipeManager.BreakfastTag);
            }

            if (CB_Lunch.IsChecked == true)
            {
                NewRecipeDef.TimeTags.Add(RecipeManager.LunchTag);
            }

            if (CB_Dinner.IsChecked == true)
            {
                NewRecipeDef.TimeTags.Add(RecipeManager.DinnerTag);
            }

            if (int.TryParse(TB_RecipeCalorieInput.Text, out int parsedValue1))
            {
                NewRecipeDef.Calories = int.Parse(TB_RecipeCalorieInput.Text);
            }


            if (!string.IsNullOrWhiteSpace(TB_TimeToCook.Text))
            {
                NewRecipeDef.TimeToCook = TB_TimeToCook.Text.ToString();
            }

            foreach (CheckBox element in SettingOptions)
            {
                if (element.IsChecked == true)
                {
                    NewRecipeDef.UserTags.Add(CompatabilityMap[SettingOptions.IndexOf(element)]);
                }
            }

            if (USIngredients.Count > 0 && BGIngredients.Count > 0 && Amounts.Count > 0 && UnitsToAdd.Count == Amounts.Count && Amounts.Count == USIngredients.Count && Amounts.Count == BGIngredients.Count)
            {
                NewRecipeDef.USIngredients = USIngredients;
                NewRecipeDef.BGIngredients = BGIngredients;
                NewRecipeDef.Units         = UnitsToAdd;
                NewRecipeDef.Amounts       = Amounts;
            }

            if (NewRecipeDef.USIngredients.Count == NewRecipeDef.Amounts.Count && NewRecipeDef.BGIngredients.Count == NewRecipeDef.Amounts.Count && NewRecipeDef.Amounts.Count == NewRecipeDef.Units.Count)
            {
                if (!RecipeList.ContainsKey(NewRecipeDef.USName.ToLower()))
                {
                    RecipeList.Add(NewRecipeDef.USName.ToLower(), NewRecipeDef);
                    SaveRecipeList();
                    RecipeList = GetRecipies();

                    if (RecipeList.ContainsKey(NewRecipeDef.USName.ToLower()))
                    {
                        NewRecipeDef = new RecipeDef();

                        USIngredients = new List <string>();
                        BGIngredients = new List <string>();
                        Amounts       = new List <float>();
                        UnitsToAdd    = new List <string>();
                        US_FoodName.Clear();
                        BG_FoodName.Clear();

                        foreach (CheckBox element in SettingOptions)
                        {
                            element.IsChecked = false;
                        }

                        foreach (CheckBox element in SettingOptions)
                        {
                            element.IsChecked = false;
                        }

                        US_IngredientList.Items.Clear();
                        BG_IngredientList.Items.Clear();
                        AmountListbox.Items.Clear();
                        TB_ImageNameInput.Clear();
                        TB_RecipeCalorieInput.Clear();
                        TB_TimeToCook.Clear();
                    }
                }
            }
        }
Beispiel #2
0
        //Handles saving the newly created FooDef
        private void Btn_SaveFoodItem_Click(object sender, RoutedEventArgs e)
        {
            FoodDef NewFoodItem = new FoodDef();

            if (!string.IsNullOrWhiteSpace(US_FoodName.Text))
            {
                NewFoodItem.USName = US_FoodName.Text.ToLower();
            }

            if (!string.IsNullOrWhiteSpace(BG_FoodName.Text))
            {
                NewFoodItem.BGName = BG_FoodName.Text.ToLower();
            }

            if (float.TryParse(tb_CalorieInput.Text, out float parsedValue))
            {
                NewFoodItem.Calories = float.Parse(tb_CalorieInput.Text);
            }

            if (float.TryParse(tb_ProteinInput.Text, out float parsedValue1))
            {
                NewFoodItem.Protein = float.Parse(tb_ProteinInput.Text);
            }

            if (float.TryParse(tb_FatInput.Text, out float parsedValue2))
            {
                NewFoodItem.Fat = float.Parse(tb_FatInput.Text);
            }

            if (float.TryParse(tb_CarbInput.Text, out float parsedValue3))
            {
                NewFoodItem.Carbs = float.Parse(tb_CarbInput.Text);
            }


            if (float.TryParse(tb_SugarInput.Text, out float parsedValue4))
            {
                NewFoodItem.Sugars = float.Parse(tb_SugarInput.Text);
            }

            if (float.TryParse(tb_SodiumInput.Text, out float parsedValue5))
            {
                NewFoodItem.Sodium = float.Parse(tb_SodiumInput.Text);
            }

            if (float.TryParse(Tb_DesityInput.Text, out float parsedValue6))
            {
                NewFoodItem.FoodDensity = float.Parse(Tb_DesityInput.Text);
            }

            if (!string.IsNullOrWhiteSpace(US_UOMInput.Text))
            {
                NewFoodItem.USUOM = US_UOMInput.Text;
            }


            if (!string.IsNullOrWhiteSpace(BG_UOMInput.Text))
            {
                NewFoodItem.BGUOM = BG_UOMInput.Text;
            }

            if (SuggestedAmounts != null && SuggestedAmounts.Count > 0)
            {
                NewFoodItem.SuggestedAmounts = SuggestedAmounts;
            }

            if (NewFoodItem.USName != null)
            {
                FoodList.Add(NewFoodItem.USName.ToLower(), NewFoodItem);
            }

            SaveFoodList();
            FoodList = GetFoodList();

            BG_UOMInput.Clear();
            US_UOMInput.Clear();
            tb_CalorieInput.Clear();
            tb_CarbInput.Clear();
            tb_FatInput.Clear();
            tb_ProteinInput.Clear();
            tb_SodiumInput.Clear();
            tb_SugarInput.Clear();
            US_FoodName.Clear();
            Lb_SuggestedAmounts.Items.Clear();
            SuggestedAmounts = new List <float>();
            BG_FoodName.Clear();
            Lb_SuggestedAmounts.Items.Clear();
        }