StrataFrame Forum

Aggregate on a Custom Property

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

By Bill Cunnien - 5/30/2008

I did some preliminary searches in these forums and I have hit the docs, but I am not coming up with a way to perform an aggregate on a custom property.  Can anyone point me in the right direction?

Here is an example...I have a BO called InvoiceMasterBO.  The BO has a custom property called 'grandtotal' which summarizes the finance info on each invoice.  I need to send a batch of these invoices to the accounting system.  For a double check and a requirement of the accounting system, I need to export the SUM(grandtotal), too.  How do I do that?

This is probably so obvious that I will kick myself as soon as I find out how to do it.

Thanks,
Bill

By Trent L. Taylor - 5/30/2008

This kinda feels like atrick question....since you are using a custom property, you can do anything that you want....cycle through the rows in the BO, execute another query, pull from a sproc...you can do anything that you want at this point, so I guess I don't really know how to answer this post.  Smile
By Bill Cunnien - 5/30/2008


This kinda feels like atrick question....

BigGrin

Naw...just the Friday-I-Want-To-Get-Out-Of-The-Office-Mentality!  I . . . must . . . stay . . . focused . . .

Ok...here is the answer that I came up with to the trick question--I put this in the InvoiceMasterBO:

public decimal GetBatchTotal(String pBatchID)
{
   
InvoiceMasterBO mInvoiceBatch = new InvoiceMasterBO();
    mInvoiceBatch.FillByBatchID(pBatchID);
   
decimal mGrandTotal = 0;
   
if (mInvoiceBatch.MoveFirst())
    {
       
do
       
{
            mGrandTotal += mInvoiceBatch.grandtotal;
        }
       
while (mInvoiceBatch.MoveNext());
    }
   
return mGrandTotal;
}

Whaddya think?
Bill

By Bill Cunnien - 5/30/2008

Do I even need a sub-reference to the same BO?  I am over-thinking this stuff sometimes.  Could I do this, instead?

public decimal GetBatchTotal()
{
   
decimal mGrandTotal = 0;
   
if (this.MoveFirst())
    {
       
do
       
{
            mGrandTotal +=
this.grandtotal;
        }
       
while (this.MoveNext());
    }
   
return mGrandTotal;
}

A little cleaner...less filling...even greener...

Hehe

By Ivan George Borges - 5/30/2008

Hey Bill.

This is not really about your question, but rather the way you are moving through your BO rows. Have a look at this post from Trent:

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

By Bill Cunnien - 5/30/2008

Cool...so I could do this, then:

public decimal GetBatchTotal()
{
   
decimal mGrandTotal = 0;
   
foreach (InvoiceMasterBO mBO in this.GetEnumerable())
    {
        mGrandTotal +=
this.grandtotal;
    }
   
return mGrandTotal;
}

Lean and mean! Smile

By Bill Cunnien - 5/30/2008

Oops!  Blink

mGrandTotal += mBO.grandtotal;

By Trent L. Taylor - 5/30/2008

I just scanned over your code and didn't really digest it...but from the looks of it you have it going, so let me know if you are still having issues.