Example #1
0
        private void buttonEditBook_Click(object sender, EventArgs e)
        {
            if (dataGridViewBooks.SelectedRows.Count > 0)
            {
                using (LibraryContext context = new LibraryContext())
                {
                    int      bookID   = (int)dataGridViewBooks.SelectedRows[0].Cells["BookID"].Value;
                    BookForm formBook = new BookForm();
                    formBook.FormBook = context.Books.First(x => x.BookID == bookID);
                    if (DialogResult.OK == formBook.ShowDialog())
                    {
                        context.SaveChanges();
                        LoadBooks();
                    }

                    //Refresh books by this author
                    if (dataGridViewAuthors.SelectedRows.Count > 0)
                    {
                        int    authorID   = (int)dataGridViewAuthors.SelectedRows[0].Cells["AuthorID"].Value;
                        string authorName = (string)dataGridViewAuthors.SelectedRows[0].Cells["FirstName"].Value
                                            + " " + (string)dataGridViewAuthors.SelectedRows[0].Cells["LastName"].Value;

                        if (formBook.FormBook.Author == authorName)
                        {
                            LoadOther(authorID);
                        }
                    }
                }
            }
        }
Example #2
0
        private void btnNewBook_Click(object sender, EventArgs e)
        {
            //Form where you add a new book
            BookForm bokform = new BookForm(_authorService, _bookService, _bookCopyService);

            bokform.ShowDialog();
        }
Example #3
0
        private void BookAdd_Click(object sender, EventArgs e)
        {
            BookForm     bookForm     = new BookForm();
            DialogResult dialogResult = bookForm.ShowDialog(this);

            if (dialogResult == DialogResult.Cancel)
            {
                return;
            }

            Book book = new Book();

            book.Name = bookForm.nameTextBox.Text;
        }
Example #4
0
        private void buttonAddBook_Click(object sender, EventArgs e)
        {
            if (dataGridViewAuthors.SelectedRows.Count > 0)
            {
                using (LibraryContext context = new LibraryContext())
                {
                    BookForm formBook = new BookForm();

                    //Set author name in the coresponding text field in a new book form
                    int authorID = (int)dataGridViewAuthors.SelectedRows[0].Cells["AuthorID"].Value;
                    formBook.setAuthor((string)dataGridViewAuthors.SelectedRows[0].Cells["FirstName"].Value + " "
                                       + (string)dataGridViewAuthors.SelectedRows[0].Cells["LastName"].Value);

                    if (DialogResult.OK == formBook.ShowDialog())
                    {
                        Book b = new Book()
                        {
                            Title     = formBook.FormBook.Title,
                            Genre     = formBook.FormBook.Genre,
                            Author    = formBook.FormBook.Author,
                            Publisher = formBook.FormBook.Publisher,
                        };
                        context.Books.Add(b);
                        context.SaveChanges();

                        //Increase number of books written by author
                        foreach (Author a in context.Authors)
                        {
                            if (a.AuthorID == authorID)
                            {
                                a.BooksWritten += 1;
                            }
                        }
                        context.SaveChanges();

                        //Add new relation between book and author
                        Relation newRel = new Relation();
                        newRel.AuthorID = authorID;
                        newRel.BookID   = b.BookID;
                        context.Relations.Add(newRel);
                        context.SaveChanges();

                        LoadAuthors();
                        LoadBooks();
                        LoadOther(authorID);
                    }
                }
            }
        }
Example #5
0
 private void btn_editBook_Click(object sender, EventArgs e)
 {
     BookForm form = new BookForm(pAuthorService, pBook);
     try
     {
         if (DialogResult.OK == form.ShowDialog())
         {
             pBookService.EditBook(form.Book);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #6
0
        private void msp_file_add_book_Click(object sender, EventArgs e)
        {
            BookForm form = new BookForm(authorService);

            try
            {
                if (DialogResult.OK == form.ShowDialog())
                {
                    bookService.AddBook(form.Book);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #7
0
        private void msp_edit_book_Click(object sender, EventArgs e)
        {
            if (null == SelectedBook) // Unknown state, crash application deliberately
            {
                throw new InvalidOperationException("Should not be able to click disabled controls.");
            }
            BookForm form = new BookForm(authorService, SelectedBook);

            try
            {
                if (DialogResult.OK == form.ShowDialog())
                {
                    bookService.EditBook(form.Book);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #8
0
        private void booksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BookForm bkf = new BookForm();

            bkf.ShowDialog();
        }