From ef3efe2380e4061a2f84bb17d090308c4f574786 Mon Sep 17 00:00:00 2001 From: John Jenko Date: Wed, 13 Sep 2023 14:27:38 -0400 Subject: [PATCH 1/3] B2023-093 Convert PROMS Word sections to the DOCX format if needed before Editing or Printing --- .../Extension/DocumentExt.cs | 72 +++++++++++ .../FrmPopupStatusMessage.Designer.cs | 72 +++++++++++ .../FrmPopupStatusMessage.cs | 28 ++++ .../FrmPopupStatusMessage.resx | 120 ++++++++++++++++++ .../Volian.Base.Library.csproj | 9 ++ .../DisplayTabControl.cs | 1 + PROMS/Volian.Print.Library/PromsPrinter.cs | 4 + 7 files changed, 306 insertions(+) create mode 100644 PROMS/Volian.Base.Library/FrmPopupStatusMessage.Designer.cs create mode 100644 PROMS/Volian.Base.Library/FrmPopupStatusMessage.cs create mode 100644 PROMS/Volian.Base.Library/FrmPopupStatusMessage.resx diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs index fab71599..9267e2cb 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs @@ -160,6 +160,78 @@ 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 + 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 + + // 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; + if (statMsg.Length == 0) + statMsg = itmInfo.DisplayText; + FrmPopupStatusMessage pmsg = new FrmPopupStatusMessage("Converting This Section to Word DOCX", statMsg); + pmsg.Show(); + + // Get Document as file - it's placed in the user's temporary folder (like we do when we edit a Word section) + DSOFile myfile = new DSOFile(docInfo); + + // Open MSWord App + LBWordLibrary.LBApplicationClass ap = new LBWordLibrary.LBApplicationClass(); + LBWordLibrary.LBDocumentClass doc = ap.Documents.Open(myfile.FullName); + + // Older versions of PROMS saved the Word section as either a RTF or the old-style Word DOC file + // In either case, we want to convert it to a Word DOCX file + // So now create a file name with the .DOCX extension + string orgFilename = myfile.FullName.ToUpper(); + string filename = orgFilename.Replace(".RTF", ".DOCX").Replace(".DOC", ".DOCX"); // we want to convert either .RTF or .DOC Word sections + + // This calls Word's convert function to convert the opened .DOC or .RTF to DOCX and save it to our new DOCX file name + doc.SaveAs(filename, LBWordLibrary.LBWdSaveFormat.wdFormatXMLDocument); // Convert to Word DOCX + doc.Close(); + ap.Quit(); // close the Word app + + // Now read in the new .DOCX file and save the contents to the SQL database + FileInfo fi = new FileInfo(filename); + FileStream fs = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);// B2016-053 + long len = fs.Length; + byte[] ByteArray = new byte[len]; + int nBytesRead = fs.Read(ByteArray, 0, (int)len); + fs.Close(); + + bool isLibraryDocument = (docInfo.LibTitle != null && docInfo.LibTitle != ""); + Document myDoc = null; + if (isLibraryDocument) + myDoc = Document.Get(docInfo.DocID); + else + myDoc = Document.MakeDocument(null, ByteArray, docInfo.DocAscii, docInfo.Config, ".DOCX"); + + // update the document information in the database + SectionInfo msi = itmInfo as SectionInfo; + Section sec = msi.Get(); + SectionConfig cfg = sec.SectionConfig; + if (!isLibraryDocument) + cfg.MySection.MyContent.MyEntry.MyDocument = myDoc; // resetting MyDocument will clear the library doc link - so don't do if a library document + else + cfg.MySection.MyContent.MyEntry.MyDocument.DocContent = ByteArray; // only update .DocContent for library documents + cfg.MySection.MyContent.MyEntry.MyDocument.FileExtension = ".DOCX"; // make sure the Word file extension is .DOCX + cfg.MySection.MyContent.MyEntry.MyDocument.DTS = fi.LastWriteTimeUtc; + 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 + fi.Delete();// delete the temporary .DOCX file + FileInfo orgFile = new FileInfo(orgFilename); + orgFile.Delete();// delete the old temporary Word file (.DOC or .RTF) + pmsg.Close(); // close the statue message + } + /// /// FixString processes the string returned and changes any symbols (0xF0??) to normal characters /// diff --git a/PROMS/Volian.Base.Library/FrmPopupStatusMessage.Designer.cs b/PROMS/Volian.Base.Library/FrmPopupStatusMessage.Designer.cs new file mode 100644 index 00000000..eb355a93 --- /dev/null +++ b/PROMS/Volian.Base.Library/FrmPopupStatusMessage.Designer.cs @@ -0,0 +1,72 @@ + +namespace Volian.Base.Library +{ + partial class FrmPopupStatusMessage + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.popMsg = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // popMsg + // + this.popMsg.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.popMsg.Location = new System.Drawing.Point(13, 13); + this.popMsg.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.popMsg.Name = "popMsg"; + this.popMsg.Size = new System.Drawing.Size(536, 16); + this.popMsg.TabIndex = 0; + this.popMsg.Text = "label1"; + this.popMsg.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.popMsg.UseWaitCursor = true; + // + // FrmPopupStatusMessage + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.ClientSize = new System.Drawing.Size(562, 38); + this.ControlBox = false; + this.Controls.Add(this.popMsg); + this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "FrmPopupStatusMessage"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "FrmPopupStatusMessage"; + this.TopMost = true; + this.UseWaitCursor = true; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label popMsg; + } +} \ No newline at end of file diff --git a/PROMS/Volian.Base.Library/FrmPopupStatusMessage.cs b/PROMS/Volian.Base.Library/FrmPopupStatusMessage.cs new file mode 100644 index 00000000..4894102e --- /dev/null +++ b/PROMS/Volian.Base.Library/FrmPopupStatusMessage.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Volian.Base.Library +{ + public partial class FrmPopupStatusMessage : Form + { + // This creates a simple message box consisting of a title and the message + // The purpose is to allow the coder to pop up brief status message during the running of a method for a 3rd party. + // i.e. this is used when PROMS uses Word to convert to a DOCX file format for PROMS Word sections. + // The message is centered in the message box - we can expand on this class if needed + // The coder uses the Show method to display the message box and Close to remove it + // The user is not prompted for a response. + public FrmPopupStatusMessage(string title, string msg) + { + InitializeComponent(); + Text = title; + popMsg.Text = msg; + } + } +} diff --git a/PROMS/Volian.Base.Library/FrmPopupStatusMessage.resx b/PROMS/Volian.Base.Library/FrmPopupStatusMessage.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/PROMS/Volian.Base.Library/FrmPopupStatusMessage.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PROMS/Volian.Base.Library/Volian.Base.Library.csproj b/PROMS/Volian.Base.Library/Volian.Base.Library.csproj index 9672f395..d4fcbc7b 100644 --- a/PROMS/Volian.Base.Library/Volian.Base.Library.csproj +++ b/PROMS/Volian.Base.Library/Volian.Base.Library.csproj @@ -95,6 +95,12 @@ Component + + Form + + + FrmPopupStatusMessage.cs + Form @@ -117,6 +123,9 @@ + + FrmPopupStatusMessage.cs + frmRtfEdit.cs diff --git a/PROMS/Volian.Controls.Library/DisplayTabControl.cs b/PROMS/Volian.Controls.Library/DisplayTabControl.cs index 90ed2439..c995e33d 100644 --- a/PROMS/Volian.Controls.Library/DisplayTabControl.cs +++ b/PROMS/Volian.Controls.Library/DisplayTabControl.cs @@ -655,6 +655,7 @@ namespace Volian.Controls.Library } else // Otherwise open it in the Word editor { + Document.ConvertWordSectionToDOCX(myItemInfo); // B2023-093 Convert a Word section to the DOCX Word format if needed before opening it for edit return OpenDSOTabPage(myItemInfo); } } diff --git a/PROMS/Volian.Print.Library/PromsPrinter.cs b/PROMS/Volian.Print.Library/PromsPrinter.cs index 338b32bf..941347ee 100644 --- a/PROMS/Volian.Print.Library/PromsPrinter.cs +++ b/PROMS/Volian.Print.Library/PromsPrinter.cs @@ -761,6 +761,10 @@ namespace Volian.Print.Library int cnt = 0; foreach (SectionInfo mySection in myProcedure.Sections) { + if (!mySection.MyDocStyle.IsStepSection && !mySection.IsAutoTOCSection) + { + VEPROMS.CSLA.Library.Document.ConvertWordSectionToDOCX((ItemInfo)mySection); // B2023-093 Convert a Word section to the DOCX Word format if needed before printing + } //C2019-042 Section_IsFoldout checks Section Number, Section Title, and use of check box if ((myProcedure.ActiveFormat.PlantFormat.FormatData.PrintData.SectionLevelFoldouts && (mySection.MyConfig as SectionConfig).Section_IsFoldout == "Y") || (myProcedure.ActiveFormat.PlantFormat.FormatData.PrintData.AlternateFloatingFoldout && (mySection.MyConfig as SectionConfig).Section_IsFoldout == "Y")) From 6d5d87f04d099a03305b3a78f02b744573f3ccb2 Mon Sep 17 00:00:00 2001 From: John Jenko Date: Wed, 13 Sep 2023 16:27:13 -0400 Subject: [PATCH 2/3] B2023-093 added a Try Catch to the Convert method per suggestion from review --- .../Extension/DocumentExt.cs | 133 +++++++++++------- 1 file changed, 81 insertions(+), 52 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs index 9267e2cb..5288803e 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DocumentExt.cs @@ -169,67 +169,96 @@ namespace VEPROMS.CSLA.Library // 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; + LBWordLibrary.LBDocumentClass doc = null; + string orgFilename = null; + string filename = null; + FileInfo fi = null; + FileStream fs = null; + SectionInfo msi = null; + Section sec = null; + SectionConfig cfg = null; - // 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; - if (statMsg.Length == 0) - statMsg = itmInfo.DisplayText; - FrmPopupStatusMessage pmsg = new FrmPopupStatusMessage("Converting This Section to Word DOCX", statMsg); - pmsg.Show(); + try + { + // 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; + if (statMsg.Length == 0) + statMsg = itmInfo.DisplayText; + pmsg = new FrmPopupStatusMessage("Converting This Section to Word DOCX", statMsg); + pmsg.Show(); - // Get Document as file - it's placed in the user's temporary folder (like we do when we edit a Word section) - DSOFile myfile = new DSOFile(docInfo); + // Get Document as file - it's placed in the user's temporary folder (like we do when we edit a Word section) + myfile = new DSOFile(docInfo); - // Open MSWord App - LBWordLibrary.LBApplicationClass ap = new LBWordLibrary.LBApplicationClass(); - LBWordLibrary.LBDocumentClass doc = ap.Documents.Open(myfile.FullName); + // Open MSWord App + ap = new LBWordLibrary.LBApplicationClass(); + doc = ap.Documents.Open(myfile.FullName); - // Older versions of PROMS saved the Word section as either a RTF or the old-style Word DOC file - // In either case, we want to convert it to a Word DOCX file - // So now create a file name with the .DOCX extension - string orgFilename = myfile.FullName.ToUpper(); - string filename = orgFilename.Replace(".RTF", ".DOCX").Replace(".DOC", ".DOCX"); // we want to convert either .RTF or .DOC Word sections + // Older versions of PROMS saved the Word section as either a RTF or the old-style Word DOC file + // In either case, we want to convert it to a Word DOCX file + // So now create a file name with the .DOCX extension + orgFilename = myfile.FullName.ToUpper(); + filename = orgFilename.Replace(".RTF", ".DOCX").Replace(".DOC", ".DOCX"); // we want to convert either .RTF or .DOC Word sections - // This calls Word's convert function to convert the opened .DOC or .RTF to DOCX and save it to our new DOCX file name - doc.SaveAs(filename, LBWordLibrary.LBWdSaveFormat.wdFormatXMLDocument); // Convert to Word DOCX - doc.Close(); - ap.Quit(); // close the Word app + // This calls Word's convert function to convert the opened .DOC or .RTF to DOCX and save it to our new DOCX file name + doc.SaveAs(filename, LBWordLibrary.LBWdSaveFormat.wdFormatXMLDocument); // Convert to Word DOCX + doc.Close(); + doc = null; - // Now read in the new .DOCX file and save the contents to the SQL database - FileInfo fi = new FileInfo(filename); - FileStream fs = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);// B2016-053 - long len = fs.Length; - byte[] ByteArray = new byte[len]; - int nBytesRead = fs.Read(ByteArray, 0, (int)len); - fs.Close(); + // Now read in the new .DOCX file and save the contents to the SQL database + fi = new FileInfo(filename); + fs = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);// B2016-053 + long len = fs.Length; + byte[] ByteArray = new byte[len]; + int nBytesRead = fs.Read(ByteArray, 0, (int)len); - bool isLibraryDocument = (docInfo.LibTitle != null && docInfo.LibTitle != ""); - Document myDoc = null; - if (isLibraryDocument) - myDoc = Document.Get(docInfo.DocID); - else - myDoc = Document.MakeDocument(null, ByteArray, docInfo.DocAscii, docInfo.Config, ".DOCX"); + bool isLibraryDocument = (docInfo.LibTitle != null && docInfo.LibTitle != ""); + Document myDoc = null; + if (isLibraryDocument) + myDoc = Document.Get(docInfo.DocID); + else + myDoc = Document.MakeDocument(null, ByteArray, docInfo.DocAscii, docInfo.Config, ".DOCX"); - // update the document information in the database - SectionInfo msi = itmInfo as SectionInfo; - Section sec = msi.Get(); - SectionConfig cfg = sec.SectionConfig; - if (!isLibraryDocument) - cfg.MySection.MyContent.MyEntry.MyDocument = myDoc; // resetting MyDocument will clear the library doc link - so don't do if a library document - else - cfg.MySection.MyContent.MyEntry.MyDocument.DocContent = ByteArray; // only update .DocContent for library documents - cfg.MySection.MyContent.MyEntry.MyDocument.FileExtension = ".DOCX"; // make sure the Word file extension is .DOCX - cfg.MySection.MyContent.MyEntry.MyDocument.DTS = fi.LastWriteTimeUtc; - cfg.MySection.MyContent.MyEntry.MyDocument.MarkDirty(); - cfg.MySection.MyContent.MyEntry.Save(); + // update the document information in the database + msi = itmInfo as SectionInfo; + sec = msi.Get(); + cfg = sec.SectionConfig; + if (!isLibraryDocument) + cfg.MySection.MyContent.MyEntry.MyDocument = myDoc; // resetting MyDocument will clear the library doc link - so don't do if a library document + else + cfg.MySection.MyContent.MyEntry.MyDocument.DocContent = ByteArray; // only update .DocContent for library documents + cfg.MySection.MyContent.MyEntry.MyDocument.FileExtension = ".DOCX"; // make sure the Word file extension is .DOCX + cfg.MySection.MyContent.MyEntry.MyDocument.DTS = fi.LastWriteTimeUtc; + 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 - fi.Delete();// delete the temporary .DOCX file - FileInfo orgFile = new FileInfo(orgFilename); - orgFile.Delete();// delete the old temporary Word file (.DOC or .RTF) - pmsg.Close(); // close the statue message + _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 + 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); + } + finally + { + if (pmsg != null) + pmsg.Close();// close the statue message + if (ap != null) + ap.Quit(); // close the Word app + if (doc != null) + doc.Close(); + if (fs != null) + fs.Close(); + if (fi != null && fi.Exists) + fi.Delete();// delete the temporary .DOCX file + } } /// From 830c84a62eec86541acdc3c5bdb63cc5ca33c814 Mon Sep 17 00:00:00 2001 From: Kathy Ruffing Date: Thu, 14 Sep 2023 09:11:36 -0400 Subject: [PATCH 3/3] F2023-135: Farley FSG - override width of unnumbered HLS --- PROMS/Formats/fmtall/fnpnmpall.xml | Bin 59214 -> 59254 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/PROMS/Formats/fmtall/fnpnmpall.xml b/PROMS/Formats/fmtall/fnpnmpall.xml index 45d2a2823d69da0ce4695b37d3d1c53aef7254a6..4ffc6e816529d643c1d880c91ae24f22ddbe74ab 100644 GIT binary patch delta 32 ocmX?ij``a;<_%mflN(ZGIBgk}7)%&U84M-|M$g>5z-8Sc0LG3BxBvhE delta 30 ocmV+(0O9}k&I8WQ1F#B2lg