using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Abs.Sys.Model;
using Abs.Sys.Utility.Authorization;
using Sinopec.IWMS.Business;
public partial class ProjectPlan_CommonPage_Organization : System.Web.UI.Page
{
/// <summary>
/// 都改成本地库了(2011-06-29)
/// </summary>
private readonly string DATAOJBECT_GROUP_ID = "B28E12B0-E375-4D97-95E8-8BFF098F9033"; //数据对象中的“业务组织机构ID查询”ID
//private readonly string BUSINESS_GROUP_ID = "47978AC9-3AEC-4F19-B1B0-93862800BD84"; //业务组织机构树根节点ID
private readonly string BUSINESS_GROUP_ID = "E3796A1C-3C42-433B-82B0-12FF6B2DEF62"; //业务组织机构树根节点ID,资产
/// <summary>
/// 显示树的方式
/// 1、等于1时根据当前传入的行政组织机构ID构建树
/// 2、等于2时根据当前传入的节点展示其下所有节点构建树
/// 3、默认为显示所有节点
/// </summary>
private string showOrgType = string.Empty;
/// <summary>
/// 需要显示的机构节点父ID(行政组织机构)
/// </summary>
private string orgId = string.Empty;
/// <summary>
/// 需要显示的机构节点父ID(业务组织机构)
/// </summary>
private string bOrgId = string.Empty;
/// <summary>
/// 树节点需要显示到的深度
/// </summary>
private int showDepth = 0;
protected void Page_Load(object sender, EventArgs e)
{
showDepth = 2;
showOrgType = Request.QueryString["OrgType"];
orgId = Request.QueryString["OrgId"];
bOrgId = Request.QueryString["BOrgId"];
if (!IsPostBack)
{
DataTable dtSource = new DataTable();
switch (showOrgType)
{
case "1":
dtSource = BoBasePage.Instance.GetBusinessOrgListByOrgId(orgId); //根据当前传入的行政组织机构ID构建树
TreeNode node = new TreeNode();
node.Text = "信息化业务组织机构";
node.SelectAction = TreeNodeSelectAction.None;
this.TreeView1.Nodes.Add(node);
foreach (DataRow row in dtSource.Rows)
{
TreeNode childNode = new TreeNode();
childNode.Text = row["BusinessName"].ToString();
childNode.Value = row["BusinessID"].ToString();
childNode.SelectAction = TreeNodeSelectAction.None;
node.ChildNodes.Add(childNode);
}
break;
case "2":
dtSource = BoBasePage.Instance.GetBusinessOrganizationTable(bOrgId); //显示指定结构的树
CreateTree(dtSource);
break;
case "3":
break;
default:
dtSource = BoBasePage.Instance.GetBusinessOrganizationTable(); //显示所有节点
CreateTree(dtSource);
break;
}
}
this.Page.Title = "组织机构树";
}
private DataTable GetTable(DataTable dtSource, string topid)
{
DataTable dtOutPut = dtSource.Clone();
try
{
DataRow[] rows = dtSource.Select("BusinessParentId='" + topid + "'");
foreach (DataRow row in rows)
{
dtOutPut.Rows.Add(row.ItemArray);
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
return dtOutPut;
}
/// <summary>
/// 创建组织机构树
/// </summary>
/// <param name="dtInputTable"></param>
private void CreateTree(DataTable dtInputTable)
{
try
{
if (dtInputTable != null)
{
DataTable dtSource = dtInputTable.Clone();
DataRow[] rows = dtInputTable.Select("BusinessParentId IS NULL OR BusinessParentId = ''");
bool isExistRoot = false; //是否存在为空的父节点
if (rows.Length > 0)
{
foreach (DataRow row in rows)
{
dtSource.Rows.Add(row.ItemArray);
}
isExistRoot = true;
}
else
{
dtSource = dtInputTable;
}
if (dtSource != null && dtSource.Rows.Count > 0)
{
int rootNum = 0;
if (isExistRoot)
{
rootNum = dtSource.Rows.Count;
}
else
{
rootNum = 1;
}
for (int i = 0; i < rootNum; i++)
{
TreeNode tn = new TreeNode();
tn.Text = dtSource.Rows[i]["BusinessName"].ToString();
tn.Value = dtSource.Rows[i]["BusinessID"].ToString();
tn.SelectAction = TreeNodeSelectAction.None;
TreeView1.Nodes.Add(tn);
CreateNodes(dtInputTable, tn);
}
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
/// <summary>
/// 添加组织机构节点
/// </summary>
/// <param name="dtSource"></param>
/// <param name="tn"></param>
private void CreateNodes(DataTable dtSource, TreeNode tn)
{
try
{
DataTable dtChild = GetTable(dtSource, tn.Value);
foreach (DataRow row in dtChild.Rows)
{
TreeNode node = new TreeNode();
node.Text = row["BusinessName"].ToString();
node.Value = row["BusinessID"].ToString();
node.Expanded = false;
node.SelectAction = TreeNodeSelectAction.None;
tn.ChildNodes.Add(node);
dtChild = dtSource;
if (tn.Depth != showDepth)
{
//node.ShowCheckBox = false;
CreateNodes(dtChild, node);
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
protected void btnSelect_Click(object sender, EventArgs e)
{
foreach (TreeNode nodeChecked in this.TreeView1.CheckedNodes)
{
Response.Write("<script>var u = new Array();u[0]='" + nodeChecked.Text + "';u[1]='" + nodeChecked.Value + "';window.returnValue=u;window.close();</script>");
}
}
protected void btnClear_Click(object sender, EventArgs e)
{
Response.Write("<script>var u = new Array();u[0]='';u[1]='';window.returnValue=u;window.close();</script>");
}
}
动态加载实现无限级树
最新推荐文章于 2023-08-04 18:20:56 发布