diff --git a/Results/Output/Printers/Enhanced/EnhancedPrintDocument.cs b/Results/Output/Printers/Enhanced/EnhancedPrintDocument.cs index d2f3c30f5..722295e37 100644 --- a/Results/Output/Printers/Enhanced/EnhancedPrintDocument.cs +++ b/Results/Output/Printers/Enhanced/EnhancedPrintDocument.cs @@ -13,31 +13,32 @@ namespace Results.Output.Printers.Enhanced { public class EnhancedPrintDocument : PrintDocument { - const string FontFamilyName = "Arial"; //"Times New Roman"; - - const int SpacingOne = 18; - const int SpacingOneAndHalf = (3 * SpacingOne) / 2; + /// Size of the printed area without margins, after taking into account 'pageOrientation' + readonly int printHeight; + readonly int printWidth; readonly int topMargin; readonly int bottomMargin; readonly int leftMargin; readonly int TitleX; readonly int TitleY; /// Depends on the size of the header - readonly int CommonTop; /// = TitleY + 60 - readonly int BodyTop; /// = HdrTop + 160 + + readonly int SpacingOne; + readonly int SpacingOneAndHalf; + readonly int SpacingOne4Header; + readonly int SpacingOneAndHalf4Header; + + int CommonTop; /// = TitleY + 60 + int BodyTop; /// = HdrTop + 160 /// int titleHeight; int commonHeight; - /// 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 /// Font font; - Font boldFont; + Font headerFont; Font titleFont; /// @@ -45,6 +46,8 @@ namespace Results.Output.Printers.Enhanced /// Results.Entities.Batch batch; + EnhancedPrinterCfg cfg; + /// /// Items to print /// @@ -67,40 +70,28 @@ namespace Results.Output.Printers.Enhanced /// Constructor /// /// Text to be printed - public EnhancedPrintDocument(Results.Entities.Batch batch, - PageOrientation pageOrientation, - int topMargin, - int bottomMargin, - int leftMargin, - string header, - IList commonItems, - IList testItems, - string footer) + public EnhancedPrintDocument(Results.Entities.Batch batch, EnhancedPrinterCfg cfg) { this.batch = batch; - this.topMargin = topMargin; - this.bottomMargin = bottomMargin; - this.leftMargin = leftMargin; + this.cfg = cfg; + topMargin = cfg.TopMargin; + bottomMargin = cfg.BottomMargin; + leftMargin = cfg.LeftMargin; - this.header = header; - this.commonItems = commonItems; - this.testItems = testItems; - this.footer = footer; + header = string.IsNullOrEmpty(cfg.Header) ? string.Empty : cfg.Header.Replace("~", Environment.NewLine); + commonItems = Results.WMeterRsltItemSpec.FromStrArray(cfg.CommonItems); + testItems = Results.WMeterRsltItemSpec.FromStrArray(cfg.TestItems); /// TestID info will be overwritten later on + footer = string.IsNullOrEmpty(cfg.Footer) ? string.Empty : cfg.Footer.Replace("~", Environment.NewLine); - TitleX = leftMargin; - TitleY = topMargin; /// Depends on the size of the header - /// - int headerLinesCount = (header.Contains(Environment.NewLine)) ? 2 : 1; - titleHeight = headerLinesCount * 30 + 20; - CommonTop = TitleY + titleHeight; - - commonHeight = commonItems.Count * 20 + 20; - BodyTop = CommonTop + commonHeight; - - DefaultPageSettings.Landscape = (pageOrientation == PageOrientation.Landscape); + /// Initialize fonts + titleFont = new Font(cfg.TitFntFml, cfg.TitFntSz, (FontStyle)cfg.TitFntSty); + headerFont = new Font(cfg.HdrFntFml, cfg.HdrFntSz, (FontStyle)cfg.HdrFntSty); + font = new Font(cfg.BodyFntFml, cfg.BodyFntSz, (FontStyle)cfg.BodyFntSty); /// Set print area size and margins (in dots using 100 dpi) + DefaultPageSettings.Landscape = (cfg.PageOrientation == PageOrientation.Landscape); + /// if (DefaultPageSettings.Landscape) { printHeight = base.DefaultPageSettings.PaperSize.Width - topMargin - bottomMargin; @@ -112,22 +103,36 @@ namespace Results.Output.Printers.Enhanced printWidth = base.DefaultPageSettings.PaperSize.Width - leftMargin - leftMargin; } + SpacingOne = System.Windows.Forms.TextRenderer.MeasureText("Abcgq", font).Height; + SpacingOneAndHalf = (3 * SpacingOne) / 2; + SpacingOne4Header = System.Windows.Forms.TextRenderer.MeasureText("Abcgq", headerFont).Height; + SpacingOneAndHalf4Header = (3 * SpacingOne4Header) / 2; + + /// Calculate the tests count int testsCount = 0; if (batch.WaterMeters.Count > 0) { foreach (var mtr in batch.WaterMeters[0].MeterTestRslts) { - if (mtr.Publish() == Config.Entities.Publish.Always) testsCount++; + if (mtr.Publish() == Config.Entities.Publish.Always && mtr.IsPilotRslt()) testsCount++; } } - if (batch.WaterMeters.Count > 0 && batch.WaterMeters[0].Compound()) testsCount /= 3; + /// Prepare document outline + TitleX = cfg.LeftMargin; + TitleY = cfg.TopMargin; - int wmSectionHeight = (testsCount + 4) * SpacingOne; + titleHeight = System.Windows.Forms.TextRenderer.MeasureText(header, titleFont).Height; + CommonTop = TitleY + titleHeight + SpacingOne4Header; + + commonHeight = commonItems.Count * SpacingOne; + BodyTop = CommonTop + commonHeight + SpacingOne4Header; + + int wmSectionHeight = (testsCount + 1) * SpacingOne + 3 * SpacingOne4Header; nrWMsOnFirstPage = (printHeight - BodyTop + TitleY - 2 * SpacingOne) / wmSectionHeight; nrWMsOnNextPage = (printHeight - 2 * SpacingOne) / wmSectionHeight; - nrWMsOnNextPage = Math.Max(nrWMsOnNextPage, 1); /// Prevent division by zero if there are too many WM tests + nrWMsOnNextPage = Math.Max(nrWMsOnNextPage, 1); /// Prevent division by zero if there are too many WM tests nrPages = 1 + (batch.WaterMeters.Count - nrWMsOnFirstPage + nrWMsOnNextPage - 1) / nrWMsOnNextPage; @@ -143,10 +148,6 @@ namespace Results.Output.Printers.Enhanced protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e) { base.OnBeginPrint(e); - - if (font == null) { font = new Font(FontFamilyName, 10, FontStyle.Regular); } - if (boldFont == null) { boldFont = new Font(FontFamilyName, 10, FontStyle.Bold); } - if (titleFont == null) { titleFont = new Font(FontFamilyName, 18, FontStyle.Bold); } } /// @@ -171,7 +172,7 @@ namespace Results.Output.Printers.Enhanced if (pageNr == 1) { ///---------- - /// Header + /// Title ///---------- RectangleF printArea = new RectangleF(TitleX, TitleY, printWidth, titleHeight); e.Graphics.DrawString(header, titleFont, Brushes.Black, printArea); @@ -249,7 +250,7 @@ namespace Results.Output.Printers.Enhanced for (int i = 0; i < testItems.Count; i++) { - float columnWidth = e.Graphics.MeasureString(testItems[i].Caption, font).Width; + float columnWidth = e.Graphics.MeasureString(testItems[i].Caption, headerFont).Width; foreach (var mtr in wm.MeterTestRslts) { if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always) @@ -270,24 +271,24 @@ namespace Results.Output.Printers.Enhanced int tableRightX = (int)columnPos[testItems.Count] - 20; string wmText = string.Format("{0} {1}", Strings.Water_Meter, printedWMNr); - PrintAt(e, leftMargin, top, wmText); + PrintHeaderAt(e, leftMargin, top, wmText); if (!string.IsNullOrEmpty(wm.SerialNr)) { - PrintAt(e, leftMargin + (int)e.Graphics.MeasureString(wmText, font).Width, top, + PrintHeaderAt(e, leftMargin + (int)e.Graphics.MeasureString(wmText, headerFont).Width, top, string.Format(" {0} = {1}", Strings.sn, wm.SerialNr)); } /// Horizontal line - int horY = top + 25; + int horY = top + SpacingOneAndHalf4Header; e.Graphics.DrawLine(new Pen(Color.Black, 2), new Point(tableLeftX, horY), new Point(tableRightX, horY)); for (int i = 0; i < testItems.Count; i++) { - PrintAt(e, (int)columnPos[i], top + 27, testItems[i].Caption); + PrintHeaderAt(e, (int)columnPos[i], top + (int)(1.6 * SpacingOne4Header), testItems[i].Caption); } /// Horizontal line - horY = top + 27 + SpacingOne; + horY = top + (int)(2.8 * SpacingOne4Header); e.Graphics.DrawLine(new Pen(Color.Black, 2), new Point(tableLeftX, horY), new Point(tableRightX, horY)); int testsCount = 0; @@ -309,16 +310,16 @@ namespace Results.Output.Printers.Enhanced /// TODO: How to print colors? } - PrintAt(e, (int)columnPos[i], top + 30 + SpacingOne * testsCount, itemText); + PrintAt(e, (int)columnPos[i], top + 2 * SpacingOne4Header + SpacingOne * testsCount, itemText); } } } /// Horizontal line - horY = top + 30 + SpacingOne * (testsCount + 1); + horY = top + 2 * SpacingOneAndHalf4Header + SpacingOne * testsCount; e.Graphics.DrawLine(new Pen(Color.Black, 2), new Point(tableLeftX, horY), new Point(tableRightX, horY)); - return (testsCount + 4) * SpacingOne; + return (testsCount + 1) * SpacingOne + 3 * SpacingOne4Header; } @@ -330,21 +331,21 @@ namespace Results.Output.Printers.Enhanced void PrintAt(System.Drawing.Printing.PrintPageEventArgs e, int x, int y, string text) { - RectangleF printArea = new RectangleF(x, y, 667, SpacingOne); + RectangleF printArea = new RectangleF(x, y, 2000, SpacingOne); e.Graphics.DrawString(text, this.font, Brushes.Black, printArea); } - void PrintBoldAt(System.Drawing.Printing.PrintPageEventArgs e, Point p, string text) + void PrintHeaderAt(System.Drawing.Printing.PrintPageEventArgs e, Point p, string text) { - PrintBoldAt(e, p.X, p.Y, text); + PrintHeaderAt(e, p.X, p.Y, text); } - void PrintBoldAt(System.Drawing.Printing.PrintPageEventArgs e, int x, int y, string text) + void PrintHeaderAt(System.Drawing.Printing.PrintPageEventArgs e, int x, int y, string text) { - RectangleF printArea = new RectangleF(x, y, 667, SpacingOne); - e.Graphics.DrawString(text, this.boldFont, Brushes.Black, printArea); + RectangleF printArea = new RectangleF(x, y, 2000, SpacingOne4Header); + e.Graphics.DrawString(text, this.headerFont, Brushes.Black, printArea); } } } diff --git a/Results/Output/Printers/Enhanced/EnhancedPrinterCfg.cs b/Results/Output/Printers/Enhanced/EnhancedPrinterCfg.cs new file mode 100644 index 000000000..db318ef0c --- /dev/null +++ b/Results/Output/Printers/Enhanced/EnhancedPrinterCfg.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Results.Output.Printers.Enhanced +{ + public class EnhancedPrinterCfg + { + public Config.Entities.PageOrientation PageOrientation; + public int TopMargin; + public int BottomMargin; + public int LeftMargin; + public string TitFntFml; + public int TitFntSz; + public int TitFntSty; + public string HdrFntFml; + public int HdrFntSz; + public int HdrFntSty; + public string BodyFntFml; + public int BodyFntSz; + public int BodyFntSty; + public bool SupressPrinting; /// Bypass printing when true + public System.Globalization.CultureInfo CultureInfo; + public string[] CommonItems; + public string[] TestItems; + public string Header; /// =Title + public string Footer; + } +} diff --git a/Results/Properties/AssemblyInfo.cs b/Results/Properties/AssemblyInfo.cs index 74e473885..dac5192e7 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.14.595.0")] -[assembly: AssemblyFileVersion("2.14.595.0")] +[assembly: AssemblyVersion("2.14.597.0")] +[assembly: AssemblyFileVersion("2.14.597.0")] diff --git a/Results/Results.csproj b/Results/Results.csproj index b89a9eb19..7af9f30a7 100644 --- a/Results/Results.csproj +++ b/Results/Results.csproj @@ -103,6 +103,7 @@ Component + Component diff --git a/TestBenchFramework/BenchControl/Output/FileWriters/Basic/Writer.cs b/TestBenchFramework/BenchControl/Output/FileWriters/Basic/Writer.cs index ad154adef..15e3f01b5 100644 --- a/TestBenchFramework/BenchControl/Output/FileWriters/Basic/Writer.cs +++ b/TestBenchFramework/BenchControl/Output/FileWriters/Basic/Writer.cs @@ -26,9 +26,8 @@ namespace TBF.BenchControl.Output.FileWriters.Basic /// readonly IList rsltItems; + Results.Entities.Batch batch; - Thread thread; /// Thread where one file is saved - bool completed; /// Set to 'true' by the first thread when writing to the file completed bool abort; /// Set to 'true' by Stop() operation to abort writing to the file @@ -140,40 +139,34 @@ namespace TBF.BenchControl.Output.FileWriters.Basic /// Reference to the operation public IOperation WriteResultsOp(Results.Entities.Batch batch) { - thread = new Thread(() => - { - WriteRslts(batch, writerCfg.DestinationPath); - WriteRslts(batch, writerCfg.DestinationPath2); - completed = true; - }); - - if (writerCfg.Culture > Culture.system && writerCfg.Culture < Culture.Count) - { - thread.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString()); - } - + this.batch = batch; return this; } /// Start this operation public void Start() { - completed = false; - abort = false; - thread.Start(); - } + CultureInfo oriCulture = Thread.CurrentThread.CurrentCulture; + + try { Thread.CurrentThread.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString()); } + catch { } + + WriteRslts(batch, writerCfg.DestinationPath); + WriteRslts(batch, writerCfg.DestinationPath2); + + Thread.CurrentThread.CurrentCulture = oriCulture; + } /// Run this operation /// Event.ResultsWritten public Event Run() { - return completed ? Event.ResultsWritten : Event.Busy; + return Event.ResultsWritten; } /// Stop this operation public void Stop() { - if (!completed) abort = true; } diff --git a/TestBenchFramework/BenchControl/Output/FileWriters/Enhanced/Writer.cs b/TestBenchFramework/BenchControl/Output/FileWriters/Enhanced/Writer.cs index ce673da08..9fa809ac0 100644 --- a/TestBenchFramework/BenchControl/Output/FileWriters/Enhanced/Writer.cs +++ b/TestBenchFramework/BenchControl/Output/FileWriters/Enhanced/Writer.cs @@ -214,7 +214,9 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced public void Start() { CultureInfo oriCulture = Thread.CurrentThread.CurrentCulture; - Thread.CurrentThread.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString()); + + try { Thread.CurrentThread.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString()); } + catch { } WriteRslts(batch, writerCfg.DestinationPath); WriteRslts(batch, writerCfg.DestinationPath2); diff --git a/TestBenchFramework/BenchControl/Output/FileWriters/Xml/Writer.cs b/TestBenchFramework/BenchControl/Output/FileWriters/Xml/Writer.cs index 6cdb0f29b..a0eba4168 100644 --- a/TestBenchFramework/BenchControl/Output/FileWriters/Xml/Writer.cs +++ b/TestBenchFramework/BenchControl/Output/FileWriters/Xml/Writer.cs @@ -193,7 +193,9 @@ namespace TBF.BenchControl.Output.FileWriters.Xml public void Start() { CultureInfo oriCulture = Thread.CurrentThread.CurrentCulture; - Thread.CurrentThread.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString()); + + try { Thread.CurrentThread.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString()); } + catch { } WriteRslts(batch, writerCfg.DestinationPath); WriteRslts(batch, writerCfg.DestinationPath2); diff --git a/TestBenchFramework/BenchControl/Output/Printers/Enhanced/Printer.cs b/TestBenchFramework/BenchControl/Output/Printers/Enhanced/Printer.cs index e58cdc6dd..c841fb900 100644 --- a/TestBenchFramework/BenchControl/Output/Printers/Enhanced/Printer.cs +++ b/TestBenchFramework/BenchControl/Output/Printers/Enhanced/Printer.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Threading; +using Results.Output.Printers.Enhanced; using log4net; namespace TBF.BenchControl.Output.Printers.Enhanced @@ -77,6 +78,17 @@ namespace TBF.BenchControl.Output.Printers.Enhanced 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.CommonItems = newCfg.CommonItems; @@ -144,17 +156,35 @@ namespace TBF.BenchControl.Output.Printers.Enhanced 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) { - new Results.Output.Printers.Enhanced.EnhancedPrintDocument(batch, - printerCfg.PageOrientation, - printerCfg.TopMargin, - printerCfg.BottomMargin, - printerCfg.LeftMargin, - header, - commonItems, - testItems, - footer).Print(); + EnhancedPrinterCfg cfg = new EnhancedPrinterCfg { + 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, + CultureInfo = culture, + Header = printerCfg.Header, + CommonItems = printerCfg.CommonItems, + TestItems = printerCfg.SelectedItems, + Footer = printerCfg.Footer, + }; + + new Results.Output.Printers.Enhanced.EnhancedPrintDocument(batch, cfg).Print(); } } } diff --git a/TestBenchFramework/Properties/AssemblyInfo.cs b/TestBenchFramework/Properties/AssemblyInfo.cs index b4d233a17..d9aea7788 100644 --- a/TestBenchFramework/Properties/AssemblyInfo.cs +++ b/TestBenchFramework/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.14.596.1")] -[assembly: AssemblyFileVersion("2.14.596.1")] +[assembly: AssemblyVersion("2.14.597.1")] +[assembly: AssemblyFileVersion("2.14.597.1")]