Exemple #1
0
        protected void BindSearch()
        {
            ProductBrowseQuery productBrowseQuery = this.GetCurrProductBrowseQuery();

            if (this.serach_text != null)
            {
                this.serach_text.Value = productBrowseQuery.Keywords;
            }
            if (search_Subtext != null)
            {
                search_Subtext.Value = productBrowseQuery.SubKeywords;
            }
            DbQueryResult browseProductList = ProductBrowser.GetCurrBrowseProductList(productBrowseQuery);

            this.rptProducts.DataSource = browseProductList.Data;
            this.rptProducts.DataBind();

            #region 获取控件品牌、产地过滤条件
            List <string> search_BrandStr     = new List <string>();
            List <string> search_ProducingStr = new List <string>();
            if (common_attributeslist != null)
            {
                DataTable dt = ProductBrowser.GetBrowseProductImportSourceIdAndBrandIdList(productBrowseQuery);
                foreach (DataRow r in dt.Rows)
                {
                    string str = r["BrandId"].ToString();
                    if (!search_BrandStr.Contains(str) && !string.IsNullOrWhiteSpace(str))
                    {
                        search_BrandStr.Add(str);
                    }
                    str = r["ImportSourceId"].ToString();
                    if (!search_ProducingStr.Contains(str) && !string.IsNullOrWhiteSpace(str) && !str.Equals("0"))
                    {
                        search_ProducingStr.Add(str);
                    }
                }
                //更新品牌、产地控件显示值

                this.common_attributeslist.search_BrandStr     = search_BrandStr;
                this.common_attributeslist.search_ProducingStr = search_ProducingStr;
            }
            #endregion

            this.hotSale = (Common_GoodsList_HotSale)this.FindControl("list_Common_GoodsList_HotSale");//销售排行
            if (this.hotSale != null)
            {
                int cid     = 0;
                int brandId = 0;
                if (!string.IsNullOrEmpty(this.Page.Request.QueryString["categoryId"]))
                {
                    int.TryParse(this.Page.Request.QueryString["categoryId"], out cid);
                }
                if (!string.IsNullOrEmpty(this.Page.Request.QueryString["brand"]))
                {
                    int.TryParse(this.Page.Request.QueryString["brand"], out brandId);
                }
                this.hotSale.DataSource = ProductBrowser.GetBrowseHotProductList(cid, brandId).DBHotSale;
                this.hotSale.DataBind();
            }

            this.pager.TotalRecords = browseProductList.TotalRecords;
            int pageCount = browseProductList.TotalRecords / this.pager.PageSize;
            if (browseProductList.TotalRecords % this.pager.PageSize > 0)
            {
                pageCount++;
            }

            if (pageCount <= 1)
            {
                //this.litSearchResultPage.Text = string.Format("共<span>{0}</span>件商品<span class=\"pager\">&lt;<span class=\"cur-page\">{1}</span>/<span class=\"total-page\">{1}</span>&gt;</span>", browseProductList.TotalRecords, pageCount);
                this.litSearchResultPage.Text = string.Format("<span class=\"fb\">共<span class=\"total-count\">{0}</span>件商品</span><span class=\"pager\"><span class=\"cur-page\">{1}</span>/<span class=\"total-page\">{1}页</span></span>", browseProductList.TotalRecords, pageCount);
                return;
            }
            #region 分页控件代码

            int pageIndex = 1;
            if (!string.IsNullOrEmpty(this.Page.Request.QueryString["pageindex"]))
            {
                int.TryParse(this.Page.Request.QueryString["pageindex"], out pageIndex);
            }
            if (browseProductList.TotalRecords <= 0)
            {
                pageIndex = 0;
            }

            string previousPager = "";
            string nextPager     = "";

            Regex           regex       = new Regex(@"(pageindex=\d+)");
            MatchCollection tempMatches = regex.Matches(this.Page.Request.RawUrl);
            if (tempMatches.Count == 0)
            {
                previousPager = this.Page.Request.RawUrl + (this.Page.Request.RawUrl.Contains("?") ? "&" : "?") + "pageindex=1";
                if (pageCount > 1)
                {
                    nextPager = this.Page.Request.RawUrl + (this.Page.Request.RawUrl.Contains("?") ? "&" : "?") + "pageindex=2";
                }
                else
                {
                    nextPager = previousPager;
                }
            }
            if (tempMatches.Count == 1)
            {
                foreach (Match item in tempMatches)
                {
                    string pagerInfo = item.Value;
                    if (pageIndex <= pageCount)
                    {
                        if ((pageIndex - 1) > 0)
                        {
                            previousPager = this.Page.Request.RawUrl.Replace(pagerInfo, "") + "pageindex=" + (pageIndex - 1);
                        }
                        else
                        {
                            previousPager = this.Page.Request.RawUrl.Replace(pagerInfo, "") + "pageindex=1";
                        }
                        if ((pageIndex + 1) <= pageCount)
                        {
                            nextPager = this.Page.Request.RawUrl.Replace(pagerInfo, "") + "pageindex=" + (pageIndex + 1);
                        }
                        else
                        {
                            nextPager = this.Page.Request.RawUrl.Replace(pagerInfo, "") + "pageindex=" + pageCount;
                        }
                    }
                }
            }

            #endregion

            if (pageCount > 1 && pageIndex == 1)
            {
                this.litSearchResultPage.Text = string.Format("<span class=\"fb\">共<span>{0}</span>件商品</span><span class=\"pager\"><span class=\"cur-page\">{2}</span>/<span class=\"total-page\">{3}页</span><a class=\"prev-page disabled\" href=\"{1}\">上一页</a><a class=\"next-page\" href=\"{4}\">下一页</a></span>", new object[]
                {
                    browseProductList.TotalRecords,
                    previousPager,
                    pageIndex,
                    pageCount,
                    nextPager
                });
            }
            else
            {
                this.litSearchResultPage.Text = string.Format("<span class=\"fb\">共<span>{0}</span>件商品</span><span class=\"pager\"><span class=\"cur-page\">{2}</span>/<span class=\"total-page\">{3}页</span><a class=\"prev-page\" href=\"{1}\">上一页</a><a class=\"next-page\" href=\"{4}\">下一页</a></span>", new object[]
                {
                    browseProductList.TotalRecords,
                    previousPager,
                    pageIndex,
                    pageCount,
                    nextPager
                });
            }
        }