Related to using BeforeDelete EventThe delete confirmation is handled by the SF form (BaseForm actually). This can be turned off at the form level (so no SF delete conformation is used). See
http://forum.strataframe.net/FindPost11030.aspx for some more info.
I believe the events would be raised:
- OnBeforeDelete of BusinessLayer raises BeforeDelete event of the BO
- The BaseForm (which the SF StandardForm inherits from, which you form inherits from) handles this event, does the delete confirmation and raises form's BeforeDelete event.
- Any handlers you have added to the BeforeDelete event get fired (like the one you posted)...so confirmation has already happened at this point.
- Any handlers of the form's BeforeDelete event fires.
I think another option to have more control over this would be to handle it in a sub-class of BusinessLayer, then override the OnBeforeDelete method. The you have control over when the BusinessLayer raises the events in the first place. You could also add you own event that could fire when the child records aren't already deleted, then handle that event to provide the message.
MessageBox not working form within a BOI know of no reason why you couldn't use MessageBox within a BO....it's just a class like any other (including Form classes). You might want to verify that the code is ever called by stepping through it.
Referential Integerity and Cascading DeletesI also usually use referential integrity with cascading deletes. To setup this, you would setup the building address table to have a Foreign Key to the customers table with ON DELETE CASCADE set. This enforces that no building addresses can be added that don't have valid customers and that when a customer is deleted, any associated building addresses are deleted as well.
When the db is setup this way, then I usually turn off the auto confirmation of delete messages for the form and provide my own, so I can remind the user that any building addresses will be deleted as well (JC's idea of presenting how many would be deleted is a nice touch). This type of setup has a couple of advantages:
- it ensures that the db doesn't have any data in it...period
- it is simpler to implement (setup FK on table, override delete message)
- typically faster, as the db handles checking referential integrity and the cascading deletes very fast
Hope that helps!