Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Event handling in business objects
Message
From
25/06/2008 16:23:55
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
25/06/2008 14:43:45
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01326692
Message ID:
01326757
Views:
17
>Hi Tim,
>
>Thanks for the reply. I was not really concerned about forcing child objects to delete. Rather I am looking for the appropriate way to pass a delete not allowed message from the business object up to the UI layer.
>
>The following is a code snippet from my current project:
>
>/// <summary>
>/// Summary description for SQLTracGrp.
>/// </summary>
>public partial class SQLTracGrp
>{
>      .......
>
>      protected override bool HookPreDeleteEntity(SQLTracGrpEntity entity)
>      {
>
>            bool bReturn = base.HookPreDeleteEntity(entity);
>
>            if (bReturn)
>            {
>                // check to see if this type is used by a group or resource
>                string sCommand = "[dbo].[sp_SQLTrac_CanDeleteGrp]";
>
>                if ((int)this.ExecSprocScalar(sCommand, this.CreateParameter("@GrpID", (object)entity.GrpID, DbType.Int16)) == 0 )
>                {
>                    bReturn = false;
>                }
>
>
>
>            }
>
>            return bReturn;
>        }
>
>}
>
>As per the documentation, this code gets called by DeleteEnity() prior to the business object attempting to delete the record. If the stored procedures finds a FK reference to this record in the subordinate records, HookPreDeleteEntity() returns false and the delete is canceled.
>
>I would like to be able to fire an event to send a message to the UI when this happens. Of course I can add my own event to the business object
>
>
>protected override bool HookPreDeleteEntity(SQLTracGrpEntity entity)
>      {
>
>            bool bReturn = base.HookPreDeleteEntity(entity);
>
>            if (bReturn)
>            {
>                // check to see if this type is used by a group or resource
>                string sCommand = "[dbo].[sp_SQLTrac_CanDeleteGrp]";
>
>                if ((int)this.ExecSprocScalar(sCommand, this.CreateParameter("@GrpID", (object)entity.GrpID, DbType.Int16)) == 0 )
>                {
>
>                   this.OnDeleteFKBlock(); // fires a custom event handler
>                    bReturn = false;
>                }
>
>
>
>            }
>
>            return bReturn;
>        }
>
>
>But if there is already a better way built into the framework, why re-invent the wheel?
>

Ok, I see what you are talking about. I am curious is this code in a business object class? Are you calling this from a form? The form has a delete method also that ultimately calls the delete of the business object and it does raise the StateChange event with a "deleting" argument. However I don't see any place where this would lead to broken rules being set based on a FK constraint violation. I wonder if calling the Delete of the form would be better and then checking/ adding a broken rule in the HookPreDelete of the business object. Maybe Kevin can provide some insight.
Tim
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform