From 7b4b6323bfcb0e8e3a6ba05eccb5ef4e53694a74 Mon Sep 17 00:00:00 2001 From: John Jenko Date: Fri, 3 Nov 2023 09:55:48 -0400 Subject: [PATCH] =?UTF-8?q?Added=20better=20logic=20to=20catch=20null=20re?= =?UTF-8?q?ferences=20when=20PROMS=20tries=20to=20convert=20an=20older=20W?= =?UTF-8?q?ord=20section=20to=20use=20the=20Docx=20file=20format.=20=20The?= =?UTF-8?q?=20real=20issue=20was=20bad=20data=20where=20the=20tree=20view?= =?UTF-8?q?=20looks=20like=20it=E2=80=99s=20a=20step=20editor=20section,?= =?UTF-8?q?=20but=20the=20PROMS=20editor=20depicts=20it=20as=20a=20Word=20?= =?UTF-8?q?section=20(with=20the=20arrow=20icon=20instead=20of=20a=20plus?= =?UTF-8?q?=20icon).=20When=20printed=20or=20approved,=20PROMS=20tries=20t?= =?UTF-8?q?o=20process=20it=20as=20Word=20section=20but=20some=20informati?= =?UTF-8?q?on=20in=20that=20database=20record=20is=20null.=20=20PROMS=20wi?= =?UTF-8?q?ll=20now=20handle=20these=20pieces=20of=20information=20that=20?= =?UTF-8?q?is=20null=20and=20record=20the=20issue=20in=20the=20error=20log?= =?UTF-8?q?=20and=20not=20try=20to=20convert=20it=20to=20a=20Docx,=20allow?= =?UTF-8?q?ing=20to=20continue=20printing=20or=20approving.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extension/DocumentExt.cs | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs index 5288803e..64401d9a 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs @@ -164,11 +164,10 @@ namespace VEPROMS.CSLA.Library // B2023-093 This method is called before editing or printing a Word section and will convert it the Word .DOCX format if needed. // Note that the core logic was taken from frmSectionProperties.cs and modified to convert both .RTF and .DOC files // The conversion to DOCX is needs to be done only one time per Word section + // B2023-109 Moved the setting of docInfo in the try block to handle if itmInfo, MyContent, MyEntry, MyDocument is null + // Also modified the error log statements in the Catch to put the ItemID and the section number and title out to the error log public static void ConvertWordSectionToDOCX(ItemInfo itmInfo) { - // check the Word file extension that is saved in the tblDocuments SQL database table - DocumentInfo docInfo = itmInfo.MyContent.MyEntry.MyDocument; - if (docInfo.FileExtension.ToUpper() == ".DOCX") return; // already a DOCX - no need to convert FrmPopupStatusMessage pmsg = null; DSOFile myfile = null; LBWordLibrary.LBApplicationClass ap = null; @@ -180,9 +179,13 @@ namespace VEPROMS.CSLA.Library SectionInfo msi = null; Section sec = null; SectionConfig cfg = null; - + DocumentInfo docInfo = null; try { + // check the Word file extension that is saved in the tblDocuments SQL database table + docInfo = itmInfo.MyContent.MyEntry.MyDocument; + if (docInfo.FileExtension.ToUpper() == ".DOCX") return; // already a DOCX - no need to convert + // show user a status window of the Word section being converted to DOCX // use the section number (DisplayNumber) unless the length is zero, then use the section title (DisplayText) string statMsg = itmInfo.DisplayNumber; @@ -236,19 +239,25 @@ namespace VEPROMS.CSLA.Library cfg.MySection.MyContent.MyEntry.MyDocument.MarkDirty(); cfg.MySection.MyContent.MyEntry.Save(); - _MyLog.InfoFormat("Converted Word Section to DOCX - Old ID {0} - New ID {1} - {2}", docInfo.DocID, myDoc.DocID, statMsg); // record in log file (aka error log) that conversion was done - // delete the temporary files + // record in log file (aka error log) that conversion was done + _MyLog.InfoFormat("Converted Word Section to DOCX - Old ID {0} - New ID {1} - {2}", docInfo.DocID, myDoc.DocID, statMsg); + FileInfo orgFile = new FileInfo(orgFilename); orgFile.Delete();// delete the old temporary Word file (.DOC or .RTF) } catch (Exception ex) { _MyLog.ErrorFormat("Error converting Word section to DOCX - {0}", ex.Message); - _MyLog.ErrorFormat("Error converting Word section to DOCX - ConvertWordSetionToDOXX: ItemID ={0} DOCID={1} LibTitle = {2}", itmInfo, docInfo.DocID, docInfo.LibTitle); + if (docInfo == null) + { + _MyLog.ErrorFormat("Error converting Word section to DOCX - ConvertWordSetionToDOXX: ItemID ={0} {1} {2}", itmInfo.ItemID, itmInfo.MyContent.Number, itmInfo.MyContent.Text); + } + else + _MyLog.ErrorFormat("Error converting Word section to DOCX - ConvertWordSetionToDOXX: ItemID ={0} {1} {2} DOCID={3} LibTitle = {4}", itmInfo.ItemID, itmInfo.MyContent.Number, itmInfo.MyContent.Text, docInfo.DocID, docInfo.LibTitle); } finally { - if (pmsg != null) + if (pmsg != null) pmsg.Close();// close the statue message if (ap != null) ap.Quit(); // close the Word app -- 2.47.2