protected void BindPagingControls()
        {
            if (_lastPageIndex > 0)
            {
                PagerPanel.Visible    = (PagingLinksLocation == "BOTTOM" || PagingLinksLocation == "TOPANDBOTTOM");
                PagerPanelTop.Visible = (PagingLinksLocation == "TOP" || PagingLinksLocation == "TOPANDBOTTOM");

                float tempIndex         = ((float)_currentPageIndex / 10) * 10;
                int   currentPagerIndex = (int)tempIndex;

                int totalPages = currentPagerIndex + 1 + _pageSize; // ADD ONE BECAUSE IT IS A ZERO BASED INDEX
                if (totalPages > (_lastPageIndex + 1))
                {
                    totalPages = (_lastPageIndex + 1);
                }

                string baseUrl;
                if (_Category != null)
                {
                    baseUrl = this.Page.ResolveUrl(_Category.NavigateUrl) + "?";
                }
                else
                {
                    baseUrl = this.Page.ResolveUrl(Request.Url.AbsolutePath) + "?";
                }

                string s = Request.QueryString["s"];
                if (!string.IsNullOrEmpty(s))
                {
                    baseUrl = baseUrl + "s=" + s + "&";
                }

                string ps = Request.QueryString["ps"];
                if (string.IsNullOrEmpty(ps))
                {
                    ps = _pageSize.ToString();
                }
                if (!string.IsNullOrEmpty(ps))
                {
                    baseUrl = baseUrl + "ps=" + ps + "&";
                }

                if (PagerPanel.Visible)
                {
                    PagerControls.DataSource = AbleCommerce.Code.NavigationHelper.GetPaginationLinks(currentPagerIndex, totalPages, baseUrl);
                    PagerControls.DataBind();
                }

                if (PagerPanelTop.Visible)
                {
                    PagerControlsTop.DataSource = AbleCommerce.Code.NavigationHelper.GetPaginationLinks(currentPagerIndex, totalPages, baseUrl);
                    PagerControlsTop.DataBind();
                }
            }
            else
            {
                PagerPanel.Visible    = false;
                PagerPanelTop.Visible = false;
            }
        }
        protected void BindPagingControls()
        {
            if (_lastPageIndex > 0)
            {
                PagerPanel.Visible    = (PagingLinksLocation == "BOTTOM" || PagingLinksLocation == "TOPANDBOTTOM");
                PagerPanelTop.Visible = (PagingLinksLocation == "TOP" || PagingLinksLocation == "TOPANDBOTTOM");

                float tempIndex         = ((float)_hiddenPageIndex / 10) * 10;
                int   currentPagerIndex = (int)tempIndex;

                int totalPages = currentPagerIndex + 1 + _pageSize; // ADD ONE BECAUSE IT IS A ZERO BASED INDEX
                if (totalPages > (_lastPageIndex + 1))
                {
                    totalPages = (_lastPageIndex + 1);
                }

                string baseUrl;
                if (_category != null)
                {
                    baseUrl = this.Page.ResolveUrl(_category.NavigateUrl) + "?";
                }
                else if (this.CategoryId == 0)
                {
                    baseUrl = this.Page.ResolveUrl(Request.Url.AbsolutePath) + "?";
                }
                else
                {
                    baseUrl = AbleCommerce.Code.NavigationHelper.GetStoreUrl(this.Page, "Search.aspx?");
                }
                //if (!string.IsNullOrEmpty(_Keywords)) baseUrl += "k=" + Server.UrlEncode(_Keywords) + "&";
                //if (_ManufacturerId != 0) baseUrl += "m=" + _ManufacturerId.ToString() + "&";
                if (!String.IsNullOrEmpty(SortResults.SelectedValue))
                {
                    baseUrl += "s=" + SortResults.SelectedValue + "&";
                }
                if (!string.IsNullOrEmpty(PageSizeOptions.SelectedValue))
                {
                    baseUrl += "ps=" + PageSizeOptions.SelectedValue + "&";
                }

                if (PagerPanel.Visible)
                {
                    PagerControls.DataSource = AbleCommerce.Code.NavigationHelper.GetPaginationLinks(currentPagerIndex, totalPages, baseUrl);
                    PagerControls.DataBind();
                }

                if (PagerPanelTop.Visible)
                {
                    PagerControlsTop.DataSource = AbleCommerce.Code.NavigationHelper.GetPaginationLinks(currentPagerIndex, totalPages, baseUrl);
                    PagerControlsTop.DataBind();
                }
            }
            else
            {
                PagerPanel.Visible    = false;
                PagerPanelTop.Visible = false;
            }
        }
