using BLL; using System; using System.DirectoryServices; using System.Linq; using System.Web.UI; namespace FineUIPro.Web.SysManage { public partial class ADomain : PageBase { /// /// 用户编辑页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ///权限 this.GetButtonPower(); var aDomain = BLL.ADomainService.getADomain(); if (aDomain != null) { this.txtDomainName.Text = aDomain.DomainName; this.txtRootOU.Text = aDomain.RootOU; this.txtUserName.Text = aDomain.UserName; this.txtPassword.Text = aDomain.Password; this.txtIntervaltime.Text = aDomain.Intervaltime.ToString(); } else { this.txtIntervaltime.Text ="720"; string domainAndName = Page.User.Identity.Name; string[] infoes = domainAndName.Split(new string[1] { "\\" }, StringSplitOptions.RemoveEmptyEntries); if (infoes.Length > 1) { this.txtDomainName.Text = infoes[0]; this.txtUserName.Text = infoes[1]; this.txtPassword.Focus(); } else { this.txtDomainName.Focus(); } } } } #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { string menuId = Const.ADomainMenuId; var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, menuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnSave)) { this.btnSave.Hidden = false; this.btnConnect.Hidden = false; } } } #endregion /// /// 连接测试 /// /// /// protected void btnConnect_Click(object sender, EventArgs e) { ////检查域名是否存在 var admoain = ADomainService.IsConnected(this.txtDomainName.Text.Trim(), this.txtUserName.Text.Trim(), this.txtPassword.Text.Trim()); if (admoain == null) { ShowNotify("域连接不成功,请正确输入域信息!", MessageBoxIcon.Warning); return; } ////检查域组织是否存在 if (BLL.ADomainService.IsExistOU(admoain, this.txtDomainName.Text.Trim(), this.txtRootOU.Text.Trim()) == null) { ShowNotify("域连接不成功,请正确输入域信息!", MessageBoxIcon.Warning); return; } BLL.ADomainService.DeleteADomain(); Model.Sys_ADomain newADomain = new Model.Sys_ADomain(); newADomain.DomainName = this.txtDomainName.Text.Trim(); newADomain.RootOU = this.txtRootOU.Text.Trim(); newADomain.UserName = this.txtUserName.Text.Trim(); newADomain.Password = this.txtPassword.Text.Trim(); newADomain.Intervaltime = BLL.Funs.GetNewIntOrZero(this.txtIntervaltime.Text.Trim()); BLL.ADomainService.AddADomain(newADomain); } /// /// 获取AD域按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { var adomain = ADomainService.getADomain(); if (adomain != null) { DirectoryEntry domain = BLL.ADomainService.IsConnected(adomain.DomainName, adomain.UserName, adomain.Password); if (domain != null) { DirectoryEntry rootOU = BLL.ADomainService.IsExistOU(domain, adomain.DomainName, adomain.RootOU); if (rootOU != null) { ADomainService.SyncAll(rootOU); //同步所有 ShowNotify("导入成功!", MessageBoxIcon.Success); } else { ShowNotify("域中不存在此组织结构!", MessageBoxIcon.Warning); } } else { ShowNotify("不能连接到域,请确认输入是否正确!", MessageBoxIcon.Warning); } } else { ShowNotify("请先正确设置AD域信息!", MessageBoxIcon.Warning); } } } }