Esempio n. 1
0
 private void SaveManufacturer()
 {
     _ManufacturerId    = AlwaysConvert.ToInt(HiddenManufacturerId.Value);
     _Manufacturer      = ManufacturerDataSource.Load(_ManufacturerId);
     _Manufacturer.Name = Name.Text;
     _Manufacturer.Save();
 }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            _categoryId     = AbleCommerce.Code.PageHelper.GetCategoryId();
            _manufacturerId = AlwaysConvert.ToInt(Request.QueryString["m"]);
            _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(_shopBy))
                {
                    url += "&shopby=" + _shopBy;
                }
                Response.Redirect(url);
            }

            int manufecturerCount = ManufacturerDataSource.CountAll();

            foreach (ListItem li in SortResults.Items)
            {
                if (li.Value.StartsWith("Manufacturer"))
                {
                    li.Enabled = manufecturerCount > 0;
                }
            }
        }
Esempio n. 3
0
        protected void Page_InIt(object sender, EventArgs e)
        {
            _IconPath = AbleCommerce.Code.PageHelper.GetAdminThemeIconPath(this.Page);
            Manufacturers.DataSource = ManufacturerDataSource.LoadForStore(AbleContext.Current.StoreId);
            Manufacturers.DataBind();

            Vendors.DataSource = VendorDataSource.LoadForStore(AbleContext.Current.StoreId);
            Vendors.DataBind();
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            //INITIALIZE VARIABLES
            _CategoryId = AbleCommerce.Code.PageHelper.GetCategoryId();
            _Category   = CategoryDataSource.Load(_CategoryId);
            _ProductId  = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
            _Product    = ProductDataSource.Load(_ProductId);
            if (_Product == null)
            {
                Response.Redirect(AbleCommerce.Code.NavigationHelper.GetAdminUrl("Catalog/Browse.aspx?CategoryId=" + _CategoryId.ToString()));
            }
            _KitComponentId = AlwaysConvert.ToInt(Request.QueryString["KitComponentId"]);
            _KitComponent   = KitComponentDataSource.Load(_KitComponentId);
            if (_KitComponent == null)
            {
                Response.Redirect("EditKit.aspx?CategoryId=" + _CategoryId.ToString() + "&ProductId=" + _ProductId.ToString());
            }
            CancelLink.NavigateUrl += "?CategoryId=" + _CategoryId.ToString() + "&ProductId=" + _ProductId.ToString();
            Caption.Text            = string.Format(Caption.Text, _KitComponent.Name);
            InstructionText.Text    = string.Format(InstructionText.Text, _KitComponent.Name, _Product.Name);

            int categoryCount             = CategoryDataSource.CountAll();
            StoreSettingsManager settings = AbleContext.Current.Store.Settings;

            _DisplayCategorySearch = settings.CategorySearchDisplayLimit > 0 && categoryCount >= settings.CategorySearchDisplayLimit;

            // INITIALIZE DROP DOWN LISTS
            if (!_DisplayCategorySearch)
            {
                InitializeCategoryTree();
            }
            else
            {
                // DISPLAY AUTO COMPLETE FOR CATEGORY SEARCH OPTION
                string js = PageHelper.GetAutoCompleteScript(Page.ResolveClientUrl("~/CategorySuggest.ashx"), CategoryAutoComplete, HiddenSelectedCategoryId, "Key", "Value");

                ScriptManager.RegisterStartupScript(PageAjax, this.GetType(), "CATEGORY_SUGGEST", js, true);
                CategoryAutoComplete.Visible = true;
                CategoryFilter.Visible       = false;
            }
            ManufacturerFilter.DataSource = ManufacturerDataSource.LoadAll("Name");
            ManufacturerFilter.DataBind();
            VendorFilter.DataSource = VendorDataSource.LoadAll("Name");
            VendorFilter.DataBind();

            // LOAD CUSTOM VIEWSTATE VARIABLES
            LoadCustomViewState();
            if (_SelectedProducts.Count > 0)
            {
                // REBIND THE REPEATER
                BindSelectedProducts(_SelectedProducts);
            }

            AbleCommerce.Code.PageHelper.SetDefaultButton(NameFilter, SearchButton.ClientID);
            AbleCommerce.Code.PageHelper.SetDefaultButton(SkuFilter, SearchButton.ClientID);
        }
        protected string GetManufacturerLink(int manufacturerId)
        {
            Manufacturer manufacturer = ManufacturerDataSource.Load(manufacturerId);

            if (manufacturer != null)
            {
                return(manufacturer.Name);
            }
            return(String.Empty);
        }
