From 5c48dbf60e7e78f0d769424f2cc7abb53bf94de1 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Wed, 24 Feb 2016 22:55:40 +0100 Subject: [PATCH] Basic results printer modified as well. --- .../Basic/BasicPrintDocument.cs | 71 +++++++++---------- .../ResultsPrinters/Basic/Printer.cs | 4 +- .../ResultsPrinters/Basic/PrinterCfg.cs | 10 ++- .../Basic/PrinterCfgCtrl.Designer.cs | 68 +++++++++++++++--- .../ResultsPrinters/Basic/PrinterCfgCtrl.cs | 20 +++++- 5 files changed, 118 insertions(+), 55 deletions(-) diff --git a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/BasicPrintDocument.cs b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/BasicPrintDocument.cs index 57911daf0..cc9d2ed8c 100644 --- a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/BasicPrintDocument.cs +++ b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/BasicPrintDocument.cs @@ -17,11 +17,19 @@ namespace TBF.BenchControl.ResultsPrinters.Basic const int SpacingOne = 18; const int SpacingOneAndHalf = (3 * SpacingOne) / 2; - const int TitleX = 100; + + readonly int topMargin; + readonly int bottomMargin; + readonly int leftMargin; + readonly int TitleX; readonly int TitleY; /// Depends on the size of the header readonly int HdrTop; /// = TitleY + 60 readonly int BodyTop; /// = HdrTop + 160 + /// Size of the printed area without margins, after taking into account 'pageOrientation' + int printHeight; + int printWidth; + /// /// Property variable for the Font the user wishes to use /// @@ -55,13 +63,18 @@ namespace TBF.BenchControl.ResultsPrinters.Basic /// Text to be printed public BasicPrintDocument(Results.Entities.Batch batch, PageOrientation pageOrientation, - int topMrgn) + int topMargin, int bottomMargin, int leftMargin) { this.batch = batch; DefaultPageSettings.Landscape = (pageOrientation == PageOrientation.Landscape); - TitleY = topMrgn; /// Depends on the size of the header + this.topMargin = topMargin; + this.bottomMargin = bottomMargin; + this.leftMargin = leftMargin; + + TitleX = leftMargin; + TitleY = topMargin; /// Depends on the size of the header HdrTop = TitleY + 60; BodyTop = HdrTop + 160; @@ -74,19 +87,16 @@ namespace TBF.BenchControl.ResultsPrinters.Basic rsltItems = Results.ItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Printer_SingleWM); } - /// Set print area size and margins (in dots using 80 dpi) - int printHeight = base.DefaultPageSettings.PaperSize.Height - base.DefaultPageSettings.Margins.Top - base.DefaultPageSettings.Margins.Bottom; - int printWidth = base.DefaultPageSettings.PaperSize.Width - base.DefaultPageSettings.Margins.Left - base.DefaultPageSettings.Margins.Right; - int leftMargin = base.DefaultPageSettings.Margins.Left; /// X - int topMargin = base.DefaultPageSettings.Margins.Top; /// Y - - /// Check if the user selected to print in Landscape mode - /// if they did then we need to swap height/width parameters + /// Set print area size and margins (in dots using 100 dpi) if (DefaultPageSettings.Landscape) { - int tmp = printHeight; - printHeight = printWidth; - printWidth = tmp; + printHeight = base.DefaultPageSettings.PaperSize.Width - topMargin - bottomMargin; + printWidth = base.DefaultPageSettings.PaperSize.Height - leftMargin - leftMargin; + } + else + { + printHeight = base.DefaultPageSettings.PaperSize.Height - topMargin - bottomMargin; + printWidth = base.DefaultPageSettings.PaperSize.Width - leftMargin - leftMargin; } int testsCount = batch.WaterMeters[0].MeterTestRslts.Count; @@ -133,24 +143,6 @@ namespace TBF.BenchControl.ResultsPrinters.Basic e.Graphics.DrawImage(new Bitmap(img), new Rectangle(0, 0, 827, 1169)); } - /// Set print area size and margins (in dots using 80 dpi) - int printHeight = base.DefaultPageSettings.PaperSize.Height - base.DefaultPageSettings.Margins.Top - base.DefaultPageSettings.Margins.Bottom; - int printWidth = base.DefaultPageSettings.PaperSize.Width - base.DefaultPageSettings.Margins.Left - base.DefaultPageSettings.Margins.Right; - int leftMargin = base.DefaultPageSettings.Margins.Left; /// X - int topMargin = base.DefaultPageSettings.Margins.Top; /// Y - - /// Check if the user selected to print in Landscape mode - /// if they did then we need to swap height/width parameters - if (base.DefaultPageSettings.Landscape) - { - int tmp = printHeight; - printHeight = printWidth; - printWidth = tmp; - } - - int x = leftMargin; - int y = topMargin; - /// Use the StringFormat class for the text layout of our document StringFormat format = new StringFormat(StringFormatFlags.LineLimit); @@ -159,7 +151,7 @@ namespace TBF.BenchControl.ResultsPrinters.Basic ///---------- /// Header ///---------- - RectangleF printArea = new RectangleF(TitleX, TitleY, 667, 40); + RectangleF printArea = new RectangleF(TitleX, TitleY, printWidth, 40); e.Graphics.DrawString(batch.ProtocolTitle, titleFont, Brushes.Black, printArea); string[] leftColumn = new string[] @@ -196,7 +188,7 @@ namespace TBF.BenchControl.ResultsPrinters.Basic /// Write aligned columns for (int i = 0; i < Math.Min(leftColumn.Length, rightColumn.Length); i++) { - PrintAt(e, 100, HdrTop + SpacingOne * i, leftColumn[i]); + PrintAt(e, leftMargin, HdrTop + SpacingOne * i, leftColumn[i]); PrintAt(e, 300, HdrTop + SpacingOne * i, rightColumn[i]); } } @@ -222,7 +214,10 @@ namespace TBF.BenchControl.ResultsPrinters.Basic ///---------- /// Footer ///---------- - PrintAt(e, leftMargin, topMargin + printHeight - SpacingOne, string.Format("{0} {1}/{2}", Strings.Page, pageNr++, nrPages)); + string footerText = string.Format("str. {1}/{2}", Strings.Page, pageNr++, nrPages); + int footerWidth = (int)e.Graphics.MeasureString(footerText, font).Width; + PrintAt(e, leftMargin + (printWidth - footerWidth) / 2, topMargin + printHeight - SpacingOne, footerText); + } @@ -238,7 +233,7 @@ namespace TBF.BenchControl.ResultsPrinters.Basic { /// Determin column widths float[] columnPos = new float[rsltItems.Count + 1]; - columnPos[0] = 100.0f; + columnPos[0] = (float)leftMargin; for (int i = 0; i < rsltItems.Count; i++) { @@ -275,10 +270,10 @@ namespace TBF.BenchControl.ResultsPrinters.Basic int tableRightX = (int)columnPos[rsltItems.Count] - 20; string wmText = string.Format("Water meter {0}", printedWMNr); - PrintAt(e, 100, top, wmText); + PrintAt(e, leftMargin, top, wmText); if (!string.IsNullOrEmpty(wm.SerialNr)) { - PrintAt(e, 100 + (int)e.Graphics.MeasureString(wmText, font).Width, top, + PrintAt(e, leftMargin + (int)e.Graphics.MeasureString(wmText, font).Width, top, string.Format(" s/n = {0}", wm.SerialNr)); } diff --git a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/Printer.cs b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/Printer.cs index 740b67475..a2584de2d 100644 --- a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/Printer.cs +++ b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/Printer.cs @@ -46,9 +46,7 @@ namespace TBF.BenchControl.ResultsPrinters.Basic { if (batch.WaterMeters.Count > 0) { - new BasicPrintDocument(batch, - printerCfg.PageOrientation, - printerCfg.TopMargin).Print(); + new BasicPrintDocument(batch, printerCfg.PageOrientation, printerCfg.TopMargin, printerCfg.BottomMargin, printerCfg.LeftMargin).Print(); } } diff --git a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterCfg.cs b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterCfg.cs index 43e848e66..65c204b65 100644 --- a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterCfg.cs +++ b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterCfg.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2015 Sensus Metering Systems +/// Copyright (c) 2013-2016 Sensus Metering Systems /// using System; using System.Collections.Generic; @@ -20,6 +20,8 @@ namespace TBF.BenchControl.ResultsPrinters.Basic /// public PageOrientation PageOrientation; public int TopMargin; + public int BottomMargin; + public int LeftMargin; public bool SupressPrinting; /// Bypass printing when true /// Private parameterless constructor invoked by all other (public) constructors @@ -29,6 +31,8 @@ namespace TBF.BenchControl.ResultsPrinters.Basic ParentName = string.Empty; PageOrientation = PageOrientation.Portrait; TopMargin = 100; + BottomMargin = 100; + LeftMargin = 100; SupressPrinting = false; } @@ -40,10 +44,12 @@ namespace TBF.BenchControl.ResultsPrinters.Basic public string ToString(int i) { - return string.Format("Name={0}, Orientation={1}, TopMargin={2}, SupressPrinting={3}", + return string.Format("Name={0}, Orientation={1}, Margins T={2} B={3} L={4}, SupressPrinting={5}", Name, PageOrientation, TopMargin, + BottomMargin, + LeftMargin, SupressPrinting ? "yes" : "no" ); } diff --git a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterCfgCtrl.Designer.cs b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterCfgCtrl.Designer.cs index f7a65c9d5..70b822bbe 100644 --- a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterCfgCtrl.Designer.cs +++ b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterCfgCtrl.Designer.cs @@ -39,12 +39,16 @@ namespace TBF.BenchControl.ResultsPrinters.Basic this.orientationComboBox = new System.Windows.Forms.ComboBox(); this.topMarginTextBox = new System.Windows.Forms.TextBox(); this.topMarginLabel = new System.Windows.Forms.Label(); + this.leftMarginTextBox = new System.Windows.Forms.TextBox(); + this.leftMarginLabel = new System.Windows.Forms.Label(); + this.bottomMarginTextBox = new System.Windows.Forms.TextBox(); + this.bottomMarginLabel = new System.Windows.Forms.Label(); this.SuspendLayout(); // // nameTextBox // this.nameTextBox.Enabled = false; - this.nameTextBox.Location = new System.Drawing.Point(142, 57); + this.nameTextBox.Location = new System.Drawing.Point(142, 40); this.nameTextBox.Name = "nameTextBox"; this.nameTextBox.Size = new System.Drawing.Size(130, 20); this.nameTextBox.TabIndex = 2; @@ -52,7 +56,7 @@ namespace TBF.BenchControl.ResultsPrinters.Basic // nameLabel // this.nameLabel.AutoSize = true; - this.nameLabel.Location = new System.Drawing.Point(24, 60); + this.nameLabel.Location = new System.Drawing.Point(16, 43); this.nameLabel.Name = "nameLabel"; this.nameLabel.Size = new System.Drawing.Size(35, 13); this.nameLabel.TabIndex = 1; @@ -61,7 +65,7 @@ namespace TBF.BenchControl.ResultsPrinters.Basic // classNameLabel // this.classNameLabel.AutoSize = true; - this.classNameLabel.Location = new System.Drawing.Point(139, 33); + this.classNameLabel.Location = new System.Drawing.Point(139, 16); this.classNameLabel.Name = "classNameLabel"; this.classNameLabel.Size = new System.Drawing.Size(83, 13); this.classNameLabel.TabIndex = 0; @@ -71,17 +75,17 @@ namespace TBF.BenchControl.ResultsPrinters.Basic // this.supressPrintingCheckBox.AutoSize = true; this.supressPrintingCheckBox.Enabled = false; - this.supressPrintingCheckBox.Location = new System.Drawing.Point(142, 144); + this.supressPrintingCheckBox.Location = new System.Drawing.Point(142, 167); this.supressPrintingCheckBox.Name = "supressPrintingCheckBox"; this.supressPrintingCheckBox.Size = new System.Drawing.Size(101, 17); - this.supressPrintingCheckBox.TabIndex = 7; + 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(24, 86); + this.orientationLabel.Location = new System.Drawing.Point(16, 67); this.orientationLabel.Name = "orientationLabel"; this.orientationLabel.Size = new System.Drawing.Size(84, 13); this.orientationLabel.TabIndex = 3; @@ -91,7 +95,7 @@ namespace TBF.BenchControl.ResultsPrinters.Basic // this.orientationComboBox.Enabled = false; this.orientationComboBox.FormattingEnabled = true; - this.orientationComboBox.Location = new System.Drawing.Point(142, 83); + this.orientationComboBox.Location = new System.Drawing.Point(142, 64); this.orientationComboBox.Name = "orientationComboBox"; this.orientationComboBox.Size = new System.Drawing.Size(130, 21); this.orientationComboBox.TabIndex = 4; @@ -99,24 +103,62 @@ namespace TBF.BenchControl.ResultsPrinters.Basic // topMarginTextBox // this.topMarginTextBox.Enabled = false; - this.topMarginTextBox.Location = new System.Drawing.Point(142, 110); + this.topMarginTextBox.Location = new System.Drawing.Point(142, 89); this.topMarginTextBox.Name = "topMarginTextBox"; - this.topMarginTextBox.Size = new System.Drawing.Size(130, 20); + this.topMarginTextBox.Size = new System.Drawing.Size(80, 20); this.topMarginTextBox.TabIndex = 6; // // topMarginLabel // this.topMarginLabel.AutoSize = true; - this.topMarginLabel.Location = new System.Drawing.Point(24, 113); + this.topMarginLabel.Location = new System.Drawing.Point(16, 92); this.topMarginLabel.Name = "topMarginLabel"; this.topMarginLabel.Size = new System.Drawing.Size(109, 13); this.topMarginLabel.TabIndex = 5; - this.topMarginLabel.Text = "Top margin [1/100 in]"; + this.topMarginLabel.Text = "Top margin [0.25 mm]"; + // + // leftMarginTextBox + // + this.leftMarginTextBox.Enabled = false; + this.leftMarginTextBox.Location = new System.Drawing.Point(142, 137); + this.leftMarginTextBox.Name = "leftMarginTextBox"; + this.leftMarginTextBox.Size = new System.Drawing.Size(80, 20); + this.leftMarginTextBox.TabIndex = 10; + // + // leftMarginLabel + // + this.leftMarginLabel.AutoSize = true; + this.leftMarginLabel.Location = new System.Drawing.Point(16, 140); + this.leftMarginLabel.Name = "leftMarginLabel"; + this.leftMarginLabel.Size = new System.Drawing.Size(108, 13); + this.leftMarginLabel.TabIndex = 9; + this.leftMarginLabel.Text = "Left margin [0.25 mm]"; + // + // bottomMarginTextBox + // + this.bottomMarginTextBox.Enabled = false; + this.bottomMarginTextBox.Location = new System.Drawing.Point(142, 113); + this.bottomMarginTextBox.Name = "bottomMarginTextBox"; + this.bottomMarginTextBox.Size = new System.Drawing.Size(80, 20); + this.bottomMarginTextBox.TabIndex = 8; + // + // bottomMarginLabel + // + this.bottomMarginLabel.AutoSize = true; + this.bottomMarginLabel.Location = new System.Drawing.Point(16, 116); + this.bottomMarginLabel.Name = "bottomMarginLabel"; + this.bottomMarginLabel.Size = new System.Drawing.Size(123, 13); + this.bottomMarginLabel.TabIndex = 7; + this.bottomMarginLabel.Text = "Bottom margin [0.25 mm]"; // // PrinterCfgCtrl // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.bottomMarginTextBox); + this.Controls.Add(this.bottomMarginLabel); + this.Controls.Add(this.leftMarginTextBox); + this.Controls.Add(this.leftMarginLabel); this.Controls.Add(this.topMarginTextBox); this.Controls.Add(this.topMarginLabel); this.Controls.Add(this.orientationComboBox); @@ -143,5 +185,9 @@ namespace TBF.BenchControl.ResultsPrinters.Basic private System.Windows.Forms.ComboBox orientationComboBox; private System.Windows.Forms.TextBox topMarginTextBox; private System.Windows.Forms.Label topMarginLabel; + private System.Windows.Forms.TextBox leftMarginTextBox; + private System.Windows.Forms.Label leftMarginLabel; + private System.Windows.Forms.TextBox bottomMarginTextBox; + private System.Windows.Forms.Label bottomMarginLabel; } } diff --git a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterCfgCtrl.cs b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterCfgCtrl.cs index 2cd3e22fe..859292eca 100644 --- a/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterCfgCtrl.cs +++ b/TestBenchFramework/BenchControl/ResultsPrinters/Basic/PrinterCfgCtrl.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2013-2015 Sensus Metering Systems +/// Copyright (c) 2013-2016 Sensus Metering Systems /// using System; using System.Windows.Forms; @@ -57,6 +57,8 @@ namespace TBF.BenchControl.ResultsPrinters.Basic nameTextBox.Text = config.Name; orientationComboBox.Text = config.PageOrientation.ToString(); topMarginTextBox.Text = config.TopMargin.ToString(); + bottomMarginTextBox.Text = config.BottomMargin.ToString(); + leftMarginTextBox.Text = config.LeftMargin.ToString(); supressPrintingCheckBox.Checked = config.SupressPrinting; } @@ -65,6 +67,8 @@ namespace TBF.BenchControl.ResultsPrinters.Basic nameTextBox.Enabled = true; orientationComboBox.Enabled = true; topMarginTextBox.Enabled = true; + bottomMarginTextBox.Enabled = true; + leftMarginTextBox.Enabled = true; supressPrintingCheckBox.Enabled = true; } @@ -85,6 +89,18 @@ namespace TBF.BenchControl.ResultsPrinters.Basic flags |= CfgUpdateFlags.Error; } + if (!int.TryParse(bottomMarginTextBox.Text, out dummy) || dummy < 0 || dummy > 200) + { + message += Environment.NewLine + "'Bottom margin' should be between 0 and 200"; + flags |= CfgUpdateFlags.Error; + } + + if (!int.TryParse(leftMarginTextBox.Text, out dummy) || dummy < 0 || dummy > 200) + { + message += Environment.NewLine + "Left margin' should be between 0 and 200"; + flags |= CfgUpdateFlags.Error; + } + return flags; } @@ -97,6 +113,8 @@ namespace TBF.BenchControl.ResultsPrinters.Basic config.Name = nameTextBox.Text; config.PageOrientation = GetOrientation(orientationComboBox.Text); config.TopMargin = int.Parse(topMarginTextBox.Text); + config.BottomMargin = int.Parse(bottomMarginTextBox.Text); + config.LeftMargin = int.Parse(leftMarginTextBox.Text); config.SupressPrinting = supressPrintingCheckBox.Checked; return flags;