Print Library, Svg Library, Utils Library, XYPlots

This commit is contained in:
2026-07-24 13:36:46 -04:00
parent 06c3136566
commit f67d37801a
68 changed files with 12173 additions and 16618 deletions
+209 -200
View File
@@ -5,7 +5,7 @@ using VEPROMS.CSLA.Library;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.IO;
using System.Text.RegularExpressions;
using System.Linq;
namespace Volian.Print.Library
{
@@ -13,27 +13,14 @@ namespace Volian.Print.Library
public class PDFTransitionReport
{
public event TransitionReportEvent TransitionProcessed;
private void OnTransitionProcessed(object sender, EventArgs args)
{
if (TransitionProcessed != null) TransitionProcessed(sender, args);
}
public event TransitionReportEvent ProcedureProcessed;
private void OnProcedureProcessed(object sender, EventArgs args)
{
if (ProcedureProcessed != null) ProcedureProcessed(sender, args);
}
public event TransitionReportEvent DocVersionProcessed;
private void OnDocVersionProcessed(object sender, EventArgs args)
{
if (DocVersionProcessed != null) DocVersionProcessed(sender, args);
}
private string _FileName;
public string FileName
{
get { return _FileName; }
set { _FileName = value; }
}
private PdfPCell _CurrentPageNumberCell = null;
private void OnTransitionProcessed(object sender, EventArgs args) => TransitionProcessed?.Invoke(sender, args);
public event TransitionReportEvent ProcedureProcessed;
private void OnProcedureProcessed(object sender, EventArgs args) => ProcedureProcessed?.Invoke(sender, args);
public event TransitionReportEvent DocVersionProcessed;
private void OnDocVersionProcessed(object sender, EventArgs args) => DocVersionProcessed?.Invoke(sender, args);
public string FileName { get; set; }
private PdfPCell _CurrentPageNumberCell = null;
private int _CurrentPageNumber = 1;
public int CurrentPageNumber
{
@@ -51,41 +38,27 @@ namespace Volian.Print.Library
}
}
}
private FolderInfo folderInfo;
private readonly FolderInfo folderInfo;
private ProcedureInfo procedureInfo;
private TransitionInfoList transitionInfoList;
private int _TransitionInfoCount;
public int TransitionInfoCount
{
get { return _TransitionInfoCount; }
set { _TransitionInfoCount = value; }
}
private List<DocVersionInfo> _MyDocVersionList;
public List<DocVersionInfo> MyDocVersionList
{
get { return _MyDocVersionList; }
set { _MyDocVersionList = value; }
}
private int _ProcedureCount;
public int ProcedureCount
{
get { return _ProcedureCount; }
set { _ProcedureCount = value; }
}
private string _PaperSize = "Letter";
public int TransitionInfoCount { get; set; }
public List<DocVersionInfo> MyDocVersionList { get; set; }
public int ProcedureCount { get; set; }
private readonly string _PaperSize = "Letter";
public PDFTransitionReport(FolderInfo fi, string fileName)
{
_FileName = fileName;
FileName = fileName;
folderInfo = fi;
if (fi.ActiveFormat != null)
_PaperSize = fi.ActiveFormat.PlantFormat.FormatData.PDFPageSize.PaperSize; // C2020-002 paper size is now set in the format files
}
public PDFTransitionReport(ProcedureInfo pi, string fileName)
{
_FileName = fileName;
FileName = fileName;
procedureInfo = pi;
transitionInfoList = TransitionInfoList.GetTransitionReportData(procedureInfo.MyDocVersion.VersionID, procedureInfo.ItemID);
_TransitionInfoCount = transitionInfoList.Count;
TransitionInfoCount = transitionInfoList.Count;
_PaperSize = pi.ActiveFormat.PlantFormat.FormatData.PDFPageSize.PaperSize; // C2020-002 paper size is now set in the format files
}
public void BuildTransitionReport()
@@ -100,13 +73,13 @@ namespace Volian.Print.Library
if (MyDocVersionList.Count == 1)
{
DocVersionInfo dvi = MyDocVersionList[0];
foreach (ProcedureInfo pi in dvi.Procedures)
foreach (ProcedureInfo pi in dvi.Procedures.OfType<ProcedureInfo>())
{
procedureInfo = pi;
transitionInfoList = TransitionInfoList.GetTransitionReportData(dvi.VersionID, procedureInfo.ItemID);
if (transitionInfoList.Count > 0)
{
_TransitionInfoCount = transitionInfoList.Count;
TransitionInfoCount = transitionInfoList.Count;
OnProcedureProcessed(this, new EventArgs());
BuildProcedureReport(document);
}
@@ -122,11 +95,11 @@ namespace Volian.Print.Library
{
ProcedureCount = dvi.Procedures.Count;
OnDocVersionProcessed(this, new EventArgs());
foreach (ProcedureInfo pi in dvi.Procedures)
foreach (ProcedureInfo pi in dvi.Procedures.OfType<ProcedureInfo>())
{
procedureInfo = pi;
transitionInfoList = TransitionInfoList.GetTransitionReportData(dvi.VersionID, procedureInfo.ItemID);
_TransitionInfoCount = transitionInfoList.Count;
TransitionInfoCount = transitionInfoList.Count;
OnProcedureProcessed(this, new EventArgs());
BuildProcedureReport(document);
}
@@ -140,7 +113,6 @@ namespace Volian.Print.Library
}
catch (Exception ex)
{
StringBuilder msg = new StringBuilder();
document.Add(new Paragraph("Error:"));
while (ex != null)
{
@@ -160,11 +132,13 @@ namespace Volian.Print.Library
}
PdfOutline outline = null;
ProcedureInfo lastProcedureInfo = null;
private PdfPTable BuildProcedurePDFTable(Dictionary<int, string> levels, Dictionary<int, iTextSharp.text.Font> fonts, int cols, int paddingBottom, int level, iTextSharp.text.Document doc)
private PdfPTable BuildProcedurePDFTable(Dictionary<int, string> levels, Dictionary<int, iTextSharp.text.Font> fonts, int cols, int paddingBottom, int level)
{
PdfPTable t = new PdfPTable(cols);
t.HeaderRows = 4;
t.DefaultCell.Padding = 4;
PdfPTable t = new PdfPTable(cols)
{
HeaderRows = 4
};
t.DefaultCell.Padding = 4;
t.WidthPercentage = 100;
float[] widths;
if(level == 1 || level == 2 || level == 4)
@@ -172,52 +146,66 @@ namespace Volian.Print.Library
else
widths = new float[] { 33f, 47f, 20f };
t.SetWidths(widths);
//report title
Phrase h = new Phrase();
h.Font = fonts[1];
if (folderInfo != null)
//report title
Phrase h = new Phrase
{
Font = fonts[1]
};
if (folderInfo != null)
h.Add(string.Format("Procedure Set {0} Transition Report", folderInfo.Name));
else
h.Add("Transition Report");
PdfPCell c = new PdfPCell(h);
c.Colspan = cols-1;
c.HorizontalAlignment = Element.ALIGN_LEFT;
c.PaddingBottom = paddingBottom;
c.BackgroundColor = new Color(System.Drawing.Color.DarkGoldenrod);
t.AddCell(c);
//date generated
h = new Phrase();
h.Font = fonts[4];
h.Add(DateTime.Now.ToString("dddd MMMM d, yyyy @ h:mm tt"));
c = new PdfPCell(h);
c.HorizontalAlignment = Element.ALIGN_RIGHT;
c.PaddingBottom = paddingBottom;
c.BackgroundColor = new Color(System.Drawing.Color.DarkGoldenrod);
t.AddCell(c);
//procedure title
h = new Phrase();
h.Font = fonts[2];
h.Add(string.Format("{0} - {1}", procedureInfo.DisplayNumber, procedureInfo.DisplayText));
PdfPCell c = new PdfPCell(h)
{
Colspan = cols - 1,
HorizontalAlignment = Element.ALIGN_LEFT,
PaddingBottom = paddingBottom,
BackgroundColor = new Color(System.Drawing.Color.DarkGoldenrod)
};
t.AddCell(c);
//date generated
h = new Phrase
{
Font = fonts[4]
};
h.Add(DateTime.Now.ToString("dddd MMMM d, yyyy @ h:mm tt"));
c = new PdfPCell(h)
{
HorizontalAlignment = Element.ALIGN_RIGHT,
PaddingBottom = paddingBottom,
BackgroundColor = new Color(System.Drawing.Color.DarkGoldenrod)
};
t.AddCell(c);
//procedure title
h = new Phrase
{
Font = fonts[2]
};
h.Add(string.Format("{0} - {1}", procedureInfo.DisplayNumber, procedureInfo.DisplayText));
PdfDestination dest = new PdfDestination(PdfDestination.FITH, cb.PdfDocument.PageSize.Height);
if (lastProcedureInfo != procedureInfo)
{
outline = new PdfOutline(cb.RootOutline, dest, procedureInfo.DisplayNumber, false);
lastProcedureInfo = procedureInfo;
}
c = new PdfPCell(h);
c.Colspan = cols-1;
c.HorizontalAlignment = Element.ALIGN_LEFT;
c.PaddingBottom = paddingBottom;
c.BackgroundColor = new Color(System.Drawing.Color.Goldenrod);
t.AddCell(c);
c = new PdfPCell(h)
{
Colspan = cols - 1,
HorizontalAlignment = Element.ALIGN_LEFT,
PaddingBottom = paddingBottom,
BackgroundColor = new Color(System.Drawing.Color.Goldenrod)
};
t.AddCell(c);
//page number
_CurrentPageNumberCell = BuildCell(1, string.Format("Page {0}",CurrentPageNumber), fonts[4], new Color(System.Drawing.Color.Goldenrod));
_CurrentPageNumberCell.PaddingBottom = paddingBottom;
t.AddCell(_CurrentPageNumberCell);
//transition category
h = new Phrase();
h.Font = fonts[3];
if (transitionInfoList.Count == 0)
//transition category
h = new Phrase
{
Font = fonts[3]
};
if (transitionInfoList.Count == 0)
h.Add("N/A");
else
{
@@ -225,75 +213,97 @@ namespace Volian.Print.Library
dest = new PdfDestination(PdfDestination.FITH, cb.PdfDocument.PageSize.Height);
new PdfOutline(outline, dest, levels[level]);
}
c = new PdfPCell(h);
c.Colspan = cols;
c.HorizontalAlignment = Element.ALIGN_LEFT;
c.PaddingBottom = paddingBottom;
c.BackgroundColor = new Color(System.Drawing.Color.Khaki);
t.AddCell(c);
//add column headers
h = new Phrase();
h.Font = fonts[4];
h.Add("From Procedure Location");
c = new PdfPCell(h);
c.HorizontalAlignment = Element.ALIGN_CENTER;
c.PaddingBottom = paddingBottom;
c.BackgroundColor = new Color(System.Drawing.Color.PaleGoldenrod);
t.AddCell(c);
h = new Phrase();
h.Font = fonts[4];
h.Add("From Procedure Text");
c = new PdfPCell(h);
c.HorizontalAlignment = Element.ALIGN_CENTER;
c.PaddingBottom = paddingBottom;
c.BackgroundColor = new Color(System.Drawing.Color.PaleGoldenrod);
t.AddCell(c);
h = new Phrase();
h.Font = fonts[4];
h.Add("To Procedure Location");
c = new PdfPCell(h);
c.HorizontalAlignment = Element.ALIGN_CENTER;
c.PaddingBottom = paddingBottom;
c.BackgroundColor = new Color(System.Drawing.Color.PaleGoldenrod);
t.AddCell(c);
c = new PdfPCell(h)
{
Colspan = cols,
HorizontalAlignment = Element.ALIGN_LEFT,
PaddingBottom = paddingBottom,
BackgroundColor = new Color(System.Drawing.Color.Khaki)
};
t.AddCell(c);
//add column headers
h = new Phrase
{
Font = fonts[4]
};
h.Add("From Procedure Location");
c = new PdfPCell(h)
{
HorizontalAlignment = Element.ALIGN_CENTER,
PaddingBottom = paddingBottom,
BackgroundColor = new Color(System.Drawing.Color.PaleGoldenrod)
};
t.AddCell(c);
h = new Phrase
{
Font = fonts[4]
};
h.Add("From Procedure Text");
c = new PdfPCell(h)
{
HorizontalAlignment = Element.ALIGN_CENTER,
PaddingBottom = paddingBottom,
BackgroundColor = new Color(System.Drawing.Color.PaleGoldenrod)
};
t.AddCell(c);
h = new Phrase
{
Font = fonts[4]
};
h.Add("To Procedure Location");
c = new PdfPCell(h)
{
HorizontalAlignment = Element.ALIGN_CENTER,
PaddingBottom = paddingBottom,
BackgroundColor = new Color(System.Drawing.Color.PaleGoldenrod)
};
t.AddCell(c);
return t;
}
PdfContentByte cb;
private void BuildProcedureReport(iTextSharp.text.Document doc)
{
Dictionary<int, string> tranTypes = FormatInfo.GetTransitionTypesByFormatID(procedureInfo.ActiveFormat.FormatID);
Dictionary<int, string> levels = new Dictionary<int, string>();
levels.Add(1, "Internal Transitions");
levels.Add(2, "External From Transitions");
levels.Add(3, "External To Transitions");
levels.Add(4, "Outside From Transitions");
levels.Add(5, "Outside To Transitions");
Dictionary<int, iTextSharp.text.Font> fonts = new Dictionary<int, Font>();
// C2017-036 get best available proportional font for symbols that looks close to Arial
// Note that Microsoft no longer supplies Arial Unicode MS as of Word16
fonts.Add(1, pdf.GetFont(Volian.Base.Library.vlnFont.ReportsFont, 12, 0, Color.BLACK));
fonts.Add(2, pdf.GetFont(Volian.Base.Library.vlnFont.ReportsFont, 10, 0, Color.BLACK));
fonts.Add(3, pdf.GetFont(Volian.Base.Library.vlnFont.ReportsFont, 8, 0, Color.BLACK));
fonts.Add(4, pdf.GetFont(Volian.Base.Library.vlnFont.ReportsFont, 8, 0, Color.BLACK));
Dictionary<int, string> levels = new Dictionary<int, string>
{
{ 1, "Internal Transitions" },
{ 2, "External From Transitions" },
{ 3, "External To Transitions" },
{ 4, "Outside From Transitions" },
{ 5, "Outside To Transitions" }
};
Dictionary<int, iTextSharp.text.Font> fonts = new Dictionary<int, Font>
{
// C2017-036 get best available proportional font for symbols that looks close to Arial
// Note that Microsoft no longer supplies Arial Unicode MS as of Word16
{ 1, pdf.GetFont(Volian.Base.Library.vlnFont.ReportsFont, 12, 0, Color.BLACK) },
{ 2, pdf.GetFont(Volian.Base.Library.vlnFont.ReportsFont, 10, 0, Color.BLACK) },
{ 3, pdf.GetFont(Volian.Base.Library.vlnFont.ReportsFont, 8, 0, Color.BLACK) },
{ 4, pdf.GetFont(Volian.Base.Library.vlnFont.ReportsFont, 8, 0, Color.BLACK) }
};
int lastLevel = transitionInfoList.Count > 0 ? transitionInfoList[0].Level : 0; //set level to first transition level
#region buildtable
int cols = 3;
int paddingBottom = 6;
if (folderInfo != null)
doc.NewPage();
PdfPTable t = BuildProcedurePDFTable(levels, fonts, cols, paddingBottom, lastLevel, doc);
PdfPTable t = BuildProcedurePDFTable(levels, fonts, cols, paddingBottom, lastLevel);
#endregion
//gather data
if (transitionInfoList.Count == 0)
{
Phrase h = new Phrase();
h.Font = fonts[4];
h.Add("This procedure contains no transitions");
PdfPCell c = new PdfPCell(h);
c.Colspan = cols;
c.HorizontalAlignment = Element.ALIGN_LEFT;
c.PaddingBottom = paddingBottom;
t.AddCell(c);
Phrase h = new Phrase
{
Font = fonts[4]
};
h.Add("This procedure contains no transitions");
PdfPCell c = new PdfPCell(h)
{
Colspan = cols,
HorizontalAlignment = Element.ALIGN_LEFT,
PaddingBottom = paddingBottom
};
t.AddCell(c);
}
else
{
@@ -308,37 +318,49 @@ namespace Volian.Print.Library
doc.Add(t);
doc.NewPage();
lastLevel = ti.Level;
t = BuildProcedurePDFTable(levels, fonts, cols, paddingBottom, lastLevel, doc);
t = BuildProcedurePDFTable(levels, fonts, cols, paddingBottom, lastLevel);
}
}
//add from path
Phrase h = new Phrase();
h.Font = fonts[4];
h.Add(StripProcInfo(ti.PathFrom, procedureInfo));
PdfPCell c = new PdfPCell(h);
c.HorizontalAlignment = Element.ALIGN_LEFT;
c.PaddingBottom = paddingBottom;
if (lastLevel > 1 && (!tranTypes[ti.TranType].Contains("{Proc") && !tranTypes[ti.TranType].Contains("other procedure"))) c.BackgroundColor = new Color(System.Drawing.Color.LightCoral);
//add from path
Phrase h = new Phrase
{
Font = fonts[4]
};
h.Add(StripProcInfo(ti.PathFrom, procedureInfo));
PdfPCell c = new PdfPCell(h)
{
HorizontalAlignment = Element.ALIGN_LEFT,
PaddingBottom = paddingBottom
};
if (lastLevel > 1 && (!tranTypes[ti.TranType].Contains("{Proc") && !tranTypes[ti.TranType].Contains("other procedure"))) c.BackgroundColor = new Color(System.Drawing.Color.LightCoral);
t.AddCell(c);
//add from text
h = new Phrase();
h.Font = fonts[4];
ItemInfo myItemInfo = ti.MyContent.ContentItems[0];
//add from text
h = new Phrase
{
Font = fonts[4]
};
ItemInfo myItemInfo = ti.MyContent.ContentItems[0];
h.Add(GetTextPath(myItemInfo, 0));
c = new PdfPCell(h);
c.HorizontalAlignment = Element.ALIGN_LEFT;
c.PaddingBottom = paddingBottom;
if (lastLevel > 1 && (!tranTypes[ti.TranType].Contains("{Proc") && !tranTypes[ti.TranType].Contains("other procedure"))) c.BackgroundColor = new Color(System.Drawing.Color.LightCoral);
c = new PdfPCell(h)
{
HorizontalAlignment = Element.ALIGN_LEFT,
PaddingBottom = paddingBottom
};
if (lastLevel > 1 && (!tranTypes[ti.TranType].Contains("{Proc") && !tranTypes[ti.TranType].Contains("other procedure"))) c.BackgroundColor = new Color(System.Drawing.Color.LightCoral);
t.AddCell(c);
//add to text
h = new Phrase();
h.Font = fonts[4];
myItemInfo = ti.MyItemToID;
//add to text
h = new Phrase
{
Font = fonts[4]
};
myItemInfo = ti.MyItemToID;
h.Add(GetTextPath(myItemInfo, ti.Level));
c = new PdfPCell(h);
c.HorizontalAlignment = Element.ALIGN_LEFT;
c.PaddingBottom = paddingBottom;
if (lastLevel > 1 && (!tranTypes[ti.TranType].Contains("{Proc") && !tranTypes[ti.TranType].Contains("other procedure"))) c.BackgroundColor = new Color(System.Drawing.Color.LightCoral);
c = new PdfPCell(h)
{
HorizontalAlignment = Element.ALIGN_LEFT,
PaddingBottom = paddingBottom
};
if (lastLevel > 1 && (!tranTypes[ti.TranType].Contains("{Proc") && !tranTypes[ti.TranType].Contains("other procedure"))) c.BackgroundColor = new Color(System.Drawing.Color.LightCoral);
t.AddCell(c);
}
}
@@ -357,16 +379,16 @@ namespace Volian.Print.Library
{
StringBuilder sb = new StringBuilder();
if (myItemInfo.IsProcedure)
return myItemInfo.MyProcedure.DisplayNumber + " " + myItemInfo.MyProcedure.DisplayText;
return $"{myItemInfo.MyProcedure.DisplayNumber} {myItemInfo.MyProcedure.DisplayText}";
if (myItemInfo.IsSection)
{
if (level > 1)
return myItemInfo.MyProcedure.DisplayNumber + " " + myItemInfo.MyProcedure.DisplayText + "\r\n " + myItemInfo.DisplayText;
return $"{myItemInfo.MyProcedure.DisplayNumber} {myItemInfo.MyProcedure.DisplayText}\r\n {myItemInfo.DisplayText}";
else
return myItemInfo.DisplayText;
}
if (myItemInfo.IsHigh)
return myItemInfo.ActiveSection.DisplayText + "\r\n " + myItemInfo.DisplayText;
return $"{myItemInfo.ActiveSection.DisplayText}\r\n {myItemInfo.DisplayText}";
else
{
string tmp = "";
@@ -393,10 +415,6 @@ namespace Volian.Print.Library
}
return sb.ToString();
}
public void BuildTransitionReport(FolderInfo fi)
{
System.Windows.Forms.MessageBox.Show("folder");
}
private bool CreateResultsPDF(iTextSharp.text.Document document)
{
bool result = false;
@@ -404,26 +422,20 @@ namespace Volian.Print.Library
int i = 0;
// just for safety, the while loop expects to find a file extension
// so make sure it has one before going into the loop
if (!_FileName.ToUpper().EndsWith(".PDF"))
_FileName += ".pdf";
if (!FileName.ToUpper().EndsWith(".PDF"))
FileName += ".pdf";
// Try to open a file for creating the PDF.
while (result == false)
{
string fileName = _FileName;
// Bug fix: B2013-086
// the folder path part of _FileName contained a folder name with a period
// resulting is an invalid file location/file name.
// Changed the IndexOf call to the LastIndexOf
//int loc = fileName.IndexOf(".");
string fileName = FileName;
int loc = fileName.LastIndexOf(".");
if (loc > -1)
{
string fname = fileName.Substring(0, loc);
fileName = fname + suffix + ".pdf";
fileName = $"{fname}{suffix}.pdf";
}
else
fileName = fileName + suffix + ".pdf";
// string fileName = _FileName.ToLower().Replace(".pdf", suffix + ".pdf");
fileName = $"{fileName}{suffix}.pdf";
try
{
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create));
@@ -431,7 +443,7 @@ namespace Volian.Print.Library
document.SetMargins(36, 36, 36, 36);
document.Open();
cb = writer.DirectContent;
_FileName = fileName;
FileName = fileName;
result = true;
}
catch (System.IO.IOException exIO)
@@ -468,28 +480,25 @@ namespace Volian.Print.Library
}
System.Windows.Forms.MessageBox.Show(msg.ToString(), "Error during PDF creation for search:", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
}
private PdfPCell BlankCell(int colSpan)
{
PdfPCell c = new PdfPCell();
c.Colspan = colSpan;
c.Border = 0;
return c;
}
private PdfPCell BuildCell(int colspan, string txt, Font f, iTextSharp.text.Color clr)
{
Phrase h = new Phrase();
h.Font = f;
h.Add(txt);
PdfPCell c = new PdfPCell(h);
c.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
c.Colspan = colspan;
c.BackgroundColor = clr;
return c;
Phrase h = new Phrase
{
Font = f
};
h.Add(txt);
PdfPCell c = new PdfPCell(h)
{
HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT,
Colspan = colspan,
BackgroundColor = clr
};
return c;
}
}
public class MyPageEvent : PdfPageEventHelper
{
private PDFTransitionReport _rpt = null;
private readonly PDFTransitionReport _rpt = null;
public MyPageEvent(PDFTransitionReport rpt)
{
_rpt = rpt;