StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Strataframe Datetime picker control and null...Expand / Collapse
Author
Message
Posted 03/30/2008 6:46:10 PM
StrataFrame Beginner

StrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame Beginner

Group: StrataFrame Users
Last Login: 08/02/2008 6:38:23 AM
Posts: 37, Visits: 107
I have spent quite a bit of time reviewing the forums and need to know what you suggest with Strataframe on this issue.

The SQL Database has datetime columns that do allow null values. I do not want them to reflect 1/1/1800 or 1/1/1900. I want them to reflect NULL if they are null.

My question is what settings need to be made in the BO Mapping as well as the datetime picker control to make this work.

I am using c#.

Post #15245
Posted 03/31/2008 8:59:04 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 5:02:56 PM
Posts: 2,682, Visits: 1,882
You'll want to make sure the values in the database are NULL for starters.  Then, you can use the BOMapper to customize the field(s) that are dates.  When you customize the field, there is a selection of Null Value Options that you can choose from.  You'll want the one that says Return Alternat on Null / Set Null on Alternate (value type).  Then, put

new DateTime(1800, 1, 1)

in for the replacement value.  When you access that field on the business object, it will return 1-1-1800 when the value in the database is Null and when you set the property to 1-1-1800, it will set the database to Null.  Set the corresponding properties on the DateTimePicker, too, and it will display blank when the value is 1-1-1800.

There are lots of creative ways to handle Null dates in .NET because of the fact that a date is a value type, not a reference type.  You could use the Nullable<DateTime> generic (DateTime?), or you could google it and find some solutions like CSLA's SmartDate class that handles it in a unique way.


www.bungie.net
Post #15254
Posted 03/31/2008 9:41:23 AM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: 07/29/2008 5:46:38 PM
Posts: 147, Visits: 516
Hey Ross

Set the column to nothing in the BO Mapper. Then drop a datetimepicker on the form, add a checkbox to it nd in the edit button click you can use something like the code below. Then you users will be able to null the field out if they want to. It looks pretty cool too.

I am using the Infragistics control but the SF control should work the same.

Michael

**********

    Private Sub txtDateOfBirth_EditorButtonClick1(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinEditors.EditorButtonEventArgs) Handles txtDateOfBirth.EditorButtonClick
        Dim stateButton As StateEditorButton = CType(e.Button, StateEditorButton)

        If (stateButton.Checked) Then
            e.Button.Editor.Value = Nothing
        Else
            e.Button.Editor.Value = DateTime.Today
        End If
    End Sub

Post #15260
Posted 04/01/2008 8:49:54 AM
StrataFrame Beginner

StrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame Beginner

Group: StrataFrame Users
Last Login: 08/02/2008 6:38:23 AM
Posts: 37, Visits: 107
BEN, I did what you indicated and it does work except when I use the DEL key to delete the date I get the error:

NullReferenceException
  Object reference not set to an instance of an object.

Source     : MicroFour StrataFrame UI

Stack Trace:
   at MicroFour.StrataFrame.UI.Windows.Forms.DateTimePicker.CreateManualCaret()
   at MicroFour.StrataFrame.UI.Windows.Forms.DateTimePicker.OnGotFocus(EventArgs e)
   at System.Windows.Forms.Control.WmSetFocus(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.DateTimePicker.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
   at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

It appears about 3 times and then does blank out the date. Do you know why?

Post #15270
Posted 04/01/2008 8:58:13 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 4:17:19 AM
Posts: 4,379, Visits: 4,420
You need to set a custom format to make the error go away.  This is actually not an issue but by design when wanting to have the overall NULL support since we extend the capabilities of the underlying DateTimePicker.  You can have the DateTimePicker show any date or date/time combination that you want, but you need to use a CustomFormat.  The reason for this is because we have added a lot of functionality to the DateTimePicker for the NULL support as well as caret support when in a NULL state, etc.  So if you are going to use NULLs, then you need to use a custom format.
  1. Set the Format property to Custom
  2. Set the CustomFormat property to the desired date display format.  You can get more details on this in the .NET documentation, but if you want to use a 04/01/2008 format, then it would look like this MM/dd/yyyy
Post #15271
Posted 04/01/2008 9:11:10 AM
StrataFrame Beginner

StrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame Beginner

Group: StrataFrame Users
Last Login: 08/02/2008 6:38:23 AM
Posts: 37, Visits: 107
Thanks... worked like a charm in case anyone else needs to know.
Post #15275
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 6:26pm

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 0.078. 11 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.