private void ButtonFind_Click(object sender, RoutedEventArgs e) { if (this.RadioButtonFindByName.IsChecked == true) { using (var db = new Entities()) { var query = from animal in db.AnimalSet where animal.Name == this.TextBoxNameFind.Text select animal; if (query.Count<AnimalSet>() == 0) { MessageBox.Show("Тварин з таким іменем не знайдено."); this.DataGridAnimals.ItemsSource = null; } else { List<AnimalSet> findedAnimal = new List<AnimalSet>(); foreach (var item in query) { findedAnimal.Add(item); } this.DataGridAnimals.ItemsSource = findedAnimal; this.DataGridAnimals.Items.Refresh(); } } } else { if (this.RadioButtonFindByGreed.IsChecked == true) { using (var db = new Entities()) { var query = from animal in db.AnimalSet where animal.Breed == this.TextBoxBreedFind.Text select animal; if (query.Count<AnimalSet>() == 0) { MessageBox.Show("Тварин з такою породою не знайдено."); this.DataGridAnimals.ItemsSource = null; } else { List<AnimalSet> findedAnimal = new List<AnimalSet>(); foreach (var item in query) { findedAnimal.Add(item); } this.DataGridAnimals.ItemsSource = findedAnimal; this.DataGridAnimals.Items.Refresh(); } } } else { if (this.RadioButtonFindBySex.IsChecked == true) { using (var db = new Entities()) { var query = from animal in db.AnimalSet where animal.Sex == this.ComboBoxSexFind.Text select animal; if (query.Count<AnimalSet>() == 0) { MessageBox.Show("Тварин з такою статтю не знайдено."); this.DataGridAnimals.ItemsSource = null; } else { List<AnimalSet> findedAnimal = new List<AnimalSet>(); foreach (var item in query) { findedAnimal.Add(item); } this.DataGridAnimals.ItemsSource = findedAnimal; this.DataGridAnimals.Items.Refresh(); } } } } } }
private void buttonSave_Click(object sender, RoutedEventArgs e) { using (var db = new Entities()) { for (int i = 0; i < amount; i++) { var animalToAdd = new AnimalSet { Name = animal[i].Name, Breed = animal[i].Breed, Sex = animal[i].Sex}; db.AnimalSet.Add(animalToAdd); db.SaveChanges(); } } animal.Clear(); amount = 0; this.DataGridAnimals.ItemsSource = null; }