Strange Problem when checking business rules


Author
Message
PeterA
PeterA
StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)
Group: Forum Members
Posts: 72, Visits: 235
Greg McGuffey (02/19/2008)
Ah, I see. I don't think this stomps out all hope. BigGrin



You might try to eliminate the little pop-up thingy (comment out the code in the prerender event) and see if the textbox by itself exhibits this behavior. I don't see how this could be the problem, but... plus, this should be a quick test so you could eliminate that part of your code immediately as the problem. Quick tests are good BigGrin



And as Trent said and as I've found, a simple app that can reproduce the problem is invaluable, especially when the problem is being an elusive little bugger. (I'm sure you know this...but I resist it every time and it always ends up being the quickest way to the solution in these sort of situations).



Good luck!



P.S. I'm about to leave (within an hour or so) for a little vacation, so I won't be posting for 11-14 days. Until then....asta la pasta!




Yea, I eliminated the onFocus event addition in the PreRender event. It didn't solve the problem.



Honestly, this whole application is pretty simple. One Web page with several fields bound to two business objects. I've been having this problem since before I added any of the extra JavaScript items.



Thanks!

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Ah, I see. I don't think this stomps out all hope. BigGrin



You might try to eliminate the little pop-up thingy (comment out the code in the prerender event) and see if the textbox by itself exhibits this behavior. I don't see how this could be the problem, but... plus, this should be a quick test so you could eliminate that part of your code immediately as the problem. Quick tests are good BigGrin



And as Trent said and as I've found, a simple app that can reproduce the problem is invaluable, especially when the problem is being an elusive little bugger. (I'm sure you know this...but I resist it every time and it always ends up being the quickest way to the solution in these sort of situations).



Good luck!



P.S. I'm about to leave (within an hour or so) for a little vacation, so I won't be posting for 11-14 days. Until then....asta la pasta!
PeterA
PeterA
StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)
Group: Forum Members
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.




BigGrin 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. BigGrin
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Greg will be glad to know that we have found his issue relating to the DateTimePicker and we are working on a fix now.




BigGrin 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.
PeterA
PeterA
StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)
Group: Forum Members
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 BigGrin).



Thanks!

Peter
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
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 Smile.  I totally believe you, but liek anything else, we have to get it in a reproducable state before we can do anything.

PeterA
PeterA
StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)
Group: Forum Members
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!
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Are you using a DateTimePicker? If so, you might try a TextBox (for test) and see if the problem still occurs.
PeterA
PeterA
StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)StrataFrame Novice (78 reputation)
Group: Forum Members
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?
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