From 1593dc3070ee734a0338d4ad71788ddd68f0e312 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Tue, 20 Mar 2018 04:49:11 +0100 Subject: [PATCH] ResultsBrowser : Any IResultsPrinter component from TBF can be used to print results, ver. 2.18.851 --- ResultsBrowser/Properties/AssemblyInfo.cs | 4 +- ResultsBrowser/Resources/Strings.resx | 9 +++ ResultsBrowser/Resources/Strings1.Designer.cs | 27 ++++++++ ResultsBrowser/ResultsBrowserWnd.cs | 68 +++++++++++++++++-- 4 files changed, 101 insertions(+), 7 deletions(-) diff --git a/ResultsBrowser/Properties/AssemblyInfo.cs b/ResultsBrowser/Properties/AssemblyInfo.cs index aa566cc29..dfa9130ba 100644 --- a/ResultsBrowser/Properties/AssemblyInfo.cs +++ b/ResultsBrowser/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.18.847.0")] -[assembly: AssemblyFileVersion("2.18.847.0")] +[assembly: AssemblyVersion("2.18.851.0")] +[assembly: AssemblyFileVersion("2.18.851.0")] diff --git a/ResultsBrowser/Resources/Strings.resx b/ResultsBrowser/Resources/Strings.resx index bac76065b..2d2fe1aca 100644 --- a/ResultsBrowser/Resources/Strings.resx +++ b/ResultsBrowser/Resources/Strings.resx @@ -813,4 +813,13 @@ Configure printer + + No printer defined + + + Printing failed + + + Printing completed + \ No newline at end of file diff --git a/ResultsBrowser/Resources/Strings1.Designer.cs b/ResultsBrowser/Resources/Strings1.Designer.cs index ba41b8559..0dd4534df 100644 --- a/ResultsBrowser/Resources/Strings1.Designer.cs +++ b/ResultsBrowser/Resources/Strings1.Designer.cs @@ -1644,6 +1644,15 @@ namespace ResultsBrowser.Resources { } } + /// + /// Looks up a localized string similar to No printer defined. + /// + internal static string No_printer_defined { + get { + return ResourceManager.GetString("No_printer_defined", resourceCulture); + } + } + /// /// Looks up a localized string similar to No program settings found. . /// @@ -1770,6 +1779,24 @@ namespace ResultsBrowser.Resources { } } + /// + /// Looks up a localized string similar to Printing completed. + /// + internal static string Printing_completed { + get { + return ResourceManager.GetString("Printing_completed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Printing failed. + /// + internal static string Printing_failed { + get { + return ResourceManager.GetString("Printing_failed", resourceCulture); + } + } + /// /// Looks up a localized string similar to Procedure. /// diff --git a/ResultsBrowser/ResultsBrowserWnd.cs b/ResultsBrowser/ResultsBrowserWnd.cs index 2a9018c84..63a0193e9 100644 --- a/ResultsBrowser/ResultsBrowserWnd.cs +++ b/ResultsBrowser/ResultsBrowserWnd.cs @@ -6,6 +6,7 @@ using NHibernate; using Results.Entities; using TBF.BenchControl; using TBF.BenchControl.Generic; +using TBF.BenchControl.GenericDevices; using ResultsBrowser.Filters; using ResultsBrowser.Resources; @@ -25,6 +26,9 @@ namespace ResultsBrowser DateTime timePeriodStart; DateTime timePeriodEnd; + static IList tbfComponents; + static IList tbfDevices; + public ResultsBrowserWnd(string[] args) { InitializeComponent(); @@ -33,6 +37,9 @@ namespace ResultsBrowser filtersConfig = new FiltersConfig(); this.args = args; + tbfComponents = new List(); + tbfDevices = new List(); + timePeriodStart = new DateTime(0); timePeriodEnd = new DateTime(0); } @@ -405,12 +412,63 @@ namespace ResultsBrowser "0111-OOP-C035-13").Print(); } #else - foreach (var wm in waterMeters) - { - new Results.Output.Printers.Munich.MunichPrintDocument(string.Format("4/13 - {0}", BenchName()), wm, Config.Entities.PageOrientation.Portrait).Print(); - } + if (string.IsNullOrEmpty(filtersConfig.PrinterClass)) + { + MessageBox.Show(Strings.No_printer_defined); + return; + } + + try + { + Config.Entities.Component cmpnt = new Config.Entities.Component(); + cmpnt.Name = "printer"; + cmpnt.ClassName = filtersConfig.PrinterClass; + cmpnt.Parameters = filtersConfig.PrinterCfg; + + IComponentFactory printerFactory = GetFactory(filtersConfig.PrinterClass); + IComponentCfg printerCfg = printerFactory.CmpntCfgFromCmpntEntity(cmpnt); + IComponent component = printerFactory.GetComponent(printerCfg, tbfComponents); + IResultsPrinter printer = component as IResultsPrinter; + + if (printer== null) + { + MessageBox.Show(Strings.No_printer_defined); + return; + } + + tbfComponents.Clear(); + tbfDevices.Clear(); + tbfComponents.Add(component); + IDevice dev = component as IDevice; + if (dev != null) + { + dev.Initialize(); + tbfDevices.Add(dev); + } + + /// Find batches + IList batches = new List(); + foreach (var wm in waterMeters) + { + if (!batches.Contains(wm.Batch)) batches.Add(wm.Batch); + } + + foreach (var batch in batches) + { + IOperation printOp = printer.PrintResultsOp(batch); + printOp.Start(); + while (printOp.Run() != Event.ResultsPrinted) { } + printOp.Stop(); + } + + MessageBox.Show(Strings.Printing_completed); + } + catch (Exception) + { + MessageBox.Show(Strings.Printing_failed); + } #endif - } + } private void statisticsBtn_Click(object sender, EventArgs e) {