当前位置: 首页>>代码示例>>C#>>正文


C# TreeNode.Append方法代码示例

本文整理汇总了C#中TreeNode.Append方法的典型用法代码示例。如果您正苦于以下问题:C# TreeNode.Append方法的具体用法?C# TreeNode.Append怎么用?C# TreeNode.Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TreeNode的用法示例。


在下文中一共展示了TreeNode.Append方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetCategoryMenu

        public TreeNode<MenuItem> GetCategoryMenu()
        {
            var customerRolesIds = _services.WorkContext.CurrentCustomer.CustomerRoles.Where(cr => cr.Active).Select(cr => cr.Id).ToList();
            string cacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_NAVIGATION_MODEL_KEY,
                _services.WorkContext.WorkingLanguage.Id,
                string.Join(",", customerRolesIds),
                _services.StoreContext.CurrentStore.Id);

            var model = _services.Cache.Get(cacheKey, () =>
            {
                var curParent = new TreeNode<MenuItem>(new MenuItem
                {
                    EntityId = 0,
                    Text = "Home",
                    RouteName = "HomePage"
                });

                Category prevCat = null;

                var categories = _categoryService.GetAllCategories();
                foreach (var category in categories)
                {
                    var menuItem = new MenuItem
                    {
                        EntityId = category.Id,
                        Text = category.GetLocalized(x => x.Name),
                        RouteName = "Category"
                    };
                    menuItem.RouteValues.Add("SeName", category.GetSeName());

                    // determine parent
                    if (prevCat != null)
                    {
                        if (category.ParentCategoryId != curParent.Value.EntityId)
                        {
                            if (category.ParentCategoryId == prevCat.Id)
                            {
                                // level +1
                                curParent = curParent.LastChild;
                            }
                            else
                            {
                                // level -x
                                while (!curParent.IsRoot)
                                {
                                    if (curParent.Value.EntityId == category.ParentCategoryId)
                                    {
                                        break;
                                    }
                                    curParent = curParent.Parent;
                                }
                            }
                        }
                    }

                    // add to parent
                    curParent.Append(menuItem);

                    prevCat = category;
                }

                var root = curParent.Root;

                // menu publisher
                _menuPublisher.Value.RegisterMenus(root, "catalog");

                // event
                _services.EventPublisher.Publish(new NavigationModelBuiltEvent(root));

                return root;
            });

            return model;
        }
开发者ID:toannguyen241994,项目名称:SmartStoreNET,代码行数:74,代码来源:CatalogHelper.cs

示例2: ConvertSitemapNodeToMenuItemNode

        private TreeNode<MenuItem> ConvertSitemapNodeToMenuItemNode(SiteMapNode node)
        {
            var item = new MenuItem();
            var treeNode = new TreeNode<MenuItem>(item);

            if (node.RouteName.HasValue())
            {
                item.RouteName = node.RouteName;
            }
            else if (node.ActionName.HasValue() && node.ControllerName.HasValue())
            {
                item.ActionName = node.ActionName;
                item.ControllerName = node.ControllerName;
            }
            else if (node.Url.HasValue())
            {
                item.Url = node.Url;
            }
            item.RouteValues = node.RouteValues;
            
            item.Visible = node.Visible;
            item.Text = node.Title;
            item.Attributes.Merge(node.Attributes);

            if (node.Attributes.ContainsKey("permissionNames"))
                item.PermissionNames = node.Attributes["permissionNames"] as string;

            if (node.Attributes.ContainsKey("id"))
                item.Id = node.Attributes["id"] as string;

            if (node.Attributes.ContainsKey("resKey"))
                item.ResKey = node.Attributes["resKey"] as string;

			if (node.Attributes.ContainsKey("iconClass"))
				item.Icon = node.Attributes["iconClass"] as string;

            if (node.Attributes.ContainsKey("imageUrl"))
                item.ImageUrl = node.Attributes["imageUrl"] as string;

            if (node.Attributes.ContainsKey("isGroupHeader"))
                item.IsGroupHeader = Boolean.Parse(node.Attributes["isGroupHeader"] as string);

            // iterate children recursively
            foreach (var childNode in node.ChildNodes)
            {
                var childTreeNode = ConvertSitemapNodeToMenuItemNode(childNode);
                treeNode.Append(childTreeNode);
            }
            
            return treeNode;
        }
开发者ID:mandocaesar,项目名称:Mesinku,代码行数:51,代码来源:CommonController.cs

示例3: PrepareCategoryNavigationModel

        protected TreeNode<CategoryNavigationModel.CategoryModel> PrepareCategoryNavigationModel()
        {

            var curParent = new TreeNode<CategoryNavigationModel.CategoryModel>(new CategoryNavigationModel.CategoryModel()
            {
                Id = 0,
                Name = "_ROOT_",
                Level = -1 // important
            });
            
            Category prevCat = null;
            int level = 0;

            var categories = _categoryService.GetAllCategories();
            foreach (var category in categories)
            {
                var model = new CategoryNavigationModel.CategoryModel()
                {
                    Id = category.Id,
                    Name = category.GetLocalized(x => x.Name),
                    SeName = category.GetSeName()
                };

                // determine parent
                if (prevCat != null)
                {
                    if (category.ParentCategoryId != curParent.Value.Id)
                    {
                        if (category.ParentCategoryId == prevCat.Id)
                        {
                            // level +1
                            curParent = curParent.LastChild;
                            level++;
                        }
                        else
                        {
                            // level -x
                            while (!curParent.IsRoot)
                            {
                                if (curParent.Value.Id == category.ParentCategoryId)
                                {
                                    break;
                                }
                                curParent = curParent.Parent;
                                level--;
                            }
                        }
                    }
                }

                // set level
                model.Level = level;

                // add to parent
                curParent.Append(model);

                prevCat = category;
            }

            var root = curParent.Root;

            // event
            _eventPublisher.Publish(new NavigationModelBuiltEvent(root));

            return root;
        }
开发者ID:GloriousOnion,项目名称:SmartStoreNET,代码行数:66,代码来源:CatalogController.cs


注:本文中的TreeNode.Append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。