/// <summary> /// buttong for synchronization /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSyns_Click(object sender, EventArgs e) { if (ValidationInput()) { if (ad.Connect(txtDomainName.Text.Trim(), txtUserName.Text.Trim(), txtPwd.Text.Trim(), txtRootOU.Text.Trim())) { MessageBox.Show("连接AD成功,继续同步中...", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); if (ad.ExchangeDomain != null) { /* * List<AdNode> list = ad.GetAllUsers(); //同步所有 * * StringBuilder sb = new StringBuilder(); * sb.Append("DomainName=" + txtDomainName.Text + "\n"); * sb.Append("UserName="******"\n"); * sb.Append("RootOU=" + txtRootOU.Text + "\n"); * sb.Append("同步成功" + list.Count.ToString() + "项\n"); * sb.Append("\r\n帐号\t姓名\t类型\t电邮\t路径\r\n"); * * foreach (var item in list) * { * sb.AppendFormat("{0}\t{1}\t{2}\t{3}\t{4}\r\n", item.Name, item.DisplayName, item.Type, item.Email, item.DistinguishedName); * } * * LogRecord.WriteLog(sb.ToString()); * MessageBox.Show(sb.ToString(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); */ AdGroup group = ad.FindGroup("ICS"); string sss = "ICS\n"; foreach (AdNode item in group.Members) { if (!string.IsNullOrEmpty(item.Email)) { sss += item.Email + ","; } } MessageBox.Show(sss, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); Application.Exit(); } else { MessageBox.Show("域中不存在此组织结构!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { MessageBox.Show("不能连接到域,请确认输入是否正确!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } }