StrataFrame Forum

ChildForm with child BO and Broken Rules....

http://forum.strataframe.net/Topic16065.aspx

By Edhy Rijo - 5/1/2008

Hi,

I have a ListView which calls a ChildForm with a child BO which I would like to control the saving and broken rules on the childform.  I have the following code in the Save button of my ChildForm:

Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click

     If Me.PolicyBO1.Save() = MicroFour.StrataFrame.Data.SaveUndoResult.Success Then

          Me.DialogResult = Windows.Forms.DialogResult.OK

     Else

          Me.PolicyBO1.Undo(MicroFour.StrataFrame.Business.BusinessUndoType.CurrentRowOnly)

          Me.DialogResult = Windows.Forms.DialogResult.Cancel

     End If

End Sub

The problem is that the broken rules are not shown in the form and the form is released, but in the parent form the childbo state is Editing.

How can I accomplish having control on the ChildForm to Save/Undo the data and when returning to the Parent Form not worrying about the childBO state?

By Trent L. Taylor - 5/1/2008

You are generally always better of only saving records from a single location...for example, the parent form.  But in any case, you could do this to check the rules:

If MyBo.CheckRules(True) Then
    DialogResult = OK
End If

Then on the Parent form you will look to see what the results of the Dialog were and take appropriate action.  If you are using the ListView then handle the ChildFormResults event, but if you are calling the ChildFormDialog directly, the logic would be the same, but just be wrapped around the ShowDialog.

If MyChildDialog.ShowDialog() = OK Then
    '-- Reload the list view, for example
    lstMyList.Requery()
Else
    '-- Undo the changes
    MyChildBo.Undo(CurrentRowOnly)
End If

It would look something like that.

By Edhy Rijo - 5/1/2008

Trent L. Taylor (05/01/2008)
You are generally always better of only saving records from a single location...for example, the parent form.

In this case, the Parent form will manage 1 child BO and this will manage another child BO and this another one. That is the reason I prefer to manage the save in each ChildForm.

I tried MyBo.CheckRules(True) and it worked but it did not show the Infobox, then I found another message in the forum suggesting to use the form's Save() http://forum.strataframe.net/Topic6212-6-1.aspx so I endup with the code below which so far give me the functionality I want when calling the ChildForm via the new enhanced ListView:

If Me.Save() <> MicroFour.StrataFrame.Data.SaveUndoResult.Success Then

     Exit Sub

ElseIf Me.Save() = MicroFour.StrataFrame.Data.SaveUndoResult.Success Then

     Me.DialogResult = Windows.Forms.DialogResult.OK

Else

     Me.PolicyBO1.Undo(MicroFour.StrataFrame.Business.BusinessUndoType.CurrentRowOnly)

     Me.DialogResult = Windows.Forms.DialogResult.Cancel

End If

Thanks for your recommendations!