Exemplo n.º 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();
        }
Exemplo n.º 2
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();
                    }
                }
            }
        }