using RTXSAPILib;
部分代碼:
RTXSAPILib.RTXSAPIRootObj RootObj; //聲明一個根對象
RTXSAPILib.RTXSAPIDeptManager DeptManagerObj; //聲明一個部門管理對象
RootObj = new RTXSAPIRootObj(); //建立根對象
DeptManagerObj = RootObj.DeptManager; //通過根對象建立部門管理對象
// 調用
//顯示RTX部門架構
string deptpath = null;
this.tvRTXDepts.Nodes.Clear(); //tvRTXDepts為顯示組織架構的TreeView
TreeNode td = new TreeNode();
td.Text = "部門架構";
this.tvRTXDepts.Nodes.Add(td);
GetAll(deptpath, td);
/// <summary>擷取RTX所有部門架構
/// 擷取RTX所有部門架構
/// </summary>
/// <param name="path"></param>
/// <param name="CurrentNode"></param>
private void GetAll(string path, TreeNode CurrentNode)
{
DeptInfo mainDir = new DeptInfo(path);
try
{
foreach (string depts in mainDir.GetDept())
{
TreeNode td = new TreeNode();
td.Text = depts;
CurrentNode.Nodes.Add(td);
GetAll(path + @"" + depts, td);
}
}
catch (Exception err)
{
// MessageBox.Show(err.Message);
}
}
//選中部門是在listBox中顯示該部門的成員
/// <summary>顯示RTX部門的成員
/// 顯示RTX部門的成員
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tvRTXDepts_AfterSelect(object sender, TreeViewEventArgs e)
{
XmlDocument xmldoc = new XmlDocument();
this.listRTXAccounts.Items.Clear();
try
{
if (this.tvRTXDepts.SelectedNode.Text.Trim() != "部門架構")
{
string deptUsers = DeptManagerObj.GetDeptUsers(this.tvRTXDepts.SelectedNode.Text.Trim()); //查看部門下的使用者列表
string xmlstr = "<?xml version="1.0" encoding="GB2312" ?>" + deptUsers;
xmldoc.LoadXml(xmlstr);
XmlNode root = xmldoc.SelectSingleNode(@"/Users");
XmlNodeList nodeList = root.ChildNodes;
foreach (XmlNode node in nodeList)
{
this.listRTXAccounts.Items.Add(node.Attributes["Name"].InnerText);
}
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
MessageBox.Show(ex.Message);
}
}
using System;
using System.Collections.Generic;
using System.Text;
using RTXSAPILib;
using System.Xml;
using System.Diagnostics;
using System.Collections;
namespace RTXMsgTongYiManagerForm
{
class DeptInfo
{
string deptpath;
public DeptInfo(string path) //建構函式,輸入一個部門的路徑
{
deptpath = path;
}
public string DetpPath //屬性,把傳進來的路徑賦值給類的deptpath
{
get
{
return deptpath;
}
set
{
deptpath = value;
}
}
public List<string> GetDept()
{
RTXSAPIRootObj RootObj = new RTXSAPIRootObj(); //建立一個根對象
RTXSAPIDeptManager DeptObj = RootObj.DeptManager; //建立一個部門管理對象
string strChildDepts = DeptObj.GetChildDepts(deptpath); //擷取該部門下的子部門
List<string> ChildDepts = new List<string>(); //建立一個集合對象,用來存在子部門
XmlDocument xmlDoc = new XmlDocument(); //建立一個xmlDocument對象
xmlDoc.LoadXml(strChildDepts);// 把子部門的xml字串輸進xml對象裡面
XmlNode root = xmlDoc.DocumentElement; //擷取文檔的element
IEnumerator ienum = root.GetEnumerator();
XmlNode dept;
if (HasChildDepts(strChildDepts)) //判斷是否有子部門
{
while (ienum.MoveNext())
{
dept = (XmlNode)ienum.Current;
string deptNameXml = dept.OuterXml;
int beginPos = deptNameXml.IndexOf(""") + 1;
int lastPos = deptNameXml.LastIndexOf(""");
string strDeptName = deptNameXml.Substring(beginPos, lastPos - beginPos);
ChildDepts.Add(strDeptName);
}
return ChildDepts; //返回集合
}
else
{
return new List<string>(); //如果沒有子部門返回空
}
}
private bool HasChildDepts(string strChildDetps)
{
if (strChildDetps.Length == 27)
return false;
else
return true;
}
}
}