private async void buttonInsecticideDelete_Click(object sender, RoutedEventArgs e) { if (listInsecticides.SelectedIndex == -1) { return; } MessageBoxResult result = MessageBox.Show("Are you sure you want to delete this Insecticide?", "Are you sure?", MessageBoxButton.OKCancel); if (result == MessageBoxResult.OK) { Insect insect = Insects.ElementAt(listInsects.SelectedIndex); insect.InsecticideIds.RemoveAt(listInsecticides.SelectedIndex); await insect.SaveAsync(); Insecticide i = LoadedInsecticides.ElementAt(listInsecticides.SelectedIndex); Insecticides.Remove(i); LoadedInsecticides.Remove(i); labelInsecticides.Content = insect.Name + ": Insecticides (" + LoadedInsecticides.Count + ")"; if (LoadedInsecticides.Count == 0) { labelNoInsecticides.Visibility = Visibility.Visible; } await i.DeleteAsync(); MessageBox.Show("Insecticide deleted."); } }
public InsectObjectEditor(Insect i) { InitializeComponent(); CurrentInsect = i; textBoxName.Text = i.Name; textBoxName.TextChanged += delegate { CurrentInsect.Name = textBoxName.Text; }; textBoxCategory.Text = i.Category; textBoxCategory.TextChanged += delegate { CurrentInsect.Category = textBoxCategory.Text; }; textBoxDescription.Text = i.Description; textBoxDescription.TextChanged += delegate { CurrentInsect.Description = textBoxDescription.Text; }; this.Closing += async delegate { await CurrentInsect.SaveAsync(); }; GetPictures(); }
private async void buttonInsectAdd_Click(object sender, RoutedEventArgs e) { Insect i = new Insect() { InsectId = GetFirstInsectId(), PictureId = -1 }; await i.SaveAsync(); Insects.Add(i); listInsects.SelectedIndex = Insects.Count - 1; InsectObjectEditor window = new InsectObjectEditor(i); window.Closing += async delegate { await i.SaveAsync(); labelInsects.Content = "Insects (" + Insects.Count + ")"; }; window.ShowDialog(); }