前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >XML循环菜单

XML循环菜单

作者头像
用户3519280
发布2023-07-07 20:23:31
1300
发布2023-07-07 20:23:31
举报
文章被收录于专栏:c++ 学习分享c++ 学习分享
代码语言:javascript
复制
 private void bulidMenu()

    {

        int id = 0;

        int code;

        if (!checkUser.checkAdmin())

        {

            DataTable tblInf = (DataTable)HttpContext.Current.Session["user_inf"];            DataRow row = tblInf.Rows[0];

            code = Convert.ToInt32(row["Code"]);

        }

        else

        {

            code = 1;

        }

        XmlDocument xmlMenu = new XmlDocument();

        string xmlMenuFile;

        if (Session["admin"] != null && Session["admin"].ToString() == "OK")

        {

            xmlMenuFile = Server.MapPath("menuItem2.config");

        }

        else

            xmlMenuFile = Server.MapPath("menuItem.config");

            xmlMenu.Load(xmlMenuFile);

        XmlNode root = xmlMenu.SelectSingleNode("/menu");

        //循环一级产生主菜单

        foreach (XmlNode rootNode in root.ChildNodes)

        {

            if (rootNode.NodeType != XmlNodeType.Element)

            {

                continue;

            }

            //try

            //{

            if (rootNode.Attributes["code"].Value.Length >= code && rootNode.Attributes["code"].Value.Substring(code - 1, 1) == "1")

            {



                menu += "<ul class=\"t\">\r\n";

                id++;

                string imgid = "img" + id;

                string menuid = "menu" + id;

                //menu += "<li><span class=\"out\" style=\"cursor:hand; vertical-align:top;\"  onclick=\"titleClick('" + imgid + "','" + menuid + "')\" onmousemove=\"this.className='over'\" onmouseout=\"this.className='out'\"><img src=\"images/ico_s.gif\" id=\"" + imgid + "\" /> ";

                //menu += "<li><span class=\"out\" style=\"cursor:hand; vertical-align:top;\"  onclick=\"titleClick('" + imgid + "','" + menuid + "')\" ><img src=\"images/ico_s.gif\" id=\"" + imgid + "\" /> ";

                menu += "<li><span class=\"out\" style=\"cursor:hand; vertical-align:top;\"  onclick=\"titleClick('" + imgid + "','" + menuid + "')\" onmousemove=\"onover(this)\" onmouseout=\"onout(this)\"><img src=\"images/ico_s.gif\" id=\"" + imgid + "\" /><img src=\"images/disk.gif\" width=\"18\" height=\"14\" /> ";

                menu += "<strong>" + rootNode.Attributes["text"].Value + "</strong>";

                menu += "</span>\r\n";

                menu += "<ul id=\"" + menuid + "\" style=\"display:none\">";

                //循环二级产生一级菜单

                foreach (XmlNode menuNode in rootNode.ChildNodes)

                {

                    if (menuNode.NodeType != XmlNodeType.Element)

                    {

                        continue;

                    }

                    if (menuNode.Attributes["code"].Value.Length >= code && menuNode.Attributes["code"].Value.Substring(code - 1, 1) == "1")

                    {

                        id++;

                        string text = menuNode.Attributes["text"].Value;

                        if (!menuNode.HasChildNodes && menuNode.Attributes["url"].Value != "")

                        {



                            string url = "../" + menuNode.Attributes["url"].Value;

                            //menu += "<li><img src=\"images/count.gif\" /> <a href=\"" + url + "\" target=\"main_frame\" class=\"out\" onmousemove=\"this.className='over'\" onmouseout=\"this.className='out'\">" + menuNode.Attributes["text"].Value + "</a>";

                            if (text.Length >= 11)

                            {

                                string shortText = text.Substring(0, 9) + "...";

                                menu += "<li><img src=\"images/count.gif\" /> <a href=\"" + url + "\" target=\"main_frame\" title=\"" + text + "\" class=\"out\" onmousemove=\"onover(this)\" onmouseout=\"onout(this)\">" + shortText + "</a>";

                            }

                            else

                                menu += "<li><img src=\"images/count.gif\" /> <a href=\"" + url + "\" target=\"main_frame\" class=\"out\" onmousemove=\"onover(this)\" onmouseout=\"onout(this)\">" + text + "</a>";

                        }

                        else if (menuNode.HasChildNodes)

                        {

                            id++;

                            string img2id = "img2i" + id;

                            string menu2id = "menu2i" + id;

                            menu += "<li><span style=\"cursor:hand; vertical-align:middle;\"  onclick=\"titleClick('" + img2id + "','" + menu2id + "')\" onmousemove=\"onover(this)\" onmouseout=\"onout(this)\"><img src=\"images/ico_s.gif\" id=\"" + img2id + "\" /><img src=\"images/dir_close.gif\" width=\"18\" height=\"14\" id=\"" + img2id + "_dir\" /> " + text + "</span>\r\n";

                            menu += "<ul id=\"" + menu2id + "\" style=\"display:none\">\r\n";

                            //循环三级产生二级菜单

                            foreach (XmlNode subMenuNode in menuNode.ChildNodes)

                            {

                                if (subMenuNode.NodeType != XmlNodeType.Element)

                                {

                                    continue;

                                }

                                if (subMenuNode.Attributes["code"].Value.Length >= code && subMenuNode.Attributes["code"].Value.Substring(code - 1, 1) == "1" && subMenuNode.Attributes["url"].Value != "")

                                {

                                    id++;

                                    string text2 = subMenuNode.Attributes["text"].Value;

                                    string url2 = "../" + subMenuNode.Attributes["url"].Value;

                                    if (text2.Length >= 10)

                                    {

                                        string shortText2 = text2.Substring(0, 8) + "...";

                                        menu += "<li><img src=\"images/count.gif\" width=\"11\" height=\"11\" /> <a href=\"" + url2 + "\" title=\"" + text2 + "\" target=\"main_frame\" class=\"out\" onmousemove=\"onover(this)\" onmouseout=\"onout(this)\">" + shortText2 + "</a>\r\n";

                                    }

                                    else

                                        menu += "<li><img src=\"images/count.gif\" width=\"11\" height=\"11\" /> <a href=\"" + url2 + "\" target=\"main_frame\" class=\"out\" onmousemove=\"onover(this)\" onmouseout=\"onout(this)\">" + text2 + "</a>\r\n";

                                }

                            }

                            menu += "</ul>";

                        }

                    }



                }

                menu += "</ul></ul>";

            }

            //}

            //catch { }

        }

    }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-07-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档