Handling Null Dates


Author
Message
Randy Jean
Randy Jean
StrataFrame User (233 reputation)StrataFrame User (233 reputation)StrataFrame User (233 reputation)StrataFrame User (233 reputation)StrataFrame User (233 reputation)StrataFrame User (233 reputation)StrataFrame User (233 reputation)StrataFrame User (233 reputation)StrataFrame User (233 reputation)
Group: StrataFrame Users
Posts: 105, Visits: 641
Been away from this issue for a while - thought I had it figured out before but must have tabled it. Anyway, datetime is the only type in SQL we allow nulls to handle when a date can be empty. So, I've set the bizobj to AllowNullValuesOnNewRow = False but in SetDefaultValues I set:



Me.CurrentRow("ExpirationDate") = DBNull.Value



I'm using the strataframe dt picker control.



So, this all seems to work fine for adding records, etc. The problem comes in that if I navigate from a record that has a date to one that is null OR I navigate from a row with a null to a record with a date the buffer is dirty. If I set a breakpoint in the IsDirtyChanged event I see it is the Set Alternate on Null code causing this:





>BayerAcquire.exe!BayerAcquire.DCAReagentsBO.DCAReagentsBO_IsDirtyChanged(Object sender = {BayerAcquire.DCAReagentsBO}, System.EventArgs e = {System.EventArgs}) Line 124Basic

[External Code]

BayerAcquire.exe!BayerAcquire.DCAReagentsBO.set_ExpirationDate(Date value = #1/1/1800#) Line 306 + 0x42 bytesBasic

BayerAcquire.exe!BayerAcquire.DCAReagentsBO.Field_ExpirationDate_Descriptor.SetValue(Object component = {BayerAcquire.DCAReagentsBO}, Object Value = #1/1/1800#) Line 691 + 0x45 bytesBasic

[External Code]

BayerAcquire.exe!BayerAcquire.AppMain.Main() Line 21 + 0x6 bytesBasic

[External Code]





The partial class code looks like this:





'''

''' ExpirationDate

'''


'''


BusinessFieldDisplayInEditor(), _

Description("ExpirationDate"), _

DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _

Public Property [ExpirationDate]() As System.DateTime

Get

Dim loValue As Object

loValue = Me.CurrentRow.Item("ExpirationDate")

If loValue Is DBNull.Value Then

Return #1/1/1800#

Else

Return CType(loValue, System.DateTime)

End If

End Get

Set(ByVal value As System.DateTime)

Me.CurrentRow.Item("ExpirationDate") = value

End Set

End Property





How do I handle date fields when the date is optional (not required) and I don't want navigation to dirty the buffer? I also don't want to store 1/1/1800 in the DB.
Reply
Randy Jean
Randy Jean
StrataFrame User (233 reputation)StrataFrame User (233 reputation)StrataFrame User (233 reputation)StrataFrame User (233 reputation)StrataFrame User (233 reputation)StrataFrame User (233 reputation)StrataFrame User (233 reputation)StrataFrame User (233 reputation)StrataFrame User (233 reputation)
Group: StrataFrame Users
Posts: 105, Visits: 641
Did this and my buffer is still dirty upon navigation when going from a record with a null to a record with a date or vice versa. If I navigate from null to null or date to date, buffer does not dirty. So, yes, the BO mapper "works" as far as translating the value correctly and nothing "blows up" and data is saved correctly, etc. But if the user did not change the date from null or vice versa why should the buffer be dirty prompting them to save? That's what I'm saying. I don't want this "behavior" or side-effect but the underlying data is being handled properly by the Set Alternate as you describe.



I'd be happy to do host a quick Crossloop (see http://www.crossloop.com) session with you to show you first hand what it's doing. And I also re-produced with the CRM sample customer maintenance so I can show you there as well.



Thanks, Randy
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Randy Jean - 18 Years Ago
Peter Jones - 18 Years Ago
Randy Jean - 18 Years Ago
Trent L. Taylor - 18 Years Ago
Randy Jean - 18 Years Ago
Randy Jean - 18 Years Ago
                         The OnValidation is actually the default for .NET binding... it...
StrataFrame Team - 18 Years Ago
                             Hi Ben,
It's starting to make sense now... I'm still a newbie at...
Randy Jean - 18 Years Ago
                                 Yes, creating an imaginary control to focus would work, but firstly, I...
StrataFrame Team - 18 Years Ago
                                     Works for me! :D

Thanks, Randy
Randy Jean - 18 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search