Esempio n. 6
0
 protected void Page_Init(object sender, System.EventArgs e)
 {
     _ManufacturerId = AlwaysConvert.ToInt(Request.QueryString["ManufacturerId"]);
     _Manufacturer   = ManufacturerDataSource.Load(_ManufacturerId);
     if (_Manufacturer == null)
     {
         Response.Redirect("Default.aspx");
     }
     Caption.Text         = string.Format(Caption.Text, _Manufacturer.Name);
     InstructionText.Text = string.Format(InstructionText.Text, _Manufacturer.Name);
     BindManufacturers();
 }
Esempio n. 7
0
        private void BindManufacturers()
        {
            IList <Manufacturer> manufacturers = ManufacturerDataSource.LoadAll("Name");
            int index = manufacturers.IndexOf(_ManufacturerId);

            if (index > -1)
            {
                manufacturers.RemoveAt(index);
            }
            ManufacturerList.DataSource = manufacturers;
            ManufacturerList.DataBind();
        }
Esempio n. 8
0
 protected void ManufacturerGrid_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName.Equals("EditManufacturer"))
     {
         string[] data = ((string)e.CommandArgument).Split(':');
         _ManufacturerId            = AlwaysConvert.ToInt(data[0]);
         HiddenManufacturerId.Value = _ManufacturerId.ToString();
         _Manufacturer = ManufacturerDataSource.Load(_ManufacturerId);
         Name.Text     = _Manufacturer.Name;
         ModalPopupExtender.Show();
         EditAjax.Update();
     }
 }
 protected void NewManufacturerLink_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(NewManufacturerName.Value))
     {
         Manufacturer manufacturer = ManufacturerDataSource.LoadForName(NewManufacturerName.Value, true);
         ManufacturerList.DataBind();
         ListItem selectedItem = ManufacturerList.Items.FindByValue(manufacturer.Id.ToString());
         if (selectedItem != null)
         {
             ManufacturerList.SelectedIndex = ManufacturerList.Items.IndexOf(selectedItem);
         }
     }
 }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            _ManufacturerId = AlwaysConvert.ToInt(Request.QueryString["ManufacturerId"]);
            _Manufacturer   = ManufacturerDataSource.Load(_ManufacturerId);
            if (_Manufacturer == null)
            {
                Response.Redirect("Default.aspx");
            }

            Caption.Text = string.Format(Caption.Text, _Manufacturer.Name);
            FindAssignProducts1.AssignmentValue  = _ManufacturerId;
            FindAssignProducts1.OnAssignProduct += new AssignProductEventHandler(FindAssignProducts1_AssignProduct);
            FindAssignProducts1.OnLinkCheck     += new AssignProductEventHandler(FindAssignProducts1_LinkCheck);
            FindAssignProducts1.OnCancel        += new EventHandler(FindAssignProducts1_CancelButton);
        }
Esempio n. 11
0
 protected void AddManufacturerButton_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         Manufacturer manufacturer = ManufacturerDataSource.LoadForName(AddManufacturerName.Text, false);
         // MANUFACTURER NAME SHOULD BE UNIQUE
         if (manufacturer != null)
         {
             AddManufacturerNameRequired.IsValid      = false;
             AddManufacturerNameRequired.ErrorMessage = "The manufacturer with name \"" + AddManufacturerName.Text + "\" already exists.";
             return;
         }
         manufacturer      = new Manufacturer();
         manufacturer.Name = AddManufacturerName.Text;
         manufacturer.Save();
         AddManufacturerName.Text = String.Empty;
         AddedMessage.Text        = string.Format((string)ViewState["AddedMessage.Text"], manufacturer.Name);
         AddedMessage.Visible     = true;
         ManufacturerGrid.DataBind();
         SearchAjax.Update();
     }
 }
