protected void Page_PreRender(object sender, EventArgs e)
        {
            Trace.Write(this.GetType().ToString(), "Begin PreRender");
            //GET PRODUCT COUNTS FOR MANUFACTURERS THAT MEET SEARCH FILTER
            _manufacturers = ProductDataSource.AdvancedSearchCountByManufacturer(_keyword, this._categoryId, true, true, true, 0, 0, PageHelper.GetShopByChoices());

            //BIND THE EXPAND PANEL
            BindExpandResultPanel();

            //BIND THE NARROW BY CATEGORY PANEL
            BindNarrowByCategoryPanel();

            //BIND THE NARROW BY MANUFACTURER PANEL
            BindNarrowByManufacturerPanel();

            //BIND THE NARROW BY KEYWORD PANEL
            BindNarrowByKeywordPanel();

            BindShopByPanel();

            Trace.Write(this.GetType().ToString(), "End PreRender");
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            _categoryId     = AlwaysConvert.ToInt(Request.QueryString["c"]);
            _manufacturerId = AlwaysConvert.ToInt(Request.QueryString["m"]);
            _keywords       = StringHelper.StripHtml(Server.UrlDecode(Request.QueryString["k"]));
            if (!string.IsNullOrEmpty(_keywords))
            {
                _keywords = StringHelper.StripHtml(_keywords).Trim();
            }

            _shopBy = StringHelper.StripHtml(Server.UrlDecode(Request.QueryString["shopby"]));
            if (!string.IsNullOrEmpty(_shopBy))
            {
                _shopBy = StringHelper.StripHtml(_shopBy).Trim();
            }

            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;
                if (_categoryId != 0)
                {
                    url += "&c=" + _categoryId.ToString();
                }
                if (_manufacturerId != 0)
                {
                    url += "&m=" + _manufacturerId.ToString();
                }
                if (!string.IsNullOrEmpty(_keywords))
                {
                    url += "&k=" + _keywords;
                }
                if (!string.IsNullOrEmpty(_shopBy))
                {
                    url += "&shopby=" + _shopBy;
                }
                Response.Redirect(url);
            }

            _pageSize = AlwaysConvert.ToInt(PageSizeOptions.SelectedValue);
            ProductList.RepeatColumns = Cols;
            if (_pageSize == 0)
            {
                _pageSize = ProductDataSource.AdvancedSearchCount(_keywords, _categoryId, _manufacturerId, true, true, true, 0, 0, false, PageHelper.GetShopByChoices());
            }

            if (!Page.IsPostBack)
            {
                if (ApplicationSettings.Instance.SearchProvider == "LuceneSearchProvider" || ApplicationSettings.Instance.SearchProvider == "SqlFtsSearchProvider")
                {
                    bool sortByRelevance = true;
                    if (!string.IsNullOrEmpty(_keywords))
                    {
                        ISearchProvider      provider = SearchProviderLocator.Locate();
                        LuceneSearchProvider lucene   = provider as LuceneSearchProvider;
                        if (lucene != null)
                        {
                            sortByRelevance = !lucene.UseSQLSearch(_keywords);
                        }
                        SqlFtsSearchProvider sqlFTS = provider as SqlFtsSearchProvider;
                        if (sqlFTS != null)
                        {
                            sortByRelevance = !sqlFTS.UseSQLSearch(_keywords);
                        }
                    }

                    if (sortByRelevance)
                    {
                        SortResults.Items.Insert(0, new ListItem("By Relevance", "FTS.RANK DESC"));
                    }
                }

                //INITIALIZE SEARCH CRITERIA ON FIRST VISIT
                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;
                    }
                }
            }

            int  manufecturerCount      = ManufacturerDataSource.CountAll();
            bool showSortByManufacturer = false;

            if (manufecturerCount > 0 && _manufacturerId == 0)
            {
                IList <ManufacturerProductCount> mCounts = ProductDataSource.AdvancedSearchCountByManufacturer(_keywords, _categoryId, true, true, true, 0, 0, PageHelper.GetShopByChoices());
                showSortByManufacturer = mCounts != null && mCounts.Count > 0;
            }

            foreach (ListItem li in SortResults.Items)
            {
                if (li.Value.StartsWith("Manufacturer"))
                {
                    li.Enabled = showSortByManufacturer;
                }
            }

            BindSearchResultsPanel();
        }