Output.Printers.OnePerMeter : Table class added, common items use Table class for printing, ver. 2.18.844
This commit is contained in:
parent
f8a358c21e
commit
0adec1cb51
@ -1,5 +1,5 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
/// Copyright (c) 2017-2018 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -161,131 +161,70 @@ namespace Results.Output.Printers.OnePerMeter
|
||||
catch (Exception) { } /// Cope with situations when file is missing or is not correct
|
||||
}
|
||||
|
||||
titleHeight = System.Windows.Forms.TextRenderer.MeasureText(header, titleFont).Height;
|
||||
commonTop = TitleY + titleHeight + spacingOne4Header;
|
||||
|
||||
commonHeight = commonItems.Count * spacingOne;
|
||||
bodyTop = commonTop + commonHeight + spacingOne4Header;
|
||||
|
||||
///
|
||||
/// Title
|
||||
///
|
||||
RectangleF printArea = new RectangleF(TitleX, TitleY, printWidth, titleHeight);
|
||||
e.Graphics.DrawString(header, titleFont, Brushes.Black, printArea);
|
||||
|
||||
titleHeight = System.Windows.Forms.TextRenderer.MeasureText(header, titleFont).Height;
|
||||
commonTop = TitleY + titleHeight + spacingOne4Header;
|
||||
|
||||
|
||||
///
|
||||
/// Common items
|
||||
///
|
||||
string[] leftColumn = new string[commonItems.Count];
|
||||
string[] rightColumn = new string[commonItems.Count];
|
||||
|
||||
int cnt = 0;
|
||||
Table table = new Table(2);
|
||||
table.Style = new TableStyle { Font = font, MarginX = 5, MarginY = 3 };
|
||||
Alignment[] horizAlgn = new Alignment[] { Alignment.Left, Alignment.Left };
|
||||
VertAlignment[] vertAlgn = new VertAlignment[] { VertAlignment.Top, VertAlignment.Top };
|
||||
///
|
||||
foreach (var v in commonItems)
|
||||
{
|
||||
leftColumn[cnt] = v.Caption;
|
||||
rightColumn[cnt] = (batch.WaterMeters.Count > 0) ? v.Print(batch.WaterMeters[0]) : string.Empty;
|
||||
cnt++;
|
||||
string[] row = new string[] { v.Caption, (batch.WaterMeters.Count > 0) ? v.Print(batch.WaterMeters[0]) : string.Empty };
|
||||
table.AddRow(row, horizAlgn, vertAlgn);
|
||||
}
|
||||
|
||||
/// Determine left column width
|
||||
float maxWidth = 0;
|
||||
foreach (var str in leftColumn)
|
||||
{
|
||||
float width = e.Graphics.MeasureString(str, font).Width;
|
||||
if (width > maxWidth) maxWidth = width;
|
||||
}
|
||||
|
||||
/// Write aligned columns
|
||||
for (int i = 0; i < Math.Min(leftColumn.Length, rightColumn.Length); i++)
|
||||
{
|
||||
PrintAt(e, leftColumn[i], font, leftMargin, commonTop + spacingOne * i, maxWidth, 0, Alignment.Left, VertAlignment.Top);
|
||||
PrintAt(e, rightColumn[i], font, leftMargin + maxWidth + GapBetweenCommonColumns, commonTop + spacingOne * i, 0, 0, Alignment.Left, VertAlignment.Top);
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Body
|
||||
///
|
||||
IList<string[]> tableRows;
|
||||
IList<Alignment[]> horizAlignment;
|
||||
IList<VertAlignment[]> vertAlignment;
|
||||
if (pageNr == 1)
|
||||
bodyTop = table.Draw(e, (float)leftMargin, commonTop) + spacingOne4Header;
|
||||
}
|
||||
|
||||
///
|
||||
/// Draw table
|
||||
///
|
||||
if (cfg.TestsAreRows)
|
||||
{
|
||||
///
|
||||
/// Prepare table content: tableHeader + tableRows + itemAlignment
|
||||
///
|
||||
if (cfg.TestsAreRows)
|
||||
TableStyle style = new TableStyle
|
||||
{
|
||||
GetContentTestsAreRows(wm, testItems, out tableRows, out horizAlignment, out vertAlignment);
|
||||
DrawTable(e, (float)leftMargin, bodyTop, tableRows, horizAlignment, vertAlignment,
|
||||
new TableStyle
|
||||
{
|
||||
Font = font,
|
||||
HeaderFont = headerFont,
|
||||
MarginX = 5,
|
||||
MarginY = 3,
|
||||
LineWidth = 1,
|
||||
TopHeadersCount = 1,
|
||||
HorizLines = TableLines.All,
|
||||
VertLines = TableLines.All
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
GetContentTestsAreColumns(wm, testItems, out tableRows, out horizAlignment, out vertAlignment);
|
||||
DrawTable(e, (float)leftMargin, bodyTop, tableRows, horizAlignment, vertAlignment,
|
||||
new TableStyle
|
||||
{
|
||||
Font = font,
|
||||
HeaderFont = headerFont,
|
||||
MarginX = 5,
|
||||
MarginY = 3,
|
||||
LineWidth = 1,
|
||||
LeftHeadersCount = 1,
|
||||
HorizLines = TableLines.All,
|
||||
VertLines = TableLines.All
|
||||
});
|
||||
}
|
||||
Font = font,
|
||||
HeaderFont = headerFont,
|
||||
MarginX = 5,
|
||||
MarginY = 3,
|
||||
LineWidth = 1,
|
||||
TopHeadersCount = 1,
|
||||
HorizLines = TableLines.All,
|
||||
VertLines = TableLines.FirstSecondAndLast
|
||||
};
|
||||
|
||||
GetTable_TestsAreRows(wm, (pageNr == 1) ? testItems : testItems2, style).Draw(e, (float)leftMargin, bodyTop);
|
||||
}
|
||||
else
|
||||
{
|
||||
///
|
||||
/// Prepare table content: tableHeader + tableRows + itemAlignment
|
||||
///
|
||||
if (cfg.TestsAreRows2)
|
||||
TableStyle style = new TableStyle
|
||||
{
|
||||
GetContentTestsAreRows(wm, testItems2, out tableRows, out horizAlignment, out vertAlignment);
|
||||
DrawTable(e, (float)leftMargin, bodyTop, tableRows, horizAlignment, vertAlignment,
|
||||
new TableStyle
|
||||
{
|
||||
Font = font,
|
||||
HeaderFont = headerFont,
|
||||
MarginX = 5,
|
||||
MarginY = 3,
|
||||
LineWidth = 1,
|
||||
TopHeadersCount = 1,
|
||||
HorizLines = TableLines.All,
|
||||
VertLines = TableLines.All
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
GetContentTestsAreColumns(wm, testItems2, out tableRows, out horizAlignment, out vertAlignment);
|
||||
DrawTable(e, (float)leftMargin, bodyTop, tableRows, horizAlignment, vertAlignment,
|
||||
new TableStyle
|
||||
{
|
||||
Font = font,
|
||||
HeaderFont = headerFont,
|
||||
MarginX = 5,
|
||||
MarginY = 3,
|
||||
LineWidth = 1,
|
||||
LeftHeadersCount = 1,
|
||||
HorizLines = TableLines.All,
|
||||
VertLines = TableLines.All
|
||||
});
|
||||
}
|
||||
Font = font,
|
||||
HeaderFont = headerFont,
|
||||
MarginX = 5,
|
||||
MarginY = 3,
|
||||
LineWidth = 1,
|
||||
LeftHeadersCount = 1,
|
||||
HorizLines = TableLines.FirstSecondAndLast,
|
||||
VertLines = TableLines.All
|
||||
};
|
||||
|
||||
GetTable_TestsAreColumns(wm, (pageNr == 1) ? testItems : testItems2, style).Draw(e, (float)leftMargin, bodyTop);
|
||||
}
|
||||
|
||||
|
||||
if (pageNr == nrPages)
|
||||
{
|
||||
///
|
||||
@ -308,41 +247,34 @@ namespace Results.Output.Printers.OnePerMeter
|
||||
}
|
||||
|
||||
|
||||
void GetContentTestsAreRows(Results.Entities.WaterMeter wm, IList<WMeterRsltItemSpec> items,
|
||||
out IList<string[]> tableRows, out IList<Alignment[]> horizAlignments, out IList<VertAlignment[]> vertAlignments)
|
||||
Table GetTable_TestsAreRows(Results.Entities.WaterMeter wm, IList<WMeterRsltItemSpec> items, TableStyle style)
|
||||
{
|
||||
/// Top row contains column captions
|
||||
|
||||
int tableColumnsCount = items.Count;
|
||||
Table table = new Table(items.Count);
|
||||
table.Style = style;
|
||||
|
||||
tableRows = new List<string[]>();
|
||||
horizAlignments = new List<Alignment[]>();
|
||||
vertAlignments = new List<VertAlignment[]>();
|
||||
|
||||
|
||||
string[] tableHeader = new string[tableColumnsCount];
|
||||
Alignment[] horizAlignment = new Alignment[tableColumnsCount];
|
||||
VertAlignment[] vertAlignment = new VertAlignment[tableColumnsCount];
|
||||
for (int i = 0; i < tableColumnsCount; i++)
|
||||
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;
|
||||
}
|
||||
tableRows.Add(tableHeader);
|
||||
horizAlignments.Add(horizAlignment);
|
||||
vertAlignments.Add(vertAlignment);
|
||||
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[tableColumnsCount];
|
||||
horizAlignment = new Alignment[tableColumnsCount];
|
||||
vertAlignment = new VertAlignment[tableColumnsCount];
|
||||
string[] oneTableRow = new string[table.ColumnsCount];
|
||||
horizAlignment = new Alignment[table.ColumnsCount];
|
||||
vertAlignment = new VertAlignment[table.ColumnsCount];
|
||||
|
||||
for (int i = 0; i < tableColumnsCount; i++)
|
||||
for (int i = 0; i < table.ColumnsCount; i++)
|
||||
{
|
||||
WMeterRsltItemSpec.TableColumnNr = i + 1;
|
||||
oneTableRow[i] = items[i].Print(wm, mtr.Name()).Split(new char[] { '|' })[0];
|
||||
@ -350,48 +282,34 @@ namespace Results.Output.Printers.OnePerMeter
|
||||
vertAlignment[i] = VertAlignment.Middle;
|
||||
}
|
||||
|
||||
tableRows.Add(oneTableRow);
|
||||
horizAlignments.Add(horizAlignment);
|
||||
vertAlignments.Add(vertAlignment);
|
||||
table.AddRow(oneTableRow, horizAlignment, vertAlignment);
|
||||
|
||||
WMeterRsltItemSpec.TableRowNr++;
|
||||
}
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
|
||||
void GetContentTestsAreColumns(Results.Entities.WaterMeter wm, IList<WMeterRsltItemSpec> items,
|
||||
out IList<string[]> tableRows, out IList<Alignment[]> horizAlignments, out IList<VertAlignment[]> vertAlignments)
|
||||
Table GetTable_TestsAreColumns(Results.Entities.WaterMeter wm, IList<WMeterRsltItemSpec> items, TableStyle style)
|
||||
{
|
||||
/// Left column contains row captions
|
||||
|
||||
///
|
||||
/// Calculate columns count
|
||||
///
|
||||
int tableColumnsCount = 1; /// Left column contains item caption
|
||||
int columnsCount = 1; /// Left column contains item caption
|
||||
foreach (var mtr in wm.MeterTestRslts)
|
||||
{
|
||||
if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always)
|
||||
{
|
||||
tableColumnsCount++; /// One additional column for each test to be published
|
||||
columnsCount++; /// One additional column for each test to be published
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Alignment of columns
|
||||
///
|
||||
tableRows = new List<string[]>();
|
||||
horizAlignments = new List<Alignment[]>();
|
||||
vertAlignments = new List<VertAlignment[]>();
|
||||
|
||||
int columnsCount = 1;
|
||||
foreach (var mtr in wm.MeterTestRslts)
|
||||
{
|
||||
if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always)
|
||||
{
|
||||
columnsCount++;
|
||||
}
|
||||
}
|
||||
Table table = new Table(columnsCount);
|
||||
table.Style = style;
|
||||
|
||||
///
|
||||
/// Table content
|
||||
@ -399,9 +317,9 @@ namespace Results.Output.Printers.OnePerMeter
|
||||
WMeterRsltItemSpec.TableRowNr = 1;
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
string[] oneTableRow = new string[tableColumnsCount];
|
||||
Alignment[] horizAlignment = new Alignment[tableColumnsCount];
|
||||
VertAlignment[] vertAlignment = new VertAlignment[tableColumnsCount];
|
||||
string[] oneTableRow = new string[columnsCount];
|
||||
Alignment[] horizAlignment = new Alignment[columnsCount];
|
||||
VertAlignment[] vertAlignment = new VertAlignment[columnsCount];
|
||||
|
||||
oneTableRow[0] = items[i].Caption;
|
||||
horizAlignment[0] = Alignment.Center;
|
||||
@ -422,12 +340,12 @@ namespace Results.Output.Printers.OnePerMeter
|
||||
}
|
||||
}
|
||||
|
||||
tableRows.Add(oneTableRow);
|
||||
horizAlignments.Add(horizAlignment);
|
||||
vertAlignments.Add(vertAlignment);
|
||||
table.AddRow(oneTableRow, horizAlignment, vertAlignment);
|
||||
|
||||
WMeterRsltItemSpec.TableRowNr++;
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,7 +32,6 @@ namespace Results.Output.Printers.OnePerMeter
|
||||
public string[] TestItems2;
|
||||
public string Footer;
|
||||
public bool TestsAreRows;
|
||||
public bool TestsAreRows2;
|
||||
public string ImgFullPathName;
|
||||
public int ImgLeft;
|
||||
public int ImgTop;
|
||||
|
||||
@ -6,149 +6,8 @@ using Config.Entities;
|
||||
|
||||
namespace Results.Output.Printers
|
||||
{
|
||||
public enum TableLines
|
||||
{
|
||||
None,
|
||||
FirstAndLast,
|
||||
FirstSecondAndLast,
|
||||
All,
|
||||
}
|
||||
|
||||
public class TableStyle
|
||||
{
|
||||
public float MarginX;
|
||||
public float MarginY;
|
||||
public Font Font;
|
||||
public Font HeaderFont;
|
||||
public int TopHeadersCount;
|
||||
public int LeftHeadersCount;
|
||||
public float LineWidth;
|
||||
public TableLines HorizLines;
|
||||
public TableLines VertLines;
|
||||
}
|
||||
|
||||
public class PrintersCommon : PrintDocument
|
||||
{
|
||||
protected SizeF MeasureTable(System.Drawing.Printing.PrintPageEventArgs e, IList<string[]> rows, TableStyle tableStyle)
|
||||
{
|
||||
SizeF retVal = new SizeF(0, 0);
|
||||
|
||||
if (rows == null || rows.Count == 0) return retVal;
|
||||
|
||||
int tblColumnsCount = rows[0].Length;
|
||||
|
||||
float[] columnWidth = new float[tblColumnsCount];
|
||||
float[] rowHeight = new float[rows.Count];
|
||||
|
||||
///
|
||||
/// Measure table column widths and header height
|
||||
///
|
||||
for (int colIx = 0; colIx < tblColumnsCount; colIx++)
|
||||
{
|
||||
for (int rowIx = 0; rowIx < rows.Count; rowIx++)
|
||||
{
|
||||
bool isHeader = (colIx < tableStyle.LeftHeadersCount) || (rowIx < tableStyle.TopHeadersCount);
|
||||
SizeF size = Measure(e, rows[rowIx][colIx], isHeader ? tableStyle.HeaderFont : tableStyle.Font);
|
||||
if (size.Width > columnWidth[colIx]) columnWidth[colIx] = size.Width;
|
||||
if (size.Height > rowHeight[rowIx]) rowHeight[rowIx] = size.Height;
|
||||
}
|
||||
retVal.Width += columnWidth[colIx] + 2 * tableStyle.MarginX;
|
||||
}
|
||||
for (int rowIx = 0; rowIx < rows.Count; rowIx++)
|
||||
{
|
||||
retVal.Height += rowHeight[rowIx] + 2 * tableStyle.MarginY;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
protected float DrawTable(System.Drawing.Printing.PrintPageEventArgs e, float left, float top, IList<string[]> rows,
|
||||
IList<Alignment[]> horizAlignments, IList<VertAlignment[]> vertAlignments, TableStyle tableStyle)
|
||||
{
|
||||
if (rows == null || rows.Count == 0) return top;
|
||||
|
||||
int tblColumnsCount = rows[0].Length;
|
||||
float[] columnWidth = new float[tblColumnsCount];
|
||||
float[] columnPos = new float[tblColumnsCount + 1];
|
||||
float[] rowHeight = new float[rows.Count];
|
||||
float[] rowPos = new float[rows.Count + 1];
|
||||
|
||||
///
|
||||
/// Measure table column widths and header height
|
||||
///
|
||||
columnPos[0] = left;
|
||||
rowPos[0] = top;
|
||||
for (int colIx = 0; colIx < tblColumnsCount; colIx++)
|
||||
{
|
||||
for (int rowIx = 0; rowIx < rows.Count; rowIx++)
|
||||
{
|
||||
bool isHeader = (colIx < tableStyle.LeftHeadersCount) || (rowIx < tableStyle.TopHeadersCount);
|
||||
SizeF size = Measure(e, rows[rowIx][colIx], isHeader ? tableStyle.HeaderFont : tableStyle.Font);
|
||||
if (size.Width > columnWidth[colIx]) columnWidth[colIx] = size.Width;
|
||||
if (size.Height > rowHeight[rowIx]) rowHeight[rowIx] = size.Height;
|
||||
}
|
||||
columnPos[colIx + 1] = columnPos[colIx] + columnWidth[colIx] + 2 * tableStyle.MarginX + tableStyle.LineWidth;
|
||||
}
|
||||
for (int rowIx = 0; rowIx < rows.Count; rowIx++)
|
||||
{
|
||||
rowPos[rowIx + 1] = rowPos[rowIx] + rowHeight[rowIx] + 2 * tableStyle.MarginY + tableStyle.LineWidth;
|
||||
}
|
||||
|
||||
/// Horizontal lines
|
||||
float tableLeftX = left;
|
||||
float tableRightX = columnPos[tblColumnsCount] + tableStyle.LineWidth;
|
||||
if (tableStyle.HorizLines != TableLines.None)
|
||||
{
|
||||
for (int rowIx = 0; rowIx <= rows.Count; rowIx++)
|
||||
{
|
||||
if (tableStyle.HorizLines == TableLines.All || rowIx == 0 || rowIx == rows.Count || (tableStyle.HorizLines == TableLines.FirstSecondAndLast && rowIx == 1))
|
||||
{
|
||||
e.Graphics.DrawLine(new Pen(Color.Black, tableStyle.LineWidth), new PointF(tableLeftX, rowPos[rowIx] + tableStyle.LineWidth / 2), new PointF(tableRightX, rowPos[rowIx] + tableStyle.LineWidth / 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Vertical lines
|
||||
float tableTopY = top;
|
||||
float tableBottomY = rowPos[rows.Count] + tableStyle.LineWidth;
|
||||
if (tableStyle.VertLines != TableLines.None)
|
||||
{
|
||||
for (int colIx = 0; colIx <= tblColumnsCount; colIx++)
|
||||
{
|
||||
if (tableStyle.VertLines == TableLines.All || colIx == 0 || colIx == rows.Count || (tableStyle.VertLines == TableLines.FirstSecondAndLast && colIx == 1))
|
||||
{
|
||||
e.Graphics.DrawLine(new Pen(Color.Black, tableStyle.LineWidth), new PointF(columnPos[colIx] + tableStyle.LineWidth / 2, tableTopY), new PointF(columnPos[colIx] + tableStyle.LineWidth / 2, tableBottomY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Draw table body
|
||||
///
|
||||
for (int rowIndex = 0; rowIndex < rows.Count; rowIndex++)
|
||||
{
|
||||
string[] oneTableRow = rows[rowIndex];
|
||||
Alignment[] horizAlignment = horizAlignments[(horizAlignments.Count > rowIndex) ? rowIndex : 0];
|
||||
VertAlignment[] vertAlignment = vertAlignments[(vertAlignments.Count > rowIndex) ? rowIndex : 0];
|
||||
for (int colIndex = 0; colIndex < tblColumnsCount; colIndex++)
|
||||
{
|
||||
bool isHeader = (colIndex < tableStyle.LeftHeadersCount) || (rowIndex < tableStyle.TopHeadersCount);
|
||||
PrintAt(e, oneTableRow[colIndex],
|
||||
isHeader ? tableStyle.HeaderFont : tableStyle.Font,
|
||||
columnPos[colIndex] + tableStyle.MarginX + tableStyle.LineWidth,
|
||||
rowPos[rowIndex] + tableStyle.MarginY,
|
||||
columnWidth[colIndex],
|
||||
rowHeight[rowIndex],
|
||||
horizAlignment[colIndex],
|
||||
vertAlignment[colIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
return tableBottomY;
|
||||
}
|
||||
|
||||
|
||||
static Font lastFont = null;
|
||||
static float lastSpacing = 0;
|
||||
|
||||
@ -159,7 +18,7 @@ namespace Results.Output.Printers
|
||||
/// <param name="text">Text, lines are separated by '~'</param>
|
||||
/// <param name="font">Font</param>
|
||||
/// <returns>Size of the paragraph of text</returns>
|
||||
protected SizeF Measure(System.Drawing.Printing.PrintPageEventArgs e, string text, Font font)
|
||||
public static SizeF Measure(System.Drawing.Printing.PrintPageEventArgs e, string text, Font font)
|
||||
{
|
||||
if (font != lastFont)
|
||||
{
|
||||
@ -190,10 +49,11 @@ namespace Results.Output.Printers
|
||||
/// <param name="height">Height, 0 = no vertical centering</param>
|
||||
/// <param name="horizAlignment">Horizontal alignment</param>
|
||||
/// <param name="vertAlignment">Vertical alignment</param>
|
||||
protected void PrintAt(System.Drawing.Printing.PrintPageEventArgs e, string text, Font font,
|
||||
float x, float y, float width, float height, Alignment horizAlignment, VertAlignment vertAlignment)
|
||||
public static void PrintAt(System.Drawing.Printing.PrintPageEventArgs e, string text, Font font,
|
||||
float x, float y, float width, float height,
|
||||
Alignment horizAlignment, VertAlignment vertAlignment)
|
||||
{
|
||||
SizeF size = Measure(e, text, font);
|
||||
SizeF size = PrintersCommon.Measure(e, text, font);
|
||||
|
||||
string[] lines = text.Split(new char[] { '~' });
|
||||
|
||||
|
||||
202
Results/Output/Printers/Table.cs
Normal file
202
Results/Output/Printers/Table.cs
Normal file
@ -0,0 +1,202 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Printing;
|
||||
using Config.Entities;
|
||||
|
||||
namespace Results.Output.Printers
|
||||
{
|
||||
public enum TableLines
|
||||
{
|
||||
None,
|
||||
FirstAndLast,
|
||||
FirstSecondAndLast,
|
||||
All,
|
||||
}
|
||||
|
||||
public class TableStyle
|
||||
{
|
||||
public float MarginX;
|
||||
public float MarginY;
|
||||
public Font Font;
|
||||
public Font HeaderFont;
|
||||
public int TopHeadersCount;
|
||||
public int LeftHeadersCount;
|
||||
public float LineWidth;
|
||||
public TableLines HorizLines;
|
||||
public TableLines VertLines;
|
||||
}
|
||||
|
||||
public class Table
|
||||
{
|
||||
public readonly int ColumnsCount;
|
||||
public int RowsCount { get { return Rows.Count; } }
|
||||
|
||||
public readonly IList<string[]> Rows;
|
||||
public readonly IList<Alignment[]> HorizAlignments;
|
||||
public readonly IList<VertAlignment[]> VertAlignments;
|
||||
public TableStyle Style;
|
||||
|
||||
|
||||
public Table(int columnsCount)
|
||||
{
|
||||
ColumnsCount = columnsCount;
|
||||
|
||||
Rows = new List<string[]>();
|
||||
HorizAlignments = new List<Alignment[]>();
|
||||
VertAlignments = new List<VertAlignment[]>();
|
||||
Style = new TableStyle();
|
||||
}
|
||||
|
||||
|
||||
public void AddRow(string[] texts, Alignment[] horizAlignment, VertAlignment[] vertAlignemnt)
|
||||
{
|
||||
Rows.Add(texts);
|
||||
HorizAlignments.Add(horizAlignment);
|
||||
VertAlignments.Add(vertAlignemnt);
|
||||
}
|
||||
|
||||
|
||||
public SizeF Measure(System.Drawing.Printing.PrintPageEventArgs e)
|
||||
{
|
||||
SizeF retVal = new SizeF(0, 0);
|
||||
if (RowsCount == 0) return retVal;
|
||||
|
||||
float[] columnWidth = new float[ColumnsCount];
|
||||
float[] rowHeight = new float[RowsCount];
|
||||
|
||||
///
|
||||
/// Measure table column widths and header height
|
||||
///
|
||||
for (int colIx = 0; colIx < ColumnsCount; colIx++)
|
||||
{
|
||||
for (int rowIx = 0; rowIx < RowsCount; rowIx++)
|
||||
{
|
||||
bool isHeader = (colIx < Style.LeftHeadersCount) || (rowIx < Style.TopHeadersCount);
|
||||
SizeF size = PrintersCommon.Measure(e, Rows[rowIx][colIx], isHeader ? Style.HeaderFont : Style.Font);
|
||||
if (size.Width > columnWidth[colIx]) columnWidth[colIx] = size.Width;
|
||||
if (size.Height > rowHeight[rowIx]) rowHeight[rowIx] = size.Height;
|
||||
}
|
||||
|
||||
bool hasLineToTheLeft = (Style.VertLines == TableLines.All)
|
||||
|| ((Style.VertLines == TableLines.FirstAndLast) && (colIx == 0))
|
||||
|| ((Style.VertLines == TableLines.FirstSecondAndLast) && (colIx <= 1));
|
||||
|
||||
retVal.Width += columnWidth[colIx] + (hasLineToTheLeft ? (Style.LineWidth + Style.MarginX) : 0) + Style.MarginX;
|
||||
}
|
||||
for (int rowIx = 0; rowIx < RowsCount; rowIx++)
|
||||
{
|
||||
bool hasLineAbove = (Style.HorizLines == TableLines.All)
|
||||
|| ((Style.HorizLines == TableLines.FirstAndLast) && (rowIx == 0))
|
||||
|| ((Style.HorizLines == TableLines.FirstSecondAndLast) && (rowIx <= 1));
|
||||
|
||||
retVal.Height += rowHeight[rowIx] + (hasLineAbove ? (Style.LineWidth + Style.MarginY) : 0) + Style.MarginY;
|
||||
}
|
||||
|
||||
if (Style.VertLines == TableLines.None) retVal.Width -= Style.MarginX;
|
||||
if (Style.HorizLines == TableLines.None) retVal.Height -= Style.MarginY;
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
public float Draw(System.Drawing.Printing.PrintPageEventArgs e, float left, float top)
|
||||
{
|
||||
if (RowsCount == 0) return top;
|
||||
|
||||
int tblColumnsCount = Rows[0].Length;
|
||||
|
||||
float[] columnWidth = new float[tblColumnsCount];
|
||||
float[] columnPos = new float[tblColumnsCount];
|
||||
float[] vertLinePos = new float[tblColumnsCount + 1];
|
||||
|
||||
float[] rowHeight = new float[RowsCount];
|
||||
float[] rowPos = new float[RowsCount];
|
||||
float[] horizLinePos = new float[RowsCount + 1];
|
||||
|
||||
///
|
||||
/// Measure table column widths and header height
|
||||
///
|
||||
vertLinePos[0] = left;
|
||||
horizLinePos[0] = top;
|
||||
for (int colIx = 0; colIx < tblColumnsCount; colIx++)
|
||||
{
|
||||
for (int rowIx = 0; rowIx < RowsCount; rowIx++)
|
||||
{
|
||||
bool isHeader = (colIx < Style.LeftHeadersCount) || (rowIx < Style.TopHeadersCount);
|
||||
SizeF size = PrintersCommon.Measure(e, Rows[rowIx][colIx], isHeader ? Style.HeaderFont : Style.Font);
|
||||
if (size.Width > columnWidth[colIx]) columnWidth[colIx] = size.Width;
|
||||
if (size.Height > rowHeight[rowIx]) rowHeight[rowIx] = size.Height;
|
||||
}
|
||||
|
||||
bool hasLineToTheLeft = (Style.VertLines == TableLines.All)
|
||||
|| ((Style.VertLines == TableLines.FirstAndLast) && (colIx == 0))
|
||||
|| ((Style.VertLines == TableLines.FirstSecondAndLast) && (colIx <= 1));
|
||||
|
||||
columnPos[colIx] = vertLinePos[colIx] + (hasLineToTheLeft ? (Style.LineWidth + Style.MarginX) : 0);
|
||||
vertLinePos[colIx + 1] = columnPos[colIx] + columnWidth[colIx] + Style.MarginX;
|
||||
}
|
||||
for (int rowIx = 0; rowIx < RowsCount; rowIx++)
|
||||
{
|
||||
bool hasLineAbove = (Style.HorizLines == TableLines.All)
|
||||
|| ((Style.HorizLines == TableLines.FirstAndLast) && (rowIx == 0))
|
||||
|| ((Style.HorizLines == TableLines.FirstSecondAndLast) && (rowIx <= 1));
|
||||
|
||||
rowPos[rowIx] = horizLinePos[rowIx] + (hasLineAbove ? Style.MarginY : 0);
|
||||
horizLinePos[rowIx + 1] = rowPos[rowIx] + rowHeight[rowIx] + Style.LineWidth + Style.MarginY;
|
||||
}
|
||||
|
||||
/// Horizontal lines
|
||||
float tableLeftX = left;
|
||||
float tableRightX = vertLinePos[tblColumnsCount] + Style.LineWidth;
|
||||
if (Style.HorizLines != TableLines.None)
|
||||
{
|
||||
for (int rowIx = 0; rowIx <= RowsCount; rowIx++)
|
||||
{
|
||||
if (Style.HorizLines == TableLines.All || rowIx == 0 || rowIx == RowsCount || (Style.HorizLines == TableLines.FirstSecondAndLast && rowIx == 1))
|
||||
{
|
||||
e.Graphics.DrawLine(new Pen(Color.Black, Style.LineWidth), new PointF(tableLeftX, horizLinePos[rowIx] + Style.LineWidth / 2), new PointF(tableRightX, horizLinePos[rowIx] + Style.LineWidth / 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Vertical lines
|
||||
float tableTopY = top;
|
||||
float tableBottomY = horizLinePos[RowsCount] + Style.LineWidth;
|
||||
if (Style.VertLines != TableLines.None)
|
||||
{
|
||||
for (int colIx = 0; colIx <= tblColumnsCount; colIx++)
|
||||
{
|
||||
if (Style.VertLines == TableLines.All || colIx == 0 || colIx == RowsCount || (Style.VertLines == TableLines.FirstSecondAndLast && colIx == 1))
|
||||
{
|
||||
e.Graphics.DrawLine(new Pen(Color.Black, Style.LineWidth), new PointF(vertLinePos[colIx] + Style.LineWidth / 2, tableTopY), new PointF(vertLinePos[colIx] + Style.LineWidth / 2, tableBottomY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Draw table body
|
||||
///
|
||||
for (int rowIndex = 0; rowIndex < RowsCount; rowIndex++)
|
||||
{
|
||||
string[] oneTableRow = Rows[rowIndex];
|
||||
Alignment[] horizAlignment = HorizAlignments[(RowsCount > rowIndex) ? rowIndex : 0];
|
||||
VertAlignment[] vertAlignment = VertAlignments[(RowsCount > rowIndex) ? rowIndex : 0];
|
||||
for (int colIndex = 0; colIndex < tblColumnsCount; colIndex++)
|
||||
{
|
||||
bool isHeader = (colIndex < Style.LeftHeadersCount) || (rowIndex < Style.TopHeadersCount);
|
||||
PrintersCommon.PrintAt(e, oneTableRow[colIndex],
|
||||
isHeader ? Style.HeaderFont : Style.Font,
|
||||
columnPos[colIndex],
|
||||
rowPos[rowIndex],
|
||||
columnWidth[colIndex],
|
||||
rowHeight[rowIndex],
|
||||
horizAlignment[colIndex],
|
||||
vertAlignment[colIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
return tableBottomY;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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.825.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.825.0")]
|
||||
[assembly: AssemblyVersion("2.18.844.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.844.0")]
|
||||
|
||||
@ -114,6 +114,7 @@
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Output\Printers\OnePerMeter\OnePerMeterPrinterCfg.cs" />
|
||||
<Compile Include="Output\Printers\Table.cs" />
|
||||
<Compile Include="Output\Printers\Zapiska\ZapiskaPrintDocument.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
|
||||
@ -99,7 +99,6 @@ namespace TBF.BenchControl.Output.Printers.OnePerMeter
|
||||
printerCfg.SelectedItems2 = newCfg.SelectedItems2;
|
||||
printerCfg.Footer = newCfg.Footer;
|
||||
printerCfg.TestsAreRows = newCfg.TestsAreRows;
|
||||
printerCfg.TestsAreRows2 = newCfg.TestsAreRows2;
|
||||
printerCfg.DocName = newCfg.DocName;
|
||||
printerCfg.ImgName = newCfg.ImgName;
|
||||
printerCfg.ImgLeft = newCfg.ImgLeft;
|
||||
@ -203,7 +202,6 @@ namespace TBF.BenchControl.Output.Printers.OnePerMeter
|
||||
TestItems2 = printerCfg.SelectedItems2,
|
||||
Footer = printerCfg.Footer,
|
||||
TestsAreRows = printerCfg.TestsAreRows,
|
||||
TestsAreRows2 = printerCfg.TestsAreRows2,
|
||||
ImgFullPathName = (wm.ArchivePath != null) ? System.IO.Path.Combine(wm.ArchivePath, printerCfg.ImgName) : null,
|
||||
ImgLeft = printerCfg.ImgLeft,
|
||||
ImgTop = printerCfg.ImgTop,
|
||||
|
||||
@ -43,7 +43,6 @@ namespace TBF.BenchControl.Output.Printers.OnePerMeter
|
||||
public string[] SelectedItems2;
|
||||
public string Footer;
|
||||
public bool TestsAreRows; /// true = Tests are rows
|
||||
public bool TestsAreRows2; /// true = Tests are rows
|
||||
public string DocName;
|
||||
public string ImgName;
|
||||
public int ImgLeft;
|
||||
|
||||
@ -65,7 +65,6 @@ namespace TBF.BenchControl.Output.Printers.OnePerMeter
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.testsAreRowsCheckBox = new System.Windows.Forms.CheckBox();
|
||||
this.tests2AreRowsCheckBox = new System.Windows.Forms.CheckBox();
|
||||
this.testItems2Button = new System.Windows.Forms.Button();
|
||||
this.goodOnlyCheckBox = new System.Windows.Forms.CheckBox();
|
||||
this.templateTextBox = new System.Windows.Forms.TextBox();
|
||||
@ -409,17 +408,6 @@ namespace TBF.BenchControl.Output.Printers.OnePerMeter
|
||||
this.testsAreRowsCheckBox.Text = "Tests are rows";
|
||||
this.testsAreRowsCheckBox.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// tests2AreRowsCheckBox
|
||||
//
|
||||
this.tests2AreRowsCheckBox.AutoSize = true;
|
||||
this.tests2AreRowsCheckBox.Enabled = false;
|
||||
this.tests2AreRowsCheckBox.Location = new System.Drawing.Point(192, 281);
|
||||
this.tests2AreRowsCheckBox.Name = "tests2AreRowsCheckBox";
|
||||
this.tests2AreRowsCheckBox.Size = new System.Drawing.Size(104, 17);
|
||||
this.tests2AreRowsCheckBox.TabIndex = 36;
|
||||
this.tests2AreRowsCheckBox.Text = "Tests are rows 2";
|
||||
this.tests2AreRowsCheckBox.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// testItems2Button
|
||||
//
|
||||
this.testItems2Button.Enabled = false;
|
||||
@ -641,7 +629,6 @@ namespace TBF.BenchControl.Output.Printers.OnePerMeter
|
||||
this.Controls.Add(this.templateTextBox);
|
||||
this.Controls.Add(this.templateLabel);
|
||||
this.Controls.Add(this.goodOnlyCheckBox);
|
||||
this.Controls.Add(this.tests2AreRowsCheckBox);
|
||||
this.Controls.Add(this.testItems2Button);
|
||||
this.Controls.Add(this.testsAreRowsCheckBox);
|
||||
this.Controls.Add(this.label2);
|
||||
@ -721,7 +708,6 @@ namespace TBF.BenchControl.Output.Printers.OnePerMeter
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.CheckBox testsAreRowsCheckBox;
|
||||
private System.Windows.Forms.CheckBox tests2AreRowsCheckBox;
|
||||
private System.Windows.Forms.Button testItems2Button;
|
||||
private System.Windows.Forms.CheckBox goodOnlyCheckBox;
|
||||
private System.Windows.Forms.TextBox templateTextBox;
|
||||
|
||||
@ -122,7 +122,6 @@ namespace TBF.BenchControl.Output.Printers.OnePerMeter
|
||||
supressPrintingCheckBox.Checked = config.SupressPrinting;
|
||||
goodOnlyCheckBox.Checked = config.GoodOnly;
|
||||
testsAreRowsCheckBox.Checked = config.TestsAreRows;
|
||||
tests2AreRowsCheckBox.Checked = config.TestsAreRows2;
|
||||
|
||||
cultureComboBox.Text = config.Culture.ToString();
|
||||
|
||||
@ -167,7 +166,6 @@ namespace TBF.BenchControl.Output.Printers.OnePerMeter
|
||||
testItems2Button.Enabled = true;
|
||||
footerButton.Enabled = true;
|
||||
testsAreRowsCheckBox.Enabled = true;
|
||||
tests2AreRowsCheckBox.Enabled = true;
|
||||
docNameTextBox.Enabled = true;
|
||||
imageNameTextBox.Enabled = true;
|
||||
imageLeftTextBox.Enabled = true;
|
||||
@ -319,7 +317,6 @@ namespace TBF.BenchControl.Output.Printers.OnePerMeter
|
||||
flags |= UpdateDifferent(ref config.SupressPrinting, supressPrintingCheckBox.Checked, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
flags |= UpdateDifferent(ref config.GoodOnly, goodOnlyCheckBox.Checked, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
flags |= UpdateDifferent(ref config.TestsAreRows, testsAreRowsCheckBox.Checked, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
flags |= UpdateDifferent(ref config.TestsAreRows2, tests2AreRowsCheckBox.Checked, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
|
||||
flags |= UpdateDifferent(ref config.CommonItems, commonItems, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
flags |= UpdateDifferent(ref config.SelectedItems, testItems, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
|
||||
@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.18.843.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.843.0")]
|
||||
[assembly: AssemblyVersion("2.18.844.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.844.0")]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user