private void Back_Click(object sender, RoutedEventArgs e) { try { if (_modify) { Window browseWindow = new BrowseSpecimensWindow(); browseWindow.Left = this.Left; browseWindow.Top = this.Top; browseWindow.Show(); this.Close(); } else { Window mainWindow = new MainWindow(); mainWindow.Left = this.Left; mainWindow.Top = this.Top; mainWindow.Show(); this.Close(); } }catch (Exception x) { ShowError(x.Message); } }
private void Back_Click(object sender, RoutedEventArgs e) { Window browseWindow = new BrowseSpecimensWindow(); browseWindow.Left = this.Left; browseWindow.Top = this.Top; browseWindow.Show(); this.Close(); }
private void Save_Click(object sender, RoutedEventArgs e) { try { Dog specimen = null; if (_modify == false) { specimen = new Dog(); } else { specimen = context.Dogs.Where(x => x.DogId == _idToModify).SingleOrDefault(); } bool noFather = false; bool noMother = false; int? fatherId = null; int? motherId = null; Breeder breeder = null; Owner owner = null; //parents MessageBoxResult popupResult = MessageBoxResult.Yes; owner = context.Owners.Where(x => x.Name == this.OwnerName.Text.Trim() & x.Surname == this.OwnerSurname.Text.Trim() & x.Adderss == this.OwnerAdress.Text.Trim()).SingleOrDefault(); if (this.BreederName.Text.Trim().Length != 0 & this.BreederSurname.Text.Trim().Length != 0) { breeder = context.Breeders.Where(x => x.Name == this.BreederName.Text.Trim() & x.Surname == this.BreederSurname.Text.Trim()).SingleOrDefault(); if (breeder == null) { var pop = System.Windows.MessageBox.Show("Hodowca nie odnaleziony. Czy chcesz dodać do bazy?", "Brak hodowcy", System.Windows.MessageBoxButton.YesNo); if (pop == MessageBoxResult.No) { return; } else if (pop == MessageBoxResult.Yes) { breeder = new Breeder() { Name = this.BreederName.Text.Trim(), Surname = this.BreederSurname.Text.Trim() }; } } } if (this.OwnerName.Text.Trim().Length != 0 & this.OwnerSurname.Text.Trim().Length != 0 & this.OwnerAdress.Text.Trim().Length != 0) { owner = context.Owners.Where(x => x.Name == this.OwnerName.Text.Trim() & x.Surname == this.OwnerSurname.Text.Trim() & x.Adderss == this.OwnerAdress.Text.Trim()).SingleOrDefault(); if (owner == null) { var pop = System.Windows.MessageBox.Show("Właściciel nie odnaleziony. Czy chcesz dodać do bazy?", "Brak hodowcy", System.Windows.MessageBoxButton.YesNo); if (pop == MessageBoxResult.No) { return; } else if (pop == MessageBoxResult.Yes) { owner = new Owner() { Name = this.OwnerName.Text.Trim(), Surname = this.OwnerSurname.Text.Trim(), Adderss = this.OwnerAdress.Text.Trim() }; } } } if (this.FatherChipNumber.Text.Trim().Length == 0 & this.FatherName.Text.Trim().Length == 0 & this.FatherNickname.Text.Trim().Length == 0) { if (System.Windows.MessageBox.Show("Czy chcesz dodać psa bez ojca?", "Pies bez rodzica", System.Windows.MessageBoxButton.YesNo) == MessageBoxResult.Yes) { noFather = true; } } if (this.MotherChipNumber.Text.Trim().Length == 0 & this.MotherName.Text.Trim().Length == 0 & this.MotherNickname.Text.Trim().Length == 0) { if (System.Windows.MessageBox.Show("Czy chcesz dodać psa bez matki?", "Pies bez rodzica", System.Windows.MessageBoxButton.YesNo) == MessageBoxResult.Yes) { noMother = true; } } if (noFather == false) { ////Więcej niż jeden rodzic... var fathers = context.Dogs.Where(x => x.Name == this.FatherName.Text.Trim() & x.Nickname == this.FatherNickname.Text.Trim() & x.ChipNumber == this.FatherChipNumber.Text.Trim()).SingleOrDefault(); if (fathers == null) { popupResult = System.Windows.MessageBox.Show("Nie udało się odnaleźć ojca lub w bazie znajduje się więcej niż jeden osobnik, do którego pasują parametry.\n Proszę poprawić dane lub pozostawić okna puste.", "Brak ojca", System.Windows.MessageBoxButton.OK); return; } else { fatherId = fathers.DogId; } } if (noMother == false) { var mothers = context.Dogs.Where(x => x.Name == this.MotherName.Text.Trim() & x.Nickname == this.MotherNickname.Text.Trim() & x.ChipNumber == this.MotherChipNumber.Text.Trim()).SingleOrDefault(); if (mothers == null) { popupResult = System.Windows.MessageBox.Show("Nie udało się odnaleźć matki lub w bazie znajduje się więcej niż jeden osobnik, do którego pasują parametry.\n Proszę poprawić dane lub pozostawić okna puste.", "Brak matki", System.Windows.MessageBoxButton.OK); return; } else { motherId = mothers.DogId; } } if (this.BirthDate.SelectedDate.HasValue == true) { specimen.BirthDate = this.BirthDate.SelectedDate.Value; } else { specimen.BirthDate = null; } if (this.CertificationDate.SelectedDate.HasValue == true) { specimen.CertificationDate = this.CertificationDate.SelectedDate.Value; } else { specimen.CertificationDate = null; } specimen.ChipNumber = this.ChipNumber.Text.Trim(); specimen.Coat = this.Coat.Text.Trim(); specimen.DNA = this.DNA.Text.Trim(); specimen.Dysplasia = this.Dysplasia.Text.Trim(); specimen.ExhibitionTitles = this.ExhibitionTitles.Text.Trim(); specimen.Name = this.DogName.Text.Trim(); specimen.Nickname = this.Nickname.Text.Trim(); specimen.Breeder = breeder; specimen.Owner = owner; specimen.PedegreeCertificateNumber = this.PedegreeCertificateNumber.Text.Trim(); specimen.Sex = this.Sex.Text.Trim(); specimen.Training = this.Training.Text.Trim(); specimen.CertificationNo = Int32.Parse(this.CertificateNo.Text.Trim()); specimen.Rase = this.Rase.Text.Trim(); specimen.FatherId = fatherId; specimen.MotherId = motherId; if (_modify == false) { context.Dogs.Add(specimen); } context.SaveChanges(); if (_modify) { Window browseWindow = new BrowseSpecimensWindow(); browseWindow.Left = this.Left; browseWindow.Top = this.Top; browseWindow.Height = this.Height; browseWindow.Width = this.Width; browseWindow.Show(); this.Close(); } else { Window mainWindow = new MainWindow(); mainWindow.Left = this.Left; mainWindow.Top = this.Top; mainWindow.Height = this.Height; mainWindow.Width = this.Width; mainWindow.Show(); this.Close(); } } catch (Exception x) { ShowError(x.Message); } }