private void AddToSP(object sender, RoutedEventArgs e) { bool flag = false; Comida ad = new Comida(); foreach (Comida c in Globals.My) { if (c.Nome == ((Button)sender).Tag.ToString()) { ad = c; break; } } foreach (Comida d in Globals.Shopping) { if (d.Nome == ((Button)sender).Tag.ToString()) { flag = true; break; } } if (flag) { MessageBox.Show("Item already in Shopping List", "LarderManager", MessageBoxButton.OK, MessageBoxImage.Warning); } else { Globals.Shopping.Add(ad); checkState(Globals.My); MessageBox.Show("Item added to Shopping List", "Lardermanager", MessageBoxButton.OK, MessageBoxImage.Information); } //Globals.Shopping.Add(ad); //MessageBox.Show("Item added to Shopping List","Lardermanager",MessageBoxButton.OK,MessageBoxImage.Information); }
private void Button_Click_1(object sender, RoutedEventArgs e) { if (addIngredient.Text == "") { MessageBox.Show("No ingredient to add", "LarderManager", MessageBoxButton.OK, MessageBoxImage.Error); } else { Comida comida = new Comida { Nome = addIngredient.Text, Quantidade = 0, Estado = 0 }; bool flag = false; foreach (Comida c in Globals.Shopping) { if (String.Equals(comida.Nome, c.Nome, StringComparison.OrdinalIgnoreCase)) { flag = true; } } if (flag) { MessageBox.Show("Item already in Shopping List", "LarderManager", MessageBoxButton.OK, MessageBoxImage.Warning); } else { Globals.Shopping.Add(comida); } checkState(Globals.Shopping); //listaAlimentos.ItemsSource = Globals.Shopping; //addIngredient.Clear(); addIngredient.Text = "Add ingredient"; addIngredient.Foreground = new SolidColorBrush(Colors.Gray); } }