Esempio n. 1
0
        private void miBooks_Click(object sender, EventArgs e)  //открытие справочника Книги
        {
            BookForm bookForm = new BookForm();

            switch (AuthorizationForm.userRole)
            {
            case 1:
                bookForm.btnInsert.Enabled           = true;
                bookForm.btnUpdate.Enabled           = true;
                bookForm.btnDelete.Enabled           = true;
                bookForm.btnUpdateGenre.Enabled      = true;
                bookForm.btnUpdatePublishing.Enabled = true;
                bookForm.btnUpdateWriter.Enabled     = true;
                break;

            case 4:
                bookForm.btnInsert.Enabled           = true;
                bookForm.btnUpdate.Enabled           = true;
                bookForm.btnDelete.Enabled           = true;
                bookForm.btnUpdateGenre.Enabled      = true;
                bookForm.btnUpdatePublishing.Enabled = true;
                bookForm.btnUpdateWriter.Enabled     = true;
                break;
            }
            bookForm.Show(this);
        }
Esempio n. 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();
        }
Esempio n. 3
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);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        private void bookMenuView_Click(object sender, EventArgs e)
        {
            var f = new BookForm(1);

            foreach (Control c in f.tabControl.Controls)
            {
                c.Enabled = false;
            }

            using (context = new LibContext(LibConnection.GetConnString()))
            {
                DataGridViewRow selectedRow = viewBooks.SelectedRows[0];
                int             value       = (int)selectedRow.Cells[4].Value;
                f.book = context.books.Where(b => b.bID == value).First();

                f.authors = from a in context.authors

                            where a.bID == value

                            where a.bID == (int)selectedRow.Cells[4].Value

                            select a;
                f.fillForm();
            }
            f.FormClosed += new FormClosedEventHandler(BookForm_Closed);
            f.Show();
        }
Esempio n. 5
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;
        }
Esempio n. 6
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);
                    }
                }
            }
        }
Esempio n. 7
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);
     }
 }
Esempio n. 8
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);
            }
        }
Esempio n. 9
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);
            }
        }
Esempio n. 10
0
        private void btnUpdateBook_Click(object sender, EventArgs e)    //открытие справочника книги
        {
            BookForm bookForm = new BookForm();

            bookForm.Show(this);
        }
Esempio n. 11
0
        private void btnAddBook_Click(object sender, EventArgs e)
        {
            BookForm form = new BookForm(0);

            form.Show();
        }
Esempio n. 12
0
        private void booksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BookForm bkf = new BookForm();

            bkf.ShowDialog();
        }