using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Text; using System.Collections.Generic; using System.Collections.Specialized; public partial class Browse : WebBlockPage { public int CategoryID { get { return (ViewState["CategoryID"] == null ? 0 : (int)ViewState["CategoryID"]); } set { ViewState["CategoryID"] = value; } } public string AttributeIDList { get { return (string)ViewState["AttributeIDList"]; } set { ViewState["AttributeIDList"] = value; } } public int AttributeIDCount { get { return (ViewState["AttributeIDCount"] == null ? 0 : (int)ViewState["AttributeIDCount"]); } set { ViewState["AttributeIDCount"] = value; } } #region callbacks protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (Request["CategoryID"] != null) CategoryID = Int32.Parse(Request["CategoryID"]); else if (Request.PathInfo.Length > 0) { if (Utilities.ValidateBrowseString.IsMatch(Request.PathInfo)) { // split into chunks string[] PathInfoChunks = Request.PathInfo.Split('/'); // PathInfoChunks[1] should be our ID CategoryID = Int32.Parse(PathInfoChunks[1]); // PathInfoChunks[2] is the SEO name // ignore it // PathInfoChunks[3] and onward should be the attributes to apply // we need to serialize these into a list string AttList = ""; for(int i = 3; i < PathInfoChunks.Length; i++) AttList += PathInfoChunks[i] + ","; if (AttList.Length > 0) { AttributeIDList = AttList.TrimEnd(','); AttributeIDCount = PathInfoChunks.Length - 3; } } else throw new Exception("Malformed path string."); } else { pnlAutoBrowse.Visible = false; tbCategoryLanding.Visible = true; } if (CategoryID > 0) { //ProductNav1.SelectedCategoryID = CategoryID; Breadcrumbs1.SelectedCategoryID = CategoryID; //FilterControl1.CategoryID = CategoryID; //FilterControl1.AttributeIDList = AttributeIDList; //FilterControl1.AttributeCount = AttributeIDCount; // replace the normal autogenerated browse section with a // category landing page if need be DataRow dr = Database.Categories_Get(CategoryID); if (dr != null) { string CategoryName = (string)dr["CategoryName"]; // replace the contents with the landing data if ((bool)dr["UseCategoryLanding"] && Request["Page"] == null) { tbCategoryLanding.BlockTitle = "Category Landing Page - " + CategoryName; tbCategoryLanding.Visible = true; pnlAutoBrowse.Visible = false; } else { // otherwise, set the page title and display the category contents litTitle.Text = CategoryName; wbTitle.BlockTitle = "Category Landing Page - " + CategoryName; BindData(); } // set the page title string PageTitle = ConfigurationManager.AppSettings["EstorePageTitle"]; if (PageTitle != null) Page.Title = String.Format("{0} - {1}", CategoryName, PageTitle); else Page.Title = CategoryName; } else throw new Exception("Invalid Category ID"); } BindData(); } //FilterControl1.BindData(); } protected void FilterControl1_AttributeSelected(int AttributeID) { Response.Redirect(Request.RawUrl + "/" + AttributeID); } #endregion public void BindData() { DataTable dt = Database.Selectors_GetForBrowsing(CategoryID, AttributeIDList, AttributeIDCount); if (dt.Rows.Count > 0) { DataView dv = dt.DefaultView; Pagination1.MaxResults = dv.Count; Pagination2.MaxResults = dv.Count; if (Pagination1.PageIndex != -1) { // we only need filter if they are using pagination dv.RowFilter = "RowNumber >= " + Pagination1.LowRow + " AND RowNumber < " + Pagination1.HighRow; } dlProducts.DataSource = dv; dlProducts.DataBind(); } else { pnlNoResults.Visible = true; } // now bind the sub categories, if there are any if (CategoryID > 0 && Pagination1.PageIndex == 1) { dt = Database.Categories_GetChildren(CategoryID); dlSubCategories.DataSource = dt; dlSubCategories.DataBind(); dlSubCategories.Visible = true; } } protected void dlSubCategories_ItemDataBound(object sender, DataListItemEventArgs e) { DataRowView drv = (DataRowView)e.Item.DataItem; DataList dlSubCategoryProducts = (DataList)e.Item.FindControl("dlSubCategoryProducts"); DataTable dt = Database.Selectors_GetTopResultsByCategoryID(4, (int)drv["CategoryID"]); dlSubCategoryProducts.DataSource = dt; dlSubCategoryProducts.DataBind(); } }