EditLevel mismatch

EditLevel mismatch

Old forum URL: forums.lhotka.net/forums/t/4116.aspx


culprit posted on Thursday, January 03, 2008

I continue to get these EditLevel mismatches for a quite complex object I have. I am using the saving method from the 3.0 project. Do you have to do anything in the Save routing for readonly children? Currently I am not. Currently I have a parent and 7 children/grandchildren which I am unbinding (etc..) during the save operation.

I am probably missing something simple here.

Here is my Rebind/Save procedure:

Private Function RebindUI(ByVal Save As Boolean, ByVal Rebind As Boolean) As Boolean Implements RSSoftware.ScriptAssist.ObjectEdit.RebindUI

' disable events

Me.PrescriptionBindingSource.RaiseListChangedEvents = False

Me.IngredientsBindingSource.RaiseListChangedEvents = False

Me.OtherPayersBindingSource.RaiseListChangedEvents = False

Me.RejectCodesBindingSource.RaiseListChangedEvents = False

Me.AmountsPaidBindingSource.RaiseListChangedEvents = False

Me.DURCodesBindingSource.RaiseListChangedEvents = False

Me.DiagnosesBindingSource.RaiseListChangedEvents = False

Try

' unbind the UI

ScriptAssist.Utilities.UnbindBindingSource(Me.IngredientsBindingSource, Save, False)

ScriptAssist.Utilities.UnbindBindingSource(Me.OtherPayersBindingSource, Save, False)

ScriptAssist.Utilities.UnbindBindingSource(Me.RejectCodesBindingSource, Save, False)

ScriptAssist.Utilities.UnbindBindingSource(Me.AmountsPaidBindingSource, Save, False)

ScriptAssist.Utilities.UnbindBindingSource(Me.DURCodesBindingSource, Save, False)

ScriptAssist.Utilities.UnbindBindingSource(Me.DiagnosesBindingSource, Save, False)

ScriptAssist.Utilities.UnbindBindingSource(Me.PrescriptionBindingSource, Save, True)

Me.IngredientsBindingSource.DataSource = Me.PrescriptionBindingSource

Me.OtherPayersBindingSource.DataSource = Me.PrescriptionBindingSource

Me.RejectCodesBindingSource.DataSource = Me.PrescriptionBindingSource

Me.AmountsPaidBindingSource.DataSource = Me.PrescriptionBindingSource

Me.DURCodesBindingSource.DataSource = Me.PrescriptionBindingSource

Me.DiagnosesBindingSource.DataSource = Me.PrescriptionBindingSource

' save or cancel changes

If Save Then

CurrentRX.ApplyEdit()

Try

Dim temp As ScriptAssist.Prescription = CurrentRX.Clone()

CurrentRX = temp.Save()

Catch ex As Csla.DataPortalException When TypeOf ex.BusinessException Is SqlClient.SqlException

If CType(ex.BusinessException, SqlClient.SqlException).Class = 16 Then

'Most likely due to concurrency error - recommend closing drug and reopening

MessageBox.Show("This record has been changed in another window either on this machine or " _

& Microsoft.VisualBasic.ControlChars.CrLf & "on another client machine while this record was open. Click OK, make a note" _

& Microsoft.VisualBasic.ControlChars.CrLf & "of any changes you have made here you wish saved for this record, close this" _

& Microsoft.VisualBasic.ControlChars.CrLf & "window, the reopen this record in a new window and make the desired changes " _

& Microsoft.VisualBasic.ControlChars.CrLf & "finally saving the record.", "CONCURRENCY ERROR", MessageBoxButtons.OK, MessageBoxIcon.Stop)

Else

MessageBox.Show(ex.BusinessException.ToString, _

"Error saving", MessageBoxButtons.OK, _

MessageBoxIcon.Exclamation)

End If

Catch ex As Csla.DataPortalException

MessageBox.Show(ex.BusinessException.ToString, _

"Error saving", MessageBoxButtons.OK, _

MessageBoxIcon.Exclamation)

Catch ex As Csla.Validation.ValidationException

Dim sMsg As New System.Text.StringBuilder("One or more fields have failed validation. Refer to any errors")

sMsg.AppendLine(" on this form and the following list: ")

sMsg.AppendLine()

For Each BrokenRule As Csla.Validation.BrokenRule In CurrentRX.BrokenRulesCollection

sMsg.AppendLine(" " & BrokenRule.Description)

Next

MessageBox.Show(sMsg.ToString, "VALIDATION ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

Catch ex As Exception

MessageBox.Show(ex.ToString, _

"Error saving", MessageBoxButtons.OK, _

MessageBoxIcon.Exclamation)

End Try

Else

CurrentRX.CancelEdit()

End If

Finally

' rebind UI if requested

If Rebind Then

BindUI()

End If

' restore events

Me.PrescriptionBindingSource.RaiseListChangedEvents = True

Me.IngredientsBindingSource.RaiseListChangedEvents = True

Me.OtherPayersBindingSource.RaiseListChangedEvents = True

Me.RejectCodesBindingSource.RaiseListChangedEvents = True

Me.AmountsPaidBindingSource.RaiseListChangedEvents = True

Me.DURCodesBindingSource.RaiseListChangedEvents = True

Me.DiagnosesBindingSource.RaiseListChangedEvents = True

If Rebind Then

' refresh the UI if rebinding

Me.PrescriptionBindingSource.ResetBindings(False)

Me.IngredientsBindingSource.ResetBindings(False)

Me.OtherPayersBindingSource.ResetBindings(False)

Me.RejectCodesBindingSource.ResetBindings(False)

Me.AmountsPaidBindingSource.ResetBindings(False)

Me.DURCodesBindingSource.ResetBindings(False)

Me.DiagnosesBindingSource.ResetBindings(False)

End If

End Try

If CurrentRX.IsDirty = False And CurrentRX.IsValid = True Then

Return True

Else

Return False

End If

End Function

Thanks,

Rob

Copyright (c) Marimer LLC