How to create a broken rule not property related

How to create a broken rule not property related

Old forum URL: forums.lhotka.net/forums/t/1589.aspx


Tommybouy posted on Wednesday, October 25, 2006

In our old app we used to have an mdi parent that would open a root object form. From that form you could open a child form and because they were both mdi children you couldn't go modal on the child form. To ensure that the root object form wasn't closed while a child form was open we would simply apply a broke rule to the root like this; mobject.m_valid.RuleBroken("Child form needs to be closed!", True). Once the form was closed we would remove the rule.

This seemed to work great but with the new release of CSLA it seems all rules are associated to a property of the object. How do people handle the opening of a child form and not allow the parent to be closed or is there a way to do what we used to do - add a broken rule when the child form is opened.

On a side note, I have searched for details on VB subclassing of the baseobjects and most examples are in C#. Is there a link to examples or detailed discussions anywhere about VB subclassing.

Thanks

Tom

ajj3085 replied on Wednesday, October 25, 2006

You shouldn't be using business rules in this way.  What you should do is open the child window, and set the window with the root object's Enable to false.

The rule that the root window cannot be closed is not a business rule, that's a ui constraint; for example, this wouldn't work at all in the web world.

Tommybouy replied on Wednesday, October 25, 2006

Thanks for your reply ajj3085.

We handled it this way because a parent object that has say 3 different child collections could very well have 3 different child forms open. Adding a rule for each then gave the user a visual description of why the parent can't be closed, specifically the names of all of the open child forms. Our users in many cases have muliple child forms open at the same today.

I suppose this issue is win form specfic as you couldn't do this in a web UI.

ajj3085 replied on Wednesday, October 25, 2006

You could disable the saving / closing of the form if it knows one of the child windows is open. 

Track via booleans in the parent window which child windows are open.  Handle the Closing event on the parent form, and if any of these are true, cancel the close.  You can also add a textual lable somewhere that appears to tell the user why the window was not closed.


JoeFallon1 replied on Wednesday, October 25, 2006

"VB subclassing of the baseobjects "

I know I posted some VB samples for BusinessBase and BusinessListBase.

 

<Serializable()> _
  Public MustInherit Class MyBusinessBase(Of T As MyBusinessBase(Of T))
    Inherits BusinessBase(Of T)

 

<Serializable()> _
  Public MustInherit Class MyBusinessListBase(Of T As MyBusinessListBase(Of T, C), C As IBusinessObject)
    Inherits BusinessListBase(Of T, C)

Note: C As IBusinessObject can be changed to whatever you need it to be - some other Interface or ...

Joe

 

 

 

 

Copyright (c) Marimer LLC