IsDirty Question?


Author
Message
fansanitis
fansanitis
StrataFrame Novice (63 reputation)StrataFrame Novice (63 reputation)StrataFrame Novice (63 reputation)StrataFrame Novice (63 reputation)StrataFrame Novice (63 reputation)StrataFrame Novice (63 reputation)StrataFrame Novice (63 reputation)StrataFrame Novice (63 reputation)StrataFrame Novice (63 reputation)
Group: Forum Members
Posts: 45, Visits: 103
Whenever I do a BO.Add() to my business object the IsDirty flag is being turned on even though no bound UI controls have been changed.  I'm not sure but I believe its because I have several fields in the BO that have Custom Field Properties set.  The underlying table does NOT allow nulls on any field but the user is not required to enter all fields.  So for the fields that are not required I set the Null Value Option and Null Replacement value as follows:

Strings: Return Alternate On Null/Set Null On Alternate(reference type) -- String.Empty

Integers: Return Alternate On Null/Set Null On Alternate(value type) -- 0

DateTime: Return Alternate On Null/Set Null On Alternate(reference type) -- #1/1/1800#

The getting/setting of the values works fine but is that what is causing the BO to be flagged as dirty when a new record is added?  If so, how do I get around this problem?  I have a simple data entry app that clears the BO on each successful BO.Save and then adds a new record using BO.Add.  When the user closes the app, they're always prompted with the "Save Changes" message dialog since the BO is flagged as dirty.

Thanks!!

Replies
fansanitis
fansanitis
StrataFrame Novice (63 reputation)StrataFrame Novice (63 reputation)StrataFrame Novice (63 reputation)StrataFrame Novice (63 reputation)StrataFrame Novice (63 reputation)StrataFrame Novice (63 reputation)StrataFrame Novice (63 reputation)StrataFrame Novice (63 reputation)StrataFrame Novice (63 reputation)
Group: Forum Members
Posts: 45, Visits: 103
I added a Evaluations.CurrentDataTable.AcceptChanges() statement immediately after each Evaluations.Add() to accept the changes to the table but not the database.  This gaves me Original datavalues that I can compare to the Current datavalues to see if anything has changed.

Here's some code I placed in the FormClosing event:

Dim ix As Integer = Evaluations.CurrentDataTable.Columns.Count

Dim isDirty As Boolean

For ix = 0 To Evaluations.CurrentDataTable.Columns.Count - 1

   If Evaluations.CurrentRow.Item(ix, Data.DataRowVersion.Original) <>

      Evaluations.CurrentRow.Item(ix, Data.DataRowVersion.Current) Then

         isDirty = True

         Exit For

   End If

Next

If isDirty Then

   Dim dlgResult As DialogResult

   dlgResult = MessageBox.Show("Do you want to save changes?", My.Application.Info.Title, _  

      MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button3)

        Select Case dlgResult

          Case Windows.Forms.DialogResult.Cancel

             e.Cancel = True

          Case Windows.Forms.DialogResult.Yes

             If Evaluations.Save() <> MicroFour.StrataFrame.Data.SaveUndoResult.Success Then

                 e.Cancel = True

             End If

          Case Windows.Forms.DialogResult.No

             '--Do nothing

       End Select

This seems to work but is this a proper way of getting what I need or am I opening myself up for future problems?

Thanks!! 

 


Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
This seems to work but is this a proper way of getting what I need or am I opening myself up for future problems?

No, I think you are good. Smile

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search