Rich 98d8a174fb Changed how DoBeforeTransFlagSupport located replace words string in step text from first location to last location
Added and used new method IncludesParentToHLS to PDFReport to correct how step tab data is displayed in PDF report
2013-07-25 03:38:16 +00:00

1386 lines
53 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using VEPROMS.CSLA.Library;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.IO;
using System.Text.RegularExpressions;
//using Volian.Generic;
namespace Volian.Print.Library
{
public class PDFReport
{
public enum ReportType
{
SearchResults = 0,
LibraryDocUsage = 1,
ReferencedObjectsUsage = 2,
TransitionUsage = 3,
ReferencedObjectSummary = 4,
ReferencedObjectComplete =5
}
private ICollection<ItemInfo> _ResultList;
public ICollection<ItemInfo> ResultList
{
get { return _ResultList; }
set { _ResultList = value; }
}
private string _FileName;
public string FileName
{
get { return _FileName; }
set { _FileName = value; }
}
private string _ReportTitle;
public string ReportTitle
{
get { return _ReportTitle; }
set { _ReportTitle = value; }
}
private string _TypesSelected;
public string TypesSelected
{
get { return _TypesSelected; }
set { _TypesSelected = value; }
}
private bool _ShowAnnotations = true;
public bool ShowAnnotations
{
get { return _ShowAnnotations; }
set { _ShowAnnotations = value; }
}
private string _SearchString;
public string SearchString
{
get { return _SearchString; }
set { _SearchString = VEPROMS.CSLA.Library.ItemInfo.ConvertToDisplayText(value); }
}
private DocumentInfoList _LibDocList;
public DocumentInfoList LibDocList
{
get { return _LibDocList; }
set { _LibDocList = value; }
}
private int _ReportType = 0;
private string _ByLine;
private bool _SortUsageByProcedure = false;
private string _RODataFile = "";
// Search Results Report
public PDFReport(string reportTitle, string typesSelected, ICollection<ItemInfo> resultList, string fileName)
{
_ResultList = resultList;
_FileName = fileName;
_ReportTitle = VEPROMS.CSLA.Library.ItemInfo.ConvertToDisplayText(reportTitle);
_TypesSelected = VEPROMS.CSLA.Library.ItemInfo.ConvertToDisplayText(typesSelected);
_ReportType = (int)ReportType.SearchResults;
_ByLine = "PROMS Search Results";
}
// Library Document Report
public PDFReport(string reportTitle, DocumentInfoList libDocList, string fileName)
{
_LibDocList = libDocList;
_FileName = fileName;
_ReportTitle = VEPROMS.CSLA.Library.ItemInfo.ConvertToDisplayText(reportTitle);
_ReportType = (int)ReportType.LibraryDocUsage;
_ByLine = "Generated By PROMS";
}
// Transition and RO Usage
public PDFReport(string reportTitle, ICollection<ItemInfo> resultList, string fileName, bool sortUsageByProcedure)
{
_ResultList = resultList;
_FileName = fileName;
_ReportTitle = VEPROMS.CSLA.Library.ItemInfo.ConvertToDisplayText(reportTitle);
_ReportType = (int)ReportType.ReferencedObjectsUsage;
_ByLine = "Generated By PROMS";
_SortUsageByProcedure = sortUsageByProcedure;
}
// RO Coomplete and Summary Reports
public PDFReport(string reportTitle, string roDataFile, string outfile, bool completeReport)
{
_FileName = outfile;
_ReportTitle = reportTitle;
_ReportType = (completeReport) ? (int)ReportType.ReferencedObjectComplete : (int)ReportType.ReferencedObjectSummary;
_ByLine = (completeReport) ? "Complete RO Report" : "Summary RO Report";
_RODataFile = roDataFile;
}
//public void Build2()
//{
// iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.LETTER, 36, 36, 36, 36);
// try
// {
// PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(_FileName, FileMode.Create));
// // we add some meta information to the document
// document.SetMargins(36, 36, 36, 36);
// // step 3: we open the document
// document.Open();
// AddTable(document, 20, 80);
// //AddTable(document, 10, 90);
// //AddTable(document, 10, 100);
// //AddTable(document, 15, 75);
// //AddTable(document, 20, 70);
// //AddTable(document, 25, 65);
// //AddTable(document, 30, 60);
// document.Close();
// }
// catch (Exception ex)
// {
// }
//}
//private void AddTable(iTextSharp.text.Document document, int width1, int width2)
//{
// float[] headerwidths = { width1, width2 };
// PdfPTable datatable = new PdfPTable(headerwidths);
// datatable.HeaderRows = 3;
// datatable.FooterRows = 1;
// //datatable.Padding = 4;
// //datatable.DefaultCell.Padding = 4;
// //datatable.Spacing = 0;
// //datatable.setBorder(Rectangle.NO_BORDER);
// //datatable.Widths = headerwidths;
// //datatable.WidthPercentage = 100;
// datatable.TotalWidth = (width1 + width2) * 5;
// datatable.LockedWidth = true;
// // the first cell spans 10 columns
// //iTextSharp.text.Font f1 = FontFactory.GetFont("Arial Unicode MS", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 14, Font.BOLD);
// iTextSharp.text.Font f1 = pdf.GetFont("Arial Unicode MS", 14, 1, Color.BLACK);
// PdfPCell cell = new PdfPCell(new Phrase(ReportTitle, f1));
// //Font f2 = FontFactory.GetFont(FontFactory.HELVETICA, 10);
// //FontFactory.RegisterDirectory(FontFind.FontDir);
// //iTextSharp.text.Font f2 = FontFactory.GetFont("Arial Unicode MS", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10);
// iTextSharp.text.Font f2 = pdf.GetFont("Arial Unicode MS", 10, 0, Color.BLACK);
// //iTextSharp.text.Font f3 = FontFactory.GetFont("Prestige Elite Tall", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 9);
// iTextSharp.text.Font f3 = pdf.GetFont("Prestige Elite Tall", 9, 0, Color.BLACK);
// cell.HorizontalAlignment = Element.ALIGN_CENTER;
// //cell.Leading = 20;
// cell.Colspan = 2;
// //cell.Border = Rectangle.NO_BORDER;
// cell.BackgroundColor = new Color(0xD0, 0xF0, 0xF0);
// datatable.AddCell(cell);
// Color subHeaderColor = new Color(0xD0, 0xF0, 0xD0);
// // These cells span 2 rows
// //datatable.DefaultCellBorderWidth = 2;
// //datatable.DefaultHorizontalAlignment = 1;
// //datatable.DefaultRowspan = 2;
// datatable.DefaultCell.Padding = 4;
// datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
// AddCell(datatable, "Step", f2, subHeaderColor);
// AddCell(datatable, "Text", f2, subHeaderColor);
// AddCell(datatable, "Step", f2, subHeaderColor);
// AddCell(datatable, "Text", f2, subHeaderColor);
// datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
// //datatable.DefaultCellBorderWidth = 1;
// //datatable.DefaultRowspan = 1;
// //datatable.DefaultHorizontalAlignment = Element.ALIGN_LEFT;
// string lastDvPath = "";
// string lastPath = "";
// Color AnnoColor = new Color(0xFF, 0xFF, 0xC0);
// Color TextColor = Color.WHITE;
// Color SectColor = Color.LIGHT_GRAY;
// foreach (ItemInfo item in _ResultList)
// {
// if (item.SearchDVPath != lastDvPath)
// AddGroup(datatable, item.SearchDVPath, lastDvPath, f2, false, new Color(0xC0, 0xFF, 0xC0));
// lastDvPath = item.SearchDVPath;
// //if (item.SearchPath != lastPath)
// string stepPath = AddGroup(datatable, item.SearchPath, lastPath, f2, true, new Color(0xE0, 0xFF, 0xE0));
// lastPath = item.SearchPath;
// AddCell(datatable, stepPath, f2, (item.IsSection ? SectColor : TextColor));
// if (item.DisplayText.Contains("|")) // Need a better way to determine if it is a table.
// AddCell(datatable, item.DisplayText, f3, TextColor);
// else
// AddCell(datatable, item.DisplayText, f2, (item.IsSection ? SectColor : TextColor));
// if (item.ItemAnnotationCount > 0)
// {
// foreach (AnnotationInfo ai in item.ItemAnnotations)
// {
// AddCell(datatable, ai.MyAnnotationType.Name, f2, AnnoColor);
// AddCell(datatable, ai.SearchText, f2, AnnoColor);
// }
// }
// }
// document.Add(datatable);
//}
//private static void AddCell(PdfPTable datatable, string str, iTextSharp.text.Font fnt, Color bgColor)
//{
// PdfPCell cell = new PdfPCell(new Phrase(str, fnt));
// cell.BackgroundColor = bgColor;
// datatable.AddCell(cell);
//}
private string AddGroup(PdfPTable datatable, string dvPath, string lastDvPath, Font f2, bool StripLast, Color bgColor, bool skipFirst)
{
int level = 0;
string retval = "";
StringBuilder sb = new StringBuilder();
string ttt = dvPath.Replace("\x11", " ");
string[] OldPath = lastDvPath.Split("\x7".ToCharArray());
string[] NewPath = dvPath.Split("\x7".ToCharArray());
string sep = "";
bool foundMisMatch = false;
int n = NewPath.Length;
int jstart = (skipFirst) ? 1 : 0;
if (StripLast)
{
retval = NewPath[--n];
if (retval.Contains("\x11"))
retval = retval.Substring(0, retval.IndexOf("\x11")); // this is the step number
}
for (int j = jstart; j < n; j++)
{
if (NewPath[j] != "" && (foundMisMatch || OldPath.Length < j + 1 || NewPath[j] != OldPath[j]))
{
sb.Append(sep + "".PadLeft(2 * level) + NewPath[j].Replace("\x11", " ")).Replace(@"\u8209?", "-");
sep = "\r\n";
foundMisMatch = true;
}
level++;
}
if (sb.ToString() != "")
{
PdfPCell cell = new PdfPCell(new Phrase(sb.ToString(), f2));
cell.Colspan = 2;
cell.BackgroundColor = bgColor;
cell.BorderWidthTop = 1;
datatable.AddCell(cell);
}
return retval;
}
private void AddProcedureSectionGroup(PdfPTable datatable, string curProc, string lastProc, string curSect, string lastSect, Font f2, Color bgColor)
{
string headerText = "";
if (curProc != lastProc)
headerText = curProc + "\r\n";
if (curSect != lastSect)
headerText += " " + curSect;
if (headerText.Length > 0)
{
headerText = headerText.Replace(@"\u8209?", "-");// repace unicode with dash char
headerText = headerText.Replace(@"\u160?", " "); // replace Hard Space with normal Space
PdfPCell cell = new PdfPCell(new Phrase(headerText, f2));
cell.Colspan = 2;
cell.BackgroundColor = bgColor;
cell.BorderWidthTop = 1;
datatable.AddCell(cell);
}
}
private string GetCurProcNum(string path)
{
string[] NewPath = path.Split("\x7".ToCharArray());
string pnumtitle = NewPath[1];
pnumtitle = pnumtitle.Replace('\x11', ' ');
//return NewPath[1].Replace("\x11:"," ");
return pnumtitle;
}
//private string GetCurSectionNumTitle(string path)
//{
// string[] NewPath = path.Split("\x7".ToCharArray());
// int idx = 2; //start of section and subsection num and title
// int stpidx = NewPath.Length - 1; // last position is the step number
// string rtnstr = "";
// while (idx < stpidx)
// {
// rtnstr += NewPath[idx++];
// if (idx < stpidx)
// rtnstr += "\n ";
// }
// return rtnstr; // srting containing section and subsection number/titles
//}
private string GetCurSectionNumTitle(ItemInfo itm)
{
string rtnstr = "";
rtnstr = itm.ActiveSection.DisplayNumber;
if (rtnstr.Length > 0) rtnstr += " ";
rtnstr += itm.ActiveSection.DisplayText;
return rtnstr; // srting containing section and subsection number/titles
}
//private string GetStepNumberFromSearchPath(string path)
//{
// string[] NewPath = path.Split("\x7".ToCharArray());
// int idx = NewPath.Length - 1;
// string retval = NewPath[idx];
// if (retval.Contains("\x11"))
// retval = retval.Substring(0, retval.IndexOf("\x11")); // this is the step number
// return retval;
//}
private int FindSpitLevel()
{
int level = 0;
bool foundMisMatch = false;
string lastPath = "";
foreach (string p in ProcSetList)
{
string[] NewPath = p.Split("\x7".ToCharArray());
if (lastPath != "")
{
string[] OldPath = lastPath.Split("\x7".ToCharArray());
int n = NewPath.Length;
int lvl = 0;
foundMisMatch = false;
for (int j = 0; j < n && !foundMisMatch; j++)
{
if (NewPath[j] != "" && (OldPath.Length < j + 1 || NewPath[j] != OldPath[j]))
foundMisMatch = true;
lvl++;
}
if (level == 0) level = lvl;
if (foundMisMatch)
level = Math.Min(level, lvl);
}
lastPath = p;
if (ProcSetList.Count == 1)
level = NewPath.Length-1;
}
//if (level > 0) level--;
return level;
}
public void AddMainPathGroup(PdfPTable datatable, string dvPath, int splitLevel, Font f2, Color bgColor, int colSpan)
{
int level = 0;
StringBuilder sb = new StringBuilder();
string[] NewPath = dvPath.Split("\x7".ToCharArray());
string sep = "";
int n = NewPath.Length;
for (int j = 1; j < n && j < splitLevel; j++)
{
sb.Append(sep + "".PadLeft(2 * level) + NewPath[j].Replace("\x11", " ")).Replace(@"\u8209?", "-");
sep = "\r\n";
level++;
}
if (sb.ToString() != "")
{
PdfPCell cell = new PdfPCell(new Phrase(sb.ToString(), f2));
cell.Colspan = colSpan;
cell.BackgroundColor = bgColor;
cell.BorderWidthTop = 1;
datatable.AddCell(cell);
}
}
public void AddSubPathGroup(PdfPTable datatable, string dvPath, int splitLevel, Font f2, Color bgColor, int colSpan)
{
int level = 0;
StringBuilder sb = new StringBuilder();
string[] NewPath = dvPath.Split("\x7".ToCharArray());
string sep = "";
int n = NewPath.Length;
if (splitLevel < n)
{
for (int j = splitLevel; j < n; j++)
{
sb.Append(sep + "".PadLeft(2 * level) + NewPath[j].Replace("\x11", " ")).Replace(@"\u8209?", "-");
sep = "\r\n";
level++;
}
if (sb.ToString() != "")
{
PdfPCell cell = new PdfPCell(new Phrase(sb.ToString(), f2));
cell.Colspan = colSpan;
cell.BackgroundColor = bgColor;
cell.BorderWidthTop = 1;
datatable.AddCell(cell);
}
}
}
public void Build()
{
iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.LETTER, 36, 36, 36, 36);
if (!CreateResultsPDF(document)) return;
try
{
switch (_ReportType) // set in the PDFReport constructor
{
case (int)ReportType.SearchResults:
BuildSearchResultsTable(document);
break;
case (int)ReportType.LibraryDocUsage:
BuildLibDocUsageReport(document);
break;
case (int)ReportType.ReferencedObjectsUsage:
if (_SortUsageByProcedure)
BuildROUsageTableByProcedure(document);
else
BuildROUsageTableByRO(document);
break;
case (int)ReportType.ReferencedObjectComplete:
BuildCompleteROReport(document);
break;
}
}
catch (Exception ex)
{
StringBuilder msg = new StringBuilder();
document.Add(new Paragraph("Error:"));
while (ex != null)
{
document.Add(new Paragraph(ex.GetType().Name));
document.Add(new Paragraph(ex.Message));
ex = ex.InnerException;
}
}
finally
{
if (document.IsOpen())
{
document.Close();
System.Diagnostics.Process.Start(_FileName);
}
}
}
/// <summary>
/// Attempt to open a file for the PDF output.
/// If the file cannot be opened because it is in use, try adding a suffix
/// If the file cannot be opened for some other reason, display an error message
/// </summary>
/// <param name="document"></param>
/// <returns></returns>
private bool CreateResultsPDF(iTextSharp.text.Document document)
{
bool result = false;
string suffix = "";
int i = 0;
// Try to open a file for creating the PDF.
while (result == false)
{
string fileName = _FileName.ToLower().Replace(".pdf", suffix + ".pdf");
try
{
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create));
writer.PageEvent = new MyPageHelper(_ByLine); // JSJ - 7/8/2011
document.SetMargins(36, 36, 36, 36);
document.Open();
_FileName = fileName;
result = true;
}
catch (System.IO.IOException exIO)
{
if (exIO.Message.Contains("because it is being used by another process"))
suffix = string.Format("_{0}", ++i);// If this file is in use, increment the suffix and try again
else // If some other error, display a message and don't print the results
{
ShowException(exIO);
return false;
}
}
catch (Exception ex)
{
ShowException(ex);
return false; // Could not open the output file
}
}
return true;
}
private static void ShowException(Exception ex)
{
Console.WriteLine("{0} - {1}", ex.GetType().Name, ex.Message);
StringBuilder msg = new StringBuilder();
string sep = "";
string indent = "";
while (ex != null)
{
msg.Append(string.Format("{0}{1}{2}:\r\n{1}{3}", sep, indent, ex.GetType().Name, ex.Message));
ex = ex.InnerException;
sep = "\r\n";
indent += " ";
}
System.Windows.Forms.MessageBox.Show(msg.ToString(), "Error during PDF creation for search:", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
}
/// <summary>
/// Use Cells within Cells to see if I can limit the way Cells break from Page to Page
/// </summary>
/// <param name="document"></param>
private void BuildSearchResultsTable(iTextSharp.text.Document document)
{
float[] headerwidths = { 20, 80 };
PdfPTable datatable = new PdfPTable(1);
PdfPTable colHeader = new PdfPTable(headerwidths);
//datatable.FooterRows = 1;
datatable.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
datatable.LockedWidth = true;
//FontFactory.RegisterDirectory(FontFind.FontDir);
//iTextSharp.text.Font f1 = FontFactory.GetFont("Arial Unicode MS", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 14, Font.BOLD);
//iTextSharp.text.Font f2 = FontFactory.GetFont("Arial Unicode MS", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10);
//iTextSharp.text.Font f3 = FontFactory.GetFont("Prestige Elite Tall", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 9);
iTextSharp.text.Font f1 = pdf.GetFont("Arial Unicode MS", 14, 1, Color.BLACK);
iTextSharp.text.Font f2 = pdf.GetFont("Arial Unicode MS", 10, 0, Color.BLACK);
iTextSharp.text.Font f3 = pdf.GetFont("Arial Unicode MS", 12, 0, Color.BLACK);
//iTextSharp.text.Font f3 = pdf.GetFont("Prestige Elite Tall", 9, 0, Color.BLACK);
PdfPCell cell = new PdfPCell(new Phrase(ReportTitle, f1));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
//cell.Colspan = 2;
cell.BackgroundColor = new Color(0xD0, 0xF0, 0xF0);
datatable.AddCell(cell);
cell = new PdfPCell(new Phrase(TypesSelected,f3));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
//cell.Colspan = 2;
cell.BackgroundColor = new Color(0xD0, 0xF0, 0xF0);
datatable.AddCell(cell);
BuildSearchResultsProcSetList();
datatable.HeaderRows = 3 + (ProcSetList.Count ==1 ? 1 : 0);
int splitAt = FindSpitLevel(); // find the split level of the common path - for all procedure sets that use these library documents
//AddMainPathGroup(datatable, ProcSetList[0].ToString(), splitAt, f2, Color.LIGHT_GRAY, 0);
Color subHeaderColor = new Color(0xD0, 0xF0, 0xD0);
datatable.DefaultCell.Padding = 4;
datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
//AddCell(datatable, "Step", f2, subHeaderColor);
//AddCell(datatable, "Text", f2, subHeaderColor);
AddCell(colHeader, "Step", f2, subHeaderColor);
AddCell(colHeader, "Text", f2, subHeaderColor);
//datatable.AddCell(colHeader);
// This puts "Step" and "Text" column headers at the bottom of the page
//AddCell(datatable, "Step", f2, subHeaderColor);
//AddCell(datatable, "Text", f2, subHeaderColor);
datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
//string lastDvPath = "";
string lastPath = "";
Color AnnoColor = new Color(0xFF, 0xFF, 0xC0);
Color TextColor = Color.WHITE;
Color SectColor = new Color(0xE0, 0xFF, 0xE0);//new Color(0xC0, 0xFF, 0xC0);//Color.LIGHT_GRAY;
PdfPTable subTable = new PdfPTable(headerwidths);
string lastProcNum = "";
string lastDVPath = "";
foreach (ItemInfo item in _ResultList)
{
if (lastDVPath != item.SearchDVPath)
{
datatable.AddCell(subTable);
subTable = new PdfPTable(headerwidths);
AddMainPathGroup(datatable, item.SearchDVPath, splitAt, f2, Color.LIGHT_GRAY, 0);
datatable.AddCell(colHeader);
lastProcNum = "";
}
lastDVPath = item.SearchDVPath;
string curProcNum = GetCurProcNum(item.SearchPath);
if (lastProcNum != "" && curProcNum != lastProcNum)
{
datatable.AddCell(subTable);
subTable = new PdfPTable(headerwidths);
}
lastProcNum = curProcNum;
//if (item.SearchDVPath != lastDvPath)
// AddGroup(datatable, item.SearchDVPath, lastDvPath, f2, false, Color.LIGHT_GRAY, true);
//AddGroup(datatable, item.SearchDVPath, lastDvPath, f2, false, new Color(0xC0, 0xFF, 0xC0), true);
//lastDvPath = item.SearchDVPath;
//string stepPath = AddGroup(datatable, item.SearchPath, lastPath, f2, true, new Color(0xE0, 0xFF, 0xE0), true);
//string stepPath = AddGroup(datatable, item.SearchPath, lastPath, f2, true, new Color(0xC0, 0xFF, 0xC0), true);
string stepPath = AddGroup(subTable, item.SearchPath ?? item.ShortPath, lastPath, f2, true, new Color(0xC0, 0xFF, 0xC0), true);
lastPath = item.SearchPath ?? item.ShortPath;
//AddCell(datatable, stepPath, f2, (item.IsSection ? SectColor : TextColor));
stepPath = BuildStepTab(item);
AddCell(subTable, stepPath, f2, (item.IsSection ? SectColor : TextColor));
// This was for the old 16-bit style of table - jsj 7/7/2011
//if (item.DisplayText.Contains("|")) // Need a better way to determine if it is a table.
// AddCell(datatable, item.DisplayText, f3, TextColor);
//else
//AddCell(datatable, item.DisplayText, f2, (item.IsSection ? SectColor : TextColor));
AddCell(subTable, item.DisplayText, f2, (item.IsSection ? SectColor : TextColor));
if (item.ItemAnnotationCount > 0)
{
foreach (AnnotationInfo ai in item.ItemAnnotations)
{
//AddCell(datatable, ai.MyAnnotationType.Name, f2, AnnoColor);
//AddCell(datatable, ai.SearchText, f2, AnnoColor);
AddCell(subTable, ai.MyAnnotationType.Name, f2, AnnoColor);
AddCell(subTable, ai.SearchText, f2, AnnoColor);
}
}
}
datatable.AddCell(subTable);
document.Add(datatable);
}
private void AddCell(PdfPTable datatable, string str, iTextSharp.text.Font fnt, Color bgColor)
{
iTextSharp.text.Font fntBold = new Font(fnt.BaseFont, fnt.Size, Font.BOLD, Color.RED);
Phrase p = BuildPhrase2(str, fnt, fntBold);
PdfPCell cell = new PdfPCell(p);
cell.PaddingBottom = 4;
cell.BackgroundColor = bgColor;
datatable.AddCell(cell);
}
private void AddColSpanCell(PdfPTable datatable, string str, iTextSharp.text.Font fnt, Color bgColor, int span, int txtAlign)
{
iTextSharp.text.Font fntBold = new Font(fnt.BaseFont, fnt.Size, Font.BOLD, Color.RED);
Phrase p = BuildPhrase2(str, fnt, fntBold);
PdfPCell cell = new PdfPCell(p);
cell.PaddingBottom = 4;
cell.BackgroundColor = bgColor;
cell.Colspan = span;
cell.HorizontalAlignment = txtAlign;
datatable.AddCell(cell);
}
private Phrase BuildPhrase(string str, Font fnt, Font fntBold)
{
Phrase p = new Phrase();
if (_SearchString != null)
{
while (str.ToLower().Contains(_SearchString.ToLower()))
{
int iStart = str.ToLower().IndexOf(_SearchString.ToLower());
if (iStart > 0) p.Add(new Phrase(str.Substring(0, iStart), fnt));
Phrase p2 = new Phrase(str.Substring(iStart, _SearchString.Length), fntBold);
p.Add(p2);
str = str.Substring(iStart + _SearchString.Length);
}
}
if (str.Length > 0) p.Add(new Phrase(str, fnt));
return p;
}
private string _RegexSearchString = null;
private string RegexSearchString
{
get
{
if (_RegexSearchString == null)
{
_RegexSearchString = _SearchString;
// Make it match the smallest matching string
_RegexSearchString = _RegexSearchString.Replace("*", ".*?");
// If search string starts with a wildcard use the beginning of line token (^)
if (_RegexSearchString.StartsWith(".*?"))
_RegexSearchString = "^" + _RegexSearchString;
// If search string ends with a wildcard use the end of line token ($)
if(_RegexSearchString.EndsWith(".*?"))
_RegexSearchString = _RegexSearchString+"$";
_RegexSearchString = _RegexSearchString.Replace("[", @"\[");
_RegexSearchString = _RegexSearchString.Replace("]", @"\]");
}
return _RegexSearchString;
}
}
private Phrase BuildPhrase2(string str, Font fnt, Font fntBold)
{
Phrase p = new Phrase();
int lastIndex = 0;
if ((_SearchString ?? "") != "")
{
Regex reg = new Regex(RegexSearchString, RegexOptions.Multiline | RegexOptions.IgnoreCase);
foreach (Match m in reg.Matches(str))
{
if (m.Index > 0)
p.Add(new Phrase(str.Substring(lastIndex, m.Index - lastIndex), fnt));
Chunk chk = new Chunk(m.Value, fnt);
//Phrase p2 = new Phrase();
//foreach (Chunk chk in p2.Chunks)
chk.SetBackground(Color.YELLOW);
p.Add(chk);
lastIndex = m.Index + m.Length;
}
}
p.Add(new Phrase(str.Substring(lastIndex), fnt));
return p;
}
private void BuildLibDocUsageReport(iTextSharp.text.Document document)
{
float[] headerwidths = { 20, 80 };
PdfPTable datatable = new PdfPTable(1);// (headerwidths);
PdfPTable colheader = new PdfPTable(headerwidths);
datatable.HeaderRows = 3;
datatable.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
datatable.LockedWidth = true;
iTextSharp.text.Font f1 = pdf.GetFont("Arial Unicode MS", 14, 1, Color.BLACK);
iTextSharp.text.Font f2 = pdf.GetFont("Arial Unicode MS", 10, 0, Color.BLACK);
iTextSharp.text.Font f3 = pdf.GetFont("Arial Unicode MS", 12, 0, Color.BLACK);
PdfPCell cell = new PdfPCell(new Phrase(ReportTitle, f1));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
//cell.Colspan = 2;
cell.BackgroundColor = new Color(0xD0, 0xF0, 0xF0);
datatable.AddCell(cell);
BuildLibDocProcSetList();
int splitAt = FindSpitLevel(); // find the split level of the common path - for all procedure sets that use these library documents
AddMainPathGroup(datatable, ProcSetList[0].ToString(), splitAt, f2, Color.LIGHT_GRAY, 0);//2);
Color subHeaderColor = new Color(0xD0, 0xF0, 0xD0);
datatable.DefaultCell.Padding = 4;
datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
//AddCell(datatable, "Procedure", f2, subHeaderColor);
//AddCell(datatable, "Section", f2, subHeaderColor);
AddCell(colheader, "Procedure", f2, subHeaderColor);
AddCell(colheader, "Section", f2, subHeaderColor);
datatable.AddCell(colheader);
datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
string lastDvPath = "";
Color AnnoBackgroundColor = new Color(0xFF, 0xFF, 0xC0);
Color TextBackgroundColor = Color.WHITE;
Color NotUsedBackgroundColor = Color.WHITE;
//BuildProcSetList();
//int splitAt = FindSpitLevel(); // find the split level of the common path - for all procedure sets that use these library documents
//bool doMainProcSetpath = true;
foreach (DocumentInfo di in _LibDocList)
{
PdfPTable subtable = new PdfPTable(headerwidths);
subtable.HeaderRows = 0;
//if (doMainProcSetpath)
//{
// AddMainPathGroup(datatable, ProcSetList[0].ToString(), splitAt, f2, Color.LIGHT_GRAY, 0);//2);
// doMainProcSetpath = false;
//}
//AddGroup(datatable, di.DocumentTitle, "", f2, false, new Color(0xC0, 0xFF, 0xC0)); // Library Document Title
AddGroup(subtable, di.DocumentTitle, "", f2, false, new Color(0xC0, 0xFF, 0xC0), false); // Library Document Title
if (di.DocumentConfig.LibDoc_Comment != null && di.DocumentConfig.LibDoc_Comment.Length > 0)
{
//AddCell(datatable, "Comment", f2, AnnoBackgroundColor);
//AddCell(datatable, di.DocumentConfig.LibDoc_Comment, f2, AnnoBackgroundColor); // lib doc comment
AddCell(subtable, "Comment", f2, AnnoBackgroundColor);
AddCell(subtable, di.DocumentConfig.LibDoc_Comment, f2, AnnoBackgroundColor); // lib doc comment
}
if (di.DocumentEntries == null || di.DocumentEntries.Count == 0)
{
//AddColSpanCell(datatable, "*No References To This Library Document", f2, NotUsedBackgroundColor, 2, Element.ALIGN_LEFT);
AddColSpanCell(subtable, "*No References To This Library Document", f2, NotUsedBackgroundColor, 2, Element.ALIGN_LEFT);
}
else
{
System.Collections.ArrayList LibDocUsageList = GetSortedItemInfoList(di.LibraryDocumentUsageList);
lastDvPath = "";
foreach (ItemInfo item in LibDocUsageList)//di.LibraryDocumentUsageList)
{
string ProcNumber = item.MyProcedure.ProcedureConfig.Number;
ProcNumber = ProcNumber.Replace(@"\u8209?", "-"); // repace unicode with dash char
ProcNumber = ProcNumber.Replace(@"\u160?", " "); // replace Hard Space with normal Space
//if (item.SearchDVPath != lastDvPath)
// AddGroup(datatable, item.SearchDVPath, lastDvPath, f2, false, Color.LIGHT_GRAY);//new Color(0xC0, 0xFF, 0xC0));
//if (item.SearchDVPath != lastDvPath)
// AddSubPathGroup(datatable, item.SearchDVPath,splitAt, f2, Color.LIGHT_GRAY, 2);//new Color(0xC0, 0xFF, 0xC0));
if (item.SearchDVPath != lastDvPath)
AddSubPathGroup(subtable, item.SearchDVPath, splitAt, f2, Color.LIGHT_GRAY, 2);//new Color(0xC0, 0xFF, 0xC0));
lastDvPath = item.SearchDVPath;
//AddCell(datatable, ProcNumber, f2, TextBackgroundColor);
//AddCell(datatable, item.MyContent.Number + " - " + item.MyContent.Text, f2, TextBackgroundColor);
AddCell(subtable, ProcNumber, f2, TextBackgroundColor);
AddCell(subtable, item.MyContent.Number + " - " + item.MyContent.Text, f2, TextBackgroundColor);
}
}
datatable.AddCell(subtable);
}
document.Add(datatable);
}
private void AddROUsages(ItemInfo item, Dictionary<string,List<ItemInfo>> roUse)
{
//string lastROid = "";
if (item.FoundROID != null && item.FoundROID != "")
{
string roid = item.FoundROID;
if (roUse.ContainsKey(roid))
((List<ItemInfo>)roUse[roid]).Add(item);
else
{
List<ItemInfo> itmIfoLst = new List<ItemInfo>();
itmIfoLst.Add(item);
roUse.Add(roid, itmIfoLst);
}
}
}
private void PutROusageForProcedure(PdfPTable curTable, Dictionary<string, List<ItemInfo>> rosused, float[] headerwidths)
{
//if (rosused.Count == 0) return; // nothing to process
iTextSharp.text.Font f2 = pdf.GetFont("Arial Unicode MS", 10, 0, Color.BLACK);
foreach (string roKey in rosused.Keys)
{
PdfPTable rotable = new PdfPTable(headerwidths);
string rotitle = "";
foreach (ItemInfo itm in rosused[roKey])
{
if (rotitle == "")
{
//ROFSTLookup myrofstlookup = itm.MyDocVersion.DocVersionAssociations[0].MyROFst.ROFSTLookup;
//List<string> roTitleList = myrofstlookup.GetROTitleAndGroupPath(roKey);
//for (int cnt = 0; cnt < roTitleList.Count; cnt++)
//{
// if (cnt == roTitleList.Count - 1)
// //rotitle += string.Format("<{0}> {1} {2}", myrofstlookup.GetRoACID(roKey), myrofstlookup.GetTranslatedRoValue(roKey, true), roTitleList[cnt]);
// rotitle += roTitleList[cnt];
// else
// rotitle += roTitleList[cnt] + "\n ";
//}
rotitle = GetROTitleAndGroup(roKey, itm);
PdfPCell ROTitleCell = new PdfPCell(new Phrase(rotitle, f2));
ROTitleCell.Colspan = 2;
ROTitleCell.HorizontalAlignment = Element.ALIGN_LEFT;
ROTitleCell.BackgroundColor = new Color(0xDC, 0xE7, 0xC9); //new Color(0xD0, 0xF0, 0xD0);//ligt green //new Color(0xC8, 0xC8, 0x91);//(0xAF, 0xD8, 0xD8);//(0xF5, 0xE4, 0xA0);
//curTable.AddCell(ROTitleCell); // put RO value and description
rotable.AddCell(ROTitleCell); // put RO value and description
}
string stepnum = "";
string sectitle = itm.ActiveSection.DisplayText;
if (itm.IsSection)
stepnum = itm.MyActiveSection.DisplayNumber;
else
stepnum = BuildStepTab(itm);//GetStepNumberFromSearchPath(itm.SearchPath);//stepnum.Substring(itm.SearchPath.LastIndexOf(sectitle) + sectitle.Length +1);
// stepnum = stepnum.Substring(stepnum.LastIndexOf("\a") + 1);
//AddCell(curTable, stepnum, f2, Color.WHITE);
//AddCell(curTable, itm.DisplayText, f2, Color.WHITE);
AddCell(rotable, stepnum, f2, Color.WHITE);
AddCell(rotable, itm.DisplayText, f2, Color.WHITE);
}
curTable.AddCell(rotable);
}
}
private static string BuildStepTab(ItemInfo item)
{
if (item == null) return "";
string sret = "";
switch (item.MyContent.Type / 10000)
{
case 0: //procedure
sret = ProcedureInfo.Get(item.ItemID).MyTab.CleanText;
break;
case 1: // section
sret = SectionInfo.Get(item.ItemID).MyTab.CleanText;
break;
case 2: // step
ItemInfo pitem = item;
bool hasDelim = item.ActiveFormat.PlantFormat.FormatData.TransData.StepSubstepDelimeter != null;
List<string> DelimList = null;
DelimList = new List<string>();
if (!hasDelim)
{
SeqTabFmtList seqtabs = item.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.SeqTabFmtList;
foreach (SeqTabFmt seqtab in seqtabs)
{
string delim = seqtab.PrintTabFormat.Replace("{seq}", "");
if (!DelimList.Contains(delim))
DelimList.Add(delim.Trim());
}
}
else
{
string stpdelms = item.ActiveFormat.PlantFormat.FormatData.TransData.StepSubstepDelimeter;
foreach (char c in stpdelms)
{
if (!DelimList.Contains(c.ToString()))
DelimList.Add(c.ToString());
}
}
while (!pitem.IsHigh)
{
StepInfo stpinfo = StepInfo.Get(pitem.ItemID);
string thisTab = stpinfo.MyTab.CleanText; //StepInfo.Get(pitem.ItemID).MyTab.CleanText;
if (IncludesParentToHLS(stpinfo))
return thisTab;
string typeName = stpinfo.FormatStepData.StepEditData.TypeMenu.MenuItem;//stpinfo.FormatStepData.ToString();
// remove delimiters of '.' and ')' in tab.
//if (thisTab != null && !hasDelim)
if (thisTab != null)
{
// get list of delimiters to remove from the format:
foreach (string rmvDelim in DelimList) thisTab = thisTab.Replace(rmvDelim, "");
}
if (thisTab != null) thisTab = thisTab.Trim();
// if the tab is null or
// if the the tab is not a letter or number OR
// the tab is an AND or OR type and is the letter "o"
// then reset the tab an empty string so that the type name along with the count of that type
// (ex. "AND 2", "OR 3")
if (thisTab == null || (thisTab != "" && (!(char.IsLetterOrDigit(thisTab[0])) || ((pitem.IsAnd || pitem.IsOr || pitem.IsCaution || pitem.IsNote) && thisTab.Contains("o")))))
thisTab = "";
if (pitem.IsRNOPart)
{
if (thisTab == "")
sret = "RNO." + sret; //"RNO." + sret;
else
{
thisTab = thisTab.Trim(" ".ToCharArray());
if (!thisTab.EndsWith(".") && !thisTab.EndsWith(")")) thisTab = thisTab + ".";
sret = "RNO." + thisTab + sret; //"RNO." + thisTab + sret;
}
}
else if (pitem.IsCaution || pitem.IsNote)
{
// add the Caution or Note count to the tab (ex "Caution 1", "Note 2")
if (thisTab == "")
sret = "{" + typeName + " " + pitem.Ordinal.ToString() + "}";
else
{
thisTab = thisTab.Trim(" ".ToCharArray());
//sret = "." + thisTab + " " + pitem.Ordinal.ToString() + sret;
sret = thisTab + " " + pitem.Ordinal.ToString() + sret;
}
}
else
{
if (thisTab != "")
{
thisTab = thisTab.Trim(" ".ToCharArray());
//if (hasDelim && !thisTab.EndsWith(".") && !thisTab.EndsWith(")")) thisTab = thisTab + ".";
if (!thisTab.EndsWith(".") && !thisTab.EndsWith(")")) thisTab = thisTab + ".";
}
else
thisTab = "{" + typeName + " " + pitem.Ordinal.ToString() + "}.";
//sret = "." + thisTab + sret;
sret = thisTab + sret;
}
pitem = pitem.ActiveParent as ItemInfo;
if (pitem == null) break;
}
// add hls tab if it's not already in the tab.
if (pitem.IsHigh)
{
StepInfo stpinfo = StepInfo.Get(pitem.ItemID);
string hlsTab = stpinfo.MyTab.CleanTextNoSymbols; //StepInfo.Get(pitem.ItemID).MyTab.CleanTextNoSymbols;
//string thisTab = stpinfo.MyTab.CleanText; //StepInfo.Get(pitem.ItemID).MyTab.CleanText;
string typeName = stpinfo.FormatStepData.StepEditData.TypeMenu.MenuItem;//stpinfo.FormatStepData.GetPDDisplayName(); //.ToString();
if (hlsTab == null || hlsTab == "")
hlsTab = "{" + typeName + " "+ pitem.Ordinal.ToString()+"}.";
else if (!sret.StartsWith(hlsTab.Trim(" ".ToCharArray())))
{
//if (!hasDelim)
foreach (string rmvDelim in DelimList) hlsTab = hlsTab.Replace(rmvDelim, "");
hlsTab = hlsTab.Trim(" ".ToCharArray());
//if (hasDelim && !hlsTab.EndsWith(".") && !hlsTab.EndsWith(")")) hlsTab = hlsTab + ".";
if (!hlsTab.EndsWith(".") && !hlsTab.EndsWith(")")) hlsTab = hlsTab + ".";
}
sret = hlsTab + sret;
}
break;
}
sret = sret.Trim(" .)".ToCharArray());
return sret;
}
private static bool IncludesParentToHLS(StepInfo stpinfo)
{
if (stpinfo.IsHigh)
return true;
StepInfo parent = StepInfo.Get((stpinfo.ActiveParent as ItemInfo).ItemID);
if (stpinfo.MyTab.CleanText.StartsWith(parent.MyTab.CleanText.Trim()) && stpinfo.MyTab.CleanText.Length > parent.MyTab.CleanText.Length)
return IncludesParentToHLS(parent);
return false;
}
private void BuildROUsageTableByProcedure(iTextSharp.text.Document document)
{
Dictionary<string, List<ItemInfo>> roUse = new Dictionary<string, List<ItemInfo>>();
float[] headerwidths = { 20, 80 };
PdfPTable datatable = new PdfPTable(1);
PdfPTable colHeader = new PdfPTable(headerwidths);
//datatable.FooterRows = 1;
datatable.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
datatable.LockedWidth = true;
iTextSharp.text.Font f1 = pdf.GetFont("Arial Unicode MS", 14, 1, Color.BLACK);
iTextSharp.text.Font f2 = pdf.GetFont("Arial Unicode MS", 10, 0, Color.BLACK);
iTextSharp.text.Font f3 = pdf.GetFont("Arial Unicode MS", 12, 0, Color.BLACK);
PdfPCell cell = new PdfPCell(new Phrase(ReportTitle, f1));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
//cell.Colspan = 2;
cell.BackgroundColor = new Color(0xD0, 0xF0, 0xF0); // light blue
datatable.AddCell(cell);
BuildSearchResultsProcSetList();
datatable.HeaderRows = 2;//3 + (ProcSetList.Count == 1 ? 1 : 0);
int splitAt = FindSpitLevel(); // find the split level of the common path - for all procedure sets that use these library documents
Color subHeaderColor = new Color(0xD0, 0xF0, 0xF0); // light blue //new Color(0xD0, 0xF0, 0xD0);//ligt green
datatable.DefaultCell.Padding = 4;
datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
// This puts "Step" and "Text" column headers at the bottom of the page
AddCell(colHeader, "Step", f2, subHeaderColor);
AddCell(colHeader, "Text", f2, subHeaderColor);
datatable.AddCell(colHeader);
datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
//string lastPath = "";
Color AnnoColor = new Color(0xFF, 0xFF, 0xC0);
Color TextColor = Color.WHITE;
Color SectColor = new Color(0xE0, 0xFF, 0xE0);//new Color(0xC0, 0xFF, 0xC0);//Color.LIGHT_GRAY;
PdfPTable subTable = new PdfPTable(headerwidths);
datatable.AddCell(subTable);
string lastProcNum = "";
string lastSection = "";
string lastDVPath = "";
foreach (ItemInfo item in _ResultList)
{
// Check Doc Version path
if (lastDVPath != item.SearchDVPath)
{
subTable = new PdfPTable(headerwidths);
AddMainPathGroup(datatable, item.SearchDVPath, splitAt, f2, Color.LIGHT_GRAY, 0);
lastProcNum = "";
lastSection = "";
}
lastDVPath = item.SearchDVPath;
//check for different procedure number
string curProcNum = GetCurProcNum(item.SearchPath);
string curSection = GetCurSectionNumTitle(item);
if (lastProcNum != "" && (curProcNum != lastProcNum))
{
if (roUse.Count > 0)
{
PutROusageForProcedure(datatable, roUse, headerwidths);
roUse.Clear();
}
lastSection = "";
}
if (lastSection != "" && (curSection != lastSection))
{
if (roUse.Count > 0)
{
PutROusageForProcedure(datatable, roUse, headerwidths);
roUse.Clear();
}
}
AddROUsages(item, roUse); // add the used ro to the list for this procedure
AddProcedureSectionGroup(datatable, curProcNum, lastProcNum, curSection, lastSection, f2, new Color(0xC0, 0xFF, 0xC0));
lastProcNum = curProcNum;
lastSection = curSection;
}
PutROusageForProcedure(datatable, roUse, headerwidths);
document.Add(datatable);
}
private void AddProcROUse(ItemInfo item, SortedDictionary<string, List<ItemInfo>> procRoUse)
{
string dictKey = GetCurProcNum(item.SearchPath) + " " + GetCurSectionNumTitle(item);
if (dictKey != null && dictKey != "")
{
if (procRoUse.ContainsKey(dictKey))
((List<ItemInfo>)procRoUse[dictKey]).Add(item);
else
{
List<ItemInfo> itmIfoLst = new List<ItemInfo>();
itmIfoLst.Add(item);
procRoUse.Add(dictKey, itmIfoLst);
}
}
}
private void PutStepListForProcedure(PdfPTable rotable, SortedDictionary<string, string> sortedStepList)
{
iTextSharp.text.Font f2 = pdf.GetFont("Arial Unicode MS", 10, 0, Color.BLACK);
foreach (string stepnum in sortedStepList.Keys)
{
AddCell(rotable, stepnum, f2, Color.WHITE);
AddCell(rotable, sortedStepList[stepnum], f2, Color.WHITE);
}
sortedStepList.Clear();
}
private void PutROusageForROID(PdfPTable curTable, SortedDictionary<string, List<ItemInfo>> procRoUse, float[] headerwidths)
{
SortedDictionary<string, string> sortedStepList = new SortedDictionary<string, string>();
//if (rosused.Count == 0) return; // nothing to process
iTextSharp.text.Font f2 = pdf.GetFont("Arial Unicode MS", 10, 0, Color.BLACK);
string lastProcKey = "";
string lastProcNumTitle = "";
string curProcNumTitle = "";
foreach (string procKey in procRoUse.Keys)
{
PdfPTable rotable = new PdfPTable(headerwidths);
foreach (ItemInfo itm in procRoUse[procKey])
{
if (procKey != lastProcKey)
{
if (sortedStepList.Count > 0) PutStepListForProcedure(rotable, sortedStepList);
//string procNumTitleSect = GetCurProcNum(itm.SearchPath) + "\r\n " + GetCurSectionNumTitle(itm);
string procNumTitleSect = "";
curProcNumTitle = GetCurProcNum(itm.SearchPath);
if (lastProcNumTitle == "" || lastProcNumTitle != curProcNumTitle)
{
procNumTitleSect = curProcNumTitle + "\r\n";
lastProcNumTitle = curProcNumTitle;
}
procNumTitleSect += " " + GetCurSectionNumTitle(itm);
procNumTitleSect = procNumTitleSect.Replace(@"\u8209?", "-"); // repace unicode with dash char
procNumTitleSect = procNumTitleSect.Replace(@"\u160?", " "); // replace Hard Space with normal Space
PdfPCell ProcTitleCell = new PdfPCell(new Phrase(procNumTitleSect, f2));
ProcTitleCell.Colspan = 2;
ProcTitleCell.HorizontalAlignment = Element.ALIGN_LEFT;
ProcTitleCell.BackgroundColor = new Color(0xDC, 0xE7, 0xC9); //new Color(0xD0, 0xF0, 0xD0);//ligt green //new Color(0xC8, 0xC8, 0x91);//(0xAF, 0xD8, 0xD8);//(0xF5, 0xE4, 0xA0);
rotable.AddCell(ProcTitleCell); // put RO value and description
lastProcKey = procKey;
}
string stepnum = "";
string sectitle = itm.ActiveSection.DisplayText;
if (itm.IsSection)
stepnum = itm.MyActiveSection.DisplayNumber;
else
stepnum = BuildStepTab(itm);//GetStepNumberFromSearchPath(itm.SearchPath);//stepnum.Substring(itm.SearchPath.LastIndexOf(sectitle) + sectitle.Length +1);
sortedStepList.Add(stepnum, itm.DisplayText);
//AddCell(rotable, stepnum, f2, Color.WHITE);
//AddCell(rotable, itm.DisplayText, f2, Color.WHITE);
}
if (sortedStepList.Count > 0) PutStepListForProcedure(rotable, sortedStepList);
curTable.AddCell(rotable);
}
}
private static string GetROTitleAndGroup(string roid, ItemInfo itm)
{
string rotitle = "";
ROFSTLookup myrofstlookup = itm.MyDocVersion.DocVersionAssociations[0].MyROFst.ROFSTLookup;
List<string> roTitleList = myrofstlookup.GetROTitleAndGroupPath(roid);
for (int cnt = 0; cnt < roTitleList.Count; cnt++)
{
if (cnt == roTitleList.Count - 1)
rotitle += roTitleList[cnt];
else
rotitle += roTitleList[cnt] + "\n ";
}
return rotitle;
}
private void AddROHeaderGroup(PdfPTable datatable, string curROID, ItemInfo itm, Font f2, Color bgColor)
{
string headerText = GetROTitleAndGroup(curROID, itm);
if (headerText.Length > 0)
{
PdfPCell cell = new PdfPCell(new Phrase(headerText, f2));
cell.Colspan = 2;
cell.BackgroundColor = bgColor;
cell.BorderWidthTop = 1;
datatable.AddCell(cell);
}
}
private void BuildROUsageTableByRO(iTextSharp.text.Document document)
{
SortedDictionary<string, List<ItemInfo>> procRoUse = new SortedDictionary<string, List<ItemInfo>>();
float[] headerwidths = { 20, 80 };
PdfPTable datatable = new PdfPTable(1);
PdfPTable colHeader = new PdfPTable(headerwidths);
//datatable.FooterRows = 1;
datatable.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
datatable.LockedWidth = true;
iTextSharp.text.Font f1 = pdf.GetFont("Arial Unicode MS", 14, 1, Color.BLACK);
iTextSharp.text.Font f2 = pdf.GetFont("Arial Unicode MS", 10, 0, Color.BLACK);
iTextSharp.text.Font f3 = pdf.GetFont("Arial Unicode MS", 12, 0, Color.BLACK);
PdfPCell cell = new PdfPCell(new Phrase(ReportTitle, f1));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
//cell.Colspan = 2;
cell.BackgroundColor = new Color(0xD0, 0xF0, 0xF0); // light blue
datatable.AddCell(cell);
BuildSearchResultsProcSetList();
datatable.HeaderRows = 2;//3 + (ProcSetList.Count == 1 ? 1 : 0);
int splitAt = FindSpitLevel(); // find the split level of the common path - for all procedure sets that use these library documents
Color subHeaderColor = new Color(0xD0, 0xF0, 0xF0); // light blue //new Color(0xD0, 0xF0, 0xD0);//ligt green
datatable.DefaultCell.Padding = 4;
datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
// This puts "Step" and "Text" column headers at the bottom of the page
AddCell(colHeader, "Step", f2, subHeaderColor);
AddCell(colHeader, "Text", f2, subHeaderColor);
datatable.AddCell(colHeader);
datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
string lastPath = "";
Color AnnoColor = new Color(0xFF, 0xFF, 0xC0);
Color TextColor = Color.WHITE;
Color SectColor = new Color(0xE0, 0xFF, 0xE0);//new Color(0xC0, 0xFF, 0xC0);//Color.LIGHT_GRAY;
PdfPTable subTable = new PdfPTable(headerwidths);
datatable.AddCell(subTable);
string lastDVPath = "";
string lastROID = "";
foreach (ItemInfo item in _ResultList)
{
// Check Doc Version path
if (lastDVPath != item.SearchDVPath)
{
subTable = new PdfPTable(headerwidths);
AddMainPathGroup(datatable, item.SearchDVPath, splitAt, f2, Color.LIGHT_GRAY, 0);
}
lastDVPath = item.SearchDVPath;
// Chec for different ROID
string curROID = item.FoundROID;
if (lastROID == "" || curROID.Substring(0,12) != lastROID.Substring(0,12))
{
if (lastROID != "" && procRoUse.Count > 0)
{
PutROusageForROID(datatable, procRoUse, headerwidths);
procRoUse.Clear();
}
AddROHeaderGroup(datatable, curROID, item, f2, new Color(0xC0, 0xFF, 0xC0));
}
AddProcROUse(item, procRoUse);
lastROID = curROID;
}
PutROusageForROID(datatable, procRoUse, headerwidths);
document.Add(datatable);
}
private System.Collections.ArrayList ProcSetList;
private void BuildSearchResultsProcSetList()
{
ProcSetList = new System.Collections.ArrayList();
foreach (ItemInfo item in _ResultList)
{
if (!ProcSetList.Contains(item.SearchDVPath))
ProcSetList.Add(item.SearchDVPath);
}
}
private void BuildLibDocProcSetList()
{
ProcSetList = new System.Collections.ArrayList();
foreach (DocumentInfo di in _LibDocList)
{
if (di.LibraryDocumentUsageList!= null && di.LibraryDocumentUsageList.Count > 0)
foreach (ItemInfo item in di.LibraryDocumentUsageList)
{
if (!ProcSetList.Contains(item.SearchDVPath))
ProcSetList.Add(item.SearchDVPath);
}
}
}
private System.Collections.ArrayList GetSortedItemInfoList(ItemInfoList orgIFL)
{
//ICollection<ItemInfo> rtnIFL;
//get list of different procedure sets
System.Collections.ArrayList libDocProcSetList = new System.Collections.ArrayList();
System.Collections.ArrayList rtnIFL = new System.Collections.ArrayList();
foreach (ItemInfo item in orgIFL)
{
if (!libDocProcSetList.Contains(item.SearchDVPath))
libDocProcSetList.Add(item.SearchDVPath);
}
foreach (string pset in libDocProcSetList)
{
foreach (ItemInfo item in orgIFL)
{
if (item.SearchDVPath.Equals(pset))
rtnIFL.Add(item);
}
}
return rtnIFL;
}
private void BuildCompleteROReport(iTextSharp.text.Document document)
{
iTextSharp.text.Font f1 = pdf.GetFont("Arial Unicode MS", 14, 1, Color.BLACK);
iTextSharp.text.Font f2 = pdf.GetFont("Arial Unicode MS", 10, 0, Color.BLACK);
iTextSharp.text.Font f3 = pdf.GetFont("Arial Unicode MS", 12, 0, Color.BLACK);
iTextSharp.text.Font fntBold = new Font(f3.BaseFont, f3.Size, Font.BOLD, Color.RED);
CompleteROReport compRORpt = new CompleteROReport(document, _RODataFile);
compRORpt.Run();
Phrase phrs = BuildPhrase2("Complete Referenced Objects Report", f1, fntBold);
Paragraph prgh = new Paragraph(phrs);//("Complete", fntBold);
//document.Add(prgh);
document.Add(phrs);
}
}
public class MyPageHelper : PdfPageEventHelper
{
protected PdfTemplate total;
protected BaseFont helv;
private int ptSize = 10; // text point size of page number and page total
string _ByLine = "PROMS";
public MyPageHelper(string byLine)
{
_ByLine = byLine;
}
public override void OnOpenDocument(PdfWriter writer, iTextSharp.text.Document document)
{
total = writer.DirectContent.CreateTemplate(100, 100);
total.BoundingBox = new Rectangle(-20, -20, 100, 100);
//try
//{
helv = BaseFont.CreateFont(BaseFont.HELVETICA,
BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
//}
//catch (Exception)
//{
// //throw new ExceptionConverter(e);
//}
}
public override void OnEndPage(PdfWriter writer, iTextSharp.text.Document document)
{
PdfContentByte cb = writer.DirectContent;
cb.SaveState();
String text = "Page " + writer.PageNumber + " of ";
float textBase = document.Bottom - 19;//20;
float textSize = helv.GetWidthPoint(text, ptSize);
cb.BeginText();
cb.SetFontAndSize(helv, ptSize);
//if ((writer.PageNumber % 2) == 1)
//{
// cb.SetTextMatrix(document.Left, textBase);
// cb.ShowText(text);
// cb.EndText();
// cb.AddTemplate(total, document.Left + textSize, textBase);
//}
//else
//{
// float adjust = helv.GetWidthPoint("0", 12);
// cb.SetTextMatrix(
// document.Right - textSize - adjust, textBase);
// cb.ShowText(text);
// cb.EndText();
// cb.AddTemplate(total, document.Right - adjust, textBase);
//}
float posCenter = document.Left + ((document.Right - document.Left) / 2) - (helv.GetWidthPoint(text+"XX", ptSize) / 2);
cb.SetTextMatrix(posCenter, textBase);
cb.ShowText(text);
cb.EndText();
cb.AddTemplate(total, posCenter + helv.GetWidthPoint(text, ptSize), textBase);
cb.RestoreState();
AddVolianFooter(writer,document);
AddDateFooter(writer, document);
}
private void AddVolianFooter(PdfWriter writer, iTextSharp.text.Document document)
{
PdfContentByte cb = writer.DirectContent;
cb.SaveState();
String text = _ByLine;//"PROMS Search Results";
float textBase = document.Bottom - 19;//20;
float textSize = helv.GetWidthPoint(text, ptSize);
cb.BeginText();
cb.SetFontAndSize(helv, ptSize);
cb.SetTextMatrix(document.Left, textBase);
cb.ShowText(text);
cb.EndText();
cb.RestoreState();
}
private void AddDateFooter(PdfWriter writer, iTextSharp.text.Document document)
{
PdfContentByte cb = writer.DirectContent;
cb.SaveState();
String text = DateTime.Today.ToShortDateString();
float textBase = document.Bottom - 19;//20;
float textSize = helv.GetWidthPoint(text, ptSize);
float posRight = document.Right - helv.GetWidthPoint(text, ptSize);
cb.BeginText();
cb.SetFontAndSize(helv, ptSize);
cb.SetTextMatrix(posRight, textBase);
cb.ShowText(text);
cb.EndText();
cb.RestoreState();
}
public override void OnCloseDocument(PdfWriter writer, iTextSharp.text.Document document)
{
total.BeginText();
total.SetFontAndSize(helv, ptSize);
total.SetTextMatrix(0, 0);
total.ShowText((writer.PageNumber - 1).ToString());
total.EndText();
base.OnCloseDocument(writer, document);
}
}
}