Exemple #3
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            string kwords = KeywordField.Text;

            if (string.IsNullOrEmpty(kwords))
            {
                kwords = HiddenSearchKeywords.Value;
            }
            if (Page.IsPostBack && !string.IsNullOrEmpty(kwords))
            {
                _keywords = StringHelper.StripHtml(kwords).Trim();
                HiddenSearchKeywords.Value = _keywords;
            }
            else
            {
                _keywords = Server.UrlDecode(Request.QueryString["k"]);
                if (!string.IsNullOrEmpty(_keywords))
                {
                    _keywords = StringHelper.StripHtml(_keywords).Trim();
                }
            }

            if (HasSearchCriteria())
            {
                //has something to search
                ResultsPanel.Visible          = true;
                NoSearchCriteriaPanel.Visible = false;
                ResultTermMessage.Visible     = true;

                if (!Page.IsPostBack)
                {
                    //initialize search sorting and paging criteria based on query string parameters
                    HiddenPageIndex.Value = AlwaysConvert.ToInt(Request.QueryString["p"]).ToString();
                    string tempSort = Request.QueryString["s"];
                    if (!string.IsNullOrEmpty(tempSort))
                    {
                        ListItem item = SortResults.Items.FindByValue(tempSort);
                        if (item != null)
                        {
                            item.Selected = true;
                        }
                    }
                }

                //initialize paging vars
                _hiddenPageIndex   = AlwaysConvert.ToInt(HiddenPageIndex.Value);
                _searchResultCount = ProductDataSource.AdvancedSearchCount(_keywords, _categoryId, _manufacturerId, true, true, true, 0, 0);
                _lastPageIndex     = ((int)Math.Ceiling(((double)_searchResultCount / (double)_pageSize))) - 1;
                if (_hiddenPageIndex > _lastPageIndex)
                {
                    _hiddenPageIndex = _lastPageIndex;
                }
                if (_pageSize == 0)
                {
                    _pageSize = _searchResultCount;
                }

                //update the header search criteria message
                StringBuilder sb = new StringBuilder();
                if (!string.IsNullOrEmpty(_keywords))
                {
                    sb.Append(string.Format(" for '{0}'", _keywords));
                }
                Category category = CategoryDataSource.Load(_categoryId);
                if (category != null)
                {
                    sb.Append(string.Format(" in '{0}'", category.Name));
                }
                Manufacturer manufacturer = ManufacturerDataSource.Load(_manufacturerId);
                if (manufacturer != null)
                {
                    sb.Append(string.Format(" in '{0}'", manufacturer.Name));
                }
                ResultTermMessage.Text = string.Format(ResultTermMessage.Text, sb.ToString());

                //bind search results
                int startIndex = (_hiddenPageIndex * _pageSize);
                if (startIndex < 0)
                {
                    startIndex = 0;
                }
                var products = ProductDataSource.AdvancedSearch(_keywords, _categoryId, _manufacturerId, true, true, true, 0, 0, _pageSize, startIndex, SortResults.SelectedValue);

                // DELAYED QUERIES TO EAGER LOAD RELATED DATA FOR PERFORMANCE BOOST
                if (products.Count < 415)
                {
                    List <int> ids = products.Select(p => p.Id).ToList <int>();

                    var futureQuery = NHibernateHelper.QueryOver <Product>()
                                      .AndRestrictionOn(p => p.Id).IsIn(ids)
                                      .Fetch(p => p.Specials).Eager
                                      .Future <Product>();

                    NHibernateHelper.QueryOver <Product>()
                    .AndRestrictionOn(p => p.Id).IsIn(ids)
                    .Fetch(p => p.ProductOptions).Eager
                    .Future <Product>();

                    NHibernateHelper.QueryOver <Product>()
                    .AndRestrictionOn(p => p.Id).IsIn(ids)
                    .Fetch(p => p.ProductKitComponents).Eager
                    .Future <Product>();

                    NHibernateHelper.QueryOver <Product>()
                    .AndRestrictionOn(p => p.Id).IsIn(ids)
                    .Fetch(p => p.ProductTemplates).Eager
                    .Future <Product>();

                    futureQuery.ToList();
                }

                ProductList.DataSource = products;
                ProductList.DataBind();

                NoResultsPanel.Visible = _searchResultCount == 0;
                SortPanel.Visible      = _searchResultCount > 1;

                //bind paging
                int totalPages;
                if (_pageSize <= 0)
                {
                    totalPages = 1;
                }
                else
                {
                    totalPages = (int)Math.Ceiling((double)_searchResultCount / _pageSize);
                }

                if (_lastPageIndex > 0)
                {
                    PagerPanel.Visible    = true;
                    PagerPanelTop.Visible = true;
                    List <PagerLinkData> pagerLinkData = GetPagingLinkData(totalPages);
                    PagerControls.DataSource = pagerLinkData;
                    PagerControls.DataBind();
                    PagerControlsTop.DataSource = pagerLinkData;
                    PagerControlsTop.DataBind();

                    PagerMessageTop.Text    = string.Format("Page {0} of {1}", (_hiddenPageIndex + 1), totalPages);
                    PagerMessageBottom.Text = string.Format("Page {0} of {1}", (_hiddenPageIndex + 1), totalPages);
                }
                else
                {
                    PagerPanel.Visible    = false;
                    PagerPanelTop.Visible = false;
                }
            }
            else
            {
                //no search criteria
                ResultsPanel.Visible          = false;
                NoSearchCriteriaPanel.Visible = true;
                ResultTermMessage.Visible     = false;
            }
        }
