using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using RTXSAPILib; using System.Runtime.InteropServices; namespace DeptmanagerObj { public partial class DeptUserfrm : Form { RTXSAPILib.RTXSAPIRootObj RootObj; //声明一个根对象 RTXSAPILib.RTXSAPIDeptManager DeptManagerObj; //声明一个部门管理对象 public DeptUserfrm() { InitializeComponent(); RootObj = new RTXSAPIRootObj(); //创建根对象 DeptManagerObj = RootObj.DeptManager; //通过根对象创建部门管理对象 } private void btnGetDeptUsers_Click( object sender, EventArgs e) { try { string deptUsers = DeptManagerObj.GetDeptUsers(txtDeptName.Text); //查看部门下的用户列表 MessageBox.Show(deptUsers); } catch (COMException ex) { MessageBox.Show(ex.Message); } } private void btnGetUserDepts_Click( object sender, EventArgs e) { try { string depts = DeptManagerObj.GetUserDepts(txtUserName.Text); //查看用户所属部门 MessageBox.Show(depts); } catch (COMException ex) { MessageBox.Show(ex.Message); } } private void btnAddUserToDept_Click( object sender, EventArgs e) { string SrcDeptName; if (txtSrcDeptName.Text == "") SrcDeptName = null; else SrcDeptName = txtSrcDeptName.Text; try { DeptManagerObj.AddUserToDept(txtUser.Text, SrcDeptName, txtDesDeptName.Text, false); //添加用户进某个部门,如果用户没有所属部门,源部门名为null即可。 MessageBox.Show( "添加成功"); } catch (COMException ex) { MessageBox.Show(ex.Message); } } private void btnDelUserFromDept_Click( object sender, EventArgs e) { try { DeptManagerObj.DelUserFromDept(txtdelUser.Text, txtDept.Text); //从某个部门下删除用户 MessageBox.Show( "删除成功"); } catch (COMException ex) { MessageBox.Show(ex.Message); } } //通常不需要用到该方法,该方法主要应用场景是有些用户同时属于多个部门,想把主要部门显示在前面。 //最多能设置前三个部门 private void btnSetUserMainDept_Click( object sender, EventArgs e) { try { DeptManagerObj.SetUserMainDepts(txtMainDeptUser.Text, txtDept1.Text, txtDept2.Text, txtDept3.Text); MessageBox.Show( "设置成功"); } catch (COMException ex) { MessageBox.Show(ex.Message); } } } } .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }