SyncUser.aspx.cs
资源名称:H3_OA.rar [点击查看]
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:5k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Collections;
- using System.Configuration;
- using System.Data;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- namespace OThinker.H3.Portal
- {
- public partial class SyncUser : PortalPage
- {
- protected string ParentID
- {
- get
- {
- return this.Request.QueryString[Param_Parent];
- }
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!this.IsPostBack)
- {
- if (!this.UserValidator.ValidateAdministrator())
- {
- this.NotifyMessage(LackOfAuth);
- }
- // 返回按钮
- string q = HttpUtility.UrlDecode(this.Request.QueryString[Param_Q]);
- if (q == null || q == "")
- {
- this.lnkReturn.Visible = false;
- }
- else
- {
- this.lnkReturn.NavigateUrl = q;
- }
- this.lblADPath.Text = OThinker.H3.Server.Engine.SettingManager.ADPath;
- this.lblADUser.Text = OThinker.H3.Server.Engine.SettingManager.ADUser;
- }
- }
- protected void lnkQuery_Click(object sender, EventArgs e)
- {
- this.lstUser.Items.Clear();
- string[] users = null;
- try
- {
- users = OThinker.H3.Server.Engine.Organization.QueryADUsers(
- OThinker.H3.Server.Engine.SettingManager.ADPath,
- OThinker.H3.Server.Engine.SettingManager.ADUser,
- OThinker.H3.Server.Engine.SettingManager.ADPassword,
- this.txtUserAlias.Text);
- }
- catch
- {
- this.NotifyMessage("与活动目录连接出现异常,请检查:1、是否有设置活动目录信息;2、运行工作流服务的帐号是否有访问活动目录的权限;3、域服务器是否可以访问");
- }
- if (users == null || users.Length == 0)
- {
- this.lblResult.Text = "没有找到满足条件的用户";
- }
- else
- {
- this.lblResult.Text = null;
- foreach (string user in users)
- {
- this.lstUser.Items.Add(user);
- }
- }
- }
- protected void btnSubmit_Click(object sender, EventArgs e)
- {
- string userAlias = this.lstUser.SelectedValue;
- if (userAlias == null || userAlias == "")
- {
- userAlias = this.txtUserAlias.Text;
- }
- if (userAlias == null || userAlias == "")
- {
- this.lblSubmitResult.Text = "没有输入要同步的用户";
- return;
- }
- // 检查是否已经存在
- if (OThinker.H3.Server.Engine.Organization.GetUserIDByAlias(userAlias) != null)
- {
- this.lblSubmitResult.Text = "该用户已经存在";
- return;
- }
- // 尝试创建一个用户
- OThinker.Organization.HandleResult result = OThinker.Organization.HandleResult.SUCCESS;
- OThinker.Organization.User user = null;
- try
- {
- user = OThinker.H3.Server.Engine.Organization.CreateUser(
- OThinker.H3.Server.Engine.SettingManager.ADPath,
- OThinker.H3.Server.Engine.SettingManager.ADUser,
- OThinker.H3.Server.Engine.SettingManager.ADPassword,
- userAlias,
- ref result);
- }
- catch
- {
- this.lblSubmitResult.Text = "同步出现异常,请检查:1、登录域的配置是否有配置;2、运行工作流服务的帐号是否有读取域的权限。";
- return;
- }
- if (result != OThinker.Organization.HandleResult.SUCCESS)
- {
- this.lblSubmitResult.Text = this.ParseResult(result);
- return;
- }
- else
- {
- // 跳转到编辑用户属性的界面
- string url =
- PageName_EditUser + "?" +
- Param_Parent + "=" + this.ParentID + "&" +
- Param_ADUser + "=" + userAlias + "&" +
- Param_ExpandPath + "=" + this.Request.QueryString[Param_ExpandPath];
- this.Response.Redirect(url);
- }
- }
- }
- }