Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Event handling in business objects
Message
From
25/06/2008 14:43:45
 
 
To
25/06/2008 14:23:56
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01326692
Message ID:
01326723
Views:
9
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?

Best regards,

Tim
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform