How to SUM child BO field into parent


Author
Message
Luiz Lima
Luiz Lima
StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)
Group: Forum Members
Posts: 66, Visits: 724
Hi,

I´d like to sum a field value from a Child BO into its parent.
Is there a method to do that automatically?

Example:

BoOrders
field: orderTotalProduct

BoOrdersItens
field: orderItemTotalProduct

While the user input orderItemTotalProduct, the field orderTotalProduct would receive the sum from child (in the EditState set as Adding or Editing).

Tks Wink

Replies
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
No problem Smile Glad it came in handy!
Luiz Lima
Luiz Lima
StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)
Group: Forum Members
Posts: 66, Visits: 724
Trent and Greg,

Tks a lot, but I still have doubts... i´m starter (don´t forget! Smile)

My Parent is: boPedidoCompra1, field to be summarized: pec_valtotal_item (it should be saved into table)
My Child is: boPedidoCompraItens1, total field: itc_total_mercadorias

How will I create a property on Parent boPedidoCompra1 if the pec_valtotal already already exist?
The code would be like below on boPedidoCompra1?

boPedidoCompraItens1.CurrentDataTable.Compute("Sum(itc_total_mercadorias)","");

 (and... where I put it in my code below generated by BOM?)

''' <summary>
''' Valor Total dos Itens
''' </summary>
''' <remarks></remarks>
<Browsable(False), _
BusinessFieldDisplayInEditor(), _
Description(
"Valor Total dos Itens"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public Property [pec_valtotal_item]() As System.Decimal
    Get
        Dim loValue As Object
         loValue = Me.CurrentRow.Item("pec_valtotal_item")
         If loValue Is DBNull.Value Then
            Return Nothing
         Else
           Return CType(loValue, System.Decimal)
         End If
     End Get
     Set(ByVal value As System.Decimal)
        Me.CurrentRow.Item("pec_valtotal_item") = value
    End Set
End Property


Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
If you are saving it into the table, then the Compute method might not be the way to go. That is the way to go if you are going to calculate it when you need it.



If you are saving it to the table, then no custom property needed. It will be added when you map the BO (since there should be a column in the table to hold it). Thus, the saving, retrieving of the value from the table is taken care just like any other column in the table, via the BO.



However, the source of the data is different. Instead of a user filling it in, you need to manage the value of the parent total column, pec_valtotal_item, based on edits to the child items, from the itc_total_mercadorias field. I'm sure there are lots of ways to do this, but here are a few to start (these assume you want to persist the total to the table, as you indicated):



- in the child BO, handle some key events and keep the parent record updated.

- During the process of saving the child BO, call a sproc to keep parent updated.



The issue with the first is that you'd then have to code the UI to keep it fresh. I've worked up a sample that implements the first solution. It uses the StrataFrameSample database. Run the sql script in the SQL folder to update the Orders table to include a total column and initialize it with the correct data.



This sample uses BO property events (Changing and Changed) along with the handling BeforeUndo and AfterUndo events. The basic concept is that the child BO () updates its parent during edits, via these events.



Hope this helps!
Attachments
ChildUpdateParentExample.zip (186 views, 212.00 KB)
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
Thanks for the sample, Greg.
Luiz Lima
Luiz Lima
StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)StrataFrame User (214 reputation)
Group: Forum Members
Posts: 66, Visits: 724
Greg, tks a lot!!!

It was really fantastic, my problem is solved!BigGrin
I´ve implemented some Business Rules events and my fields works automatically.

Trent, some comments:

- I think the SF documentation would have more details about Advanced things, to solve my problem I read the "Dynamic Business Object Events" chapter from help, and with Greg explanations I´ve got it! I´m a SF BeginnerWink.
- Worth doing the SF training for advanced stuffs? (Remeber that I´m not a advanced VB developer).
- Congratulations for SF development, until now I didn´t see nothing like that (I´ve tested a lot of RAD Tools).
- You and your team came from Softvelocity Clarion? Because SF it´s very close of Clarion concepts.

See ya guys!

 

Les Pinter
Les Pinter
StrataFrame Team Member (95 reputation)StrataFrame Team Member (95 reputation)StrataFrame Team Member (95 reputation)StrataFrame Team Member (95 reputation)StrataFrame Team Member (95 reputation)StrataFrame Team Member (95 reputation)StrataFrame Team Member (95 reputation)StrataFrame Team Member (95 reputation)StrataFrame Team Member (95 reputation)
Group: Forum Members
Posts: 43, Visits: 213
Oi Luiz,



Good guess, but StrataFrame evolved not from Clarion, but from FoxPro, which had so many data handling features built in that it made .NET look a little weak. Luckily, Trent decided to fix what was wrong with it, and StrataFrame is the result.



Les
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Glad that sample helped!
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Luiz Lima - 15 Years Ago
Trent L. Taylor - 15 Years Ago
Luiz Lima - 15 Years Ago
Greg McGuffey - 15 Years Ago
                     Luiz,

Greg is correct that it should work. If you have the...
Trent L. Taylor - 15 Years Ago
Edhy Rijo - 15 Years Ago
                         No problem :) Glad it came in handy!
Trent L. Taylor - 15 Years Ago
                             Trent and Greg, Tks a lot, but I still have doubts... i´m starter...
Luiz Lima - 15 Years Ago
                                 If you are saving it into the table, then the Compute method might not...
Greg McGuffey - 15 Years Ago
                                     Thanks for the sample, Greg.
Trent L. Taylor - 15 Years Ago
                                         Greg, tks a lot!!! It was really fantastic, my problem is solved!:D...
Luiz Lima - 15 Years Ago
                                             Oi Luiz,

Good guess, but StrataFrame evolved not from...
Les Pinter - 15 Years Ago
                                             Glad that sample helped!
Greg McGuffey - 15 Years Ago
Luiz Lima - 15 Years Ago
Dustin Taylor - 15 Years Ago
Luiz Lima - 15 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search