| | | StrataFrame 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!! |
| | | | StrataFrame VIP
       
Group: StrataFrame Users Last Login: Yesterday @ 7:28:28 PM Posts: 1,148, Visits: 2,830 |
| 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! |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Today @ 11:13:06 AM Posts: 4,104, Visits: 4,176 |
| Greg's references are good...if this doesn't get you going let us know. Thanks. |
| | | | StrataFrame 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.CountDim isDirty As BooleanFor 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 IfNextIf 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 SelectThis seems to work but is this a proper way of getting what I need or am I opening myself up for future problems? Thanks!! |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Today @ 11:13:06 AM Posts: 4,104, Visits: 4,176 |
| 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.  |
| |
|
|