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);
                        }
                    }
                }
            }
        }
        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;
        }
        public BookInfoForm()
        {
            InitializeComponent();

            grcCatalogue.DataSource = lst;

            CategoryBUS bus = new CategoryBUS();
            _lstCate.Add(new CategoryDTO()
            {
                CategoryId = "",
                CategoryName = "--Tất cả danh mục--"
            });
            _lstCate.AddRange(bus.GetAllCatagory());

            foreach (CategoryDTO categoryDTO in _lstCate)
            {
                for (int i = 0; i < categoryDTO.CategoryId.Split('.').Length - 1; i++)
                {
                    categoryDTO.CategoryName = "|--" + categoryDTO.CategoryName;
                }
            }

            cbeDetailCategory.DataSource = _lstCate;

            cboxField1.SelectedIndex = 0;
            cboxField2.SelectedIndex = 0;
            cboxField3.SelectedIndex = 0;
            cboxAno1.SelectedIndex = 0;
            cboxAno2.SelectedIndex = 0;
            cboxType1.SelectedIndex = 0;
            cboxType2.SelectedIndex = 0;
            cboxType3.SelectedIndex = 0;

            SearchBookBUS bbus = new SearchBookBUS();
            int stype = 1;
            dto = new SearchBookDTO();
            dto.Info1 = txtTitle.Text;
            dto.PageNumber = 1;
            dto.SearchType = (SearchType)stype;
            //grcCatalogue.DataSource = bbus.SearchBooks(dto);
            lst.Clear();
            lst.AddRange(bbus.SearchBooks(dto));

            grcCatalogue.RefreshDataSource();

            int NoR = bbus.SearchBooksCount(dto);
            lblResult.Text = NoR.ToString();

            int pages = (int)Math.Ceiling(((double)NoR) / ((double)Options.NumberOfRecord));

            cbePage.Items.Clear();
            cbePage.Text = "";
            for (int i = 1; i <= pages; i++)
            {
                cbePage.Items.Add(i);
            }
            if (pages != 0)
            {
                cbePage.SelectedIndex = 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);
                        }
                    }

                }
            }
        }
 private void btnSearch_Click(object sender, EventArgs e)
 {
     CategoryBUS bus = new CategoryBUS();
     string info = txtCate.Text;
     lst.Clear();
     lst.AddRange(bus.SearchCate(info));
     grdCategory.RefreshDataSource();
 }