Exemplo n.º 1
0
        private void BtnAddToLookup_Click(object sender, RoutedEventArgs e)
        {
            bool          success = false;
            List <string> validateResults;

            ingredients.Ingredient = new Ingredient
            {
                Name = TbIngredient.Text
            };

            validateResults = ingredients.Validate(ingredients.Ingredient);

            if (validateResults.Count == 0)
            {
                success = ingredients.Add(ingredients.Ingredient);
            }

            if (success)
            {
                ClearNewIngredient();
                RefreshIngredients();
                LbIngredients.SelectedItem = ingredients.Ingredient;
                LbIngredients.ScrollIntoView(LbIngredients.SelectedItem);

                ;
            }
            else
            {
                MessageBox.Show("There are problems with your ingredient:\r\n" + string.Join("\r\n", validateResults.ToArray()), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Set default state of Recipe Ingredients
 /// Deselect Recipe Ingredients Listbox and disable "Add to Recipe" button.
 /// </summary>
 private void ClearNewRecipeIngredients()
 {
     LbIngredients.UnselectAll();
     TbQuantity.Text = "";
     BtnAddRecipeIngredient.IsEnabled    = false;
     BtnRemoveRecipeIngredient.IsEnabled = false;
 }
 public void Clear()
 {
     TbIngredient.Text = "";
     LbIngredients.UnselectAll();
     Ingredients.Current = null;
     BtnSave.Content     = "Add";
     BtnDelete.IsEnabled = false;
     BtnClear.IsEnabled  = false;
 }