Sub UpdateCreateCustomer(ByVal patient As patient)
'get the customer number if it exists
'otherwise, get a new one
Dim strCustomerNumber As String
Dim bSuccess As Boolean = False
Try
'get the server and database from the config
Dim strServer As String = System.Configuration.ConfigurationManager.AppSettings("SQLServer")
Dim strDatabase As String = System.Configuration.ConfigurationManager.AppSettings("Database")
Dim oDT As DataTable = SPs.FP_RM00101EXT_INSSEL(New Guid(patient.PatientID)).getTable
If oDT.Rows.Count = 0 Then
Throw New Exception("Unable to get a customer number")
End If
strCustomerNumber = oDT.Rows(0)("CUSTNMBR")
'update the customer
'create the objects that we'll need
Dim oeConnectType As New Microsoft.Dynamics.GP.eConnect.Serialization.eConnectType
Dim oRMCustomerMasterType As New Microsoft.Dynamics.GP.eConnect.Serialization.RMCustomerMasterType
Dim otaUpdateCreateCustomerRcd As New Microsoft.Dynamics.GP.eConnect.Serialization.taUpdateCreateCustomerRcd
'this is our common eConnect class, it can be found on the KB menu under eConnect
Dim oeConnectFunctions As New eConnectFunctions(strServer, strDatabase)
With otaUpdateCreateCustomerRcd
.CUSTNMBR = strCustomerNumber
.HOLD = 0
.CUSTNAME = patient.FirstName & patient.LastName
.CUSTCLAS = "DEFAULT"
.ADRSCODE = "PRIMARY"
.CNTCPRSN = ""
.ADDRESS1 = patient.Street1
.ADDRESS2 = patient.Street2
.CITY = patient.City
.STATE = patient.State
.ZIPCODE = patient.Zip
.COUNTRY = ""
.PHNUMBR1 = patient.Phone
.FAX = ""
.PRSTADCD = "PRIMARY"
End With
oRMCustomerMasterType.taUpdateCreateCustomerRcd = otaUpdateCreateCustomerRcd
ReDim Preserve oeConnectType.RMCustomerMasterType(0)
oeConnectType.RMCustomerMasterType(0) = oRMCustomerMasterType
bSuccess = oeConnectFunctions.CreateEntity(oeConnectType)
Catch ex As Exception
Throw ex
End Try
End Sub