private void Edit_OnClick(object sender, RoutedEventArgs e) { var p = new WindowEditLocation(Owner, Display, Display.DCount); p.ShowDialog(); Close(); //This_OnLoaded(null, null); }
private void LocationButton_OnClick(object sender, RoutedEventArgs e) { int num = 0; int.TryParse(PubNumber.Text, out num); Hide(); if (Publication == null) { using (var db = new LibraryDBContainer()) { Publication = new DbPublication(NameBox.Text, new List <DbAuthor>(), BookRButton.IsChecked == true ? ePublicationType.None : ScientificPublication.IsChecked == true ? ePublicationType.Scientific : ePublicationType.Educational, BookRButton.IsChecked == true ? eBookPublication.Book : eBookPublication.Publication, PublishDatePicker.SelectedDate.Value, Publisher.Text); if (Course1.IsChecked == true) { db.DbCourseSet.Find(1).Publication.Add(Publication); } if (Course2.IsChecked == true) { db.DbCourseSet.Find(2).Publication.Add(Publication); } if (Course3.IsChecked == true) { db.DbCourseSet.Find(3).Publication.Add(Publication); } if (Course4.IsChecked == true) { db.DbCourseSet.Find(4).Publication.Add(Publication); } var selectedIds = AuthorList .SelectedItems.Cast <DbAuthor>() .Select(g => g.Id); Publication.Authors = db.DbAuthorSet1.Where(d => selectedIds.Contains(d.Id)).ToList(); db.DbPublicationSet1.Add(Publication); var selectedDisciplines = db.DbDisciplineSet .ToArray() .Where(d => { return(DisciplinesList .SelectedItems .Cast <DbDiscipline>() .Select(f => f.Id) .Contains(d.Id)); }); foreach (var disc in selectedDisciplines) { disc.Publication.Add(Publication); } if (EpubCheckBox.IsChecked == true) { Publication.InternetLocation = EpubAdress.Text; } if (EpubCheckBox.IsChecked != true && PubNumberChechBox.IsChecked != true) { Publication.BookPublication = eBookPublication.None.e(); } Publication.PhysicalLocations = new List <DbBookLocation>(num); db.SaveChanges(); } if (PubNumberChechBox.IsChecked == true) { var p = new WindowEditLocation(this, Publication, num); p.ShowDialog(); } Close(); } else { using (var db = new LibraryDBContainer()) { Publication = db.DbPublicationSet1.Find(Publication.Id); Publication.Name = NameBox.Text; Publication.DatePublished = PublishDatePicker.SelectedDate.Value; Publication.Publisher = Publisher.Text; Publication.BookPublication = BookRButton.IsChecked == true ? eBookPublication.Book.e() : eBookPublication.Publication.e(); Publication.PublicationType = BookRButton.IsChecked == true ? ePublicationType.None.e() : ScientificPublication.IsChecked == true ? ePublicationType.Scientific.e() : ePublicationType.Educational.e(); Publication.Course.Clear(); if (Course1.IsChecked == true) { db.DbCourseSet.Find(1).Publication.Add(Publication); } if (Course2.IsChecked == true) { db.DbCourseSet.Find(2).Publication.Add(Publication); } if (Course3.IsChecked == true) { db.DbCourseSet.Find(3).Publication.Add(Publication); } if (Course4.IsChecked == true) { db.DbCourseSet.Find(4).Publication.Add(Publication); } Publication.Discipline.Clear(); foreach (var disc in DisciplinesList .SelectedItems.Cast <DbDiscipline>().Select(d => db.DbDisciplineSet.Find(d.Id))) { Publication.Discipline.Add(disc); } if (EpubCheckBox.IsChecked == true) { Publication.InternetLocation = EpubAdress.Text; } Publication.Authors.Clear(); Publication.Authors = AuthorList.SelectedItems.Cast <DbAuthor>() .Select(d => db.DbAuthorSet1.Find(d.Id)).ToList(); Thread.Sleep(10); db.SaveChanges(); } if (PubNumberChechBox.IsChecked == true) { var p = new WindowEditLocation(this, Publication, num); p.ShowDialog(); } Close(); } }