ChengDa_English/SGGL/FineUIPro.Web/SysManage/ADomain.aspx.cs

138 lines
5.1 KiB
C#

using BLL;
using System;
using System.DirectoryServices;
using System.Linq;
using System.Web.UI;
namespace FineUIPro.Web.SysManage
{
public partial class ADomain : PageBase
{
/// <summary>
/// 用户编辑页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
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
/// <summary>
/// 连接测试
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
/// <summary>
/// 获取AD域按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
}
}