bug fixes and changes to search results reports, changes to wording on search panel for step types

This commit is contained in:
2011-07-11 19:57:01 +00:00
parent a0bcd7d9c0
commit daddf5d47c
3 changed files with 416 additions and 253 deletions

View File

@@ -31,6 +31,13 @@ namespace Volian.Print.Library
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
{
@@ -43,112 +50,113 @@ namespace Volian.Print.Library
get { return _SearchString; }
set { _SearchString = VEPROMS.CSLA.Library.ItemInfo.ConvertToDisplayText(value); }
}
public PDFReport(string reportTitle, ICollection<ItemInfo> resultList, string fileName)
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);
}
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));
//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)
{
}
}
// // 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);
//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);
}
// 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));
@@ -239,6 +247,7 @@ namespace Volian.Print.Library
try
{
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create));
writer.PageEvent = new MyPageHelper(); // JSJ - 7/8/2011
document.SetMargins(36, 36, 36, 36);
document.Open();
_FileName = fileName;
@@ -287,7 +296,7 @@ namespace Volian.Print.Library
float[] headerwidths = { 20, 80 };
PdfPTable datatable = new PdfPTable(headerwidths);
datatable.HeaderRows = 3;
datatable.FooterRows = 1;
//datatable.FooterRows = 1;
datatable.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
datatable.LockedWidth = true;
//FontFactory.RegisterDirectory(FontFind.FontDir);
@@ -296,19 +305,26 @@ namespace Volian.Print.Library
//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("Prestige Elite Tall", 9, 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);
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(datatable, "Step", f2, subHeaderColor);
AddCell(datatable, "Text", f2, subHeaderColor);
// 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 = "";
@@ -323,9 +339,10 @@ namespace Volian.Print.Library
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
// 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));
if (item.ItemAnnotationCount > 0)
{
@@ -406,4 +423,102 @@ namespace Volian.Print.Library
}
}
public class MyPageHelper : PdfPageEventHelper
{
protected PdfTemplate total;
protected BaseFont helv;
private int ptSize = 10; // text point size of page number and page total
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 = "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);
}
}
}