private void grvAuthor_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } // get current Category var author = _authorService.GetById(Convert.ToInt32(gridViewAuthor.Rows[e.RowIndex].Cells["Id"].Value)); // for Editing if (e.ColumnIndex == gridViewAuthor.Columns["Edit"].Index) { using (var authorFrom = new AuthorDetail(_user, author, _authorService)) { var dr = authorFrom.ShowDialog(); if (dr == DialogResult.OK) { _authorService = new AuthorService(new BookStoreDB()); SearchAuthor(txtFilter.Text); } } } // for Deleting else { var deleteColumn = gridViewAuthor.Columns["Delete"]; if (deleteColumn != null && e.ColumnIndex == deleteColumn.Index) { DialogResult result = MessageBox.Show(BookStoreConstants.MSG_CONFIRM_DELETE, BookStoreConstants.CONFIRM_DIALOG_NAME, MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { try { if (author.Books != null && author.Books.Count > 0) { var dr = MessageBox.Show(BookStoreConstants.MSG_AUTHOR_CONFIRM_DELETE, BookStoreConstants.CONFIRM_DIALOG_NAME, MessageBoxButtons.YesNo); if (dr == DialogResult.No) { return; } foreach (Book book in author.Books) { book.AuthorId = null; } } _authorService.Delete(author); SearchAuthor(txtFilter.Text); } catch (Exception) { MessageBox.Show(BookStoreConstants.MSG_DB_ERROR); } } } } }
private void btnAddAuthor_Click(object sender, EventArgs e) { using (var caregoryFrom = new AuthorDetail(_user, null, _authorService)) { DialogResult dr = caregoryFrom.ShowDialog(); if (dr == DialogResult.OK) { SearchAuthor(txtFilter.Text); } } }