If ds.HasChanges Then
Dim oDA As New PRDAL.DataAccess(AppInfo.ConnectionString, True) ' The True parameter tells the DAL to use a Transaction
Dim iPatient_ID As Integer
' Check for changes to Patients
If Not ds.Patients.GetChanges(DataRowState.Added) Is Nothing Then
iPatient_ID = oDA.Inserts.InsertPatient(ds.Patients.GetChanges(DataRowState.Added))
If iPatient_ID = 0 Then
GoTo RollBackAndExit
End If
End If
If Not ds.Patients.GetChanges(DataRowState.Modified) Is Nothing Then
If oDA.Updates.UpdatePatient(ds.Patients.GetChanges(DataRowState.Modified)) Then
iPatient_ID = ds.Patients(0)("Patient_ID")
Else
GoTo RollBackAndExit
End If
End If
' There is no insert or update
If iPatient_ID = 0 Then
iPatient_ID = ds.Patients(0)("Patient_ID")
End If
If Not ProcessContacts(ds.Contacts, iPatient_ID, oDA) Then GoTo RollBackAndExit
If Not ProcessContactTelephones(ds.Telephones, oDA) Then GoTo RollBackAndExit
oDA.Transaction.Commit()
Return True
RollBackAndExit:
oDA.Transaction.Rollback()
Return False