Exemplo n.º 1
0
        /// <summary>
        /// On Button Add Author Clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddAuthor_Click(object sender, EventArgs e)
        {
            var caregoryFrom = new frmAuthorDetail(_user, null);

            caregoryFrom.AddUpdateItemCallback = new AddItemDelegate(this.AddUpdateItemCallbackFn);
            caregoryFrom.ShowDialog();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handle clicking on row Edit or row Delete
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void grvAuthor_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == grvAuthor.Columns["Edit"].Index && e.RowIndex >= 0)
            {
                var    currentRow   = grvAuthor.Rows[e.RowIndex];
                Author authorUpdate = new Author();
                authorUpdate.Id    = Convert.ToInt32(currentRow.Cells["Id"].Value);
                authorUpdate.Title = currentRow.Cells["Title"].Value.ToString();
                var descriptionValue = currentRow.Cells["Description"].Value;
                authorUpdate.Description = descriptionValue?.ToString() ?? string.Empty;
                var coverValue = currentRow.Cells["Cover"].Value;
                authorUpdate.Cover = coverValue?.ToString() ?? string.Empty;
                var caregoryFrom = new frmAuthorDetail(_user, authorUpdate);
                caregoryFrom.AddUpdateItemCallback = new AddItemDelegate(this.AddUpdateItemCallbackFn);
                caregoryFrom.ShowDialog();
            }

            else if (e.ColumnIndex == grvAuthor.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
                    {
                        var authorDelete = _authorService.GetById(Convert.ToInt32(grvAuthor.Rows[e.RowIndex].Cells["Id"].Value));
                        _authorService.Delete(authorDelete.Id);
                        SearchAuthor(txtFilter.Text);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(BookStoreConstants.MSG_DB_ERROR + ex.Message);
                        _authorService.Dispose();
                    }
                }
            }
        }