Saving of Business object


Author
Message
John Frankewicz
John Frankewicz
StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)
Group: Forum Members
Posts: 36, Visits: 65
It is my understanding that a business object has an underlying ADO-DATABLE as the source of record storage.

I would like to understand what happens when you call the Save method of the Business Object when there are multiple records in the DataTable and there are broken rules for some of the records.

I assume only those records that don't have broken rules are saved or do all the records of the datatable have to be valid for the Business object to be saved?

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
The help documentation has a flow chart that shows the exact save sequence.  I just pulled this image from the help documentation, but for more information read [ Business Layer -> Common Business Object Tasks -> Saving Data ] in the help and this should clear some things up.

When a Save is called, the business rules are checked on each row within the  DataTable.  As the business object checks each row, it raises the CheckRulesOnCurrentRow event (where the business logic resides).  If there is even one broken rule on any row, no data will be saved back to the server until all of the rules have been corrected. 

If the AutoNavigateToFirstBrokenRow property on the business object is set to true, the business object will automatically position itself on the first broken record.

You can access the broken rules one of two ways, first you can use the BrokenRules property:

BrokenRules Example
Dim loRule As MicroFour.StrataFrame.Business.BrokenRule

For Each loRule In Customers.BrokenRules.ToArray()
        '-- Show the rule
        Console.WriteLine(loRule.Description)
Next

The other method is to capture the BusinessRulesChecked event on a business object or a form and use the event arguments passed to that event.

BusinessRulesCheckedEvent Example
Private Sub Customers_BusinessRulesChecked(ByVal e As StrataFrame.Business.BusinessRulesCheckedEventArgs) Handles Customers.BusinessRulesChecked

        '-- Establish Locals
        Dim loBO As MicroFour.StrataFrame.Business.BusinessLayer
        Dim loRule As MicroFour.StrataFrame.Business.BrokenRule

       '-- When captured on a form, there may be more than one business object with broken rules
       '   this is how to cycle through all of the business objects with broken rules

        For Each loBO In e.AllBrokenRules.Keys
            For Each loRule In loBO.BrokenRules.ToArray()
                '-- Show the broken rule
                Console.WriteLine(loRule.Description)
            Next
        Next

    End Sub

You can also determine how many broken rules there are on the current row, all other rows, and an accumulation of all rows using the same event arguments in the BusinessRulesChecked event:

Broken Rules Counters
Private Sub Customers_BusinessRulesChecked(ByVal e As StrataFrame.Business.BusinessRulesCheckedEventArgs) Handles Customers.BusinessRulesChecked

        Console.WriteLine("Broken rules on this row: {0}", e.CountOfBrokenRulesCurrentRow)
        Console.WriteLine("Broken rules on other rows: {0}", e.CountOfBrokenRulesAdditionalRows)
        Console.WriteLine("Broken rules on all rows: {0}", e.CountOfBrokenRulesTotal)

End Sub

You can also force the save and ignore all broken rules.  When this is done, the data will be saved back to the server regardless of the broken rules.

Ignoring Broken Rules
Private Sub Customers_BusinessRulesChecked(ByVal e As StrataFrame.Business.BusinessRulesCheckedEventArgs) Handles Customers.BusinessRulesChecked

        '-- Ignore the broken rules and force the save
        e.IgnoreRulesAndForceSave = True

    End Sub

StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
No, John, when you save, if there are broken rules on any of the rows, none of the rows will save. (Unless of course, you tell it to ignore the broken rules, then everything will save.)
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