Пример #1
0
        public override void DataBind()
        {
            if (bound)
            {
                return;
            }
            bound = true;

            DataView      source = new DataView();
            CategoriesMgr pMgr   = new CategoriesMgr();
            int           catId  = -1;

            if (category != "")
            {
                DataView cats = pMgr.GetCategories(string.Format("name='{0}'", category)).DefaultView;
                if (cats.Count > 0)
                {
                    catId       = (int)cats[0]["CategoryId"];
                    source      = pMgr.GetChildrenCategories(catId).DefaultView;
                    source.Sort = "SortingOrder";
                }
            }



            this.DataSource     = source;
            this.DataTextField  = "Title";
            this.DataValueField = "CategoryId";

            this.Visible = source.Count > 0;

            base.DataBind();
        }
Пример #2
0
        public override void DataBind()
        {
            if (_bound)
            {
                return;
            }
            _bound = true;

            lw.Base.CustomPage page = this.Page as lw.Base.CustomPage;

            if (WebContext.Request["Search"] == "1")
            {
                ListBy = ListItemsBy.Search;
            }

            switch (ListBy)
            {
            case ListItemsBy.Brand:
                if (Brand == "")
                {
                    _brand = page.GetQueryValue("Brand");
                }
                break;

            case ListItemsBy.Category:
                if (String.IsNullOrWhiteSpace(Category))
                {
                    _category = page.GetQueryValue("Category");
                }
                if (String.IsNullOrWhiteSpace(SubCategory))
                {
                    _subCategory = page.GetQueryValue("SubCategory");
                }
                break;

            case ListItemsBy.Package:

                object obj = DataBinder.Eval(this.NamingContainer, "DataItem.ItemId");
                if (obj == null)
                {
                    string uniqueName = page.GetQueryValue("Item");
                    if (uniqueName != "")
                    {
                        ProductsDS.ItemsRow Item = (new ItemsMgr()).GetItemByUniqueName(uniqueName);
                        _packageItemId = Item.ItemId;
                    }
                }
                else
                {
                    _packageItemId = (int)obj;
                }

                break;

            case ListItemsBy.Search:
                Cond += string.Format(" and (ProductNumber like '%{0}%' or Title like '%{0}%' or Keywords like '%{0}%')", StringUtils.SQLEncode(page.GetQueryValue("q")));
                break;

            case ListItemsBy.All:
            default:
                break;
            }


            string categoryCondition = "";

            if (!String.IsNullOrWhiteSpace(Category))
            {
                categoryCondition = string.Format("(Name='{0}' or Title='{0}')",
                                                  StringUtils.SQLEncode(Category));
            }
            if (!String.IsNullOrWhiteSpace(SubCategory))
            {
                categoryCondition += (categoryCondition != ""? " or " : "") +
                                     string.Format("(Name='{0}' or Title='{0}')", StringUtils.SQLEncode(SubCategory));
            }

            string moreConditions = "";

            if (!String.IsNullOrWhiteSpace(categoryCondition))
            {
                CategoriesMgr cMgr = new CategoriesMgr();
                DataTable     cat  = cMgr.GetCategories(categoryCondition);

                string cats = "", sep = "";

                if (cat.Rows.Count > 0)
                {
                    foreach (DataRow row in cat.Rows)
                    {
                        cats += sep + row["CategoryId"].ToString();
                        sep   = ",";
                    }
                    Cond += string.Format(" and CategoryId in ({0})", cats);
                }

                if (!String.IsNullOrWhiteSpace(SubCategory))
                {
                    moreConditions = @"Join (select ItemId, Count(*) as _Count from ItemCategories where CategoryId in (" + cats + ")  group by ItemId) x on s.ItemId = x.ItemId where x._Count >= 2";
                }
            }


            if (!String.IsNullOrWhiteSpace(Brand))
            {
                BrandsMgr bMgr  = new BrandsMgr();
                DataRow   brand = bMgr.GetBrand(Brand);
                if (brand != null)
                {
                    Cond += string.Format(" and BrandId={0}", brand["BrandId"]);
                }
            }

            if (BrandId != null)
            {
                Cond += string.Format(" and BrandId={0}", BrandId);
            }

            if (_packageItemId > 0)
            {
                Cond += string.Format(" and ItemId in (select ItemId1 from ItemPackages where ItemId={0})", _packageItemId);
            }

            string _status = page.GetQueryValue("status");

            if (null != _status && _status != "")
            {
                Status = (ItemStatus)Enum.Parse(typeof(ItemStatus), _status);
            }
            Cond += string.Format(" and Status&{0}<>0", (int)Status);
            if (Status == ItemStatus.OnSale)
            {
                Cond += string.Format(" and Status&{0}=0", (int)ItemStatus.Package);
            }

            SelectCommand = string.Format(@"Select Distinct top 100 percent s.ItemId,s.ProductNumber,s.Title,s.BrandId,s.Status,s.Price,s.Image1,s.Image2, 
s.Image3,s.Image4,s.ThumbImage,s.ResellerPrice,s.DownloadableFile,s.Ranking,s.UserRating,s.Views,s.SalePrice,s.UniqueName,s.Inventory, s.Brand 
from (select top {0} 
* from itemsview ",
                                          _max == -1 ? "100 PERCENT" : _max.ToString());


            if (!String.IsNullOrWhiteSpace(WebContext.Request["ByPrice"]))
            {
                string temp = WebContext.Request["ByPrice"].Replace(";", "").Replace("<=", "Price <=").Replace(">=", "Price >=")
                              .Replace("< ", "Price < ").Replace("> ", "Price > ");
                Cond += " and " + temp;
            }


            if (Cond != "")
            {
                System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("^\\s*and");
                SelectCommand += " where " + r.Replace(Cond, "");
            }
            SelectCommand += ") s " + moreConditions + " order by s.ItemId";

            //WebContext.Response.Write(SelectCommand);
            //WebContext.Response.End();

            base.DataBind();
        }
Пример #3
0
        public override void DataBind()
        {
            if (_bound)
            {
                return;
            }

            _page = this.Page as lw.Base.CustomPage;

            if (this.CategoryId > 0 || this._brandId > 0 || this.Type == CategoryType.Search)
            {
                string q = _page.GetQueryValue("q");


                DataView cats   = null;
                string   search = "1=1";

                if (!String.IsNullOrWhiteSpace(_boundTo))
                {
                    ItemsSource source = _page.FindControlRecursive(_boundTo) as ItemsSource;
                    if (source != null)
                    {
                        string items = source.ItemIds;
                        if (!String.IsNullOrWhiteSpace(items))
                        {
                            search += " and CategoryId in (select CategoryId from ItemCategories where ItemId in (" + items.TrimEnd(',') + "))";
                        }
                    }
                }
                if (q != null && this.Type == CategoryType.Search && q != "")
                {
                    search += string.Format(" and (Name like '%{0}%' or Title like '%{0}%' or Description like '%{0}%')", lw.Utils.StringUtils.SQLEncode(q));
                }
                else
                {
                    if (this._brandId == -1)
                    {
                        cats = pMgr.GetChildrenCategories(CategoryId, search).DefaultView;
                    }
                    else
                    {
                        search += string.Format(" and CategoryId in (Select CategoryId from ItemCategories Where ItemId in (Select ItemId from Items where BrandId={0})) And ParentId <> -1",
                                                _brandId);
                    }
                }

                if (cats == null)
                {
                    cats = pMgr.GetCategories(search).DefaultView;
                }
                cats.RowFilter  = "Status=1";
                cats.Sort       = "SortingOrder";
                this.DataSource = cats;

                base.DataBind();

                for (int i = 0; i < this.Controls.Count; i++)
                {
                    if ((this.Controls[i] as Categories) != null)
                    {
                        this.Controls[i].DataBind();
                    }
                }
            }
        }