public ActionResult Category(string id)
        {
            try
            {
                SearchBookBUS bus = new SearchBookBUS();
                SearchBookDTO dto = new SearchBookDTO()
                {
                    Info2 = id,
                    PageNumber = 1,
                    SearchType = SearchType.DETAIL_SEARCH
                };

                int count = bus.SearchBooksCount(dto);
                return View(new SearchResultModels()
                {
                    ParentCate = id,
                    Results = bus.SearchBooks(dto),
                    NoP =
                        (int)
                        Math.Ceiling((double)count / ((double)Options.NumberOfRecord)),
                    NumberOfResult = count,
                    CurrentPage = dto.PageNumber
                });

            }
            catch
            {
                return View();
            }
        }
        public ActionResult Index(FormCollection collection)
        {
            try
            {
                bool isByTitle = collection["chkTitle"] != null;
                bool isByContent = collection["chkContent"] != null;
                bool isByAuthor = collection["chkAuthor"] != null;

                SearchBookBUS bus = new SearchBookBUS();
                SearchBookDTO dto = new SearchBookDTO()
                {
                    Info1 = isByTitle ? collection["txtKeyword"] : "",
                    Info2 = collection["lstCategories"],
                    Info3 = isByContent ? collection["txtKeyword"] : "",
                    Info4 = isByAuthor ? collection["txtKeyword"] : "",
                    PageNumber = int.Parse(collection["txtPageNum"]),
                    SearchType = SearchType.DETAIL_SEARCH
                };

                int count = bus.SearchBooksCount(dto);
                return View(new SearchResultModels()
                {
                    KeyWord = collection["txtKeyword"],
                    SearchByAuthor = isByAuthor,
                    SearchByContent = isByContent,
                    SearchByTitle = isByTitle,
                    CateToSearch = collection["lstCategories"],
                    Results = bus.SearchBooks(dto),
                    NoP =
                        (int)
                        Math.Ceiling((double)count / ((double)Options.NumberOfRecord)),
                    NumberOfResult = count,
                    CurrentPage = dto.PageNumber
                });

            }
            catch
            {
                return View();
            }
        }
        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;
            }
        }
        public ActionResult Category(FormCollection collection)
        {
            try
            {
                SearchBookBUS bus = new SearchBookBUS();
                SearchBookDTO dto = new SearchBookDTO()
                {
                    Info2 = collection["txtCategoryId"],
                    PageNumber = int.Parse(collection["txtPageNum"]),
                    SearchType = SearchType.DETAIL_SEARCH
                };

                int count = bus.SearchBooksCount(dto);
                return View(new SearchResultModels()
                {
                    ParentCate = collection["txtCategoryId"],
                    Results = bus.SearchBooks(dto),
                    NoP =
                        (int)
                        Math.Ceiling((double)count / ((double)Options.NumberOfRecord)),
                    NumberOfResult = count,
                    CurrentPage = dto.PageNumber
                });

            }
            catch
            {
                return View();
            }
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            SearchBookBUS bbus = new SearchBookBUS();
            int stype = xtraTabControl1.SelectedTabPageIndex;
            dto = new SearchBookDTO();
            if (stype == 0)
            {
                dto.Info1 = txtTitle.Text;
                dto.PageNumber = 1;
                dto.SearchType = (SearchType)stype;
            }
            else if (stype == 1)
            {
                dto.Info1 = txtDetailTitle.Text;
                dto.Info2 = ((CategoryDTO)cbeDetailCategory.SelectedValue).CategoryId;
                dto.Info3 = txtShortDesc.Text;
                dto.Info4 = txtAuthorName.Text;
                dto.Cate = ((CategoryDTO)cbeDetailCategory.SelectedValue).CategoryId;
                dto.PageNumber = 1;
                dto.SearchType = (SearchType)stype;
            }
            else if (stype == 2)
            {
                dto.Info1 = txtInfo1.Text;
                dto.Info2 = txtInfo2.Text;
                dto.Info3 = txtInfo3.Text;
                dto.Field1 = cboxField1.SelectedItem.ToString();
                dto.Field2 = cboxField2.SelectedItem.ToString();
                dto.Field3 = cboxField3.SelectedItem.ToString();
                dto.Type1 = cboxType1.SelectedIndex;
                dto.Type2 = cboxType2.SelectedIndex;
                dto.Type3 = cboxType3.SelectedIndex;
                dto.Ano1 = cboxAno1.SelectedItem.ToString();
                dto.Ano2 = cboxAno2.SelectedItem.ToString();
                dto.PageNumber = 1;
                dto.SearchType = (SearchType) stype;
            }
            // get number of results
            lst.Clear();
            lst.AddRange(bbus.SearchBooks(dto));

            grcCatalogue.RefreshDataSource();
            // grcCatalogue.DataSource = lst;

            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;
            }
        }