Example #1
0
        //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);
            }
        }
Example #2
0
        private void Btn_usun_ksiazke_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (MessageBox.Show("Czy chcesz usuną książkę " + books1.Title + " ?", "", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    var linqdeleteBook = from x in db.AuthorsBook
                                         where x.IdBook == books1.IdBook
                                         select x;

                    foreach (var x in linqdeleteBook)
                    {
                        AuthorsBook authorsBook1 = new AuthorsBook();
                        authorsBook1 = db.AuthorsBook.Find(x.IdAK);

                        db.AuthorsBook.Remove(authorsBook1);
                    }

                    db.Books.Remove(books1);
                    db.SaveChanges();
                }


                MessageBox.Show("Usunięto");
                frame1.Content = new Page2(frame1, db);
            }
            catch (SqlException f)
            {
                MessageBox.Show(f.Message);
            }
            catch (Exception f)
            {
                MessageBox.Show(f.Message);
            }
        }
Example #3
0
        //Przycisk dodawania wspolautora
        private void Btn_dodaj_autora_Click(object sender, RoutedEventArgs e)
        {
            if (cmb_CoAuthor.SelectedIndex > -1)
            {
                AuthorsBook authorsBook1 = new AuthorsBook();

                Author autor1 = (Author)cmb_CoAuthor.SelectedItem;

                authorsBook1.IdAuthor = autor1.IdAuthor;
                authorsBook1.IdBook   = bookAuthor1.IdBook;


                db.AuthorsBook.Add(authorsBook1);
                db.SaveChanges();

                this.Close();
            }
        }
Example #4
0
        //Dodawanie ksiazki
        private void Btn_dodaj_ksiazke_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Dodawanie ksiazek
                string title = txt_title.Text;

                Books books1 = new Books();
                books1.Title = title;

                db.Books.Add(books1);
                db.SaveChanges();



                Author autor2 = (Author)cmbAutor.SelectedItem;
                MessageBox.Show(autor2.IdAuthor.ToString());



                AuthorsBook authorsBook1 = new AuthorsBook();

                authorsBook1.IdAuthor = autor2.IdAuthor;
                authorsBook1.IdBook   = books1.IdBook;

                db.AuthorsBook.Add(authorsBook1);
                db.SaveChanges();
            }
            catch (FormatException)
            {
                MessageBox.Show("Wprowadzono błędne dane");
            }
            catch (SqlException f)
            {
                MessageBox.Show(f.Message);
            }
        }