public ActionResult Author(int id)
        {
            try
            {
                SearchBookBUS bus = new SearchBookBUS();
                SearchBookDTO dto = new SearchBookDTO()
                {
                    Info1 = id.ToString(),
                    PageNumber = 1,
                    SearchType = SearchType.DETAIL_SEARCH
                };

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

            }
            catch
            {
                return View();
            }
        }
        public List<SearchBookResultDTO> SearchBooks(SearchBookDTO dto)
        {
            SearchBookDAO sbDAO=new SearchBookDAO();
            List<SearchBookResultDTO> result = new List<SearchBookResultDTO>();

            int pageSize = Options.NumberOfRecord;
            int rowStart = 0;
            if(dto.PageNumber==1)
            {
                rowStart = 1;
            }
            else
            {
                rowStart = (dto.PageNumber - 1)*pageSize;
            }
            int rowEnd = rowStart - 1 + pageSize;
            switch(dto.SearchType)
            {
                case SearchType.BASIC_SEARCH:
                    result = sbDAO.SearchBasicBooks(dto.Info1, rowStart, rowEnd);
                    break;
                case SearchType.DETAIL_SEARCH:
                    result = sbDAO.SearchDetailBooks(dto.Info1, dto.Info2, dto.Info3, dto.Info4, rowStart, rowEnd);
                    break;
                default:
                    result = sbDAO.SearchAdvanceBooks(dto, rowStart, rowEnd);
                    break;
            }
            return result;
        }
        public ActionResult Author(FormCollection collection)
        {
            try
            {
                SearchBookBUS bus = new SearchBookBUS();
                SearchBookDTO dto = new SearchBookDTO()
                {
                    Info1 = collection["txtAuthor"],
                    PageNumber = int.Parse(collection["txtPageNum"]),
                    SearchType = SearchType.DETAIL_SEARCH
                };

                int count = bus.SearchBooksByAuthorCount(dto);
                return View(new SearchResultModels()
                {
                    Author = int.Parse(collection["txtAuthor"]),
                    Results = bus.SearchBooksByAuthor(dto),
                    NoP =
                        (int)
                        Math.Ceiling((double)count / ((double)Options.NumberOfRecord)),
                    NumberOfResult = count,
                    CurrentPage = dto.PageNumber
                });

            }
            catch
            {
                return View();
            }
        }
        // By Author
        public List<SearchBookResultDTO> SearchBooksByAuthor(SearchBookDTO dto)
        {
            SearchBookDAO sbDAO = new SearchBookDAO();
            List<SearchBookResultDTO> result = new List<SearchBookResultDTO>();
            CatalogueBUS bus = new CatalogueBUS();

            int pageSize = Options.NumberOfRecord;
            int rowStart = 0;
            if (dto.PageNumber == 1)
            {
                rowStart = 1;
            }
            else
            {
                rowStart = (dto.PageNumber - 1) * pageSize;
            }
            int rowEnd = rowStart - 1 + pageSize;
            DataTable dt;

            dt = sbDAO.SearchBooksByAuthor(dto.Info1, rowStart, rowEnd);

            foreach (DataRowView record in dt.DefaultView)
            {
                result.Add(new SearchBookResultDTO()
                {
                    ISBN = record["ISBN"].ToString(),
                    AuthorName = record["AuthorName"].ToString(),
                    CategoryName = record["CategoryName"].ToString(),
                    Image = record["Image"].ToString(),
                    PublisherName = record["PublisherName"].ToString(),
                    Title = record["Title"].ToString(),
                    ShortDescription = record["ShortDescription"].ToString(),
                    No = int.Parse(record["No"].ToString())
                });
            }
            return result;
        }
 private void btnSearch_Click(object sender, EventArgs e)
 {
     if(this.Type==1)
     {
         SearchUserDTO dto=new SearchUserDTO();
         dto.UserName = txtInformation.Text;
         SearchUserBUS bus=new SearchUserBUS();
         grdSimpleInfo.DataSource = bus.SearchSimpleUser(dto);
     }
     else if (this.Type == 2)
     {
         SearchBookDTO dto=new SearchBookDTO();
         dto.Info1 = txtInformation.Text;
         SearchBookBUS bus=new SearchBookBUS();
         grdSimpleInfo.DataSource = bus.SearchBarcode(dto);
     }
     else
     {
         SearchBookDTO dto = new SearchBookDTO();
         dto.Info1 = txtInformation.Text;
         SearchBookBUS bus = new SearchBookBUS();
         grdSimpleInfo.DataSource = bus.SearchCatalogue(dto);
     }
 }
        public int SearchBooksCount(SearchBookDTO dto)
        {
            SearchBookDAO sbDAO=new SearchBookDAO();
            int result;

            switch(dto.SearchType)
            {
                case SearchType.BASIC_SEARCH:
                    result = sbDAO.SearchBasicBooksCount(dto.Info1);
                    break;
                case SearchType.DETAIL_SEARCH:
                    result = sbDAO.SearchDetailBooksCount(dto.Info1, dto.Info2, dto.Info3, dto.Info4);
                    break;
                default:
                    result = sbDAO.SearchAdvanceBooksCount(dto);
                    break;
            }

            return result;
        }
        public int SearchBooksByAuthorCount(SearchBookDTO dto)
        {
            SearchBookDAO sbDAO = new SearchBookDAO();
            int result;

            result = sbDAO.SearchBooksByAuthorCount(dto.Info1);

            return result;
        }
 public List<SearchBookDAO.SimpleCatalogue> SearchCatalogue(SearchBookDTO dto)
 {
     SearchBookDAO dao = new SearchBookDAO();
     return dao.SearchCatalogue(dto);
 }
 //Simple Search for rental
 public List<SearchBookDAO.SimpleCopyOfBook> SearchBarcode(SearchBookDTO dto)
 {
     SearchBookDAO dao=new SearchBookDAO();
     return dao.SearchBarcode(dto);
 }
        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;
            }
        }
        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;
            }
        }
        public List<SearchBookResultDTO> SearchAdvanceBooks(SearchBookDTO dto, int sRow, int eRow)
        {
            string param1 = GetParamInfor(dto.Field1, dto.Type1, dto.Info1);
            string param2 = dto.Ano1 + " " + GetParamInfor(dto.Field2, dto.Type2, dto.Info2);
            string param3 = dto.Ano2 + " " + GetParamInfor(dto.Field3, dto.Type3, dto.Info3);

            List<SearchBookResultDTO> listResult = new List<SearchBookResultDTO>();
            SearchBookResultDTO resultDto;
            try
            {
                SqlDataReader reader = ConnectionManager.GetCommand("sp0001advance",
                                                                    new Dictionary<string, SqlDbType>()
                                                                        {
                                                                            {"@param1",SqlDbType.NVarChar},
                                                                            {"@param2",SqlDbType.NVarChar},
                                                                            {"@param3",SqlDbType.NVarChar},
                                                                            {"@sRow",SqlDbType.NVarChar},
                                                                            {"@eRow",SqlDbType.NVarChar}
                                                                        },
                                                                    new List<object>() { param1, param2, param3, sRow.ToString(), eRow.ToString() }).
                    ExecuteReader();
                while(reader.Read())
                {
                    resultDto = new SearchBookResultDTO();
                    resultDto.ISBN = reader["ISBN"].ToString();
                    resultDto.AuthorName = reader["AuthorName"].ToString();
                    resultDto.CategoryName = reader["CategoryName"].ToString();
                    resultDto.Image = reader["Image"].ToString();
                    resultDto.PublisherName = reader["PublisherName"].ToString();
                    resultDto.Title = reader["Title"].ToString();
                    resultDto.ShortDescription = reader["ShortDescription"].ToString();
                    resultDto.No = int.Parse(reader["No"].ToString());
                    listResult.Add(resultDto);
                }
                //int count = result.Rows.Count;
                reader.Close();
            }
            catch (Exception e)
            {
                Log.Logger.Error("Error at SearchBookDAO - SearchAdvanceBooks", e);
                return null;
            }

            return listResult;
        }
        public List<SimpleCatalogue> SearchCatalogue(SearchBookDTO dto)
        {
            SimpleCatalogue scob;
            List<SimpleCatalogue> list = new List<SimpleCatalogue>();
            try
            {
                SqlDataReader reader = ConnectionManager.GetCommand("sp0001catalogue",
                                                                    new Dictionary<string, SqlDbType>()
                                                                        {
                                                                            {"@title", SqlDbType.NVarChar}
                                                                        },
                                                                    new List<object>()
                                                                        {
                                                                            dto.Info1
                                                                        }).
                    ExecuteReader();
                while (reader.Read())
                {
                    scob = new SimpleCatalogue();
                    scob.ISBN = reader["ISBN"].ToString();
                    scob.Title = reader["Title"].ToString();
                    list.Add(scob);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                Log.Error("Error at SearchBooksDAO - SearchCatalogue", e);
                return null;
            }

            return list;
        }
        public int SearchAdvanceBooksCount(SearchBookDTO dto)
        {
            string param1 = GetParamInfor(dto.Field1, dto.Type1, dto.Info1);
            string param2 = dto.Ano1 + " " + GetParamInfor(dto.Field2, dto.Type2, dto.Info2);
            string param3 = dto.Ano2 + " " + GetParamInfor(dto.Field3, dto.Type3, dto.Info3);
            int result;
            try
            {
                result = (int)ConnectionManager.GetCommand("sp0001advanceC",
                                                                    new Dictionary<string, SqlDbType>()
                                                                        {
                                                                            {"@param1",SqlDbType.NVarChar},
                                                                            {"@param2",SqlDbType.NVarChar},
                                                                            {"@param3",SqlDbType.NVarChar}
                                                                        },
                                                                    new List<object>() { param1, param2, param3 }).
                    ExecuteScalar();
            }
            catch (Exception e)
            {
                Log.Logger.Error("Error at SearchBookDAO - SearchAdvanceBooksCount", e);
                return 0;
            }

            return result;
        }