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!