/// <summary> /// Handle clicking on row Edit or row Delete /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void grvCategory_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == grvCategory.Columns["Edit"].Index && e.RowIndex >= 0) { var currentRow = grvCategory.Rows[e.RowIndex]; Category categoryUpdate = new Category(); categoryUpdate.Id = Convert.ToInt32(currentRow.Cells["Id"].Value); categoryUpdate.Title = currentRow.Cells["Title"].Value.ToString(); var descriptionValue = currentRow.Cells["Description"].Value; categoryUpdate.Description = descriptionValue?.ToString() ?? string.Empty; var caregoryFrom = new frmCategoryDetail(_user, categoryUpdate); caregoryFrom.AddUpdateItemCallback = new AddItemDelegate(this.AddUpdateItemCallbackFn); caregoryFrom.ShowDialog(); } else if (e.ColumnIndex == grvCategory.Columns["Delete"].Index && e.RowIndex >= 0) { DialogResult result = MessageBox.Show(BookStoreConstants.MSG_CONFIRM_DELETE, BookStoreConstants.CONFIRM_DIALOG_NAME, MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { try { _caregoryService.Delete(Convert.ToInt32(grvCategory.Rows[e.RowIndex].Cells["Id"].Value)); SearchCategory(txtFilter.Text); } catch (Exception) { MessageBox.Show(BookStoreConstants.MSG_DB_ERROR); } } } }
/// <summary> /// On Button Add Category Clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddCategory_Click(object sender, EventArgs e) { var caregoryFrom = new frmCategoryDetail(_user, null); caregoryFrom.AddUpdateItemCallback = new AddItemDelegate(this.AddUpdateItemCallbackFn); caregoryFrom.ShowDialog(); }