?
Solved

Continuing discussion on generating names from ID

Posted on 2012-08-20
10
Medium Priority
?
149 Views
Last Modified: 2013-01-29
Continuing from http://www.experts-exchange.com/Programming/Q_27818531.html
I need to display the employee name, rather than their ID, in my edit view.
0
Comment
Question by:sirbounty
  • 5
  • 3
9 Comments
 
LVL 12

Expert Comment

by:CmdoProg2
ID: 38312967
Lets start with a method of retreiving the name from empID.  Do you have a function that retrieves the name from a LDAP Query?
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38313223
Well, I was in the process of moving that to its own external class, but I think I goofed on that.

The class is listed here, but I don't currenlty reference it within the Edit.aspx code...not sure where to place it.  Do you need me to post that code as well?
Imports System.DirectoryServices

Public Class EngineerInfo
    Public FirstName As String
    Public LastName As String
    Public MainPhone As String
    Public EmployeeID As String
    Public Email As String

    Public Sub RetrieveID(EngName As String)
        FirstName = EngName.Split(" ")(0)
        LastName = EngName.Split(" ")(1)
        Using de As New DirectoryEntry("LDAP://dc=xxxxxx,dc=com")
            Using ds As New DirectorySearcher
                With ds
                    .PageSize = 15000
                    .SearchScope = SearchScope.Subtree
                    .PropertiesToLoad.AddRange({"cn", "telephonenumber", "mail"})
                    .Filter = "(&(objectCategory=person)(objectClass=user)(sn=" & LastName & ")(givenName=" & FirstName & "))"
                End With

                Try
                    Dim sr As SearchResult = ds.FindOne
                       EmployeeID = sr.Properties("cn")(0).ToString
                       MainPhone = sr.Properties("telephonenumber")(0).ToString
                       Email = sr.Properties("mail")(0).ToString
                Catch ex As Exception
                    Debug.Print(ex.Message)
                End Try
            End Using
        End Using
    End Sub
End Class

Open in new window

0
 
LVL 12

Expert Comment

by:CmdoProg2
ID: 38320159
You 'll need the intramediate class (EmployeeFetch) for your objectdatasources.  The objectdatasources will replace the sqldatasources on the edit page. (see previous question about the dataset.)  I'll be in and out for the next couple of weeks.
Public Class EmployeeInfo
....
  Public Shared Function GetName(ByVal EmpID As String) As String
      'not tested...
       Using de As New DirectoryEntry("LDAP://dc=xxxxxx,dc=com")
            Using ds As New DirectorySearcher
                With ds
                    .PageSize = 15000
                    .SearchScope = SearchScope.Subtree
                    .PropertiesToLoad.AddRange({"sn", "givenName"})
                    .Filter = "(&(objectCategory=person)(objectClass=user)(cn=" & EmpID  & "))"
                End With

                Try
                    Dim sr As SearchResult = ds.FindOne
                    return sr.Properties("cn")(0).ToString + ' ' + sr.Properties("givenName")(0).ToString
                Catch ex As Exception
                    Debug.Print(ex.Message)
                End Try
            End Using
        End Using

  End Function
End Class

'New Class
<System.ComponentModel.DataObject(True)> Public Class EmployeeFetch
 
  Public Function FetchEmployees() As MyDataSet.EmployeesDataTable
    Dim dtRslt As MyDataSet.EmployeesDataTable
    Using ta As New MyDataSetTableAdapters.EmployeesTableAdapter()
      dtRslt = ta.GetData()
    End Using
    For Each dr As MyDataSet.EmployeesRow In dtRslt
      dr.EmployeeName = EmployeeInfo.GetName(dr.EmpID)
    Next
    Return dtRslt
  End Function

  Public Function FetchEngineers() As MyDataSet.EngineersDataTable
    Dim dtRslt As MyDataSet.EngineersDataTable
    Using ta As New MyDataSetTableAdapters.EngineersTableAdapter()
      dtRslt = ta.GetData()
    End Using
    For Each dr As MyDataSet.EngineersRow In dtRslt
      dr.EngineerName = EmployeeInfo.GetName(dr.EmpID)
    Next
    Return dtRslt
  End Function
End Class
......In Edit.aspx...
             <asp:DropDownList ID="DropDownList1" runat="server" 
                    DataSourceID="odsEngPData" DataTextField="EmplyeeName" 
                    DataValueField="EmpID" SelectedValue='<%# Eval("P") %> '>
                </asp:DropDownList>
...
 <asp:ObjectDataSource ID="odsEngPData" runat="server" SelectMethod="FetchEmployees" TypeName="EmployeeData"></asp:ObjectDataSource> 

Open in new window

0
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 
LVL 67

Author Comment

by:sirbounty
ID: 38336377
Not sure how I missed this notification...sorry about that.  I'll try to test it out shortly...
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38367592
Ok, I've spent some time trying to go through this and the last question to understand what's being accomplished, but I'm afraid I think it's still a bit over my head. :(

I've tried pasting the code into my EmployeeInfo class, but there's a lot of squigglies, most all of them on the MyDataSet, so I think I've somehow overlooked how that was created.  I don't currently have any datasets, but suspect that would need to be added to my Edit page?  I don't have any data adapters there either - each data source is laid out like:
....
  DataSourceID="SqlOnCallData" 
  DataKeyNames="StartDate,EndDate"
....

Open in new window


....
  DataSourceID="SqlQEngineers" 
  DataTextField="EmployeeID" 
  DataValueField="EmployeeID" 
....

Open in new window


  DataSourceID="SqlPEngineers" 
  DataTextField="EmployeeID" 
  DataValueField="EmployeeID"

Open in new window


Does this mean I need to approach it a different way on my Edit page, or can we use what's already setup there?
0
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 38821405
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
0
 
LVL 12

Accepted Solution

by:
CmdoProg2 earned 2000 total points
ID: 38806581
Sorry SirBounty,
  I was sent to a code bootcamp and thought we had finished.   I do not object if this is deleted.

The DatasourceIDs should be pointing to the objectdatasources, not the sqldatasources.  Remember the SQL process is done on the dataset.  The EmployeeFetch class calls the dataset and the LDAP query.  Your page call the class as an objectdatasource.
0
 
LVL 67

Author Comment

by:sirbounty
ID: 38821407
I think it was put in the auto delete bucket.  I'd still like to pursue this - been out of town myself, but would like to re-examine your comment when I'm next at work.

Thanks for the followup.
0
 
LVL 67

Author Closing Comment

by:sirbounty
ID: 38830646
Alas I think I've gotten too far removed from this.  I do appreciate your efforts though.
Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question