How to check Business Rules from a parent BO into a Child BO


Author
Message
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
I have a Parent BO and a Child BO (using a Chikd Dialog) . I am at  the point where I want to save the Parent and the child out to the Database and want to check the rules first. So I have code like:

if (this.ParentBO1.CheckRules(true) && this.childBO1.CheckRules(true) )
{
this.childBo1.Save();
this.parentBO1.Save();
MessageBox.Show("Document has been saved", "Kernel Software",MessageBoxButtons.OK, MessageBoxIcon.Information);
}


All works fine. But I want to put validation code into the Parent Business object which will be dependent on what's in the child buisness object. e.g. Particular Customers (on the Parent Bo)  can only purchase certain Products (on the child BO). So at the stage I am validating the Parent BO, I need to loop through the Child BO .  I would like to put this valididation code into the CheckRulesOnCurrentRow on the parent BO but am not clear on how I will access the Child Business Object on the Parent Business Object. ( It cant really be done from the ChildBO because the Customer could be changed after a whole pile of products have been added ).
Replies
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Gerard,

Since you are using a ChildForm dialog, the StrataFlix application has a way to handle this in the ChildForm itself.

Basically in the child form, you check for the childbo rules and if OK, then return OK, otherwise show a message to the user to fix the problem before exiting the child form, I do this all the time and works just fine, here is sample VB code for the cmdOK button:

 Private Sub cmdOK_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles cmdOK.Click
        Dim validationResult As Windows.Forms.DialogResult
        With Me.BizTransactionItems1
            '-- If the record has been changed, then validate the transaction
            If .IsDirty Then
                '-- If the Start Sequence is greater than zero, then validate the sequence is valid
                '   otherwise, validation will show an error message and wait for the correct sequence
                If .CardStartSerialNumber > 0 Then
                    If Me.ValidateCardRecordData() Then
                        validationResult = Windows.Forms.DialogResult.OK
                    End If
                Else
                    validationResult = Windows.Forms.DialogResult.OK
                End If

            Else
                ' --  No data has been changed, so just exit the form as if the user press the Cancel button.
                validationResult = Windows.Forms.DialogResult.Cancel
            End If

            If validationResult = Windows.Forms.DialogResult.OK Then
                    '-- Make sure these fields are updated if they are empty.
                    If String.IsNullOrEmpty(.QBCustomerRefID) OrElse String.IsNullOrEmpty(.QBInvoiceNumber) Then
                        .QBCustomerRefID = Me.BizTransaction1.QB_CustomerRefID
                        .QBInvoiceNumber = Me.BizTransaction1.QB_InvoiceNumber
                    End If
            End If
        End With

        Me.DialogResult = validationResult
    End Sub


In the above example I have a method ValidateCardRecordData() that will display a message if something is not valid.

Edhy Rijo

Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Edhy.

Just checking the ChildBo will not be sufficient in my case (Unless I can do it from the ParentBO).

Say my 'Logical'  Business Rules stipulate that Customer 'A' is allowed Products 'X' and 'Y', and Customer 'B' is only allowed Proucts 'Z'.    Customer A is input on the Parent BO..passes all validation. Products X and Y are input on the Child BO...pass all validation and focus passes back to the parent Form . Everything ok so far...........

Now , the customer is changed , on the parent form,  from Cusrtomer 'A'  to Customer 'B' . This now should not pass validation as Customer 'B' is only allowed product 'Z',   ... but at this stage products 'X'  and 'Y' have been entered on the Child BO.

What I am trying to do,  is set up , on the Business Object , the Business Rule that Customer 'B' is only allowed Product 'Z'. My issue is how do I do this from within a Business Object, i.e. set up a Business Rule on say a Parent BO which will also require access to another BO (the child).

The scenario above is just one example, but the same would apply where 'Rules' will cross Business Objects.  Another example would be where a date is entered on the Parent Business Object which might control what Product Discounts ara llowed. Initially , when the lines are being entered on the child, they will pass validation, but the problem may arise if the date is subsequently changed on the Parent, causing the child rules then to be broken
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