Design Question

Design Question

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


mr_lasseter posted on Monday, March 19, 2007

I want to get some opinions on the best way to do things.  I have circuit which is an (BusinessBase).  It contains a list (BusinessListBase) of drop locations (BusinessBase).  Depending on some of the values of the circuit, the validation rules for the drops can be different.  Some configurations only allow 1 drop and some allow 2 while other configurations can allow up to 10.  Depending on these configurations some of the drops are required to be populated.  My question is what is the best way to go about getting the number of drops allowed from the circuit?

 

Thanks is advance. 

RockfordLhotka replied on Monday, March 19, 2007

It somewhat depends on the user experience you are after.

You could allow the addition of n drops, and have CircuitEdit (your root) become invalid if there are too many.

Or you could disallow the addition of n+1 drops in DropLocations by throwing an exception when the max is exceeded - though that could get messy depending on your UI style.

Or you could add the n+1 item and have that item never become valid. But it is hard to see how you could do that without frustrating the user.

I'd think you'd want to go with the first option, plus have a way for the UI to know the max value so it could give the user visual cues that they can't add another.

So in CircuitEdit you could expose a read-only property: MaxDrops. This could be used by both CircuitEdit and the UI to know the max possible.

Then in CircuitEdit you'd have a read-only property: CurrentDrops. This property would have a validation rule associated with it to ensure it didn't exceed the value of MaxDrops.

You'd handle the ListChanged event from DropLocations and call CheckRules("CurrentDrops") when the collection is changed.

If you don't want to show CurrentDrops, you can put a Label control with size 0,0 on your form, and the ErrorProvider will still show the "!" icon at that location - giving you a way to easily show the user the nature of the issue.

Copyright (c) Marimer LLC