SmartDate - A great Asset

SmartDate - A great Asset

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


Jav posted on Tuesday, June 07, 2011

I have been using SmartDate since Csla 1.0 and I have found it to be a great asset.  With the latest version I had to struggle a little bit but now finally have it doing whatever I need.

My main property preserves the fileld as a Csla.SmartDate. 

        public static PropertyInfo<SmartDate> BirthdateProperty =
 RegisterProperty(new PropertyInfo<SmartDate>("Birthdate", "Birthdate", new SmartDate(SmartDate.EmptyValue.MinDate)));
        public SmartDate Birthdate
        {
            get { return GetProperty(BirthdateProperty); }
            set { SetProperty(BirthdateProperty, value); }
        }

This allows me to use all of the functionality like, Birthdate.Date, BirthDate.Add, or Subtract, BirthDate.ToDateTimeOffset() etc.

Then I have a second property. I Got this from the CodeSmith Templates which add the following for DataBinding:

        public string BirthdateString
        {
            get { return GetPropertyConvert<SmartDate, string>(BirthdateProperty); }
            set { SetPropertyConvert(BirthdateProperty, value);}
        }

But in this form the property does not work correctly for DataBinding. The following modification appears to take care of that.

        public string BirthdateString
        {
            get { return GetPropertyConvert<SmartDate, string>(BirthdateProperty); }
            set { SetPropertyConvert<SmartDate, string>(BirthdateProperty, value);  OnPropertyChanged("BirthdateString"); }
        }

As a computer user I find the easiest way to enter a date is without any slashes or dashes : 09232011.  This does mandate that the string is exactly 8 digits and the format be mmddyyyy.  In the Property Set, I call one of my methods to basically check the value and then insert a couple of slashes.  So instead of value it is FormatDate(value)

If one keeps the primary Property as SmartDate, I believe there is nothing that you cannot do with your data in terms date math etc.

Jav

Copyright (c) Marimer LLC