From d3ca871eb59ed2504f6edfc8aa1650bb124f5601 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Sun, 13 Jan 2019 12:30:02 +0100 Subject: [PATCH] Output.Printers.Label.Printer re-implemented using a configurable list of items, ver. 2.18.1109 --- .../Printers/Label/LabelPrintDocument.cs | 98 +++++ .../Output/Printers/Label/LabelPrinterCfg.cs | 21 ++ Results/Properties/AssemblyInfo.cs | 4 +- Results/Results.csproj | 4 + .../Output/Printers/Enhanced/PrinterCfg.cs | 4 +- .../PrinterFactory.cs => Label/Factory.cs} | 4 +- .../PrintLabelDocument.cs | 2 +- .../Output/Printers/Label/Printer.cs | 159 ++++++++ .../{LabelPrinter => Label}/PrinterCfg.cs | 28 +- .../Printers/Label/PrinterCfgCtrl.Designer.cs | 355 ++++++++++++++++++ .../Output/Printers/Label/PrinterCfgCtrl.cs | 233 ++++++++++++ .../PrinterCfgCtrl.resx | 0 .../Output/Printers/LabelPrinter/Printer.cs | 67 ---- .../LabelPrinter/PrinterCfgCtrl.Designer.cs | 193 ---------- .../Printers/LabelPrinter/PrinterCfgCtrl.cs | 123 ------ TBF/BenchControl/TbfComponents.cs | 2 +- TBF/TBF.csproj | 14 +- 17 files changed, 906 insertions(+), 405 deletions(-) create mode 100644 Results/Output/Printers/Label/LabelPrintDocument.cs create mode 100644 Results/Output/Printers/Label/LabelPrinterCfg.cs rename TBF/BenchControl/Output/Printers/{LabelPrinter/PrinterFactory.cs => Label/Factory.cs} (88%) rename TBF/BenchControl/Output/Printers/{LabelPrinter => Label}/PrintLabelDocument.cs (99%) create mode 100644 TBF/BenchControl/Output/Printers/Label/Printer.cs rename TBF/BenchControl/Output/Printers/{LabelPrinter => Label}/PrinterCfg.cs (70%) create mode 100644 TBF/BenchControl/Output/Printers/Label/PrinterCfgCtrl.Designer.cs create mode 100644 TBF/BenchControl/Output/Printers/Label/PrinterCfgCtrl.cs rename TBF/BenchControl/Output/Printers/{LabelPrinter => Label}/PrinterCfgCtrl.resx (100%) delete mode 100644 TBF/BenchControl/Output/Printers/LabelPrinter/Printer.cs delete mode 100644 TBF/BenchControl/Output/Printers/LabelPrinter/PrinterCfgCtrl.Designer.cs delete mode 100644 TBF/BenchControl/Output/Printers/LabelPrinter/PrinterCfgCtrl.cs diff --git a/Results/Output/Printers/Label/LabelPrintDocument.cs b/Results/Output/Printers/Label/LabelPrintDocument.cs new file mode 100644 index 000000000..e18355d19 --- /dev/null +++ b/Results/Output/Printers/Label/LabelPrintDocument.cs @@ -0,0 +1,98 @@ +/// +/// Copyright (c) 2018 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Printing; +using System.IO; +using Config.Entities; +using Results.Resources; + +namespace Results.Output.Printers.Label +{ + public class LabelPrintDocument : PrintersCommon + { + /// Size of the printed area without margins, after taking into account 'pageOrientation' + readonly int printHeight; + readonly int printWidth; + + /// Selected font + readonly Font font; + + /// Data to print + Results.Entities.Batch batch; + LabelPrinterCfg cfg; + Results.Entities.WaterMeter wm; + + /// Items to print + IList itemsToPrint; + + /// + /// Constructor + /// + /// Text to be printed + public LabelPrintDocument(Results.Entities.Batch batch, LabelPrinterCfg cfg, Results.Entities.WaterMeter wm, string documentName) + { + DocumentName = documentName; + + this.batch = batch; + this.cfg = cfg; + this.wm = wm; + this.itemsToPrint = Results.WMeterRsltItemSpec.FromStrArray(cfg.ItemsToPrint); + + /// Initialize fonts + font = new Font((cfg.FontFamily != null ? cfg.FontFamily : "Arial"), + (cfg.FontSize > 0 ? cfg.FontSize : 10), + (FontStyle)cfg.FontStyle); + + /// Set print area size and margins (in dots using 100 dpi) + DefaultPageSettings.Landscape = (cfg.PageOrientation == PageOrientation.Landscape); + /// + printHeight = cfg.PaperHeight; + printWidth = cfg.PaperWidth; + } + + /// + /// Override the default onbeginPrint method of the PrintDocument Object + /// + /// + /// + protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e) + { + base.OnBeginPrint(e); + } + + /// + /// Override the default OnPrintPage method of the PrintDocument. + /// + /// + /// This provides the print logic for our document + protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e) + { + /// Run base code + base.OnPrintPage(e); + + if (!string.IsNullOrEmpty(cfg.Template)) + { + string templatePath = Path.Combine("C:\\TBF\\Templates\\", cfg.Template); + if (File.Exists(templatePath)) + { + e.Graphics.DrawImage(new Bitmap(Image.FromFile(templatePath), printWidth, printHeight), new Rectangle(0, 0, printWidth, printHeight)); + } + } + + foreach (var item in itemsToPrint) + { + string[] coords = item.Caption.Split(new char[] { ';' }); + int x, y; + if (coords.Length >= 2 && int.TryParse(coords[0].Trim(new char[] { ' ' }), out x) + && int.TryParse(coords[1].Trim(new char[] { ' ' }), out y)) + { + RectangleF printArea = new RectangleF(x, y, printWidth, printHeight); + e.Graphics.DrawString(item.Print(wm), this.font, Brushes.Black, printArea); + } + } + } + } +} diff --git a/Results/Output/Printers/Label/LabelPrinterCfg.cs b/Results/Output/Printers/Label/LabelPrinterCfg.cs new file mode 100644 index 000000000..90490cd4b --- /dev/null +++ b/Results/Output/Printers/Label/LabelPrinterCfg.cs @@ -0,0 +1,21 @@ +/// +/// Copyright (c) 2018 Sensus Slovensko a.s. +/// + +namespace Results.Output.Printers.Label +{ + public class LabelPrinterCfg + { + public string Template; /// Full path to a 'png' file + public Config.Entities.PageOrientation PageOrientation; + public int PaperWidth; /// In 0,254 mm = 1/100 in = 100dpi pixels count + public int PaperHeight; /// In 0,254 mm = 1/100 in = 100dpi pixels count + public string[] ItemsToPrint; + public string FontFamily; + public int FontSize; + public int FontStyle; + public System.Globalization.CultureInfo CultureInfo; + public bool GoodOnly; + public bool SupressPrinting; /// true = Bypass printing + } +} diff --git a/Results/Properties/AssemblyInfo.cs b/Results/Properties/AssemblyInfo.cs index 7e37c9209..2fd976ff5 100644 --- a/Results/Properties/AssemblyInfo.cs +++ b/Results/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.1093.0")] -[assembly: AssemblyFileVersion("2.18.1093.0")] +[assembly: AssemblyVersion("2.18.1109.0")] +[assembly: AssemblyFileVersion("2.18.1109.0")] diff --git a/Results/Results.csproj b/Results/Results.csproj index 3d41cba26..d2e6be048 100644 --- a/Results/Results.csproj +++ b/Results/Results.csproj @@ -104,6 +104,10 @@ Component + + Component + + Component diff --git a/TBF/BenchControl/Output/Printers/Enhanced/PrinterCfg.cs b/TBF/BenchControl/Output/Printers/Enhanced/PrinterCfg.cs index b4919c48d..962d2e57e 100644 --- a/TBF/BenchControl/Output/Printers/Enhanced/PrinterCfg.cs +++ b/TBF/BenchControl/Output/Printers/Enhanced/PrinterCfg.cs @@ -32,8 +32,8 @@ namespace TBF.BenchControl.Output.Printers.Enhanced public int FooterFntSz; public int TitFntSty; public int HdrFntSty; - public int BodyFntSty; - public int FooterFntSty; + public int BodyFntSty; + public int FooterFntSty; public bool GoodOnly; public bool SupressPrinting; /// Bypass printing when true public Culture Culture; diff --git a/TBF/BenchControl/Output/Printers/LabelPrinter/PrinterFactory.cs b/TBF/BenchControl/Output/Printers/Label/Factory.cs similarity index 88% rename from TBF/BenchControl/Output/Printers/LabelPrinter/PrinterFactory.cs rename to TBF/BenchControl/Output/Printers/Label/Factory.cs index 980f6cd1f..9fcc71832 100644 --- a/TBF/BenchControl/Output/Printers/LabelPrinter/PrinterFactory.cs +++ b/TBF/BenchControl/Output/Printers/Label/Factory.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; using TBF.BenchControl.Generic; -namespace TBF.BenchControl.Output.Printers.LabelPrinter +namespace TBF.BenchControl.Output.Printers.Label { - public class PrinterFactory : IComponentFactory + public class Factory : IComponentFactory { public string ClassName { get { return this.GetType().Namespace.Substring(17); } } diff --git a/TBF/BenchControl/Output/Printers/LabelPrinter/PrintLabelDocument.cs b/TBF/BenchControl/Output/Printers/Label/PrintLabelDocument.cs similarity index 99% rename from TBF/BenchControl/Output/Printers/LabelPrinter/PrintLabelDocument.cs rename to TBF/BenchControl/Output/Printers/Label/PrintLabelDocument.cs index 20b90015d..94d064133 100644 --- a/TBF/BenchControl/Output/Printers/LabelPrinter/PrintLabelDocument.cs +++ b/TBF/BenchControl/Output/Printers/Label/PrintLabelDocument.cs @@ -9,7 +9,7 @@ using System.IO; using Config.Entities; using TBF.Resources; -namespace TBF.BenchControl.Output.Printers.LabelPrinter +namespace TBF.BenchControl.Output.Printers.Label { public class PrintLabelDocument : PrintDocument { diff --git a/TBF/BenchControl/Output/Printers/Label/Printer.cs b/TBF/BenchControl/Output/Printers/Label/Printer.cs new file mode 100644 index 000000000..b56fed008 --- /dev/null +++ b/TBF/BenchControl/Output/Printers/Label/Printer.cs @@ -0,0 +1,159 @@ +/// +/// Copyright (c) 2015-2018 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using log4net; +using System.Globalization; +using System.Threading; +using Results.Output.Printers.Label; + +namespace TBF.BenchControl.Output.Printers.Label +{ + 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; } } + + /// Data to print + Results.Entities.Batch batch; + + /// + /// Items to print + /// + IList commonItems; + + + public Printer() { } + + public Printer(Generic.IComponentCfg cfg) + : base(cfg) + { + printerCfg = cfg as PrinterCfg; + ApplyConfig(); + log.Debug(this.ToString()); + } + + void ApplyConfig() + { + commonItems = Results.WMeterRsltItemSpec.FromStrArray(printerCfg.ItemsToPrint); + } + + + #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 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.Template = newCfg.Template; + printerCfg.PageOrientation = newCfg.PageOrientation; + printerCfg.PaperWidth = newCfg.PaperWidth; + printerCfg.PaperHeight = newCfg.PaperHeight; + printerCfg.ItemsToPrint = newCfg.ItemsToPrint; + printerCfg.FontFamily = newCfg.FontFamily; + printerCfg.FontSize = newCfg.FontSize; + printerCfg.FontStyle = newCfg.FontStyle; + printerCfg.Culture = newCfg.Culture; + printerCfg.NrOfCopies = newCfg.NrOfCopies; + printerCfg.GoodOnly = newCfg.GoodOnly; + printerCfg.SupressPrinting = newCfg.SupressPrinting; + + ApplyConfig(); + } + } + }; + } + + #endregion Configuration Change Handling + + + /// + /// Prints the test cycle results, Events: Event.ResultsPrinted + /// + /// Batch results to print + /// Reference to the operation + public IOperation PrintResultsOp(Results.Entities.Batch batch) + { + this.batch = batch; + return this; + } + + /// Start this operation + public void Start() + { + CultureInfo oriCulture = Thread.CurrentThread.CurrentCulture; + + if (printerCfg.Culture != Culture.system) + { + Thread.CurrentThread.CurrentCulture = new CultureInfo(printerCfg.Culture.ToString()); + } + + foreach (var wm in batch.WaterMeters) + { + if (wm != null && (!printerCfg.GoodOnly || wm.Passed)) + { + PrintResults(batch, wm, string.Format("{0}-{1}", batch.BatchNr, wm.WMPosition)); + } + } + + Thread.CurrentThread.CurrentCulture = oriCulture; + } + + /// Run this operation + /// Event.ResultsPrinted + public Event Run() + { + return Event.ResultsPrinted; + } + + /// Stop this operation + public void Stop() + { + } + + + + void PrintResults(Results.Entities.Batch batch, Results.Entities.WaterMeter wm, string documentName) + { + LabelPrinterCfg cfg = new LabelPrinterCfg + { + Template = printerCfg.Template, + PageOrientation = printerCfg.PageOrientation, + PaperWidth = printerCfg.PaperWidth, + PaperHeight = printerCfg.PaperHeight, + ItemsToPrint = printerCfg.ItemsToPrint, + FontFamily = printerCfg.FontFamily, + FontSize = printerCfg.FontSize, + FontStyle = printerCfg.FontStyle, + CultureInfo = (printerCfg.Culture == Culture.system) ? Thread.CurrentThread.CurrentCulture : new CultureInfo(printerCfg.Culture.ToString()), + GoodOnly = printerCfg.GoodOnly, + SupressPrinting = printerCfg.SupressPrinting, + }; + + for (int i = 1; i <= printerCfg.NrOfCopies; i++) + { + string docNameEx = string.Format(((printerCfg.NrOfCopies == 1) ? "{0}" : "{0}_{1}"), documentName, i); + new Results.Output.Printers.Label.LabelPrintDocument(batch, cfg, wm, docNameEx).Print(); + } + } + } +} diff --git a/TBF/BenchControl/Output/Printers/LabelPrinter/PrinterCfg.cs b/TBF/BenchControl/Output/Printers/Label/PrinterCfg.cs similarity index 70% rename from TBF/BenchControl/Output/Printers/LabelPrinter/PrinterCfg.cs rename to TBF/BenchControl/Output/Printers/Label/PrinterCfg.cs index 148acfb83..ec64399ad 100644 --- a/TBF/BenchControl/Output/Printers/LabelPrinter/PrinterCfg.cs +++ b/TBF/BenchControl/Output/Printers/Label/PrinterCfg.cs @@ -8,7 +8,7 @@ using System.Xml.Serialization; using Config.Entities; using TBF.BenchControl.Generic; -namespace TBF.BenchControl.Output.Printers.LabelPrinter +namespace TBF.BenchControl.Output.Printers.Label { public class PrinterCfg : ComponentCfgBase, Generic.IComponentCfg { @@ -20,10 +20,17 @@ namespace TBF.BenchControl.Output.Printers.LabelPrinter /// /// Serialized parameters /// + public string Template; /// Full path to a 'png' file public PageOrientation PageOrientation; public int PaperWidth; /// In 0,254 mm = 1/100 in = 100dpi pixels count public int PaperHeight; /// In 0,254 mm = 1/100 in = 100dpi pixels count - public string TemplateFile; /// Full path to a 'png' file + public string[] ItemsToPrint; + public string FontFamily; + public int FontSize; + public int FontStyle; + public Culture Culture; + public int NrOfCopies; + public bool GoodOnly; public bool SupressPrinting; /// true = Bypass printing /// Private parameterless constructor invoked by all other (public) constructors @@ -37,21 +44,28 @@ namespace TBF.BenchControl.Output.Printers.LabelPrinter this.Name = name; this.Factory = factory; ParentName = string.Empty; - PageOrientation = PageOrientation.Portrait; + + Template = string.Empty; + PageOrientation = PageOrientation.Portrait; PaperWidth = 827; /// A4 width PaperHeight = 1169; /// A4 height - TemplateFile = "C:\\TBF\\Templates\\Label.png"; - SupressPrinting = false; + FontFamily = "Arial"; + FontSize = 10; + FontStyle = 0; + NrOfCopies = 1; + GoodOnly = false; + SupressPrinting = false; } public string ToString(int i) { - return string.Format("Name={0}, Orientation={1}, PaperWidth={2}, PaperHeight={3}, TemplateFile={4}, SupressPrinting={5}", + return string.Format("Name={0}, Orientation={1}, PaperWidth={2}, PaperHeight={3}, TemplateFile={4}, GoodOnly={5}, SupressPrinting={6}", Name, PageOrientation, PaperWidth, PaperHeight, - TemplateFile, + Template, + GoodOnly ? "yes" : "no", SupressPrinting ? "yes" : "no" ); } diff --git a/TBF/BenchControl/Output/Printers/Label/PrinterCfgCtrl.Designer.cs b/TBF/BenchControl/Output/Printers/Label/PrinterCfgCtrl.Designer.cs new file mode 100644 index 000000000..0be840a9b --- /dev/null +++ b/TBF/BenchControl/Output/Printers/Label/PrinterCfgCtrl.Designer.cs @@ -0,0 +1,355 @@ +/// +/// Copyright (c) 2015 Sensus Metering Systems +/// +namespace TBF.BenchControl.Output.Printers.Label +{ + partial class PrinterCfgCtrl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.nameTextBox = new System.Windows.Forms.TextBox(); + this.nameLabel = new System.Windows.Forms.Label(); + this.classNameLabel = new System.Windows.Forms.Label(); + this.supressPrintingCheckBox = new System.Windows.Forms.CheckBox(); + this.orientationLabel = new System.Windows.Forms.Label(); + this.orientationComboBox = new System.Windows.Forms.ComboBox(); + this.templateTextBox = new System.Windows.Forms.TextBox(); + this.templateLabel = new System.Windows.Forms.Label(); + this.paperWidthTextBox = new System.Windows.Forms.TextBox(); + this.paperWidthLabel = new System.Windows.Forms.Label(); + this.paperHeightTextBox = new System.Windows.Forms.TextBox(); + this.paperHeightLabel = new System.Windows.Forms.Label(); + this.italicCheckBox = new System.Windows.Forms.CheckBox(); + this.boldCheckBox = new System.Windows.Forms.CheckBox(); + this.fontSizeTextBox = new System.Windows.Forms.TextBox(); + this.fontFamilyComboBox = new System.Windows.Forms.ComboBox(); + this.bodyFontLabel = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.itemsToPrintButton = new System.Windows.Forms.Button(); + this.nrOfCopiesLabel = new System.Windows.Forms.Label(); + this.nrOfCopiesTextBox = new System.Windows.Forms.TextBox(); + this.cultureComboBox = new System.Windows.Forms.ComboBox(); + this.cultureLabel = new System.Windows.Forms.Label(); + this.goodOnlyCheckBox = new System.Windows.Forms.CheckBox(); + this.SuspendLayout(); + // + // nameTextBox + // + this.nameTextBox.Enabled = false; + this.nameTextBox.Location = new System.Drawing.Point(122, 35); + this.nameTextBox.Name = "nameTextBox"; + this.nameTextBox.Size = new System.Drawing.Size(130, 20); + this.nameTextBox.TabIndex = 2; + // + // nameLabel + // + this.nameLabel.AutoSize = true; + this.nameLabel.Location = new System.Drawing.Point(8, 38); + this.nameLabel.Name = "nameLabel"; + this.nameLabel.Size = new System.Drawing.Size(35, 13); + this.nameLabel.TabIndex = 1; + this.nameLabel.Text = "Name"; + // + // classNameLabel + // + this.classNameLabel.AutoSize = true; + this.classNameLabel.Location = new System.Drawing.Point(119, 11); + this.classNameLabel.Name = "classNameLabel"; + this.classNameLabel.Size = new System.Drawing.Size(61, 13); + this.classNameLabel.TabIndex = 0; + this.classNameLabel.Text = "Class name"; + // + // supressPrintingCheckBox + // + this.supressPrintingCheckBox.AutoSize = true; + this.supressPrintingCheckBox.Enabled = false; + this.supressPrintingCheckBox.Location = new System.Drawing.Point(122, 283); + this.supressPrintingCheckBox.Name = "supressPrintingCheckBox"; + this.supressPrintingCheckBox.Size = new System.Drawing.Size(101, 17); + this.supressPrintingCheckBox.TabIndex = 11; + this.supressPrintingCheckBox.Text = "Supress printing"; + this.supressPrintingCheckBox.UseVisualStyleBackColor = true; + // + // orientationLabel + // + this.orientationLabel.AutoSize = true; + this.orientationLabel.Location = new System.Drawing.Point(8, 84); + this.orientationLabel.Name = "orientationLabel"; + this.orientationLabel.Size = new System.Drawing.Size(84, 13); + this.orientationLabel.TabIndex = 3; + this.orientationLabel.Text = "Page orientation"; + // + // orientationComboBox + // + this.orientationComboBox.Enabled = false; + this.orientationComboBox.FormattingEnabled = true; + this.orientationComboBox.Location = new System.Drawing.Point(122, 81); + this.orientationComboBox.Name = "orientationComboBox"; + this.orientationComboBox.Size = new System.Drawing.Size(130, 21); + this.orientationComboBox.TabIndex = 4; + // + // templateTextBox + // + this.templateTextBox.Enabled = false; + this.templateTextBox.Location = new System.Drawing.Point(122, 58); + this.templateTextBox.Name = "templateTextBox"; + this.templateTextBox.Size = new System.Drawing.Size(228, 20); + this.templateTextBox.TabIndex = 10; + // + // templateLabel + // + this.templateLabel.AutoSize = true; + this.templateLabel.Location = new System.Drawing.Point(8, 61); + this.templateLabel.Name = "templateLabel"; + this.templateLabel.Size = new System.Drawing.Size(67, 13); + this.templateLabel.TabIndex = 9; + this.templateLabel.Text = "Template file"; + // + // paperWidthTextBox + // + this.paperWidthTextBox.Enabled = false; + this.paperWidthTextBox.Location = new System.Drawing.Point(122, 105); + this.paperWidthTextBox.Name = "paperWidthTextBox"; + this.paperWidthTextBox.Size = new System.Drawing.Size(51, 20); + this.paperWidthTextBox.TabIndex = 6; + // + // paperWidthLabel + // + this.paperWidthLabel.AutoSize = true; + this.paperWidthLabel.Location = new System.Drawing.Point(8, 108); + this.paperWidthLabel.Name = "paperWidthLabel"; + this.paperWidthLabel.Size = new System.Drawing.Size(63, 13); + this.paperWidthLabel.TabIndex = 5; + this.paperWidthLabel.Text = "Paper width"; + // + // paperHeightTextBox + // + this.paperHeightTextBox.Enabled = false; + this.paperHeightTextBox.Location = new System.Drawing.Point(122, 128); + this.paperHeightTextBox.Name = "paperHeightTextBox"; + this.paperHeightTextBox.Size = new System.Drawing.Size(51, 20); + this.paperHeightTextBox.TabIndex = 8; + // + // paperHeightLabel + // + this.paperHeightLabel.AutoSize = true; + this.paperHeightLabel.Location = new System.Drawing.Point(8, 131); + this.paperHeightLabel.Name = "paperHeightLabel"; + this.paperHeightLabel.Size = new System.Drawing.Size(67, 13); + this.paperHeightLabel.TabIndex = 7; + this.paperHeightLabel.Text = "Paper height"; + // + // bodyItalicCheckBox + // + this.italicCheckBox.AutoSize = true; + this.italicCheckBox.Enabled = false; + this.italicCheckBox.Location = new System.Drawing.Point(335, 190); + this.italicCheckBox.Name = "bodyItalicCheckBox"; + this.italicCheckBox.Size = new System.Drawing.Size(15, 14); + this.italicCheckBox.TabIndex = 47; + this.italicCheckBox.UseVisualStyleBackColor = true; + // + // bodyBoldCheckBox + // + this.boldCheckBox.AutoSize = true; + this.boldCheckBox.Enabled = false; + this.boldCheckBox.Location = new System.Drawing.Point(307, 190); + this.boldCheckBox.Name = "bodyBoldCheckBox"; + this.boldCheckBox.Size = new System.Drawing.Size(15, 14); + this.boldCheckBox.TabIndex = 46; + this.boldCheckBox.UseVisualStyleBackColor = true; + // + // bodyFontSizeTextBox + // + this.fontSizeTextBox.Enabled = false; + this.fontSizeTextBox.Location = new System.Drawing.Point(259, 184); + this.fontSizeTextBox.Name = "bodyFontSizeTextBox"; + this.fontSizeTextBox.Size = new System.Drawing.Size(29, 20); + this.fontSizeTextBox.TabIndex = 45; + // + // bodyFontFamilyComboBox + // + this.fontFamilyComboBox.Enabled = false; + this.fontFamilyComboBox.FormattingEnabled = true; + this.fontFamilyComboBox.Location = new System.Drawing.Point(122, 184); + this.fontFamilyComboBox.Name = "bodyFontFamilyComboBox"; + this.fontFamilyComboBox.Size = new System.Drawing.Size(130, 21); + this.fontFamilyComboBox.TabIndex = 44; + // + // bodyFontLabel + // + this.bodyFontLabel.AutoSize = true; + this.bodyFontLabel.Location = new System.Drawing.Point(8, 187); + this.bodyFontLabel.Name = "bodyFontLabel"; + this.bodyFontLabel.Size = new System.Drawing.Size(106, 13); + this.bodyFontLabel.TabIndex = 43; + this.bodyFontLabel.Text = "Font family/size/style"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.label2.Location = new System.Drawing.Point(331, 175); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(24, 13); + this.label2.TabIndex = 49; + this.label2.Text = "Ital."; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.label1.Location = new System.Drawing.Point(297, 175); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(32, 13); + this.label1.TabIndex = 48; + this.label1.Text = "Bold"; + // + // itemsToPrintButton + // + this.itemsToPrintButton.Enabled = false; + this.itemsToPrintButton.Location = new System.Drawing.Point(121, 154); + this.itemsToPrintButton.Name = "itemsToPrintButton"; + this.itemsToPrintButton.Size = new System.Drawing.Size(132, 23); + this.itemsToPrintButton.TabIndex = 50; + this.itemsToPrintButton.Text = "Items to print"; + this.itemsToPrintButton.UseVisualStyleBackColor = true; + this.itemsToPrintButton.Click += new System.EventHandler(this.itemsToPrintButton_Click); + // + // nrOfCopiesLabel + // + this.nrOfCopiesLabel.AutoSize = true; + this.nrOfCopiesLabel.Location = new System.Drawing.Point(8, 235); + this.nrOfCopiesLabel.Name = "nrOfCopiesLabel"; + this.nrOfCopiesLabel.Size = new System.Drawing.Size(90, 13); + this.nrOfCopiesLabel.TabIndex = 52; + this.nrOfCopiesLabel.Text = "Number of copies"; + // + // nrOfCopiesTextBox + // + this.nrOfCopiesTextBox.Enabled = false; + this.nrOfCopiesTextBox.Location = new System.Drawing.Point(122, 232); + this.nrOfCopiesTextBox.Name = "nrOfCopiesTextBox"; + this.nrOfCopiesTextBox.Size = new System.Drawing.Size(51, 20); + this.nrOfCopiesTextBox.TabIndex = 51; + // + // cultureComboBox + // + this.cultureComboBox.Enabled = false; + this.cultureComboBox.FormattingEnabled = true; + this.cultureComboBox.Location = new System.Drawing.Point(122, 208); + this.cultureComboBox.Name = "cultureComboBox"; + this.cultureComboBox.Size = new System.Drawing.Size(218, 21); + this.cultureComboBox.TabIndex = 54; + // + // cultureLabel + // + this.cultureLabel.AutoSize = true; + this.cultureLabel.Location = new System.Drawing.Point(8, 211); + this.cultureLabel.Name = "cultureLabel"; + this.cultureLabel.Size = new System.Drawing.Size(42, 13); + this.cultureLabel.TabIndex = 53; + this.cultureLabel.Text = "Cullture"; + // + // goodOnlyCheckBox + // + this.goodOnlyCheckBox.AutoSize = true; + this.goodOnlyCheckBox.Enabled = false; + this.goodOnlyCheckBox.Location = new System.Drawing.Point(122, 262); + this.goodOnlyCheckBox.Name = "goodOnlyCheckBox"; + this.goodOnlyCheckBox.Size = new System.Drawing.Size(74, 17); + this.goodOnlyCheckBox.TabIndex = 55; + this.goodOnlyCheckBox.Text = "Good only"; + this.goodOnlyCheckBox.UseVisualStyleBackColor = true; + // + // PrinterCfgCtrl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.goodOnlyCheckBox); + this.Controls.Add(this.cultureComboBox); + this.Controls.Add(this.cultureLabel); + this.Controls.Add(this.nrOfCopiesLabel); + this.Controls.Add(this.nrOfCopiesTextBox); + this.Controls.Add(this.itemsToPrintButton); + this.Controls.Add(this.italicCheckBox); + this.Controls.Add(this.boldCheckBox); + this.Controls.Add(this.fontSizeTextBox); + this.Controls.Add(this.fontFamilyComboBox); + this.Controls.Add(this.bodyFontLabel); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.paperHeightTextBox); + this.Controls.Add(this.paperHeightLabel); + this.Controls.Add(this.paperWidthTextBox); + this.Controls.Add(this.paperWidthLabel); + this.Controls.Add(this.templateTextBox); + this.Controls.Add(this.templateLabel); + this.Controls.Add(this.orientationComboBox); + this.Controls.Add(this.orientationLabel); + this.Controls.Add(this.supressPrintingCheckBox); + this.Controls.Add(this.nameTextBox); + this.Controls.Add(this.nameLabel); + this.Controls.Add(this.classNameLabel); + this.Name = "PrinterCfgCtrl"; + this.Size = new System.Drawing.Size(372, 327); + this.Load += new System.EventHandler(this.PrinterCfgCtrl_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox nameTextBox; + private System.Windows.Forms.Label nameLabel; + private System.Windows.Forms.Label classNameLabel; + private System.Windows.Forms.CheckBox supressPrintingCheckBox; + private System.Windows.Forms.Label orientationLabel; + private System.Windows.Forms.ComboBox orientationComboBox; + private System.Windows.Forms.TextBox templateTextBox; + private System.Windows.Forms.Label templateLabel; + private System.Windows.Forms.TextBox paperWidthTextBox; + private System.Windows.Forms.Label paperWidthLabel; + private System.Windows.Forms.TextBox paperHeightTextBox; + private System.Windows.Forms.Label paperHeightLabel; + private System.Windows.Forms.CheckBox italicCheckBox; + private System.Windows.Forms.CheckBox boldCheckBox; + private System.Windows.Forms.TextBox fontSizeTextBox; + private System.Windows.Forms.ComboBox fontFamilyComboBox; + private System.Windows.Forms.Label bodyFontLabel; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button itemsToPrintButton; + private System.Windows.Forms.Label nrOfCopiesLabel; + private System.Windows.Forms.TextBox nrOfCopiesTextBox; + private System.Windows.Forms.ComboBox cultureComboBox; + private System.Windows.Forms.Label cultureLabel; + private System.Windows.Forms.CheckBox goodOnlyCheckBox; + } +} diff --git a/TBF/BenchControl/Output/Printers/Label/PrinterCfgCtrl.cs b/TBF/BenchControl/Output/Printers/Label/PrinterCfgCtrl.cs new file mode 100644 index 000000000..b1e9f5a5b --- /dev/null +++ b/TBF/BenchControl/Output/Printers/Label/PrinterCfgCtrl.cs @@ -0,0 +1,233 @@ +/// +/// Copyright (c) 2015-2018 Sensus Slovensko a.s. +/// +using System; +using System.IO; +using System.Windows.Forms; +using log4net; +using Config.Entities; +using TBF.BenchControl.Generic; +using TBF.BenchControl.Configs; + +namespace TBF.BenchControl.Output.Printers.Label +{ + public partial class PrinterCfgCtrl : ConfigCtrlUtils, IComponentCfgCtrl + { + static readonly ILog log = LogManager.GetLogger(typeof(PrinterCfgCtrl)); + + public bool ShowMore { get { return false; } } + + PrinterCfg config; + public IComponentCfg Config + { + get { return config as IComponentCfg; } + set + { + config = value as PrinterCfg; + Redraw(); + } + } + + string[] itemsToPrint; + + public PrinterCfgCtrl() + { + InitializeComponent(); + Localize(); + + orientationComboBox.Items.Add(PageOrientation.Portrait.ToString()); + orientationComboBox.Items.Add(PageOrientation.Landscape.ToString()); + + foreach (var ff in System.Drawing.FontFamily.Families) + { + fontFamilyComboBox.Items.Add(ff.Name); + } + } + + private void PrinterCfgCtrl_Load(object sender, EventArgs e) + { + for (Culture s = 0; s < Culture.Count; s++) cultureComboBox.Items.Add(s.ToString()); + + itemsToPrint = config.ItemsToPrint; + + Redraw(); + } + + void Localize() + { + } + + public void Closing() + { + } + + void Redraw() + { + if (config == null) return; /// Control was not loaded, settings were not changed + classNameLabel.Text = config.Factory.ClassName; + nameTextBox.Text = config.Name; + templateTextBox.Text = config.Template; + orientationComboBox.Text = config.PageOrientation.ToString(); + paperWidthTextBox.Text = config.PaperWidth.ToString(); + paperHeightTextBox.Text = config.PaperHeight.ToString(); + + fontFamilyComboBox.Text = config.FontFamily; + fontSizeTextBox.Text = config.FontSize.ToString(); + boldCheckBox.Checked = ((config.FontStyle & (int)System.Drawing.FontStyle.Bold) != 0); + italicCheckBox.Checked = ((config.FontStyle & (int)System.Drawing.FontStyle.Italic) != 0); + + cultureComboBox.Text = config.Culture.ToString(); + nrOfCopiesTextBox.Text = config.NrOfCopies.ToString(); + goodOnlyCheckBox.Checked = config.GoodOnly; + supressPrintingCheckBox.Checked = config.SupressPrinting; + } + + public void Unlock() + { + nameTextBox.Enabled = true; + templateTextBox.Enabled = true; + orientationComboBox.Enabled = true; + paperWidthTextBox.Enabled = true; + paperHeightTextBox.Enabled = true; + itemsToPrintButton.Enabled = true; + fontFamilyComboBox.Enabled = true; + fontSizeTextBox.Enabled = true; + boldCheckBox.Enabled = true; + italicCheckBox.Enabled = true; + cultureComboBox.Enabled = true; + nrOfCopiesTextBox.Enabled = true; + goodOnlyCheckBox.Enabled = true; + supressPrintingCheckBox.Enabled = true; + } + + public CfgUpdateFlags VerifyCfg(ref string message) + { + CfgUpdateFlags flags = CfgUpdateFlags.None; + + if (!File.Exists(Path.Combine("C:\\TBF\\Templates", templateTextBox.Text))) + { + message += Environment.NewLine + "Template file missing"; + flags |= CfgUpdateFlags.Error; + } + + if ((int)GetOrientation(orientationComboBox.Text) < 0) + { + message += Environment.NewLine + "Invalid page orientation"; + flags |= CfgUpdateFlags.Error; + } + + int dummy; + if (!int.TryParse(paperWidthTextBox.Text, out dummy) || dummy <= 0) + { + message += Environment.NewLine + "Invalid paper width"; + flags |= CfgUpdateFlags.Error; + } + if (!int.TryParse(paperHeightTextBox.Text, out dummy) || dummy <= 0) + { + message += Environment.NewLine + "Invalid paper height"; + flags |= CfgUpdateFlags.Error; + } + if (!int.TryParse(fontSizeTextBox.Text, out dummy) || dummy < 6 || dummy > 48) + { + message += Environment.NewLine + "Font size' should be between 6 and 48"; + flags |= CfgUpdateFlags.Error; + } + if (!cultureComboBox.Items.Contains(cultureComboBox.Text)) + { + message += Environment.NewLine + "Invalid culture"; + flags |= CfgUpdateFlags.Error; + } + if (!int.TryParse(nrOfCopiesTextBox.Text, out dummy) || dummy < 0 || dummy > 9) + { + message += Environment.NewLine + "'Number of copies' should be between 0 and 9"; + flags |= CfgUpdateFlags.Error; + } + + return flags; + } + + public CfgUpdateFlags UpdateCfg() + { + CfgUpdateFlags flags = CfgUpdateFlags.None; + + if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed + + + if (config.Name != nameTextBox.Text) + { + config.Name = nameTextBox.Text; + flags |= (CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange); + } + + flags |= UpdateDifferent(ref config.Template, templateTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange); + + if (config.PageOrientation != GetOrientation(orientationComboBox.Text)) + { + config.PageOrientation = GetOrientation(orientationComboBox.Text); + flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange); + } + + flags |= UpdateDifferent(ref config.PaperWidth, paperWidthTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange); + flags |= UpdateDifferent(ref config.PaperHeight, paperHeightTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange); + + flags |= UpdateDifferent(ref config.ItemsToPrint, itemsToPrint, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange); + + /// Body font properties + flags |= UpdateDifferent(ref config.FontFamily, fontFamilyComboBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange); + flags |= UpdateDifferent(ref config.FontSize, int.Parse(fontSizeTextBox.Text), CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange); + int tmp = (boldCheckBox.Checked ? (int)System.Drawing.FontStyle.Bold : 0) + + (italicCheckBox.Checked ? (int)System.Drawing.FontStyle.Italic : 0); + flags |= UpdateDifferent(ref config.FontStyle, tmp, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange); + + for (Culture i = 0; i < Culture.Count; i++) + { + if (i.ToString().Equals(cultureComboBox.Text) && (config.Culture != i)) + { + config.Culture = i; + flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange); + break; + } + } + + flags |= UpdateDifferent(ref config.NrOfCopies, nrOfCopiesTextBox.Text, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange); + flags |= UpdateDifferent(ref config.GoodOnly, goodOnlyCheckBox.Checked, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange); + flags |= UpdateDifferent(ref config.SupressPrinting, supressPrintingCheckBox.Checked, CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange); + + if ((flags & CfgUpdateFlags.InvokeCfgChange) != 0) + { + Printer.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.CfgChange, config)); + } + + return flags; + } + + private void itemsToPrintButton_Click(object sender, EventArgs e) + { + Results.Forms.ResultsConfigDlg dlg = new Results.Forms.ResultsConfigDlg() + { + SelectedItems = Results.WMeterRsltItemSpec.FromStrArray(itemsToPrint), + }; + + if (dlg.ShowDialog() == DialogResult.OK) + { + itemsToPrint = Results.WMeterRsltItemSpec.ToStrArray(dlg.SelectedItems); + } + } + + #region Configuration Change Handling + + public static void OnCmdResponse(object sender, CmdResponseArgs args) + { + if (CmdResponseHandler == null) return; + try { CmdResponseHandler(sender, args); } + catch (Exception e) { log.Error("CmdResponseHandler(...) failed", e); } + } + + public static event EventHandler CmdResponseHandler; + + public void StartResponseHandler() { } + public void StopResponseHandler() { } + + #endregion Configuration Change Handling + } +} diff --git a/TBF/BenchControl/Output/Printers/LabelPrinter/PrinterCfgCtrl.resx b/TBF/BenchControl/Output/Printers/Label/PrinterCfgCtrl.resx similarity index 100% rename from TBF/BenchControl/Output/Printers/LabelPrinter/PrinterCfgCtrl.resx rename to TBF/BenchControl/Output/Printers/Label/PrinterCfgCtrl.resx diff --git a/TBF/BenchControl/Output/Printers/LabelPrinter/Printer.cs b/TBF/BenchControl/Output/Printers/LabelPrinter/Printer.cs deleted file mode 100644 index b37ffcfda..000000000 --- a/TBF/BenchControl/Output/Printers/LabelPrinter/Printer.cs +++ /dev/null @@ -1,67 +0,0 @@ -/// -/// Copyright (c) 2015-2016 Sensus Metering Systems -/// -using log4net; - -namespace TBF.BenchControl.Output.Printers.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; } } - - /// Data to print - Results.Entities.Batch batch; - - - public Printer() { } - - - public Printer(Generic.IComponentCfg cfg) - : base(cfg) - { - printerCfg = cfg as PrinterCfg; - log.Debug(this.ToString()); - } - - /// - /// Prints the test cycle results, Events: Event.ResultsPrinted - /// - /// Batch results to print - /// Reference to the operation - public IOperation PrintResultsOp(Results.Entities.Batch batch) - { - this.batch = batch; - return this; - } - - /// Start this operation - public void Start() - { - if (batch.WaterMeters.Count > 0) - { - new PrintLabelDocument(batch, - printerCfg.PageOrientation, - printerCfg.PaperWidth, - printerCfg.PaperHeight, - printerCfg.TemplateFile).Print(); - } - } - - /// Run this operation - /// Event.ResultsPrinted - public Event Run() - { - return Event.ResultsPrinted; - } - - /// Stop this operation - public void Stop() - { - } - } -} diff --git a/TBF/BenchControl/Output/Printers/LabelPrinter/PrinterCfgCtrl.Designer.cs b/TBF/BenchControl/Output/Printers/LabelPrinter/PrinterCfgCtrl.Designer.cs deleted file mode 100644 index 3f1a0c6a3..000000000 --- a/TBF/BenchControl/Output/Printers/LabelPrinter/PrinterCfgCtrl.Designer.cs +++ /dev/null @@ -1,193 +0,0 @@ -/// -/// Copyright (c) 2015 Sensus Metering Systems -/// -namespace TBF.BenchControl.Output.Printers.LabelPrinter -{ - partial class PrinterCfgCtrl - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Component Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.nameTextBox = new System.Windows.Forms.TextBox(); - this.nameLabel = new System.Windows.Forms.Label(); - this.classNameLabel = new System.Windows.Forms.Label(); - this.supressPrintingCheckBox = new System.Windows.Forms.CheckBox(); - this.orientationLabel = new System.Windows.Forms.Label(); - this.orientationComboBox = new System.Windows.Forms.ComboBox(); - this.templateTextBox = new System.Windows.Forms.TextBox(); - this.templateLabel = new System.Windows.Forms.Label(); - this.paperWidthTextBox = new System.Windows.Forms.TextBox(); - this.paperWidthLabel = new System.Windows.Forms.Label(); - this.paperHeightTextBox = new System.Windows.Forms.TextBox(); - this.paperHeightLabel = new System.Windows.Forms.Label(); - this.SuspendLayout(); - // - // nameTextBox - // - this.nameTextBox.Enabled = false; - this.nameTextBox.Location = new System.Drawing.Point(98, 30); - this.nameTextBox.Name = "nameTextBox"; - this.nameTextBox.Size = new System.Drawing.Size(130, 20); - this.nameTextBox.TabIndex = 2; - // - // nameLabel - // - this.nameLabel.AutoSize = true; - this.nameLabel.Location = new System.Drawing.Point(8, 33); - this.nameLabel.Name = "nameLabel"; - this.nameLabel.Size = new System.Drawing.Size(35, 13); - this.nameLabel.TabIndex = 1; - this.nameLabel.Text = "Name"; - // - // classNameLabel - // - this.classNameLabel.AutoSize = true; - this.classNameLabel.Location = new System.Drawing.Point(95, 6); - this.classNameLabel.Name = "classNameLabel"; - this.classNameLabel.Size = new System.Drawing.Size(83, 13); - this.classNameLabel.TabIndex = 0; - this.classNameLabel.Text = "ComonentName"; - // - // supressPrintingCheckBox - // - this.supressPrintingCheckBox.AutoSize = true; - this.supressPrintingCheckBox.Enabled = false; - this.supressPrintingCheckBox.Location = new System.Drawing.Point(98, 164); - this.supressPrintingCheckBox.Name = "supressPrintingCheckBox"; - this.supressPrintingCheckBox.Size = new System.Drawing.Size(101, 17); - this.supressPrintingCheckBox.TabIndex = 11; - this.supressPrintingCheckBox.Text = "Supress printing"; - this.supressPrintingCheckBox.UseVisualStyleBackColor = true; - // - // orientationLabel - // - this.orientationLabel.AutoSize = true; - this.orientationLabel.Location = new System.Drawing.Point(8, 59); - this.orientationLabel.Name = "orientationLabel"; - this.orientationLabel.Size = new System.Drawing.Size(84, 13); - this.orientationLabel.TabIndex = 3; - this.orientationLabel.Text = "Page orientation"; - // - // orientationComboBox - // - this.orientationComboBox.Enabled = false; - this.orientationComboBox.FormattingEnabled = true; - this.orientationComboBox.Location = new System.Drawing.Point(98, 56); - this.orientationComboBox.Name = "orientationComboBox"; - this.orientationComboBox.Size = new System.Drawing.Size(130, 21); - this.orientationComboBox.TabIndex = 4; - // - // templateTextBox - // - this.templateTextBox.Enabled = false; - this.templateTextBox.Location = new System.Drawing.Point(98, 135); - this.templateTextBox.Name = "templateTextBox"; - this.templateTextBox.Size = new System.Drawing.Size(187, 20); - this.templateTextBox.TabIndex = 10; - // - // templateLabel - // - this.templateLabel.AutoSize = true; - this.templateLabel.Location = new System.Drawing.Point(8, 138); - this.templateLabel.Name = "templateLabel"; - this.templateLabel.Size = new System.Drawing.Size(67, 13); - this.templateLabel.TabIndex = 9; - this.templateLabel.Text = "Template file"; - // - // paperWidthTextBox - // - this.paperWidthTextBox.Enabled = false; - this.paperWidthTextBox.Location = new System.Drawing.Point(98, 83); - this.paperWidthTextBox.Name = "paperWidthTextBox"; - this.paperWidthTextBox.Size = new System.Drawing.Size(51, 20); - this.paperWidthTextBox.TabIndex = 6; - // - // paperWidthLabel - // - this.paperWidthLabel.AutoSize = true; - this.paperWidthLabel.Location = new System.Drawing.Point(8, 86); - this.paperWidthLabel.Name = "paperWidthLabel"; - this.paperWidthLabel.Size = new System.Drawing.Size(63, 13); - this.paperWidthLabel.TabIndex = 5; - this.paperWidthLabel.Text = "Paper width"; - // - // paperHeightTextBox - // - this.paperHeightTextBox.Enabled = false; - this.paperHeightTextBox.Location = new System.Drawing.Point(98, 109); - this.paperHeightTextBox.Name = "paperHeightTextBox"; - this.paperHeightTextBox.Size = new System.Drawing.Size(51, 20); - this.paperHeightTextBox.TabIndex = 8; - // - // paperHeightLabel - // - this.paperHeightLabel.AutoSize = true; - this.paperHeightLabel.Location = new System.Drawing.Point(8, 112); - this.paperHeightLabel.Name = "paperHeightLabel"; - this.paperHeightLabel.Size = new System.Drawing.Size(67, 13); - this.paperHeightLabel.TabIndex = 7; - this.paperHeightLabel.Text = "Paper height"; - // - // PrinterCfgCtrl - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.paperHeightTextBox); - this.Controls.Add(this.paperHeightLabel); - this.Controls.Add(this.paperWidthTextBox); - this.Controls.Add(this.paperWidthLabel); - this.Controls.Add(this.templateTextBox); - this.Controls.Add(this.templateLabel); - this.Controls.Add(this.orientationComboBox); - this.Controls.Add(this.orientationLabel); - this.Controls.Add(this.supressPrintingCheckBox); - this.Controls.Add(this.nameTextBox); - this.Controls.Add(this.nameLabel); - this.Controls.Add(this.classNameLabel); - this.Name = "PrinterCfgCtrl"; - this.Size = new System.Drawing.Size(300, 200); - this.Load += new System.EventHandler(this.PrinterCfgCtrl_Load); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.TextBox nameTextBox; - private System.Windows.Forms.Label nameLabel; - private System.Windows.Forms.Label classNameLabel; - private System.Windows.Forms.CheckBox supressPrintingCheckBox; - private System.Windows.Forms.Label orientationLabel; - private System.Windows.Forms.ComboBox orientationComboBox; - private System.Windows.Forms.TextBox templateTextBox; - private System.Windows.Forms.Label templateLabel; - private System.Windows.Forms.TextBox paperWidthTextBox; - private System.Windows.Forms.Label paperWidthLabel; - private System.Windows.Forms.TextBox paperHeightTextBox; - private System.Windows.Forms.Label paperHeightLabel; - } -} diff --git a/TBF/BenchControl/Output/Printers/LabelPrinter/PrinterCfgCtrl.cs b/TBF/BenchControl/Output/Printers/LabelPrinter/PrinterCfgCtrl.cs deleted file mode 100644 index b8471c5b5..000000000 --- a/TBF/BenchControl/Output/Printers/LabelPrinter/PrinterCfgCtrl.cs +++ /dev/null @@ -1,123 +0,0 @@ -/// -/// Copyright (c) 2015 Sensus Metering Systems -/// -using System; -using System.IO; -using System.Windows.Forms; -using log4net; -using Config.Entities; -using TBF.BenchControl.Generic; - -namespace TBF.BenchControl.Output.Printers.LabelPrinter -{ - public partial class PrinterCfgCtrl : UserControl, IComponentCfgCtrl - { - static readonly ILog log = LogManager.GetLogger(typeof(PrinterCfgCtrl)); - - public bool ShowMore { get { return false; } } - - PrinterCfg config; - public IComponentCfg Config - { - get { return config as IComponentCfg; } - set - { - config = value as PrinterCfg; - Redraw(); - } - } - - public PrinterCfgCtrl() - { - InitializeComponent(); - - orientationComboBox.Items.Add(PageOrientation.Portrait.ToString()); - orientationComboBox.Items.Add(PageOrientation.Landscape.ToString()); - } - - private void PrinterCfgCtrl_Load(object sender, EventArgs e) - { - Redraw(); - } - - public void Closing() - { - } - - PageOrientation GetOrientation(string str) - { - if (str.Equals(PageOrientation.Landscape.ToString())) return PageOrientation.Landscape; - if (str.Equals(PageOrientation.Portrait.ToString())) return PageOrientation.Portrait; - return (PageOrientation)(-1); - } - - void Redraw() - { - if (config == null) return; /// Control was not loaded, settings were not changed - classNameLabel.Text = config.Factory.ClassName; - nameTextBox.Text = config.Name; - orientationComboBox.Text = config.PageOrientation.ToString(); - paperWidthTextBox.Text = config.PaperWidth.ToString(); - paperHeightTextBox.Text = config.PaperHeight.ToString(); - templateTextBox.Text = config.TemplateFile; - supressPrintingCheckBox.Checked = config.SupressPrinting; - } - - public void Unlock() - { - nameTextBox.Enabled = true; - orientationComboBox.Enabled = true; - paperWidthTextBox.Enabled = true; - paperHeightTextBox.Enabled = true; - templateTextBox.Enabled = true; - supressPrintingCheckBox.Enabled = true; - } - - public CfgUpdateFlags VerifyCfg(ref string message) - { - CfgUpdateFlags flags = CfgUpdateFlags.None; - - if ((int)GetOrientation(orientationComboBox.Text) < 0) - { - message += Environment.NewLine + "Invalid page orientation"; - flags |= CfgUpdateFlags.Error; - } - - int dummy; - if (!int.TryParse(paperWidthTextBox.Text, out dummy) || dummy <= 0) - { - message += Environment.NewLine + "Invalid paper width"; - flags |= CfgUpdateFlags.Error; - } - if (!int.TryParse(paperHeightTextBox.Text, out dummy) || dummy <= 0) - { - message += Environment.NewLine + "Invalid paper height"; - flags |= CfgUpdateFlags.Error; - } - - if (!File.Exists(config.TemplateFile)) - { - message += Environment.NewLine + "Template file missing"; - flags |= CfgUpdateFlags.Error; - } - - return flags; - } - - public CfgUpdateFlags UpdateCfg() - { - CfgUpdateFlags flags = CfgUpdateFlags.RestartRqrd; - - if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed - - config.Name = nameTextBox.Text; - config.PageOrientation = GetOrientation(orientationComboBox.Text); - config.PaperWidth = int.Parse(paperWidthTextBox.Text); - config.PaperHeight = int.Parse(paperHeightTextBox.Text); - config.TemplateFile = templateTextBox.Text; - config.SupressPrinting = supressPrintingCheckBox.Checked; - - return flags; - } - } -} diff --git a/TBF/BenchControl/TbfComponents.cs b/TBF/BenchControl/TbfComponents.cs index a30cefddc..f7ac5eaf8 100644 --- a/TBF/BenchControl/TbfComponents.cs +++ b/TBF/BenchControl/TbfComponents.cs @@ -133,7 +133,7 @@ namespace TBF.BenchControl Factories.Add(new Output.Printers.Enhanced.FactorySingle()); Factories.Add(new Output.Printers.Enhanced.FactoryCompound()); Factories.Add(new Output.Printers.Enhanced.FactoryHeatMeters()); - Factories.Add(new Output.Printers.LabelPrinter.PrinterFactory()); /// LabelPrinter + Factories.Add(new Output.Printers.Label.Factory()); /// Label printer Factories.Add(new Output.Printers.Munich.PrinterFactory()); Factories.Add(new Output.Printers.OnePerMeter.FactorySingle()); Factories.Add(new Output.Printers.OnePerMeter.FactoryCompound()); diff --git a/TBF/TBF.csproj b/TBF/TBF.csproj index 856f603b3..4a875b8cb 100644 --- a/TBF/TBF.csproj +++ b/TBF/TBF.csproj @@ -865,16 +865,16 @@ PrinterCfgCtrl.cs - - - + + + UserControl - + PrinterCfgCtrl.cs - - + + Component @@ -2549,7 +2549,7 @@ PrinterCfgCtrl.cs - + PrinterCfgCtrl.cs