讀取RTX組織架構

來源:互聯網
上載者:User

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;
        }
    }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.