2017-09-21 06:59:08 +00:00
|
|
|
|
///
|
|
|
|
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
|
|
|
|
///
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using Results.Output.Printers.Zapiska;
|
|
|
|
|
|
using log4net;
|
|
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl.Output.Printers.Zapiska
|
|
|
|
|
|
{
|
|
|
|
|
|
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.CommonItems1);
|
|
|
|
|
|
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.TitFntFml = newCfg.TitFntFml;
|
|
|
|
|
|
printerCfg.TitFntSz = newCfg.TitFntSz;
|
|
|
|
|
|
printerCfg.TitFntSty = newCfg.TitFntSty;
|
|
|
|
|
|
printerCfg.HdrFntFml = newCfg.HdrFntFml;
|
|
|
|
|
|
printerCfg.HdrFntSz = newCfg.HdrFntSz;
|
|
|
|
|
|
printerCfg.HdrFntSty = newCfg.HdrFntSty;
|
|
|
|
|
|
printerCfg.BodyFntFml = newCfg.BodyFntFml;
|
|
|
|
|
|
printerCfg.BodyFntSz = newCfg.BodyFntSz;
|
|
|
|
|
|
printerCfg.BodyFntSty = newCfg.BodyFntSty;
|
|
|
|
|
|
|
|
|
|
|
|
printerCfg.SupressPrinting = newCfg.SupressPrinting;
|
|
|
|
|
|
printerCfg.Culture = newCfg.Culture;
|
|
|
|
|
|
printerCfg.Header = newCfg.Header;
|
2017-09-26 08:19:46 +00:00
|
|
|
|
printerCfg.ColW0Pct = newCfg.ColW0Pct;
|
|
|
|
|
|
printerCfg.ColW1Pct = newCfg.ColW1Pct;
|
2017-09-21 06:59:08 +00:00
|
|
|
|
printerCfg.ColW2Pct = newCfg.ColW2Pct;
|
|
|
|
|
|
printerCfg.CommonItems1 = newCfg.CommonItems1;
|
|
|
|
|
|
printerCfg.CommonItems2 = newCfg.CommonItems2;
|
|
|
|
|
|
printerCfg.CommonItems3 = newCfg.CommonItems3;
|
|
|
|
|
|
printerCfg.SelectedItems = newCfg.SelectedItems;
|
2017-09-26 08:19:46 +00:00
|
|
|
|
printerCfg.BelowW0Pct = newCfg.BelowW0Pct;
|
|
|
|
|
|
printerCfg.BelowW1Pct = newCfg.BelowW1Pct;
|
|
|
|
|
|
printerCfg.BelowW2Pct = newCfg.BelowW2Pct;
|
|
|
|
|
|
printerCfg.BelowItems1 = newCfg.BelowItems1;
|
|
|
|
|
|
printerCfg.BelowItems2 = newCfg.BelowItems2;
|
|
|
|
|
|
printerCfg.BelowItems3 = newCfg.BelowItems3;
|
|
|
|
|
|
printerCfg.Footer = newCfg.Footer;
|
2017-09-21 06:59:08 +00:00
|
|
|
|
|
2017-09-29 13:21:40 +00:00
|
|
|
|
printerCfg.GoodOnly = newCfg.GoodOnly;
|
|
|
|
|
|
|
2017-09-21 06:59:08 +00:00
|
|
|
|
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;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
thread.CurrentCulture = Thread.CurrentThread.CurrentCulture;
|
|
|
|
|
|
thread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
CultureInfo culture = Thread.CurrentThread.CurrentCulture;
|
|
|
|
|
|
try { culture = new System.Globalization.CultureInfo(printerCfg.Culture.ToString()); }
|
|
|
|
|
|
catch { }
|
|
|
|
|
|
|
|
|
|
|
|
if (batch.WaterMeters.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
ZapiskaPrinterCfg cfg = new ZapiskaPrinterCfg {
|
|
|
|
|
|
PageOrientation = printerCfg.PageOrientation,
|
|
|
|
|
|
TopMargin = printerCfg.TopMargin,
|
|
|
|
|
|
BottomMargin = printerCfg.BottomMargin,
|
|
|
|
|
|
LeftMargin = printerCfg.LeftMargin,
|
|
|
|
|
|
TitFntFml = printerCfg.TitFntFml,
|
|
|
|
|
|
HdrFntFml = printerCfg.HdrFntFml,
|
|
|
|
|
|
BodyFntFml = printerCfg.BodyFntFml,
|
|
|
|
|
|
TitFntSz = printerCfg.TitFntSz,
|
|
|
|
|
|
HdrFntSz = printerCfg.HdrFntSz,
|
|
|
|
|
|
BodyFntSz = printerCfg.BodyFntSz,
|
|
|
|
|
|
TitFntSty = printerCfg.TitFntSty,
|
|
|
|
|
|
HdrFntSty = printerCfg.HdrFntSty,
|
|
|
|
|
|
BodyFntSty = printerCfg.BodyFntSty,
|
|
|
|
|
|
SupressPrinting = printerCfg.SupressPrinting,
|
2017-09-26 08:19:46 +00:00
|
|
|
|
GoodOnly = printerCfg.GoodOnly,
|
|
|
|
|
|
CultureInfo = culture,
|
2017-09-21 06:59:08 +00:00
|
|
|
|
Header = printerCfg.Header,
|
2017-09-28 07:39:58 +00:00
|
|
|
|
ColW0Pct = printerCfg.ColW0Pct,
|
|
|
|
|
|
ColW1Pct = printerCfg.ColW1Pct,
|
2017-09-21 06:59:08 +00:00
|
|
|
|
ColW2Pct = printerCfg.ColW2Pct,
|
|
|
|
|
|
CommonItems1 = printerCfg.CommonItems1,
|
|
|
|
|
|
CommonItems2 = printerCfg.CommonItems2,
|
|
|
|
|
|
CommonItems3 = printerCfg.CommonItems3,
|
2017-09-21 12:04:31 +00:00
|
|
|
|
SelectedItems = printerCfg.SelectedItems,
|
2017-09-28 07:39:58 +00:00
|
|
|
|
BelowW0Pct = printerCfg.BelowW0Pct,
|
|
|
|
|
|
BelowW1Pct = printerCfg.BelowW1Pct,
|
|
|
|
|
|
BelowW2Pct = printerCfg.BelowW2Pct,
|
|
|
|
|
|
BelowItems1 = printerCfg.BelowItems1,
|
|
|
|
|
|
BelowItems2 = printerCfg.BelowItems2,
|
|
|
|
|
|
BelowItems3 = printerCfg.BelowItems3,
|
|
|
|
|
|
Footer = printerCfg.Footer,
|
2017-09-21 06:59:08 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
new Results.Output.Printers.Zapiska.ZapiskaPrintDocument(batch, cfg).Print();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|