Esempio n. 12
0
 /// <summary>
 /// Deletes a manufacturer, reassociating any products with the specified manufacturer.
 /// </summary>
 /// <param name="newManufacturerId">The manufacturer that associated products should be switched to</param>
 /// <returns>True if the manufacturer is deleted, false otherwise.</returns>
 public virtual bool Delete(int newManufacturerId)
 {
     ManufacturerDataSource.MoveProducts(this.ManufacturerId, newManufacturerId);
     return(this.Delete());
 }
        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;
                }
            }
        }
Esempio n. 14
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            Trace.Write(this.GetType().ToString(), "Load Begin");

            _categoryId     = AbleCommerce.Code.PageHelper.GetCategoryId();
            _manufacturerId = AlwaysConvert.ToInt(Request.QueryString["m"]);
            _keywords       = Server.UrlDecode(Request.QueryString["k"]);
            _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(_shopBy))
                {
                    url += "&shopby=" + _shopBy;
                }
                Response.Redirect(url);
            }

            _pageSize = AlwaysConvert.ToInt(PageSizeOptions.SelectedValue);
            ProductList.RepeatColumns = Cols;
            if (!string.IsNullOrEmpty(_keywords))
            {
                _keywords = StringHelper.StripHtml(_keywords).Trim();
            }
            _category = CategoryDataSource.Load(this._categoryId);
            if (_pageSize == 0)
            {
                _pageSize = ProductDataSource.AdvancedSearchCount(_keywords, _categoryId, _manufacturerId, true, true, true, 0, 0, false, PageHelper.GetShopByChoices());
            }
            //EXIT PROCESSING IF CATEGORY IS INVALID OR MARKED PRIVATE
            if (!IsValidCategory())
            {
                SearchResultsAjaxPanel.Visible = false;
            }
            else
            {
                if (_category != null)
                {
                    //REGISTER THE PAGEVISIT
                    AbleCommerce.Code.PageVisitHelper.RegisterPageVisit(_category.Id, CatalogNodeType.Category, _category.Name);
                }
                if (!Page.IsPostBack)
                {
                    //INITIALIZE SEARCH CRITERIA ON FIRST VISIT
                    HiddenPageIndex.Value = Request.QueryString["p"];
                    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;
                        }
                    }
                }
            }

            // NEED TO BIND THE PAGE
            // BUT IF THE MULTIPLE ADD TO BASKET BUTTON CLICKED THEN THE BINDING SHOULD TAKE PLACE AT PRE_RENDER
            // THAT IS AFTER ADD TO CART
            if (IsValidCategory() && Request.Form["__EVENTTARGET"] != MultipleAddToBasketButton.UniqueID)
            {
                BindPage();
                MultipleAddToBasketButton.Visible = _quantityVisible;
            }

            int manufecturerCount = ManufacturerDataSource.CountAll();

            foreach (ListItem li in SortResults.Items)
            {
                if (li.Value.StartsWith("Manufacturer"))
                {
                    li.Enabled = manufecturerCount > 0;
                }
            }
        }
Esempio n. 15
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;
            }
        }
Esempio n. 16
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();
        }
