private void newBook_Click_1(object sender, EventArgs e) { BookForm bookForm = new BookForm(categories); bookForm.Show(); bookForm.Text = "Add new book"; bookForm.bookPanelPurpose = "new"; bookForm.adminPanel = this; }
private void btnBookAdd_Click(object sender, EventArgs e) { BookForm bookForm = new BookForm(_db); bookForm.Owner = this; bookForm.Show(); bindingSourceBookSearch.DataSource = null; bindingSourceBookSearch.DataSource = SearchedBooks; }
private void dataGridView2_CellContentClick_1(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 8) // handle edit button { BookForm bookForm = new BookForm(categories); bookForm.Show(); bookForm.Text = "Edit book"; bookForm.adminPanel = this; bookForm.editBook(booksGridView.CurrentRow.Cells[0].Value.ToString()); } else if (e.ColumnIndex == 9) // handle delete button { deleteBook(booksGridView.CurrentRow.Cells[0].Value.ToString()); } }
private void btnBookChange_Click(object sender, EventArgs e) { if (dataGridViewBooks.SelectedRows.Count > 0) { int index = dataGridViewBooks.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridViewBooks[0, index].Value.ToString(), out id); if (converted == false) { return; } Book book = _db.Books.Find(id); BookForm bookForm = new BookForm(_db); bookForm.textBoxTitle.Text = book.Title; bookForm.textBoxPublishing.Text = book.PublishingDate.ToString(); bookForm.comboBoxGenre.SelectedIndex = (int)book.Genre; if (book.Author != null) { bookForm.comboBoxAuthor.SelectedValue = book.Author.Id; } DialogResult result = bookForm.ShowDialog(this); if (result == DialogResult.Cancel) { return; } book.Title = bookForm.textBoxTitle.Text; book.Author = (Author)bookForm.comboBoxAuthor.SelectedItem; book.Genre = (BookGenre)Enum.Parse(typeof(BookGenre), bookForm.comboBoxGenre.SelectedValue.ToString()); int publishingDate = 0; if (int.TryParse(bookForm.textBoxPublishing.Text, out publishingDate)) { book.PublishingDate = publishingDate; _db.Entry(book).State = EntityState.Modified; _db.SaveChanges(); MessageBox.Show($"Book \"{book.Title}\" was updated"); } } }