I have been tasked with trapping and displaying dates when CheckOffs are made in DMR Processing. I created a DateTimeEditor for each CheckOff on the Header/Detail tab and modified the GroupBox as shown below, with the code used below that. When I check/uncheck the Checkoff box, the DateTimeEditor reacts as expected. But, when trying to save the data after a checkbox has been unchecked, the DBNull date does not save to the table, and the DateTimeEditor reverts to the previously saved date. Can anyone see what I am doing wrong, or have a better idea how to accomplish the task?
Thanks John. Not sure why we should add a customization for the controls and not be able to complete the task in the same customization, but it looks like that will be the path I have to take. I appreciate you sharing your experience and saving me some headache investigating.
It’s for separating out client-side UI behavior from server-side business logic. Yeah, you can blur that line by putting server calls in the client. That keeps everything in one place, but it’s not considered best practice. Also, in my experience, BPM customizations are simpler and break less often when upgrading.
@JimF , I looked at a code example I had where I used DBNull.Value in a customization. The only real difference between my code and yours was that I used the BeginEdit() and EndEdit() methods on the EpiDataView data row before setting the UD field.
I’m not sure why that would make a difference for this issue, but could be worth a try. It’s also possible my code has the same issue but no one ever noticed it…
Thanks Tom. I actually found some other example code that used BeginEdit() and EndEdit() and tried using them but got the same results. That fact that it works for you though means that there is probably something else you are doing that I am not. I know I have done this with other controls without issue, I am pretty sure it has something to do with the EpiDateTimeEditor and setting it from a value to a DBNull. You could be right if no one ever tried to blank/reset the control from code or externally from the control itself, it would very well have gone unnoticed. I haven’t gotten to creating the BPM yet. If you think of anything else I might be missing, let me know. Thanks!
Thanks @hkeric.wci . For whatever reason that rendered the same results. I’m sure I am either doing something wrong or have things setup incorrectly, but it is easy enough to create a BPM to handle it. That is the road I’ll take. Thanks again for taking the time guys.
@hkeric.wci I was called into another project before completing this one, but I am now back on it. Do you have any customizations that use this logic? I am having a devil of a time getting the DateTimeEdtor/bound UD field to act as expected. If I use the customization code to set the values, when the checkbox is checked the DateTimeEditor reacts as expected (Sets to today’s date) both immediately and on Save, when the checkbox is unchecked, the DateTimeEditor value blanks as expected, but when the record is saved, the DTE reverts to the previously saved vale and on examining the DB, the UD field was never updated. When I use a directive, the DB UD Field is updated, but the DTE on the UI does not update and I have to hit Refresh to see the proper value. It seems to me to be an issue with the DateTimeEditor. Any help or experience with this would be greatly appreciated. Thanks.
Current Code:
private void DMRHead_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row["FieldName"]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
switch (args.Column.ColumnName)
{
case "CheckOff1": // QA
if (Convert.ToBoolean(args.ProposedValue) == true)
edvDMRHead.dataView[edvDMRHead.Row]["QACheckOffDate_c"] = DateTime.Now;
else
edvDMRHead.dataView[edvDMRHead.Row]["QACheckOffDate_c"] = DBNull.Value;
break;
case "CheckOff2": // Engineering
if (Convert.ToBoolean(args.ProposedValue) == true)
edvDMRHead.dataView[edvDMRHead.Row]["EngCheckOffDate_c"] = DateTime.Now;
else
edvDMRHead.dataView[edvDMRHead.Row]["EngCheckOffDate_c"] = DBNull.Value;
break;
case "CheckOff3": // Production
if (Convert.ToBoolean(args.ProposedValue) == true)
edvDMRHead.dataView[edvDMRHead.Row]["ProdCheckOffDate_c"] = DateTime.Now;
else
edvDMRHead.dataView[edvDMRHead.Row]["ProdCheckOffDate_c"] = DBNull.Value;
break;
case "CheckOff4": // Purchasing
if (Convert.ToBoolean(args.ProposedValue) == true)
edvDMRHead.dataView[edvDMRHead.Row]["PurchCheckOffDate_c"] = DateTime.Now;
else
edvDMRHead.dataView[edvDMRHead.Row]["PurchCheckOffDate_c"] = DBNull.Value;
break;
case "CheckOff5": // QA Final
if (Convert.ToBoolean(args.ProposedValue) == true)
edvDMRHead.dataView[edvDMRHead.Row]["QAFinalCheckOffDate_c"] = DateTime.Now;
else
edvDMRHead.dataView[edvDMRHead.Row]["QAFinalCheckOffDate_c"] = DBNull.Value;
break;
}
}
CheckBox Checked and Date correct:
After CheckBox is unchecked:
After Save is pressed:
Thanks Aaron. I have a directive that works, but the issue with it is that when the field is updated, the DTE doesn’t reflect the change. I have to hit refresh to see the value. It’s like the control is not properly bound to the UD Field.
With the BPM:
After the CheckBox is unchecked:
After save is pressed:
I check the UD Field:
Then hit refresh:
Since (I believe) the oTrans.Upate() is essentially the same as pressing save, adding it just causes the DTE to display the date that happened after pressing Save.
After much testing, it seems that if you bind a DB DateTime field to a EpiDateTimeEditor and set the value of the bound field to null, it will not update the DB DateTime field. I don’t think the EpiDateTimeEditor is the issue as far as the update is concerned as I am just attempting to set the row/column value to DBNull.Value.
You can update from a BPM, but then have to refresh the UI to reflect the change which as a side note, seems to be a known issue:
I am still working on this. If I find a reasonable solution I will post here.
Looks like I had to revert to the ol’ hidden control trick. Place a control (in this case a read-only blank textbox) behind the control you want to ‘blank’ and use BringToFront() and SendToBack(). A lot of nonsense to fix what probably should work natively, but in conjunction with a directive to update the DB, works in a pinch, no refresh needed.