NON-CSLA Programming Question

NON-CSLA Programming Question

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


wjcomeaux posted on Friday, January 16, 2009

You guys come up with some of the best designs I've seen so here goes.

We are implementing a process that I am designing with a state manager. At any time a merchant can be in some state regarding credit processing (Accepted, ReadyForProcessing, Cancelled, SwitchingProcessors, etc).

We are building the business objects with CSLA and that all works well, however we want the GUI programmer to have access to only a single interface called something like ICreditProcessor

The state manager would return the proper (current) state as an ICreditProcessor instance and then raise an event that the GUI hears and appropriately refreshes the binding for values, editability and visibility..

For databinding the only way we have come up with would be for ICreditProcessor to allow things like IsMerchantNameEditable, IsMerchantNameVisible, IsSICCodeEditable, IsSICCodeVisible, etc for everything we'd want to bind to.

We thought about a dictionary<string, bool> where string is the property name and then we databind to something like EditableFieldDictionary["MerchantName"]. But that won't work.

Neither will databinding to a function like
IsPropertyEditable("MerchantName") that in turns searches the dictionary or performs some business logic.

So, how would you guys approach this?

Thanks,
Will

rfcdejong replied on Saturday, January 17, 2009

It depends which GUI u are using, if it's WPF then the required code will be less. Let the GUI programmer search for "Style.Triggers" combined with WPF databinding.

wjcomeaux replied on Monday, January 19, 2009

Straight up windows forms and/or ASP.NET. we haven't evolved into WPF users here yet =)

JonnyBee replied on Tuesday, January 20, 2009

You could use the ReadWriteAuthorizationProvider to help you with this.

Ovveride the CanReadProperty (similiar to Is<propertyname>Visible) and CanWriteProperty(similar to Is<propertyname>Editable) in your BO's.

The RWAM will extend the usual edit controls (not the DataGridView) and hence set:
- ReadOnly or Enabled if not CanWriteProperty
- Blank (or actually type.Default) in not CanReadProperty.

In DataBindingSorce.CurrentItemChanged event (is called whenever CurrentChanged or a property is changed) you could just add :
- RWAM.ResetControlAuthorization();

You will get a new property on each control (this is an Extender Control) like "Apply authorization on RWAM1" -  that must be set to true for the controls that the RWAM should control the above mentioned properties for.

Or you could adapt your own version of the RWAM - tailored to suit your needs.

/jonny


Copyright (c) Marimer LLC