Output.Printers.Enhanced prints complete tables with vertical lines, multi-line support in tables, ver. 2.18.855
This commit is contained in:
parent
2efdb8bb61
commit
5c8ebd6476
@ -44,6 +44,8 @@ namespace Results.Output.Printers.Enhanced
|
||||
Font font;
|
||||
Font footerFont;
|
||||
|
||||
TableStyle style;
|
||||
|
||||
///
|
||||
/// Data to print
|
||||
///
|
||||
@ -75,7 +77,7 @@ namespace Results.Output.Printers.Enhanced
|
||||
/// <param name="textToPrint">Text to be printed</param>
|
||||
public EnhancedPrintDocument(Results.Entities.Batch batch, EnhancedPrinterCfg cfg, string documentName)
|
||||
{
|
||||
this.batch = batch;
|
||||
this.batch = batch;
|
||||
this.cfg = cfg;
|
||||
DocumentName = documentName;
|
||||
|
||||
@ -94,7 +96,20 @@ namespace Results.Output.Printers.Enhanced
|
||||
font = new Font((cfg.BodyFntFml != null ? cfg.BodyFntFml : "Arial"), (cfg.BodyFntSz > 0 ? cfg.BodyFntSz : 10), (FontStyle)cfg.BodyFntSty);
|
||||
footerFont = new Font((cfg.FooterFntFml != null ? cfg.FooterFntFml : "Arial"), (cfg.FooterFntSz > 0 ? cfg.FooterFntSz : 10), (FontStyle)cfg.FooterFntSty);
|
||||
|
||||
/// Set print area size and margins (in dots using 100 dpi)
|
||||
/// Table style of one water meter table where tests are rows
|
||||
style = new TableStyle
|
||||
{
|
||||
Font = font,
|
||||
HeaderFont = headerFont,
|
||||
MarginX = 5,
|
||||
MarginY = 3,
|
||||
LineWidth = 1,
|
||||
TopHeadersCount = 1,
|
||||
HorizLines = TableLines.FirstSecondAndLast,
|
||||
VertLines = TableLines.All
|
||||
};
|
||||
|
||||
/// Set print area size and margins (in dots using 100 dpi)
|
||||
DefaultPageSettings.Landscape = (cfg.PageOrientation == PageOrientation.Landscape);
|
||||
///
|
||||
if (DefaultPageSettings.Landscape)
|
||||
@ -108,39 +123,15 @@ namespace Results.Output.Printers.Enhanced
|
||||
printWidth = base.DefaultPageSettings.PaperSize.Width - leftMargin - leftMargin;
|
||||
}
|
||||
|
||||
SpacingOne = System.Windows.Forms.TextRenderer.MeasureText("Abcgq", font).Height;
|
||||
SpacingOneAndHalf = (3 * SpacingOne) / 2;
|
||||
SpacingOne4Header = System.Windows.Forms.TextRenderer.MeasureText("Abcgq", headerFont).Height;
|
||||
SpacingOneAndHalf4Header = (3 * SpacingOne4Header) / 2;
|
||||
/// Document outline preliminary calculations
|
||||
SpacingOne = System.Windows.Forms.TextRenderer.MeasureText("Abcgq", font).Height;
|
||||
SpacingOneAndHalf = (3 * SpacingOne) / 2;
|
||||
SpacingOne4Header = System.Windows.Forms.TextRenderer.MeasureText("Abcgq", headerFont).Height;
|
||||
SpacingOneAndHalf4Header = (3 * SpacingOne4Header) / 2;
|
||||
SpacingOne4Footer = System.Windows.Forms.TextRenderer.MeasureText("Abcgq", footerFont).Height;
|
||||
|
||||
/// Calculate the tests count
|
||||
int testsCount = 0;
|
||||
if (batch.WaterMeters.Count > 0)
|
||||
{
|
||||
foreach (var mtr in batch.WaterMeters[0].MeterTestRslts)
|
||||
{
|
||||
if (mtr.Publish() == Config.Entities.Publish.Always && mtr.IsPilotRslt()) testsCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/// Prepare document outline
|
||||
TitleX = cfg.LeftMargin;
|
||||
TitleY = cfg.TopMargin;
|
||||
|
||||
titleHeight = System.Windows.Forms.TextRenderer.MeasureText(header, titleFont).Height;
|
||||
CommonTop = TitleY + titleHeight + SpacingOne4Header;
|
||||
|
||||
commonHeight = commonItems.Count * SpacingOne;
|
||||
BodyTop = CommonTop + commonHeight + SpacingOne4Header;
|
||||
|
||||
int wmSectionHeight = (testsCount + 1) * SpacingOne + 3 * SpacingOne4Header;
|
||||
|
||||
nrWMsOnFirstPage = (printHeight - BodyTop + TitleY - 2 * SpacingOne) / wmSectionHeight;
|
||||
nrWMsOnNextPage = (printHeight - 2 * SpacingOne) / wmSectionHeight;
|
||||
nrWMsOnNextPage = Math.Max(nrWMsOnNextPage, 1); /// Prevent division by zero if there are too many WM tests
|
||||
|
||||
nrPages = 1 + (batch.WaterMeters.Count - nrWMsOnFirstPage + nrWMsOnNextPage - 1) / nrWMsOnNextPage;
|
||||
TitleX = cfg.LeftMargin;
|
||||
TitleY = cfg.TopMargin;
|
||||
|
||||
pageNr = 1;
|
||||
nextWMNr = 0;
|
||||
@ -183,7 +174,27 @@ namespace Results.Output.Printers.Enhanced
|
||||
|
||||
if (pageNr == 1)
|
||||
{
|
||||
///----------
|
||||
///----------
|
||||
/// Prepare document outline
|
||||
///----------
|
||||
titleHeight = System.Windows.Forms.TextRenderer.MeasureText(header, titleFont).Height;
|
||||
CommonTop = TitleY + titleHeight + SpacingOne4Header;
|
||||
|
||||
commonHeight = commonItems.Count * SpacingOne;
|
||||
BodyTop = CommonTop + commonHeight + SpacingOne4Header;
|
||||
|
||||
Table table0 = GetTable_TestsAreRows(batch.WaterMeters[0], testItems, style);
|
||||
SizeF tableSize = table0.Measure(e);
|
||||
int wmSectionHeight = (int)tableSize.Height + 3 * SpacingOne4Header;
|
||||
|
||||
nrWMsOnFirstPage = (printHeight - BodyTop + TitleY - 2 * SpacingOne) / wmSectionHeight;
|
||||
nrWMsOnNextPage = (printHeight - 2 * SpacingOne) / wmSectionHeight;
|
||||
nrWMsOnNextPage = Math.Max(nrWMsOnNextPage, 1); /// Prevent division by zero if there are too many WM tests
|
||||
|
||||
nrPages = 1 + (batch.WaterMeters.Count - nrWMsOnFirstPage + nrWMsOnNextPage - 1) / nrWMsOnNextPage;
|
||||
|
||||
|
||||
///----------
|
||||
/// Title
|
||||
///----------
|
||||
RectangleF printArea = new RectangleF(TitleX, TitleY, printWidth, titleHeight);
|
||||
@ -228,8 +239,7 @@ namespace Results.Output.Printers.Enhanced
|
||||
for (int wmNr = nextWMNr; wmNr < Math.Min(nextWMNr + nrWMsOnPage, batch.WaterMeters.Count); wmNr++) /// wmNr is 0-based
|
||||
{
|
||||
int wmPosition = true ? batch.WaterMeters[wmNr].WMPosition : (wmNr + 1);
|
||||
int sectionHght = PrintWM(e, batch.WaterMeters[wmNr], wmPosition, nextWmTop);
|
||||
nextWmTop += sectionHght;
|
||||
nextWmTop = (int)PrintWM(e, batch.WaterMeters[wmNr], wmPosition, nextWmTop) + SpacingOneAndHalf4Header;
|
||||
}
|
||||
|
||||
nextWMNr += nrWMsOnPage;
|
||||
@ -254,88 +264,21 @@ namespace Results.Output.Printers.Enhanced
|
||||
/// <param name="printedWMNr">Number of the water meter printed</param>
|
||||
/// <param name="top">Top coordinate of watermeter data</param>
|
||||
/// <returns>The height of the printed section</returns>
|
||||
int PrintWM(System.Drawing.Printing.PrintPageEventArgs e,
|
||||
float PrintWM(System.Drawing.Printing.PrintPageEventArgs e,
|
||||
Results.Entities.WaterMeter wm, int printedWMNr, int top)
|
||||
{
|
||||
/// Determin column widths
|
||||
float[] columnPos = new float[testItems.Count + 1];
|
||||
columnPos[0] = (float)leftMargin;
|
||||
/// Print the water meter number and the serial number
|
||||
string wmText = string.Format("{0} {1}", Strings.Water_Meter, printedWMNr);
|
||||
PrintHeaderAt(e, leftMargin, top, wmText);
|
||||
if (!string.IsNullOrEmpty(wm.SerialNr))
|
||||
{
|
||||
PrintHeaderAt(e, leftMargin + (int)e.Graphics.MeasureString(wmText, headerFont).Width, top,
|
||||
string.Format(" {0} = {1}", Strings.sn, wm.SerialNr));
|
||||
}
|
||||
|
||||
for (int i = 0; i < testItems.Count; i++)
|
||||
{
|
||||
float columnWidth = e.Graphics.MeasureString(testItems[i].Caption, headerFont).Width;
|
||||
foreach (var mtr in wm.MeterTestRslts)
|
||||
{
|
||||
if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always)
|
||||
{
|
||||
string itemText = testItems[i].Print(wm, mtr.Name());
|
||||
Table table = GetTable_TestsAreRows(wm, testItems, style);
|
||||
|
||||
/// Strip color information
|
||||
string[] texts = itemText.Split(new char[] { '|' });
|
||||
if (texts.Length == 2) { itemText = texts[0]; }
|
||||
|
||||
float width = e.Graphics.MeasureString(itemText, font).Width;
|
||||
if (width > columnWidth) columnWidth = width;
|
||||
}
|
||||
}
|
||||
columnPos[i + 1] = columnPos[i] + columnWidth + 20.0f;
|
||||
}
|
||||
int tableLeftX = (int)columnPos[0];
|
||||
int tableRightX = (int)columnPos[testItems.Count] - 20;
|
||||
|
||||
string wmText = string.Format("{0} {1}", Strings.Water_Meter, printedWMNr);
|
||||
PrintHeaderAt(e, leftMargin, top, wmText);
|
||||
if (!string.IsNullOrEmpty(wm.SerialNr))
|
||||
{
|
||||
PrintHeaderAt(e, leftMargin + (int)e.Graphics.MeasureString(wmText, headerFont).Width, top,
|
||||
string.Format(" {0} = {1}", Strings.sn, wm.SerialNr));
|
||||
}
|
||||
|
||||
/// Horizontal line
|
||||
int horY = top + SpacingOneAndHalf4Header;
|
||||
e.Graphics.DrawLine(new Pen(Color.Black, 2), new Point(tableLeftX, horY), new Point(tableRightX, horY));
|
||||
|
||||
for (int i = 0; i < testItems.Count; i++)
|
||||
{
|
||||
PrintHeaderAt(e, (int)columnPos[i], top + (int)(1.6 * SpacingOne4Header), testItems[i].Caption);
|
||||
}
|
||||
|
||||
/// Horizontal line
|
||||
horY = top + (int)(2.8 * SpacingOne4Header);
|
||||
e.Graphics.DrawLine(new Pen(Color.Black, 2), new Point(tableLeftX, horY), new Point(tableRightX, horY));
|
||||
|
||||
int testsCount = 0;
|
||||
foreach (var mtr in wm.MeterTestRslts)
|
||||
{
|
||||
if ((mtr != null) && (mtr.Publish() == Config.Entities.Publish.Always))
|
||||
{
|
||||
WMeterRsltItemSpec.TableRowNr = ++testsCount;
|
||||
|
||||
for (int i = 0; i < testItems.Count; i++)
|
||||
{
|
||||
WMeterRsltItemSpec.TableColumnNr = i + 1;
|
||||
|
||||
string itemText = testItems[i].Print(wm, mtr.Name());
|
||||
|
||||
/// Strip color information
|
||||
string[] texts = itemText.Split(new char[] { '|' });
|
||||
if (texts.Length == 2)
|
||||
{
|
||||
itemText = texts[0];
|
||||
Color color = texts[1].Equals("Green") ? Color.Green : (texts[1].Equals("Red") ? Color.Red : Color.White);
|
||||
/// TODO: How to print colors?
|
||||
}
|
||||
|
||||
PrintAt(e, (int)columnPos[i], top + 2 * SpacingOne4Header + SpacingOne * testsCount, itemText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Horizontal line
|
||||
horY = top + 2 * SpacingOneAndHalf4Header + SpacingOne * testsCount;
|
||||
e.Graphics.DrawLine(new Pen(Color.Black, 2), new Point(tableLeftX, horY), new Point(tableRightX, horY));
|
||||
|
||||
return (testsCount + 1) * SpacingOne + 3 * SpacingOne4Header;
|
||||
return table.Draw(e, leftMargin, top + SpacingOneAndHalf4Header);
|
||||
}
|
||||
|
||||
|
||||
@ -370,5 +313,50 @@ namespace Results.Output.Printers.Enhanced
|
||||
RectangleF printArea = new RectangleF(x, y, 2000, SpacingOne4Footer);
|
||||
e.Graphics.DrawString(text, this.footerFont, Brushes.Black, printArea);
|
||||
}
|
||||
|
||||
|
||||
Table GetTable_TestsAreRows(Results.Entities.WaterMeter wm, IList<WMeterRsltItemSpec> items, TableStyle style)
|
||||
{
|
||||
/// Top row contains column captions
|
||||
|
||||
Table table = new Table(items.Count);
|
||||
table.Style = style;
|
||||
|
||||
string[] tableHeader = new string[table.ColumnsCount];
|
||||
Alignment[] horizAlignment = new Alignment[table.ColumnsCount];
|
||||
VertAlignment[] vertAlignment = new VertAlignment[table.ColumnsCount];
|
||||
for (int i = 0; i < table.ColumnsCount; i++)
|
||||
{
|
||||
tableHeader[i] = items[i].Caption;
|
||||
horizAlignment[i] = Alignment.Center;
|
||||
vertAlignment[i] = VertAlignment.Middle;
|
||||
}
|
||||
table.AddRow(tableHeader, horizAlignment, vertAlignment);
|
||||
|
||||
WMeterRsltItemSpec.TableRowNr = 1;
|
||||
foreach (var mtr in wm.MeterTestRslts)
|
||||
{
|
||||
if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always)
|
||||
{
|
||||
string[] oneTableRow = new string[table.ColumnsCount];
|
||||
horizAlignment = new Alignment[table.ColumnsCount];
|
||||
vertAlignment = new VertAlignment[table.ColumnsCount];
|
||||
|
||||
for (int i = 0; i < table.ColumnsCount; i++)
|
||||
{
|
||||
WMeterRsltItemSpec.TableColumnNr = i + 1;
|
||||
oneTableRow[i] = items[i].Print(wm, mtr.Name()).Split(new char[] { '|' })[0];
|
||||
horizAlignment[i] = items[i].Alignment;
|
||||
vertAlignment[i] = VertAlignment.Middle;
|
||||
}
|
||||
|
||||
table.AddRow(oneTableRow, horizAlignment, vertAlignment);
|
||||
|
||||
WMeterRsltItemSpec.TableRowNr++;
|
||||
}
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("2.18.844.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.844.0")]
|
||||
[assembly: AssemblyVersion("2.18.855.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.855.0")]
|
||||
|
||||
@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.18.854.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.854.0")]
|
||||
[assembly: AssemblyVersion("2.18.855.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.855.0")]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user