SyncAllUsers.aspx.cs
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:3k
源码类别:

OA系统

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.HtmlControls;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. namespace OThinker.H3.Portal
  12. {
  13.     public partial class SyncAllUsers : PortalPage
  14.     {
  15.         protected string ParentID
  16.         {
  17.             get
  18.             {
  19.                 return this.Request.QueryString[Param_Parent];
  20.             }
  21.         }
  22.         protected void Page_Load(object sender, EventArgs e)
  23.         {
  24.             if (!this.IsPostBack)
  25.             {
  26.                 // 验证是否具有管理员权限
  27.                 if (!this.UserValidator.ValidateAdministrator())
  28.                 {
  29.                     this.NotifyMessage(LackOfAuth);
  30.                 }
  31.                 this.lblADPath.Text = OThinker.H3.Server.Engine.SettingManager.ADPath;
  32.                 this.lblADUser.Text = OThinker.H3.Server.Engine.SettingManager.ADUser;
  33.                 string adPassword = OThinker.H3.Server.Engine.SettingManager.ADPassword;
  34.                 this.lblADPassword.Text = ((adPassword == null || adPassword == "") ? "未设置" : "已设置");
  35.             }
  36.         }
  37.         protected void lnkOk_Click(object sender, EventArgs e)
  38.         {
  39.             try
  40.             {
  41.                 // 查询满足条件的用户
  42.                 string[] users = OThinker.H3.Server.Engine.Organization.QueryADUsers(
  43.                    OThinker.H3.Server.Engine.SettingManager.ADPath,
  44.                    OThinker.H3.Server.Engine.SettingManager.ADUser,
  45.                    OThinker.H3.Server.Engine.SettingManager.ADPassword,
  46.                    null);
  47.                 if (users != null)
  48.                 {
  49.                     foreach (string userAlias in users)
  50.                     {
  51.                         OThinker.Organization.HandleResult result = OThinker.Organization.HandleResult.SUCCESS;
  52.                         OThinker.Organization.User user = OThinker.H3.Server.Engine.Organization.CreateUser(
  53.                             OThinker.H3.Server.Engine.SettingManager.ADPath,
  54.                             OThinker.H3.Server.Engine.SettingManager.ADUser,
  55.                             OThinker.H3.Server.Engine.SettingManager.ADPassword,
  56.                             userAlias,
  57.                             ref result);
  58. user.ParentID = this.ParentID;
  59.                         OThinker.H3.Server.Engine.Organization.AddUnit(this.UserValidator.UserID, user, ref result);
  60.                     }
  61.                 }
  62.             }
  63.             catch
  64.             {
  65.                 this.NotifyMessage("与活动目录连接出现异常,请检查:1、是否有设置活动目录信息;2、运行工作流服务的帐号是否有访问活动目录的权限;3、域服务器是否可以访问");
  66.             }
  67.             // 显示结果
  68.             this.NotifyResult(
  69.                 OThinker.Organization.HandleResult.SUCCESS,
  70.                 true,
  71.                 this.Request.QueryString[Param_ExpandPath]);
  72.         }
  73.     }
  74. }