Output.Printers.Enhanced component added.
This commit is contained in:
parent
17c685148e
commit
0f7ff301c4
342
Results/Output/Printers/Enhanced/EnhancedPrintDocument.cs
Normal file
342
Results/Output/Printers/Enhanced/EnhancedPrintDocument.cs
Normal file
@ -0,0 +1,342 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Printing;
|
||||
using System.IO;
|
||||
using Config.Entities;
|
||||
using Results.Resources;
|
||||
|
||||
namespace Results.Output.Printers.Enhanced
|
||||
{
|
||||
public class EnhancedPrintDocument : PrintDocument
|
||||
{
|
||||
const string FontFamilyName = "Arial"; //"Times New Roman";
|
||||
|
||||
const int SpacingOne = 18;
|
||||
const int SpacingOneAndHalf = (3 * SpacingOne) / 2;
|
||||
|
||||
readonly int topMargin;
|
||||
readonly int bottomMargin;
|
||||
readonly int leftMargin;
|
||||
readonly int TitleX;
|
||||
readonly int TitleY; /// Depends on the size of the header
|
||||
readonly int HdrTop; /// = TitleY + 60
|
||||
readonly int BodyTop; /// = HdrTop + 160
|
||||
|
||||
/// Size of the printed area without margins, after taking into account 'pageOrientation'
|
||||
int printHeight;
|
||||
int printWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Property variable for the Font the user wishes to use
|
||||
/// </summary>
|
||||
Font font;
|
||||
Font boldFont;
|
||||
Font titleFont;
|
||||
|
||||
///
|
||||
/// Data to print
|
||||
///
|
||||
Results.Entities.Batch batch;
|
||||
|
||||
///
|
||||
/// Items to print
|
||||
///
|
||||
string header;
|
||||
IList<WMeterRsltItemSpec> commonItems;
|
||||
IList<WMeterRsltItemSpec> testItems;
|
||||
string footer;
|
||||
|
||||
///
|
||||
/// Layout and status
|
||||
///
|
||||
int nrWMsOnFirstPage;
|
||||
int nrWMsOnNextPage;
|
||||
int nextWMNr; /// nr. of watermeter to be printed as the first one on the next page
|
||||
int nrPages;
|
||||
int pageNr; /// Page number to be printed at the bottom of the page
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="textToPrint">Text to be printed</param>
|
||||
public EnhancedPrintDocument(Results.Entities.Batch batch,
|
||||
PageOrientation pageOrientation,
|
||||
int topMargin,
|
||||
int bottomMargin,
|
||||
int leftMargin,
|
||||
string header,
|
||||
IList<WMeterRsltItemSpec> commonItems,
|
||||
IList<WMeterRsltItemSpec> testItems,
|
||||
string footer)
|
||||
{
|
||||
this.batch = batch;
|
||||
|
||||
this.topMargin = topMargin;
|
||||
this.bottomMargin = bottomMargin;
|
||||
this.leftMargin = leftMargin;
|
||||
|
||||
this.header = header;
|
||||
this.commonItems = commonItems;
|
||||
this.testItems = testItems;
|
||||
this.footer = footer;
|
||||
|
||||
TitleX = leftMargin;
|
||||
TitleY = topMargin; /// Depends on the size of the header
|
||||
HdrTop = TitleY + 60;
|
||||
BodyTop = HdrTop + 160;
|
||||
|
||||
DefaultPageSettings.Landscape = (pageOrientation == PageOrientation.Landscape);
|
||||
|
||||
/// Set print area size and margins (in dots using 100 dpi)
|
||||
if (DefaultPageSettings.Landscape)
|
||||
{
|
||||
printHeight = base.DefaultPageSettings.PaperSize.Width - topMargin - bottomMargin;
|
||||
printWidth = base.DefaultPageSettings.PaperSize.Height - leftMargin - leftMargin;
|
||||
}
|
||||
else
|
||||
{
|
||||
printHeight = base.DefaultPageSettings.PaperSize.Height - topMargin - bottomMargin;
|
||||
printWidth = base.DefaultPageSettings.PaperSize.Width - leftMargin - leftMargin;
|
||||
}
|
||||
|
||||
int testsCount = 0;
|
||||
if (batch.WaterMeters.Count > 0)
|
||||
{
|
||||
foreach (var mtr in batch.WaterMeters[0].MeterTestRslts)
|
||||
{
|
||||
if (mtr.Publish() == Config.Entities.Publish.Always) testsCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (batch.WaterMeters.Count > 0 && batch.WaterMeters[0].Compound()) testsCount /= 3;
|
||||
|
||||
int wmSectionHeight = (testsCount + 4) * SpacingOne;
|
||||
|
||||
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;
|
||||
|
||||
pageNr = 1;
|
||||
nextWMNr = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override the default onbeginPrint method of the PrintDocument Object
|
||||
/// </summary>
|
||||
/// <param name=e></param>
|
||||
/// <remarks></remarks>
|
||||
protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e)
|
||||
{
|
||||
base.OnBeginPrint(e);
|
||||
|
||||
if (font == null) { font = new Font(FontFamilyName, 10, FontStyle.Regular); }
|
||||
if (boldFont == null) { boldFont = new Font(FontFamilyName, 10, FontStyle.Bold); }
|
||||
if (titleFont == null) { titleFont = new Font(FontFamilyName, 18, FontStyle.Bold); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override the default OnPrintPage method of the PrintDocument.
|
||||
/// </summary>
|
||||
/// <param name=e></param>
|
||||
/// <remarks>This provides the print logic for our document</remarks>
|
||||
protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
|
||||
{
|
||||
/// Run base code
|
||||
base.OnPrintPage(e);
|
||||
|
||||
if (File.Exists("C:\\TBF\\header.png"))
|
||||
{
|
||||
Image img = Image.FromFile("C:\\TBF\\header.png");
|
||||
e.Graphics.DrawImage(new Bitmap(img), new Rectangle(0, 0, 827, 1169));
|
||||
}
|
||||
|
||||
/// Use the StringFormat class for the text layout of our document
|
||||
StringFormat format = new StringFormat(StringFormatFlags.LineLimit);
|
||||
|
||||
if (pageNr == 1)
|
||||
{
|
||||
///----------
|
||||
/// Header
|
||||
///----------
|
||||
RectangleF printArea = new RectangleF(TitleX, TitleY, printWidth, 40);
|
||||
e.Graphics.DrawString(header, titleFont, Brushes.Black, printArea);
|
||||
|
||||
///----------------
|
||||
/// Common items
|
||||
///----------------
|
||||
string[] leftColumn = new string[commonItems.Count];
|
||||
string[] rightColumn = new string[commonItems.Count];
|
||||
|
||||
int cnt = 0;
|
||||
foreach (var v in commonItems)
|
||||
{
|
||||
leftColumn[cnt] = v.Caption;
|
||||
rightColumn[cnt] = (batch.WaterMeters.Count > 0) ? v.Print(batch.WaterMeters[0]) : string.Empty;
|
||||
cnt++;
|
||||
}
|
||||
|
||||
/// Determine max. left column width in characters
|
||||
int maxLen = 0;
|
||||
foreach (var s in leftColumn) if (s.Length > maxLen) maxLen = s.Length;
|
||||
|
||||
/// Write aligned columns
|
||||
for (int i = 0; i < Math.Min(leftColumn.Length, rightColumn.Length); i++)
|
||||
{
|
||||
PrintAt(e, leftMargin, HdrTop + SpacingOne * i, leftColumn[i]);
|
||||
PrintAt(e, 300, HdrTop + SpacingOne * i, rightColumn[i]);
|
||||
}
|
||||
}
|
||||
|
||||
///--------
|
||||
/// Body
|
||||
///--------
|
||||
|
||||
/// This variable represents the top coordinate of the area where WM results are printed
|
||||
/// and it is updated (increased by) the value returned by PrintXyzWM() - the section size.
|
||||
int nextWmTop = (pageNr == 1) ? BodyTop : TitleY;
|
||||
|
||||
int nrWMsOnPage = (pageNr == 1) ? nrWMsOnFirstPage : nrWMsOnNextPage;
|
||||
|
||||
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);
|
||||
nextWmTop += PrintWM(e, batch.WaterMeters[wmNr], wmPosition, nextWmTop);
|
||||
}
|
||||
|
||||
nextWMNr += nrWMsOnPage;
|
||||
e.HasMorePages = (nextWMNr < batch.WaterMeters.Count);
|
||||
|
||||
///----------
|
||||
/// Footer
|
||||
///----------
|
||||
int footerWidth = (int)e.Graphics.MeasureString(footer, font).Width;
|
||||
PrintAt(e, leftMargin + (printWidth - footerWidth) / 2, topMargin + printHeight - 2 * SpacingOne, footer);
|
||||
|
||||
string pageNrText = string.Format("{0} {1}/{2}", Strings.Page, pageNr++, nrPages);
|
||||
int pageNrWidth = (int)e.Graphics.MeasureString(pageNrText, font).Width;
|
||||
PrintAt(e, leftMargin + (printWidth - pageNrWidth) / 2, topMargin + printHeight - SpacingOne, pageNrText);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Print one water meter results
|
||||
/// </summary>
|
||||
/// <param name="wm">Water meter</param>
|
||||
/// <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,
|
||||
Results.Entities.WaterMeter wm, int printedWMNr, int top)
|
||||
{
|
||||
/// Determin column widths
|
||||
float[] columnPos = new float[testItems.Count + 1];
|
||||
columnPos[0] = (float)leftMargin;
|
||||
|
||||
for (int i = 0; i < testItems.Count; i++)
|
||||
{
|
||||
float columnWidth = e.Graphics.MeasureString(testItems[i].Caption, font).Width;
|
||||
foreach (var mtr in wm.MeterTestRslts)
|
||||
{
|
||||
if ((mtr != null) && (mtr.Publish() == Config.Entities.Publish.Always))
|
||||
{
|
||||
string itemText = testItems[i].Print(wm, mtr.Name());
|
||||
|
||||
/// 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);
|
||||
PrintAt(e, leftMargin, top, wmText);
|
||||
if (!string.IsNullOrEmpty(wm.SerialNr))
|
||||
{
|
||||
PrintAt(e, leftMargin + (int)e.Graphics.MeasureString(wmText, font).Width, top,
|
||||
string.Format(" {0} = {1}", Strings.sn, wm.SerialNr));
|
||||
}
|
||||
|
||||
/// Horizontal line
|
||||
int horY = top + 25;
|
||||
e.Graphics.DrawLine(new Pen(Color.Black, 2), new Point(tableLeftX, horY), new Point(tableRightX, horY));
|
||||
|
||||
for (int i = 0; i < testItems.Count; i++)
|
||||
{
|
||||
PrintAt(e, (int)columnPos[i], top + 27, testItems[i].Caption);
|
||||
}
|
||||
|
||||
/// Horizontal line
|
||||
horY = top + 27 + SpacingOne;
|
||||
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))
|
||||
{
|
||||
testsCount++;
|
||||
for (int i = 0; i < testItems.Count; i++)
|
||||
{
|
||||
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 + 30 + SpacingOne * testsCount, itemText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Horizontal line
|
||||
horY = top + 30 + SpacingOne * (testsCount + 1);
|
||||
e.Graphics.DrawLine(new Pen(Color.Black, 2), new Point(tableLeftX, horY), new Point(tableRightX, horY));
|
||||
|
||||
return (testsCount + 4) * SpacingOne;
|
||||
}
|
||||
|
||||
|
||||
void PrintAt(System.Drawing.Printing.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)
|
||||
{
|
||||
RectangleF printArea = new RectangleF(x, y, 667, SpacingOne);
|
||||
e.Graphics.DrawString(text, this.font, Brushes.Black, printArea);
|
||||
}
|
||||
|
||||
|
||||
void PrintBoldAt(System.Drawing.Printing.PrintPageEventArgs e, Point p, string text)
|
||||
{
|
||||
PrintBoldAt(e, p.X, p.Y, text);
|
||||
}
|
||||
|
||||
|
||||
void PrintBoldAt(System.Drawing.Printing.PrintPageEventArgs e, int x, int y, string text)
|
||||
{
|
||||
RectangleF printArea = new RectangleF(x, y, 667, SpacingOne);
|
||||
e.Graphics.DrawString(text, this.boldFont, Brushes.Black, printArea);
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Results/Resources/Strings.Designer.cs
generated
9
Results/Resources/Strings.Designer.cs
generated
@ -969,6 +969,15 @@ namespace Results.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Water Meter.
|
||||
/// </summary>
|
||||
internal static string Water_Meter {
|
||||
get {
|
||||
return ResourceManager.GetString("Water_Meter", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Width.
|
||||
/// </summary>
|
||||
|
||||
@ -195,4 +195,10 @@
|
||||
<data name="Quantity" xml:space="preserve">
|
||||
<value>Veličina</value>
|
||||
</data>
|
||||
<data name="sn" xml:space="preserve">
|
||||
<value>sériové číslo</value>
|
||||
</data>
|
||||
<data name="Water_Meter" xml:space="preserve">
|
||||
<value>Vodoměr</value>
|
||||
</data>
|
||||
</root>
|
||||
@ -381,4 +381,10 @@
|
||||
<data name="Quantity" xml:space="preserve">
|
||||
<value>Größe</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Blz.</value>
|
||||
</data>
|
||||
<data name="Water_Meter" xml:space="preserve">
|
||||
<value>Wasserzähler</value>
|
||||
</data>
|
||||
</root>
|
||||
@ -432,4 +432,7 @@
|
||||
<data name="Quantity" xml:space="preserve">
|
||||
<value>Quantity</value>
|
||||
</data>
|
||||
<data name="Water_Meter" xml:space="preserve">
|
||||
<value>Water Meter</value>
|
||||
</data>
|
||||
</root>
|
||||
@ -94,6 +94,9 @@
|
||||
<Compile Include="Output\Printers\Cevak\PrintDocumentCevak.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Output\Printers\Enhanced\EnhancedPrintDocument.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Output\Printers\Munich\MunichPrintDocument.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
|
||||
14
TestBenchFramework/BenchControl/Output/Enums.cs
Normal file
14
TestBenchFramework/BenchControl/Output/Enums.cs
Normal file
@ -0,0 +1,14 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
namespace TBF.BenchControl.Output
|
||||
{
|
||||
public enum Culture
|
||||
{
|
||||
system,
|
||||
EN,
|
||||
DE,
|
||||
SK,
|
||||
Count
|
||||
}
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
using System.Windows.Forms;
|
||||
using TBF.Resources;
|
||||
|
||||
namespace TBF.BenchControl.Output.FileWriters.Enhanced
|
||||
{
|
||||
public partial class HeaderFooterDlg : Form
|
||||
{
|
||||
public string EditedText
|
||||
{
|
||||
set { textBox.Text = value; }
|
||||
get { return textBox.Text; }
|
||||
}
|
||||
|
||||
public HeaderFooterDlg()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public HeaderFooterDlg(bool isHeader, string text)
|
||||
: this()
|
||||
{
|
||||
Text = isHeader ? Strings.Header : Strings.Footer;
|
||||
textBox.Text = text;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -7,8 +7,6 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using log4net;
|
||||
using Config.Entities;
|
||||
using TBF.BenchControl;
|
||||
using TBF.Resources;
|
||||
|
||||
namespace TBF.BenchControl.Output.FileWriters.Enhanced
|
||||
@ -31,11 +29,11 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
|
||||
string footer;
|
||||
|
||||
|
||||
Thread thread1; /// Thread where one file is saved
|
||||
Thread thread2; /// Thread where another file is saved
|
||||
bool completed1; /// Set to 'true' by the first thread when writing to the file completed
|
||||
bool completed2; /// Set to 'true' by the second thread when writing to the file completed
|
||||
bool abort; /// Set to 'true' by Stop() operation to abort writing to the file
|
||||
Thread thread1; /// Thread where one file is saved
|
||||
Thread thread2; /// Thread where another file is saved
|
||||
bool completed1; /// Set to 'true' by the first thread when writing to the file completed
|
||||
bool completed2; /// Set to 'true' by the second thread when writing to the file completed
|
||||
bool abort; /// Set to 'true' by Stop() operation to abort writing to the file
|
||||
|
||||
|
||||
public Writer() {}
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
///
|
||||
/// Copyright (c) 2016-2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml.Serialization;
|
||||
using TBF.BenchControl.Generic;
|
||||
|
||||
|
||||
@ -16,8 +16,6 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
|
||||
|
||||
public bool ShowMore { get { return false; } }
|
||||
|
||||
public bool Compound;
|
||||
|
||||
WriterCfg config;
|
||||
public IComponentCfg Config
|
||||
{
|
||||
|
||||
@ -37,13 +37,4 @@ namespace TBF.BenchControl.Output.FileWriters
|
||||
Semicolon,
|
||||
Count
|
||||
}
|
||||
|
||||
public enum Culture
|
||||
{
|
||||
system,
|
||||
EN,
|
||||
DE,
|
||||
SK,
|
||||
Count
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,85 +0,0 @@
|
||||
namespace TBF.BenchControl.Output.FileWriters.Xml
|
||||
{
|
||||
partial class HeaderFooterDlg
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.okButton = new System.Windows.Forms.Button();
|
||||
this.cancelButton = new System.Windows.Forms.Button();
|
||||
this.textBox = new System.Windows.Forms.TextBox();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// okButton
|
||||
//
|
||||
this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
|
||||
this.okButton.Location = new System.Drawing.Point(393, 169);
|
||||
this.okButton.Name = "okButton";
|
||||
this.okButton.Size = new System.Drawing.Size(75, 34);
|
||||
this.okButton.TabIndex = 1;
|
||||
this.okButton.Text = "OK";
|
||||
this.okButton.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// cancelButton
|
||||
//
|
||||
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||
this.cancelButton.Location = new System.Drawing.Point(484, 169);
|
||||
this.cancelButton.Name = "cancelButton";
|
||||
this.cancelButton.Size = new System.Drawing.Size(75, 34);
|
||||
this.cancelButton.TabIndex = 2;
|
||||
this.cancelButton.Text = "Cancel";
|
||||
this.cancelButton.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// textBox
|
||||
//
|
||||
this.textBox.Location = new System.Drawing.Point(12, 12);
|
||||
this.textBox.Multiline = true;
|
||||
this.textBox.Name = "textBox";
|
||||
this.textBox.Size = new System.Drawing.Size(547, 142);
|
||||
this.textBox.TabIndex = 0;
|
||||
//
|
||||
// HeaderFooterDlg
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(571, 216);
|
||||
this.Controls.Add(this.textBox);
|
||||
this.Controls.Add(this.cancelButton);
|
||||
this.Controls.Add(this.okButton);
|
||||
this.Name = "HeaderFooterDlg";
|
||||
this.Text = "Enter text";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Button okButton;
|
||||
private System.Windows.Forms.Button cancelButton;
|
||||
private System.Windows.Forms.TextBox textBox;
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
namespace TBF.BenchControl.Output.FileWriters.Enhanced
|
||||
namespace TBF.BenchControl.Output
|
||||
{
|
||||
partial class HeaderFooterDlg
|
||||
{
|
||||
@ -4,7 +4,7 @@
|
||||
using System.Windows.Forms;
|
||||
using TBF.Resources;
|
||||
|
||||
namespace TBF.BenchControl.Output.FileWriters.Xml
|
||||
namespace TBF.BenchControl.Output
|
||||
{
|
||||
public partial class HeaderFooterDlg : Form
|
||||
{
|
||||
@ -0,0 +1,372 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Printing;
|
||||
using System.IO;
|
||||
using Config.Entities;
|
||||
using TBF.Resources;
|
||||
|
||||
namespace TBF.BenchControl.Output.Printers.Enhanced
|
||||
{
|
||||
public class BasicPrintDocument : PrintDocument
|
||||
{
|
||||
const string FontFamilyName = "Arial"; //"Times New Roman";
|
||||
|
||||
const int SpacingOne = 18;
|
||||
const int SpacingOneAndHalf = (3 * SpacingOne) / 2;
|
||||
|
||||
readonly int topMargin;
|
||||
readonly int bottomMargin;
|
||||
readonly int leftMargin;
|
||||
readonly int TitleX;
|
||||
readonly int TitleY; /// Depends on the size of the header
|
||||
readonly int HdrTop; /// = TitleY + 60
|
||||
readonly int BodyTop; /// = HdrTop + 160
|
||||
|
||||
/// Size of the printed area without margins, after taking into account 'pageOrientation'
|
||||
int printHeight;
|
||||
int printWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Property variable for the Font the user wishes to use
|
||||
/// </summary>
|
||||
Font font;
|
||||
Font boldFont;
|
||||
Font titleFont;
|
||||
|
||||
///
|
||||
/// Data to print
|
||||
///
|
||||
Results.Entities.Batch batch;
|
||||
|
||||
///
|
||||
/// Items to print
|
||||
///
|
||||
readonly IList<Results.ItemSpec> rsltItems;
|
||||
|
||||
///
|
||||
/// Layout and status
|
||||
///
|
||||
int nrWMsOnFirstPage;
|
||||
int nrWMsOnNextPage;
|
||||
int nextWMNr; /// nr. of watermeter to be printed as the first one on the next page
|
||||
int nrPages;
|
||||
int pageNr; /// Page number to be printed at the bottom of the page
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="textToPrint">Text to be printed</param>
|
||||
public BasicPrintDocument(Results.Entities.Batch batch,
|
||||
PageOrientation pageOrientation,
|
||||
int topMargin, int bottomMargin, int leftMargin)
|
||||
{
|
||||
this.batch = batch;
|
||||
|
||||
DefaultPageSettings.Landscape = (pageOrientation == PageOrientation.Landscape);
|
||||
|
||||
this.topMargin = topMargin;
|
||||
this.bottomMargin = bottomMargin;
|
||||
this.leftMargin = leftMargin;
|
||||
|
||||
TitleX = leftMargin;
|
||||
TitleY = topMargin; /// Depends on the size of the header
|
||||
HdrTop = TitleY + 60;
|
||||
BodyTop = HdrTop + 160;
|
||||
|
||||
if (batch.WaterMeters.Count > 0 && batch.WaterMeters[0].Compound())
|
||||
{
|
||||
rsltItems = Results.ItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Printer_CombinedWM);
|
||||
}
|
||||
else
|
||||
{
|
||||
rsltItems = Results.ItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Printer_SingleWM);
|
||||
}
|
||||
|
||||
/// Set print area size and margins (in dots using 100 dpi)
|
||||
if (DefaultPageSettings.Landscape)
|
||||
{
|
||||
printHeight = base.DefaultPageSettings.PaperSize.Width - topMargin - bottomMargin;
|
||||
printWidth = base.DefaultPageSettings.PaperSize.Height - leftMargin - leftMargin;
|
||||
}
|
||||
else
|
||||
{
|
||||
printHeight = base.DefaultPageSettings.PaperSize.Height - topMargin - bottomMargin;
|
||||
printWidth = base.DefaultPageSettings.PaperSize.Width - leftMargin - leftMargin;
|
||||
}
|
||||
|
||||
int testsCount = 0;
|
||||
if (batch.WaterMeters.Count > 0)
|
||||
{
|
||||
foreach (var mtr in batch.WaterMeters[0].MeterTestRslts)
|
||||
{
|
||||
if (mtr.Publish() == Config.Entities.Publish.Always) testsCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (batch.WaterMeters.Count > 0 && batch.WaterMeters[0].Compound()) testsCount /= 3;
|
||||
|
||||
int wmSectionHeight = (testsCount + 4) * SpacingOne;
|
||||
|
||||
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;
|
||||
|
||||
pageNr = 1;
|
||||
nextWMNr = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override the default onbeginPrint method of the PrintDocument Object
|
||||
/// </summary>
|
||||
/// <param name=e></param>
|
||||
/// <remarks></remarks>
|
||||
protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e)
|
||||
{
|
||||
base.OnBeginPrint(e);
|
||||
|
||||
if (font == null) { font = new Font(FontFamilyName, 10, FontStyle.Regular); }
|
||||
if (boldFont == null) { boldFont = new Font(FontFamilyName, 10, FontStyle.Bold); }
|
||||
if (titleFont == null) { titleFont = new Font(FontFamilyName, 18, FontStyle.Bold); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override the default OnPrintPage method of the PrintDocument.
|
||||
/// </summary>
|
||||
/// <param name=e></param>
|
||||
/// <remarks>This provides the print logic for our document</remarks>
|
||||
protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
|
||||
{
|
||||
/// Run base code
|
||||
base.OnPrintPage(e);
|
||||
|
||||
if (File.Exists("C:\\TBF\\header.png"))
|
||||
{
|
||||
Image img = Image.FromFile("C:\\TBF\\header.png");
|
||||
e.Graphics.DrawImage(new Bitmap(img), new Rectangle(0, 0, 827, 1169));
|
||||
}
|
||||
|
||||
/// Use the StringFormat class for the text layout of our document
|
||||
StringFormat format = new StringFormat(StringFormatFlags.LineLimit);
|
||||
|
||||
if (pageNr == 1)
|
||||
{
|
||||
///----------
|
||||
/// Header
|
||||
///----------
|
||||
RectangleF printArea = new RectangleF(TitleX, TitleY, printWidth, 40);
|
||||
e.Graphics.DrawString(batch.ProtocolTitle, titleFont, Brushes.Black, printArea);
|
||||
|
||||
string[] leftColumn = new string[]
|
||||
{
|
||||
"Batch number: ",
|
||||
"Date and time: ",
|
||||
"Procedure: ",
|
||||
Strings.User + ": ",
|
||||
"Ambient temperature: ",
|
||||
"Ambient pressure: ",
|
||||
"Ambient humidity: ",
|
||||
};
|
||||
|
||||
string[] rightColumn = new string[]
|
||||
{
|
||||
batch.BatchNr.ToString(),
|
||||
//batch.EndTime.ToShortDateString() + " " + batch.EndTime.ToShortTimeString(),
|
||||
string.Format("{0:yyyy.MM.dd HH:mm}", batch.EndTime),
|
||||
batch.ProcedureName,
|
||||
Users.GlobalData.CurrentUser.UserName,
|
||||
batch.AmbientTempAve().ToString("F1") + " °C",
|
||||
Config.Units.ConvertTo(Config.Unit.mbar, batch.AmbientPressAve()).ToString("F0") + " mbar",
|
||||
batch.AmbientHumiAve().ToString("F0") + " %",
|
||||
};
|
||||
|
||||
/// Determine max. left column width in characters
|
||||
int maxLen = 0;
|
||||
foreach (var s in leftColumn) if (s.Length > maxLen) maxLen = s.Length;
|
||||
|
||||
/// Write aligned columns
|
||||
for (int i = 0; i < Math.Min(leftColumn.Length, rightColumn.Length); i++)
|
||||
{
|
||||
PrintAt(e, leftMargin, HdrTop + SpacingOne * i, leftColumn[i]);
|
||||
PrintAt(e, 300, HdrTop + SpacingOne * i, rightColumn[i]);
|
||||
}
|
||||
}
|
||||
|
||||
///--------
|
||||
/// Body
|
||||
///--------
|
||||
|
||||
/// This variable represents the top coordinate of the area where WM results are printed
|
||||
/// and it is updated (increased by) the value returned by PrintXyzWM() - the section size.
|
||||
int nextWmTop = (pageNr == 1) ? BodyTop : TitleY;
|
||||
|
||||
int nrWMsOnPage = (pageNr == 1) ? nrWMsOnFirstPage : nrWMsOnNextPage;
|
||||
|
||||
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);
|
||||
nextWmTop += PrintWM(e, batch.WaterMeters[wmNr], wmPosition, nextWmTop);
|
||||
}
|
||||
|
||||
nextWMNr += nrWMsOnPage;
|
||||
e.HasMorePages = (nextWMNr < batch.WaterMeters.Count);
|
||||
|
||||
///----------
|
||||
/// Footer
|
||||
///----------
|
||||
string footerText = string.Format("str. {1}/{2}", Strings.Page, pageNr++, nrPages);
|
||||
int footerWidth = (int)e.Graphics.MeasureString(footerText, font).Width;
|
||||
PrintAt(e, leftMargin + (printWidth - footerWidth) / 2, topMargin + printHeight - SpacingOne, footerText);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Print one water meter results
|
||||
/// </summary>
|
||||
/// <param name="wm">Water meter</param>
|
||||
/// <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,
|
||||
Results.Entities.WaterMeter wm, int printedWMNr, int top)
|
||||
{
|
||||
/// Determin column widths
|
||||
float[] columnPos = new float[rsltItems.Count + 1];
|
||||
columnPos[0] = (float)leftMargin;
|
||||
|
||||
for (int i = 0; i < rsltItems.Count; i++)
|
||||
{
|
||||
float columnWidth = e.Graphics.MeasureString(rsltItems[i].ClmnHeaderText, font).Width;
|
||||
foreach (var mtr in wm.MeterTestRslts)
|
||||
{
|
||||
string itemText;
|
||||
|
||||
if (!wm.Compound())
|
||||
{
|
||||
itemText = rsltItems[i].Print(mtr);
|
||||
}
|
||||
else if (mtr.CompoundMeterId == (byte)CompoundMeterId.Compound)
|
||||
{
|
||||
Results.Entities.MeterTestRslt mainMtr = wm.GetMeterTestRslt(mtr.Name(), CompoundMeterId.CompoundMain);
|
||||
Results.Entities.MeterTestRslt auxMtr = wm.GetMeterTestRslt(mtr.Name(), CompoundMeterId.CompoundAux);
|
||||
itemText = rsltItems[i].PrintCombined(mainMtr, auxMtr, mtr);
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/// 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[rsltItems.Count] - 20;
|
||||
|
||||
string wmText = string.Format("Water meter {0}", printedWMNr);
|
||||
PrintAt(e, leftMargin, top, wmText);
|
||||
if (!string.IsNullOrEmpty(wm.SerialNr))
|
||||
{
|
||||
PrintAt(e, leftMargin + (int)e.Graphics.MeasureString(wmText, font).Width, top,
|
||||
string.Format(" s/n = {0}", wm.SerialNr));
|
||||
}
|
||||
|
||||
/// Horizontal line
|
||||
int horY = top + 25;
|
||||
e.Graphics.DrawLine(new Pen(Color.Black, 2), new Point(tableLeftX, horY), new Point(tableRightX, horY));
|
||||
|
||||
for (int i = 0; i < rsltItems.Count; i++)
|
||||
{
|
||||
PrintAt(e, (int)columnPos[i], top + 27, rsltItems[i].ClmnHeaderText);
|
||||
}
|
||||
|
||||
/// Horizontal line
|
||||
horY = top + 27 + SpacingOne;
|
||||
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.Publish() == Config.Entities.Publish.Always)
|
||||
{
|
||||
testsCount++;
|
||||
for (int i = 0; i < rsltItems.Count; i++)
|
||||
{
|
||||
string itemText;
|
||||
|
||||
if (!wm.Compound())
|
||||
{
|
||||
/// Single water meter
|
||||
itemText = rsltItems[i].Print(mtr);
|
||||
}
|
||||
else if (mtr.CompoundMeterId == (byte)CompoundMeterId.Compound)
|
||||
{
|
||||
Results.Entities.MeterTestRslt mainMtr = wm.GetMeterTestRslt(mtr.Name(), CompoundMeterId.CompoundMain);
|
||||
Results.Entities.MeterTestRslt auxMtr = wm.GetMeterTestRslt(mtr.Name(), CompoundMeterId.CompoundMain);
|
||||
itemText = rsltItems[i].PrintCombined(mainMtr, auxMtr, mtr);
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/// 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 + 30 + SpacingOne * testsCount, itemText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Horizontal line
|
||||
horY = top + 30 + SpacingOne * (testsCount + 1);
|
||||
e.Graphics.DrawLine(new Pen(Color.Black, 2), new Point(tableLeftX, horY), new Point(tableRightX, horY));
|
||||
|
||||
return (testsCount + 4) * SpacingOne;
|
||||
}
|
||||
|
||||
|
||||
void PrintAt(System.Drawing.Printing.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)
|
||||
{
|
||||
RectangleF printArea = new RectangleF(x, y, 667, SpacingOne);
|
||||
e.Graphics.DrawString(text, this.font, Brushes.Black, printArea);
|
||||
}
|
||||
|
||||
|
||||
void PrintBoldAt(System.Drawing.Printing.PrintPageEventArgs e, Point p, string text)
|
||||
{
|
||||
PrintBoldAt(e, p.X, p.Y, text);
|
||||
}
|
||||
|
||||
|
||||
void PrintBoldAt(System.Drawing.Printing.PrintPageEventArgs e, int x, int y, string text)
|
||||
{
|
||||
RectangleF printArea = new RectangleF(x, y, 667, SpacingOne);
|
||||
e.Graphics.DrawString(text, this.boldFont, Brushes.Black, printArea);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System.Collections.Generic;
|
||||
using TBF.BenchControl.Generic;
|
||||
|
||||
namespace TBF.BenchControl.Output.Printers.Enhanced
|
||||
{
|
||||
public class FactoryCompound : IComponentFactory
|
||||
{
|
||||
public string ClassName { get { return this.GetType().Namespace.Substring(17) + ".Compound"; } }
|
||||
|
||||
public void ResetStaticProperties() { Printer.ResetStaticProperties(); }
|
||||
|
||||
public IComponent DummyComponent() { return new Printer(); }
|
||||
|
||||
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new Printer(cfg); }
|
||||
|
||||
public IComponentCfg DefaultConfig() { return new PrinterCfg("Printer.Enhanced.Compound", this, Config.Entities.MetersKind.Combined); }
|
||||
|
||||
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
|
||||
{
|
||||
return ComponentCfgBase.CreateFromDbEntity(typeof(PrinterCfg), component, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System.Collections.Generic;
|
||||
using TBF.BenchControl.Generic;
|
||||
|
||||
namespace TBF.BenchControl.Output.Printers.Enhanced
|
||||
{
|
||||
public class FactoryHeatMeters : IComponentFactory
|
||||
{
|
||||
public string ClassName { get { return this.GetType().Namespace.Substring(17) + ".HeatMeters"; } }
|
||||
|
||||
public void ResetStaticProperties() { Printer.ResetStaticProperties(); }
|
||||
|
||||
public IComponent DummyComponent() { return new Printer(); }
|
||||
|
||||
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new Printer(cfg); }
|
||||
|
||||
public IComponentCfg DefaultConfig() { return new PrinterCfg("Printer.Enhanced.HeatMeters", this, Config.Entities.MetersKind.HeatMeter); }
|
||||
|
||||
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
|
||||
{
|
||||
return ComponentCfgBase.CreateFromDbEntity(typeof(PrinterCfg), component, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System.Collections.Generic;
|
||||
using TBF.BenchControl.Generic;
|
||||
|
||||
namespace TBF.BenchControl.Output.Printers.Enhanced
|
||||
{
|
||||
public class FactorySingle : IComponentFactory
|
||||
{
|
||||
public string ClassName { get { return this.GetType().Namespace.Substring(17) + ".Single"; } }
|
||||
|
||||
public void ResetStaticProperties() { Printer.ResetStaticProperties(); }
|
||||
|
||||
public IComponent DummyComponent() { return new Printer(); }
|
||||
|
||||
public IComponent GetComponent(IComponentCfg cfg, IList<IComponent> components) { return new Printer(cfg); }
|
||||
|
||||
public IComponentCfg DefaultConfig() { return new PrinterCfg("Printer.Enhanced.Single", this, Config.Entities.MetersKind.Single); }
|
||||
|
||||
public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component)
|
||||
{
|
||||
return ComponentCfgBase.CreateFromDbEntity(typeof(PrinterCfg), component, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,158 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using log4net;
|
||||
|
||||
namespace TBF.BenchControl.Output.Printers.Enhanced
|
||||
{
|
||||
public class Printer : ComponentBase, IOperation, GenericDevices.IResultsPrinter
|
||||
{
|
||||
private static readonly ILog log = LogManager.GetLogger(typeof(Printer));
|
||||
public override string ToString() { return string.Format("ResultsPrinters.Basic({0})", Cfg.ToString(1)); }
|
||||
|
||||
readonly PrinterCfg printerCfg;
|
||||
|
||||
public bool SupressPrinting { get { return printerCfg.SupressPrinting; } }
|
||||
|
||||
///
|
||||
/// Items to print
|
||||
///
|
||||
string header;
|
||||
IList<Results.WMeterRsltItemSpec> commonItems;
|
||||
IList<Results.WMeterRsltItemSpec> testItems;
|
||||
string footer;
|
||||
|
||||
|
||||
Thread thread; /// Thread where results are printed
|
||||
bool completed; /// Set to 'true' by the thread when printing results is completed
|
||||
bool abort; /// Set to 'true' by Stop() operation to abort printing results
|
||||
|
||||
|
||||
public Printer() { }
|
||||
|
||||
|
||||
public Printer(Generic.IComponentCfg cfg)
|
||||
: base(cfg)
|
||||
{
|
||||
printerCfg = cfg as PrinterCfg;
|
||||
ApplyConfig();
|
||||
log.Debug(this.ToString());
|
||||
}
|
||||
|
||||
|
||||
void ApplyConfig()
|
||||
{
|
||||
header = string.IsNullOrEmpty(printerCfg.Header) ? string.Empty : printerCfg.Header.Replace("~", Environment.NewLine);
|
||||
commonItems = Results.WMeterRsltItemSpec.FromStrArray(printerCfg.CommonItems);
|
||||
testItems = Results.WMeterRsltItemSpec.FromStrArray(printerCfg.SelectedItems); /// TestID info will be overwritten later on
|
||||
footer = string.IsNullOrEmpty(printerCfg.Footer) ? string.Empty : printerCfg.Footer.Replace("~", Environment.NewLine);
|
||||
}
|
||||
|
||||
|
||||
#region Configuration Change Handling
|
||||
|
||||
public static void OnCfgChange(object sender, CfgChangeArgs args)
|
||||
{
|
||||
if (CfgChangeHandler == null) return;
|
||||
try { CfgChangeHandler(sender, args); }
|
||||
catch (Exception e) { log.Error("CfgChangeHandler(...) failed", e); }
|
||||
}
|
||||
|
||||
public static event EventHandler<CfgChangeArgs> CfgChangeHandler;
|
||||
|
||||
public override void StartChangeHandler()
|
||||
{
|
||||
CfgChangeHandler += delegate(object sender, CfgChangeArgs args)
|
||||
{
|
||||
PrinterCfg newCfg = args.Cfg as PrinterCfg;
|
||||
if (newCfg != null && newCfg.Name.Equals(Name))
|
||||
{
|
||||
if (args.Command == CfgChangeCmd.CfgChange)
|
||||
{
|
||||
printerCfg.PageOrientation = newCfg.PageOrientation;
|
||||
printerCfg.TopMargin = newCfg.TopMargin;
|
||||
printerCfg.BottomMargin = newCfg.BottomMargin;
|
||||
printerCfg.LeftMargin = newCfg.LeftMargin;
|
||||
printerCfg.SupressPrinting = newCfg.SupressPrinting;
|
||||
printerCfg.Culture = newCfg.Culture;
|
||||
printerCfg.CommonItems = newCfg.CommonItems;
|
||||
printerCfg.SelectedItems = newCfg.SelectedItems;
|
||||
printerCfg.Header = newCfg.Header;
|
||||
printerCfg.Footer = newCfg.Footer;
|
||||
|
||||
ApplyConfig();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endregion Configuration Change Handling
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Prints the test cycle results, Events: Event.ResultsPrinted
|
||||
/// </summary>
|
||||
/// <param name="batch">Batch results to print</param>
|
||||
/// <returns>Reference to the operation</returns>
|
||||
public IOperation PrintResultsOp(Results.Entities.Batch batch)
|
||||
{
|
||||
thread = new Thread(() =>
|
||||
{
|
||||
PrintResults(batch);
|
||||
completed = true;
|
||||
});
|
||||
|
||||
if (printerCfg.Culture > Culture.system && printerCfg.Culture < Culture.Count)
|
||||
{
|
||||
thread.CurrentCulture = new CultureInfo(printerCfg.Culture.ToString());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>Start this operation</summary>
|
||||
public void Start()
|
||||
{
|
||||
completed = false;
|
||||
abort = false;
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
/// <summary>Run this operation</summary>
|
||||
/// <returns>Event.ResultsPrinted</returns>
|
||||
public Event Run()
|
||||
{
|
||||
if (completed)
|
||||
return Event.ResultsPrinted;
|
||||
else
|
||||
return Event.Busy;
|
||||
}
|
||||
|
||||
/// <summary>Stop this operation</summary>
|
||||
public void Stop()
|
||||
{
|
||||
if (!completed) abort = true;
|
||||
}
|
||||
|
||||
|
||||
void PrintResults(Results.Entities.Batch batch)
|
||||
{
|
||||
if (batch.WaterMeters.Count > 0)
|
||||
{
|
||||
new Results.Output.Printers.Enhanced.EnhancedPrintDocument(batch,
|
||||
printerCfg.PageOrientation,
|
||||
printerCfg.TopMargin,
|
||||
printerCfg.BottomMargin,
|
||||
printerCfg.LeftMargin,
|
||||
header,
|
||||
commonItems,
|
||||
testItems,
|
||||
footer).Print();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,65 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System.Xml.Serialization;
|
||||
using Config.Entities;
|
||||
using TBF.BenchControl.Generic;
|
||||
|
||||
namespace TBF.BenchControl.Output.Printers.Enhanced
|
||||
{
|
||||
public class PrinterCfg : ComponentCfgBase, Generic.IComponentCfg
|
||||
{
|
||||
public IComponentCfgCtrl GetControl() { return new PrinterCfgCtrl(); }
|
||||
|
||||
///
|
||||
/// Serialized parameters
|
||||
///
|
||||
public PageOrientation PageOrientation;
|
||||
public int TopMargin;
|
||||
public int BottomMargin;
|
||||
public int LeftMargin;
|
||||
public bool SupressPrinting; /// Bypass printing when true
|
||||
public Culture Culture;
|
||||
public string[] CommonItems;
|
||||
public string[] SelectedItems;
|
||||
public string Header;
|
||||
public string Footer;
|
||||
|
||||
[XmlIgnore]
|
||||
public Config.Entities.MetersKind MetersKind;
|
||||
|
||||
/// Private parameterless constructor invoked by all other (public) constructors
|
||||
PrinterCfg()
|
||||
{
|
||||
}
|
||||
|
||||
public PrinterCfg(string name, IComponentFactory factory, Config.Entities.MetersKind metersKind)
|
||||
: this()
|
||||
{
|
||||
Name = name;
|
||||
Factory = factory;
|
||||
MetersKind = metersKind;
|
||||
|
||||
ParentName = string.Empty;
|
||||
PageOrientation = PageOrientation.Portrait;
|
||||
TopMargin = 100;
|
||||
BottomMargin = 100;
|
||||
LeftMargin = 100;
|
||||
SupressPrinting = false;
|
||||
Header = string.Empty;
|
||||
Footer = string.Empty;
|
||||
}
|
||||
|
||||
public string ToString(int i)
|
||||
{
|
||||
return string.Format("Name={0}, Orientation={1}, Margins T={2} B={3} L={4}, SupressPrinting={5}",
|
||||
Name,
|
||||
PageOrientation,
|
||||
TopMargin,
|
||||
BottomMargin,
|
||||
LeftMargin,
|
||||
SupressPrinting ? "yes" : "no"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
273
TestBenchFramework/BenchControl/Output/Printers/Enhanced/PrinterCfgCtrl.Designer.cs
generated
Normal file
273
TestBenchFramework/BenchControl/Output/Printers/Enhanced/PrinterCfgCtrl.Designer.cs
generated
Normal file
@ -0,0 +1,273 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
namespace TBF.BenchControl.Output.Printers.Enhanced
|
||||
{
|
||||
partial class PrinterCfgCtrl
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Component Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.nameTextBox = new System.Windows.Forms.TextBox();
|
||||
this.nameLabel = new System.Windows.Forms.Label();
|
||||
this.classNameLabel = new System.Windows.Forms.Label();
|
||||
this.supressPrintingCheckBox = new System.Windows.Forms.CheckBox();
|
||||
this.orientationLabel = new System.Windows.Forms.Label();
|
||||
this.orientationComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.topMarginTextBox = new System.Windows.Forms.TextBox();
|
||||
this.topMarginLabel = new System.Windows.Forms.Label();
|
||||
this.leftMarginTextBox = new System.Windows.Forms.TextBox();
|
||||
this.leftMarginLabel = new System.Windows.Forms.Label();
|
||||
this.bottomMarginTextBox = new System.Windows.Forms.TextBox();
|
||||
this.bottomMarginLabel = new System.Windows.Forms.Label();
|
||||
this.cultureComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.cultureLabel = new System.Windows.Forms.Label();
|
||||
this.commonItemsButton = new System.Windows.Forms.Button();
|
||||
this.footerButton = new System.Windows.Forms.Button();
|
||||
this.headerButton = new System.Windows.Forms.Button();
|
||||
this.testItemsButton = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// nameTextBox
|
||||
//
|
||||
this.nameTextBox.Enabled = false;
|
||||
this.nameTextBox.Location = new System.Drawing.Point(142, 40);
|
||||
this.nameTextBox.Name = "nameTextBox";
|
||||
this.nameTextBox.Size = new System.Drawing.Size(146, 20);
|
||||
this.nameTextBox.TabIndex = 2;
|
||||
//
|
||||
// nameLabel
|
||||
//
|
||||
this.nameLabel.AutoSize = true;
|
||||
this.nameLabel.Location = new System.Drawing.Point(16, 43);
|
||||
this.nameLabel.Name = "nameLabel";
|
||||
this.nameLabel.Size = new System.Drawing.Size(35, 13);
|
||||
this.nameLabel.TabIndex = 1;
|
||||
this.nameLabel.Text = "Name";
|
||||
//
|
||||
// classNameLabel
|
||||
//
|
||||
this.classNameLabel.AutoSize = true;
|
||||
this.classNameLabel.Location = new System.Drawing.Point(139, 16);
|
||||
this.classNameLabel.Name = "classNameLabel";
|
||||
this.classNameLabel.Size = new System.Drawing.Size(83, 13);
|
||||
this.classNameLabel.TabIndex = 0;
|
||||
this.classNameLabel.Text = "ComonentName";
|
||||
//
|
||||
// supressPrintingCheckBox
|
||||
//
|
||||
this.supressPrintingCheckBox.AutoSize = true;
|
||||
this.supressPrintingCheckBox.Enabled = false;
|
||||
this.supressPrintingCheckBox.Location = new System.Drawing.Point(142, 167);
|
||||
this.supressPrintingCheckBox.Name = "supressPrintingCheckBox";
|
||||
this.supressPrintingCheckBox.Size = new System.Drawing.Size(101, 17);
|
||||
this.supressPrintingCheckBox.TabIndex = 11;
|
||||
this.supressPrintingCheckBox.Text = "Supress printing";
|
||||
this.supressPrintingCheckBox.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// orientationLabel
|
||||
//
|
||||
this.orientationLabel.AutoSize = true;
|
||||
this.orientationLabel.Location = new System.Drawing.Point(16, 67);
|
||||
this.orientationLabel.Name = "orientationLabel";
|
||||
this.orientationLabel.Size = new System.Drawing.Size(84, 13);
|
||||
this.orientationLabel.TabIndex = 3;
|
||||
this.orientationLabel.Text = "Page orientation";
|
||||
//
|
||||
// orientationComboBox
|
||||
//
|
||||
this.orientationComboBox.Enabled = false;
|
||||
this.orientationComboBox.FormattingEnabled = true;
|
||||
this.orientationComboBox.Location = new System.Drawing.Point(142, 64);
|
||||
this.orientationComboBox.Name = "orientationComboBox";
|
||||
this.orientationComboBox.Size = new System.Drawing.Size(146, 21);
|
||||
this.orientationComboBox.TabIndex = 4;
|
||||
//
|
||||
// topMarginTextBox
|
||||
//
|
||||
this.topMarginTextBox.Enabled = false;
|
||||
this.topMarginTextBox.Location = new System.Drawing.Point(142, 89);
|
||||
this.topMarginTextBox.Name = "topMarginTextBox";
|
||||
this.topMarginTextBox.Size = new System.Drawing.Size(80, 20);
|
||||
this.topMarginTextBox.TabIndex = 6;
|
||||
//
|
||||
// topMarginLabel
|
||||
//
|
||||
this.topMarginLabel.AutoSize = true;
|
||||
this.topMarginLabel.Location = new System.Drawing.Point(16, 92);
|
||||
this.topMarginLabel.Name = "topMarginLabel";
|
||||
this.topMarginLabel.Size = new System.Drawing.Size(109, 13);
|
||||
this.topMarginLabel.TabIndex = 5;
|
||||
this.topMarginLabel.Text = "Top margin [0.25 mm]";
|
||||
//
|
||||
// leftMarginTextBox
|
||||
//
|
||||
this.leftMarginTextBox.Enabled = false;
|
||||
this.leftMarginTextBox.Location = new System.Drawing.Point(142, 137);
|
||||
this.leftMarginTextBox.Name = "leftMarginTextBox";
|
||||
this.leftMarginTextBox.Size = new System.Drawing.Size(80, 20);
|
||||
this.leftMarginTextBox.TabIndex = 10;
|
||||
//
|
||||
// leftMarginLabel
|
||||
//
|
||||
this.leftMarginLabel.AutoSize = true;
|
||||
this.leftMarginLabel.Location = new System.Drawing.Point(16, 140);
|
||||
this.leftMarginLabel.Name = "leftMarginLabel";
|
||||
this.leftMarginLabel.Size = new System.Drawing.Size(108, 13);
|
||||
this.leftMarginLabel.TabIndex = 9;
|
||||
this.leftMarginLabel.Text = "Left margin [0.25 mm]";
|
||||
//
|
||||
// bottomMarginTextBox
|
||||
//
|
||||
this.bottomMarginTextBox.Enabled = false;
|
||||
this.bottomMarginTextBox.Location = new System.Drawing.Point(142, 113);
|
||||
this.bottomMarginTextBox.Name = "bottomMarginTextBox";
|
||||
this.bottomMarginTextBox.Size = new System.Drawing.Size(80, 20);
|
||||
this.bottomMarginTextBox.TabIndex = 8;
|
||||
//
|
||||
// bottomMarginLabel
|
||||
//
|
||||
this.bottomMarginLabel.AutoSize = true;
|
||||
this.bottomMarginLabel.Location = new System.Drawing.Point(16, 116);
|
||||
this.bottomMarginLabel.Name = "bottomMarginLabel";
|
||||
this.bottomMarginLabel.Size = new System.Drawing.Size(123, 13);
|
||||
this.bottomMarginLabel.TabIndex = 7;
|
||||
this.bottomMarginLabel.Text = "Bottom margin [0.25 mm]";
|
||||
//
|
||||
// cultureComboBox
|
||||
//
|
||||
this.cultureComboBox.Enabled = false;
|
||||
this.cultureComboBox.FormattingEnabled = true;
|
||||
this.cultureComboBox.Location = new System.Drawing.Point(142, 192);
|
||||
this.cultureComboBox.Name = "cultureComboBox";
|
||||
this.cultureComboBox.Size = new System.Drawing.Size(146, 21);
|
||||
this.cultureComboBox.TabIndex = 28;
|
||||
//
|
||||
// cultureLabel
|
||||
//
|
||||
this.cultureLabel.AutoSize = true;
|
||||
this.cultureLabel.Location = new System.Drawing.Point(16, 195);
|
||||
this.cultureLabel.Name = "cultureLabel";
|
||||
this.cultureLabel.Size = new System.Drawing.Size(42, 13);
|
||||
this.cultureLabel.TabIndex = 27;
|
||||
this.cultureLabel.Text = "Cullture";
|
||||
//
|
||||
// commonItemsButton
|
||||
//
|
||||
this.commonItemsButton.Enabled = false;
|
||||
this.commonItemsButton.Location = new System.Drawing.Point(142, 242);
|
||||
this.commonItemsButton.Name = "commonItemsButton";
|
||||
this.commonItemsButton.Size = new System.Drawing.Size(146, 23);
|
||||
this.commonItemsButton.TabIndex = 30;
|
||||
this.commonItemsButton.Text = "Common items";
|
||||
this.commonItemsButton.UseVisualStyleBackColor = true;
|
||||
this.commonItemsButton.Click += new System.EventHandler(this.commonItemsButton_Click);
|
||||
//
|
||||
// footerButton
|
||||
//
|
||||
this.footerButton.Enabled = false;
|
||||
this.footerButton.Location = new System.Drawing.Point(142, 292);
|
||||
this.footerButton.Name = "footerButton";
|
||||
this.footerButton.Size = new System.Drawing.Size(146, 23);
|
||||
this.footerButton.TabIndex = 32;
|
||||
this.footerButton.Text = "Footer";
|
||||
this.footerButton.UseVisualStyleBackColor = true;
|
||||
this.footerButton.Click += new System.EventHandler(this.footerButton_Click);
|
||||
//
|
||||
// headerButton
|
||||
//
|
||||
this.headerButton.Enabled = false;
|
||||
this.headerButton.Location = new System.Drawing.Point(142, 217);
|
||||
this.headerButton.Name = "headerButton";
|
||||
this.headerButton.Size = new System.Drawing.Size(146, 23);
|
||||
this.headerButton.TabIndex = 29;
|
||||
this.headerButton.Text = "Header";
|
||||
this.headerButton.UseVisualStyleBackColor = true;
|
||||
this.headerButton.Click += new System.EventHandler(this.headerButton_Click);
|
||||
//
|
||||
// testItemsButton
|
||||
//
|
||||
this.testItemsButton.Enabled = false;
|
||||
this.testItemsButton.Location = new System.Drawing.Point(142, 267);
|
||||
this.testItemsButton.Name = "testItemsButton";
|
||||
this.testItemsButton.Size = new System.Drawing.Size(146, 23);
|
||||
this.testItemsButton.TabIndex = 31;
|
||||
this.testItemsButton.Text = "Test items";
|
||||
this.testItemsButton.UseVisualStyleBackColor = true;
|
||||
this.testItemsButton.Click += new System.EventHandler(this.testItemsButton_Click);
|
||||
//
|
||||
// PrinterCfgCtrl
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.cultureComboBox);
|
||||
this.Controls.Add(this.cultureLabel);
|
||||
this.Controls.Add(this.commonItemsButton);
|
||||
this.Controls.Add(this.footerButton);
|
||||
this.Controls.Add(this.headerButton);
|
||||
this.Controls.Add(this.testItemsButton);
|
||||
this.Controls.Add(this.bottomMarginTextBox);
|
||||
this.Controls.Add(this.bottomMarginLabel);
|
||||
this.Controls.Add(this.leftMarginTextBox);
|
||||
this.Controls.Add(this.leftMarginLabel);
|
||||
this.Controls.Add(this.topMarginTextBox);
|
||||
this.Controls.Add(this.topMarginLabel);
|
||||
this.Controls.Add(this.orientationComboBox);
|
||||
this.Controls.Add(this.orientationLabel);
|
||||
this.Controls.Add(this.supressPrintingCheckBox);
|
||||
this.Controls.Add(this.nameTextBox);
|
||||
this.Controls.Add(this.nameLabel);
|
||||
this.Controls.Add(this.classNameLabel);
|
||||
this.Name = "PrinterCfgCtrl";
|
||||
this.Size = new System.Drawing.Size(400, 350);
|
||||
this.Load += new System.EventHandler(this.PrinterCfgCtrl_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.TextBox nameTextBox;
|
||||
private System.Windows.Forms.Label nameLabel;
|
||||
private System.Windows.Forms.Label classNameLabel;
|
||||
private System.Windows.Forms.CheckBox supressPrintingCheckBox;
|
||||
private System.Windows.Forms.Label orientationLabel;
|
||||
private System.Windows.Forms.ComboBox orientationComboBox;
|
||||
private System.Windows.Forms.TextBox topMarginTextBox;
|
||||
private System.Windows.Forms.Label topMarginLabel;
|
||||
private System.Windows.Forms.TextBox leftMarginTextBox;
|
||||
private System.Windows.Forms.Label leftMarginLabel;
|
||||
private System.Windows.Forms.TextBox bottomMarginTextBox;
|
||||
private System.Windows.Forms.Label bottomMarginLabel;
|
||||
private System.Windows.Forms.ComboBox cultureComboBox;
|
||||
private System.Windows.Forms.Label cultureLabel;
|
||||
private System.Windows.Forms.Button commonItemsButton;
|
||||
private System.Windows.Forms.Button footerButton;
|
||||
private System.Windows.Forms.Button headerButton;
|
||||
private System.Windows.Forms.Button testItemsButton;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,289 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using log4net;
|
||||
using Config.Entities;
|
||||
using TBF.BenchControl.Generic;
|
||||
using TBF.Resources;
|
||||
|
||||
namespace TBF.BenchControl.Output.Printers.Enhanced
|
||||
{
|
||||
public partial class PrinterCfgCtrl : UserControl, IComponentCfgCtrl
|
||||
{
|
||||
static readonly ILog log = LogManager.GetLogger(typeof(PrinterCfgCtrl));
|
||||
|
||||
public bool ShowMore { get { return false; } }
|
||||
|
||||
PrinterCfg config;
|
||||
public IComponentCfg Config
|
||||
{
|
||||
get { return config as IComponentCfg; }
|
||||
set
|
||||
{
|
||||
config = value as PrinterCfg;
|
||||
Redraw();
|
||||
}
|
||||
}
|
||||
|
||||
string header;
|
||||
string[] commonItems;
|
||||
string[] testItems;
|
||||
string footer;
|
||||
|
||||
public PrinterCfgCtrl()
|
||||
{
|
||||
InitializeComponent();
|
||||
Localize();
|
||||
|
||||
orientationComboBox.Items.Add(PageOrientation.Portrait.ToString());
|
||||
orientationComboBox.Items.Add(PageOrientation.Landscape.ToString());
|
||||
}
|
||||
|
||||
private void PrinterCfgCtrl_Load(object sender, EventArgs e)
|
||||
{
|
||||
for (Culture s = 0; s < Culture.Count; s++) cultureComboBox.Items.Add(s.ToString());
|
||||
|
||||
header = config.Header;
|
||||
commonItems = config.CommonItems;
|
||||
testItems = config.SelectedItems;
|
||||
footer = config.Footer;
|
||||
|
||||
Redraw();
|
||||
}
|
||||
|
||||
void Localize()
|
||||
{
|
||||
nameLabel.Text = Strings.Name;
|
||||
cultureLabel.Text = "Culture";
|
||||
headerButton.Text = Strings.Header;
|
||||
commonItemsButton.Text = "Common items";
|
||||
testItemsButton.Text = "Test items";
|
||||
footerButton.Text = Strings.Footer;
|
||||
}
|
||||
|
||||
public void Closing()
|
||||
{
|
||||
}
|
||||
|
||||
PageOrientation GetOrientation(string str)
|
||||
{
|
||||
if (str.Equals(PageOrientation.Landscape.ToString())) return PageOrientation.Landscape;
|
||||
if (str.Equals(PageOrientation.Portrait.ToString())) return PageOrientation.Portrait;
|
||||
return (PageOrientation)(-1);
|
||||
}
|
||||
|
||||
void Redraw()
|
||||
{
|
||||
if (config == null) return; /// Control was not loaded, settings were not changed
|
||||
classNameLabel.Text = config.Factory.ClassName;
|
||||
nameTextBox.Text = config.Name;
|
||||
orientationComboBox.Text = config.PageOrientation.ToString();
|
||||
topMarginTextBox.Text = config.TopMargin.ToString();
|
||||
bottomMarginTextBox.Text = config.BottomMargin.ToString();
|
||||
leftMarginTextBox.Text = config.LeftMargin.ToString();
|
||||
supressPrintingCheckBox.Checked = config.SupressPrinting;
|
||||
cultureComboBox.Text = config.Culture.ToString();
|
||||
}
|
||||
|
||||
public void Unlock()
|
||||
{
|
||||
nameTextBox.Enabled = true;
|
||||
orientationComboBox.Enabled = true;
|
||||
topMarginTextBox.Enabled = true;
|
||||
bottomMarginTextBox.Enabled = true;
|
||||
leftMarginTextBox.Enabled = true;
|
||||
supressPrintingCheckBox.Enabled = true;
|
||||
cultureComboBox.Enabled = true;
|
||||
headerButton.Enabled = true;
|
||||
commonItemsButton.Enabled = true;
|
||||
testItemsButton.Enabled = true;
|
||||
footerButton.Enabled = true;
|
||||
}
|
||||
|
||||
public CfgUpdateFlags VerifyCfg(ref string message)
|
||||
{
|
||||
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
||||
|
||||
if ((int)GetOrientation(orientationComboBox.Text) < 0)
|
||||
{
|
||||
message += Environment.NewLine + "Invalid 'Page orientation'";
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
}
|
||||
|
||||
int dummy;
|
||||
if (!int.TryParse(topMarginTextBox.Text, out dummy) || dummy < 0 || dummy > 500)
|
||||
{
|
||||
message += Environment.NewLine + "'Top margin' should be between 0 and 500";
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
}
|
||||
|
||||
if (!int.TryParse(bottomMarginTextBox.Text, out dummy) || dummy < 0 || dummy > 200)
|
||||
{
|
||||
message += Environment.NewLine + "'Bottom margin' should be between 0 and 200";
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
}
|
||||
|
||||
if (!int.TryParse(leftMarginTextBox.Text, out dummy) || dummy < 0 || dummy > 200)
|
||||
{
|
||||
message += Environment.NewLine + "Left margin' should be between 0 and 200";
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
}
|
||||
|
||||
if (!cultureComboBox.Items.Contains(cultureComboBox.Text))
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "Invalid culture";
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
public CfgUpdateFlags UpdateCfg()
|
||||
{
|
||||
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
||||
|
||||
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
||||
|
||||
if (config.Name != nameTextBox.Text)
|
||||
{
|
||||
config.Name = nameTextBox.Text;
|
||||
flags |= (CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
if (config.PageOrientation != GetOrientation(orientationComboBox.Text))
|
||||
{
|
||||
config.PageOrientation = GetOrientation(orientationComboBox.Text);
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
int tmp = int.Parse(topMarginTextBox.Text);
|
||||
if (config.TopMargin != tmp)
|
||||
{
|
||||
config.TopMargin = tmp;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
tmp = int.Parse(bottomMarginTextBox.Text);
|
||||
if (config.BottomMargin != tmp)
|
||||
{
|
||||
config.BottomMargin = tmp;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
tmp = int.Parse(leftMarginTextBox.Text);
|
||||
if (config.LeftMargin != tmp)
|
||||
{
|
||||
config.LeftMargin = tmp;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
if (config.SupressPrinting != supressPrintingCheckBox.Checked)
|
||||
{
|
||||
config.SupressPrinting = supressPrintingCheckBox.Checked;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
if (config.CommonItems != commonItems)
|
||||
{
|
||||
config.CommonItems = commonItems;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
if (config.SelectedItems != testItems)
|
||||
{
|
||||
config.SelectedItems = testItems;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
if (config.Header != header)
|
||||
{
|
||||
config.Header = header;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
if (config.Footer != footer)
|
||||
{
|
||||
config.Footer = footer;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
if ((flags & CfgUpdateFlags.InvokeCfgChange) != 0)
|
||||
{
|
||||
Printer.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.CfgChange, config));
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
private void headerButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
HeaderFooterDlg dlg = new HeaderFooterDlg(true, string.IsNullOrEmpty(header) ? string.Empty : header.Replace("~", Environment.NewLine));
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
header = dlg.EditedText.Replace(Environment.NewLine, "~");
|
||||
}
|
||||
}
|
||||
|
||||
private void commonItemsButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Results.Forms.ResultsConfigDlg dlg = new Results.Forms.ResultsConfigDlg()
|
||||
{
|
||||
MetersKind = config.MetersKind,
|
||||
SelectedItems = Results.WMeterRsltItemSpec.FromStrArray(commonItems),
|
||||
AvailableItems = new List<Results.WMeterRsltItemSpec>()
|
||||
};
|
||||
|
||||
foreach (var v in Results.WMeterRsltItemSpec.AllItems) dlg.AvailableItems.Add(v);
|
||||
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
commonItems = Results.WMeterRsltItemSpec.ToStrArray(dlg.SelectedItems);
|
||||
}
|
||||
}
|
||||
|
||||
private void testItemsButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Results.Forms.ResultsConfigDlg dlg = new Results.Forms.ResultsConfigDlg(true)
|
||||
{
|
||||
MetersKind = config.MetersKind,
|
||||
SelectedItems = Results.WMeterRsltItemSpec.FromStrArray(testItems),
|
||||
AvailableItems = new List<Results.WMeterRsltItemSpec>()
|
||||
};
|
||||
|
||||
foreach (var v in Results.WMeterRsltItemSpec.AllItems) dlg.AvailableItems.Add(v);
|
||||
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
testItems = Results.WMeterRsltItemSpec.ToStrArray(dlg.SelectedItems);
|
||||
}
|
||||
}
|
||||
|
||||
private void footerButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
HeaderFooterDlg dlg = new HeaderFooterDlg(false, string.IsNullOrEmpty(footer) ? string.Empty : footer.Replace("~", Environment.NewLine));
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
footer = dlg.EditedText.Replace(Environment.NewLine, "~");
|
||||
}
|
||||
}
|
||||
|
||||
#region Configuration Change Handling
|
||||
|
||||
public static void OnCmdResponse(object sender, CmdResponseArgs args)
|
||||
{
|
||||
if (CmdResponseHandler == null) return;
|
||||
try { CmdResponseHandler(sender, args); }
|
||||
catch (Exception e) { log.Error("CmdResponseHandler(...) failed", e); }
|
||||
}
|
||||
|
||||
public static event EventHandler<CmdResponseArgs> CmdResponseHandler;
|
||||
|
||||
public void StartResponseHandler() { }
|
||||
public void StopResponseHandler() { }
|
||||
|
||||
#endregion Configuration Change Handling
|
||||
}
|
||||
}
|
||||
@ -627,18 +627,13 @@
|
||||
<Compile Include="BenchControl\Operations\EnduranceDataLoggingOp.cs" />
|
||||
<Compile Include="BenchControl\Operations\EnthalpyCalculationOp.cs" />
|
||||
<Compile Include="BenchControl\Operations\ReturnGivenEventOp.cs" />
|
||||
<Compile Include="BenchControl\Output\Enums.cs" />
|
||||
<Compile Include="BenchControl\Output\FileWriters\Basic\FactoryCompound.cs" />
|
||||
<Compile Include="BenchControl\Output\FileWriters\Basic\FactoryHeatMeters.cs" />
|
||||
<Compile Include="BenchControl\Output\FileWriters\Basic\FactorySingle.cs" />
|
||||
<Compile Include="BenchControl\Output\FileWriters\Enhanced\FactoryCompound.cs" />
|
||||
<Compile Include="BenchControl\Output\FileWriters\Enhanced\FactoryHeatMeters.cs" />
|
||||
<Compile Include="BenchControl\Output\FileWriters\Enhanced\FactorySingle.cs" />
|
||||
<Compile Include="BenchControl\Output\FileWriters\Enhanced\HeaderFooterDlg.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BenchControl\Output\FileWriters\Enhanced\HeaderFooterDlg.Designer.cs">
|
||||
<DependentUpon>HeaderFooterDlg.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BenchControl\Output\FileWriters\Enhanced\Writer.cs" />
|
||||
<Compile Include="BenchControl\Output\FileWriters\Enhanced\WriterCfg.cs" />
|
||||
<Compile Include="BenchControl\Output\FileWriters\Enhanced\WriterCfgCtrl.cs">
|
||||
@ -651,12 +646,6 @@
|
||||
<Compile Include="BenchControl\Output\FileWriters\Xml\FactoryCompound.cs" />
|
||||
<Compile Include="BenchControl\Output\FileWriters\Xml\FactoryHeatMeters.cs" />
|
||||
<Compile Include="BenchControl\Output\FileWriters\Xml\FactorySingle.cs" />
|
||||
<Compile Include="BenchControl\Output\FileWriters\Xml\HeaderFooterDlg.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BenchControl\Output\FileWriters\Xml\HeaderFooterDlg.designer.cs">
|
||||
<DependentUpon>HeaderFooterDlg.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BenchControl\Output\FileWriters\Xml\Writer.cs" />
|
||||
<Compile Include="BenchControl\Output\FileWriters\Xml\WriterCfg.cs" />
|
||||
<Compile Include="BenchControl\Output\FileWriters\Xml\WriterCfgCtrl.cs">
|
||||
@ -665,6 +654,23 @@
|
||||
<Compile Include="BenchControl\Output\FileWriters\Xml\WriterCfgCtrl.designer.cs">
|
||||
<DependentUpon>WriterCfgCtrl.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BenchControl\Output\HeaderFooterDlg.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BenchControl\Output\HeaderFooterDlg.designer.cs">
|
||||
<DependentUpon>HeaderFooterDlg.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BenchControl\Output\Printers\Enhanced\FactoryCompound.cs" />
|
||||
<Compile Include="BenchControl\Output\Printers\Enhanced\FactoryHeatMeters.cs" />
|
||||
<Compile Include="BenchControl\Output\Printers\Enhanced\Printer.cs" />
|
||||
<Compile Include="BenchControl\Output\Printers\Enhanced\PrinterCfg.cs" />
|
||||
<Compile Include="BenchControl\Output\Printers\Enhanced\PrinterCfgCtrl.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BenchControl\Output\Printers\Enhanced\PrinterCfgCtrl.designer.cs">
|
||||
<DependentUpon>PrinterCfgCtrl.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="BenchControl\Output\Printers\Enhanced\FactorySingle.cs" />
|
||||
<Compile Include="BenchControl\ResultsPrinters\Cevak\Printer.cs" />
|
||||
<Compile Include="BenchControl\ResultsPrinters\Cevak\PrinterCfg.cs" />
|
||||
<Compile Include="BenchControl\ResultsPrinters\Cevak\PrinterCfgCtrl.cs">
|
||||
@ -1985,18 +1991,18 @@
|
||||
<EmbeddedResource Include="BenchControl\Operations\MessageBoxForm.resx">
|
||||
<DependentUpon>MessageBoxForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="BenchControl\Output\FileWriters\Enhanced\HeaderFooterDlg.resx">
|
||||
<DependentUpon>HeaderFooterDlg.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="BenchControl\Output\FileWriters\Enhanced\WriterCfgCtrl.resx">
|
||||
<DependentUpon>WriterCfgCtrl.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="BenchControl\Output\FileWriters\Xml\HeaderFooterDlg.resx">
|
||||
<DependentUpon>HeaderFooterDlg.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="BenchControl\Output\FileWriters\Xml\WriterCfgCtrl.resx">
|
||||
<DependentUpon>WriterCfgCtrl.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="BenchControl\Output\HeaderFooterDlg.resx">
|
||||
<DependentUpon>HeaderFooterDlg.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="BenchControl\Output\Printers\Enhanced\PrinterCfgCtrl.resx">
|
||||
<DependentUpon>PrinterCfgCtrl.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="BenchControl\ResultsPrinters\Basic\PrinterCfgCtrl.resx">
|
||||
<DependentUpon>PrinterCfgCtrl.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
@ -2448,9 +2454,7 @@
|
||||
<Name>Users</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="BenchControl\Output\Printers\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user