From 5114f5f1ebaef1dea2f82a4e480197af7f6b4253 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Mon, 21 Nov 2016 11:03:44 +0100 Subject: [PATCH] ResultsBrowser : Printing statistics in progress. --- ResultsBrowser/Forms/StatisticsDlg.cs | 17 +- .../Statistics/StatisticsPrintDocument.cs | 168 +++++------------- 2 files changed, 56 insertions(+), 129 deletions(-) diff --git a/ResultsBrowser/Forms/StatisticsDlg.cs b/ResultsBrowser/Forms/StatisticsDlg.cs index 52d91a002..931b7d01c 100644 --- a/ResultsBrowser/Forms/StatisticsDlg.cs +++ b/ResultsBrowser/Forms/StatisticsDlg.cs @@ -185,7 +185,22 @@ namespace ResultsBrowser.Forms private void printButton_Click(object sender, EventArgs e) { - new StatisticsPrintDocument("", rowValues, columnValues, occurances, Config.Entities.PageOrientation.Portrait).Print(); + int columnsCount = Math.Max(1, columnValues.Count); + string[,] table = new string[rowValues.Count + 1, columnsCount + 1]; + + table[0, 0] = string.Empty; + for (int column = 0; column < columnsCount; column++) + { + table[0, column + 1] = (twoDim ? columnValues[column] : Strings.Count); + } + + for (int row = 0; row < rowValues.Count; row++) + { + table[row + 1, 0] = rowValues[row]; + for (int column = 0; column < columnsCount; column++) table[row + 1, column + 1] = occurances[row, column].ToString(); + } + + new StatisticsPrintDocument(table, Config.Entities.PageOrientation.Portrait).Print(); } } } diff --git a/ResultsBrowser/Output/Printers/Statistics/StatisticsPrintDocument.cs b/ResultsBrowser/Output/Printers/Statistics/StatisticsPrintDocument.cs index 5cb934c32..9bb29101e 100644 --- a/ResultsBrowser/Output/Printers/Statistics/StatisticsPrintDocument.cs +++ b/ResultsBrowser/Output/Printers/Statistics/StatisticsPrintDocument.cs @@ -29,11 +29,7 @@ namespace ResultsBrowser.Output.Printers.Statistics /// /// Data to print /// - readonly string docVersion; - readonly IList rowValues; - readonly IList columnValues; - readonly int[,] occurances; - readonly int columnsCount; + string[,] table; /// Top coordinate of the table int top; @@ -49,16 +45,9 @@ namespace ResultsBrowser.Output.Printers.Statistics /// Constructor /// /// Text to be printed - public StatisticsPrintDocument(string docVersion, - IList rowValues, IList columnValues, int[,] occurances, - PageOrientation pageOrientation) + public StatisticsPrintDocument(string[,] table, PageOrientation pageOrientation) { - this.docVersion = docVersion; - this.rowValues = rowValues; - this.columnValues = columnValues; - this.occurances = occurances; - columnsCount = Math.Max(1, columnValues.Count); - + this.table = table; DefaultPageSettings.Landscape = (pageOrientation == PageOrientation.Landscape); } @@ -108,110 +97,33 @@ namespace ResultsBrowser.Output.Printers.Statistics StringFormat format = new StringFormat(StringFormatFlags.LineLimit); RectangleF printArea = new RectangleF(TitleX, TitleY, 667, 50); - e.Graphics.DrawString("ABCDEF", this.fontTitle, Brushes.Black, printArea); + e.Graphics.DrawString("TITLE", this.fontTitle, Brushes.Black, printArea); - int lineNr = FirstLineNr; - PrintAt(e, Tab1, lineNr * SpacingOne, docVersion); - lineNr++; -/* - PrintBoldAt(e, Tab1, lineNr * SpacingOne, "Prüfstand Nr :"); - PrintBoldAt(e, Tab2, lineNr * SpacingOne, wm.BenchId().ToString()); - PrintBoldAt(e, Tab3, lineNr * SpacingOne, "Datum :"); - PrintBoldAt(e, Tab4, lineNr * SpacingOne, wm.Batch.EndTime.Date.ToString("d")); - lineNr++; - PrintAt(e, Tab1, lineNr * SpacingOne, "Zählertyp :"); - PrintAt(e, Tab2, lineNr * SpacingOne, zaehlertyp); - PrintAt(e, Tab3, lineNr * SpacingOne, "Eichjahr :"); - PrintAt(e, Tab4, lineNr * SpacingOne, wm.YearOfProduction.ToString()); - lineNr++; - PrintAt(e, Tab1, lineNr * SpacingOne, "Prüfvorlage :"); - PrintAt(e, Tab2, lineNr * SpacingOne, pruefvorlage); - lineNr += 2; - - PrintAt(e, Tab1, lineNr * SpacingOne, "Hersteller :"); - PrintAt(e, Tab2, lineNr * SpacingOne, wm.Producer()); - lineNr++; - - PrintAt(e, Tab1, lineNr * SpacingOne, "Seriennummer :"); - PrintAt(e, Tab2, lineNr * SpacingOne, wm.SerialNr); - lineNr++; - - PrintAt(e, Tab1, lineNr * SpacingOne, "Qn :"); - PrintAt(e, Tab2, lineNr * SpacingOne, wm.Q3_Qn().ToString()); - lineNr++; - - PrintAt(e, Tab1, lineNr * SpacingOne, "Zulassungszeichen :"); - PrintAt(e, Tab2, lineNr * SpacingOne, wm.ApprovalInfo()); - lineNr++; - - PrintAt(e, Tab1, lineNr * SpacingOne, "Metr. klasse :"); - PrintAt(e, Tab2, lineNr * SpacingOne, wm.MetrologicalClass()); - lineNr++; - - PrintAt(e, Tab1, lineNr * SpacingOne, "Stand :"); - PrintAt(e, Tab2, lineNr * SpacingOne, wm.EndState); - - lineNr += 2; - top = SpacingOne * lineNr; -*/ - PrintTable(e); - DrawTable(e); - } - - /// - /// Print table texts. - /// - void PrintTable(System.Drawing.Printing.PrintPageEventArgs e) - { - PrintAt(e, FromTest(-1, -1), "Prüflauf"); - PrintAt(e, FromTest(-1, 0), "Q [l/h]"); - PrintAt(e, FromTest(-1, 1), "Prüf-Vol.[l]"); - PrintAt(e, FromTest(-1, 4), "Fehler [%]"); - PrintAt(e, FromTest(-1, 5), "Ergebnis"); - - PrintAt(e, FromTest(-1, 6), "Q [l/h]"); - PrintAt(e, FromTest(-1, 7), "Temperatur"); - PrintAt(e, FromTest(-1, 8), "Dichte"); - PrintAt(e, FromTest(-1, 9), "Prüfzeit"); - PrintAt(e, FromTest(-1, 10), "Druck Eing."); - PrintAt(e, FromTest(-1, 11), "Druck Ausg."); -/* - int rowCnt = 0; - foreach (var mtr in wm.MeterTestRslts) + /// Measure texts + float[] columnWidths = new float[table.GetLength(1)]; + for (int c = 0; c < columnWidths.Length; c++) { - Point p = FromTest(rowCnt, -1); - PrintAt(e, p.X, p.Y, mtr.Name()); - PrintAt(e, p.X, p.Y + (resultsCount + 2) * SpacingOneAndHalf, mtr.Name()); - - PrintAt(e, FromTest(rowCnt, 0), mtr.TestRslt.FlowMass.ToString("F1")); - PrintAt(e, FromTest(rowCnt, 1), mtr.TestRslt.VolumeCTV.ToString("F2")); - if (compound) + columnWidths[c] = e.Graphics.MeasureString(table[0, c], font).Width; + for (int r = 1; r < table.GetLength(0); r++) { - Results.Entities.MeterTestRslt mainMtr = wm.GetMeterTestRslt(mtr.Name(), CompoundMeterId.CompoundMain); - Results.Entities.MeterTestRslt auxMtr = wm.GetMeterTestRslt(mtr.Name(), CompoundMeterId.CompoundAux); - - PrintAt(e, FromTest(rowCnt, 2), mainMtr.VolumeMeter.ToString("F2")); - PrintAt(e, FromTest(rowCnt, 3), auxMtr.VolumeMeter.ToString("F2")); - PrintAt(e, FromTest(rowCnt, 4), mtr.Error.ToString("F2")); - PrintAt(e, FromTest(rowCnt, 5), mtr.Passed ? "iO" : "NiO"); + float width = e.Graphics.MeasureString(table[r, c], font).Width; + if (width > columnWidths[c]) columnWidths[c] = width; } - else - { - PrintAt(e, FromTest(rowCnt, 2), mtr.VolumeMeter.ToString("F2")); - PrintAt(e, FromTest(rowCnt, 3), "-"); - PrintAt(e, FromTest(rowCnt, 4), mtr.Error.ToString("F2")); - PrintAt(e, FromTest(rowCnt, 5), mtr.Passed ? "iO" : "NiO"); - } - PrintAt(e, FromTest(rowCnt, 6), mtr.TestRslt.FlowMass.ToString("F1")); - PrintAt(e, FromTest(rowCnt, 7), mtr.TestRslt.TempDownMean.ToString("F2")); - PrintAt(e, FromTest(rowCnt, 8), mtr.TestRslt.DensityDiv.ToString("F2")); - PrintAt(e, FromTest(rowCnt, 9), mtr.TestTime.ToString("F1")); - PrintAt(e, FromTest(rowCnt, 10), Config.Units.ConvertTo(Config.Unit.bar, mtr.TestRslt.PressUpMean).ToString("F3")); - PrintAt(e, FromTest(rowCnt, 11), Config.Units.ConvertTo(Config.Unit.bar, mtr.TestRslt.PressDownMean).ToString("F3")); - - rowCnt++; } -*/ + + /// Print texts + float top = topMargin; + for (int r = 0; r < table.GetLength(0); r++) + { + float left = leftMargin; + for (int c = 0; c < columnWidths.Length; c++) + { + PrintAt(e, new Point((int)left, (int)top), table[r, c]); + left += columnWidths[c]; + } + + top += SpacingOne; + } } /// @@ -219,23 +131,23 @@ namespace ResultsBrowser.Output.Printers.Statistics /// void DrawTable(System.Drawing.Printing.PrintPageEventArgs e) { - int mid = top + SpacingOneAndHalf; - int bot = top + (rowValues.Count + 1) * SpacingOneAndHalf; + //int mid = top + SpacingOneAndHalf; + //int bot = top + (rowValues.Count + 1) * SpacingOneAndHalf; - // Horizontal lines - e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(80, top), new Point(747, top)); - e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(80, mid), new Point(747, mid)); - e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(80, bot), new Point(747, bot)); + //// Horizontal lines + //e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(80, top), new Point(747, top)); + //e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(80, mid), new Point(747, mid)); + //e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(80, bot), new Point(747, bot)); - // Vertical lines - e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point( 80, top), new Point( 80, bot)); - e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(267, top), new Point(267, bot)); - e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(347, top), new Point(347, bot)); - e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(427, top), new Point(427, bot)); - e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(507, top), new Point(507, bot)); - e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(587, top), new Point(587, bot)); - e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(667, top), new Point(667, bot)); - e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(747, top), new Point(747, bot)); + //// Vertical lines + //e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point( 80, top), new Point( 80, bot)); + //e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(267, top), new Point(267, bot)); + //e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(347, top), new Point(347, bot)); + //e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(427, top), new Point(427, bot)); + //e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(507, top), new Point(507, bot)); + //e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(587, top), new Point(587, bot)); + //e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(667, top), new Point(667, bot)); + //e.Graphics.DrawLine(new Pen(Color.Black, BorderW), new Point(747, top), new Point(747, bot)); } void PrintAt(System.Drawing.Printing.PrintPageEventArgs e, Point p, string text)