如何根据员工下拉列表的值填充经理下拉列表?

时间:2022-11-06 02:56:13

Right now, I am trying to come up with 2 DropDownLists, one employee DropDownListand the other, manager DropDownList.

现在,我正在尝试提出2个DropDownLists,一个员工DropDownList,另一个是经理DropDownList。

First, I am not familiar with how Active Directory works but having done some research, I did find something like the code below which as I understand, represents Manager definition:

首先,我不熟悉Active Directory的工作原理但是做了一些研究,我确实找到了类似下面的代码,据我所知,它代表了Manager的定义:

   Dim deEmployee As New DirectoryEntry("LDAP://CN=John Employee,OU=Sales,DC=Corp,DC=com")

   deEmployee.[Property]("manager") = "CN=Peter Manager,OU=Sales,DC=Corp,DC=com"
   deEmployee.CommitChanges()

Since there are several manageers, I can hard code the name as done above = CN=Peter Manager.

由于有几个管理员,我可以硬编码上面的名称= CN = Peter Manager。

What group represents manager in Active Directory that I can use instead of CN=Peter Manager?

哪个组代表Active Directory中的管理员,而不是CN = Peter Manager?

The bigger issue for me though is if I select employee from the first DropDownList, how does it populate the second DropDownListwith the manager of that employee?

对我来说更大的问题是,如果我从第一个DropDownList中选择员工,它如何用该员工的经理填充第二个DropDownList?

From what I undersand, department is the attribute that relates employee to manager but how do I use this in code?

从我的内容来看,部门是将员工与经理联系起来的属性,但我如何在代码中使用它?

In normal cascading dropdownlist, I can select employee and list the department the employee belongs to in the first dropdownlist and in the second dropdownlist, I can select manager where department = theDepartmentListed in first dropdownlist.

在正常的级联下拉列表中,我可以在第一个下拉列表中选择员工并列出员工所属的部门,在第二个下拉列表中,我可以在第一个下拉列表中选择manager = theDepartmentListed中的manager。

That's querying the database but in my case, we are querying the Active Directory.

那是在查询数据库,但就我而言,我们正在查询Active Directory。

Can someone please show how to link the relationship between employee in first DropDownListand manager in the second DropDownList based on department?

有人可以说明如何链接第一个DropDownList中的员工与基于部门的第二个DropDownList中的经理之间的关系?

1 个解决方案

#1


1  

There isn't a built-in group for managers in AD, the only way you would be able to query them straight out of a group or OU is if your organisation has added one.

AD中没有内置的管理员组,只有您的组织添加了一个组,才能直接从组或OU中查询它们。

There is no automatic linking of employees to managers, so you would have to query the department and select the correct user as the manager.

员工与经理之间没有自动链接,因此您必须查询部门并选择正确的用户作为经理。

You will need to write a query that gets all users in a department except for the selected user, something like this should work:

您将需要编写一个查询来获取除所选用户之外的部门中的所有用户,这样的事情应该起作用:

Imports System.DirectoryServices

...

Protected Sub EmployeeChanged(sender as object, e as EventArgs) Handles ddlEmployees.SelectedIndexChanged

    Dim selectedUser as new DirectoryEntry(ddlEmployees.SelectedValue) 'assuming your Value on the empoyees dropdown is the LDAP object path
    Dim domainRoot as new DirectoryEntry("LDAP://DC=corp,DC=com")
    Dim searcher as new DirectorySearcher()
    searcher.SearchRoot = domainRoot 
    searcher.Filter = "(&(objectClass=user)(department=" & selectedUser.Properties("department").Value & "))"

    Dim results as SearchResultCollection = searcher.FindAll()

    For Each result as SearchResult in results

        Dim de as DirectoryEntry = result.GetDirectoryEntry()

        If de IsNot Nothing Then

            If Not de.Properties("samaccountname").Value.ToString().ToLower() = selectedUser.Properties("samaccountname").Value.ToString().ToLower() Then

                ddlManagers.Items.Add(de.Properties("displayName").Value.ToString(), de.Properties("distinguishedName").Value.ToString())

            End If

        End If

    Next

End Sub

For more information on writing LDAP queries: http://technet.microsoft.com/en-us/library/aa996205(v=exchg.65).aspx

有关编写LDAP查询的更多信息,请访问:http://technet.microsoft.com/en-us/library/aa996205(v = exchg.65).aspx

#1


1  

There isn't a built-in group for managers in AD, the only way you would be able to query them straight out of a group or OU is if your organisation has added one.

AD中没有内置的管理员组,只有您的组织添加了一个组,才能直接从组或OU中查询它们。

There is no automatic linking of employees to managers, so you would have to query the department and select the correct user as the manager.

员工与经理之间没有自动链接,因此您必须查询部门并选择正确的用户作为经理。

You will need to write a query that gets all users in a department except for the selected user, something like this should work:

您将需要编写一个查询来获取除所选用户之外的部门中的所有用户,这样的事情应该起作用:

Imports System.DirectoryServices

...

Protected Sub EmployeeChanged(sender as object, e as EventArgs) Handles ddlEmployees.SelectedIndexChanged

    Dim selectedUser as new DirectoryEntry(ddlEmployees.SelectedValue) 'assuming your Value on the empoyees dropdown is the LDAP object path
    Dim domainRoot as new DirectoryEntry("LDAP://DC=corp,DC=com")
    Dim searcher as new DirectorySearcher()
    searcher.SearchRoot = domainRoot 
    searcher.Filter = "(&(objectClass=user)(department=" & selectedUser.Properties("department").Value & "))"

    Dim results as SearchResultCollection = searcher.FindAll()

    For Each result as SearchResult in results

        Dim de as DirectoryEntry = result.GetDirectoryEntry()

        If de IsNot Nothing Then

            If Not de.Properties("samaccountname").Value.ToString().ToLower() = selectedUser.Properties("samaccountname").Value.ToString().ToLower() Then

                ddlManagers.Items.Add(de.Properties("displayName").Value.ToString(), de.Properties("distinguishedName").Value.ToString())

            End If

        End If

    Next

End Sub

For more information on writing LDAP queries: http://technet.microsoft.com/en-us/library/aa996205(v=exchg.65).aspx

有关编写LDAP查询的更多信息,请访问:http://technet.microsoft.com/en-us/library/aa996205(v = exchg.65).aspx