private string GetADUser(string gourp, string name) { string json = string.Empty; Yawei.Domain.Domain domain = new Yawei.Domain.Domain(); if (name.Trim() != "") { SearchResultCollection searchResultCollection = Yawei.Domain.Domain.ExecuteSearchResult(domain.GetDirectoryEntry(domain.DistinguishedName), "(&(objectCategory=person)(objectClass=user)(CN=*" + name + "*))", SearchScope.Subtree); json += "{"; json += "\"total\":" + searchResultCollection.Count.ToString() + ",\"rows\":["; for (int i = 0; i < searchResultCollection.Count; i++) { DomainUser user = domain.GetUser(searchResultCollection[i].GetDirectoryEntry().Guid.ToString()); json += "{\"UserGuid\":\"" + user.Guid.ToString() + "\",\"UserDN\":\"" + user.DN + "\",\"UserCN\":\"" + user.CN + "\",\"UserLoginName\":\"" + user.LoginName + "\",\"UserType\":\"AD\"}"; if (i + 1 < searchResultCollection.Count) { json += ","; } } json += "]}"; } else { using (DomainOU domainOU = domain.GetOU(gourp)) { SearchResultCollection searchResultCollection = Yawei.Domain.Domain.ExecuteSearchResult(domainOU, "(&(objectCategory=person)(objectClass=user))", SearchScope.OneLevel);;//Yawei.Domain.Domain.ExecuteSearchResult(domainOU, "(&(objectCategory=person)(objectClass=user))", SearchScope.OneLevel); json += "{"; json += "\"total\":" + searchResultCollection.Count.ToString() + ",\"rows\":["; for (int i = 0; i < searchResultCollection.Count; i++) { DomainUser user = domain.GetUser(searchResultCollection[i].GetDirectoryEntry().Guid.ToString()); json += "{\"UserGuid\":\"" + user.Guid.ToString() + "\",\"UserDN\":\"" + user.DN + "\",\"UserCN\":\"" + user.CN + "\",\"UserLoginName\":\"" + user.LoginName + "\",\"UserType\":\"AD\"}"; if (i + 1 < searchResultCollection.Count) { json += ","; } } json += "]}"; } } return(json); }
private void SetPageData() { switch (model) { case "AD": Yawei.Domain.Domain domain = new Yawei.Domain.Domain(); DomainOU domainOU = domain.GetOU("OU=市直机关,DC=qd,DC=gov,DC=cn"); foreach (SearchResult searchResult in Yawei.Domain.Domain.ExecuteSearchResult(domainOU, "(objectClass=organizationalUnit)", SearchScope.OneLevel)) { ou += "<option value=\"" + searchResult.GetDirectoryEntry().Guid + "\">" + searchResult.GetDirectoryEntry().Name.Replace("OU=", "") + "</option>"; } break; case "DB": Database database = DatabaseFactory.CreateDatabase("SystemPerson"); DataSet doc = database.ExecuteDataSet("select Guid,title from Groups where ouPath='OU=青岛市政府投资项目科技防腐平台,DC=组'"); foreach (DataRow dr in doc.Tables[0].Rows) { ou += "<option value=\"" + dr["Guid"].ToString() + "\">" + dr["title"].ToString() + "</option>"; } break; } }