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



IsDirty Question?Expand / Collapse
Author
Message
Posted 02/06/2008 8:57:02 AM
StrataFrame Beginner

StrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame Beginner

Group: StrataFrame Users
Last Login: 04/14/2008 7:41:48 AM
Posts: 45, Visits: 102
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!!

Post #14071
Posted 02/06/2008 11:06:01 AM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIP

Group: StrataFrame Users
Last Login: Yesterday @ 7:28:14 PM
Posts: 1,280, Visits: 3,259
This is the normal behavior. It took me a while to wrap my head around it, but what happens is that when you add a new record, the underlying DataTable has a row added to it. That row is marked as dirty (via normal ADO.NET mechanisms). Because DataTables are disconnected, it is hard to tell when, exactly, a row changed from "just added, but no user changes" to "dirty because the user changed something". This is really an ADO.NET thing.

Some other posts on this subject:
some background...
http://forum.strataframe.net/FindPost9401.aspx

about this very issue...
http://forum.strataframe.net/FindPost7177.aspx

I know this doesn't exactly answer your question, but hopefully understanding what's going on will help you start to figure something out.

As to how to know if the user has entered any data, you might look into using property changed events to flag that the user has entered something, then check that flag when the form closes. If they haven't made any changes, you could simply Undo the changes on the BO before closing.

Good luck!
Post #14087
Posted 02/06/2008 11:07:53 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 3:31:03 AM
Posts: 4,586, Visits: 4,569
Greg's references are good...if this doesn't get you going let us know.  Thanks.
Post #14089
Posted 02/06/2008 12:51:18 PM
StrataFrame Beginner

StrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame Beginner

Group: StrataFrame Users
Last Login: 04/14/2008 7:41:48 AM
Posts: 45, Visits: 102
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!! 

 

Post #14099
Posted 02/06/2008 1:00:51 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 3:31:03 AM
Posts: 4,586, Visits: 4,569
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.

Post #14103
« 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 5:46am

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 0.109. 10 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.