コード例 #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            CategoryBUS bus = new CategoryBUS();
            if (txtCategoryID.ReadOnly == false)
            {
                MessageBox.Show(Resources.DELETE_NONE_CATEGORY);
            }
            else
            {
                if (String.IsNullOrEmpty(txtCategoryID.Text))
                {
                    MessageBox.Show(Resources.DELETE_NONE_CATEGORY);
                }
                else
                {

                    if (MessageBox.Show(Resources.DELETE_CATEGORY_CONFIRM, "", MessageBoxButtons.YesNo) ==
                        DialogResult.Yes)
                    {
                        if (!txtCategoryID.Text.Equals("0"))
                        {
                            CategoryDTO category = bus.GetCategoryById(txtCategoryID.Text);
                            if (bus.DeleteCategory(category) == 1)
                            {
                                MessageBox.Show(Resources.DELETE_CATEGORY_SUCCESS);
                                txtCategoryID.Text = "";
                                txtCategoryName.Text = "";
                                lst.Clear();
                                lst.AddRange(bus.GetAllCatagory());
                                grdCategory.RefreshDataSource();
                            }
                            else
                            {
                                MessageBox.Show(Resources.DELETE_CATEGORY_FAIL);
                            }
                        }
                        else
                        {
                            MessageBox.Show(Resources.DELETE_DEFAULT_CATEGORY);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public CatalogueDTO GetCatalogueById(String isbn)
        {
            CatalogueDTO catalogueDto = new CatalogueDTO();

            CatalogueDAO dao = new CatalogueDAO();
            catalogueDto = dao.GetCatalogueById(isbn);

            if (catalogueDto != null)
            {
                PublisherBUS publisherBus = new PublisherBUS();
                CategoryBUS categoryBus = new CategoryBUS();
                AuthorOfBookBUS authorOfBookBus = new AuthorOfBookBUS();

                catalogueDto.Publisher = publisherBus.GetPublisherById(catalogueDto.Publisher.PublisherId);
                catalogueDto.Category = categoryBus.GetCategoryById(catalogueDto.Category.CategoryId);
                catalogueDto.AuthorList = authorOfBookBus.GetAuthorListByIsbn(catalogueDto.ISBN);
            }
            return catalogueDto;
        }
コード例 #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            CategoryBUS bus = new CategoryBUS();
            if (txtCategoryID.ReadOnly == true)
            {
                if (String.IsNullOrEmpty(txtCategoryName.Text))
                {
                    MessageBox.Show(Resources.ADD_NULL_CATEGORY_NAME);
                    txtCategoryName.Focus();
                }
                else
                {
                    CategoryDTO category = (CategoryDTO) grvCategory.GetFocusedRow();
                    category.CategoryName = txtCategoryName.Text;
                    if (bus.UpdateCategory(category) == 1)
                    {
                        MessageBox.Show(Resources.ADD_CATEGORY_SUCCESS);
                        grdCategory.RefreshDataSource();
                    }
                    else
                    {
                        MessageBox.Show(Resources.ADD_CATEGORY_FAIL);
                    }
                }
            }
            else
            {
                if (String.IsNullOrEmpty(txtCategoryID.Text))
                {
                    MessageBox.Show(Resources.ADD_NULL_CATEGORY_ID);
                    txtCategoryID.Focus();
                }
                else
                {
                    if(String.IsNullOrEmpty(txtCategoryName.Text))
                    {
                        MessageBox.Show(Resources.ADD_NULL_CATEGORY_NAME);
                        txtCategoryName.Focus();
                    }
                    else
                    {
                        if (bus.GetCategoryById(txtCategoryID.Text) != null)
                        {
                            MessageBox.Show(Resources.ADD_EXISTING_CATEGORY_ID);
                        }
                        else
                        {
                            bool Ok = false;
                            if (txtCategoryID.Text.IndexOf('.') == -1)
                            {
                                Ok = true;
                            }
                            else
                            {
                                if (bus.GetCategoryById(txtCategoryID.Text.Substring(0, txtCategoryID.Text.LastIndexOf('.'))) != null)
                                    Ok = true;
                                else Ok = false;
                            }

                            if (Ok)
                            {
                                CategoryDTO category = new CategoryDTO()
                                {
                                    CategoryId = txtCategoryID.Text,
                                    CategoryName = txtCategoryName.Text,
                                    CreatedDate = DateTime.Now,
                                    UpdatedDate = DateTime.Now
                                };
                                if (bus.InsertCategory(category) == 1)
                                {
                                    MessageBox.Show(Resources.ADD_CATEGORY_SUCCESS);
                                    txtCategoryID.ReadOnly = true;
                                    lst.Add(category);
                                    grdCategory.RefreshDataSource();
                                }
                                else
                                {
                                    MessageBox.Show(Resources.ADD_CATEGORY_FAIL);
                                }
                            }
                            else MessageBox.Show(Resources.ADD_ORPHANAGE_CATEGORY);
                        }
                    }

                }
            }
        }