Beispiel #1
0
        private void grvCategory_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }
            // get current Category
            var category = _caregoryService.GetById(Convert.ToInt32(gridViewCategory.Rows[e.RowIndex].Cells["Id"].Value));

            // for Editing
            if (e.ColumnIndex == gridViewCategory.Columns["Edit"].Index)
            {
                using (var categoryFrom = new CategoryDetail(_user, category, _caregoryService))
                {
                    var dr = categoryFrom.ShowDialog();
                    if (dr == DialogResult.OK)
                    {
                        _caregoryService = new CategoryService(new BookStoreDB());
                        SearchCategory(txtFilter.Text);
                    }
                }
            }

            // for Deleting
            else
            {
                var deleteColumn = gridViewCategory.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 (category.Books != null && category.Books.Count > 0)
                            {
                                var dr = MessageBox.Show(BookStoreConstants.MSG_CATEGORY_CONFIRM_DELETE, BookStoreConstants.CONFIRM_DIALOG_NAME, MessageBoxButtons.YesNo);
                                if (dr == DialogResult.No)
                                {
                                    return;
                                }

                                foreach (Book book in category.Books)
                                {
                                    book.CategoryId = null;
                                }
                            }
                            _caregoryService.Delete(category);
                            SearchCategory(txtFilter.Text);
                        }
                        catch (Exception)
                        {
                            MessageBox.Show(BookStoreConstants.MSG_DB_ERROR);
                        }
                    }
                }
            }
        }
Beispiel #2
0
 private void btnAddCategory_Click(object sender, EventArgs e)
 {
     using (var caregoryFrom = new CategoryDetail(_user, null, _caregoryService))
     {
         var dr = caregoryFrom.ShowDialog();
         if (dr == DialogResult.OK)
         {
             SearchCategory(txtFilter.Text);
         }
     }
 }