Exemplo n.º 1
0
    /// <summary>
    /// 加载数据
    /// </summary>
    void BindCategory()
    {
        TreeNode root = new TreeNode("所有分类", "0", GlobalSettings.RelativeWebRoot + "images/default/cat.gif");
        TreeNode tn   = null;

        this.tvCategory.Nodes.Add(root);
        List <ProductCategory> categories = ProductCategories.GetChidCategories(0);

        foreach (ProductCategory category in categories)
        {
            tn         = new TreeNode(category.CategoryName, category.CategoryID.ToString(), GlobalSettings.RelativeWebRoot + "images/default/cat.gif");
            tn.ToolTip = category.CategoryDesc;
            //tn.CollapseAll();
            LoadChild(tn);
            root.ChildNodes.Add(tn);
            //mbMsg.ShowMsg("请在产品分类树中选择您将要执行操作的分类");
        }

        HttpCookie cache      = HHCookie.GetCookie(nodeState + Profile.AccountInfo.UserName);
        int        categoryID = 0;

        if (cache != null)
        {
            categoryID = Convert.ToInt32(cache.Value);
        }

        CheckNode(tvCategory.Nodes, categoryID.ToString());
        BindDetail(categoryID);
    }
 private void AddChildCategory(TreeNode parent, ProductCategory category)
 {
     foreach (ProductCategory pc in ProductCategories.GetChidCategories(category.CategoryID))
     {
         TreeNode tn = CreateNode(pc.CategoryName, pc.CategoryID.ToString(), pc.CategoryDesc);
         parent.ChildNodes.Add(tn);
         AddChildCategory(tn, pc);
     }
 }
        string RenderHTML()
        {
            if (_Cache.ContainsKey(_CategoryID))
            {
                return(_Cache[_CategoryID]);
            }
            List <ProductCategory> pcs = ProductCategories.GetCategories();
            StringBuilder          sb  = new StringBuilder();

            if (_CategoryID == 0)
            {
                return("<div class=\"" + _CssClass + "\"><span>暂无子分类信息!</span></div>");
            }
            else
            {
                string                 _catId  = string.Empty;
                ProductCategory        curCat  = null;
                List <ProductCategory> subCats = ProductCategories.GetChidCategories(_CategoryID);
                if (subCats == null || subCats.Count == 0)
                {
                    return("<div class=\"" + _CssClass + "\"><span>暂无子分类信息!</span></div>");
                }
                sb.Append("<div class=\"" + _CssClass + "\">");
                ProductQuery            query;
                int                     count = 0;
                PagingDataSet <Product> __ps  = null;
                for (int i = 0; i < subCats.Count; i++)
                {
                    curCat           = subCats[i];
                    count            = 0;
                    query            = new ProductQuery();
                    query.CategoryID = curCat.CategoryID;

                    __ps = Products.GetProducts(query);
                    if (__ps != null && __ps.Records != null)
                    {
                        count = Products.GetProducts(query).Records.Count;
                    }

                    sb.AppendFormat(_href, GlobalSettings.Encrypt(curCat.CategoryID.ToString()), curCat.CategoryName + "(" + count + ")");
                }
                sb.Append("</div>");
                if (!_Cache.ContainsKey(_CategoryID))
                {
                    lock (_lock)
                    {
                        if (!_Cache.ContainsKey(_CategoryID))
                        {
                            _Cache.Add(_CategoryID, sb.ToString());
                        }
                    }
                }
            }
            return(sb.ToString());
        }
    void BindTreeView()
    {
        this.tvCategories.Nodes.Clear();
        List <ProductCategory> categories = ProductCategories.GetChidCategories(0);
        TreeNode tn = null;

        foreach (ProductCategory pc in categories)
        {
            tn = CreateNode(pc.CategoryName, pc.CategoryID.ToString(), pc.CategoryDesc);
            AddChildCategory(tn, pc);
            this.tvCategories.Nodes.Add(tn);
        }
        this.tvCategories.CollapseAll();
    }
