Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
BusinessRules between different BOs
Message
De
05/10/2010 13:30:34
 
 
À
30/09/2010 15:02:14
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01483404
Message ID:
01484011
Vues:
52
This message has been marked as the solution to the initial question of the thread.
>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?

I spent some time with Josh this morning looking at why the gridview is not showing the error icon (see my other thread on that) and asked him how he would approach this. Here's what he came up with:

In my ReceiptDetailRules.Partial.cs I created a method:
        public string CheckReceiptTotal(Decimal? ReceiptAmount, DataSet dsReceiptDetails)
        {
            string message = null;
            Decimal sumAmountReceived = 0;
            foreach (DataRow Row in dsReceiptDetails.Tables["ReceiptDetails"].Rows)
            {
                sumAmountReceived += (Decimal)Row["AmountReceived"];
            }
            if (sumAmountReceived != ReceiptAmount)
            {
                message = "The sum of the Split Amount values does not match Total Amount Received";
                AddErrorProviderBrokenRule("AmountReceived", message);
            }
            return message;
        }
In ReceiptDetail.Partial.cs I added a new property:
public Decimal ParentReceivedTotal = 0;
and created this hook override which sets the property when saving to the value entered on the Parent BO:

Update: changed HookParentSaving to HookParentPreSaving as this fires before the child gets saved whereas the HookParentSaving fires after the child has been saved
        protected override void HookParentPreSaving(mmBusinessObject bizObj, mmBusinessStateChangeEventArgs e)
        {
            Receipt oParent = bizObj as Receipt;

            ParentReceivedTotal = oParent.Entity.ReceiptAmount;
            base.HookParentSaving(bizObj, e);
        }
Then in ReceiptDetailRules.cs I added this code to the CheckRulesHook just prior to the return statement:
            if (this.ErrorProviderBrokenRuleCount == 0 && entityList.Count > 0)
            {
                ReceiptDetail oReceiptDetail = (ReceiptDetail)this.HostObject;
                ReceiptDetailEntity oReceiptDetailEntity = entityList[0] as ReceiptDetailEntity;
                this.CheckReceiptTotal(oReceiptDetail.ParentReceivedTotal, oReceiptDetailEntity.GetDataRow().Table.DataSet);
            }
I hope this helps someone else.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform