I have a ROB object that checks for the existence of any Drawing objects having a particular drawingCode; it returns a bool based on whether or not any such objects exist. Additionally, I have a DrawingTypes collection of DrawingType objects. If the call to my ROB shows a DrawingType is referenced by my collection of Drawings, I want to disallow deletion of the DrawingType. I'd originally thought of using a CommandObject similar to what Rocky describes in chapter 8 until I read his response to a question someone else posed at http://forums.lhotka.net/forums/thread/3261.aspx. Anyway, since this isn't something the UI should access, I have it declared as a protected method within my DrawingExists class. My question is: where should I place the call to it? Should it be in my DrawingTypes DataPortal_Update method? Or should it be in my DrawingType's internal DeleteSelf method?
I put calls like this in my ValidationRules code.
I also set the priority to 1 so that all the level 0 rules must first be passed (length<>0, length <10, etc.) before the rules that hit the DB run.
In the case of a Delete I would probaly have the call in DeleteSelf and then branch accordingly.
You probably have to throw an Exception as there is no Return value from a Delete. You know the Delete succeeded if there is no Exception. Catch it and then present a friendly message to the user:
"Caanot delete drawing type as child drawings exist."
Joe
Copyright (c) Marimer LLC