protected bool HasChildProducts(Category cat) { if (cat == null) { return(false); } return(ProductDataSource.CountForCategory(cat.Id, false, true) > 0); }
private void InitializePagingVars(bool forceRefresh) { Trace.Write("Initialize Paging Vars"); if (!_PagingVarsInitialized || forceRefresh) { _HiddenPageIndex = AlwaysConvert.ToInt(HiddenPageIndex.Value); _searchResultCount = ProductDataSource.CountForCategory(true, this.CategoryId, false, true); _LastPageIndex = ((int)Math.Ceiling(((double)_searchResultCount / (double)_pageSize))) - 1; _PagingVarsInitialized = true; } }
protected void PagerControls_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "Page") { InitializePagingVars(false); _HiddenPageIndex = AlwaysConvert.ToInt((string)e.CommandArgument); _searchResultCount = ProductDataSource.CountForCategory(true, this.CategoryId, false, true); if (_HiddenPageIndex < 0) { _HiddenPageIndex = 0; } if (_HiddenPageIndex > _LastPageIndex) { _HiddenPageIndex = _LastPageIndex; } HiddenPageIndex.Value = _HiddenPageIndex.ToString(); } }
protected void BindSubCategories() { IList <Category> allCategories = CategoryDataSource.LoadForParent(this.CategoryId, true); List <SubCategoryData> populatedCategories = new List <SubCategoryData>(); foreach (Category category in allCategories) { int productCount = ProductDataSource.CountForCategory(true, category.Id, true, true); if (productCount > 0) { populatedCategories.Add(new SubCategoryData(category.Id, category.Name, category.NavigateUrl, productCount)); } } if (populatedCategories.Count > 0) { SubCategoryPanel.Visible = true; SubCategoryRepeater.DataSource = populatedCategories; SubCategoryRepeater.DataBind(); } else { SubCategoryPanel.Visible = false; } }
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; } }
protected void Page_Load(object sender, EventArgs e) { CategoryBreadCrumbs1.Visible = DisplayBreadCrumbs; CategoryBreadCrumbs1.CategoryId = this.CategoryId; //BIND THE DISPLAY ELEMENTS if (IsValidCategory()) { if (_Category != null) { Caption.Text = _Category.Name; if (!string.IsNullOrEmpty(_Category.Summary) && ShowSummary) { CategorySummaryPanel.Visible = true; CategorySummary.Text = _Category.Summary; } else { CategorySummaryPanel.Visible = false; } if (!string.IsNullOrEmpty(_Category.Description) && ShowDescription) { CategoryDescriptionPanel.Visible = true; CategoryDescription.Text = _Category.Description; } else { CategoryDescriptionPanel.Visible = false; } } else { // IF IT IS ROOT CATEGORY Caption.Text = DefaultCaption; } BindSubCategories(); if (_Category != null) { //UPDATE THE RESULT INDEX MESSAGE _totalProducts = ProductDataSource.CountForCategory(true, _Category.Id, false, true); } //INITIALIZE PAGING VARIABLES InitializePagingVars(false); int startRowIndex = (_PageSize * _HiddenPageIndex); int endRowIndex = startRowIndex + _PageSize; if (endRowIndex > _totalProducts) { endRowIndex = _totalProducts; } if (_totalProducts == 0) { startRowIndex = -1; } ResultIndexMessage.Text = string.Format(ResultIndexMessage.Text, (startRowIndex + 1), endRowIndex, _totalProducts); if (_Category != null) { var products = ProductDataSource.LoadForCategory(true, _Category.Id, false, true, SortResults.SelectedValue, PageSize, startRowIndex); if (products.Count > 0) { var productIds = products.Select(p => p.Id) .ToList <int>(); var futureQuery = NHibernateHelper.QueryOver <Product>() .AndRestrictionOn(p => p.Id).IsIn(productIds) .Fetch(p => p.Manufacturer).Eager .Fetch(p => p.Specials).Eager .Future <Product>(); NHibernateHelper.QueryOver <Product>() .AndRestrictionOn(p => p.Id).IsIn(productIds) .Fetch(p => p.ProductOptions).Eager .Future <Product>(); NHibernateHelper.QueryOver <Product>() .AndRestrictionOn(p => p.Id).IsIn(productIds) .Fetch(p => p.ProductKitComponents).Eager .Future <Product>(); NHibernateHelper.QueryOver <Product>() .AndRestrictionOn(p => p.Id).IsIn(productIds) .Fetch(p => p.ProductTemplates).Eager .Future <Product>(); NHibernateHelper.QueryOver <Product>() .AndRestrictionOn(p => p.Id).IsIn(productIds) .Fetch(p => p.Reviews).Eager .Future <Product>(); futureQuery.ToList(); } CatalogNodeList.DataSource = products; CatalogNodeList.DataBind(); } if (_totalProducts > 0) { phCategoryContents.Visible = true; //BIND THE PAGING CONTROLS FOOTER BindPagingControls(); } else { ResultIndexMessage.Text = string.Format(ResultIndexMessage.Text, 0, 0, 0); //HIDE THE CONTENTS phCategoryContents.Visible = false; phEmptyCategory.Visible = (_Category != null && _Category.CatalogNodes.Count == 0); phNoSearchResults.Visible = !phEmptyCategory.Visible; } //UPDATE AJAX PANEL SearchResultsAjaxPanel.Update(); } else { CategoryHeaderPanel.Visible = false; } int manufecturerCount = ManufacturerDataSource.CountAll(); foreach (ListItem li in SortResults.Items) { if (li.Value.StartsWith("Manufacturer")) { li.Enabled = manufecturerCount > 0; } } }