Why Does .Save .CheckRules causes Navigated event to fire


Author
Message
Leonard P.
Leonard P.
StrataFrame Novice (83 reputation)StrataFrame Novice (83 reputation)StrataFrame Novice (83 reputation)StrataFrame Novice (83 reputation)StrataFrame Novice (83 reputation)StrataFrame Novice (83 reputation)StrataFrame Novice (83 reputation)StrataFrame Novice (83 reputation)StrataFrame Novice (83 reputation)
Group: Awaiting Activation
Posts: 65, Visits: 306
Hi,

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.

Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Leonard,

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 If

End Sub

 

Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click

     DialogResult = Windows.Forms.DialogResult.Cancel

End Sub

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().

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Edhy's suggestion is a good one...but this is by design and correct.  You can set a shared property someplace if you want to take certain considerations into affect when checking rules.  But when a rule is checked, all rows within the BO are evaluated.  This will enforce a navigation so any child logic can take place as well since the CheckRulesOnCurrentRow event will be raised and the strong-typed properties evaluated.

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.

Aaron Young
Aaron Young
StrataFrame User (439 reputation)StrataFrame User (439 reputation)StrataFrame User (439 reputation)StrataFrame User (439 reputation)StrataFrame User (439 reputation)StrataFrame User (439 reputation)StrataFrame User (439 reputation)StrataFrame User (439 reputation)StrataFrame User (439 reputation)
Group: StrataFrame Users
Posts: 277, Visits: 1.1K
Sounds like your biggest problem here is the overhead in filling your child BOs. I would also recommend putting a check in your fill code so that you only do the fill when the parent has changed. Check the parent's primary key against the child's foreign key and if they are the same there is probably no need to run the fill. When you move to a different parent record, the keys will not match and the fill will be triggered.

I would recommend this anyway as it will cut out unnecessary server data operations.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search