Private Delegate Sub InsertUpdateData(ByRef inDataTable As DataTable, ByRef inTrans As System.Data.SqlClient.SqlTransaction)
Private Sub SaveData
Dim myDelegate As InsertUpdateData
' Check for Additions to Contacts
myDelegate = AddressOf iData.InsertContact
Call CheckForAdditionsAndPost(ds.ContactsL1.GetChanges(DataRowState.Added), myTrans, iPatient_ID, myDelegate)
Call CheckForAdditionsAndPost(ds.ContactsR1.GetChanges(DataRowState.Added), myTrans, iPatient_ID, myDelegate)
Call CheckForAdditionsAndPost(ds.ContactsL2.GetChanges(DataRowState.Added), myTrans, iPatient_ID, myDelegate)
Call CheckForAdditionsAndPost(ds.ContactsR2.GetChanges(DataRowState.Added), myTrans, iPatient_ID, myDelegate)
' Check for Updates to Contacts
myDelegate = AddressOf uData.UpdateContact
Call CheckForUpdatesAndPost(ds.ContactsL1.GetChanges(DataRowState.Modified), myTrans, iPatient_ID, myDelegate)
Call CheckForUpdatesAndPost(ds.ContactsR1.GetChanges(DataRowState.Modified), myTrans, iPatient_ID, myDelegate)
Call CheckForUpdatesAndPost(ds.ContactsL2.GetChanges(DataRowState.Modified), myTrans, iPatient_ID, myDelegate)
Call CheckForUpdatesAndPost(ds.ContactsR2.GetChanges(DataRowState.Modified), myTrans, iPatient_ID, myDelegate)
End Sub
Private Sub CheckForAdditionsAndPost(ByRef inDataTable As DataTable, ByRef inTrans As System.Data.SqlClient.SqlTransaction, ByRef inPatient_ID As Int32, ByRef inDelegate As InsertUpdateData)
If Not inDataTable Is Nothing Then
Dim dr As DataRow
' Set the Patient_ID for each row in the Insert
For Each dr In inDataTable.Rows
dr("Patient_ID") = inPatient_ID
Next
BindingContext(inDataTable).EndCurrentEdit()
inDelegate.Invoke(inDataTable, inTrans)
End If
End Sub
Private Sub CheckForUpdatesAndPost(ByRef inDataTable As DataTable, ByRef inTrans As System.Data.SqlClient.SqlTransaction, ByRef inDelegate As InsertUpdateData)
If Not inDataTable Is Nothing Then
inDelegate.Invoke(inDataTable, inTrans)
End If
End Sub