338 lines
14 KiB
C#
338 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Drawing.Printing;
|
|
using TBF.BenchControl;
|
|
|
|
namespace TBF.BenchControl.ResultsPrinters.Munich
|
|
{
|
|
public class MunichPrintDocument : PrintDocument
|
|
{
|
|
const string FontFamilyName = "Arial"; //"Times New Roman";
|
|
|
|
const int SpacingOne = 18;
|
|
const int SpacingOneAndHalf = (3 * SpacingOne) / 2;
|
|
const int TitleX = 240;
|
|
const int TitleY = 180; /// Depends on the size of the header
|
|
const int FirstLineNr = 14; /// Depends on the size of the header
|
|
const int Tab1 = 80; /// Positions of columns above the table
|
|
const int Tab2 = 240;
|
|
const int Tab3 = 430;
|
|
const int Tab4 = 590;
|
|
const int BorderW = 1; /// Table border line width
|
|
const int MarginTop = 7; /// Margins of the text from table lines
|
|
const int MarginLeft = 4; /// Margins of the text from table lines
|
|
|
|
/// Initialized in the constructor
|
|
readonly Printer prn;
|
|
readonly bool combined; /// true when MetersKind is MetersKind.Combined
|
|
readonly int secondTableOffset; /// Calculated in the constructor
|
|
|
|
/// Top coordinate of the table
|
|
int top;
|
|
|
|
/// <summary>
|
|
/// Property variable for the Font the user wishes to use
|
|
/// </summary>
|
|
Font font;
|
|
Font boldFont;
|
|
Font fontTitle;
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
/// <param name="textToPrint">Text to be printed</param>
|
|
public MunichPrintDocument(Printer printer)
|
|
{
|
|
prn = printer;
|
|
combined = (prn.Results[0].MetersKind == Entities.MetersKind.Combined);
|
|
secondTableOffset = (prn.Results.Count + 2) * SpacingOneAndHalf;
|
|
}
|
|
|
|
/// <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 (fontTitle == null) { fontTitle = new Font(FontFamilyName, 24, 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);
|
|
|
|
e.Graphics.DrawImageUnscaled(Properties.Resources.Headpic, 0, 0);
|
|
|
|
/// Set print area size and margins (in dots using 80 dpi)
|
|
int printHeight = base.DefaultPageSettings.PaperSize.Height - base.DefaultPageSettings.Margins.Top - base.DefaultPageSettings.Margins.Bottom;
|
|
int printWidth = base.DefaultPageSettings.PaperSize.Width - base.DefaultPageSettings.Margins.Left - base.DefaultPageSettings.Margins.Right;
|
|
int leftMargin = base.DefaultPageSettings.Margins.Left; /// X
|
|
int topMargin = base.DefaultPageSettings.Margins.Top; /// Y
|
|
|
|
/// Check if the user selected to print in Landscape mode
|
|
/// if they did then we need to swap height/width parameters
|
|
if (base.DefaultPageSettings.Landscape)
|
|
{
|
|
int tmp = printHeight;
|
|
printHeight = printWidth;
|
|
printWidth = tmp;
|
|
}
|
|
|
|
int x = leftMargin;
|
|
int y = topMargin;
|
|
|
|
/// Use the StringFormat class for the text layout of our document
|
|
StringFormat format = new StringFormat(StringFormatFlags.LineLimit);
|
|
|
|
RectangleF printArea = new RectangleF(TitleX, TitleY, 667, 50);
|
|
e.Graphics.DrawString(prn.Title, this.fontTitle, Brushes.Black, printArea);
|
|
|
|
int lineNr = FirstLineNr;
|
|
PrintAt(e, Tab1, lineNr * SpacingOne, prn.Version);
|
|
lineNr++;
|
|
PrintBoldAt(e, Tab1, lineNr * SpacingOne, "Prüfstand Nr :");
|
|
PrintBoldAt(e, Tab2, lineNr * SpacingOne, (prn.BenchId != null) ? prn.BenchId.TestBenchNr.ToString() : "");
|
|
PrintBoldAt(e, Tab3, lineNr * SpacingOne, "Datum :");
|
|
PrintBoldAt(e, Tab4, lineNr * SpacingOne, DateTime.Now.Date.ToString("d"));
|
|
lineNr++;
|
|
PrintAt(e, Tab1, lineNr * SpacingOne, "Zahlertyp :");
|
|
PrintAt(e, Tab2, lineNr * SpacingOne, prn.Zaehlertyp);
|
|
PrintAt(e, Tab3, lineNr * SpacingOne, "Eichjahr :");
|
|
PrintAt(e, Tab4, lineNr * SpacingOne, prn.Eichjahr);
|
|
lineNr++;
|
|
PrintAt(e, Tab1, lineNr * SpacingOne, "Prüfvorlage :");
|
|
PrintAt(e, Tab2, lineNr * SpacingOne, prn.Pruefvorlage);
|
|
lineNr += 2;
|
|
|
|
if (combined)
|
|
{
|
|
PrintBoldAt(e, Tab1, lineNr * SpacingOne, "Hauptzahler");
|
|
PrintBoldAt(e, Tab3, lineNr * SpacingOne, "Nebenzahler");
|
|
lineNr++;
|
|
}
|
|
|
|
PrintAt(e, Tab1, lineNr * SpacingOne, "Hersteller :");
|
|
PrintAt(e, Tab2, lineNr * SpacingOne, prn.WaterMeters[0].Producer);
|
|
if (combined)
|
|
{
|
|
PrintAt(e, Tab3, lineNr * SpacingOne, "Hersteller :");
|
|
PrintAt(e, Tab4, lineNr * SpacingOne, prn.WaterMeters[1].Producer);
|
|
}
|
|
lineNr++;
|
|
|
|
PrintAt(e, Tab1, lineNr * SpacingOne, "Seriennummer :");
|
|
PrintAt(e, Tab2, lineNr * SpacingOne, prn.WaterMeters[0].SerialNr);
|
|
if (combined)
|
|
{
|
|
PrintAt(e, Tab3, lineNr * SpacingOne, "Seriennummer :");
|
|
PrintAt(e, Tab4, lineNr * SpacingOne, prn.WaterMeters[1].SerialNr);
|
|
}
|
|
lineNr++;
|
|
|
|
PrintAt(e, Tab1, lineNr * SpacingOne, "Qn :");
|
|
PrintAt(e, Tab2, lineNr * SpacingOne, prn.WaterMeters[0].Qn.ToString());
|
|
if (combined)
|
|
{
|
|
PrintAt(e, Tab3, lineNr * SpacingOne, "Qn :");
|
|
PrintAt(e, Tab4, lineNr * SpacingOne, prn.WaterMeters[1].Qn.ToString());
|
|
}
|
|
lineNr++;
|
|
|
|
PrintAt(e, Tab1, lineNr * SpacingOne, "Zulassungszeichen :");
|
|
PrintAt(e, Tab2, lineNr * SpacingOne, prn.WaterMeters[0].ApprovalInfo);
|
|
if (combined)
|
|
{
|
|
PrintAt(e, Tab3, lineNr * SpacingOne, "Zulassungszeichen :");
|
|
PrintAt(e, Tab4, lineNr * SpacingOne, prn.WaterMeters[1].ApprovalInfo);
|
|
}
|
|
lineNr++;
|
|
|
|
PrintAt(e, Tab1, lineNr * SpacingOne, "Metr. klasse :");
|
|
PrintAt(e, Tab2, lineNr * SpacingOne, prn.WaterMeters[0].MetrologicalClass);
|
|
if (combined)
|
|
{
|
|
PrintAt(e, Tab3, lineNr * SpacingOne, "Metr. klasse :");
|
|
PrintAt(e, Tab4, lineNr * SpacingOne, prn.WaterMeters[1].MetrologicalClass);
|
|
}
|
|
lineNr++;
|
|
|
|
PrintAt(e, Tab1, lineNr * SpacingOne, "Stand :");
|
|
PrintAt(e, Tab2, lineNr * SpacingOne, prn.WaterMeters[0].EndState);
|
|
if (combined)
|
|
{
|
|
PrintAt(e, Tab3, lineNr * SpacingOne, "Stand :");
|
|
PrintAt(e, Tab4, lineNr * SpacingOne, prn.WaterMeters[1].EndState);
|
|
|
|
lineNr += 2;
|
|
PrintAt(e, Tab1, lineNr * SpacingOne, "Umschaltpunkte :");
|
|
lineNr++;
|
|
PrintAt(e, Tab1, lineNr * SpacingOne, "Qsteig");
|
|
PrintAt(e, Tab2, lineNr * SpacingOne, (1000.0f * Sequences.SequenceBase.Qrise).ToString("F1") + " l/h");
|
|
lineNr++;
|
|
PrintAt(e, Tab1, lineNr * SpacingOne, "Qfall");
|
|
PrintAt(e, Tab2, lineNr * SpacingOne, (1000.0f * Sequences.SequenceBase.Qfall).ToString("F1") + " l/h");
|
|
}
|
|
|
|
lineNr += 2;
|
|
top = SpacingOne * lineNr;
|
|
|
|
PrintTable(e);
|
|
DrawTable(e);
|
|
|
|
lineNr += (secondTableOffset * 2) / SpacingOne;
|
|
PrintAt(e, Tab1, lineNr * SpacingOne, "Temperatur");
|
|
PrintAt(e, Tab2, lineNr * SpacingOne, prn.Results[0].AmbientTempAve.ToString("F1") + " \x00b0C");
|
|
lineNr++;
|
|
PrintAt(e, Tab1, lineNr * SpacingOne, "Feuchtigkeit");
|
|
PrintAt(e, Tab2, lineNr * SpacingOne, prn.Results[0].AmbientHumiAve.ToString("F0") + " %");
|
|
lineNr++;
|
|
PrintAt(e, Tab1, lineNr * SpacingOne, "Luftdruck");
|
|
PrintAt(e, Tab2, lineNr * SpacingOne, prn.Results[0].AmbientPressAve.ToString("F0") + " mbar");
|
|
|
|
lineNr++;
|
|
PrintAt(e, Tab3, lineNr * SpacingOne, DateTime.Now.Date.ToString("d"));
|
|
lineNr ++;
|
|
PrintAt(e, Tab3, lineNr * SpacingOne, "Datum");
|
|
PrintAt(e, Tab4, lineNr * SpacingOne, "Unterschrift");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Print table texts.
|
|
/// </summary>
|
|
void PrintTable(System.Drawing.Printing.PrintPageEventArgs e)
|
|
{
|
|
PrintAt(e, FromTest(-1, -1), "Prüflauf");
|
|
PrintAt(e, FromTest(-1, 0), "Q [l/h]");
|
|
PrintAt(e, FromTest(-1, 1), "Prüf-Vol.[l]");
|
|
PrintAt(e, FromTest(-1, 2), combined ? "HZ-Vol.[l]" : "Z-Vol.[l]");
|
|
PrintAt(e, FromTest(-1, 3), combined ? "NZ-Vol.[l]" : "-");
|
|
PrintAt(e, FromTest(-1, 4), "Fehler [%]");
|
|
PrintAt(e, FromTest(-1, 5), "Ergebnis");
|
|
|
|
PrintAt(e, FromTest(-1, 6), "Q [l/h]");
|
|
PrintAt(e, FromTest(-1, 7), "Temperatur");
|
|
PrintAt(e, FromTest(-1, 8), "Dichte");
|
|
PrintAt(e, FromTest(-1, 9), "Prüfzeit");
|
|
PrintAt(e, FromTest(-1, 10), "Druck Eing.");
|
|
PrintAt(e, FromTest(-1, 11), "Druck Ausg.");
|
|
|
|
for (int i = 0; i < prn.Results.Count; i++)
|
|
{
|
|
Point p = FromTest(i, -1);
|
|
PrintAt(e, p.X, p.Y, prn.Results[i].Name);
|
|
PrintAt(e, p.X, p.Y + (prn.Results.Count + 2) * SpacingOneAndHalf, prn.Results[i].Name);
|
|
|
|
PrintAt(e, FromTest(i, 0), prn.Results[i].FlowMass.ToString("F1"));
|
|
PrintAt(e, FromTest(i, 1), prn.Results[i].VolumeCTV.ToString("F2"));
|
|
PrintAt(e, FromTest(i, 2), prn.Results[i].Meters[0].VolumeMeter.ToString("F2"));
|
|
if (combined)
|
|
{
|
|
PrintAt(e, FromTest(i, 3), prn.Results[i].Meters[1].VolumeMeter.ToString("F2"));
|
|
PrintAt(e, FromTest(i, 4), prn.Results[i].CombinedMeters[0].VolumeErrorPct.ToString("F2"));
|
|
PrintAt(e, FromTest(i, 5), prn.Results[i].CombinedMeters[0].Passed ? "iO" : "NiO");
|
|
}
|
|
else
|
|
{
|
|
PrintAt(e, FromTest(i, 3), "-");
|
|
PrintAt(e, FromTest(i, 4), prn.Results[i].Meters[0].VolumeErrorPct.ToString("F2"));
|
|
PrintAt(e, FromTest(i, 5), prn.Results[i].Meters[0].Passed ? "iO" : "NiO");
|
|
}
|
|
PrintAt(e, FromTest(i, 6), prn.Results[i].FlowMass.ToString("F1"));
|
|
PrintAt(e, FromTest(i, 7), prn.Results[i].TempOutAvrg.ToString("F2"));
|
|
PrintAt(e, FromTest(i, 8), prn.Results[i].DensityDiv.ToString("F2"));
|
|
PrintAt(e, FromTest(i, 9), prn.Results[i].Time.ToString("F1"));
|
|
PrintAt(e, FromTest(i, 10), prn.Results[i].PressInAvrg.ToString("F2"));
|
|
PrintAt(e, FromTest(i, 11), prn.Results[i].PressOutAvrg.ToString("F2"));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Draw table lines.
|
|
/// </summary>
|
|
void DrawTable(System.Drawing.Printing.PrintPageEventArgs e)
|
|
{
|
|
int mid = top + SpacingOneAndHalf;
|
|
int bot = top + (prn.Results.Count + 1) * SpacingOneAndHalf;
|
|
|
|
int top2 = top + secondTableOffset;
|
|
int mid2 = mid + secondTableOffset;
|
|
int bot2 = bot + secondTableOffset;
|
|
|
|
// Horizontal lines
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(80, top), new Point(747, top));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(80, mid), new Point(747, mid));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(80, bot), new Point(747, bot));
|
|
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(80, top2), new Point(747, top2));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(80, mid2), new Point(747, mid2));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(80, bot2), new Point(747, bot2));
|
|
|
|
// Vertical lines
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point( 80, top), new Point( 80, bot));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(267, top), new Point(267, bot));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(347, top), new Point(347, bot));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(427, top), new Point(427, bot));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(507, top), new Point(507, bot));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(587, top), new Point(587, bot));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(667, top), new Point(667, bot));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(747, top), new Point(747, bot));
|
|
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point( 80, top2), new Point( 80, bot2));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(267, top2), new Point(267, bot2));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(347, top2), new Point(347, bot2));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(427, top2), new Point(427, bot2));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(507, top2), new Point(507, bot2));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(587, top2), new Point(587, bot2));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(667, top2), new Point(667, bot2));
|
|
e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(747, top2), new Point(747, bot2));
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
Point FromTest(int testNr, int parNr)
|
|
{
|
|
const int NrParamsInOneTableRow = 6;
|
|
|
|
int x = 267 + (parNr % NrParamsInOneTableRow) * 80 + MarginLeft;
|
|
int y = top + SpacingOneAndHalf + MarginTop + testNr * SpacingOneAndHalf
|
|
+ ((parNr >= NrParamsInOneTableRow) ? secondTableOffset : 0);
|
|
|
|
if (parNr < 0) x = 80 + MarginLeft; /// When parNr == -1 return the left column x coordinate
|
|
|
|
return new Point(x, y);
|
|
}
|
|
}
|
|
}
|