Initial commit almost identical to SVN-repo rev.340
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Printing;
|
||||
|
||||
namespace TBF.BenchControl.ResultsPrinters.Basic
|
||||
{
|
||||
public class BasicPrintDocument : PrintDocument
|
||||
{
|
||||
/// <summary>
|
||||
/// Property variable for the Font the user wishes to use
|
||||
/// </summary>
|
||||
public Font Font
|
||||
{
|
||||
get { return font; }
|
||||
set { font = value; }
|
||||
}
|
||||
Font font;
|
||||
|
||||
/// <summary>
|
||||
/// Data to print
|
||||
/// </summary>
|
||||
BenchControl.BenchId.Component benchId;
|
||||
IList<GenericDevices.IWaterMeter> waterMeters;
|
||||
IList<Entities.TestResult> results;
|
||||
string title;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="textToPrint">Text to be printed</param>
|
||||
public BasicPrintDocument(BenchControl.BenchId.Component benchId,
|
||||
IList<GenericDevices.IWaterMeter> waterMeters,
|
||||
IList<Entities.TestResult> results,
|
||||
string title)
|
||||
{
|
||||
this.benchId = benchId;
|
||||
this.waterMeters = waterMeters;
|
||||
this.results = results;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/// <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("Times New Roman", 10); }
|
||||
}
|
||||
|
||||
/// <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);
|
||||
|
||||
/// 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);
|
||||
|
||||
foreach (var testResults in results)
|
||||
{
|
||||
RectangleF printArea = new RectangleF(x, y, printWidth, printHeight);
|
||||
e.Graphics.DrawString("Test: " + testResults.TestName, font, Brushes.Black, printArea);
|
||||
y += 30;
|
||||
|
||||
printArea = new RectangleF(x + 100, y, printWidth, printHeight);
|
||||
e.Graphics.DrawString("Watermeter1: Error = " + testResults.Meters[0].VolumeErrorPct.ToString() +
|
||||
"% Result = " + testResults.Meters[0].Passed.ToString(),
|
||||
font, Brushes.Black, printArea);
|
||||
y += 30;
|
||||
|
||||
printArea = new RectangleF(x + 100, y, printWidth, printHeight);
|
||||
e.Graphics.DrawString("Watermeter2: " + testResults.Meters[1].Passed.ToString(),
|
||||
font, Brushes.Black, printArea);
|
||||
y += 30;
|
||||
|
||||
printArea = new RectangleF(x + 100, y, printWidth, printHeight);
|
||||
e.Graphics.DrawString("Watermeter3: " + testResults.Meters[2].Passed.ToString(),
|
||||
font, Brushes.Black, printArea);
|
||||
y += 50;
|
||||
}
|
||||
|
||||
e.HasMorePages = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user