Devexpress使用手记-aspxmenu(3)

在网上找了一圈没有找到通过数据库生成web.sitemap文件的代码,只好自己写了
为了能够动态加载sitemap到devexpress控件的sitemapcontrol件上,写了这个将数据库表转换为sitemap的类库,需要的兄弟只需要将
其中调用数据库的方法换成自己的就可以很简单的生成相应的sitemap文件(不是自己写的多好,只不过这东西重复写太没意思),其它的就不多说了,用上了一点LINQ TO XML的东西,感觉LINQ还是很好用的,呵呵

 

ExpandedBlockStart.gif 代码
public class SqlSiteMapGen
    {

        private XDocument siteMap;
        private const string SiteMapSchemas = "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0";
        private const string SiteMap_Name = "siteMap";
        private const string SiteMapNode_Name = "siteMapNode";
        private const string SiteMapNode_Attribute_Url = "url";
        private const string SiteMapNode_Attribute_Title = "title";
        private const string SiteMapNode_Attribute_Description = "description";
        
        public XDocument CreateSiteMapNode()
        {
            siteMap = new XDocument(new XDeclaration("1.0", "utf-8",""));
            XNamespace xw = SiteMapSchemas;
            XElement rootNode = new XElement(SiteMap_Name);
            XElement mapNode = CreateNode("后台管理菜单", "", "");
            rootNode.Add(CreateSiteMapNode(mapNode, "00000000-0000-0000-0000-000000000000"));
            siteMap.Add(rootNode);
            
            return siteMap;
        }

        private static XElement CreateSiteMapNode(XElement node,string PrentID)
        {
            XElement childnode;
            Debug.Print(PrentID);
            using (Mder_CenterEntities ctx = new Mder_CenterEntities())
            {
               
                var query = from c in ctx.COMM_HUMAN_FUNCTION
                            where c.LOCKED_IF == "0" && c.FUNCTION_PID == PrentID
                            orderby c.SORT
                            select new { c.FUNCTION_ID, c.FUNCTION_NAME, c.FUNCTION_PID, c.URL };

                foreach (var item in query)
                {
                    childnode = CreateNode(item.FUNCTION_NAME, item.URL, item.FUNCTION_NAME);
                    CreateSiteMapNode(childnode, item.FUNCTION_ID);
                    node.Add(childnode);
                }
              
            }
            return node;
        }


        private static XElement CreateNode(string sTitel, string sUrl, string sDescription)
        {
            XElement node = new XElement(
                SiteMapNode_Name,
                new XAttribute(SiteMapNode_Attribute_Title, sTitel),
                new XAttribute(SiteMapNode_Attribute_Url, sUrl??""),
                new XAttribute(SiteMapNode_Attribute_Description, sDescription??"")
                );
            return node;
        }

 

 

转载于:https://www.cnblogs.com/forrestsun/articles/1553877.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值