using System; using System.Data; using System.Data.SqlClient; using Csla; namespace VEPROMS.CSLA.Library { public partial class Pdf { public static void DeleteAll(int docID) { try { DataPortal.Delete(new DocIDCriteria(docID)); } catch (Exception ex) { throw new DbCslaException("Error on Pdf.DeleteAll", ex); } } [Serializable()] protected class DocIDCriteria { private readonly int _DocID; public int DocID => _DocID; public DocIDCriteria(int docID) => _DocID = docID; } [Transactional(TransactionalTypes.TransactionScope)] private void DataPortal_Delete(DocIDCriteria criteria) { if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Pdf.DataPortal_Delete", GetHashCode()); try { using (SqlConnection cn = Database.VEPROMS_SqlConnection) { using (SqlCommand cm = cn.CreateCommand()) { cm.CommandType = CommandType.StoredProcedure; cm.CommandTimeout = Database.SQLTimeout; cm.CommandText = "deleteAllPdfs"; cm.Parameters.AddWithValue("@DocID", criteria.DocID); cm.ExecuteNonQuery(); } } } catch (Exception ex) { if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.DataPortal_Delete", ex); _ErrorMessage = ex.Message; throw new DbCslaException("Pdf.DataPortal_Delete", ex); } } //C2026-008 Re-Architect RO.FST to include RO Modification date/time // used to remove word section PDFs to force ROs to be updated when printed or saved public static void DeleteDocVersionPDFsWithNewROs(int versionID, int origfstid, int newfstid) { try { DeleteWithNewROs(versionID, origfstid, newfstid); } catch (Exception ex) { throw new DbCslaException("Error on Pdf.DeleteAllDocVersion", ex); } } static private void DeleteWithNewROs(int docversionID, int origfstid, int newfstid) { try { using (SqlConnection cn = Database.VEPROMS_SqlConnection) { using (SqlCommand cm = cn.CreateCommand()) { cm.CommandType = CommandType.StoredProcedure; cm.CommandTimeout = Database.SQLTimeout; cm.CommandText = "deleteDocVersionPdfsWithNewROs"; cm.Parameters.AddWithValue("@VersionID", docversionID); cm.Parameters.AddWithValue("@OrigFSTid", origfstid); cm.Parameters.AddWithValue("@NewFSTid", newfstid); cm.ExecuteNonQuery(); } } } catch (Exception ex) { if (_MyLog.IsErrorEnabled) _MyLog.Error("Pdf.DeleteWithNewROs", ex); throw new DbCslaException("Pdf.DeleteWithNewROs", ex); } } } public partial class PdfInfo { // B2023-024 PROMS was using old cached PDF data when printing Word sections. // Added this method that can be called to clear the PDF print cache for a specified section. public static void RemovePDFFromCache(ItemInfo sect) { if (sect.MyContent.MyEntry == null) return; // B2023-030 not a word section so just jump out DocStyle myDocStyle = sect.ActiveSection.MyDocStyle; int ss = sect.MyDocVersion.DocVersionConfig.SelectedSlave; if (sect.ActiveSection.MyConfig is SectionConfig sc && sc.Section_WordMargin == "Y") { RemoveFromCachedByPrimaryKey(sect.MyContent.MyEntry.DocID, ss * 10 + MSWordToPDF.DebugStatus, 0, 0, 0, 0); } else { RemoveFromCachedByPrimaryKey(sect.MyContent.MyEntry.DocID, ss * 10 + MSWordToPDF.DebugStatus, (int)myDocStyle.Layout.TopMargin, (int)myDocStyle.Layout.PageLength, (int)myDocStyle.Layout.LeftMargin, (int)myDocStyle.Layout.PageWidth); } } public static PdfInfo Get(ItemInfo sect, bool ovrride) { int count = 0; while (count < 2) { DocStyle myDocStyle = sect.ActiveSection.MyDocStyle; int ss = sect.MyDocVersion.DocVersionConfig.SelectedSlave; PdfInfo myPdf; if (sect.ActiveSection.MyConfig is SectionConfig sc && sc.Section_WordMargin == "Y") { myPdf = Get(sect.MyContent.MyEntry.DocID, ss * 10 + MSWordToPDF.DebugStatus, 0, 0, 0, 0); } else { myPdf = Get(sect.MyContent.MyEntry.DocID, ss * 10 + MSWordToPDF.DebugStatus, (int)myDocStyle.Layout.TopMargin, (int)myDocStyle.Layout.PageLength, (int)myDocStyle.Layout.LeftMargin, (int)myDocStyle.Layout.PageWidth); } // override forces the printing of the word section, which creates a word file with resolved ROs, which is saved for an approved export if (!ovrride || (ovrride && count == 1)) { if (myPdf != null) return myPdf; if (count > 0) return null; // Could not find or create a pdf } MSWordToPDF.SetDocPdf(sect.MyContent.MyEntry.MyDocument, sect); count++; } return null; } } public partial class PdfInfoList { } }