private void GetIngredients(string text) { var listIngredients = MyStorage.ReadXml <List <Ingredient> >("IngredientData.xml"); var ingredients = new List <Ingredient>(); var ingredientListBegin = (from n in listIngredients where n.name.ToLower().StartsWith(text.ToLower()) select n.name).ToList(); var ingredientListContain = (from n in listIngredients where n.name.ToLower().Contains(text.ToLower()) select n.name).ToList(); ingredientListBegin.Sort(); ingredientListContain.Sort(); ingredientListBegin.AddRange(ingredientListContain); var ingredientList = ingredientListBegin.Distinct().ToList(); foreach (var ingAdded in recipeIngredients) { if (ingredientList.Contains(ingAdded.ingredientName)) { ingredientList.Remove(ingAdded.ingredientName); } } if (ingredientList.Count() > 0) { Lbx_ingredient.ItemsSource = ingredientList.Take(5); } else { Lbx_ingredient.Visibility = Visibility.Collapsed; Lbx_ingredient.ItemsSource = null; } }
private void MakeUpdateToRecipe() { var recipe = (from n in listInput where n.id == Convert.ToInt32(selectedRecipe.id) select n).FirstOrDefault(); listInput.Remove(recipe); listInput.Add(selectedRecipe); MyStorage.WriteXml <ObservableCollection <Recipe> >(listInput, "InputData.xml"); }
private void CreateXMLData() { var listInput = MyStorage.ReadXml <List <Recipe> >("InputData.xml"); var recipes = new List <Recipe>(); //initial load var recipeList = (from n in listInput where n.ingredients.Count > 0 select n).Take(20).ToList(); }
private void StarImage_MouseDown(object sender, MouseButtonEventArgs e) { var recipeId = ((((sender as TextBlock).Parent as StackPanel).Parent as StackPanel).Children[0] as TextBlock).Text; var listInput = MyStorage.ReadXml <List <Recipe> >("InputData.xml"); var recipe = (from n in listInput where n.id == Convert.ToInt32(recipeId) select n).FirstOrDefault(); recipe.isFavorite = recipe.isFavorite == true ? false : true; MyStorage.WriteXml <List <Recipe> >(listInput, "InputData.xml"); GetRecipes(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { recipes = MyStorage.ReadXml <ObservableCollection <Recipe> >("InputData.xml"); recipeIngredients = new ObservableCollection <RecipeIngredient>(); if (selectedRecipe != null) { selectedRecipe.instruction = selectedRecipe.instruction.Replace("\\n", "\n"); DataContext = selectedRecipe; if (selectedRecipe.ingredients.Count > 0) { recipeIngredients = new ObservableCollection <RecipeIngredient>(selectedRecipe.ingredients); Sp_Lbx_ingredients.Visibility = Visibility.Visible; Lbx_ingredients.ItemsSource = recipeIngredients; } } }
private void GetIngredients(string text) { var listIngredients = MyStorage.ReadXml <List <Ingredient> >("IngredientData.xml"); var ingredients = new List <Ingredient>(); //initial load var ingredientListBegin = (from n in listIngredients where n.name.ToLower().StartsWith(text.ToLower()) select n.name).ToList(); var ingredientListContain = (from n in listIngredients where n.name.ToLower().Contains(text.ToLower()) select n.name).ToList(); ingredientListBegin.Sort(); ingredientListContain.Sort(); ingredientListBegin.AddRange(ingredientListContain); var ingredientList = ingredientListBegin.Distinct().ToList(); foreach (var button in (Sp_filterIngredients as StackPanel).Children) { var buttonTxt = GetButtonContent(button); if (ingredientList.Contains(buttonTxt)) { ingredientList.Remove(buttonTxt); } } if (ingredientList.Count() > 0) { Lbx_ingredient.ItemsSource = ingredientList.Take(5); //Tbx_ingredient.BorderBrush = Brushes.Black; } else { Lbx_ingredient.Visibility = Visibility.Collapsed; Lbx_ingredient.ItemsSource = null; //Tbx_ingredient.BorderBrush = Brushes.Red; } }
private void Window_Loaded(object sender, RoutedEventArgs e) { listInput = MyStorage.ReadXml <ObservableCollection <Recipe> >("InputData.xml"); SetRecipeDetail(); }
private int SaveRecipe(bool fromSave) { if (Tbx_recipeName.Text != "" || Tbx_recipeDescription.Text.Trim() != "" || Tbx_instructions.Text.Trim() != "" || Tbx_image.Text != "" || Lbx_ingredients.Items.Count > 0) { storeData = true; } else { storeData = false; } if (storeData) { if (Tbx_recipeName.Text != "") { string imagePath = Tbx_image.Text; string destPath = imagePath; if (imagePath != "") { string[] parts = imagePath.Split('\\'); if (parts[0] != "") { string imageName = parts[parts.Length - 1]; destPath = @"\Images\" + imageName; string currentDirectory = System.Environment.CurrentDirectory; if (currentDirectory.EndsWith("\\bin\\Debug")) { int index = currentDirectory.IndexOf("\\bin\\Debug"); currentDirectory = currentDirectory.Substring(0, index); } File.Copy(imagePath, currentDirectory + destPath, true); } else { destPath = imagePath; } } if (!isEdit) { var id = recipes.Max(m => m.id); recipes.Add(new Recipe { isMyRecipe = true, name = Tbx_recipeName.Text, description = Tbx_recipeDescription.Text, id = id + 1, timeRequiredHours = Cbx_hours.SelectedValue.ToString(), timeRequiredMinutes = Cbx_minutes.SelectedValue.ToString(), servings = Cbx_servings.SelectedValue.ToString(), instruction = Tbx_instructions.Text, ingredients = recipeIngredients.ToList(), isFavorite = Cbx_markFavorite.IsChecked.GetValueOrDefault(), image = imagePath == "" ? @"\Images\noimage.jpg" : destPath }); var recipeList = recipes.ToList(); MyStorage.WriteXml <List <Recipe> >(recipeList, "InputData.xml"); MessageBox.Show("Your recipe has been added to the cookbook."); } else { var listInput = MyStorage.ReadXml <List <Recipe> >("InputData.xml"); var recipe = (from n in listInput where n.id == Convert.ToInt32(selectedRecipe.id) select n).FirstOrDefault(); selectedRecipe.ingredients = recipeIngredients.ToList(); selectedRecipe.image = destPath; listInput.Remove(recipe); listInput.Add(selectedRecipe); MyStorage.WriteXml <List <Recipe> >(listInput, "InputData.xml"); } return(1); } else { if (!fromSave) { MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("You need to enter a recipe name to save the recipe. Click yes to enter the name.", "Save recipe confirmation", System.Windows.MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.No || messageBoxResult == MessageBoxResult.Cancel || messageBoxResult == MessageBoxResult.None) { return(1); } else if (messageBoxResult == MessageBoxResult.Yes) { Tbx_recipeName.Focus(); return(0); } } else { MessageBox.Show("Please enter a recipe name to save the recipe.", ":|", MessageBoxButton.OK, MessageBoxImage.Error); Tbx_recipeName.Focus(); return(0); } } } return(1); }
private Ingredient GetIngDetail(string ingredient, bool getType) { var listIngredients = MyStorage.ReadXml <List <Ingredient> >("IngredientData.xml"); return((from l in listIngredients where l.name.ToLower().Equals(ingredient.ToLower()) select l).FirstOrDefault()); }
private void CreateXMLData() { #region recipes List <Recipe> recipes = new List <Recipe>(); recipes = new List <Recipe> { new Recipe { id = 1, name = "Potato Curry", description = "A simple and easy-to-make potato curry.", servings = "4", timeRequired = "00:30", instruction = @"1. Add the coconut oil to large skillet on medium heat. Add minced garlic. 2. Once garlic is fragrant, add diced onion and cook until starting to turn translucent, about 5 minutes. 3. Add coconut milk, diced tomatoes, ginger, maple syrup, and spices. Stir to combine. 4. Bring to a low simmer and add potatoes. 5. Cover and let simmer on low/medium until potatoes are softened, 10 - 15 minutes. 6. Add frozen peas, stir, and let sit for 5 minutes. 7. Stir again and serve. ", ingredients = new List <RecipeIngredient> { new RecipeIngredient { ingredientId = 1, ingredientName = "Potato", ingredientType = "solid", quantity = "250", measure = "gram(s)", recipeId = 0 }, new RecipeIngredient { ingredientId = 2, ingredientName = "Coconut oil", ingredientType = "cream", quantity = "1", measure = "tablespoon(s)" }, new RecipeIngredient { ingredientId = 3, ingredientName = "Onion(s)", ingredientType = "solid", quantity = "200", measure = "gram(s)" }, new RecipeIngredient { ingredientId = 4, ingredientName = "Tomato(s)", ingredientType = "solid", quantity = "200", measure = "gram(s)" }, new RecipeIngredient { ingredientId = 5, ingredientName = "Coconut milk", ingredientType = "solid", quantity = "200", measure = "ml" }, new RecipeIngredient { ingredientId = 6, ingredientName = "Curry powder", ingredientType = "spice", quantity = "200", measure = "ml" }, new RecipeIngredient { ingredientId = 7, ingredientName = "Turmeric", ingredientType = "spice", quantity = "200", measure = "ml" }, new RecipeIngredient { ingredientId = 8, ingredientName = "Salt", ingredientType = "spice", quantity = "1", measure = "teaspoon(s)" }, new RecipeIngredient { ingredientId = 9, ingredientName = "Chilli powder", ingredientType = "spice", quantity = "1", measure = "teaspoon(s)" }, new RecipeIngredient { ingredientId = 10, ingredientName = "Curry powder", ingredientType = "spice", quantity = "1", measure = "teaspoon(s)" }, new RecipeIngredient { ingredientId = 11, ingredientName = "Garlic powder", ingredientType = "spice", quantity = "1", measure = "teaspoon(s)" }, new RecipeIngredient { ingredientId = 12, ingredientName = "Ginger powder", ingredientType = "spice", quantity = "1", measure = "teaspoon(s)" } }, isMyRecipe = false, isFavorite = false, image = @"Images\easy-potato-curry-1.jpg", }, new Recipe { id = 2, name = "Oven-Roasted Potatoes", description = "A side dish that goes along with roasted chicken, lamb chops and almost anything!", servings = "4", timeRequired = "00:30", instruction = @"1. Heat oven to 425°F. In an ungreased 15x10x1-inch pan, mix all ingredients; spread evenly. 2. Roast uncovered 25 to 35 minutes, stirring occasionally, until potatoes are tender and browned.", ingredients = new List <RecipeIngredient> { new RecipeIngredient { ingredientId = 1, ingredientName = "Potato", ingredientType = "solid", quantity = "250", measure = "gram(s)", recipeId = 0 }, new RecipeIngredient { ingredientId = 2, ingredientName = "Vegetable or olive oil", ingredientType = "cream", quantity = "2", measure = "tablespoon(s)" }, new RecipeIngredient { ingredientId = 3, ingredientName = "Rosemary leaves", ingredientType = "spice", quantity = "1", measure = "teaspoon(s)" }, new RecipeIngredient { ingredientId = 4, ingredientName = "Salt", ingredientType = "spice", quantity = "0.5", measure = "teaspoon(s)" }, new RecipeIngredient { ingredientId = 5, ingredientName = "Pepper powder", ingredientType = "spice", quantity = "0.5", measure = "teaspoon(s)" } }, isMyRecipe = false, isFavorite = false, image = @"", } }; MyStorage.WriteXml <List <Recipe> >(recipes, "RecipeData.xml"); #endregion recipes #region ingredient List <Ingredient> ingredient = new List <Ingredient>(); ingredient = new List <Ingredient> { new Ingredient { id = 1, name = "Potato", type = "solid" }, new Ingredient { id = 2, name = "Coconut oil", type = "creamy" }, new Ingredient { id = 3, name = "Onion", type = "solid" }, new Ingredient { id = 4, name = "Tomato", type = "solid" }, new Ingredient { id = 5, name = "Rosemary leaves", type = "spice" }, new Ingredient { id = 6, name = "Salt", type = "spice" }, new Ingredient { id = 7, name = "Pepper powder", type = "spice" }, new Ingredient { id = 8, name = "Coconut milk", type = "creamy" }, new Ingredient { id = 9, name = "Curry powder", type = "spice" }, new Ingredient { id = 10, name = "Turmeric", type = "spice" }, new Ingredient { id = 11, name = "Chilli powder", type = "spice" }, new Ingredient { id = 12, name = "Garlic powder", type = "spice" }, new Ingredient { id = 13, name = "Ginger powder", type = "spice" }, new Ingredient { id = 14, name = "Olive oil", type = "creamy" }, new Ingredient { id = 15, name = "Vegetable oil", type = "creamy" }, new Ingredient { id = 16, name = "Sugar", type = "creamy" }, new Ingredient { id = 17, name = "Chicken", type = "solid" } }; MyStorage.WriteXml <List <Ingredient> >(ingredient, "IngredientData.xml"); #endregion ingredient }
private void GetRecipes() { var ingredient1 = ""; var ingredient2 = ""; var ingredient3 = ""; for (int i = 0; i < (Sp_filterIngredients as StackPanel).Children.Count; i++) { var button = (Sp_filterIngredients as StackPanel).Children[i] as Button; if (i == 0) { ingredient1 = GetButtonContent(button); } else if (i == 1) { ingredient2 = GetButtonContent(button); } else { ingredient3 = GetButtonContent(button); } } var listInput = MyStorage.ReadXml <List <Recipe> >("InputData.xml"); var recipes = new List <Recipe>(); //initial load var recipeList = (from n in listInput where n.isDelete == false select n).Take(20).ToList(); //filter by ingredients if (ingredient1 != "") { var recipeListFilter1 = (from n in listInput where n.isDelete == false & n.ingredients.Count > 0 from m in n.ingredients where m.ingredientName.ToLower().Contains(ingredient1.ToLower()) select n).ToList(); if (ingredient3 == "" && ingredient2 == "") { recipes = recipeListFilter1; } else { var recipeListFilter2 = (from n in recipeListFilter1 from m in n.ingredients where m.ingredientName.ToLower().Contains(ingredient2.ToLower()) select n).ToList(); if (ingredient3 == "") { recipes = recipeListFilter2; } else { var recipeListFilter3 = (from n in recipeListFilter2 from m in n.ingredients where m.ingredientName.ToLower().Contains(ingredient3.ToLower()) select n).ToList(); recipes = recipeListFilter3; } } } else { recipes = recipeList; } recipes = Cbx_getFavorites.IsChecked == true?recipes.Where(r => r.isFavorite == true).ToList() : recipes; recipes = Cbx_getMyRecipes.IsChecked == true?recipes.Where(r => r.isMyRecipe == true).ToList() : recipes; if (Tbx_filterName.Text.Length >= 1) { recipes = recipes.Where(r => r.name.ToLower().Contains(Tbx_filterName.Text.ToLower())).ToList(); } if (recipes.Count > 0) { recipes = recipes.OrderBy(r => r.name).ToList(); var observableRecipe = new ObservableCollection <Recipe>(recipes); Lbx_Items_Recipes.Visibility = Visibility.Visible; Lbx_Items_Recipes.ItemsSource = recipes; Tbk_RecipeListEmpty.Visibility = Visibility.Collapsed; Tbk_recipeListTitle.Visibility = Visibility.Visible; } else { Lbx_Items_Recipes.Visibility = Visibility.Collapsed; Lbx_Items_Recipes.ItemsSource = null; Tbk_RecipeListEmpty.Visibility = Visibility.Visible; Tbk_recipeListTitle.Visibility = Visibility.Collapsed; } }