From be72063a3c3132e6cf2a404f06dc7d925247821c Mon Sep 17 00:00:00 2001 From: Kathy Date: Tue, 13 Jun 2023 12:59:43 +0000 Subject: [PATCH] B2023-072: Crash when restoring annotation whose type had been removed --- PROMS/VEPROMS.CSLA.Library/Extension/AuditExt.cs | 3 ++- PROMS/Volian.Controls.Library/DisplayHistory.cs | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/AuditExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/AuditExt.cs index 600185a4..b449193e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/AuditExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/AuditExt.cs @@ -1704,8 +1704,9 @@ namespace VEPROMS.CSLA.Library try { AnnotationInfo tmp = DataPortal.Fetch(new RestoreCriteria(aai)); + // B2023 - 073: Crash when restoring annotation whose type had been removed (if no record return null) + if (tmp.ErrorMessage == "No Record Found") return null; AddToCache(tmp); - if (tmp.ErrorMessage == "No Record Found") tmp = null; tmp.MyItem.RefreshItemAnnotations(); return tmp; } diff --git a/PROMS/Volian.Controls.Library/DisplayHistory.cs b/PROMS/Volian.Controls.Library/DisplayHistory.cs index 01c415b0..966e0388 100644 --- a/PROMS/Volian.Controls.Library/DisplayHistory.cs +++ b/PROMS/Volian.Controls.Library/DisplayHistory.cs @@ -827,6 +827,16 @@ namespace Volian.Controls.Library if (FlexibleMessageBox.Show(this, "Do you want to restore this annotation?", "Confirm Annotation Restore", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes) { AnnotationInfo ai = AnnotationInfo.RestoreAnnotation(aai); + // B2023-072: Don't crash if annotation type was deleted for the restore annotation + if (ai == null) + { + AnnotationTypeInfo ati = AnnotationTypeInfo.Get(aai.TypeID); + if (ati == null) + { + FlexibleMessageBox.Show(this, "Annotation Type was deleted, cannot restore Annotation Type\r\nCopy text from window in Change Details and paste into new annotation to restore the text.", "Annotation Type Deleted", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + return; + } OnAnnotationRestored(ai, ai.MyItem); RefreshRequired = true; UpdateHistory();