Exemple #4
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            Page.Title   = string.IsNullOrEmpty(_category.Title) ? _category.Name : _category.Title;
            Caption.Text = _category.Name;

            if (!Page.IsPostBack)
            {
                //initialize search sorting and paging criteria based on query string parameters
                HiddenPageIndex.Value = AlwaysConvert.ToInt(Request.QueryString["p"]).ToString();
                string tempSort = Request.QueryString["s"];
                if (!string.IsNullOrEmpty(tempSort))
                {
                    ListItem item = SortResults.Items.OfType <ListItem>().SingleOrDefault(x => string.Compare(x.Value, tempSort, StringComparison.InvariantCultureIgnoreCase) == 0);
                    if (item != null)
                    {
                        item.Selected = true;
                    }
                }
            }

            //initialize paging vars
            _hiddenPageIndex = AlwaysConvert.ToInt(HiddenPageIndex.Value);
            _productCount    = ProductDataSource.CountForCategory(_categoryId, false, true);
            _lastPageIndex   = ((int)Math.Ceiling(((double)_productCount / (double)_pageSize))) - 1;
            if (_hiddenPageIndex > _lastPageIndex)
            {
                _hiddenPageIndex = _lastPageIndex;
            }
            if (_pageSize == 0)
            {
                _pageSize = _productCount;
            }

            //bind products
            ProductList.DataSource = ProductDataSource.LoadForCategory(true, _categoryId, false, true, SortResults.SelectedValue, _pageSize, (_hiddenPageIndex * _pageSize));
            ProductList.DataBind();

            ProductsPanel.Visible = _productCount > 0;
            if (_productCount == 0 && CategoryDataSource.CountForParent(_categoryId, true) == 0)
            {
                NoResultPanel.Visible = true;
            }

            //bind paging
            int totalPages;

            if (_pageSize <= 0)
            {
                totalPages = 1;
            }
            else
            {
                totalPages = (int)Math.Ceiling((double)_productCount / _pageSize);
            }

            if (_lastPageIndex > 0)
            {
                PagerPanel.Visible    = true;
                PagerPanelTop.Visible = true;
                List <PagerLinkData> pagerLinkData = GetPagingLinkData(totalPages);
                PagerControls.DataSource = pagerLinkData;
                PagerControls.DataBind();
                PagerControlsTop.DataSource = pagerLinkData;
                PagerControlsTop.DataBind();

                PagerMessageTop.Text    = string.Format("Page {0} of {1}", (_hiddenPageIndex + 1), totalPages);
                PagerMessageBottom.Text = string.Format("Page {0} of {1}", (_hiddenPageIndex + 1), totalPages);
            }
            else
            {
                PagerPanel.Visible    = false;
                PagerPanelTop.Visible = false;
            }
        }