diff --git a/TestBenchFramework/BenchControl/DataEntry/Standard/EntryForm.cs b/TestBenchFramework/BenchControl/DataEntry/Standard/EntryForm.cs index 4881ae196..d757535f1 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Standard/EntryForm.cs +++ b/TestBenchFramework/BenchControl/DataEntry/Standard/EntryForm.cs @@ -183,18 +183,20 @@ namespace TBF.BenchControl.DataEntry.Standard /// Updates test results with the information collected in watermeters. /// /// Watermetes with information entered in the forms - /// Test results to be updated with the information - public void UpdateTestResults(IList waterMeters, IList results) + /// Test results to be updated with the information + public void UpdateTestResults(IList waterMeters, IList testResults) { - foreach (var test in results) + foreach (var testRslt in testResults) { - if (test.MetersKind != Entities.MetersKind.Single) continue; + if (testRslt.MetersKind != Entities.MetersKind.Single) continue; - int nrMtrsToUpdate = Math.Min(waterMeters.Count, test.Meters.Count); - for (int i = 0; i < nrMtrsToUpdate; i++) + testRslt.PurchaseOrder = PurchaseOrder; + + for (int i = 0; i < testRslt.Meters.Count; i++) { - test.Meters[i].SerialNr = waterMeters[i].SerialNr; - test.Meters[i].EndState = waterMeters[i].EndState; + testRslt.Meters[i].SerialNr = SerialNr(i); + testRslt.Meters[i].Disabled = Disabled(i); + testRslt.Meters[i].EndState = WMEndState(i); } } } diff --git a/TestBenchFramework/Forms/PrintOrderForm.Designer.cs b/TestBenchFramework/Forms/PrintOrderForm.Designer.cs new file mode 100644 index 000000000..5f8e9d578 --- /dev/null +++ b/TestBenchFramework/Forms/PrintOrderForm.Designer.cs @@ -0,0 +1,105 @@ +namespace TBF.Forms +{ + partial class PrintOrderForm + { + /// + /// 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 Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.purchaseOrderComboBox = new System.Windows.Forms.ComboBox(); + this.purchaseOrderGroupBox = new System.Windows.Forms.GroupBox(); + this.printButton = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + this.purchaseOrderGroupBox.SuspendLayout(); + this.SuspendLayout(); + // + // purchaseOrderComboBox + // + this.purchaseOrderComboBox.FormattingEnabled = true; + this.purchaseOrderComboBox.Location = new System.Drawing.Point(47, 47); + this.purchaseOrderComboBox.Name = "purchaseOrderComboBox"; + this.purchaseOrderComboBox.Size = new System.Drawing.Size(380, 31); + this.purchaseOrderComboBox.TabIndex = 0; + // + // purchaseOrderGroupBox + // + this.purchaseOrderGroupBox.Controls.Add(this.purchaseOrderComboBox); + this.purchaseOrderGroupBox.Location = new System.Drawing.Point(59, 38); + this.purchaseOrderGroupBox.Name = "purchaseOrderGroupBox"; + this.purchaseOrderGroupBox.Size = new System.Drawing.Size(481, 114); + this.purchaseOrderGroupBox.TabIndex = 1; + this.purchaseOrderGroupBox.TabStop = false; + this.purchaseOrderGroupBox.Text = "Purchase order"; + // + // printButton + // + this.printButton.Location = new System.Drawing.Point(106, 204); + this.printButton.Name = "printButton"; + this.printButton.Size = new System.Drawing.Size(144, 64); + this.printButton.TabIndex = 2; + this.printButton.Text = "Print"; + this.printButton.UseVisualStyleBackColor = true; + this.printButton.Click += new System.EventHandler(this.printButton_Click); + // + // cancelButton + // + this.cancelButton.Location = new System.Drawing.Point(342, 204); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(144, 64); + this.cancelButton.TabIndex = 3; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); + // + // PrintOrderForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 23F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(597, 323); + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.printButton); + this.Controls.Add(this.purchaseOrderGroupBox); + this.Font = new System.Drawing.Font("Verdana", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "PrintOrderForm"; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.Text = "Print watermeter results"; + this.Load += new System.EventHandler(this.PrintOrderForm_Load); + this.purchaseOrderGroupBox.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ComboBox purchaseOrderComboBox; + private System.Windows.Forms.GroupBox purchaseOrderGroupBox; + private System.Windows.Forms.Button printButton; + private System.Windows.Forms.Button cancelButton; + } +} \ No newline at end of file diff --git a/TestBenchFramework/Forms/PrintOrderForm.cs b/TestBenchFramework/Forms/PrintOrderForm.cs new file mode 100644 index 000000000..483a892b3 --- /dev/null +++ b/TestBenchFramework/Forms/PrintOrderForm.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace TBF.Forms +{ + public partial class PrintOrderForm : Form + { + public string PurchaseOrder; + + public PrintOrderForm() + { + InitializeComponent(); + } + + private void PrintOrderForm_Load(object sender, EventArgs e) + { + TBF.LocalSettings ls = Program.LocalSettings; + Left = (ls.PrintOrderLeft != 0) ? ls.PrintOrderLeft : 200; + Top = (ls.PrintOrderTop != 0) ? ls.PrintOrderTop : 100; + + PrepareOrderCombo(purchaseOrderComboBox); + } + + /// + /// Load Purchase order combo box items from the LocalSettings PurchaseOrderHistory array + /// + /// Puchase order ComboBox + void PrepareOrderCombo(ComboBox orderComboBox) + { + for (int i = 0; i < Program.LocalSettings.PurchaseOrderHistoryCount; i++) + { + orderComboBox.Items.Add(Program.LocalSettings.PurchaseOrderHistory[i]); + } + + if (orderComboBox.Items.Count > 0) + { + orderComboBox.Text = orderComboBox.Items[0].ToString(); + } + } + + private void printButton_Click(object sender, EventArgs e) + { + PurchaseOrder = purchaseOrderComboBox.Text; + + Program.LocalSettings.PrintOrderLeft = Location.X; + Program.LocalSettings.PrintOrderTop = Location.Y; + if (!Program.LocalSettings.UpdatePurchaseOrderHistory(purchaseOrderComboBox.Text)) + { + Program.LocalSettings.Save(); + } + + DialogResult = DialogResult.OK; + Close(); + } + + private void cancelButton_Click(object sender, EventArgs e) + { + PurchaseOrder = string.Empty; + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/TestBenchFramework/Forms/PrintOrderForm.resx b/TestBenchFramework/Forms/PrintOrderForm.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TestBenchFramework/Forms/PrintOrderForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TestBenchFramework/LocalSettings.cs b/TestBenchFramework/LocalSettings.cs index e91012724..6ccc83528 100644 --- a/TestBenchFramework/LocalSettings.cs +++ b/TestBenchFramework/LocalSettings.cs @@ -126,6 +126,10 @@ namespace TBF public int OneProcedureDlgWidth; public int OneProcedureDlgHeight; + /// OneProcedure + public int PrintOrderLeft; + public int PrintOrderTop; + /// Purchase order history public string[] PurchaseOrderHistory; [XmlIgnore] @@ -208,9 +212,12 @@ namespace TBF /// Updates purchase order history /// /// - public void UpdatePurchaseOrderHistory(string lastPurchaseOrder) + /// true = updated and saved + public bool UpdatePurchaseOrderHistory(string lastPurchaseOrder) { - if (string.IsNullOrEmpty(lastPurchaseOrder)) return; + const int HistoryLen = 10; + + if (string.IsNullOrEmpty(lastPurchaseOrder)) return false; int match = -1; for (int i = 0; i < PurchaseOrderHistoryCount; i++) @@ -222,9 +229,9 @@ namespace TBF } } - if (match >= 0 || PurchaseOrderHistoryCount >= 10) + if (match >= 0 || PurchaseOrderHistoryCount >= HistoryLen) { - /// History does not have to be or should not be extended + /// History does not have to be (because of a match) or should not be extended (because of the lenght) if (match < 0) match = PurchaseOrderHistoryCount - 1; for (int j = match; j > 0; j--) @@ -245,6 +252,7 @@ namespace TBF PurchaseOrderHistory = newHistory; } Save(); + return true; } } diff --git a/TestBenchFramework/MainWnd.Designer.cs b/TestBenchFramework/MainWnd.Designer.cs index ff2d06deb..a4bdb5904 100644 --- a/TestBenchFramework/MainWnd.Designer.cs +++ b/TestBenchFramework/MainWnd.Designer.cs @@ -44,6 +44,7 @@ this.procedureGroupBox = new System.Windows.Forms.GroupBox(); this.procedureComboBox = new System.Windows.Forms.ComboBox(); this.activityGroupBox = new System.Windows.Forms.GroupBox(); + this.messageLabel = new System.Windows.Forms.Label(); this.activityLabel = new System.Windows.Forms.Label(); this.mainTabControl = new System.Windows.Forms.TabControl(); this.homeTabPage = new System.Windows.Forms.TabPage(); @@ -87,7 +88,7 @@ this.processToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.picturesTSMItem = new System.Windows.Forms.ToolStripMenuItem(); this.resultsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.messageLabel = new System.Windows.Forms.Label(); + this.printToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.verticalSplitContainer)).BeginInit(); this.verticalSplitContainer.Panel1.SuspendLayout(); this.verticalSplitContainer.Panel2.SuspendLayout(); @@ -192,6 +193,11 @@ this.activityGroupBox.Name = "activityGroupBox"; this.activityGroupBox.TabStop = false; // + // messageLabel + // + resources.ApplyResources(this.messageLabel, "messageLabel"); + this.messageLabel.Name = "messageLabel"; + // // activityLabel // resources.ApplyResources(this.activityLabel, "activityLabel"); @@ -456,6 +462,7 @@ this.measurementTSMenuItem, this.picturesTSMItem, this.resultsToolStripMenuItem, + this.printToolStripMenuItem, this.logsTSMenuItem, this.editTSMenuItem, this.helpTSMenuItem}); @@ -486,10 +493,11 @@ resources.ApplyResources(this.resultsToolStripMenuItem, "resultsToolStripMenuItem"); this.resultsToolStripMenuItem.Click += new System.EventHandler(this.resultsTSMenuItem_Click); // - // messageLabel + // printToolStripMenuItem // - resources.ApplyResources(this.messageLabel, "messageLabel"); - this.messageLabel.Name = "messageLabel"; + this.printToolStripMenuItem.Name = "printToolStripMenuItem"; + resources.ApplyResources(this.printToolStripMenuItem, "printToolStripMenuItem"); + this.printToolStripMenuItem.Click += new System.EventHandler(this.printToolStripMenuItem_Click); // // MainWnd // @@ -607,6 +615,7 @@ private System.Windows.Forms.GroupBox descriptionGroupBox; private System.Windows.Forms.Label descriptionLabel; private System.Windows.Forms.Label messageLabel; + private System.Windows.Forms.ToolStripMenuItem printToolStripMenuItem; } } diff --git a/TestBenchFramework/MainWnd.cs b/TestBenchFramework/MainWnd.cs index 3a38a2184..711e85ba3 100644 --- a/TestBenchFramework/MainWnd.cs +++ b/TestBenchFramework/MainWnd.cs @@ -449,5 +449,54 @@ namespace TBF if (emergencyStopModelessDlg != null) emergencyStopModelessDlg.Visible = oriEmgStopState; } + + + private void printToolStripMenuItem_Click(object sender, EventArgs e) + { + TBF.Forms.PrintOrderForm dlg = new TBF.Forms.PrintOrderForm(); + if (dlg.ShowDialog() == DialogResult.OK) + { + string purchaseOrder = dlg.PurchaseOrder; + + NHibernate.ISession session = FluentCommon.CreateSession(Database.Procedures); + + IList testResults = session + .CreateQuery("FROM TestResult WHERE PurchaseOrder = :purchaseOrder") + .SetParameter("purchaseOrder", purchaseOrder) + .List(); + + if (testResults.Count == 0) + { + MessageBox.Show("No results to print", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return; + } + + IList procedure = session + .CreateQuery("FROM Procedure WHERE Name = :procedureName") + .SetParameter("procedureName", testResults[0].ProcedureName) + .List(); + + if (procedure.Count != 1) + { + MessageBox.Show("No results to print", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return; + } + + + if ((testResults != null) && (testResults.Count != 0) && (testResults[0].MetersKind == Entities.MetersKind.Single)) + { + new PrintOrderDocument(procedure[0], testResults).Print(); + } + else if((testResults != null) && (testResults.Count != 0) && (testResults[0].MetersKind == Entities.MetersKind.Combined)) + { + /// Do nothing right now + } + else + { + MessageBox.Show("No results to print", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return; + } + } + } } } \ No newline at end of file diff --git a/TestBenchFramework/MainWnd.resx b/TestBenchFramework/MainWnd.resx index 58bebe546..bd5e0de34 100644 --- a/TestBenchFramework/MainWnd.resx +++ b/TestBenchFramework/MainWnd.resx @@ -463,7 +463,7 @@ processTabPageCtrl - TBF.Screens.ProcessTabPageCtrl, TBF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + TBF.Screens.ProcessTabPageCtrl, TBF, Version=1.2.5.2, Culture=neutral, PublicKeyToken=null processTabPage @@ -517,7 +517,7 @@ MeasurementTabPageCtrl - TBF.Screens.MeasurementTabPageCtrl, TBF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + TBF.Screens.MeasurementTabPageCtrl, TBF, Version=1.2.5.2, Culture=neutral, PublicKeyToken=null measurementTabPage @@ -592,7 +592,7 @@ picturesTabPageCtrl1 - TBF.Screens.PicturesTabPageCtrl, TBF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + TBF.Screens.PicturesTabPageCtrl, TBF, Version=1.2.5.2, Culture=neutral, PublicKeyToken=null picturesTabPage @@ -646,7 +646,7 @@ resultsTabPageCtrl - TBF.Screens.ResultsTabPageCtrl, TBF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + TBF.Screens.ResultsTabPageCtrl, TBF, Version=1.2.5.2, Culture=neutral, PublicKeyToken=null resultsTabPage @@ -700,7 +700,7 @@ logsTabPageCtrl - TBF.Screens.LogsTabPageCtrl, TBF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + TBF.Screens.LogsTabPageCtrl, TBF, Version=1.2.5.2, Culture=neutral, PublicKeyToken=null logsTabPage @@ -1089,6 +1089,12 @@ Results + + 44, 20 + + + Print + 0, 0 @@ -1272,6 +1278,12 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + printToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + MainWnd diff --git a/TestBenchFramework/PrintOrderDocument.cs b/TestBenchFramework/PrintOrderDocument.cs new file mode 100644 index 000000000..647123750 --- /dev/null +++ b/TestBenchFramework/PrintOrderDocument.cs @@ -0,0 +1,419 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Printing; +using System.IO; +using TBF.Resources; + +namespace TBF +{ + public class PrintOrderDocument : PrintDocument + { + const string FontFamilyName = "Arial"; //"Times New Roman"; + + const int SpacingOne = 18; + const int SpacingOneAndHalf = (3 * SpacingOne) / 2; + const int TitleX = 100; + const int TitleY = 180; /// Depends on the size of the header + const int HdrTop = 240; /// Depends on the size of the header + const int BodyTop = 400; + + /// + /// Property variable for the Font the user wishes to use + /// + Font font; + Font boldFont; + Font titleFont; + + /// + /// Data to print + /// + readonly Entities.Procedure procedure; + readonly IList allResults; + readonly bool combined; + readonly DateTime dateTime; + readonly int batchMin; + readonly int batchMax; + + /// + /// Items to print + /// + readonly int testsPerMeter; + readonly IList resultItems; + + readonly int maxNrRows; + readonly int nrRows; + readonly int nrColumns; + + IList unsortedResults; + + string[,] dataToPrint; + + /// + /// Constructor + /// + /// Procedure belonging to the results + /// Results to be printed (multiple batches) + public PrintOrderDocument(Entities.Procedure procedure, IList allResults) + { + this.procedure = procedure; + this.allResults = allResults; + + dateTime = DateTime.Now; + + batchMin = int.MaxValue; + batchMax = int.MinValue; + foreach (var tr in allResults) + { + if (tr.BatchNr < batchMin) batchMin = tr.BatchNr; + if (tr.BatchNr > batchMax) batchMax = tr.BatchNr; + } + + resultItems = Forms.ResultItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Printer_SingleWM); + combined = false; + + testsPerMeter = Utils.GetSortedTestResults(procedure, null, 1).Count; + + maxNrRows = (batchMax - batchMin + 1) * Program.WMsCount; + nrColumns = testsPerMeter * resultItems.Count + 2; + + /// + /// Prepare raw data to print + /// + dataToPrint = new string[maxNrRows, nrColumns]; + nrRows = 0; + for (int i = batchMin; i <= batchMax; i++) + { + /// Collect all results belonging to one batch + unsortedResults = new List(); + foreach (var tr in allResults) if (tr.BatchNr == i) unsortedResults.Add(tr); + + if (unsortedResults.Count == 0) continue; + + for (int wmNr = 0; wmNr < Program.WMsCount; wmNr++) /// wmNr is 0-based + { + if (!unsortedResults[0].Meters[wmNr].Disabled) + { + dataToPrint[nrRows, 0] = (nrRows + 1).ToString(); + dataToPrint[nrRows, 1] = unsortedResults[0].Meters[wmNr].SerialNr; + + IList results = + Utils.GetSortedTestResults(procedure, unsortedResults, wmNr + 1); + + for (int j = 0; j < testsPerMeter; j++) + { + if (results[j] != null) + { + int k = 2 + j * resultItems.Count; + foreach (var item in resultItems) + dataToPrint[nrRows, k++] = item.Print(results[j].Meters[wmNr]); + } + } + + nrRows++; + } + } + } + + int z = 7; + } + + /// + /// Override the default onbeginPrint method of the PrintDocument Object + /// + /// + /// + 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); } + } + + /// + /// 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 (File.Exists("C:\\TBF\\header.png")) + { + Image img = Image.FromFile("C:\\TBF\\header.png"); + 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); + + ///---------- + /// Header + ///---------- + RectangleF printArea = new RectangleF(TitleX, TitleY, 667, 40); + e.Graphics.DrawString(allResults[0].ProtocolTitle, titleFont, Brushes.Black, printArea); + + string[] leftColumn = new string[] + { + "Purchase order: ", + "Date and time: ", + "Procedure:", + Strings.User_, + "Ambient temperature: ", + "Ambient pressure: ", + "Ambient humidity: ", + }; + + string[] rightColumn = new string[] + { + allResults[0].PurchaseOrder, + //dateTime.ToShortDateString() + " " + dateTime.ToShortTimeString(), + string.Format("{0}.{1}.{2} {3}:{4}", dateTime.Year.ToString("D4"), + dateTime.Month.ToString("D2"), + dateTime.Day.ToString("D2"), + dateTime.Hour.ToString("D2"), + dateTime.Minute.ToString("D2")), + procedure.Name, + Entities.User.CurrentUser.Name, + allResults[0].AmbientTempAve.ToString("F1") + " °C", + allResults[0].AmbientPressAve.ToString("F0") + " mbar", + allResults[0].AmbientHumiAve.ToString("F0") + " %", + }; + + /// Determine max. left column width in characters + int maxLen = 0; + foreach (var s in leftColumn) if (s.Length > maxLen) maxLen = s.Length; + + /// 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, 300, HdrTop + SpacingOne * i, rightColumn[i]); + } + + ///-------- + /// Body + ///-------- + + /// This variable represents the top coordinate of the area where WM results are printed + /// and it is updated (increased by) the value returned by PrintXyzWM() - the section size. + int nextWmTop = BodyTop; + + e.HasMorePages = false; + } + + + /// + /// Print one water meter results + /// + /// Water meter number (0-based) + /// Top coordinate of watermeter data + /// The height of the printed section + int PrintSingleWM(System.Drawing.Printing.PrintPageEventArgs e, int wmNr, int printedWMNr, int top) + { + IList results = Utils.GetSortedTestResults(procedure, unsortedResults, wmNr + 1); + + /// + /// Determine column widths + /// + float[] columnPos = new float[resultItems.Count + 1]; + columnPos[0] = 100.0f; + + for (int i = 0; i < resultItems.Count; i++) + { + float columnWidth = e.Graphics.MeasureString(resultItems[i].ClmnHeaderText, font).Width; + foreach (var tr in results) + { + if (tr != null) + { + float width = e.Graphics.MeasureString(resultItems[i].Print(tr.Meters[wmNr]), font).Width; + if (width > columnWidth) columnWidth = width; + } + } + columnPos[i + 1] = columnPos[i] + columnWidth + 20.0f; + } + int tableLeftX = (int)columnPos[0]; + int tableRightX = (int)columnPos[resultItems.Count] - 20; + + string wmText = string.Format("Water meter {0}", printedWMNr); + PrintAt(e, 100, top, wmText); + if (!string.IsNullOrEmpty(unsortedResults[0].Meters[wmNr].SerialNr)) + { + PrintAt(e, 100 + (int)e.Graphics.MeasureString(wmText, font).Width, top, + string.Format(" s/n = {0}", unsortedResults[0].Meters[wmNr].SerialNr)); + } + + /// Horizontal line + int horY = top + 25; + e.Graphics.DrawLine(new Pen(Color.Black, 2), new Point(tableLeftX, horY), new Point(tableRightX, horY)); + + for (int i = 0; i < resultItems.Count; i++) + { + PrintAt(e, (int)columnPos[i], top + 27, resultItems[i].ClmnHeaderText); + } + + /// Horizontal line + horY = top + 27 + SpacingOne; + e.Graphics.DrawLine(new Pen(Color.Black, 2), new Point(tableLeftX, horY), new Point(tableRightX, horY)); + + for (int r = 0; r < results.Count; r++) + { + if (results[r] != null) + { + for (int i = 0; i < resultItems.Count; i++) + { + string text = resultItems[i].Print(results[r].Meters[wmNr]); + + string[] texts = text.Split(new char[] { '|' }); + + if (texts.Length == 2) + { + Color color = texts[1].Equals("Green") ? Color.Green : (texts[1].Equals("Red") ? Color.Red : Color.White); + text = texts[0]; + /// TODO: How to print colors? + } + + PrintAt(e, (int)columnPos[i], top + 30 + SpacingOne * (r + 1), text); + } + } + } + + /// Horizontal line + horY = top + 30 + SpacingOne * (results.Count + 1); + e.Graphics.DrawLine(new Pen(Color.Black, 2), new Point(tableLeftX, horY), new Point(tableRightX, horY)); + + return (results.Count + 4) * SpacingOne; + } + + + /// + /// Print one combined water meter results + /// + /// Water meter number (1-based) + /// Top coordinate of watermeter data + /// The height of the printed section + int PrintCombinedWM(System.Drawing.Printing.PrintPageEventArgs e, int wmNr1, int top) + { + IList results = Utils.GetSortedTestResults(procedure, unsortedResults, wmNr1); + + /// Determin column widths + float[] columnPos = new float[resultItems.Count + 1]; + columnPos[0] = 100.0f; + + for (int i = 0; i < resultItems.Count; i++) + { + float columnWidth = e.Graphics.MeasureString(resultItems[i].ClmnHeaderText, font).Width; + foreach (var tr in results) + { + if (tr != null) + { + float width = e.Graphics.MeasureString(resultItems[i].PrintCombined(tr.Meters[2 * wmNr1 - 2], + tr.Meters[2 * wmNr1 - 1], + tr.CombinedMeters[wmNr1 - 1]), font).Width; + if (width > columnWidth) columnWidth = width; + } + } + columnPos[i + 1] = columnPos[i] + columnWidth + 20.0f; + } + int tableLeftX = (int)columnPos[0]; + int tableRightX = (int)columnPos[resultItems.Count] - 20; + + string wmText = string.Format("Water meter {0}", wmNr1); + PrintAt(e, 100, top, wmText); + if (!string.IsNullOrEmpty(unsortedResults[0].Meters[2 * wmNr1 - 2].SerialNr)) + { + PrintAt(e, 100 + (int)e.Graphics.MeasureString(wmText, font).Width, top, + string.Format(" Main s/n: {0} Aux. s/n:{1}", + unsortedResults[0].Meters[2 * wmNr1 - 2].SerialNr, + unsortedResults[0].Meters[2 * wmNr1 - 1].SerialNr)); + } + + /// Horizontal line + int horY = top + 25; + e.Graphics.DrawLine(new Pen(Color.Black, 2), new Point(tableLeftX, horY), new Point(tableRightX, horY)); + + for (int i = 0; i < resultItems.Count; i++) + { + PrintAt(e, (int)columnPos[i], top + 27, resultItems[i].ClmnHeaderText); + } + + /// Horizontal line + horY = top + 27 + SpacingOne; + e.Graphics.DrawLine(new Pen(Color.Black, 2), new Point(tableLeftX, horY), new Point(tableRightX, horY)); + + for (int r = 0; r < results.Count; r++) + { + if (results[r] != null) + { + for (int i = 0; i < resultItems.Count; i++) + { + string text = resultItems[i].PrintCombined(results[r].Meters[2 * wmNr1 - 2], + results[r].Meters[2 * wmNr1 - 1], + results[r].CombinedMeters[wmNr1 - 1]); + string[] texts = text.Split(new char[] { '|' }); + + if (texts.Length == 2) + { + Color color = texts[1].Equals("Green") ? Color.Green : (texts[1].Equals("Red") ? Color.Red : Color.White); + text = texts[0]; + /// TODO: How to print colors? + } + + PrintAt(e, (int)columnPos[i], top + 30 + SpacingOne * (r + 1), text); + } + } + } + + /// Horizontal line + horY = top + 30 + SpacingOne * (results.Count + 1); + e.Graphics.DrawLine(new Pen(Color.Black, 2), new Point(tableLeftX, horY), new Point(tableRightX, horY)); + + return (results.Count + 4) * SpacingOne; + } + + + void PrintAt(System.Drawing.Printing.PrintPageEventArgs e, Point p, string text) + { + PrintAt(e, p.X, p.Y, text); + } + + void PrintAt(System.Drawing.Printing.PrintPageEventArgs e, int x, int y, string text) + { + RectangleF printArea = new RectangleF(x, y, 667, SpacingOne); + e.Graphics.DrawString(text, this.font, Brushes.Black, printArea); + } + + void PrintBoldAt(System.Drawing.Printing.PrintPageEventArgs e, Point p, string text) + { + PrintBoldAt(e, p.X, p.Y, text); + } + + void PrintBoldAt(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); + } + } +} diff --git a/TestBenchFramework/TBF.csproj b/TestBenchFramework/TBF.csproj index 4fc950397..c1cc2dcd1 100644 --- a/TestBenchFramework/TBF.csproj +++ b/TestBenchFramework/TBF.csproj @@ -132,6 +132,9 @@ + + Component + @@ -650,6 +653,12 @@ EmergencyStopForm.cs + + Form + + + PrintOrderForm.cs + Form @@ -1234,6 +1243,9 @@ EmergencyStopForm.cs + + PrintOrderForm.cs + ResultsConfig.cs