コード例 #1
0
        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            Recipe recipe = new Recipe();

            recipe.Name   = Title.Text;
            recipe.Avatar = "/Images/" + System.IO.Path.GetFileName(filePathNewAvatar);
            recipe.Step   = steps;


            recipe.Ingredients = new string[]
            {
                Ingredents.Text,
            };
            recipe.VideoLink = Youtube.Text;
            recipe.Favorite  = false;
            bool result = RecipeDAO.AddRecipe(recipe);

            if (result == true)
            {
                MessageBox.Show("Add Recipe Success", "Notice", MessageBoxButton.OK);
            }
            else
            {
                MessageBox.Show("Add Recipe Failed", "Notice", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #2
0
        private void BindingFood(object sender, RoutedEventArgs e)
        {
            if (MainWindow.boolSearch == 0)
            {
                recipes   = RecipeDAO.getAllRecipesFromJson();
                totalItem = recipes.Count();

                int floor = totalItem / itemPerPage;
                totalPage = (totalItem % itemPerPage == 0) ? floor : (floor + 1);

                //MessageBox.Show(totalItem.ToString());

                if (recipes != null)
                {
                    DataListview.ItemsSource = getNextPageItems();
                }
                pageInfo.Text = $"{currentPage}/{totalPage}";
            }
            else
            {
                recipes   = RecipeDAO.SearchRecipe(MainWindow.dataSearch);
                totalItem = recipes.Count();

                int floor = totalItem / itemPerPage;
                totalPage = (totalItem % itemPerPage == 0) ? floor : (floor + 1);

                //MessageBox.Show(totalItem.ToString());

                if (recipes != null)
                {
                    DataListview.ItemsSource = getNextPageItems();
                }
                pageInfo.Text = $"{currentPage}/{totalPage}";
            }
        }
コード例 #3
0
        private void Favorite_Handler(bool isFavorite)
        {
            Recipe recipe = (FavoriteListView.SelectedItem as Recipe);

            recipe.Favorite = isFavorite;

            RecipeDAO.UpdateListRecipes(recipe);
            showFavoriteList();
        }
コード例 #4
0
        public static List <Recipe> SearchRecipe(string searchName)
        {
            List <Recipe> recipes = RecipeDAO.getAllRecipesFromJson();
            var           query   = from c in recipes
                                    where c.Name.ToLower().Contains(searchName)
                                    select c;

            return(query.ToList());
        }
コード例 #5
0
        private void Favorite_Handler(bool isFavorite)
        {
            Recipe recipe = (DataListview.SelectedItem as Recipe);

            if (recipe.Favorite != isFavorite)
            {
                recipe.Favorite = isFavorite;
                RecipeDAO.UpdateListRecipes(recipe);
            }
            //MessageBox.Show(recipe.Name, (isFavorite) ? "true" : "false");
        }
コード例 #6
0
        private void showFavoriteList()
        {
            favoriteRecipes = RecipeDAO.getFavoriteRecipesFromJson();
            if (favoriteRecipes != null)
            {
                currentPage = 0;
                totalItem   = favoriteRecipes.Count();
                int floor = totalItem / itemPerPage;
                totalPage = (totalItem % itemPerPage == 0) ? floor : (floor + 1);

                FavoriteListView.ItemsSource = getNextPageItems();
                favoritePagingInfo.Text      = $"{currentPage}/{totalPage}";
            }
        }