Esempio n. 17
0
        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);
            SetPagerIndex();

            CatalogNodeList.RepeatColumns = Cols;
            if (IsValidCategory())
            {
                //INITIALIZE THE CONTENT NODES
                _ContentNodes = new List <Product>();
                List <Product> visibleNodes = (List <Product>)ProductDataSource.LoadForCategory(true, this.CategoryId, false, true, SortResults.SelectedValue, _pageSize, (_HiddenPageIndex * _pageSize));

                // CUSTOM SORTING ON VOLUME PRICES
                if (SortResults.SelectedValue.Equals("Price ASC"))
                {
                    visibleNodes = visibleNodes.OrderBy(x => (x.VolumeDiscounts.Any() && x.VolumeDiscounts[0].Levels.Any()) ? x.VolumeDiscounts[0].Levels.First().DiscountAmount : x.Price).ThenBy(x => (x.VolumeDiscounts.Any() && x.VolumeDiscounts[0].Levels.Any()) ? x.VolumeDiscounts[0].Levels.Last().DiscountAmount : 0).ToList(); //Lowest-Highest
                }
                else if (SortResults.SelectedValue.Equals("Price DESC"))
                {
                    visibleNodes = visibleNodes.OrderByDescending(x => (x.VolumeDiscounts.Any() && x.VolumeDiscounts[0].Levels.Any()) ? x.VolumeDiscounts[0].Levels.First().DiscountAmount : x.Price).ThenByDescending(x => (x.VolumeDiscounts.Any() && x.VolumeDiscounts[0].Levels.Any()) ? x.VolumeDiscounts[0].Levels.Last().DiscountAmount : 0).ToList();  //Highest-Lowest
                }

                if (visibleNodes.Count > 0)
                {
                    _ContentNodes.AddRange(visibleNodes);

                    // DELAYED QUERIES TO EAGER LOAD RELATED DATA FOR PERFORMANCE BOOST
                    List <int> ids         = visibleNodes.Select(p => p.Id).ToList();
                    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>();

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

                    futureQuery.ToList();
                }

                if (_pageSize == 0)
                {
                    _pageSize = _ContentNodes.Count;
                }

                int minimumPageSize = AlwaysConvert.ToInt(PageSizeOptions.Items[0].Value);
                PageSizePanel.Visible = _searchResultCount > 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)
        {
            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 BindExpandResultPanel()
        {
            Trace.Write(this.GetType().ToString(), "Begin BindExpandResultPanel");

            //START WITH THE PANEL VISIBLE
            ExpandResultPanel.Visible = true;

            //BIND THE EXPAND CATEGORY LINKS
            IList <CatalogPathNode> currentPath = CatalogDataSource.GetPath(this._categoryId, false);

            if (_isCategoryPage && currentPath.Count > 0 && currentPath[0].CatalogNodeType == CatalogNodeType.Category)
            {
                currentPath.RemoveAt(0);
            }

            if (currentPath.Count > 0)
            {
                ExpandCategoryLinks.Visible    = true;
                ExpandCategoryLinks.DataSource = currentPath;
                ExpandCategoryLinks.DataBind();
            }
            else
            {
                ExpandCategoryLinks.Visible = false;
            }

            //BIND THE EXPAND MANUFACTURER LINK
            Manufacturer m = ManufacturerDataSource.Load(this._manufacturerId);

            if (m != null)
            {
                ExpandManufacturerLink.Text        = string.Format("{0} (X)", m.Name);
                ExpandManufacturerLink.NavigateUrl = RemoveQueryStringParameter("m");
                ExpandManufacturerListItem.Visible = true;
            }
            else
            {
                ExpandManufacturerListItem.Visible = false;
                ExpandManufacturerLink.NavigateUrl = "#";
            }

            //BIND THE EXPAND KEYWORD LINK
            if (!string.IsNullOrEmpty(this._keyword))
            {
                ExpandKeywordLink.Text        = string.Format("Remove Keyword: {0}", Server.HtmlEncode(this._keyword));
                ExpandKeywordLink.NavigateUrl = RemoveQueryStringParameter("k");
                ExpandKeywordListItem.Visible = true;
            }
            else
            {
                ExpandKeywordListItem.Visible = false;
            }

            IList <ShopByChoice> choices = PageHelper.GetShopByChoices();

            if (choices != null && choices.Count > 0)
            {
                ExpandShopByLinks.DataSource = choices;
                ExpandShopByLinks.DataBind();
                ExpandShopByLinks.Visible = true;
            }
            else
            {
                ExpandShopByLinks.Visible = false;
            }


            //SET VISIBILITY OF EXPAND PANEL BASED ON CHILD CONTROLS VISIBILITY
            ExpandResultPanel.Visible = (ExpandCategoryLinks.Visible || ExpandManufacturerListItem.Visible || ExpandKeywordListItem.Visible) || ExpandShopByLinks.Visible;
            Trace.Write(this.GetType().ToString(), "End BindExpandResultPanel");
        }