读取RTX组织架构

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);
///

获取RTX所有部门架构
        /// 获取RTX所有部门架构
        ///

        ///
        ///
        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中显示该部门的成员
 
 /// 显示RTX部门的成员
        /// 显示RTX部门的成员
        ///

        ///
        ///

        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 = "" + 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 GetDept()
        {
            RTXSAPIRootObj RootObj = new RTXSAPIRootObj();  //创建一个根对象
            RTXSAPIDeptManager DeptObj = RootObj.DeptManager;   //创建一个部门管理对象
            string strChildDepts = DeptObj.GetChildDepts(deptpath); //获取该部门下的子部门
            List ChildDepts = new List(); //创建一个集合对象,用来存在子部门
            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(); //如果没有子部门返回空
              }
        }
        private bool HasChildDepts(string strChildDetps)
        {
            if (strChildDetps.Length == 27)
                return false;
            else
                return true;
        }
    }
}

你可能感兴趣的:(rtx,rtx二次开发)