#region 组合ztree
//树结构HTML
/// <summary>
/// 获取树结构
/// 添加人:
/// 添加时间:2015-10-30
/// </summary>
/// <param name="_dt">DataTable数据源</param>
/// <param name="sCudisplayfiled">显示字段</param>
/// <param name="sCudisplayvalue">显示值</param>
/// <param name="parentid">父节点</param>
/// <param name="sNodeshow">节点展示 展开:1,折叠:2</param>
/// <param name="sOpenMode">打开方式 新页面:1本页面:2</param>
/// <param name="sSelectMode">单选/多选 单选:1,多选:2</param>
/// <param name="sNodeicon">节点图标</param>
/// <param name="sNodeurl">点击节点跳转地址</param>
/// <returns></returns>
public static string fListMenu(DataTable _dt, string sCudisplayfiled, string sCudisplayvalue, string parentid, string sNodeshow, string sOpenMode, string sSelectMode, string sNodeicon, string sNodeurl)
{
StringBuilder sb = new StringBuilder();
DataRow[] rows = _dt.Select(parentid + "='0'");//查找跟节点
sb.Append("[");
bool isFist = false;
#region 组合DAT的JSON字符串
foreach (DataRow dr in rows)
{
if (isFist)
sb.Append(",");
isFist = true;
string id = dr[sCudisplayfiled].ToString();
sb.Append("{");
sb.AppendFormat("'id':'{0}',", dr[sCudisplayfiled]);
sb.AppendFormat("'text':'{0}',", dr[sCudisplayvalue]);
sb.AppendFormat("'pid':'{0}',", "0");
sb.AppendFormat("'iconCls':'icon_{0}',", sNodeicon);
sb.AppendFormat("'url':'{0}',", sNodeurl);
sb.AppendFormat("'state':'{0}',", sNodeshow);
sb.Append("children:[");
sb.Append(fGetSubMenu(id, _dt, parentid, sCudisplayfiled, sCudisplayvalue, sNodeshow, sOpenMode, sSelectMode, sNodeicon, sNodeurl));
sb.Append("]");
sb.Append("}");
}
#endregion
sb.Append("]");
return sb.ToString();
}
/// <summary>
/// 递归调用生成无限级别
/// 添加人:
/// 添加时间:2015-10-30
/// </summary>
/// <param name="pid">父节点</param>
/// <param name="dt">DataTable</param>
/// <param name="parentid">父节点</param>
/// <param name="sCudisplayfiled">显示字段</param>
/// <param name="sCudisplayvalue">显示值</param>
/// <param name="sNodeshow">节点展示 展开:1,折叠:2</param>
/// <param name="sOpenMode">打开方式 新页面:1本页面:2</param>
/// <param name="sSelectMode">单选/多选 单选:1,多选:2</param>
/// <param name="sNodeicon">节点图标</param>
/// <param name="sNodeurl">点击节点跳转地址</param>
/// <returns>返回JSON字符</returns>
private static string fGetSubMenu(string pid, DataTable dt, string parentid, string sCudisplayfiled, string sCudisplayvalue, string sNodeshow, string sOpenMode, string sSelectMode, string sNodeicon, string sNodeurl)
{
StringBuilder sb = new StringBuilder();
DataRow[] rows = dt.Select(parentid + "='" + pid + "'");
if (rows.Length > 0)
{
bool isFist = false;
#region 组合DAT的JSON字符串
foreach (DataRow dr in rows)
{
if (isFist)
sb.Append(",");
isFist = true;
string id = dr[sCudisplayfiled].ToString();
sb.Append("{");
sb.AppendFormat("'id':'{0}',", dr[sCudisplayfiled]);
sb.AppendFormat("'text':'{0}',", dr[sCudisplayvalue]);
sb.AppendFormat("'pid':'{0}',", dr[parentid]);
sb.AppendFormat("'iconCls':'icon_{0}',", sNodeicon);
sb.AppendFormat("'url':'{0}',", sNodeurl);
sb.AppendFormat("'state':'{0}',", sNodeshow);
sb.Append("children:[");
sb.Append(fGetSubMenu(id, dt, parentid, sCudisplayfiled, sCudisplayvalue, sNodeshow, sOpenMode, sSelectMode, sNodeicon, sNodeurl));
sb.Append("]");
sb.Append("}");
}
#endregion
}
return sb.ToString();
}
#endregion
//树结构HTML
/// <summary>
/// 获取树结构
/// 添加人:
/// 添加时间:2015-10-30
/// </summary>
/// <param name="_dt">DataTable数据源</param>
/// <param name="sCudisplayfiled">显示字段</param>
/// <param name="sCudisplayvalue">显示值</param>
/// <param name="parentid">父节点</param>
/// <param name="sNodeshow">节点展示 展开:1,折叠:2</param>
/// <param name="sOpenMode">打开方式 新页面:1本页面:2</param>
/// <param name="sSelectMode">单选/多选 单选:1,多选:2</param>
/// <param name="sNodeicon">节点图标</param>
/// <param name="sNodeurl">点击节点跳转地址</param>
/// <returns></returns>
public static string fListMenu(DataTable _dt, string sCudisplayfiled, string sCudisplayvalue, string parentid, string sNodeshow, string sOpenMode, string sSelectMode, string sNodeicon, string sNodeurl)
{
StringBuilder sb = new StringBuilder();
DataRow[] rows = _dt.Select(parentid + "='0'");//查找跟节点
sb.Append("[");
bool isFist = false;
#region 组合DAT的JSON字符串
foreach (DataRow dr in rows)
{
if (isFist)
sb.Append(",");
isFist = true;
string id = dr[sCudisplayfiled].ToString();
sb.Append("{");
sb.AppendFormat("'id':'{0}',", dr[sCudisplayfiled]);
sb.AppendFormat("'text':'{0}',", dr[sCudisplayvalue]);
sb.AppendFormat("'pid':'{0}',", "0");
sb.AppendFormat("'iconCls':'icon_{0}',", sNodeicon);
sb.AppendFormat("'url':'{0}',", sNodeurl);
sb.AppendFormat("'state':'{0}',", sNodeshow);
sb.Append("children:[");
sb.Append(fGetSubMenu(id, _dt, parentid, sCudisplayfiled, sCudisplayvalue, sNodeshow, sOpenMode, sSelectMode, sNodeicon, sNodeurl));
sb.Append("]");
sb.Append("}");
}
#endregion
sb.Append("]");
return sb.ToString();
}
/// <summary>
/// 递归调用生成无限级别
/// 添加人:
/// 添加时间:2015-10-30
/// </summary>
/// <param name="pid">父节点</param>
/// <param name="dt">DataTable</param>
/// <param name="parentid">父节点</param>
/// <param name="sCudisplayfiled">显示字段</param>
/// <param name="sCudisplayvalue">显示值</param>
/// <param name="sNodeshow">节点展示 展开:1,折叠:2</param>
/// <param name="sOpenMode">打开方式 新页面:1本页面:2</param>
/// <param name="sSelectMode">单选/多选 单选:1,多选:2</param>
/// <param name="sNodeicon">节点图标</param>
/// <param name="sNodeurl">点击节点跳转地址</param>
/// <returns>返回JSON字符</returns>
private static string fGetSubMenu(string pid, DataTable dt, string parentid, string sCudisplayfiled, string sCudisplayvalue, string sNodeshow, string sOpenMode, string sSelectMode, string sNodeicon, string sNodeurl)
{
StringBuilder sb = new StringBuilder();
DataRow[] rows = dt.Select(parentid + "='" + pid + "'");
if (rows.Length > 0)
{
bool isFist = false;
#region 组合DAT的JSON字符串
foreach (DataRow dr in rows)
{
if (isFist)
sb.Append(",");
isFist = true;
string id = dr[sCudisplayfiled].ToString();
sb.Append("{");
sb.AppendFormat("'id':'{0}',", dr[sCudisplayfiled]);
sb.AppendFormat("'text':'{0}',", dr[sCudisplayvalue]);
sb.AppendFormat("'pid':'{0}',", dr[parentid]);
sb.AppendFormat("'iconCls':'icon_{0}',", sNodeicon);
sb.AppendFormat("'url':'{0}',", sNodeurl);
sb.AppendFormat("'state':'{0}',", sNodeshow);
sb.Append("children:[");
sb.Append(fGetSubMenu(id, dt, parentid, sCudisplayfiled, sCudisplayvalue, sNodeshow, sOpenMode, sSelectMode, sNodeicon, sNodeurl));
sb.Append("]");
sb.Append("}");
}
#endregion
}
return sb.ToString();
}
#endregion