I have a form with parent child objects, both objects have required fields defined. I noticed an issue when a user has broken rules in the child and and parent, and clicks Save button, the children controls lose all the changes as though they get refilled.
After digging around and setting a few breakpoints, I found out that calling .Save or .CheckRules on parent BO causes Navigated even to fire (which executes my code to fill children BOs).
Is this by design? Is there a property I can set to prevent this?
Thank you.
Take a look at the StrataFlix to see how this is handled by the SF team with more details.
Basically you have to check the rules in the Child Form before returning to the parent form. Here is a sample code I use in all my child forms:
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click '-- This code uses' the form's PrimaryBusiness Object instance to check the validations. If Me.PrimaryBusinessObject.CheckRules(True) Then DialogResult = Windows.Forms.DialogResult.OK Else '-- Show a custom InfoBox to alert the end user of the broken rules. Dim CountOfBrokenRulesCurrentRow As Integer = Me.PrimaryBusinessObject.BrokenRules.Count Dim CountOfBrokenRulesAdditionalRows As Integer = 0 Dim CountOfBrokenRulesTotal As Integer = Me.PrimaryBusinessObject.BrokenRules.Count MicroFour.StrataFrame.Messaging.InfoBox.ErrorBox(MicroFour.StrataFrame.UI.Localization.RetrieveTextValue(Me.BrokenRulesAlertTitleKey, Me.BrokenRulesAlertTitle), String.Format(MicroFour.StrataFrame.UI.Localization.RetrieveTextValue(Me.BrokenRulesAlertTextKey, Me.BrokenRulesAlertText), CountOfBrokenRulesCurrentRow, CountOfBrokenRulesAdditionalRows, CountOfBrokenRulesTotal), Me) End IfEnd Sub Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click DialogResult = Windows.Forms.DialogResult.CancelEnd Sub
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
'-- This code uses' the form's PrimaryBusiness Object instance to check the validations.
If Me.PrimaryBusinessObject.CheckRules(True) Then
DialogResult = Windows.Forms.DialogResult.OK
Else
'-- Show a custom InfoBox to alert the end user of the broken rules.
Dim CountOfBrokenRulesCurrentRow As Integer = Me.PrimaryBusinessObject.BrokenRules.Count
Dim CountOfBrokenRulesAdditionalRows As Integer = 0
Dim CountOfBrokenRulesTotal As Integer = Me.PrimaryBusinessObject.BrokenRules.Count
MicroFour.StrataFrame.Messaging.InfoBox.ErrorBox(MicroFour.StrataFrame.UI.Localization.RetrieveTextValue(Me.BrokenRulesAlertTitleKey, Me.BrokenRulesAlertTitle), String.Format(MicroFour.StrataFrame.UI.Localization.RetrieveTextValue(Me.BrokenRulesAlertTextKey, Me.BrokenRulesAlertText), CountOfBrokenRulesCurrentRow, CountOfBrokenRulesAdditionalRows, CountOfBrokenRulesTotal), Me)
End If
End Sub
DialogResult = Windows.Forms.DialogResult.Cancel
As you can see, the code is petty generic, so I can simply copy/paste in every child form I need. Also, I added code to show the InfoBox effect you see when using the Form's Save().
If you do not want to move a child record, etc. then you can go at this several ways. First, apply a filter to the BO in question so that only the current record is checked. Second, create a shared property someplace so that the logic in your navigated event doesn't get fired...there are a number of ways to go at this one.
I would recommend this anyway as it will cut out unnecessary server data operations.