using ;
using ;
using ;
using ;
using System;
/// <summary>
/// Summary description of CreateTree
/// </summary>
public class MenuTree
{
int index = 0;// Menu column ID index
private ArrayList havePermission = new ArrayList();
private bool isVip = false;
/// <summary>
/// Permissions owned by login user
/// </summary>
private ArrayList HavePermissions
{
get { return havePermission; }
set { havePermission = value; }
}
/// <summary>
/// Whether the logged-in user is a VIP
/// </summary>
private bool IsVip
{
get { return isVip; }
set { isVip = value; }
}
/// <summary>
/// The permissions owned by the login user are whether they are VIP users
/// </summary>
/// <param name="havePermission"></param>
/// <param name="isVip"></param>
public MenuTree(ArrayList havePermission, bool isVip)
{
= havePermission;
= isVip;
}
/// <summary>
/// Binding tree
/// </summary>
public string BindDataToTree()
{
document = new ();
((""));
return CreateTreeHtml(, 0);
}
/// <summary>
/// Create a column tree
/// </summary>
/// <param name="document">xml node</param>
/// <param name="deep">Tree depth</param>
private string CreateTreeHtml( document, int deep)
{
string nodeType = "Menu";//Name type to generate the CSS type of the child node
StringBuilder treeHtml = new StringBuilder();
foreach ( node in )
{
string menuId = ;
string treeNodeHtml = ;
string nodeName = ;
string showName = GetAttributesValue(["Name"]);//Show column name
string nodeId = GetAttributesValue(["Id"]);//Column ID
bool isExpand = GetAttributesValue(["IsExpand"]).ToLower().Trim() == "true" ? true : false;//Is it expanded
string permissions = GetAttributesValue(["Permissions"]);//Permission string
bool isOnlyVip = GetAttributesValue(["IsOnlyVip"]).ToLower().Trim() == "true" ? true : false;//Is only VIP access allowed
bool isUnVip = GetAttributesValue(["IsUnVip"]).ToLower().Trim() == "true" ? true : false;//Is non-VIP access only allowed
string eventScript = GetAttributesValue(["EventScript"]);// Event script
int chlidNodesCount = ;//Number of child nodes
bool isPermissions = GetIsPermissions(permissions);//Is there permissions
if (!isPermissions)
{
continue; //If there is no permission, this node will not be generated
}
if (nodeName == "Module")
{
if (isUnVip && IsVip)
{
continue;//If you are a VIP member, set to not allow access to sub-columns
}
menuId = GetMenuId(nodeId);
("<div class='Module' id='Menu{0}' onclick='DoNodes(this);{1}' onselectstart='return false;'>", menuId, eventScript);
(" <img src='/images/' alt='' /> ");
("<span>{0}</span>", showName);
("</div>");
deep = 0;
nodeType = "Module";
}
else
{
("<table cellpadding='0' cellspacing='0' style='border-width: 0;width:90%'>");
("<tr class='NodeLine'>");
for (int i = 0; i < deep; i++)
{
if (i == deep - 1)
{
("<td class='nodeIcoBox'>");
if (chlidNodesCount > 0)
{
menuId = GetMenuId(nodeId);
("<a id='Menu{0}' href='javascript:;' onclick='DoNodes(this,\"menu\")'><img src='/Images/{1}.gif' alt=''/></a>", menuId, (isExpand ? "open-menu" : "close-menu"));
}
else
{
("<img src='/Images/' alt=''/>");
}
("</td>");
}
else
{
("<td style='width: 20px;'> </td>");
}
}
string url = GetAttributesValue(["Url"]); //Link address
string title = GetAttributesValue(["Title"]);//Link TITLE information
string menuNodeId = ().Length > 0 ? "id='MenuNode" + nodeId + "'" : ;//Tree node ID
("<td style='white-space: nowrap;'>");
if ( > 0 || chlidNodesCount == 0)
{
if (!isOnlyVip || (isOnlyVip && IsVip))//Is the column only open for VIP
{
if ( > 0)
{
("<a href='{0}' target='MainFrame' title='{1}' {3} {4}>{2}</a>", url, title, showName, eventScript, menuNodeId);
}
else
{
("<a href='javascript:;' target='MainFrame' title='{0}' {2} {3}>{1}</a>", title, showName, eventScript, menuNodeId);
}
}
else
{
("<a href='javascript:;' target='MainFrame' title='{1}' onclick='return AlertVip();' class='disableColor' {3}>{2}</a>", url, title, showName, menuNodeId);
}
}
else
{
("<a href='javascript:;' onclick='DoAClick(\"Menu{0}\");' title='{1}' {3} {4}>{2}</a>", menuId, title, showName, eventScript, menuNodeId);
}
("</td>");
("</tr>");
("</table>");
}
if (chlidNodesCount > 0)
{
treeNodeHtml = CreateTreeHtml(node, deep + 1);
}
if ( > 0)
{
("<div id='Menu{0}Nodes' {1} style='{2}'>", menuId, (nodeType == "Module" ? "class='Menus'" : "class='MenuNodes'"), (isExpand ? "display:block;" : "display: none;"));
(treeNodeHtml);
("</div>");
}
}
return ();
}
/// <summary>
/// Obtain the column ID
/// </summary>
private string GetMenuId(string nodeId)
{
return > 0 ? nodeId : (++index);
}
/// <summary>
/// Get the node value
/// </summary>
private string GetAttributesValue(XmlAttribute attributeValue)
{
return attributeValue == null ? "" : ();
}
/// <summary>
/// Is there permission
/// </summary>
private bool GetIsPermissions(string permissions)
{
if ( == 0)
{
return false;
}
if ( == 0)
{
return true;
}
else
{
string[] arrPermissions = (',');
for (int i = 0; i < ; i++)
{
if ((arrPermissions[i].Trim()))
{
return true;
}
}
return false;
}
}
}