protected void Page_Load(object sender, EventArgs e) { string eventTarget = Request["__EVENTTARGET"]; if (string.IsNullOrEmpty(eventTarget) || !eventTarget.EndsWith("PageSizeOptions")) { string pageSizeOption = Request.QueryString["ps"]; if (!string.IsNullOrEmpty(pageSizeOption)) { PageSizeOptions.ClearSelection(); ListItem item = PageSizeOptions.Items.FindByValue(pageSizeOption); if (item != null) { item.Selected = true; } } } else if (eventTarget.EndsWith("PageSizeOptions")) { string url = Request.RawUrl; if (url.Contains("?")) { url = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("?")); } url += "?s=" + SortResults.SelectedValue; url += "&ps=" + PageSizeOptions.SelectedValue; Response.Redirect(url); } _pageSize = AlwaysConvert.ToInt(PageSizeOptions.SelectedValue); CatalogNodeList.RepeatColumns = Cols; if (IsValidCategory()) { // INITIALIZE THE CONTENT NODES _contentNodes = new List <CatalogNode>(); IList <CatalogNode> visibleNodes; if (_category != null) { visibleNodes = CatalogDataSource.LoadForCategory(_category.Id, true, true, 0, 0, string.Empty); } else { visibleNodes = CatalogDataSource.LoadForCategory(0, true, true, 0, 0, string.Empty); } if (visibleNodes.Count > 0) { // FETCH THE ASSOCIATED CATALOG ITEMS INTO ORM OBJECT GRAPH AND DISCARD RESULTS // THIS IS ESSENTIALLY FOR PERFORMANCE BOOST BY MINIMIZING NUMBER OF QUERIES var productIds = visibleNodes.Where(n => n.CatalogNodeType == CatalogNodeType.Product) .Select(n => n.CatalogNodeId) .ToList <int>(); if (productIds.Count > 0 && productIds.Count < 415) { var futureQuery = NHibernateHelper.QueryOver <Product>() .AndRestrictionOn(p => p.Id).IsIn(productIds) .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(); } var categoryIds = visibleNodes.Where(n => n.CatalogNodeType == CatalogNodeType.Category) .Select(n => n.CatalogNodeId) .ToList <int>(); if (categoryIds.Count > 0 && categoryIds.Count < 2000) { NHibernateHelper.QueryOver <Category>() .AndRestrictionOn(c => c.Id).IsIn(categoryIds) .List <Category>(); } var webpageIds = visibleNodes.Where(n => n.CatalogNodeType == CatalogNodeType.Webpage) .Select(n => n.CatalogNodeId) .ToList <int>(); if (webpageIds.Count > 0 && webpageIds.Count < 2000) { NHibernateHelper.QueryOver <Webpage>() .AndRestrictionOn(w => w.Id).IsIn(webpageIds) .List <Webpage>(); } var linkIds = visibleNodes.Where(n => n.CatalogNodeType == CatalogNodeType.Link) .Select(n => n.CatalogNodeId) .ToList <int>(); if (linkIds.Count > 0 && linkIds.Count < 2000) { NHibernateHelper.QueryOver <Link>() .AndRestrictionOn(l => l.Id).IsIn(linkIds) .List <Link>(); } } foreach (CatalogNode node in visibleNodes) { if (node.CatalogNodeType == CatalogNodeType.Category) { // only add categories that have publicly visible content int visibleCount = CatalogDataSource.CountForCategory(node.CatalogNodeId, true, true); if (visibleCount > 0) { _contentNodes.Add(node); } } else { _contentNodes.Add(node); } } if (_pageSize == 0) { _pageSize = _contentNodes.Count; } int minimumPageSize = AlwaysConvert.ToInt(PageSizeOptions.Items[0].Value); PageSizePanel.Visible = _contentNodes.Count > minimumPageSize; // BIND PAGE BindPage(); } int manufecturerCount = ManufacturerDataSource.CountAll(); foreach (ListItem li in SortResults.Items) { if (li.Value.StartsWith("Manufacturer")) { li.Enabled = manufecturerCount > 0; } } }
protected void Page_Load(object sender, EventArgs e) { if (IsValidCategory()) { string eventTarget = Request["__EVENTTARGET"]; if (string.IsNullOrEmpty(eventTarget) || !eventTarget.EndsWith("PageSizeOptions")) { string pageSizeOption = Request.QueryString["ps"]; if (!string.IsNullOrEmpty(pageSizeOption)) { PageSizeOptions.ClearSelection(); ListItem item = PageSizeOptions.Items.FindByValue(pageSizeOption); if (item != null) { item.Selected = true; } } } if (string.IsNullOrEmpty(eventTarget) || !eventTarget.EndsWith("SortResults")) { string sortOption = Request.QueryString["s"]; if (!string.IsNullOrEmpty(sortOption)) { SortResults.ClearSelection(); ListItem item = SortResults.Items.OfType <ListItem>().SingleOrDefault(x => string.Compare(x.Value, sortOption, StringComparison.InvariantCultureIgnoreCase) == 0); if (item != null) { item.Selected = true; } } } if (!string.IsNullOrEmpty(eventTarget)) { if (eventTarget.EndsWith("PageSizeOptions") || eventTarget.EndsWith("SortResults")) { string url = Request.RawUrl; if (url.Contains("?")) { url = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("?")); } url += "?s=" + SortResults.SelectedValue; url += "&ps=" + PageSizeOptions.SelectedValue; Response.Redirect(url); } } if (_Category != null) { CategoryBreadCrumbs1.CategoryId = this.CategoryId; Caption.Text = _Category.Name; if (!string.IsNullOrEmpty(_Category.Summary) && ShowSummary) { CategorySummary.Text = _Category.Summary; } if (!string.IsNullOrEmpty(_Category.Description) && ShowDescription) { CategoryDescriptionPanel.Visible = true; CategoryDescription.Text = _Category.Description; } else { CategoryDescriptionPanel.Visible = false; } } else { // IT IS ROOT CATEGORY CategoryBreadCrumbs1.CategoryId = this.CategoryId; Caption.Text = DefaultCaption; if (ShowSummary) { CategorySummary.Text = DefaultCategorySummary; } } if (_Category != null) { int count = CatalogDataSource.CountForCategory(_Category.Id, true, true); if (count > 0) { _currentPageIndex = AlwaysConvert.ToInt(Request.QueryString["p"]); _pageSize = AlwaysConvert.ToInt(PageSizeOptions.SelectedValue); _lastPageIndex = ((int)Math.Ceiling(((double)count / (double)_pageSize))) - 1; CatalogNodeList.DataSource = CatalogDataSource.LoadForCategory(_Category.Id, true, true, _pageSize, (_currentPageIndex * _pageSize), SortResults.SelectedValue); CatalogNodeList.DataBind(); int startRowIndex = (_pageSize * _currentPageIndex); int endRowIndex = startRowIndex + _pageSize; if (endRowIndex > count) { endRowIndex = count; } if (count == 0) { startRowIndex = -1; } ResultIndexMessage.Text = string.Format(ResultIndexMessage.Text, (startRowIndex + 1), endRowIndex, count); ResultIndexMessage.Text = string.Format(ResultIndexMessage.Text, (startRowIndex + 1), endRowIndex, count); BindPagingControls(); } else { phEmptyCategory.Visible = true; } AbleCommerce.Code.PageVisitHelper.RegisterPageVisit(_Category.Id, CatalogNodeType.Category, _Category.Name); } } }