(1) Printers.OnePerMeter with 3 columns above and below the body, (2) static Table Create_xy(...) introduced, ver. 2.18.866
This commit is contained in:
@@ -29,11 +29,10 @@ namespace Results.Output.Printers.OnePerMeter
|
||||
readonly int spacingOne;
|
||||
readonly int spacingOne4Header;
|
||||
|
||||
float commonTop; /// = TitleY + 60
|
||||
float bodyTop; /// = HdrTop + 160
|
||||
float commonTop; /// = TitleY + 60
|
||||
float bodyTop; /// = HdrTop + 160
|
||||
///
|
||||
float titleHeight;
|
||||
float commonHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Property variable for the Font the user wishes to use
|
||||
@@ -54,9 +53,14 @@ namespace Results.Output.Printers.OnePerMeter
|
||||
/// Items to print
|
||||
///
|
||||
string header;
|
||||
IList<WMeterRsltItemSpec> commonItems;
|
||||
IList<WMeterRsltItemSpec> commonItems1;
|
||||
IList<WMeterRsltItemSpec> commonItems2;
|
||||
IList<WMeterRsltItemSpec> commonItems3;
|
||||
IList<WMeterRsltItemSpec> testItems;
|
||||
IList<WMeterRsltItemSpec> testItems2;
|
||||
IList<WMeterRsltItemSpec> belowItems1;
|
||||
IList<WMeterRsltItemSpec> belowItems2;
|
||||
IList<WMeterRsltItemSpec> belowItems3;
|
||||
string footer;
|
||||
|
||||
int nrPages;
|
||||
@@ -78,9 +82,14 @@ namespace Results.Output.Printers.OnePerMeter
|
||||
leftMargin = cfg.LeftMargin;
|
||||
|
||||
header = string.IsNullOrEmpty(cfg.Header) ? string.Empty : cfg.Header.Replace("~", Environment.NewLine);
|
||||
commonItems = Results.WMeterRsltItemSpec.FromStrArray(cfg.CommonItems);
|
||||
testItems = Results.WMeterRsltItemSpec.FromStrArray(cfg.TestItems); /// TestID info will be overwritten later on
|
||||
commonItems1 = Results.WMeterRsltItemSpec.FromStrArray(cfg.CommonItems1);
|
||||
commonItems2 = Results.WMeterRsltItemSpec.FromStrArray(cfg.CommonItems2);
|
||||
commonItems3 = Results.WMeterRsltItemSpec.FromStrArray(cfg.CommonItems3);
|
||||
testItems = Results.WMeterRsltItemSpec.FromStrArray(cfg.TestItems); /// TestID info will be overwritten later on
|
||||
testItems2 = Results.WMeterRsltItemSpec.FromStrArray(cfg.TestItems2); /// TestID info will be overwritten later on
|
||||
belowItems1 = Results.WMeterRsltItemSpec.FromStrArray(cfg.BelowItems1);
|
||||
belowItems2 = Results.WMeterRsltItemSpec.FromStrArray(cfg.BelowItems2);
|
||||
belowItems3 = Results.WMeterRsltItemSpec.FromStrArray(cfg.BelowItems3);
|
||||
footer = string.IsNullOrEmpty(cfg.Footer) ? string.Empty : cfg.Footer.Replace("~", Environment.NewLine);
|
||||
|
||||
/// Initialize fonts
|
||||
@@ -168,66 +177,152 @@ namespace Results.Output.Printers.OnePerMeter
|
||||
e.Graphics.DrawString(header, titleFont, Brushes.Black, printArea);
|
||||
|
||||
titleHeight = System.Windows.Forms.TextRenderer.MeasureText(header, titleFont).Height;
|
||||
commonTop = TitleY + titleHeight + spacingOne4Header;
|
||||
commonTop = TitleY + titleHeight;
|
||||
|
||||
///----------------
|
||||
/// Common items
|
||||
///----------------
|
||||
commonTop += spacingOne4Header; /// Space above common part
|
||||
float leftMarginCommon1 = leftMargin + printWidth * 0.01f * cfg.ColW0Pct;
|
||||
float leftMarginCommon2 = leftMargin + printWidth * 0.01f * (cfg.ColW0Pct + cfg.ColW1Pct);
|
||||
float leftMarginCommon3 = leftMargin + printWidth * 0.01f * (cfg.ColW0Pct + cfg.ColW1Pct + cfg.ColW2Pct);
|
||||
|
||||
|
||||
///
|
||||
/// Common items
|
||||
///
|
||||
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)
|
||||
{
|
||||
TableStyle commonTableStyle = new TableStyle { Font = font, MarginX = 5, MarginY = 3 };
|
||||
|
||||
Table table = new Table(2) { Style = commonTableStyle };
|
||||
foreach (var v in commonItems1)
|
||||
{
|
||||
string[] row = new string[] { v.Caption, (batch.WaterMeters.Count > 0) ? v.Print(batch.WaterMeters[0]) : string.Empty };
|
||||
table.AddRow(row, horizAlgn, vertAlgn);
|
||||
}
|
||||
}
|
||||
float bodyTop1 = table.Draw(e, leftMarginCommon1, commonTop);
|
||||
|
||||
bodyTop = table.Draw(e, (float)leftMargin, commonTop) + spacingOne4Header;
|
||||
|
||||
table = new Table(2) { Style = commonTableStyle };
|
||||
foreach (var v in commonItems2)
|
||||
{
|
||||
string[] row = new string[] { v.Caption, (batch.WaterMeters.Count > 0) ? v.Print(batch.WaterMeters[0]) : string.Empty };
|
||||
table.AddRow(row, horizAlgn, vertAlgn);
|
||||
}
|
||||
float bodyTop2 = table.Draw(e, leftMarginCommon2, commonTop);
|
||||
|
||||
|
||||
table = new Table(2) { Style = commonTableStyle };
|
||||
foreach (var v in commonItems3)
|
||||
{
|
||||
string[] row = new string[] { v.Caption, (batch.WaterMeters.Count > 0) ? v.Print(batch.WaterMeters[0]) : string.Empty };
|
||||
table.AddRow(row, horizAlgn, vertAlgn);
|
||||
}
|
||||
float bodyTop3 = table.Draw(e, leftMarginCommon3, commonTop);
|
||||
|
||||
float bodyTop12 = (bodyTop1 > bodyTop2) ? bodyTop1 : bodyTop2;
|
||||
bodyTop = (bodyTop12 > bodyTop3) ? bodyTop12 : bodyTop3; /// Max. of all three bodyTop-s
|
||||
bodyTop += spacingOne4Header; /// Space between the common part and the table
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw table
|
||||
///
|
||||
if (cfg.TestsAreRows)
|
||||
float belowTop;
|
||||
TableStyle style;
|
||||
switch (cfg.Form)
|
||||
{
|
||||
TableStyle style = new TableStyle
|
||||
{
|
||||
Font = font,
|
||||
HeaderFont = headerFont,
|
||||
MarginX = 5,
|
||||
MarginY = 3,
|
||||
LineWidth = 1,
|
||||
TopHeadersCount = 1,
|
||||
HorizLines = TableLines.All,
|
||||
VertLines = TableLines.FirstSecondAndLast
|
||||
};
|
||||
default:
|
||||
case TableForm.Rows:
|
||||
|
||||
GetTable_TestsAreRows(wm, (pageNr == 1) ? testItems : testItems2, style).Draw(e, (float)leftMargin, bodyTop);
|
||||
}
|
||||
else
|
||||
{
|
||||
TableStyle style = new TableStyle
|
||||
{
|
||||
Font = font,
|
||||
HeaderFont = headerFont,
|
||||
MarginX = 5,
|
||||
MarginY = 3,
|
||||
LineWidth = 1,
|
||||
LeftHeadersCount = 1,
|
||||
HorizLines = TableLines.FirstSecondAndLast,
|
||||
VertLines = TableLines.All
|
||||
};
|
||||
style = new TableStyle
|
||||
{
|
||||
Font = font,
|
||||
HeaderFont = headerFont,
|
||||
MarginX = 5,
|
||||
MarginY = 3,
|
||||
LineWidth = 1,
|
||||
TopHeadersCount = 1,
|
||||
HorizLines = TableLines.All,
|
||||
VertLines = TableLines.FirstSecondAndLast
|
||||
};
|
||||
belowTop = Table.Create_TestsAreRows(wm, (pageNr == 1) ? testItems : testItems2, style).Draw(e, (float)leftMargin, bodyTop);
|
||||
break;
|
||||
|
||||
GetTable_TestsAreColumns(wm, (pageNr == 1) ? testItems : testItems2, style).Draw(e, (float)leftMargin, bodyTop);
|
||||
case TableForm.Columns:
|
||||
|
||||
style = new TableStyle
|
||||
{
|
||||
Font = font,
|
||||
HeaderFont = headerFont,
|
||||
MarginX = 5,
|
||||
MarginY = 3,
|
||||
LineWidth = 1,
|
||||
LeftHeadersCount = 1,
|
||||
HorizLines = TableLines.FirstSecondAndLast,
|
||||
VertLines = TableLines.All
|
||||
};
|
||||
belowTop = Table.Create_TestsAreColumns(wm, (pageNr == 1) ? testItems : testItems2, style).Draw(e, (float)leftMargin, bodyTop);
|
||||
break;
|
||||
|
||||
case TableForm.ColumnsPL:
|
||||
|
||||
style = new TableStyle
|
||||
{
|
||||
Font = font,
|
||||
HeaderFont = headerFont,
|
||||
MarginX = 5,
|
||||
MarginY = 3,
|
||||
LineWidth = 1,
|
||||
TopHeadersCount = 1,
|
||||
HorizLines = TableLines.FirstSecondAndLast,
|
||||
VertLines = TableLines.All
|
||||
};
|
||||
belowTop = Table.Create_TestsAreColumnsPL(wm, (pageNr == 1) ? testItems : testItems2, style).Draw(e, (float)leftMargin, bodyTop);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (pageNr == nrPages)
|
||||
{
|
||||
///
|
||||
///----------------
|
||||
/// Common items
|
||||
///----------------
|
||||
belowTop += spacingOne4Header; /// Space between the table and the bottom common part
|
||||
float leftMarginBelow1 = leftMargin + printWidth * 0.01f * cfg.BelowW0Pct;
|
||||
float leftMarginBelow2 = leftMargin + printWidth * 0.01f * (cfg.BelowW0Pct + cfg.BelowW1Pct);
|
||||
float leftMarginBelow3 = leftMargin + printWidth * 0.01f * (cfg.BelowW0Pct + cfg.BelowW1Pct + cfg.BelowW2Pct);
|
||||
|
||||
Alignment[] horizAlgn = new Alignment[] { Alignment.Left, Alignment.Left };
|
||||
VertAlignment[] vertAlgn = new VertAlignment[] { VertAlignment.Top, VertAlignment.Top };
|
||||
TableStyle commonTableStyle = new TableStyle { Font = font, MarginX = 5, MarginY = 3 };
|
||||
|
||||
Table table = new Table(2) { Style = commonTableStyle };
|
||||
foreach (var v in belowItems1)
|
||||
{
|
||||
string[] row = new string[] { v.Caption, (batch.WaterMeters.Count > 0) ? v.Print(batch.WaterMeters[0]) : string.Empty };
|
||||
table.AddRow(row, horizAlgn, vertAlgn);
|
||||
}
|
||||
table.Draw(e, leftMarginBelow1, belowTop);
|
||||
|
||||
|
||||
table = new Table(2) { Style = commonTableStyle };
|
||||
foreach (var v in belowItems2)
|
||||
{
|
||||
string[] row = new string[] { v.Caption, (batch.WaterMeters.Count > 0) ? v.Print(batch.WaterMeters[0]) : string.Empty };
|
||||
table.AddRow(row, horizAlgn, vertAlgn);
|
||||
}
|
||||
table.Draw(e, leftMarginBelow2, belowTop);
|
||||
|
||||
|
||||
table = new Table(2) { Style = commonTableStyle };
|
||||
foreach (var v in belowItems3)
|
||||
{
|
||||
string[] row = new string[] { v.Caption, (batch.WaterMeters.Count > 0) ? v.Print(batch.WaterMeters[0]) : string.Empty };
|
||||
table.AddRow(row, horizAlgn, vertAlgn);
|
||||
}
|
||||
table.Draw(e, leftMarginBelow3, belowTop);
|
||||
|
||||
|
||||
///
|
||||
/// Footer on the last page
|
||||
///
|
||||
float footerWidth = e.Graphics.MeasureString(footer, footerFont).Width;
|
||||
@@ -245,107 +340,5 @@ namespace Results.Output.Printers.OnePerMeter
|
||||
|
||||
pageNr++;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Table GetTable_TestsAreColumns(Results.Entities.WaterMeter wm, IList<WMeterRsltItemSpec> items, TableStyle style)
|
||||
{
|
||||
/// Left column contains row captions
|
||||
|
||||
///
|
||||
/// Calculate columns count
|
||||
///
|
||||
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)
|
||||
{
|
||||
columnsCount++; /// One additional column for each test to be published
|
||||
}
|
||||
}
|
||||
|
||||
Table table = new Table(columnsCount);
|
||||
table.Style = style;
|
||||
|
||||
///
|
||||
/// Table content
|
||||
///
|
||||
WMeterRsltItemSpec.TableRowNr = 1;
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
string[] oneTableRow = new string[columnsCount];
|
||||
Alignment[] horizAlignment = new Alignment[columnsCount];
|
||||
VertAlignment[] vertAlignment = new VertAlignment[columnsCount];
|
||||
|
||||
oneTableRow[0] = items[i].Caption;
|
||||
horizAlignment[0] = Alignment.Center;
|
||||
vertAlignment[0] = VertAlignment.Middle;
|
||||
|
||||
WMeterRsltItemSpec.TableColumnNr = 1;
|
||||
foreach (var mtr in wm.MeterTestRslts)
|
||||
{
|
||||
if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always)
|
||||
{
|
||||
/// Strip color information
|
||||
oneTableRow[WMeterRsltItemSpec.TableColumnNr] =
|
||||
items[i].Print(wm, mtr.Name()).Split(new char[] { '|' })[0];
|
||||
horizAlignment[WMeterRsltItemSpec.TableColumnNr] = items[i].Alignment;
|
||||
vertAlignment[WMeterRsltItemSpec.TableColumnNr] = VertAlignment.Middle;
|
||||
|
||||
WMeterRsltItemSpec.TableColumnNr++;
|
||||
}
|
||||
}
|
||||
|
||||
table.AddRow(oneTableRow, horizAlignment, vertAlignment);
|
||||
|
||||
WMeterRsltItemSpec.TableRowNr++;
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,10 +27,23 @@ namespace Results.Output.Printers.OnePerMeter
|
||||
public bool SupressPrinting; /// Bypass printing when true
|
||||
public System.Globalization.CultureInfo CultureInfo;
|
||||
public string Header; /// =Title
|
||||
public string[] CommonItems;
|
||||
public string[] TestItems;
|
||||
public int ColW0Pct;
|
||||
public int ColW1Pct;
|
||||
public int ColW2Pct;
|
||||
public string[] CommonItems1;
|
||||
public string[] CommonItems2;
|
||||
public string[] CommonItems3;
|
||||
public Config.Entities.TableForm Form;
|
||||
public string[] TestItems;
|
||||
public Config.Entities.TableForm Form2;
|
||||
public string[] TestItems2;
|
||||
public string Footer;
|
||||
public int BelowW0Pct;
|
||||
public int BelowW1Pct;
|
||||
public int BelowW2Pct;
|
||||
public string[] BelowItems1;
|
||||
public string[] BelowItems2;
|
||||
public string[] BelowItems3;
|
||||
public string Footer;
|
||||
public bool TestsAreRows;
|
||||
public string ImgFullPathName;
|
||||
public int ImgLeft;
|
||||
|
||||
Reference in New Issue
Block a user