Strange Problem when checking business rules
 
Home My Account Forum Try It! Buy It!
About Contact Us Site Map
StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Strange Problem when checking business rulesExpand / Collapse
Author
Message
Posted 02/19/2008 9:03:40 AM
StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: StrataFrame Users
Last Login: 03/03/2008 1:40:52 PM
Posts: 72, Visits: 235
I've been fighting this and I know it must be something I'm doing, but I can't seem to figure out what's causing it. I have a business object that has several date fields. Some of the date fields indicate a start date and an end date.

In the business object's CheckRulesOnCurrentRow event, I have a rule that makes sure the start date doesn't occur after the end date. When I save a record, it correctly makes this check and saves the data if I get it right the first time. If I set the start date after the end date, it adds a broken rule and lets the user correct the problem.

I set the start date earlier, and save. I get the same message and the bound control is reset to the same later value. I keep making the change and it always switches back to the old value. The only thing I can do is click my cancel button to undo everything and start from scratch.

So far, I've tried...

... checking my code and I don't have a RejectChanges() or Refresh() call anywhere in the save process. The Undo() is only called from the Undo/Cancel process.

... Adding this.BrokenRules.Clear() to the beginning of the CheckBusinessRulesOnCurrentRow event for the business object.

Anything else I might try? Any ideas?
Post #14427
Posted 02/19/2008 10:59:59 AM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIP

Group: StrataFrame Users
Last Login: 2 days ago @ 3:11:51 PM
Posts: 1,148, Visits: 2,831
Are you using a DateTimePicker? If so, you might try a TextBox (for test) and see if the problem still occurs.
Post #14429
Posted 02/19/2008 11:01:35 AM
StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: StrataFrame Users
Last Login: 03/03/2008 1:40:52 PM
Posts: 72, Visits: 235
Ok. Now I'm really confused. I've got it to work, but I don't understand why this is working and my original method wasn't. Here's the original code snippet I was using on my save button's click event (cmdSave_Click).

if (PurchaseOrderSchedules.EditingState != BusinessEditingState.Idle)
{
SaveUndoResult loSaveResult = SaveUndoResult.Cancelled;

try
{
//TODO: Fix problem with locking user into form after picking invalid dates
// Handle calculated fields
decimal loResult = 0;

// Percent Cut to date
loResult =
(((Decimal)PurchaseOrderSchedules.QTY_CUT_TOD_UNT
/ (Decimal)PurchaseOrders.QTY_PO_TOT_LT) * 100);
PurchaseOrderSchedules.PCT_CUT_UNT = loResult;

// Percent Stitched to date
loResult =
(((Decimal)PurchaseOrderSchedules.QTY_STC_TOT_UNT
/ (Decimal)PurchaseOrders.QTY_PO_TOT_LT) * 100);
PurchaseOrderSchedules.PCT_STC_UNT = loResult;

// Percent Assembled to date
loResult =
(((Decimal)PurchaseOrderSchedules.QTY_ASM_TOT_UNT
/ (Decimal)PurchaseOrders.QTY_PO_TOT_LT) * 100);
PurchaseOrderSchedules.PCT_ASM_UNT = loResult;

// Try saving the changes
loSaveResult = PurchaseOrderSchedules.Save();
#region Unsuccessful Save
if (loSaveResult == SaveUndoResult.AbortedWithBrokenRules)
{
// Broken business rules. Tell the user which ones and let them
// change their input.
lbError.Visible = true;
lbError.Text = this.GenerateWarningTable(
Global.CreateErrorLabelContents(PurchaseOrderSchedules.BrokenRules),
Global.Config["ImageUri"]
);
}
else if (loSaveResult != SaveUndoResult.Success)
{
// Something else happened, have the user contact the help desk
lbError.Visible = true;
lbError.Text = this.GenerateWarningTable(
"An error has occurred while saving the schedule" + Environment.NewLine +
"information. Please send an e-mail to" + Environment.NewLine +
"CustomCoders@payless.com" +
"
if you continue to experience this " + Environment.NewLine +
"problem.",
Global.Config["ImageUri"]
);
}
#endregion
}
#region Exceptions
catch (BusinessLayerException blex)
{
this.HandleException(blex);
}
catch (ThreadAbortException tex)
{
// do nothing
}
catch (Exception ex)
{
this.HandleException(ex);
}
#endregion

if (loSaveResult == SaveUndoResult.Success)
{
// Enable what should be enabled
lbError.Visible = false;
EnableButtonSaveCancel(false);
EnableDatePickers(false);
EnableToolbar(true);

try
{
// Connect Schedule information to the current purchase order
GetScheduleInformation();
}
#region Exceptions
catch (BusinessLayerException blex)
{
this.HandleException(blex);
}
catch (ThreadAbortException tex)
{
// do nothing
}
catch (Exception ex)
{
this.HandleException(ex);
}
#endregion
}
}


Here's the modified version that worked (with the change in bold):

