//Usuwanie wspolautora private void Btn_usun_autora_Click(object sender, RoutedEventArgs e) { try { if (cmb_Author.Items.Count <= 1) { MessageBox.Show("To jest jedyny autor, możesz usunąć książkę"); } else { BookAuthor book = new BookAuthor(); book = (BookAuthor)cmb_Author.SelectedItem; authorsBook1 = new AuthorsBook(); authorsBook1 = db.AuthorsBook.Find(book.IdAuthorsBook); db.AuthorsBook.Remove(authorsBook1); db.SaveChanges(); MessageBox.Show(book.IdAuthorsBook.ToString() + " Usunięto"); } } catch (SqlException f) { MessageBox.Show(f.Message); } }
public Okno_dodaj_wspolautora(Frame frame1, BookAuthor bookAuthor1, BibliotekaEntities db) { InitializeComponent(); this.db = db; this.bookAuthor1 = bookAuthor1; this.frame1 = frame1; cmb_CoAuthor.ItemsSource = db.Author.ToList(); lbl_bookName.Content = bookAuthor1.Title; }
//Przycisk edycji ksiazek private void Btn_edytuj_ksiazke_Click(object sender, RoutedEventArgs e) { int id_ksiazki = listView_ksiazka.SelectedIndex; BookAuthor Ba1 = (BookAuthor)listView_ksiazka.SelectedItem; if (id_ksiazki > -1) { frame2.Content = new Page_edycja_usun_ksiazke(Ba1, frame2, db); } else { MessageBox.Show("Muisz wybrać książkę", "Uwaga"); } }
//Przycisk dodawanie wspolautora private void Btn_kolejny_autor_Click(object sender, RoutedEventArgs e) { int index_ksiazki = listView_ksiazka.SelectedIndex; if (index_ksiazki > -1) { BookAuthor Ba1 = (BookAuthor)listView_ksiazka.SelectedItem; Okno_dodaj_wspolautora okno = new Okno_dodaj_wspolautora(frame2, Ba1, db); okno.Show(); } else { MessageBox.Show("Muisz wybrać książkę", "Uwaga"); } }
public Page_edycja_usun_ksiazke(BookAuthor ba1, Frame frame1, BibliotekaEntities db) { InitializeComponent(); this.ba1 = ba1; this.frame1 = frame1; this.db = db; books1 = db.Books.Find(ba1.IdBook); txt_title.Text = ba1.Title.ToString(); var linqAuthor = from x in db.AuthorsBook join y in db.Author on x.IdAuthor equals y.IdAuthor where x.IdBook == ba1.IdBook select new BookAuthor { Firstname = y.FirstName, SureName = y.Surename, IdAuthorsBook = x.IdAK }; cmb_Author.ItemsSource = linqAuthor.ToList(); }