树形插件zTree与组织插件jOrgChart交互

时间:2023-03-09 09:15:40
树形插件zTree与组织插件jOrgChart交互
 <html>
<head>
<title>组织架构</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link href="jquery.ztree/style.css" rel="stylesheet" />
<link href="jquery.ztree/zTreeStyle.css" rel="stylesheet" />
<script src="jquery.ztree/jquery-1.4.4.min.js"></script>
<script src="jquery.ztree/jquery.ztree.core.js"></script>
<link href="jOrgChart-master/example/css/jquery.jOrgChart.css" rel="stylesheet" />
<script src="jOrgChart-master/jquery.min.js"></script>
<script src="jOrgChart-master/example/jquery.jOrgChart.js"></script>
<style>
table {
margin: 0 auto;
}
a {
text-decoration: none;
color: #000000;
font-size: 12px;
}
.jOrgChart .node {
padding: 6px 1px 2px 5px;
border-radius: 3px;
width: 20px;
height: 100px;
/*line-height: 17px;*/
letter-spacing: 3px;
border: 1px solid #726bf7;
/*width: 150px;
height: 50px;
line-height: 50px;
border-radius: 4px;*/
/*margin: 0 8px;*/
}
.tj {
color: #000000;
text-align: center;
font-weight: bold;
font-size: 12px;
border: 1px solid #726bf7;
border-radius: 3px;
} </style>
</head>
<body>
<div class="float_affter">
<div style="width:20%;height:100%; float: left; border-right: 1px solid #cac5c3; box-sizing: border-box; overflow: auto; ">
<ul id="treeDemo" class="ztree" style="margin-top:20px"></ul>
</div> <div>
<table style="width:80%;height:50px; text-align:left; border-bottom : 1px solid #cac5c3;box-sizing: border-box;">
<tr>
<td class="tj" onClick="jc_click()">基层工会:<label id="jcghs"></label></td>
<td class="tj" onClick="hf_click()">分会:<label id="fhs"></label></td>
<td class="tj onClick="hy_click()">会员:<label id="hys"></label></td>
<td class="tj">男:<label id="nxs"></label></td>
<td class="tj">女:<label id="vxs"></label></td> </tr>
<tr>
<td class="tj">中专:<label id="zzs"></label></td>
<td class="tj">专科:<label id="zks"></label></td>
<td class="tj">本科:<label id="bks"></label></td>
<td class="tj">硕士研究生:<label id="shyjss"></label></td>
<td class="tj">博士研究生:<label id="bsyjss"></label></td>
<td class="tj">其他学历:<label id="qtxls"></label></td>
</tr>
</table>
<div id='jOrgChart' style="width:80%;margin-top:20px;float:left;"></div>
</div>
</div>
</body>
</html>
<script type="text/javascript">
jQuery.noConflict();
var zNodes;
var zTree;
//setting异步加载的设置
var setting = {
async: {
enable: true, //表示异步加载生效
url: "../Ajax/OrganizationalStructureAjax.ashx", // 异步加载时访问的页面
autoParam: ["id"], // 异步加载时自动提交的父节点属性的参数
otherParam: ["ajaxMethod", 'AnsyData'], //ajax请求时提交的参数
type: 'post',
dataType: 'json'
},
checkable: true,
showIcon: true,
showLine: true, // zTree显示连接线
data: { //用pId来标识父子节点的关系
simpleData: {
enable: true
}
},
expandSpeed: "", // 设置 zTree 节点展开、折叠的动画速度,默认为"fast",""表示无动画
callback: { // 回调函数
onClick: zTreeOnClick, // 单击鼠标事件
asyncSuccess: zTreeOnAsyncSuccess //异步加载成功事件
}
}; $(document).ready(function () {
//初始化
Inint();
jOrgChart(false);
$.fn.zTree.init($("#treeDemo"), setting, zNodes);
//openFirstTreenode();
// alert(JSON.stringify(zNodes));
});
/*
* 初始化加载树形节点
* */
function Inint(UNION_CODE) {
//$.ajax({
// url: '../Ajax/OrganizationalStructureAjax.ashx',
// //url: 'test1.json',
// type: 'post',
// dataType: 'json',
// async: false,
// data: { 'ajaxMethod': 'FirstAnsyData' },
// success: function (data) {
// zNodes = data; // // alert(JSON.stringify(zNodes));
// }
//});
//初始化加载组织结构图
$.ajax({
url: '../Ajax/OrganizationalStructureAjax.ashx',
type: 'post',
dataType: 'json',
async: false,
data: { 'ajaxMethod': 'Summary', 'OrgId': UNION_CODE},
success: function (data) { $("#jcghs").text(data.jcghs == "" ? 0 : data.jcghs);
$("#fhs").text(data.fhs == "" ? 0 : data.fhs);
$("#hys").text(data.hys == "" ? 0 : data.hys);
$("#nxs").text(data.nxs == "" ? 0 : data.nxs);
$("#vxs").text(data.vxs == "" ? 0 : data.vxs);
$("#zzs").text(data.zzs == "" ? 0 : data.zzs);
$("#zks").text(data.zks == "" ? 0 : data.zks);
$("#bks").text(data.bks == "" ? 0 : data.bks);
$("#shyjss").text(data.shyjss == "" ? 0 : data.shyjss);
$("#bsyjss").text(data.bsyjss == "" ? 0 : data.bsyjss);
$("#qtxls").text(data.qtxls == "" ? 0 : data.qtxls);
}
}); }; function jOrgChart(isshow) {
$.ajax({
//树图根节点下次查询数据,
url: '../Ajax/OrganizationalStructureAjax.ashx',
type: 'post',
dataType: 'json',
async: false,
data: { 'ajaxMethod': 'GetjOrgChartJson', 'isshow': isshow },
success: function (data) {
var showlist = $("<ul id='org' style='display:none'></ul>");
showall(data, showlist);
jQuery("#jOrgChart").append(showlist);
jQuery("#org").jOrgChart({
chartElement: '#jOrgChart',//指定在某个dom生成jorgchart
dragAndDrop: true //设置是否可拖动
});
}
});
EngthControl(); // alert("一级"+d1+"二级" + d2+"三级" + d3);
}
//边框自适应
function EngthControl() { //组织图三层数量
var d1 = $("#jOrgChart .node a.1").length;
var d2 = $("#jOrgChart .node a.2").length;
var d3 = $("#jOrgChart .node a.3").length;
//组织图方框大小根据字体个数变化
$("#jOrgChart .node a").each(function () {
//更改横竖显示
if ($(this).attr('class') == '1') {
$(this).parent().height(20);
$(this).parent().width($(this).text().length * 16);
}
if ($(this).attr('class') == '2') {
$(this).parent().height(20);
$(this).parent().width($(this).text().length * 16);
//if (d2 > 5) {
// return false;
// $(this).parents(".node-container:first").hide();
//}
}
if ($(this).attr('class') == '3') { $(this).parent().height($(this).text().length * 16);
$(this).parent().width(20);
}
//根据层级数据省略显示 //$(this).height($(this).text().length * 16);
});
} //单击时获取zTree节点的Id,和value的值
function zTreeOnClick(event, treeId, treeNode, clickFlag) {
//单机某个节点后展示组织结构图
//alert("单击" + treeNode.name + ",ID为" + treeNode.id); $.ajax({
url: '../Ajax/OrganizationalStructureAjax.ashx',
type: 'post',
dataType: 'json',
async: false,
data: { 'ajaxMethod': 'Summary', 'treeNodeID': treeNode.id },
success: function (data) {
$("#jcghs").text(data.jcghs == "" ? 0 : data.jcghs);
$("#fhs").text(data.fhs == "" ? 0 : data.fhs);
$("#hys").text(data.hys == "" ? 0 : data.hys);
$("#nxs").text(data.nxs == "" ? 0 : data.nxs);
$("#vxs").text(data.vxs == "" ? 0 : data.vxs);
$("#zzs").text(data.zzs == "" ? 0 : data.zzs);
$("#zks").text(data.zks == "" ? 0 : data.zks);
$("#bks").text(data.bks == "" ? 0 : data.bks);
$("#shyjss").text(data.shyjss == "" ? 0 : data.shyjss);
$("#bsyjss").text(data.bsyjss == "" ? 0 : data.bsyjss);
$("#qtxls").text(data.qtxls == "" ? 0 : data.qtxls);
}
});
$.ajax({
url: '../Ajax/OrganizationalStructureAjax.ashx',
type: 'post',
dataType: 'json',
async: false,
data: { 'ajaxMethod': 'GetjOrgChartJson', 'treeNodeID': treeNode.id },
success: function (data) {
jQuery("#jOrgChart").empty();
var showlist = $("<ul id='org' style='display:none'></ul>");
showall(data, showlist); jQuery("#jOrgChart").append(showlist);
jQuery("#org").jOrgChart({
chartElement: '#jOrgChart',//指定在某个dom生成jorgchart
dragAndDrop: true //设置是否可拖动
});
}
});
EngthControl();
// var treeValue = treeNode.id + "," + treeNode.name;
//alert(treeNode.id + "," + treeNode.name);
}; /**
* 展开树节点的第一层且关闭其他节点
*/
//function openFirstTreenode() {
// var tree = $.fn.zTree.getZTreeObj('treeDemo');
// tree.expandAll(tree);
// // 获取树对象
// var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
// /* 获取所有树节点 */
// var nodes = treeObj.transformToArray(treeObj.getNodes());
// // 关闭所有节点
// //for (var i = 0, length_1 = nodes.length; i < length_1; i++) {
// // treeObj.expandNode(nodes[i], false);//第二个参数为false证明是折叠
// //}
// //展开第一级节点
// treeObj.expandNode(nodes[0], true);//第二个参数为true证明是展开
//} function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
// alert("异步加载");
}
function showall(menu_list, parent) {
(function (jQuery) {
jQuery.each(menu_list, function (index, val) {
if (val.childrens.length > 0) { var li = $("<li></li>");
li.append("<a href='javascript:void(0)' class='"+val.UNION_TYPE+"' onclick=getOrgId('" + val.UNION_CODE + "','" + val.UNION_TYPE+"')>" + val.UNION_NAME + "</a>").append("<ul></ul>").appendTo(parent);
//递归显示
showall(val.childrens, $(li).children().eq(1));
} else {
$("<li></li>").append("<a href='javascript:void(0)' class='" + val.UNION_TYPE +"' onclick=getOrgId('" + val.UNION_CODE + "','" + val.UNION_TYPE +"')>" + val.UNION_NAME + "</a>").appendTo(parent);
}
});
})(jQuery)
}
//点击节点后统计该节点数据
function getOrgId(UNION_CODE, UNION_NAME) {
if (UNION_CODE!="") {
$.ajax({
url: '../Ajax/OrganizationalStructureAjax.ashx',
type: 'post',
dataType: 'json',
async: false,
data: { 'ajaxMethod': 'Summary', 'treeNodeID': UNION_CODE },
success: function (data) { $("#jcghs").text(data.jcghs == "" ? 0 : data.jcghs);
$("#fhs").text(data.fhs == "" ? 0 : data.fhs);
$("#hys").text(data.hys == "" ? 0 : data.hys);
$("#nxs").text(data.nxs == "" ? 0 : data.nxs);
$("#vxs").text(data.vxs == "" ? 0 : data.vxs);
$("#zzs").text(data.zzs == "" ? 0 : data.zzs);
$("#zks").text(data.zks == "" ? 0 : data.zks);
$("#bks").text(data.bks == "" ? 0 : data.bks);
$("#shyjss").text(data.shyjss == "" ? 0 : data.shyjss);
$("#bsyjss").text(data.bsyjss == "" ? 0 : data.bsyjss);
$("#qtxls").text(data.qtxls == "" ? 0 : data.qtxls);
}
});
}
else {
//展示(遍历该节点下的数据) //var htmlnode = "<td class='node-container' id='3' colspan='2'><table cellpadding='0' cellspacing='0' border='0'><tbody><tr class='node - cells'><td class='node - cell' colspan='2'><div class='node' style='height: 48px; width: 20px; '><a href='javascript: void (0)' class='3' onclick='getOrgId('', '3')'>...</a></div></td></tr></tbody></table></td>"; //$('.node-cells .node-cell .node a').find(function () { return this.classNmae == '3' && this.innerHTML == '...'; }).each(function () {
// $(this).parents('.node-container:first').after(htmlnode);
//});
}
}
function jc_click() {
$("#org").remove();
$(".jOrgChart").remove();
jOrgChart(false);
}
function hf_click() {
$("#org").remove();
$(".jOrgChart").remove();
jOrgChart(true);
}
function hy_click() {
// var htmlline = "<td class='node-container' id='3' colspan='2'>< table cellpadding = '0' cellspacing = '0' border = '0' > <tbody><tr class='node - cells'><td class='node - cell' colspan='2'><div class='node' style='height: 48px; width: 20px; '><a href='javascript: void (0)' class='3' onclick='getOrgId('', '3')'>...</a></div></td></tr></tbody></table ></td > "; } </script>

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace LY.CCPCUEP.Model.UEP
{
public class OrganizationFramework
{
public string UNION_CODE { get; set; }
public string PARENT_ORGANIZATION_CODE { get; set; }
public string UNION_NAME { get; set; } public string UNION_TYPE { get; set; }
public List<OrganizationFramework> childrens { get; set; }
} }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace LY.CCPCUEP.Model.UEP
{
public class OrganizatioTree
{
public string id { get; set; }
public string pid { get; set; }
public string name { get; set; } public List<OrganizatioTree> childrens { get; set; }
}
}
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;//反射
using System.Data; /// <summary>
///模块说明:数据结构化
///作者:xzx
///创建日期:2019-01-23
/// </summary>
namespace LY.CCPCUEP.Utility
{
public class CovertListHelper
{
//传递过来的类型必须与数据库类型保持一致问题
public List<T> convertToList<T>(DataTable dt) where T : new()
{ // 定义集合
List<T> ts = new List<T>();
// 获得此模型的类型
Type type = typeof(T);
//定义一个临时变量
string tempName = string.Empty;
//遍历DataTable中所有的数据行
foreach (DataRow dr in dt.Rows)
{
T t = new T();
// 获得此模型的公共属性
PropertyInfo[] propertys = t.GetType().GetProperties();
//遍历该对象的所有属性
foreach (PropertyInfo pi in propertys)
{
tempName = pi.Name;//将属性名称赋值给临时变量
//检查DataTable是否包含此列(列名==对象的属性名)
if (dt.Columns.Contains(tempName))
{
// 判断此属性是否有Setter
if (!pi.CanWrite) continue;//该属性不可写,直接跳出
//取值
object value = dr[tempName];
//如果非空,则赋给对象的属性
if (value != DBNull.Value) pi.SetValue(t, value, null);
}
}
//对象添加到泛型集合中
ts.Add(t);
}
return ts;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using LY.CCPCUEP.Model.UEP;
using LY.CCPCUEP.BLL.UEP;
using Newtonsoft.Json;
using LY.CCPCUEP.Utility; /// <summary>
///模块说明:ajax数据交互,数据结构化
///作者:夏志雄
///创建日期:2019-01-23
/// </summary> namespace LY.CCPCUEP.UI.Uep.Ajax
{ /// <summary>
/// OrganizationalStructureAjax1 的摘要说明
/// </summary>
public class OrganizationalStructureAjax : IHttpHandler
{
private HttpContext context;
DataTable dt = new DataTable();
public string strConn = "";
public string treeNodeID = "";
public string NodeID = "";
public string id = "";
public string reviseOption = "";
string ajaxMethod = "";
bool IsShow = false;
public void ProcessRequest(HttpContext context)
{
this.context = context;
id = context.Request.Form["id"];
NodeID = context.Request.Form["NodeID"];//初始id
treeNodeID = context.Request.Form["treeNodeID"];//点击节点id
//初始化节点为空赋值*节点
if (string.IsNullOrEmpty(treeNodeID))
{
treeNodeID = "234E45F0077881AAE0430AA3034681AA";
}
ajaxMethod = context.Request.Form["ajaxMethod"];//取得前台ajax请求的方法名称
if (!string.IsNullOrEmpty(context.Request.Form["IsShow"]))
{
IsShow = bool.Parse(context.Request.Form["IsShow"]);//节点是否展示
}
System.Reflection.MethodInfo method = this.GetType().GetMethod(ajaxMethod);
if (method != null)
{
method.Invoke(this, new object[] { });//通过方法名称指向对应的方法
}
} /// <summary>
/// 疑问联系人
/// </summary>
public void iphone()
{
T_UEP_DB_ZTREEBLL bll = new T_UEP_DB_ZTREEBLL();
var rhts = bll.Getrhts().Tables[].Rows[]["lookup_value_name"].ToString();
context.Response.Write(JsonConvert.SerializeObject(rhts));
} //统计
public void Summary()
{ DataTable dt = new DataTable();
T_UEP_DB_ZTREEBLL bll = new T_UEP_DB_ZTREEBLL(); DataTable xbdt = bll.Getxbs(treeNodeID).Tables[];
DataTable xldt = bll.Getxls(treeNodeID).Tables[];
object summaryData = null;
summaryData = new
{
jcghs = bll.Getjcghs(treeNodeID).Tables[].Rows[]["基层工会数"].ToString(),
fhs = bll.Getfhs(treeNodeID).Tables[].Rows[]["分会数"].ToString(),
hys = bll.Gethys(treeNodeID).Tables[].Rows[]["会员数"].ToString(),
nxs = xbdt.Rows[]["男性数"].ToString(),
vxs = xbdt.Rows[]["女性数"].ToString(),
zzs = xldt.Rows.Count > ? xldt.Select("LOOKUP_VALUE_NAME='中等专业学校(中专)'")[][].ToString() : "",
zks = xldt.Rows.Count > ? xldt.Select("LOOKUP_VALUE_NAME='大学专科'")[][].ToString() : "",
bks = xldt.Rows.Count > ? xldt.Select("LOOKUP_VALUE_NAME='大学本科'")[][].ToString() : "",
shyjss = xldt.Rows.Count > ? xldt.Select("LOOKUP_VALUE_NAME='硕士研究生'")[][].ToString() : "",
bsyjss = "",//博士
qtxls = xldt.Rows.Count > ? xldt.Select("LOOKUP_VALUE_NAME='小学/初中(职业初中)/高中(职业高中)/技工学校/无学历/其他学历'")[][].ToString() : "",
}; //基层工会数
context.Response.Write(JsonConvert.SerializeObject(summaryData)); }
/// <summary>
/// 异步加载当前节点的子节点
/// </summary>
public void AnsyData()
{
List<object> lsNode = new List<object>();
try
{ T_UEP_DB_ZTREEBLL dll = new T_UEP_DB_ZTREEBLL();
DataSet ds = dll.GetZtree("", false);
dt = ds.Tables[];
DataTable dataSource = new DataTable();
DataView dv = dt.DefaultView;
if (!string.IsNullOrEmpty(id))
{
dv.RowFilter = "PARENT_ORGANIZATION_CODE='" + id + "'";
}
//1.过滤后直接获取DataTable 
DataTable newTable1 = dv.ToTable();
lsNode = getList(newTable1);
context.Response.Write(JsonConvert.SerializeObject(lsNode));
}
catch (Exception)
{ throw;
}
} /// <summary>
/// 把数据形式转换成zTree的json数据格式
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
public List<object> getList(DataTable table)
{
try
{
List<object> lsNode = new List<object>();
bool isParent = true;
bool iszk = true;
foreach (DataRow row in table.Rows)
{
string iconstr = string.Empty;
if (row["UNION_TYPE"].ToString() == "")
{
iconstr = "../Images/8_open.png";
iszk = true;
}
else if (row["UNION_TYPE"].ToString() == "")
{
iconstr = "../Images/1_open.png";
iszk = false;
}
else if (row["UNION_TYPE"].ToString() == "")
{
iconstr = "../Images/6_open.png";
iszk = false;
}
if (isParentTrue(row["UNION_CODE"].ToString(), table))
isParent = true;
else
isParent = false;
var zTreeData = new
{
//ID
id = row["UNION_CODE"],
//父ID
pId = row["PARENT_ORGANIZATION_CODE"].ToString(),
//名称
name = row["UNION_NAME"],
//图标
icon = iconstr,
isParent = isParent,//是否拥有子节点
open = iszk,
};
lsNode.Add(zTreeData);
}
return lsNode;
}
catch (Exception ex)
{ throw;
}
} /// <summary>
/// 判断当前节点是否还有子节点
/// </summary>
/// <param name="ParentId">父节点Id</param>
/// <returns>bool类型</returns>
public bool isParentTrue(string ParentId, DataTable table)
{
try
{
T_UEP_DB_ZTREEBLL dll = new T_UEP_DB_ZTREEBLL();
DataRow[] dr = table.Select("PARENT_ORGANIZATION_CODE='" + ParentId + "'");
dt = ToDataTable(dr);
if (dt == null)
{
return false;
}
else
{
return true;
}
}
catch (Exception ex)
{ throw;
}
} private DataTable ToDataTable(DataRow[] rows)
{
if (rows == null || rows.Length == ) return null;
DataTable tmp = rows[].Table.Clone(); // 复制DataRow的表结构
foreach (DataRow row in rows)
{ tmp.ImportRow(row); // 将DataRow添加到DataTable中
}
return tmp;
}
public List<OrganizationFramework> Main = new List<OrganizationFramework>();
public List<OrganizatioTree> TreeMain = new List<OrganizatioTree>();
/// <summary>
/// 获取所有的组织架构数据
/// </summary>
/// <returns></returns>
public List<OrganizationFramework> GetAllFramework(string treeNodeID)
{
List<OrganizationFramework> listMenuS = new List<OrganizationFramework>();
OrganizationFramework of = new OrganizationFramework();
T_UEP_DB_ZTREEBLL dll = new T_UEP_DB_ZTREEBLL();
List<object> lsNode = new List<object>();
dt = dll.GetZtree(treeNodeID, IsShow).Tables[];
if (dt.Rows.Count > )
{
CovertListHelper co = new CovertListHelper();
listMenuS = co.convertToList<OrganizationFramework>(dt);
}
return listMenuS;
}
/// <summary>
/// 获取所有的树形框架数据
/// </summary>
/// <returns></returns>
public List<OrganizatioTree> GetAllTree()
{
List<OrganizatioTree> listMenuS = new List<OrganizatioTree>();
OrganizatioTree of = new OrganizatioTree();
T_UEP_DB_ZTREEBLL dll = new T_UEP_DB_ZTREEBLL();
dt = dll.GetZtree("", IsShow).Tables[];
if (dt.Rows.Count > )
{
listMenuS = ConvertTo(dt);
}
return listMenuS;
} //使用Linq的ToList方法,非泛型
public static List<OrganizatioTree> ConvertTo(DataTable dt)
{
if (dt == null) return null;
if (dt.Rows.Count <= ) return null;
List<OrganizatioTree> list = new List<OrganizatioTree>();
list = (from DataRow dr in dt.Rows
select new OrganizatioTree
{
id = dr["UNION_CODE"].ToString(),
pid = dr["PARENT_ORGANIZATION_CODE"].ToString(),
name = dr["UNION_NAME"].ToString(), }).ToList();
return list;
} private DataTable getData()
{
DataTable dt = new DataTable();
dt.Columns.Add("UNION_CODE", typeof(Guid));
dt.Columns.Add("UNION_NAME", typeof(string));
dt.Columns.Add("PARENT_ORGANIZATION_CODE", typeof(Guid)); dt.Rows.Add("1EF13BE6011A6733E0530100007F80DF", "天下会", "2EF13BE6011A6733E0530100007F80DF");
dt.Rows.Add("2EF13BE6011A6733E0530100007F80DF", "东风汽车有限公司", "10F13BE6011A6733E0530100007F80DF");
dt.Rows.Add("3EF13BE6011A6733E0530100007F80DF", "风神襄阳工会", "2EF13BE6011A6733E0530100007F80DF"); dt.Rows.Add("4EF13BE6011A6733E0530100007F80DF", "大连工厂工会", "2EF13BE6011A6733E0530100007F80DF");
dt.Rows.Add("5EF13BE6011A6733E0530100007F80DF", "PV机关工会", "2EF13BE6011A6733E0530100007F80DF");
dt.Rows.Add("6EF13BE6011A6733E0530100007F80DF", "发动机分公司工会", "2EF13BE6011A6733E0530100007F80DF");
dt.Rows.Add("7EF13BE6011A6733E0530100007F80DF", "广州风神工会", "2EF13BE6011A6733E0530100007F80DF");
dt.Rows.Add("8EF13BE6011A6733E0530100007F80DF", "研发采购工会", "2EF13BE6011A6733E0530100007F80DF");
dt.Rows.Add("9EF13BE6011A6733E0530100007F80DF", "郑州工厂工会", "2EF13BE6011A6733E0530100007F80DF");
dt.Rows.Add("1AF13BE6011A6733E0530100007F80DF", "工厂11", "9EF13BE6011A6733E0530100007F80DF");
dt.Rows.Add("1BF13BE6011A6733E0530100007F80DF", "工厂22", "9EF13BE6011A6733E0530100007F80DF");
return dt;
} //父子级递归
public void AddMenu(List<OrganizationFramework> all, OrganizationFramework curItem)
{
//第一层不过滤,第二层过滤为5行,第三层过滤为5行,将三层的数据拼接一起
List<OrganizationFramework> childItems = all.Where(ee => ee.PARENT_ORGANIZATION_CODE == curItem.UNION_CODE).ToList(); //得到子节点
if (curItem.UNION_TYPE == "" || curItem.UNION_TYPE == "")
{
List<OrganizationFramework> l = new List<OrganizationFramework>();
if (childItems.Count > && curItem.UNION_TYPE == "")
{
OrganizationFramework ellipsisData = new OrganizationFramework
{
UNION_CODE = "",
PARENT_ORGANIZATION_CODE = "",
UNION_NAME = "...",
UNION_TYPE = "",
childrens = new List<OrganizationFramework>(),
};
l.Add(ellipsisData);
}
if (childItems.Count > && curItem.UNION_TYPE == "")
{
OrganizationFramework ellipsisData = new OrganizationFramework
{
UNION_CODE = "",
PARENT_ORGANIZATION_CODE = "",
UNION_NAME = "...",
UNION_TYPE = "",
childrens = new List<OrganizationFramework>(),
};
l.Add(ellipsisData);
}
l.InsertRange(, childItems.Take());//序列连续的数量
childItems = l;
} curItem.childrens = childItems; //将子节点加入
//遍历子节点,进行递归,寻找子节点的子节点
foreach (var subItem in childItems)
{
AddMenu(all, subItem);
}
} //父子级递归
public void AddTreeMenu(List<OrganizatioTree> all, OrganizatioTree curItem)
{
List<OrganizatioTree> childItems = all.Where(ee => ee.pid == curItem.id).ToList(); //得到子节点
curItem.childrens = childItems; //将子节点加入
//遍历子节点,进行递归,寻找子节点的子节点
foreach (var subItem in childItems)
{
AddTreeMenu(all, subItem);
}
} /// <summary>
/// 初始化第一次节点加载
/// </summary>
public void FirstAnsyData()
{
try
{
List<object> lsNode = new List<object>();
T_UEP_DB_ZTREEBLL dll = new T_UEP_DB_ZTREEBLL();
dt = dll.GetZtree("", IsShow).Tables[];
DataRow[] dr = dt.Select("PARENT_ORGANIZATION_CODE is null ");
dt = ToDataTable(dr);
lsNode = getList(dt);
context.Response.Write(JsonConvert.SerializeObject(lsNode));
}
catch (Exception)
{ throw;
} }
/// <summary>
/// 初始化
/// </summary>
public void GetjOrgChartJson()
{
List<OrganizationFramework> allMenu = GetAllFramework(""); //得到数据
if (!string.IsNullOrEmpty(treeNodeID))
{
OrganizationFramework organizationFramework = allMenu.Where(x => x.UNION_CODE == treeNodeID).FirstOrDefault();
if (organizationFramework == null)
{
organizationFramework = new OrganizationFramework();
}
Main.Add(organizationFramework);//根节点
OrganizationFramework organizationFrameworkMain = allMenu.Where(x => x.UNION_CODE == treeNodeID).FirstOrDefault();
if (organizationFrameworkMain == null)
{
organizationFrameworkMain = new OrganizationFramework();
}
AddMenu(allMenu, organizationFrameworkMain);//递归 }
else
{
OrganizationFramework organizationFramework = allMenu.Where(x => x.PARENT_ORGANIZATION_CODE == null).FirstOrDefault();
if (organizationFramework == null)
{
organizationFramework = new OrganizationFramework();
}
Main.Add(organizationFramework);//根节点
OrganizationFramework organizationFrameworkMain = allMenu.Where(x => x.UNION_CODE == Main.ElementAt().UNION_CODE).FirstOrDefault();
// OrganizationFramework organizationFrameworkMain = allMenu.Where(x => x.UNION_TYPE == "1").FirstOrDefault();
if (organizationFrameworkMain == null)
{
organizationFrameworkMain = new OrganizationFramework();
}
AddMenu(allMenu, organizationFrameworkMain);//递归
} //结果树形结构
List<OrganizationFramework> treeMenu = Main;
string jOrgChartJson = JsonConvert.SerializeObject(treeMenu); context.Response.Write(jOrgChartJson);
} public bool IsReusable
{
get
{
return false;
}
} }
}

树形插件zTree与组织插件jOrgChart交互