if (PurchaseOrderSchedules.EditingState != BusinessEditingState.Idle)
{
SaveUndoResult loSaveResult = SaveUndoResult.Cancelled;

try
{
//TODO: Fix problem with locking user into form after picking invalid dates
// Handle calculated fields
decimal loResult = 0;

// Percent Cut to date
loResult =
(((Decimal)PurchaseOrderSchedules.QTY_CUT_TOD_UNT
/ (Decimal)PurchaseOrders.QTY_PO_TOT_LT) * 100);
PurchaseOrderSchedules.PCT_CUT_UNT = loResult;

// Percent Stitched to date
loResult =
(((Decimal)PurchaseOrderSchedules.QTY_STC_TOT_UNT
/ (Decimal)PurchaseOrders.QTY_PO_TOT_LT) * 100);
PurchaseOrderSchedules.PCT_STC_UNT = loResult;

// Percent Assembled to date
loResult =
(((Decimal)PurchaseOrderSchedules.QTY_ASM_TOT_UNT
/ (Decimal)PurchaseOrders.QTY_PO_TOT_LT) * 100);
PurchaseOrderSchedules.PCT_ASM_UNT = loResult;

// Manually assign dates
PurchaseOrderSchedules.DT_CUT_STA = DateTime.Parse(txtDateCut.Text);
PurchaseOrderSchedules.DT_CUT_END = DateTime.Parse(txtDateCutEnd.Text);

PurchaseOrderSchedules.DT_STC_STA = DateTime.Parse(txtDateStitch.Text);
PurchaseOrderSchedules.DT_STC_END = DateTime.Parse(txtDateStitchEnd.Text);

PurchaseOrderSchedules.DT_ASM_STA = DateTime.Parse(txtDateAssembly.Text);
PurchaseOrderSchedules.DT_ASM_END = DateTime.Parse(txtDateAssemblyEnd.Text);


// Try saving the changes
loSaveResult = PurchaseOrderSchedules.Save();
#region Unsuccessful Save
if (loSaveResult == SaveUndoResult.AbortedWithBrokenRules)
{
// Broken business rules. Tell the user which ones and let them
// change their input.
lbError.Visible = true;
lbError.Text = this.GenerateWarningTable(
Global.CreateErrorLabelContents(PurchaseOrderSchedules.BrokenRules),
Global.Config["ImageUri"]
);
}
else if (loSaveResult != SaveUndoResult.Success)
{
// Something else happened, have the user contact the help desk
lbError.Visible = true;
lbError.Text = this.GenerateWarningTable(
"An error has occurred while saving the schedule" + Environment.NewLine +
"information. Please send an e-mail to" + Environment.NewLine +
"CustomCoders@payless.com" +
"
if you continue to experience this " + Environment.NewLine +
"problem.",
Global.Config["ImageUri"]
);
}
#endregion
}
#region Exceptions
catch (BusinessLayerException blex)
{
this.HandleException(blex);
}
catch (ThreadAbortException tex)
{
// do nothing
}
catch (Exception ex)
{
this.HandleException(ex);
}
#endregion

if (loSaveResult == SaveUndoResult.Success)
{
// Enable what should be enabled
lbError.Visible = false;
EnableButtonSaveCancel(false);
EnableDatePickers(false);
EnableToolbar(true);

try
{
// Connect Schedule information to the current purchase order
GetScheduleInformation();
}
#region Exceptions
catch (BusinessLayerException blex)
{
this.HandleException(blex);
}
catch (ThreadAbortException tex)
{
// do nothing
}
catch (Exception ex)
{
this.HandleException(ex);
}
#endregion
}
}


If the fields are bound (they initial assignment works), then why am I needing to manually assign the values to the fields if they change? Does the CheckRules event fire before assigning values to the business object?

Thanks!
Post #14431
Posted 02/19/2008 11:19:58 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 9:47:36 PM
Posts: 4,115, Visits: 4,185
Does the CheckRules event fire before assigning values to the business object?

No.  The bound controls should have updated their bindings by this point.  I will see if I can reproduce.  Greg will be glad to know that we have found his issue relating to the DateTimePicker and we are working on a fix now.  And it only has to do with NULL values...so past that, that is the only known issue with this control...and we use it a lot.  So without a sample or a reproduction, this is one of those, "the compiler must have been having a bad day" issues .  I totally believe you, but liek anything else, we have to get it in a reproducable state before we can do anything.

Post #14433
Posted 02/19/2008 11:21:06 AM
StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: StrataFrame Users
Last Login: 03/03/2008 1:40:52 PM
Posts: 72, Visits: 235
Greg McGuffey (02/19/2008)
Are you using a DateTimePicker? If so, you might try a TextBox (for test) and see if the problem still occurs.


I was using a textbox already. It's a Web-based application (I probably should have mentioned that). I've pseudo-disabled the text boxes by adding an onFocus attribute in the PreRender event that switches focus away from the text box. I was setting the values of the textboxes by bringing up a small window that mimicked a date picker's functionality and called a JavaScript that set the textbox value to a valid date (otherwise, we'd have people entering bad dates and lots of yellow screens ).

Thanks!
Peter
Post #14434
Posted 02/19/2008 11:25:29 AM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIP

Group: StrataFrame Users
Last Login: 2 days ago @ 3:11:51 PM
Posts: 1,148, Visits: 2,831
Greg will be glad to know that we have found his issue relating to the DateTimePicker and we are working on a fix now.


Very good news.

I only mentioned the DateTimePicker as there was the possibility it was control related, based on my experience, rather than binding/BO/Database related issue. Trying another control could quickly narrow that down.
Post #14435
Posted 02/19/2008 11:58:37 AM
StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: StrataFrame Users
Last Login: 03/03/2008 1:40:52 PM
Posts: 72, Visits: 235
Greg McGuffey (02/19/2008)
Greg will be glad to know that we have found his issue relating to the DateTimePicker and we are working on a fix now.


Very good news.

I only mentioned the DateTimePicker as there was the possibility it was control related, based on my experience, rather than binding/BO/Database related issue. Trying another control could quickly narrow that down.


The only thing is that I'm on a Web-based application and not a WinForm. I'm not using a date picker control, but a popup window with a modified calendar control to set the value of the text boxes to which I bound data.

Hopefully I'm not stomping on any glimmers of hope.
Post #14439
Posted 02/19/2008 1:00:21 PM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIP