Hi There,
I am developer whose main experience is VFP and am now moving to VB .Net. This is a great idea and I can see all the benefits, the problem is I have very little idea as to what I am doing. The project at the moment is to redevelop our entire product offering in .Net. A main part of this is clients and addresses and I now need to write a function that returns a clients main electronic address (email, telephone, fax URL, etc). I am planning on writing a function for each EAddress type however so far I have managed to get the appropriate data into a new DataTable, this has only the id of the relevant record and I now need to use this ID to createa a new instance of the Eaddress Object to return to the calling function.
It may be that I am not attempting this in the best way and I am open to any suggestions. Here is the code as it stands.
Public Function GetMainEAddress(ByVal eAddressTypeID As Integer, ByVal personID As Integer, ByVal who As Integer) As EAddress
Any help would be greatly appreciated in my attempt to write this function.
Many thanks
Nathan Davies
I am developer whose main experience is VFP and am now moving to VB .Net. This is a great idea and I can see all the benefits, the problem is I have very little idea as to what I am doing. The project at the moment is to redevelop our entire product offering in .Net. A main part of this is clients and addresses and I now need to write a function that returns a clients main electronic address (email, telephone, fax URL, etc). I am planning on writing a function for each EAddress type however so far I have managed to get the appropriate data into a new DataTable, this has only the id of the relevant record and I now need to use this ID to createa a new instance of the Eaddress Object to return to the calling function.
It may be that I am not attempting this in the best way and I am open to any suggestions. Here is the code as it stands.
Public Function GetMainEAddress(ByVal eAddressTypeID As Integer, ByVal personID As Integer, ByVal who As Integer) As EAddress
Code:
' Parameters explained: eAddressTypeID = The ID from EAddressType to denote the type of EAddress to get. If its 0 then we get all
' nGetType = 1 Get only the main, 2 Get all of this type
' personID = the id for whom to get the eaddress
' who = 1 PersonalDetails, 2 Department, 3 ClientTrust
Dim eAddressTable As New DataTable
Dim sQL As String
Dim MainEmailID As Integer
Select Case who
Case 1 ' Person
sQL = "SELECT eaddress.id from eaddress, personeaddress "
sQL += "where eaddress.id = personeaddress.eaddressid "
sQL += "and personeaddress.ismain = true "
sQL += "and personeaddress.peronaldetailsid = personID "
sQL += "and personeaddress.eaddresstypeid = eAddressTypeID"
Case 2 ' Department
sQL = "SELECT eaddress.id from eaddress, departmenteaddress "
sQL += "where eaddress.id = departmenteaddress.eaddressid "
sQL += "and departmenteaddress.ismain = true "
sQL += "and departmeneaddress.departmenid = personID "
sQL += "and departmenteaddress.eaddresstypeid = eAddressTypeID"
Case 3 ' Trust
sQL = "SELECT eaddress.id from eaddress, trusteaddress "
sQL += "where eaddress.id = trusteaddress.eaddressid "
sQL += "and trusteaddress.ismain = true "
sQL += "and trusteaddress.clientTrustID = personID "
sQL += "and clienteaddress.eaddresstypeid = eAddressTypeID"
Case Else
Throw New ConstraintException("Illegal Model Manipulation")
End Select
DataBase.TableFill(sQL, eAddressTable)
If eAddressTable.Rows.Count = 0 Then
Throw New ConstraintException("Illegal E-Address Definition")
End If
' TODO Get the resultant table into the required object
' Create a new instance of EAddress based on the retreived ID
Return CType(Factory.Get_Model(GetType(EAddress), 0, Me.RetrievalMethod), EAddress)
End Function
Many thanks
Nathan Davies