>>>Hi,
>>>
>>>I may have asked this before, my apologies if I have, but I can't work out how to do this.
>>>
>>>I have a Receipt BO and a ReceiptDetails BO which is a child of the Receipt BO. For data entry validation, the user has to enter a total amount received at the Receipt BO level and then the sum of the amounts entered at the Receipt Detail BO level must equal the Receipt BO's total amount received.
>>>
>>>How should I approach writing such a Business Rule?
>>>
>>>I guess it should be at the Receipt BO level, but how would I refer to the child BO to sum all the amounts?
>>Frank,
>>In your Receipt BO Rules method, create a ReceiptDetail BO, call the method to sum the details and check that amount against the amount in the Receipt BO.
>
>Linda,
>
>but at the point in time when the Receipt BO is being saved, the Receipt Detail would not yet have been saved, so I need to sum what is currently in memory, not what is stored in the database. Or am I thinking too hard about this?
Sorry. What you probably need to do is use a foreach statement to cycle through the rows in the detail dataset and sum the amounts.
int detailSum = 0;
foreach(DataRow dr in oReceiptDetail.GetCurrentDataSet().Tables[oReceiptDetail.TableName].Rows)
{
detailSum += dr["DetailAmount"];
}
If it's in a grid, you can also use "foreach(DataGridViewRow dgvr in this.grdReceiptDetail.Rows)".
Is this closer to what you need?
Linda Harmes
HiBit Technologies, Inc.