tbf/TestBenchFramework/BenchControl/ResultsPrinters/LabelPrinter/Printer.cs
2015-12-08 23:44:52 +01:00

91 lines
2.3 KiB
C#

///
/// Copyright (c) 2015 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using log4net;
using Config.Entities;
using TBF.BenchControl;
namespace TBF.BenchControl.ResultsPrinters.LabelPrinter
{
public class Printer : ComponentBase, IOperation, GenericDevices.IResultsPrinter
{
private static readonly ILog log = LogManager.GetLogger(typeof(Printer));
public override string ToString() { return string.Format("LabelPrinter({0})", Cfg.ToString(1)); }
readonly PrinterCfg printerCfg;
public bool SupressPrinting { get { return printerCfg.SupressPrinting; } }
/// <summary>
/// Data to print
/// </summary>
GenericDevices.IBenchInfo benchId;
Procedure procedure;
IList<TestResult> unsortedResults;
public Printer()
{
}
public Printer(PrinterCfg cfg)
: base(cfg)
{
printerCfg = cfg;
log.Debug(this.ToString());
}
/// <summary>
/// Prints the test cycle results, Events: Event.ResultsPrinted
/// </summary>
/// <param name="benchId">Bench ID</param>
/// <param name="waterMeters">This parameter is unused</param>
/// <param name="procedure">Procedure to print the results of</param>
/// <param name="unsortedResults">Results to print</param>
/// <param name="title">This parameter is unused</param>
/// <returns>Reference to the operation</returns>
public IOperation PrintResultsOp(GenericDevices.IBenchInfo benchId,
IList<GenericDevices.IWaterMeter> waterMeters,
Procedure procedure,
IList<TestResult> unsortedResults,
string title)
{
if ((procedure == null) || (unsortedResults == null) || (unsortedResults.Count < 1))
{
return null;
}
this.benchId = benchId;
this.procedure = procedure;
this.unsortedResults = unsortedResults;
return this;
}
/// <summary>Start this operation</summary>
public void Start()
{
new PrintLabelDocument(benchId, procedure, unsortedResults,
printerCfg.PageOrientation,
printerCfg.PaperWidth,
printerCfg.PaperHeight,
printerCfg.TemplateFile).Print();
}
/// <summary>Run this operation</summary>
/// <returns>Event.ResultsPrinted</returns>
public Event Run()
{
return Event.ResultsPrinted;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
}
}
}