Table rewritten, Cell, TopBorder, LeftBorder, BottomMerge, RightMerge added, merging OK, clean-up, ver. 3.8.2108

This commit is contained in:
Milan Hanajik
2023-10-12 15:23:06 +02:00
parent 36d661c75e
commit 0073ac8b9e
12 changed files with 582 additions and 492 deletions
@@ -34,6 +34,22 @@ namespace Results.Output.Printers.Enhanced
readonly int spacingOneAndHalf4Header;
readonly int spacingOne4Footer;
/// <summary>
/// Property variable for the Font the user wishes to use
/// </summary>
readonly Font titleFont;
readonly Font headerFont;
readonly Font font;
readonly Font footerFont;
///
/// Items to print
///
readonly string header;
readonly IList<WMeterRsltItemSpec> commonItems;
readonly IList<WMeterRsltItemSpec> testItems;
readonly string footer;
int spacingAboveTable;
int spacingBelowTable;
@@ -43,14 +59,6 @@ namespace Results.Output.Printers.Enhanced
int titleHeight;
int commonHeight;
/// <summary>
/// Property variable for the Font the user wishes to use
/// </summary>
Font titleFont;
Font headerFont;
Font font;
Font footerFont;
TableStyle style;
///
@@ -60,14 +68,6 @@ namespace Results.Output.Printers.Enhanced
EnhancedPrinterCfg cfg;
///
/// Items to print
///
string header;
IList<WMeterRsltItemSpec> commonItems;
IList<WMeterRsltItemSpec> testItems;
string footer;
///
/// Layout and status
///
@@ -93,15 +93,15 @@ namespace Results.Output.Printers.Enhanced
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
commonItems = WMeterRsltItemSpec.FromStrArray(cfg.CommonItems);
testItems = WMeterRsltItemSpec.FromStrArray(cfg.TestItems); /// TestID info will be overwritten later on
footer = string.IsNullOrEmpty(cfg.Footer) ? string.Empty : cfg.Footer.Replace("~", Environment.NewLine);
/// Initialize fonts
titleFont = new Font((cfg.TitFntFml != null ? cfg.TitFntFml : "Arial"), (cfg.TitFntSz > 0 ? cfg.TitFntSz : 10), (FontStyle)cfg.TitFntSty);
headerFont = new Font((cfg.HdrFntFml != null ? cfg.HdrFntFml : "Arial"), (cfg.HdrFntSz > 0 ? cfg.HdrFntSz : 10), (FontStyle)cfg.HdrFntSty);
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);
titleFont = new Font(cfg.TitFntFml ?? "Arial", cfg.TitFntSz > 0 ? cfg.TitFntSz : 10, (FontStyle)cfg.TitFntSty);
headerFont = new Font(cfg.HdrFntFml ?? "Arial", cfg.HdrFntSz > 0 ? cfg.HdrFntSz : 10, (FontStyle)cfg.HdrFntSty);
font = new Font(cfg.BodyFntFml ?? "Arial", cfg.BodyFntSz > 0 ? cfg.BodyFntSz : 10, (FontStyle)cfg.BodyFntSty);
footerFont = new Font(cfg.FooterFntFml ?? "Arial", cfg.FooterFntSz > 0 ? cfg.FooterFntSz : 10, (FontStyle)cfg.FooterFntSty);
/// Table style of one water meter table where tests are rows
style = new TableStyle
@@ -149,7 +149,7 @@ namespace Results.Output.Printers.Enhanced
/// </summary>
/// <param name=e></param>
/// <remarks></remarks>
protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e)
protected override void OnBeginPrint(PrintEventArgs e)
{
base.OnBeginPrint(e);
}
@@ -159,7 +159,7 @@ namespace Results.Output.Printers.Enhanced
/// </summary>
/// <param name=e></param>
/// <remarks>This provides the print logic for our document</remarks>
protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
protected override void OnPrintPage(PrintPageEventArgs e)
{
/// Run base code
base.OnPrintPage(e);
@@ -284,7 +284,7 @@ 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>
float PrintWM(System.Drawing.Printing.PrintPageEventArgs e,
float PrintWM(PrintPageEventArgs e,
Results.Entities.WaterMeter wm, int printedWMNr, int top)
{
int tableTop = top + spacingAboveTable;
@@ -332,33 +332,33 @@ namespace Results.Output.Printers.Enhanced
}
void PrintAt(System.Drawing.Printing.PrintPageEventArgs e, Point p, string text)
void PrintAt(PrintPageEventArgs e, Point p, string text)
{
PrintAt(e, p.X, p.Y, text);
}
void PrintAt(System.Drawing.Printing.PrintPageEventArgs e, int x, int y, string text)
void PrintAt(PrintPageEventArgs e, int x, int y, string text)
{
RectangleF printArea = new RectangleF(x, y, 2000, spacingOne);
e.Graphics.DrawString(text, this.font, Brushes.Black, printArea);
}
void PrintHeaderAt(System.Drawing.Printing.PrintPageEventArgs e, Point p, string text)
void PrintHeaderAt(PrintPageEventArgs e, Point p, string text)
{
PrintHeaderAt(e, p.X, p.Y, text);
}
void PrintHeaderAt(System.Drawing.Printing.PrintPageEventArgs e, int x, int y, string text)
void PrintHeaderAt(PrintPageEventArgs e, int x, int y, string text)
{
RectangleF printArea = new RectangleF(x, y, 2000, spacingOne4Header);
e.Graphics.DrawString(text, this.headerFont, Brushes.Black, printArea);
}
void PrintFooterAt(System.Drawing.Printing.PrintPageEventArgs e, Point p, string text)
void PrintFooterAt(PrintPageEventArgs e, Point p, string text)
{
PrintFooterAt(e, p.X, p.Y, text);
}
void PrintFooterAt(System.Drawing.Printing.PrintPageEventArgs e, int x, int y, string text)
void PrintFooterAt(PrintPageEventArgs e, int x, int y, string text)
{
RectangleF printArea = new RectangleF(x, y, 2000, spacingOne4Footer);
e.Graphics.DrawString(text, this.footerFont, Brushes.Black, printArea);
@@ -9,7 +9,6 @@ using System.Drawing.Printing;
using System.IO;
using Gma.QrCodeNet.Encoding;
using Common;
using Results.Resources;
using GenCode128;
namespace Results.Output.Printers.Label
@@ -22,17 +21,17 @@ namespace Results.Output.Printers.Label
readonly int printHeight;
readonly int printWidth;
/// Selected font
readonly Font font;
/// Items to print
readonly IList<WMeterRsltItemSpec> itemsToPrint;
/// Selected font
readonly Font font;
/// Data to print
Results.Entities.Batch batch;
LabelPrinterCfg cfg;
Results.Entities.WaterMeter wm;
/// Items to print
IList<WMeterRsltItemSpec> itemsToPrint;
/// <summary>
/// Constructor
/// </summary>
@@ -44,12 +43,10 @@ namespace Results.Output.Printers.Label
this.batch = batch;
this.cfg = cfg;
this.wm = wm;
this.itemsToPrint = Results.WMeterRsltItemSpec.FromStrArray(cfg.ItemsToPrint);
this.itemsToPrint = WMeterRsltItemSpec.FromStrArray(cfg.ItemsToPrint);
/// Initialize fonts
font = new Font((cfg.FontFamily != null ? cfg.FontFamily : "Arial"),
(cfg.FontSize > 0 ? cfg.FontSize : 10),
(FontStyle)cfg.FontStyle);
font = new Font(cfg.FontFamily ?? "Arial", cfg.FontSize > 0 ? cfg.FontSize : 10, (FontStyle)cfg.FontStyle);
/// Set print area size and margins (in dots using 100 dpi)
DefaultPageSettings.Landscape = (cfg.PageOrientation == PageOrientation.Landscape);
@@ -63,7 +60,7 @@ namespace Results.Output.Printers.Label
/// </summary>
/// <param name=e></param>
/// <remarks></remarks>
protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e)
protected override void OnBeginPrint(PrintEventArgs e)
{
base.OnBeginPrint(e);
}
@@ -73,7 +70,7 @@ namespace Results.Output.Printers.Label
/// </summary>
/// <param name=e></param>
/// <remarks>This provides the print logic for our document</remarks>
protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
protected override void OnPrintPage(PrintPageEventArgs e)
{
/// Run base code
base.OnPrintPage(e);
@@ -9,7 +9,6 @@ using System.Drawing.Printing;
using System.IO;
using Gma.QrCodeNet.Encoding;
using Common;
using Results.Resources;
using GenCode128;
namespace Results.Output.Printers.MultiLabel
@@ -22,17 +21,17 @@ namespace Results.Output.Printers.MultiLabel
readonly int labelHeight;
readonly int labelWidth;
/// Selected font
readonly Font font;
/// Items to print
readonly IList<WMeterRsltItemSpec> itemsToPrint;
/// Selected font
readonly Font font;
/// Data to print
Results.Entities.Batch batch;
MultiLabelPrinterCfg cfg;
IList<Results.Entities.WaterMeter> waterMeters;
/// Items to print
IList<WMeterRsltItemSpec> itemsToPrint;
/// <summary>
/// Constructor
/// </summary>
@@ -44,15 +43,13 @@ namespace Results.Output.Printers.MultiLabel
this.batch = batch;
this.waterMeters = batch.WaterMeters;
this.cfg = cfg;
this.itemsToPrint = Results.WMeterRsltItemSpec.FromStrArray(cfg.ItemsToPrint);
this.itemsToPrint = WMeterRsltItemSpec.FromStrArray(cfg.ItemsToPrint);
/// Initialize fonts
font = new Font((cfg.FontFamily != null ? cfg.FontFamily : "Arial"),
(cfg.FontSize > 0 ? cfg.FontSize : 10),
(FontStyle)cfg.FontStyle);
/// Initialize fonts
font = new Font(cfg.FontFamily ?? "Arial", cfg.FontSize > 0 ? cfg.FontSize : 10, (FontStyle)cfg.FontStyle);
/// Set print area size and margins (in dots using 100 dpi)
DefaultPageSettings.Landscape = (cfg.PageOrientation == PageOrientation.Landscape);
/// Set print area size and margins (in dots using 100 dpi)
DefaultPageSettings.Landscape = (cfg.PageOrientation == PageOrientation.Landscape);
///
labelHeight = cfg.LabelHeight;
labelWidth = cfg.LabelWidth;
@@ -63,7 +60,7 @@ namespace Results.Output.Printers.MultiLabel
/// </summary>
/// <param name=e></param>
/// <remarks></remarks>
protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e)
protected override void OnBeginPrint(PrintEventArgs e)
{
base.OnBeginPrint(e);
}
@@ -73,7 +70,7 @@ namespace Results.Output.Printers.MultiLabel
/// </summary>
/// <param name=e></param>
/// <remarks>This provides the print logic for our document</remarks>
protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
protected override void OnPrintPage(PrintPageEventArgs e)
{
/// Run base code
base.OnPrintPage(e);
@@ -13,9 +13,6 @@ namespace Results.Output.Printers.OnePerBatch
{
public class OnePerBatchPrintDocument : Common.Printers.PrintersCommon
{
const float GapBetweenTableColumns = 10;
const float GapBetweenCommonColumns = 10;
/// Size of the printed area without margins, after taking into account 'pageOrientation'
readonly int printHeight;
readonly int printWidth;
@@ -28,39 +25,39 @@ namespace Results.Output.Printers.OnePerBatch
readonly int spacingOne;
readonly int spacingOne4Header;
float titleHeight;
/// <summary>
/// Property variable for the Font the user wishes to use
/// </summary>
Font titleFont;
Font headerFont;
Font font;
Font footerFont;
///
/// Data to print
///
Results.Entities.Batch batch;
OnePerBatchPrinterCfg cfg;
Results.Entities.WaterMeter wm;
readonly Font titleFont;
readonly Font headerFont;
readonly Font font;
readonly Font footerFont;
///
/// Items to print
///
string header;
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;
readonly string header;
readonly IList<WMeterRsltItemSpec> commonItems1;
readonly IList<WMeterRsltItemSpec> commonItems2;
readonly IList<WMeterRsltItemSpec> commonItems3;
readonly IList<WMeterRsltItemSpec> testItems;
readonly IList<WMeterRsltItemSpec> testItems2;
readonly IList<WMeterRsltItemSpec> belowItems1;
readonly IList<WMeterRsltItemSpec> belowItems2;
readonly IList<WMeterRsltItemSpec> belowItems3;
readonly string footer;
int nrPages;
///
/// Data to print
///
Results.Entities.Batch batch;
OnePerBatchPrinterCfg cfg;
Results.Entities.WaterMeter wm;
float titleHeight;
int nrPages;
int pageNr; /// Page number to be printed at the bottom of the page
/// <summary>
@@ -79,21 +76,21 @@ namespace Results.Output.Printers.OnePerBatch
leftMargin = cfg.LeftMargin;
header = string.IsNullOrEmpty(cfg.Header) ? string.Empty : cfg.Header.Replace("~", Environment.NewLine);
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);
commonItems1 = WMeterRsltItemSpec.FromStrArray(cfg.CommonItems1);
commonItems2 = WMeterRsltItemSpec.FromStrArray(cfg.CommonItems2);
commonItems3 = WMeterRsltItemSpec.FromStrArray(cfg.CommonItems3);
testItems = WMeterRsltItemSpec.FromStrArray(cfg.TestItems); /// TestID info will be overwritten later on
testItems2 = WMeterRsltItemSpec.FromStrArray(cfg.TestItems2); /// TestID info will be overwritten later on
belowItems1 = WMeterRsltItemSpec.FromStrArray(cfg.BelowItems1);
belowItems2 = WMeterRsltItemSpec.FromStrArray(cfg.BelowItems2);
belowItems3 = WMeterRsltItemSpec.FromStrArray(cfg.BelowItems3);
footer = string.IsNullOrEmpty(cfg.Footer) ? string.Empty : cfg.Footer.Replace("~", Environment.NewLine);
/// Initialize fonts
titleFont = new Font((cfg.TitFntFml != null ? cfg.TitFntFml : "Arial"), (cfg.TitFntSz > 0 ? cfg.TitFntSz : 10), (FontStyle)cfg.TitFntSty);
headerFont = new Font((cfg.HdrFntFml != null ? cfg.HdrFntFml : "Arial"), (cfg.HdrFntSz > 0 ? cfg.HdrFntSz : 10), (FontStyle)cfg.HdrFntSty);
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);
titleFont = new Font(cfg.TitFntFml ?? "Arial", cfg.TitFntSz > 0 ? cfg.TitFntSz : 10, (FontStyle)cfg.TitFntSty);
headerFont = new Font(cfg.HdrFntFml ?? "Arial", cfg.HdrFntSz > 0 ? cfg.HdrFntSz : 10, (FontStyle)cfg.HdrFntSty);
font = new Font(cfg.BodyFntFml ?? "Arial", cfg.BodyFntSz > 0 ? cfg.BodyFntSz : 10, (FontStyle)cfg.BodyFntSty);
footerFont = new Font(cfg.FooterFntFml ?? "Arial", cfg.FooterFntSz > 0 ? cfg.FooterFntSz : 10, (FontStyle)cfg.FooterFntSty);
/// Set print area size and margins (in dots using 100 dpi)
DefaultPageSettings.Landscape = (cfg.PageOrientation == PageOrientation.Landscape);
@@ -125,7 +122,7 @@ namespace Results.Output.Printers.OnePerBatch
/// </summary>
/// <param name=e></param>
/// <remarks></remarks>
protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e)
protected override void OnBeginPrint(PrintEventArgs e)
{
base.OnBeginPrint(e);
}
@@ -135,7 +132,7 @@ namespace Results.Output.Printers.OnePerBatch
/// </summary>
/// <param name=e></param>
/// <remarks>This provides the print logic for our document</remarks>
protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
protected override void OnPrintPage(PrintPageEventArgs e)
{
/// Run base code
base.OnPrintPage(e);
@@ -194,35 +191,33 @@ namespace Results.Output.Printers.OnePerBatch
float leftMarginCommon2 = leftMargin + printWidth * 0.01f * (cfg.ColW0Pct + cfg.ColW1Pct);
float leftMarginCommon3 = leftMargin + printWidth * 0.01f * (cfg.ColW0Pct + cfg.ColW1Pct + cfg.ColW2Pct);
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 table1 = new Table(2, cfg.AutoTestParam) { Style = commonTableStyle };
var table1 = new Table(2, commonTableStyle, cfg.AutoTestParam);
foreach (var item in commonItems1)
{
string[] row = new string[] { item.Caption, item.Print(wm).Split(new char[] { '|' })[0] };
table1.AddRow(row, horizAlgn, vertAlgn);
table1.AddRow(new Cell[] { new Cell(item.Caption, font),
new Cell(item.Print(wm).Split(new char[] { '|' })[0], font) });
}
float bodyTop1 = table1.Draw(e, leftMarginCommon1, commonTop);
table1 = new Table(2, cfg.AutoTestParam) { Style = commonTableStyle };
var table2 = new Table(2, commonTableStyle, cfg.AutoTestParam);
foreach (var item in commonItems2)
{
string[] row = new string[] { item.Caption, item.Print(wm).Split(new char[] { '|' })[0] };
table1.AddRow(row, horizAlgn, vertAlgn);
table2.AddRow(new Cell[] { new Cell(item.Caption, font),
new Cell(item.Print(wm).Split(new char[] { '|' })[0], font) });
}
float bodyTop2 = table1.Draw(e, leftMarginCommon2, commonTop);
float bodyTop2 = table2.Draw(e, leftMarginCommon2, commonTop);
table1 = new Table(2, cfg.AutoTestParam) { Style = commonTableStyle };
var table3 = new Table(2, commonTableStyle, cfg.AutoTestParam);
foreach (var item in commonItems3)
{
string[] row = new string[] { item.Caption, item.Print(wm).Split(new char[] { '|' })[0] };
table1.AddRow(row, horizAlgn, vertAlgn);
table3.AddRow(new Cell[] { new Cell(item.Caption, font),
new Cell(item.Print(wm).Split(new char[] { '|' })[0], font) });
}
float bodyTop3 = table1.Draw(e, leftMarginCommon3, commonTop);
float bodyTop3 = table3.Draw(e, leftMarginCommon3, commonTop);
float bodyTop12 = (bodyTop1 > bodyTop2) ? bodyTop1 : bodyTop2;
tableTop = (bodyTop12 > bodyTop3) ? bodyTop12 : bodyTop3; /// Max. of all three bodyTop-s
@@ -302,35 +297,33 @@ namespace Results.Output.Printers.OnePerBatch
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 table2 = new Table(2, cfg.AutoTestParam) { Style = commonTableStyle };
var table4 = new Table(2, commonTableStyle, cfg.AutoTestParam);
foreach (var item in belowItems1)
{
string[] row = new string[] { item.Caption, item.Print(wm).Split(new char[] { '|' })[0] };
table2.AddRow(row, horizAlgn, vertAlgn);
table4.AddRow(new Cell[] { new Cell(item.Caption, font),
new Cell(item.Print(wm).Split(new char[] { '|' })[0], font) });
}
table2.Draw(e, leftMarginBelow1, belowTop);
table4.Draw(e, leftMarginBelow1, belowTop);
table2 = new Table(2, cfg.AutoTestParam) { Style = commonTableStyle };
var table5 = new Table(2, commonTableStyle, cfg.AutoTestParam);
foreach (var item in belowItems2)
{
string[] row = new string[] { item.Caption, item.Print(wm).Split(new char[] { '|' })[0] };
table2.AddRow(row, horizAlgn, vertAlgn);
table5.AddRow(new Cell[] { new Cell(item.Caption, font),
new Cell(item.Print(wm).Split(new char[] { '|' })[0], font) });
}
table2.Draw(e, leftMarginBelow2, belowTop);
table5.Draw(e, leftMarginBelow2, belowTop);
table2 = new Table(2, cfg.AutoTestParam) { Style = commonTableStyle };
var table6 = new Table(2, commonTableStyle, cfg.AutoTestParam);
foreach (var item in belowItems3)
{
string[] row = new string[] { item.Caption, item.Print(wm).Split(new char[] { '|' })[0] };
table2.AddRow(row, horizAlgn, vertAlgn);
table6.AddRow(new Cell[] { new Cell(item.Caption, font),
new Cell(item.Print(wm).Split(new char[] { '|' })[0], font) });
}
table2.Draw(e, leftMarginBelow3, belowTop);
table6.Draw(e, leftMarginBelow3, belowTop);
///
@@ -16,9 +16,6 @@ namespace Results.Output.Printers.OnePerMeter
{
public class OnePerMeterPrintDocument : Common.Printers.PrintersCommon
{
const float GapBetweenTableColumns = 10;
const float GapBetweenCommonColumns = 10;
static QrEncoder encoder = new QrEncoder();
/// Size of the printed area without margins, after taking into account 'pageOrientation'
@@ -33,39 +30,39 @@ namespace Results.Output.Printers.OnePerMeter
readonly int spacingOne;
readonly int spacingOne4Header;
float titleHeight;
/// <summary>
/// Property variable for the Font the user wishes to use
/// </summary>
Font titleFont;
Font headerFont;
Font font;
Font footerFont;
///
/// Data to print
///
Results.Entities.Batch batch;
OnePerMeterPrinterCfg cfg;
Results.Entities.WaterMeter wm;
readonly Font titleFont;
readonly Font headerFont;
readonly Font font;
readonly Font footerFont;
///
/// Items to print
///
string header;
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;
readonly string header;
readonly IList<WMeterRsltItemSpec> commonItems1;
readonly IList<WMeterRsltItemSpec> commonItems2;
readonly IList<WMeterRsltItemSpec> commonItems3;
readonly IList<WMeterRsltItemSpec> testItems;
readonly IList<WMeterRsltItemSpec> testItems2;
readonly IList<WMeterRsltItemSpec> belowItems1;
readonly IList<WMeterRsltItemSpec> belowItems2;
readonly IList<WMeterRsltItemSpec> belowItems3;
readonly string footer;
int nrPages;
///
/// Data to print
///
Results.Entities.Batch batch;
OnePerMeterPrinterCfg cfg;
Results.Entities.WaterMeter wm;
float titleHeight;
int nrPages;
int pageNr; /// Page number to be printed at the bottom of the page
/// <summary>
@@ -84,21 +81,21 @@ namespace Results.Output.Printers.OnePerMeter
leftMargin = cfg.LeftMargin;
header = string.IsNullOrEmpty(cfg.Header) ? string.Empty : cfg.Header.Replace("~", Environment.NewLine);
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);
commonItems1 = WMeterRsltItemSpec.FromStrArray(cfg.CommonItems1);
commonItems2 = WMeterRsltItemSpec.FromStrArray(cfg.CommonItems2);
commonItems3 = WMeterRsltItemSpec.FromStrArray(cfg.CommonItems3);
testItems = WMeterRsltItemSpec.FromStrArray(cfg.TestItems); /// TestID info will be overwritten later on
testItems2 = WMeterRsltItemSpec.FromStrArray(cfg.TestItems2); /// TestID info will be overwritten later on
belowItems1 = WMeterRsltItemSpec.FromStrArray(cfg.BelowItems1);
belowItems2 = WMeterRsltItemSpec.FromStrArray(cfg.BelowItems2);
belowItems3 = WMeterRsltItemSpec.FromStrArray(cfg.BelowItems3);
footer = string.IsNullOrEmpty(cfg.Footer) ? string.Empty : cfg.Footer.Replace("~", Environment.NewLine);
/// Initialize fonts
titleFont = new Font((cfg.TitFntFml != null ? cfg.TitFntFml : "Arial"), (cfg.TitFntSz > 0 ? cfg.TitFntSz : 10), (FontStyle)cfg.TitFntSty);
headerFont = new Font((cfg.HdrFntFml != null ? cfg.HdrFntFml : "Arial"), (cfg.HdrFntSz > 0 ? cfg.HdrFntSz : 10), (FontStyle)cfg.HdrFntSty);
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);
titleFont = new Font(cfg.TitFntFml ?? "Arial", cfg.TitFntSz > 0 ? cfg.TitFntSz : 10, (FontStyle)cfg.TitFntSty);
headerFont = new Font(cfg.HdrFntFml ?? "Arial", cfg.HdrFntSz > 0 ? cfg.HdrFntSz : 10, (FontStyle)cfg.HdrFntSty);
font = new Font(cfg.BodyFntFml ?? "Arial", cfg.BodyFntSz > 0 ? cfg.BodyFntSz : 10, (FontStyle)cfg.BodyFntSty);
footerFont = new Font(cfg.FooterFntFml ?? "Arial", cfg.FooterFntSz > 0 ? cfg.FooterFntSz : 10, (FontStyle)cfg.FooterFntSty);
/// Set print area size and margins (in dots using 100 dpi)
DefaultPageSettings.Landscape = (cfg.PageOrientation == PageOrientation.Landscape);
@@ -130,7 +127,7 @@ namespace Results.Output.Printers.OnePerMeter
/// </summary>
/// <param name=e></param>
/// <remarks></remarks>
protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e)
protected override void OnBeginPrint(PrintEventArgs e)
{
base.OnBeginPrint(e);
}
@@ -140,7 +137,7 @@ namespace Results.Output.Printers.OnePerMeter
/// </summary>
/// <param name=e></param>
/// <remarks>This provides the print logic for our document</remarks>
protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
protected override void OnPrintPage(PrintPageEventArgs e)
{
/// Run base code
base.OnPrintPage(e);
@@ -223,35 +220,33 @@ namespace Results.Output.Printers.OnePerMeter
float leftMarginCommon2 = leftMargin + printWidth * 0.01f * (cfg.ColW0Pct + cfg.ColW1Pct);
float leftMarginCommon3 = leftMargin + printWidth * 0.01f * (cfg.ColW0Pct + cfg.ColW1Pct + cfg.ColW2Pct);
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 table1 = new Table(2) { Style = commonTableStyle };
var table1 = new Table(2, commonTableStyle);
foreach (var item in commonItems1)
{
string[] row = new string[] { item.Caption, item.Print(wm).Split(new char[] { '|' })[0] };
table1.AddRow(row, horizAlgn, vertAlgn);
table1.AddRow(new Cell[] { new Cell(item.Caption, font),
new Cell(item.Print(wm).Split(new char[] { '|' })[0], font) });
}
float bodyTop1 = table1.Draw(e, leftMarginCommon1, commonTop);
table1 = new Table(2) { Style = commonTableStyle };
var table2 = new Table(2, commonTableStyle);
foreach (var item in commonItems2)
{
string[] row = new string[] { item.Caption, item.Print(wm).Split(new char[] { '|' })[0] };
table1.AddRow(row, horizAlgn, vertAlgn);
table2.AddRow(new Cell[] { new Cell(item.Caption, font),
new Cell(item.Print(wm).Split(new char[] { '|' })[0], font) });
}
float bodyTop2 = table1.Draw(e, leftMarginCommon2, commonTop);
float bodyTop2 = table2.Draw(e, leftMarginCommon2, commonTop);
table1 = new Table(2) { Style = commonTableStyle };
var table3 = new Table(2, commonTableStyle);
foreach (var item in commonItems3)
{
string[] row = new string[] { item.Caption, item.Print(wm).Split(new char[] { '|' })[0] };
table1.AddRow(row, horizAlgn, vertAlgn);
table3.AddRow(new Cell[] { new Cell(item.Caption, font),
new Cell(item.Print(wm).Split(new char[] { '|' })[0], font) });
}
float bodyTop3 = table1.Draw(e, leftMarginCommon3, commonTop);
float bodyTop3 = table3.Draw(e, leftMarginCommon3, commonTop);
float bodyTop12 = (bodyTop1 > bodyTop2) ? bodyTop1 : bodyTop2;
tableTop = (bodyTop12 > bodyTop3) ? bodyTop12 : bodyTop3; /// Max. of all three bodyTop-s
@@ -331,35 +326,33 @@ namespace Results.Output.Printers.OnePerMeter
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 table2 = new Table(2) { Style = commonTableStyle };
var table4 = new Table(2, commonTableStyle);
foreach (var item in belowItems1)
{
string[] row = new string[] { item.Caption, item.Print(wm).Split(new char[] { '|' })[0] };
table2.AddRow(row, horizAlgn, vertAlgn);
table4.AddRow(new Cell[] { new Cell(item.Caption, font),
new Cell(item.Print(wm).Split(new char[] { '|' })[0], font) });
}
table2.Draw(e, leftMarginBelow1, belowTop);
table4.Draw(e, leftMarginBelow1, belowTop);
table2 = new Table(2) { Style = commonTableStyle };
var table5 = new Table(2, commonTableStyle);
foreach (var item in belowItems2)
{
string[] row = new string[] { item.Caption, item.Print(wm).Split(new char[] { '|' })[0] };
table2.AddRow(row, horizAlgn, vertAlgn);
table5.AddRow(new Cell[] { new Cell(item.Caption, font),
new Cell(item.Print(wm).Split(new char[] { '|' })[0], font) });
}
table2.Draw(e, leftMarginBelow2, belowTop);
table5.Draw(e, leftMarginBelow2, belowTop);
table2 = new Table(2) { Style = commonTableStyle };
var table6 = new Table(2, commonTableStyle);
foreach (var item in belowItems3)
{
string[] row = new string[] { item.Caption, item.Print(wm).Split(new char[] { '|' })[0] };
table2.AddRow(row, horizAlgn, vertAlgn);
table6.AddRow(new Cell[] { new Cell(item.Caption, font),
new Cell(item.Print(wm).Split(new char[] { '|' })[0], font) });
}
table2.Draw(e, leftMarginBelow3, belowTop);
table6.Draw(e, leftMarginBelow3, belowTop);
///
@@ -35,7 +35,6 @@ namespace Results.Output.Printers.OnePerMeter
public string[] CommonItems3;
public Common.TableForm Form;
public string[] TestItems;
public Common.TableForm Form2;
public string[] TestItems2;
public int BelowW0Pct;
public int BelowW1Pct;
@@ -1,5 +1,5 @@
///
/// Copyright (c) 2017 Sensus Metering Systems
/// Copyright (c) 2021 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@@ -7,8 +7,6 @@ using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using Common;
using Config.Entities;
using Results;
using Results.Resources;
namespace Results.Output.Printers.Zapiska
@@ -60,15 +58,15 @@ namespace Results.Output.Printers.Zapiska
///
/// Items to print
///
string header;
IList<WMeterRsltItemSpec> commonItems1;
IList<WMeterRsltItemSpec> commonItems2;
IList<WMeterRsltItemSpec> commonItems3;
IList<WMeterRsltItemSpec> selectedItems;
IList<WMeterRsltItemSpec> belowItems1;
IList<WMeterRsltItemSpec> belowItems2;
IList<WMeterRsltItemSpec> belowItems3;
string footer;
readonly string header;
readonly IList<WMeterRsltItemSpec> commonItems1;
readonly IList<WMeterRsltItemSpec> commonItems2;
readonly IList<WMeterRsltItemSpec> commonItems3;
readonly IList<WMeterRsltItemSpec> selectedItems;
readonly IList<WMeterRsltItemSpec> belowItems1;
readonly IList<WMeterRsltItemSpec> belowItems2;
readonly IList<WMeterRsltItemSpec> belowItems3;
readonly string footer;
///
/// Layout and status
@@ -94,20 +92,20 @@ namespace Results.Output.Printers.Zapiska
leftMargin = cfg.LeftMargin;
header = string.IsNullOrEmpty(cfg.Header) ? string.Empty : cfg.Header.Replace("~", Environment.NewLine);
commonItems1 = Results.WMeterRsltItemSpec.FromStrArray(cfg.CommonItems1);
commonItems2 = Results.WMeterRsltItemSpec.FromStrArray(cfg.CommonItems2);
commonItems3 = Results.WMeterRsltItemSpec.FromStrArray(cfg.CommonItems3);
selectedItems = Results.WMeterRsltItemSpec.FromStrArray(cfg.SelectedItems);
belowItems1 = Results.WMeterRsltItemSpec.FromStrArray(cfg.BelowItems1);
belowItems2 = Results.WMeterRsltItemSpec.FromStrArray(cfg.BelowItems2);
belowItems3 = Results.WMeterRsltItemSpec.FromStrArray(cfg.BelowItems3);
commonItems1 = WMeterRsltItemSpec.FromStrArray(cfg.CommonItems1);
commonItems2 = WMeterRsltItemSpec.FromStrArray(cfg.CommonItems2);
commonItems3 = WMeterRsltItemSpec.FromStrArray(cfg.CommonItems3);
selectedItems = WMeterRsltItemSpec.FromStrArray(cfg.SelectedItems);
belowItems1 = WMeterRsltItemSpec.FromStrArray(cfg.BelowItems1);
belowItems2 = WMeterRsltItemSpec.FromStrArray(cfg.BelowItems2);
belowItems3 = WMeterRsltItemSpec.FromStrArray(cfg.BelowItems3);
footer = string.IsNullOrEmpty(cfg.Footer) ? string.Empty : cfg.Footer.Replace("~", Environment.NewLine);
/// Initialize fonts
titleFont = new Font((cfg.TitFntFml != null ? cfg.TitFntFml : "Arial"), (cfg.TitFntSz > 0 ? cfg.TitFntSz : 10), (FontStyle)cfg.TitFntSty);
headerFont = new Font((cfg.HdrFntFml != null ? cfg.HdrFntFml : "Arial"), (cfg.HdrFntSz > 0 ? cfg.HdrFntSz : 10), (FontStyle)cfg.HdrFntSty);
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);
titleFont = new Font(cfg.TitFntFml ?? "Arial", cfg.TitFntSz > 0 ? cfg.TitFntSz : 10, (FontStyle)cfg.TitFntSty);
headerFont = new Font(cfg.HdrFntFml ?? "Arial", cfg.HdrFntSz > 0 ? cfg.HdrFntSz : 10, (FontStyle)cfg.HdrFntSty);
font = new Font(cfg.BodyFntFml ?? "Arial", cfg.BodyFntSz > 0 ? cfg.BodyFntSz : 10, (FontStyle)cfg.BodyFntSty);
footerFont = new Font(cfg.FooterFntFml ?? "Arial", cfg.FooterFntSz > 0 ? cfg.FooterFntSz : 10, (FontStyle)cfg.FooterFntSty);
/// Set print area size and margins (in dots using 100 dpi)
DefaultPageSettings.Landscape = (cfg.PageOrientation == PageOrientation.Landscape);
@@ -142,7 +140,7 @@ namespace Results.Output.Printers.Zapiska
/// </summary>
/// <param name=e></param>
/// <remarks></remarks>
protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e)
protected override void OnBeginPrint(PrintEventArgs e)
{
base.OnBeginPrint(e);
}
@@ -152,7 +150,7 @@ namespace Results.Output.Printers.Zapiska
/// </summary>
/// <param name=e></param>
/// <remarks>This provides the print logic for our document</remarks>
protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
protected override void OnPrintPage(PrintPageEventArgs e)
{
/// Run base code
base.OnPrintPage(e);
@@ -344,8 +342,7 @@ namespace Results.Output.Printers.Zapiska
/// <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>
float PrintWMs(System.Drawing.Printing.PrintPageEventArgs e,
IList<Results.Entities.WaterMeter> wms, float top)
float PrintWMs(PrintPageEventArgs e, IList<Results.Entities.WaterMeter> wms, float top)
{
///
/// Prepare table content
@@ -384,7 +381,7 @@ namespace Results.Output.Printers.Zapiska
}
float DrawTable(System.Drawing.Printing.PrintPageEventArgs e, float left, float top, string[] header, IList<string[]> rows, Alignment[] alignment)
float DrawTable(PrintPageEventArgs e, float left, float top, string[] header, IList<string[]> rows, Alignment[] alignment)
{
int tblColumnsCount = header.Length;
@@ -462,7 +459,7 @@ namespace Results.Output.Printers.Zapiska
static Font lastFont = null;
static float lastSpacing = 0;
SizeF Measure(System.Drawing.Printing.PrintPageEventArgs e, string paragraph, Font font)
SizeF Measure(PrintPageEventArgs e, string paragraph, Font font)
{
if (font != lastFont)
{
@@ -482,7 +479,7 @@ namespace Results.Output.Printers.Zapiska
}
void PrintAt(System.Drawing.Printing.PrintPageEventArgs e, float x, float y, float width, string paragraph, Font font, Alignment alignment)
void PrintAt(PrintPageEventArgs e, float x, float y, float width, string paragraph, Font font, Alignment alignment)
{
SizeF size = Measure(e, paragraph, font);