Пример #1
0
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (close != true)
            {
                e.Cancel = true;
                ___Errormessagelabel_.Visibility = Visibility.Visible;

                string message = "Please click the exit button to exit application";

                RecipeError EXITERROR = new RecipeError();
                EXITERROR.ErrorMsg = message;

                ___Errormessagelabel_.Content = EXITERROR.ErrorMsg;
            }
        }
Пример #2
0
        //private void InitializeRecipes()
        //{
        //  //RecipeItem recipe1 = new RecipeItem { RecipeName = "Test1", RecipeType = "AAA", Yield = "AAA", ServingSize = "111", Comments = "AAA", RecipeDirections = "AAA", Ingredients = "AAA"};
        //  //RecipeItem recipe2 = new RecipeItem { RecipeName = "Test2", RecipeType = "BBB", Yield = "BBB", ServingSize = "222", Comments = "BBB", RecipeDirections = "BBB", Ingredients = "BBB" };
        //  //RecipeItem recipe3 = new RecipeItem { RecipeName = "Test3", RecipeType = "CCC", Yield = "CCC", ServingSize = "333", Comments = "CCC", RecipeDirections = "CCC", Ingredients = "CCC" };

        //  //_recipes.AddRecipe(recipe1);
        //  //_recipes.AddRecipe(recipe2);
        //  //_recipes.AddRecipe(recipe3);
        //}

        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            KeywordWindow dialog = new KeywordWindow();

            // To pop the KeywordWindow in the center of parent window
            dialog.Owner = this;
            // If got a return value from dialog window
            if (dialog.ShowDialog() == true)
            {
                // If the string return is not empty
                if (dialog.SearchTerms.Length != 0 && dialog.SearchTerms.Replace("\t", "").Replace(" ", "").Length != 0)
                {
                    //success....
                    // Use StringSplitOptions.RemoveEmptyEntries to remove empty entries
                    string[] split = dialog.SearchTerms.Split(new char [] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                    List <Recipe> tempRecipes = new List <Recipe>();

                    foreach (Recipe r in ro.Recipes)
                    {
                        List <string> recipeStrings = new List <string>();
                        recipeStrings.Add(r.Title);
                        recipeStrings.Add(r.RecipeType);
                        recipeStrings.Add(r.ServingSize);
                        recipeStrings.Add(r.Yield);
                        recipeStrings.Add(r.Comment);
                        recipeStrings.Add(r.Directions);
                        recipeStrings.Add(AppendIngredientsToSingleString(SelectIngredients(r.RecipeID)));

                        if (SearchCore.SearchKeywords(split, recipeStrings))
                        {
                            tempRecipes.Add(r);
                        }
                    }

                    // If found something
                    if (tempRecipes.Count != 0)
                    {
                        TitleListBox.DataContext = tempRecipes;
                        // Clear selection after each search
                        TitleListBox.SelectedItem = null;
                        ClearDataContexts();
                        ___Errormessagelabel_.Visibility = Visibility.Hidden;
                    }
                    // If found nothing
                    else
                    {
                        ___Errormessagelabel_.Visibility = Visibility.Visible;

                        string message = "Item not found";

                        RecipeError SEARCHERROR = new RecipeError();
                        SEARCHERROR.ErrorMsg = message;

                        ___Errormessagelabel_.Content = SEARCHERROR.ErrorMsg;
                    }
                }
                else
                {
                    ___Errormessagelabel_.Visibility = Visibility.Visible;

                    string message = "Input error";

                    RecipeError SEARCHERROR = new RecipeError();
                    SEARCHERROR.ErrorMsg = message;

                    ___Errormessagelabel_.Content = SEARCHERROR.ErrorMsg;
                }
            }
            else
            {
                //message and label for ill forned text or error...
                ___Errormessagelabel_.Visibility = Visibility.Visible;

                string message = "Search canceled";

                RecipeError SEARCHERROR = new RecipeError();
                SEARCHERROR.ErrorMsg = message;

                ___Errormessagelabel_.Content = SEARCHERROR.ErrorMsg;
            }
        }