A simple SmartDate example #4190
Replies: 1 comment 4 replies
-
I can provide a common use case from our product, where we use effective dates and expiration dates. Within the business class:
Business rules enforce a proper range, require the effective date, and only allow editing the effective date when the object is new:
For the WinForms UI, I cannot post code because our custom logic is proprietary. In general, our approach is a custom text box control and data binding. The text box control has a custom event handler for the Parse event of the binding. The event handler uses a custom date parsing function, which returns a struct. If the struct indicates there was an error, the Parse returns without assigning a parsed value. Effectively, a bad date value does not get passed to the business object at all. The custom date parsing function is also used with non-UI scenarios, such as JSON input via an automation API. Errors are handled like any other field that has bad data. You mentioned that you don't use data binding? If not, then you must have code that is passing the value from the input control to the business object. That is where you should inject a parsing function and you'll have to decide what you want to do to notify the user. We use .NET's built-in Date.TryParse() function. That works with many date formats. It doesn't work for dates entered like yyyyMMdd, MMddyyyy, or MMddyy which we find common with automation scenarios. Our parsing function uses the built-in Date.TryParseExact() function to handle that potential input. As I view this business function, this isn't really a CSLA-specific issue. This is a UI-specific problem, and CSLA tries to be UI-agnostic. Hopefully this semi-detailed information is helpful. |
Beta Was this translation helpful? Give feedback.
-
I would like to see a simple SmartDate example. We have some older applications that don't use databinding.
It would be great if we could write some simple validation rules for SmartDate e.g. one for required and the other for valid formats.
It would be easier to show the users if the date was missing or invalid format.
@rockfordlhotka I know you are busy but whenever you get some downtime.
Kind Regards
Beta Was this translation helpful? Give feedback.
All reactions