Exemplo n.º 1
0
    /// <summary>
    /// 递归生成树的方法
    /// </summary>
    public StringBuilder CreateTree(int fatherId)
    {
        StringBuilder          strHtml        = new StringBuilder();
        List <SystemMenuModel> systemMenuList = bll_systemMenu.GetListByFatherId(fatherId);

        for (int i = 0; i < systemMenuList.Count; i++)
        {
            SystemMenuModel systemMenu = systemMenuList[i];

            string nodeStyle = String.Empty;
            if (systemMenu.ILevel < SystemMenu.MAX_LEVEL && systemMenu.HasChild)
            {
                nodeStyle = systemMenu.IsOpen.ToString();
            }

            strHtml.Append("<tr lv=\"").Append(systemMenu.ILevel).Append("\" onoff=\"").Append(nodeStyle).Append("\">");
            strHtml.Append("<td align=\"center\"><input type=\"checkbox\" name=\"g1\" value=\"").Append(systemMenu.Pkid).Append("\" /></td>");
            strHtml.Append("<td><input name=\"title").Append(systemMenu.Pkid).Append("\" value=\"").Append(systemMenu.Title).Append("\" maxlength=\"10\" type=\"text\" class=\"text\" /></td>");
            strHtml.Append("<td><input name=\"url").Append(systemMenu.Pkid).Append("\" value=\"").Append(systemMenu.Url).Append("\" maxlength=\"100\" type=\"text\" class=\"text\" /></td>");
            strHtml.Append("<td>").Append(systemMenu.Pkid).Append("</td>");
            strHtml.Append("<td class=\"gray\">").Append(bll_systemMenu.GetStatus(systemMenu, "enab")).Append("</td>");
            strHtml.Append("<td>");
            if (i > 0)
            {
                strHtml.Append("<a href=\"javascript:;\" onclick=\"operate('moveup',").Append(systemMenu.Pkid).Append(",null);\" class=\"icon icon_moveup\" title=\"上移\"></a>");
            }
            else
            {
                strHtml.Append("<a class=\"icon icon_empty\"></a>");
            }
            if (i < systemMenuList.Count - 1)
            {
                strHtml.Append("<a href=\"javascript:;\" onclick=\"operate('movedown',").Append(systemMenu.Pkid).Append(",null);\" class=\"icon icon_movedown\" title=\"下移\"></a>");
            }
            else
            {
                strHtml.Append("<a class=\"icon icon_empty\"></a>");
            }
            strHtml.Append("<a href=\"sysMenuEdit.aspx?pkid=").Append(systemMenu.Pkid).Append("\" class=\"icon icon_edit\" title=\"编辑\"></a>");
            strHtml.Append("<div class=\"operation\">");
            strHtml.Append("<a href=\"javascript:;\" onclick=\"operate('del',").Append(systemMenu.Pkid).Append(",null);\" class=\"icon icon_del\" title=\"删除\"></a>");
            strHtml.Append("<div>");
            strHtml.Append("</td>");
            strHtml.Append("</tr>");

            if (systemMenu.ILevel < SystemMenu.MAX_LEVEL)
            {
                if (systemMenu.HasChild && systemMenu.IsOpen)
                {
                    strHtml.Append(CreateTree(systemMenu.Pkid));
                }

                strHtml.Append("<tr lv=\"").Append(systemMenu.ILevel + 1).Append("\" rank=\"last\">");
                strHtml.Append("<td></td>");
                strHtml.Append("<td colspan=\"5\"><a href=\"javascript:;\" onclick=\"addMenu($(this), ").Append(systemMenu.Pkid).Append(");\" class=\"icon2 icon_add\"> [").Append(systemMenu.Title).Append("] 子菜单</a></td>");
                strHtml.Append("</tr>");
            }
        }

        return(strHtml);
    }