2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
2023-03-13 14:31:39 +00:00
|
|
|
|
/// Copyright (c) 2013-2023 Sensus Slovensko a.s.
|
2015-04-15 18:32:56 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
2014-12-31 12:46:33 +00:00
|
|
|
|
using log4net;
|
2023-11-30 16:51:49 +00:00
|
|
|
|
using Common;
|
|
|
|
|
|
using Common.Forms;
|
|
|
|
|
|
using Results.Output.Printers.Munich;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.Threading;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2021-10-26 09:23:57 +00:00
|
|
|
|
namespace TBF.Rig.Output.Printers.Munich
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2014-12-31 12:46:33 +00:00
|
|
|
|
public class Printer : ComponentBase, IOperation, GenericDevices.IResultsPrinter
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2014-12-31 12:46:33 +00:00
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(Printer));
|
2021-04-07 07:57:42 +00:00
|
|
|
|
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2014-12-31 12:46:33 +00:00
|
|
|
|
readonly PrinterCfg printerCfg;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2016-01-06 20:39:52 +00:00
|
|
|
|
public bool SupressPrinting { get { return false; } }
|
|
|
|
|
|
|
2015-12-09 14:55:37 +00:00
|
|
|
|
|
2016-01-06 20:39:52 +00:00
|
|
|
|
/// <summary> Data to print </summary>
|
|
|
|
|
|
Results.Entities.Batch batch;
|
2015-12-09 14:55:37 +00:00
|
|
|
|
|
2023-11-30 16:51:49 +00:00
|
|
|
|
bool printingCompleted = false;
|
|
|
|
|
|
bool statusDlgShown = false;
|
|
|
|
|
|
ModelessForm modelessForm;
|
|
|
|
|
|
|
2016-06-02 10:56:18 +00:00
|
|
|
|
public string Version { get { return printerCfg.Version; } }
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2015-04-19 14:48:46 +00:00
|
|
|
|
|
2021-04-07 07:57:42 +00:00
|
|
|
|
public Printer() { }
|
2015-06-29 09:14:33 +00:00
|
|
|
|
|
2016-08-05 12:32:36 +00:00
|
|
|
|
public Printer(Generic.IComponentCfg cfg)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
: base(cfg)
|
|
|
|
|
|
{
|
2016-08-05 12:32:36 +00:00
|
|
|
|
printerCfg = cfg as PrinterCfg;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-07 07:57:42 +00:00
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
2023-11-30 16:51:49 +00:00
|
|
|
|
if (printerCfg.DebugLevel == DebugMode.Normal)
|
|
|
|
|
|
{
|
|
|
|
|
|
string message;
|
|
|
|
|
|
if (!PrinterStatus.IsOnline(printerCfg.PrinterName, out message)) throw new ApplicationException(message);
|
|
|
|
|
|
log.FatalFormat("{0} initialized: {1}", Name, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
log.FatalFormat("{0} simulated: {1}", Name, this);
|
|
|
|
|
|
}
|
2021-04-07 07:57:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-01-06 20:39:52 +00:00
|
|
|
|
|
2023-11-30 16:51:49 +00:00
|
|
|
|
/// <summary>Events: ResultsPrinted</summary>
|
|
|
|
|
|
/// <param name="benchId">Procedure to print the results of</param>
|
|
|
|
|
|
/// <param name="results">Results to print</param>
|
|
|
|
|
|
/// <returns>Reference to the operation</returns>
|
2020-03-05 12:59:43 +00:00
|
|
|
|
public IOperation ProcessResultsOp(Results.Entities.Batch batch)
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2016-01-06 20:39:52 +00:00
|
|
|
|
this.batch = batch;
|
2014-07-28 07:54:35 +00:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Start this operation</summary>
|
|
|
|
|
|
public void Start()
|
|
|
|
|
|
{
|
2023-11-30 16:51:49 +00:00
|
|
|
|
printingCompleted = false;
|
|
|
|
|
|
statusDlgShown = false;
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2023-11-30 16:51:49 +00:00
|
|
|
|
/// <summary>Run this operation</summary>
|
|
|
|
|
|
/// <returns>Event.ResultsPrinted</returns>
|
|
|
|
|
|
public Event Run()
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
2023-11-30 16:51:49 +00:00
|
|
|
|
string message;
|
|
|
|
|
|
if (printingCompleted || printerCfg.DebugLevel != DebugMode.Normal)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Event.ResultsPrinted;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (PrinterStatus.IsOnline(printerCfg.PrinterName, out message))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (statusDlgShown)
|
|
|
|
|
|
{
|
|
|
|
|
|
statusDlgShown = false;
|
|
|
|
|
|
if (modelessForm != null) modelessForm.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Printer is online => Print results now
|
|
|
|
|
|
foreach (var wm in batch.WaterMeters)
|
|
|
|
|
|
{
|
|
|
|
|
|
var pd = new MunichPrintDocument(printerCfg.Version, wm, printerCfg.PageOrientation);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(printerCfg.PrinterName)) pd.PrinterSettings.PrinterName = printerCfg.PrinterName;
|
|
|
|
|
|
pd.Print();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
printingCompleted = true;
|
|
|
|
|
|
return Event.ResultsPrinted;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!statusDlgShown)
|
|
|
|
|
|
{
|
|
|
|
|
|
statusDlgShown = true;
|
|
|
|
|
|
modelessForm = new ModelessForm(message);
|
|
|
|
|
|
new Thread(() => System.Windows.Forms.Application.Run(modelessForm)).Start();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Event.Busy;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-07-28 07:54:35 +00:00
|
|
|
|
|
2023-11-30 16:51:49 +00:00
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
|
|
|
|
public void Stop()
|
2014-07-28 07:54:35 +00:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|