Exemplo n.º 5
0
    /// <summary>
    /// 加载子节点
    /// </summary>
    /// <param name="node"></param>
    void LoadChild(TreeNode node)
    {
        List <ProductCategory> categories = ProductCategories.GetChidCategories(int.Parse(node.Value));

        if (categories != null && categories.Count > 0)
        {
            TreeNode tn = null;
            foreach (ProductCategory c in categories)
            {
                if (c.ParentID == int.Parse(node.Value))
                {
                    tn         = new TreeNode(c.CategoryName, c.CategoryID.ToString(), GlobalSettings.RelativeWebRoot + "images/default/cat.gif");
                    tn.ToolTip = c.CategoryDesc;
                    LoadChild(tn);
                    node.ChildNodes.Add(tn);
                }
            }
        }
    }
    public override void OnPageLoaded()
    {
        string        catName = string.Empty, catRelated = string.Empty;
        StringBuilder sbRelated = new StringBuilder();

        string          id = Request.QueryString["ID"];
        ProductCategory pc = null;

        if (!string.IsNullOrEmpty(id))
        {
            int catId = int.Parse(GlobalSettings.Decrypt(id));
            pc = ProductCategories.GetCategory(catId);
            if (pc != null)
            {
                catName = pc.CategoryName;
            }
        }

        if (!string.IsNullOrEmpty(catName))
        {
            //获取子分类
            List <ProductCategory> childCategories = ProductCategories.GetChidCategories(pc.CategoryID);
            if (null == childCategories || 0 == childCategories.Count)
            {
            }
            else
            {
                foreach (ProductCategory pcChild in childCategories)
                {
                    sbRelated.AppendFormat("{0},", pcChild.CategoryName);
                }
            }
            //获取相关分类
            List <ProductCategory> relateCategories = ProductCategories.GetChidCategories(pc.ParentID);
            if (null == relateCategories || 0 == relateCategories.Count)
            {
            }
            else
            {
                foreach (ProductCategory pcRelate in relateCategories)
                {
                    sbRelated.AppendFormat("{0},", pcRelate.CategoryName);
                }
            }
            catRelated = sbRelated.ToString().TrimEnd(',');
        }
        else
        {
            List <ProductCategory> relateCategories = ProductCategories.GetCategories();
            if (null == relateCategories || 0 == relateCategories.Count)
            {
            }
            else
            {
                foreach (ProductCategory pcRelate in relateCategories)
                {
                    if (pcRelate.ParentID > 0)
                    {
                        continue;
                    }
                    sbRelated.AppendFormat("{0},", pcRelate.CategoryName);
                }
            }
            catRelated = sbRelated.ToString().TrimEnd(',');
        }

        if (string.IsNullOrEmpty(catName))
        {
            catName = "所有分类";
            this.AddKeywords(catName + "," + catRelated);
            this.AddDescription("显示所有一级和二级产品分类,选择产品分类导航到对应分类的产品列表。" + string.Format(" 关键字: {0},{1}", catName, catRelated));
            this.ShortTitle = catName;
        }
        else
        {
            this.AddKeywords(string.Format("{0},{1}", catName, catRelated));
            this.AddDescription(string.Format("显示{0}分类的产品列表。{1}", catName, string.Format(" 关键字: {0},{1}", catName, catRelated)));
            this.ShortTitle = catName + " - " + catRelated;
        }
        this.SetTitle();

        this.AddJavaScriptInclude("scripts/pages/sortby.aspx.js", false, false);
    }
Exemplo n.º 7
0
 /// <summary>
 /// 绑定子分类
 /// </summary>
 void BindChildCategory(int categoryID)
 {
     rpChildCategory.DataSource = ProductCategories.GetChidCategories(categoryID);
     rpChildCategory.DataBind();
 }