private void Delete_OnClick(object sender, RoutedEventArgs e) { DbPublication item = DataGrid.SelectedItem as DbPublication; using (var db = new LibraryDBContainer()) { item = db.DbPublicationSet1.Find(item.Id); item.Authors.Clear(); item.Course.Clear(); foreach (var location in item.PhysicalLocations) { location.Reader = null; location.Publication = null; } item.PhysicalLocations.Clear(); item.Stats.Clear(); item.Discipline.Clear(); db.DbPublicationSet1.Remove(item); db.SaveChanges(); } UpdateLayout(); }
private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { using (var db = new LibraryDBContainer()) { db.DbDisciplineSet.Add(new DbDiscipline { Name = NewDiscipline.Text }); db.SaveChanges(); } Close(); }
private void Accept_OnClick(object sender, RoutedEventArgs e) { Hide(); if (Reader == null && Author == null) { using (var db = new LibraryDBContainer()) { if (isReader) { Reader = IsStudent ? new DbReader(First.Text, Last.Text, Patronimic.Text, GroupBox.Text) : new DbReader(First.Text, Last.Text, Patronimic.Text); db.DbReaderSet.Add(Reader); } else { Author = new DbAuthor(First.Text, Last.Text, Patronimic.Text, (eWriterType)AuthorRole.SelectedIndex); db.DbAuthorSet1.Add(Author); } db.SaveChanges(); } } else { using (var db = new LibraryDBContainer()) { if (isReader) { Reader = db.DbReaderSet.Find(Reader.Id); Reader.AccessLevel = (byte)UserRole.SelectedIndex; Reader.Last = Last.Text; Reader.First = First.Text; Reader.Patronimic = Patronimic.Text; Reader.Group = GroupBox.Text; } else { Author = db.DbAuthorSet1.Find(Author.Id); Author.Last = Last.Text; Author.First = First.Text; Author.Patronimic = Patronimic.Text; Author.WriterType = (byte)AuthorRole.SelectedIndex; } db.SaveChanges(); } } Close(); }
private void Accept_OnClick(object sender, RoutedEventArgs e) { //PlacesComboBox.Items.Remove(PlacesComboBox.SelectedItem); using (var db = new LibraryDBContainer()) { EditItem = db.DbPublicationSet1.Find(EditItem.Id); int.TryParse(RoomsBox.Text, out int num); DbBookLocation p; if (EditItem.PhysicalLocations.ElementAt(PlacesComboBox.SelectedIndex) == null) { p = new DbBookLocation(num, Place.Text) { IsTaken = ReaderRButton.IsChecked == true, Reader = ListReaders.SelectedIndex != -1 ? db.DbReaderSet.Find((ListReaders.SelectedItem as DbReader)?.Id) : null, Publication = EditItem } } ; else { p = EditItem.PhysicalLocations.ElementAt(PlacesComboBox.SelectedIndex); p.Room = num; p.Place = Place.Text; p.IsTaken = ReaderRButton.IsChecked == true; p.Reader = ListReaders.SelectedIndex != -1 ? db.DbReaderSet.Find((ListReaders.SelectedItem as DbReader)?.Id) : null; } if (ReaderRButton.IsChecked == true) { db.DbStatsSet.Add(new DbStats { DateTaken = DateTime.Now, Publication = EditItem, }); } db.DbBookLocationSet.Local.Add(p); db.SaveChanges(); } if (PlacesComboBox.SelectedIndex == PlacesComboBox.Items.Count) { Close(); } PlacesComboBox.SelectedIndex++; }
private void Delete_OnClick(object sender, RoutedEventArgs e) { var item = DataGrid.SelectedItem as DbAuthor; using (var db = new LibraryDBContainer()) { item = db.DbAuthorSet1.Find(item.Id); item.Publications.Clear(); db.DbAuthorSet1.Remove(item); db.SaveChanges(); } UpdateLayout(); }
private void AcceptAll_OnClick(object sender, RoutedEventArgs e) { using (var db = new LibraryDBContainer()) { EditItem = db.DbPublicationSet1.Find(EditItem.Id); for (int i = 0; i < PlacesComboBox.Items.Count; i++) { db.DbBookLocationSet.Add(new DbBookLocation(int.Parse(RoomsBox.Text), Place.Text) { IsTaken = ReaderRButton.IsChecked == true, Reader = db.DbReaderSet.Find((ListReaders.SelectedItem as DbReader).Id), Publication = EditItem }); db.SaveChanges(); } } Close(); }
private void Delete_OnClick(object sender, RoutedEventArgs e) { var item = DataGrid.SelectedItem as DbReader; using (var db = new LibraryDBContainer()) { item = db.DbReaderSet.Find(item.Id); for (var i = 0; i < item.PhysicalLocation.Count; i++) { item.PhysicalLocation.ElementAt(i).IsTaken = false; } item.PhysicalLocation.Clear(); db.DbReaderSet.Remove(item); db.SaveChanges(); } UpdateLayout(); }
private void Test_OnClick(object sender, RoutedEventArgs e) { using (var db = new LibraryDBContainer()) { for (int i = 0; i < 6; i++) { db.DbAuthorSet1.Add(DbAuthor.FillBlanks()); } for (int i = 0; i < 10; i++) { db.DbReaderSet.Add(DbReader.FillBlanks()); } var courses = new[] { new DbCourse { Id = 1, Course = 1 }, new DbCourse { Id = 2, Course = 2 }, new DbCourse { Id = 3, Course = 3 }, new DbCourse { Id = 4, Course = 4 }, }; foreach (var t in courses) { db.DbCourseSet.Add(t); } var disciplines = new[] { new DbDiscipline { Id = 1, Name = "Программирование", }, new DbDiscipline { Id = 2, Name = "Конструирование ПО", }, new DbDiscipline { Id = 3, Name = "НИС", } }; foreach (var t in disciplines) { db.DbDisciplineSet.Add(t); } var publications = new[] { new DbPublication("Принципы программирования", db.DbAuthorSet1.Local[2], ePublicationType.None, eBookPublication.Book, new DateTime(1985, 4, 1), "Росмэн") { Id = 1, Course = new [] { courses[0], courses[1] }, Discipline = new [] { disciplines[0] } }, new DbPublication("Справочник по C#", new[] { db.DbAuthorSet1.Local[1], db.DbAuthorSet1.Local[2] }, ePublicationType.None, eBookPublication.Book, new DateTime(2011, 6, 1), "Справочники") { Id = 3, Course = new [] { courses[0], }, Discipline = new [] { disciplines[0], } }, new DbPublication("Pascal.NET programming guide", new[] { db.DbAuthorSet1.Local[2], db.DbAuthorSet1.Local[3] }, ePublicationType.Educational, eBookPublication.Publication, new DateTime(2001, 8, 1), "Питер") { Id = 2, Course = new [] { courses[1], courses[3] }, Discipline = new [] { disciplines[0], disciplines[1] } }, new DbPublication("Как писать божественный код", db.DbAuthorSet1.Local[5], ePublicationType.Scientific, eBookPublication.Publication, new DateTime(2018, 3, 1), null) { Id = 6, InternetLocation = "https://youtube.com/", Course = new [] { courses[2], courses[3] }, Discipline = new [] { disciplines[0], } }, new DbPublication("Почему Perl 6 - лучший язык программирования", new[] { db.DbAuthorSet1.Local[3], db.DbAuthorSet1.Local[4], }, ePublicationType.Educational, eBookPublication.Publication, new DateTime(2015, 1, 1), null) { Id = 4, InternetLocation = "https://google.com/", Course = new [] { courses[1], courses[2] }, Discipline = new [] { disciplines[1], } }, new DbPublication("Где учиться на программиста", db.DbAuthorSet1.Local[5], ePublicationType.Educational, eBookPublication.Publication, new DateTime(2016, 11, 1), null) { Id = 5, InternetLocation = "https://wikipedia.org/", Course = new [] { courses[1], courses[3], }, Discipline = new [] { disciplines[2], } }, }; foreach (var t in publications) { db.DbPublicationSet1.Add(t); } var locations = new[] { new DbBookLocation { Id = 1, Room = 307, Place = "здесь", IsTaken = true, Reader = db.DbReaderSet.Local[2], Publication = db.DbPublicationSet1.Local[2] }, new DbBookLocation { Id = 2, Room = 321, Place = "где-то была", IsTaken = false, Publication = db.DbPublicationSet1.Local[2] }, new DbBookLocation { Id = 3, Room = 501, Place = "в столе", IsTaken = true, Reader = db.DbReaderSet.Local[1], Publication = db.DbPublicationSet1.Local[1] }, new DbBookLocation { Id = 4, Room = 321, Place = "на верхней полке шкафа", IsTaken = false, Publication = db.DbPublicationSet1.Local[2] }, new DbBookLocation { Id = 5, Room = 318, Place = "в правом шкафу слева", IsTaken = false, Publication = db.DbPublicationSet1.Local[0] }, new DbBookLocation { Id = 6, Room = 302, Place = "на столе", IsTaken = false, Publication = db.DbPublicationSet1.Local[1] }, new DbBookLocation { Id = 7, Room = 323, Place = "под потолком", IsTaken = false, Publication = db.DbPublicationSet1.Local[0] }, }; foreach (var t in locations) { db.DbBookLocationSet.Add(t); } var stats = new[] { new DbStats { Id = 1, DateTaken = new DateTime(2016, 01, 09), Publication = db.DbPublicationSet1.Local[2] }, new DbStats { Id = 2, DateTaken = new DateTime(2017, 06, 10), Publication = db.DbPublicationSet1.Local[2] }, new DbStats { Id = 3, DateTaken = new DateTime(2017, 11, 15), Publication = db.DbPublicationSet1.Local[1] }, new DbStats { Id = 4, DateTaken = new DateTime(2018, 08, 20), Publication = db.DbPublicationSet1.Local[1] }, new DbStats { Id = 5, DateTaken = new DateTime(2018, 03, 01), Publication = db.DbPublicationSet1.Local[2] }, }; foreach (var t in stats) { db.DbStatsSet.Add(t); } db.SaveChanges(); } pPublications.UpdateLayout(); pUsers.UpdateLayout(); pAuthors.UpdateLayout(); }
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(); } }