using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using Volian.Print.Library; using VEPROMS.CSLA.Library; using Volian.Base.Library; using JR.Utils.GUI.Forms; namespace VEPROMS { public partial class frmPDFStatusForm : Form { public bool CancelPrinting { get; set; } = false; public bool CloseWhenDone { get; set; } = false; public bool CancelStop { get; set; } = false; public bool Stop { get; set; } = false; public string PDFPath { get; set; } public PromsPrinter MyPromsPrinter { get; set; } public bool OpenPDF { get; set; } private Point _NewLocation; public string Prefix { get; set; } = ""; public bool OnlyShowContinuousActionSummary { get; set; } = false; public bool OnlyShowTimeCriticalActionSummary { get; set; } = false; public bool DidAll { get; set; } = false; public int PrtSectID { get; set; } = -1; public frmPDFStatusForm(ItemInfo myItem, string rev, string watermark, bool debugOutput, bool origPgBrk, bool openPDF, bool overWrite, string pdfPath, ChangeBarDefinition cbd, string pdfFile, Point newLocation, bool insertBlankPages, bool allOrAuto, string prefix, bool saveLinks, int removeTrailingHardReturnsAndManualPageBreaks, bool showPROMSVer, bool didAll, string blankPageText, MergedPdf mergedPdf, string watermarkColor, int PrtSectID = -1) { // B2021-088 moved this if/else from CreatePDF() so that the Approval logic will have access to this logic ProcedureInfo MyProcedure = myItem as ProcedureInfo; // B2022-107: Display Progress Bar Messages/Statuses when a new ROFST binary file is loaded into the database // Added an optional parameter to "GetItemAndChildrenByUnit" and "GetItemAndChildren" methods to disable the RofstLoadingStatus pop-up screen when printing baselines if (MyProcedure.MyDocVersion.DocVersionConfig.SelectedSlave > 0 || MyProcedure.ActiveFormat.PlantFormat.FormatData.TransData.UseTransitionModifier || MyProcedure.ActiveFormat.PlantFormat.FormatData.TransData.UseSpecificTransitionModifier) { // B2023-035 Pass in the select child (selectedSlave) which may be different than docversionconfig's SelectedSlave MyProcedure = ProcedureInfo.GetItemAndChildrenByUnit(MyProcedure.ItemID, 0, MyProcedure.MyDocVersion.DocVersionConfig.SelectedSlave, allOrAuto, MyProcedure.SelectedChildToPrint); } else MyProcedure = ProcedureInfo.GetItemAndChildren(MyProcedure.ItemID, allOrAuto); // B2021-102 moved the baseline meta file write here too - should have been done with B2021-088 fix // C2018-015 add the procedure tree path and the procedure number and title to the meta file if (BaselineMetaFile.IsOpen) BaselineMetaFile.WriteLine($"!! {MyProcedure.SearchDVPath.Replace("\a", " | ")}"); if (BaselineMetaFile.IsOpen) BaselineMetaFile.WriteLine($"!! {MyProcedure.DisplayNumber} | {MyProcedure.DisplayText}"); myItem = MyProcedure; Prefix = prefix; OpenPDF = openPDF; DidAll = didAll; this.PrtSectID = PrtSectID; InitializeComponent(); // if the version number of PROMS is 1.0, then we are running a Demo version. // When running a Demo version, force a "Sample" watermark when printing. // B2020-022 append a ".pdf" extension if the file name does on have one. MyPromsPrinter = new PromsPrinter(myItem, rev, (VlnSettings.ReleaseMode.Equals("DEMO")) ? "Sample" : watermark, debugOutput, origPgBrk, pdfPath + @"\Compare", false, overWrite, cbd, (pdfFile.ToUpper().EndsWith(".PDF")) ? pdfFile : $"{pdfFile}.pdf", insertBlankPages, allOrAuto, Prefix, saveLinks, removeTrailingHardReturnsAndManualPageBreaks, blankPageText, DidAll, mergedPdf, watermarkColor) { PromsVersion = (showPROMSVer) ? AboutVEPROMS.PROMSVersion : "" //C2018-009 print PROMS version }; PDFPath = pdfPath; Text = $"Creating PDF of {myItem.DisplayNumber}"; _NewLocation = newLocation; DialogResult = DialogResult.OK; } public static void SetUnitWatermark(ProcedureInfo procInfo, ref string waterMarkText, ref string watermarkColor) { // C2022-004 BNPP Unit Specific Watermark // Check if the user selected the "Unit Designator" watermark. // If the procedure number starts with any of the ProcNumPrefix values (set in the format file) then // set the Watermark Override text and color variables with the values from the format if (waterMarkText.ToUpper().Equals("UNIT DESIGNATOR") && procInfo.ActiveFormat.PlantFormat.FormatData.UnitWatermarkList != null) { foreach (UnitWatermark uw in procInfo.ActiveFormat.PlantFormat.FormatData.UnitWatermarkList) { if (procInfo.DisplayNumber.StartsWith(uw.ProcNumPrefix) || uw.ProcNumPrefix.ToUpper() == "DEFAULT") { waterMarkText = uw.WMText; watermarkColor = uw.WMColor; break; } } // Check if the watermark is the defined Parent/Child applicability token (field) // if procedure does not use parent/child, then make the watermark text blank (empty string) if (waterMarkText.ToUpper() == "[U-TEXT]") { string utxt = (procInfo.MyDocVersion.MultiUnitCount > 1) ? procInfo.MyDocVersion.DocVersionConfig.Unit_Text : ""; waterMarkText = utxt ?? ""; } else if (waterMarkText.ToUpper() == "[U-NUMBER]") { string uNum = (procInfo.MyDocVersion.MultiUnitCount > 1) ? procInfo.MyDocVersion.DocVersionConfig.Unit_Number : ""; waterMarkText = uNum ?? ""; } } } public Dictionary DocReplace { get; set; } public bool AllowAllWatermarks { get { return MyPromsPrinter.AllowAllWatermarks; } set { MyPromsPrinter.AllowAllWatermarks = value; } } void pp_StatusChanged(object sender, PromsPrintStatusArgs args) { if (args.Type == PromsPrinterStatusType.ProgressSetup) pb.Maximum = args.Progress; else if (args.Type == PromsPrinterStatusType.Progress) { pb.Value = args.Progress; if (args.Progress == pb.Maximum) pb.Text = args.MyStatus; else pb.Text = $"Processing {args.MyStatus} ({args.Progress + 1} of {pb.Maximum})"; } MyStatus = args.MyStatus; Application.DoEvents(); } public string MyStatus { get { return lblStatus.Text; } set { lblStatus.Text = value; Application.DoEvents(); } } private void frmPDFStatusForm_Load(object sender, EventArgs e) { Location = _NewLocation; tmrRun.Enabled = true; if (MakeContinuousActionSummary) Text = Text.Replace("PDF", "Continuous Action Summary"); else if (MakeTimeCriticalActionSummary) Text = Text.Replace("PDF", "Time Critical Action Summary"); // F2022-024 Time Critical Action } public string PdfFile { get; set; } public bool MakePlaceKeeper { get; set; } = false; public bool MakeContinuousActionSummary { get; set; } = false; public bool MakeTimeCriticalActionSummary { get; set; } = false; private void tmrRun_Tick(object sender, EventArgs e) { tmrRun.Enabled = false; if (CancelStop) btnCancel.Visible = true; Application.DoEvents(); MyPromsPrinter.StatusChanged -= new PromsPrinterStatusEvent(pp_StatusChanged); MyPromsPrinter.StatusChanged += new PromsPrinterStatusEvent(pp_StatusChanged); MyPromsPrinter.DocReplace = DocReplace; // used when approve generates an export with unlinked ROs and Transitions DateTime tStart = DateTime.Now; if (!CancelStop) PromsPrinter.ClearTransPageNumProblems(); // B2018-029: delete any pdf files related to printing supplemental information facing pages: // B2018-039 Delete only pdf files that begin with "SupInof" string[] filePaths = System.IO.Directory.GetFiles(Volian.Base.Library.VlnSettings.TemporaryFolder, "SupInfo*.pdf"); foreach (string filePath in filePaths) System.IO.File.Delete(filePath); do { int profileDepth = ProfileTimer.Push(">>>> MyPromsPrinter.Print"); // B2018-099: remove cache items for contents, items and parts to prevent out of memory errors when // doing print all or automated print testing or approval of some or all procedures, i.e. HashSet and use of them below. HashSet cacheContentInfo = null; HashSet cacheItemInfo = null; HashSet cachePartInfo = null; if (DidAll) { cacheContentInfo = ContentInfo.CacheList; cacheItemInfo = ItemInfo.CacheList; cachePartInfo = PartInfo.CacheList; } //B2025-048 Problem with Printing CAS Steps // skip doing section titles if printing CAS or CTAS // - was causing it to // skip/overwrite data if (OnlyShowContinuousActionSummary) { MyPromsPrinter.PromsPrinterPrintType = PromsPrinterPrintType.CAS_Only; } if (OnlyShowTimeCriticalActionSummary) { MyPromsPrinter.PromsPrinterPrintType = PromsPrinterPrintType.TCAS_only; } PdfFile = MyPromsPrinter.Print(PDFPath, MakePlaceKeeper, MakeContinuousActionSummary, MakeTimeCriticalActionSummary, PrtSectID); ProfileTimer.Pop(profileDepth); if (DidAll) { ContentInfo.RestoreCacheList(cacheContentInfo); ItemInfo.RestoreCacheList(cacheItemInfo); PartInfo.RestoreCacheList(cachePartInfo); } } // B2024-062 Added check for EmptyProcedure. We don't need to show the Try Again message if the procedure // is empty, as it would be just be a waste of time for the user. while (!MyPromsPrinter.MergeNotIncluded && PdfFile == null && !MyPromsPrinter.EmptyProcedure && MessageBox.Show("Try Again?", "PDF Creation Failed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes); if (PdfFile == null) { Close(); return; } if (!CancelStop) { if (PromsPrinter.ReportTransPageNumProblems() == DialogResult.Yes && MyPromsPrinter.BeforePageNumberPdf != null) { System.Diagnostics.Process.Start(MyPromsPrinter.BeforePageNumberPdf); // C2017-018 - Open Pass 2 output if it exists if (MyPromsPrinter.BeforePageNumber2Pdf != null) System.Diagnostics.Process.Start(MyPromsPrinter.BeforePageNumber2Pdf); } } DateTime tEnd = DateTime.Now; MyStatus = $"{PdfFile} created."; MyStatus = $"{PdfFile} created in {(TimeSpan.FromTicks(tEnd.Ticks - tStart.Ticks).TotalMilliseconds):0.} milliseconds"; if (OpenPDF) { OpenPDFandPlacekeeper(PdfFile); Close(); // C2021-010: Remove trailing returns/spaces & manual page breaks & allow save. Ask if user wants to save chanages // if they were found. if ((MyPromsPrinter.RemoveManualPageBreaks != null && MyPromsPrinter.RemoveManualPageBreaks.Count > 0) || (MyPromsPrinter.RemoveTrailingHardReturnsAndSpaces != null && MyPromsPrinter.RemoveTrailingHardReturnsAndSpaces.Count > 0)) { if (UserInfo.CanEdit(frmVEPROMS.SMyUserInfo, MyPromsPrinter.MyItem.MyDocVersion)) { // C2023-018: Clarify message on temporary/permanent removal of returns/spaces & page breaks if (FlexibleMessageBox.Show(this, "The procedure PDF file was created by temporarily removing certain hard returns,\r\ntrailing spaces, and/or manual page breaks that could affect the pagination\r\n"+ "of the procedure.\r\n\r\nAfter reviewing the PDF file, do you want to permanently remove the deleted hard returns, \r\nspaces and/or manual page breaks?\r\n\r\n"+ "An annotation will be added to every location where data has been deleted. The locations \r\ncan be found by performing a Global Search for the \"Manual Pagination Issues\" annotation type.", "Confirm Pagination Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { MyPromsPrinter.SavePaginationFixes(); } } } return; } btnOpenFolder.Visible = btnOpenPDF.Visible = true; if (CloseWhenDone) { OpenPDFandPlacekeeper(null); Close(); return; } } private void btnOpenPDF_Click(object sender, EventArgs e) { OpenPDFandPlacekeeper(PdfFile); Close(); } // set a delay so that the word document containing the newly generated placekeeper will appear on top of everything else. // - requested by Calvert Cliffs private void OpenPDFandPlacekeeper(string pdffile) { try // B2019-106 Error Handling for PDF Open { if ((pdffile ?? "") != "" && !OnlyShowContinuousActionSummary && !OnlyShowTimeCriticalActionSummary) // F2022-024 Time Critical Action Summary { System.Diagnostics.Process sdp = System.Diagnostics.Process.Start(pdffile); sdp?.WaitForInputIdle(); } if (OnlyShowContinuousActionSummary || OnlyShowTimeCriticalActionSummary) // F2022-024 Time Critical Action Summary System.IO.File.Delete(pdffile); // remove the temporary PDF file used to create the Continuous Action Summary if (MyPromsPrinter.MyPlacekeeper != null) { // The PlacekeeperDelay is a switch that can be added to the PROMS.exe shortcut // ex: VEPROMS.EXE /PlacekeeperDelay=2.5 will delay it 2 1/2 seconds float delay = Volian.Base.Library.VlnSettings.GetCommandFloat("PlacekeeperDelay", 3.0f); int mydelay = (int)(1000 * delay); System.Threading.Thread.Sleep(mydelay); MyPromsPrinter.MyPlacekeeper.Visible(); } // this will display the generated Continuous Action Summary in MS Word (starting a new instance of MS Word outside of PROMS) if (MyPromsPrinter.MyContActSummary != null) { //C2025-013 - Allow not continuously generate message that opening Summaries in MS Word using (dlgMSWordMessage msg = new dlgMSWordMessage("Continuous Action")) { if (msg.ShouldDisplay()) msg.ShowDialog(); } // The ContActSummaryDelay is a switch that can be added to the PROMS.exe shortcut // ex: VEPROMS.EXE /ContActSummaryDelay=2.5 will delay it 2 1/2 seconds float delay = Volian.Base.Library.VlnSettings.GetCommandFloat("ContActSummaryDelay", 1.0f); int mydelay = (int)(1000 * delay); System.Threading.Thread.Sleep(mydelay); MyPromsPrinter.MyContActSummary.Visible(); } // F2022-024 this will display the generated Time Critical Action Summary in MS Word (starting a new instance of MS Word outside of PROMS) if (MyPromsPrinter.MyTimeCriticalActSummary != null) { //C2025-013 - Allow not continuously generate message that opening Summaries in MS Word using (dlgMSWordMessage msg = new dlgMSWordMessage("Time Critical Action")) { if (msg.ShouldDisplay()) msg.ShowDialog(); } // The ContActSummaryDelay is a switch that can be added to the PROMS.exe shortcut // ex: VEPROMS.EXE /ContActSummaryDelay=2.5 will delay it 2 1/2 seconds float delay = Volian.Base.Library.VlnSettings.GetCommandFloat("TimeCritActSummaryDelay", 1.0f); int mydelay = (int)(1000 * delay); System.Threading.Thread.Sleep(mydelay); MyPromsPrinter.MyTimeCriticalActSummary.Visible(); } } catch (Exception ex) { string str = $"{pdffile} - {ex.GetType().Name} - {ex.Message}"; MessageBox.Show(str, "Error Opening PDFFile", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } private void btnOpenFolder_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("Explorer", $"/select,{PdfFile}"); OpenPDFandPlacekeeper(null); Close(); } private void btnCancel_Click(object sender, EventArgs e) { CancelPrinting = true; btnCancel.Text = "Cancelled"; btnCancel.Enabled = false; } } }