From 8c76185c131e7670ef4cf115084e25b435de1cbc Mon Sep 17 00:00:00 2001 From: Rich Date: Thu, 29 Oct 2015 15:25:12 +0000 Subject: [PATCH] Search was throwing an error if the user pressed the search button, when the the Step Type Radio button was pressed when no procedures were selected. B2015-171 Fixed the Library Document Report. --- .../Volian.Controls.Library/DisplaySearch.cs | 15 +- PROMS/Volian.Print.Library/PDFReport.cs | 205 ++++++++++++++---- 2 files changed, 167 insertions(+), 53 deletions(-) diff --git a/PROMS/Volian.Controls.Library/DisplaySearch.cs b/PROMS/Volian.Controls.Library/DisplaySearch.cs index 79daa7d9..02df6bc8 100644 --- a/PROMS/Volian.Controls.Library/DisplaySearch.cs +++ b/PROMS/Volian.Controls.Library/DisplaySearch.cs @@ -1315,13 +1315,16 @@ namespace Volian.Controls.Library SearchResults = ItemInfoList.GetListFromTransitionSearch(docVersionList, cbxTranFormat.SelectedIndex - 1, cbxTranCategory.SelectedItem.ToString() == "All" ? "" : cbxTranCategory.SelectedItem.ToString(), TypeSearchList); cmbResultsStyleIndex = 3; // display step text in results } - AddMessageForEmptyAnnotations(); - if (cmbResultsStyleIndex == 3 && cmbResultsStyle.Items.Count == 3) cmbResultsStyleIndex--; - cmbResultsStyle.SelectedIndex = cmbResultsStyleIndex; - DisplayResults(); - if (SearchResults != null && SearchResults.Count == 0) + if (SearchResults != null) { - MessageBox.Show("No Matches Found.", "Search"); + AddMessageForEmptyAnnotations(); + if (cmbResultsStyleIndex == 3 && cmbResultsStyle.Items.Count == 3) cmbResultsStyleIndex--; + cmbResultsStyle.SelectedIndex = cmbResultsStyleIndex; + DisplayResults(); + if (SearchResults != null && SearchResults.Count == 0) + { + MessageBox.Show("No Matches Found.", "Search"); + } } } catch (Exception ex) diff --git a/PROMS/Volian.Print.Library/PDFReport.cs b/PROMS/Volian.Print.Library/PDFReport.cs index dfd291db..4ec070a8 100644 --- a/PROMS/Volian.Print.Library/PDFReport.cs +++ b/PROMS/Volian.Print.Library/PDFReport.cs @@ -143,7 +143,8 @@ namespace Volian.Print.Library string[] NewPath = dvPath.Split("\x7".ToCharArray()); string sep = ""; bool foundMisMatch = false; - int n = NewPath.Length; + // n-1 Exclude the "Working Draft" entry from the list + int n = NewPath.Length-1; int jstart = (skipFirst) ? 1 : 0; if (StripLast) { @@ -151,15 +152,71 @@ namespace Volian.Print.Library if (retval.Contains("\x11")) retval = retval.Substring(0, retval.IndexOf("\x11")); // this is the step number } - for (int j = jstart; j < n; j++) + if (n == 0) { - if (NewPath[j] != "" && (foundMisMatch || OldPath.Length < j + 1 || NewPath[j] != OldPath[j])) + sb.Append(dvPath); + } + else + { + for (int j = jstart; j < n; j++) { - sb.Append(sep + "".PadLeft(2 * level) + NewPath[j].Replace("\x11", " ")).Replace(@"\u8209?", "-"); - sep = "\r\n"; - foundMisMatch = true; + 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 string AddGroupLibDoc(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 - 1; + 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 + } + //If no colons output tthe entire text + if (n == 0) + { + sb.Append(dvPath); + } + else + { + 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++; } - level++; } if (sb.ToString() != "") { @@ -269,13 +326,22 @@ namespace Volian.Print.Library datatable.AddCell(cell); } } - public void AddSubPathGroup(PdfPTable datatable, string dvPath, int splitLevel, Font f2, Color bgColor, int colSpan) + public void AddSubPathGroup(PdfPTable datatable, string oldDVPath, string dvPath, int splitLevel, Font f2, Color bgColor, int colSpan) { int level = 0; StringBuilder sb = new StringBuilder(); string[] NewPath = dvPath.Split("\x7".ToCharArray()); + string[] OldPath = oldDVPath.Split("\x7".ToCharArray()); string sep = ""; - int n = NewPath.Length; + int n = NewPath.Length-1; + for (int i = 0; i < n; i++) + { + if (OldPath[i] != NewPath[i]) + { + splitLevel = Math.Max(splitLevel, i); + break; + } + } if (splitLevel < n) { for (int j = splitLevel; j < n; j++) @@ -297,7 +363,7 @@ namespace Volian.Print.Library public void Build() { iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.LETTER, 36, 36, 36, 36); - if (!CreateResultsPDF(document)) return; + if (!CreateResultsPDF(document, _ReportType)) return; try { switch (_ReportType) // set in the PDFReport constructor @@ -349,8 +415,15 @@ namespace Volian.Print.Library /// /// /// - private bool CreateResultsPDF(iTextSharp.text.Document document) + private bool CreateResultsPDF(iTextSharp.text.Document document,int typ) { + int topMargin = 36; + switch (typ) + { + case (int)ReportType.LibraryDocUsage: + topMargin = 80; // Add some space for the Report Header for the Library Document Report + break; + } bool result = false; string suffix = ""; int i = 0; @@ -362,7 +435,7 @@ namespace Volian.Print.Library { _MyPdfWriter = PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create)); _MyPdfWriter.PageEvent = new MyPageHelper(_ByLine); // JSJ - 7/8/2011 - document.SetMargins(36, 36, 36, 36); + document.SetMargins(36, 36, topMargin, 36); document.Open(); _FileName = fileName; result = true; @@ -573,41 +646,25 @@ namespace Volian.Print.Library } 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); + // Adjusted from 20,80 to 25,75 to account for long Procedure Numbers + float[] headerwidths = { 25, 75 }; 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(colheader, "Procedure", f2, subHeaderColor); - AddCell(colheader, "Section", f2, subHeaderColor); - datatable.AddCell(colheader); - datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; + int splitAt = FindSpitLevel()-1; // find the split level of the common path - for all procedure sets that use these library documents string lastDvPath = ""; Color AnnoBackgroundColor = new Color(0xFF, 0xFF, 0xC0); Color TextBackgroundColor = Color.WHITE; Color NotUsedBackgroundColor = Color.WHITE; + MyPageHelper pghlp = _MyPdfWriter.PageEvent as MyPageHelper; + pghlp.HeaderTable = LibDocTable(document, headerwidths, f2,null); foreach (DocumentInfo di in _LibDocList) { - PdfPTable subtable = new PdfPTable(headerwidths); - subtable.HeaderRows = 0; - AddGroup(subtable, di.DocumentTitle, "", f2, false, new Color(0xC0, 0xFF, 0xC0), false); // Library Document Title + //PdfPTable datatable = LibDocTable(document, headerwidths, f2, di); + //AddMainPathGroup(datatable, ProcSetList[0].ToString(), splitAt, f2, Color.LIGHT_GRAY, 0);//2); + PdfPTable subtable; + subtable = BuildSubTable(document, headerwidths); + + AddGroupLibDoc(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(subtable, "Comment", f2, AnnoBackgroundColor); @@ -615,27 +672,74 @@ namespace Volian.Print.Library } if (di.DocumentEntries == null || di.DocumentEntries.Count == 0) { - AddColSpanCell(subtable, "*No References To This Library Document", f2, NotUsedBackgroundColor, 2, Element.ALIGN_LEFT); + AddGroupLibDoc(subtable, "* No References To This Library Document *", "", f2, false, TextBackgroundColor, false); // Library Document Title } else { + subtable.HeaderRows = 2; System.Collections.ArrayList LibDocUsageList = GetSortedItemInfoList(di.LibraryDocumentUsageList); lastDvPath = ""; foreach (ItemInfo item in LibDocUsageList)//di.LibraryDocumentUsageList) { + if (item.SearchDVPath != lastDvPath) + { + if (lastDvPath != "") + { + document.Add(subtable); + subtable = BuildSubTable(document, headerwidths); + subtable.HeaderRows = 2; + AddGroupLibDoc(subtable, di.DocumentTitle, "", f2, false, new Color(0xC0, 0xFF, 0xC0), false); // Library Document Title + } + AddSubPathGroup(subtable, lastDvPath, item.SearchDVPath, splitAt, f2, Color.LIGHT_GRAY, 2);//new Color(0xC0, 0xFF, 0xC0)); + } + lastDvPath = item.SearchDVPath; 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) - AddSubPathGroup(subtable, item.SearchDVPath, splitAt, f2, Color.LIGHT_GRAY, 2);//new Color(0xC0, 0xFF, 0xC0)); - lastDvPath = item.SearchDVPath; AddCell(subtable, ProcNumber, f2, TextBackgroundColor); - AddCell(subtable, item.MyContent.Number + " - " + item.MyContent.Text, f2, TextBackgroundColor); + AddCell(subtable, item.DisplayNumber + " - " + item.DisplayText, f2, TextBackgroundColor); } + } - datatable.AddCell(subtable); + document.Add(subtable); } - document.Add(datatable); + } + + private static PdfPTable BuildSubTable(iTextSharp.text.Document document, float[] headerwidths) + { + PdfPTable subtable; + subtable = new PdfPTable(headerwidths); + subtable.HeaderRows = 1; + subtable.KeepTogether = true; + subtable.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; + subtable.LockedWidth = true; + subtable.DefaultCell.Padding = 4; + return subtable; + } + + private PdfPTable LibDocTable(iTextSharp.text.Document document, float[] headerwidths, iTextSharp.text.Font f2, DocumentInfo di) + { + PdfPTable datatable = new PdfPTable(1);// (headerwidths); + PdfPTable colheader = new PdfPTable(headerwidths); + datatable.HeaderRows = 2; + datatable.KeepTogether = false; + 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 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); + Color subHeaderColor = new Color(0xD0, 0xF0, 0xD0); + datatable.DefaultCell.Padding = 4; + datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; + AddCell(colheader, "Procedure", f2, subHeaderColor); + AddCell(colheader, "Section", f2, subHeaderColor); + datatable.AddCell(colheader); + datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; + return datatable; } private void AddROUsages(ItemInfo item, Dictionary> roUse) { @@ -1307,6 +1411,12 @@ namespace Volian.Print.Library } public class MyPageHelper : PdfPageEventHelper { + private PdfPTable _HeaderTable = null; + public PdfPTable HeaderTable + { + get { return _HeaderTable; } + set { _HeaderTable = value; } + } protected PdfTemplate total; protected BaseFont helv; private int ptSize = 10; // text point size of page number and page total @@ -1333,9 +1443,10 @@ namespace Volian.Print.Library { PdfContentByte cb = writer.DirectContent; cb.SaveState(); + if (HeaderTable != null) + HeaderTable.WriteSelectedRows(0, 2, 36, document.Top+44, cb); 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)