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

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 SyncUser : 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.                 if (!this.UserValidator.ValidateAdministrator())
  27.                 {
  28.                     this.NotifyMessage(LackOfAuth);
  29.                 }
  30.                 // 返回按钮
  31.                 string q = HttpUtility.UrlDecode(this.Request.QueryString[Param_Q]);
  32.                 if (q == null || q == "")
  33.                 {
  34.                     this.lnkReturn.Visible = false;
  35.                 }
  36.                 else
  37.                 {
  38.                     this.lnkReturn.NavigateUrl = q;
  39.                 }
  40.                 this.lblADPath.Text = OThinker.H3.Server.Engine.SettingManager.ADPath;
  41.                 this.lblADUser.Text = OThinker.H3.Server.Engine.SettingManager.ADUser;
  42.             }
  43.         }
  44.         protected void lnkQuery_Click(object sender, EventArgs e)
  45.         {
  46.             this.lstUser.Items.Clear();
  47.             string[] users = null;
  48.             try
  49.             {
  50.                  users = OThinker.H3.Server.Engine.Organization.QueryADUsers(
  51.                     OThinker.H3.Server.Engine.SettingManager.ADPath,
  52.                     OThinker.H3.Server.Engine.SettingManager.ADUser,
  53.                     OThinker.H3.Server.Engine.SettingManager.ADPassword,
  54.                     this.txtUserAlias.Text);
  55.             }
  56.             catch
  57.             {
  58.                 this.NotifyMessage("与活动目录连接出现异常,请检查:1、是否有设置活动目录信息;2、运行工作流服务的帐号是否有访问活动目录的权限;3、域服务器是否可以访问");
  59.             }
  60.             if (users == null || users.Length == 0)
  61.             {
  62.                 this.lblResult.Text = "没有找到满足条件的用户";
  63.             }
  64.             else
  65.             {
  66.                 this.lblResult.Text = null;
  67.                 foreach (string user in users)
  68.                 {
  69.                     this.lstUser.Items.Add(user);
  70.                 }
  71.             }
  72.         }
  73.         protected void btnSubmit_Click(object sender, EventArgs e)
  74.         {
  75.             string userAlias = this.lstUser.SelectedValue;
  76.             if (userAlias == null || userAlias == "")
  77.             {
  78.                 userAlias = this.txtUserAlias.Text;
  79.             }
  80.             if (userAlias == null || userAlias == "")
  81.             {
  82.                 this.lblSubmitResult.Text = "没有输入要同步的用户";
  83.                 return;
  84.             }
  85.             // 检查是否已经存在
  86.             if (OThinker.H3.Server.Engine.Organization.GetUserIDByAlias(userAlias) != null)
  87.             {
  88.                 this.lblSubmitResult.Text = "该用户已经存在";
  89.                 return;
  90.             }
  91.             // 尝试创建一个用户
  92.             OThinker.Organization.HandleResult result = OThinker.Organization.HandleResult.SUCCESS;
  93.             OThinker.Organization.User user = null;
  94.             try
  95.             {
  96.                 user = OThinker.H3.Server.Engine.Organization.CreateUser(
  97.                     OThinker.H3.Server.Engine.SettingManager.ADPath,
  98.                     OThinker.H3.Server.Engine.SettingManager.ADUser,
  99.                     OThinker.H3.Server.Engine.SettingManager.ADPassword,
  100.                     userAlias,
  101.                     ref result);
  102.             }
  103.             catch
  104.             {
  105.                 this.lblSubmitResult.Text = "同步出现异常,请检查:1、登录域的配置是否有配置;2、运行工作流服务的帐号是否有读取域的权限。";
  106.                 return;
  107.             }
  108.             if (result != OThinker.Organization.HandleResult.SUCCESS)
  109.             {
  110.                 this.lblSubmitResult.Text = this.ParseResult(result);
  111.                 return;
  112.             }
  113.             else
  114.             {
  115.                 // 跳转到编辑用户属性的界面
  116.                 string url = 
  117.                     PageName_EditUser + "?" + 
  118.                     Param_Parent + "=" + this.ParentID + "&" + 
  119.                     Param_ADUser + "=" + userAlias + "&" + 
  120.                     Param_ExpandPath + "=" + this.Request.QueryString[Param_ExpandPath];
  121.                 this.Response.Redirect(url);
  122.             }
  123.         }
  124.     }
  125. }