From 12bd4e80ddded99b86af99a90ae8569be28232bd Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Tue, 15 Dec 2015 04:16:53 +0100 Subject: [PATCH] Many various changes. --- ResultsBrowser/DataDeposit.cs | 8 +- ResultsBrowser/LocalSettings.cs | 12 +- ResultsBrowser/MainWnd.Designer.cs | 236 +++++++++++++++++++++++---- ResultsBrowser/MainWnd.cs | 166 +++++++++++++++++-- ResultsBrowser/ResultsBrowser.csproj | 4 + ResultsBrowser/WaterMeterResult.cs | 5 +- 6 files changed, 377 insertions(+), 54 deletions(-) diff --git a/ResultsBrowser/DataDeposit.cs b/ResultsBrowser/DataDeposit.cs index e9be5b733..315a4f2cb 100644 --- a/ResultsBrowser/DataDeposit.cs +++ b/ResultsBrowser/DataDeposit.cs @@ -97,7 +97,7 @@ namespace ResultsBrowser foreach (var tr in selectedTestResults) QueryTestResults.Add(tr); } - static void AddWMResultsAvoidDuplicates(IList wmResults, bool resolveManually) + public static void AddWMResultsAvoidDuplicates(IList wmResults, bool resolveManually) { foreach (var wmr in wmResults) { @@ -127,5 +127,11 @@ namespace ResultsBrowser } } } + + public static void AddQueryToReport() + { + foreach (var wm in QueryWaterMeterResults) ReportWaterMeterResults.Add(wm); + QueryWaterMeterResults.Clear(); + } } } diff --git a/ResultsBrowser/LocalSettings.cs b/ResultsBrowser/LocalSettings.cs index 73dddf140..bbf9a0c3d 100644 --- a/ResultsBrowser/LocalSettings.cs +++ b/ResultsBrowser/LocalSettings.cs @@ -49,7 +49,17 @@ namespace ResultsBrowser [XmlIgnore] public int PurchaseOrderHistoryCount { get { return (PurchaseOrderHistory != null) ? PurchaseOrderHistory.Length : 0; } } - /// Report ocnfiguration + /// Procedure history + public string[] ProcedureHistory; + [XmlIgnore] + public int ProcedureHistoryCount { get { return (ProcedureHistory != null) ? ProcedureHistory.Length : 0; } } + + /// Report file name history + public string[] ReportFileNameHistory; + [XmlIgnore] + public int ReportFileNameHistoryCount { get { return (ReportFileNameHistory != null) ? ReportFileNameHistory.Length : 0; } } + + /// Report configuration public string[] ReportItems_Single; public string[] ReportItems_Compound; diff --git a/ResultsBrowser/MainWnd.Designer.cs b/ResultsBrowser/MainWnd.Designer.cs index f6bc82ad7..8e8fb9802 100644 --- a/ResultsBrowser/MainWnd.Designer.cs +++ b/ResultsBrowser/MainWnd.Designer.cs @@ -29,13 +29,13 @@ private void InitializeComponent() { this.queryButton = new System.Windows.Forms.Button(); - this.outputTextBox = new System.Windows.Forms.TextBox(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.removeFromQueryButton = new System.Windows.Forms.Button(); + this.addToReportButton = new System.Windows.Forms.Button(); this.resolveManuallyCheckBox = new System.Windows.Forms.CheckBox(); this.procedureGroupBox = new System.Windows.Forms.GroupBox(); this.procedureCheckBox = new System.Windows.Forms.CheckBox(); this.procedureComboBox = new System.Windows.Forms.ComboBox(); - this.configReportButton = new System.Windows.Forms.Button(); this.clearButton = new System.Windows.Forms.Button(); this.fromGroupBox = new System.Windows.Forms.GroupBox(); this.label2 = new System.Windows.Forms.Label(); @@ -46,6 +46,17 @@ this.purchaseOrderGroupBox = new System.Windows.Forms.GroupBox(); this.purchaseOrderCheckBox = new System.Windows.Forms.CheckBox(); this.purchaseOrderComboBox = new System.Windows.Forms.ComboBox(); + this.queryResultsListBox = new System.Windows.Forms.ListBox(); + this.configReportButton = new System.Windows.Forms.Button(); + this.splitContainer2 = new System.Windows.Forms.SplitContainer(); + this.splitContainer3 = new System.Windows.Forms.SplitContainer(); + this.removeFromReportButton = new System.Windows.Forms.Button(); + this.reportFileGroupBox = new System.Windows.Forms.GroupBox(); + this.browseFileButton = new System.Windows.Forms.Button(); + this.reportFileComboBox = new System.Windows.Forms.ComboBox(); + this.makeReportButton = new System.Windows.Forms.Button(); + this.addOracleDataButton = new System.Windows.Forms.Button(); + this.reportListBox = new System.Windows.Forms.ListBox(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -53,11 +64,20 @@ this.procedureGroupBox.SuspendLayout(); this.fromGroupBox.SuspendLayout(); this.purchaseOrderGroupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit(); + this.splitContainer2.Panel1.SuspendLayout(); + this.splitContainer2.Panel2.SuspendLayout(); + this.splitContainer2.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).BeginInit(); + this.splitContainer3.Panel1.SuspendLayout(); + this.splitContainer3.Panel2.SuspendLayout(); + this.splitContainer3.SuspendLayout(); + this.reportFileGroupBox.SuspendLayout(); this.SuspendLayout(); // // queryButton // - this.queryButton.Location = new System.Drawing.Point(15, 199); + this.queryButton.Location = new System.Drawing.Point(15, 162); this.queryButton.Name = "queryButton"; this.queryButton.Size = new System.Drawing.Size(108, 40); this.queryButton.TabIndex = 3; @@ -65,16 +85,6 @@ this.queryButton.UseVisualStyleBackColor = true; this.queryButton.Click += new System.EventHandler(this.queryButton_Click); // - // outputTextBox - // - this.outputTextBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.outputTextBox.Location = new System.Drawing.Point(0, 0); - this.outputTextBox.Multiline = true; - this.outputTextBox.Name = "outputTextBox"; - this.outputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.outputTextBox.Size = new System.Drawing.Size(767, 370); - this.outputTextBox.TabIndex = 4; - // // splitContainer1 // this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; @@ -86,9 +96,10 @@ // // splitContainer1.Panel1 // + this.splitContainer1.Panel1.Controls.Add(this.removeFromQueryButton); + this.splitContainer1.Panel1.Controls.Add(this.addToReportButton); this.splitContainer1.Panel1.Controls.Add(this.resolveManuallyCheckBox); this.splitContainer1.Panel1.Controls.Add(this.procedureGroupBox); - this.splitContainer1.Panel1.Controls.Add(this.configReportButton); this.splitContainer1.Panel1.Controls.Add(this.clearButton); this.splitContainer1.Panel1.Controls.Add(this.fromGroupBox); this.splitContainer1.Panel1.Controls.Add(this.queryButton); @@ -96,11 +107,31 @@ // // splitContainer1.Panel2 // - this.splitContainer1.Panel2.Controls.Add(this.outputTextBox); - this.splitContainer1.Size = new System.Drawing.Size(767, 624); - this.splitContainer1.SplitterDistance = 250; + this.splitContainer1.Panel2.Controls.Add(this.queryResultsListBox); + this.splitContainer1.Size = new System.Drawing.Size(604, 624); + this.splitContainer1.SplitterDistance = 220; this.splitContainer1.TabIndex = 5; // + // removeFromQueryButton + // + this.removeFromQueryButton.Location = new System.Drawing.Point(453, 162); + this.removeFromQueryButton.Name = "removeFromQueryButton"; + this.removeFromQueryButton.Size = new System.Drawing.Size(46, 40); + this.removeFromQueryButton.TabIndex = 9; + this.removeFromQueryButton.Text = "Delete"; + this.removeFromQueryButton.UseVisualStyleBackColor = true; + this.removeFromQueryButton.Click += new System.EventHandler(this.removeFromQueryButton_Click); + // + // addToReportButton + // + this.addToReportButton.Location = new System.Drawing.Point(558, 162); + this.addToReportButton.Name = "addToReportButton"; + this.addToReportButton.Size = new System.Drawing.Size(46, 40); + this.addToReportButton.TabIndex = 8; + this.addToReportButton.Text = ">>>"; + this.addToReportButton.UseVisualStyleBackColor = true; + this.addToReportButton.Click += new System.EventHandler(this.addToReportButton_Click); + // // resolveManuallyCheckBox // this.resolveManuallyCheckBox.AutoSize = true; @@ -140,19 +171,9 @@ this.procedureComboBox.Size = new System.Drawing.Size(201, 21); this.procedureComboBox.TabIndex = 0; // - // configReportButton - // - this.configReportButton.Location = new System.Drawing.Point(641, 26); - this.configReportButton.Name = "configReportButton"; - this.configReportButton.Size = new System.Drawing.Size(103, 47); - this.configReportButton.TabIndex = 5; - this.configReportButton.Text = "Configure Report"; - this.configReportButton.UseVisualStyleBackColor = true; - this.configReportButton.Click += new System.EventHandler(this.configReportButton_Click); - // // clearButton // - this.clearButton.Location = new System.Drawing.Point(149, 199); + this.clearButton.Location = new System.Drawing.Point(149, 162); this.clearButton.Name = "clearButton"; this.clearButton.Size = new System.Drawing.Size(108, 40); this.clearButton.TabIndex = 4; @@ -243,12 +264,142 @@ this.purchaseOrderComboBox.Size = new System.Drawing.Size(201, 21); this.purchaseOrderComboBox.TabIndex = 0; // + // queryResultsListBox + // + this.queryResultsListBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.queryResultsListBox.FormattingEnabled = true; + this.queryResultsListBox.Location = new System.Drawing.Point(0, 0); + this.queryResultsListBox.Name = "queryResultsListBox"; + this.queryResultsListBox.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple; + this.queryResultsListBox.Size = new System.Drawing.Size(604, 400); + this.queryResultsListBox.TabIndex = 0; + // + // configReportButton + // + this.configReportButton.Location = new System.Drawing.Point(334, 95); + this.configReportButton.Name = "configReportButton"; + this.configReportButton.Size = new System.Drawing.Size(103, 47); + this.configReportButton.TabIndex = 5; + this.configReportButton.Text = "Configure Report"; + this.configReportButton.UseVisualStyleBackColor = true; + this.configReportButton.Click += new System.EventHandler(this.configReportButton_Click); + // + // splitContainer2 + // + this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer2.Location = new System.Drawing.Point(0, 0); + this.splitContainer2.Name = "splitContainer2"; + // + // splitContainer2.Panel1 + // + this.splitContainer2.Panel1.Controls.Add(this.splitContainer1); + // + // splitContainer2.Panel2 + // + this.splitContainer2.Panel2.Controls.Add(this.splitContainer3); + this.splitContainer2.Size = new System.Drawing.Size(1284, 624); + this.splitContainer2.SplitterDistance = 604; + this.splitContainer2.TabIndex = 6; + // + // splitContainer3 + // + this.splitContainer3.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer3.FixedPanel = System.Windows.Forms.FixedPanel.Panel1; + this.splitContainer3.IsSplitterFixed = true; + this.splitContainer3.Location = new System.Drawing.Point(0, 0); + this.splitContainer3.Name = "splitContainer3"; + this.splitContainer3.Orientation = System.Windows.Forms.Orientation.Horizontal; + // + // splitContainer3.Panel1 + // + this.splitContainer3.Panel1.Controls.Add(this.removeFromReportButton); + this.splitContainer3.Panel1.Controls.Add(this.reportFileGroupBox); + this.splitContainer3.Panel1.Controls.Add(this.makeReportButton); + this.splitContainer3.Panel1.Controls.Add(this.addOracleDataButton); + this.splitContainer3.Panel1.Controls.Add(this.configReportButton); + // + // splitContainer3.Panel2 + // + this.splitContainer3.Panel2.Controls.Add(this.reportListBox); + this.splitContainer3.Size = new System.Drawing.Size(676, 624); + this.splitContainer3.SplitterDistance = 220; + this.splitContainer3.TabIndex = 6; + // + // removeFromReportButton + // + this.removeFromReportButton.Location = new System.Drawing.Point(58, 162); + this.removeFromReportButton.Name = "removeFromReportButton"; + this.removeFromReportButton.Size = new System.Drawing.Size(46, 40); + this.removeFromReportButton.TabIndex = 10; + this.removeFromReportButton.Text = "Delete"; + this.removeFromReportButton.UseVisualStyleBackColor = true; + this.removeFromReportButton.Click += new System.EventHandler(this.removeFromReportButton_Click); + // + // reportFileGroupBox + // + this.reportFileGroupBox.Controls.Add(this.browseFileButton); + this.reportFileGroupBox.Controls.Add(this.reportFileComboBox); + this.reportFileGroupBox.Location = new System.Drawing.Point(18, 14); + this.reportFileGroupBox.Name = "reportFileGroupBox"; + this.reportFileGroupBox.Size = new System.Drawing.Size(546, 63); + this.reportFileGroupBox.TabIndex = 8; + this.reportFileGroupBox.TabStop = false; + this.reportFileGroupBox.Text = "Report file name"; + // + // browseFileButton + // + this.browseFileButton.Location = new System.Drawing.Point(453, 22); + this.browseFileButton.Name = "browseFileButton"; + this.browseFileButton.Size = new System.Drawing.Size(75, 27); + this.browseFileButton.TabIndex = 2; + this.browseFileButton.Text = "Browse"; + this.browseFileButton.UseVisualStyleBackColor = true; + this.browseFileButton.Click += new System.EventHandler(this.browseFileButton_Click); + // + // reportFileComboBox + // + this.reportFileComboBox.FormattingEnabled = true; + this.reportFileComboBox.Location = new System.Drawing.Point(20, 25); + this.reportFileComboBox.Name = "reportFileComboBox"; + this.reportFileComboBox.Size = new System.Drawing.Size(414, 21); + this.reportFileComboBox.TabIndex = 1; + // + // makeReportButton + // + this.makeReportButton.Location = new System.Drawing.Point(443, 95); + this.makeReportButton.Name = "makeReportButton"; + this.makeReportButton.Size = new System.Drawing.Size(103, 47); + this.makeReportButton.TabIndex = 7; + this.makeReportButton.Text = "Make Report"; + this.makeReportButton.UseVisualStyleBackColor = true; + this.makeReportButton.Click += new System.EventHandler(this.makeReportButton_Click); + // + // addOracleDataButton + // + this.addOracleDataButton.Location = new System.Drawing.Point(225, 95); + this.addOracleDataButton.Name = "addOracleDataButton"; + this.addOracleDataButton.Size = new System.Drawing.Size(103, 47); + this.addOracleDataButton.TabIndex = 6; + this.addOracleDataButton.Text = "Add Oracle Data"; + this.addOracleDataButton.UseVisualStyleBackColor = true; + this.addOracleDataButton.Click += new System.EventHandler(this.addOracleDataButton_Click); + // + // reportListBox + // + this.reportListBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.reportListBox.FormattingEnabled = true; + this.reportListBox.Location = new System.Drawing.Point(0, 0); + this.reportListBox.Name = "reportListBox"; + this.reportListBox.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple; + this.reportListBox.Size = new System.Drawing.Size(676, 400); + this.reportListBox.TabIndex = 0; + // // MainWnd // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(767, 624); - this.Controls.Add(this.splitContainer1); + this.ClientSize = new System.Drawing.Size(1284, 624); + this.Controls.Add(this.splitContainer2); this.Name = "MainWnd"; this.Text = "Form1"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainWnd_FormClosing); @@ -256,7 +407,6 @@ this.splitContainer1.Panel1.ResumeLayout(false); this.splitContainer1.Panel1.PerformLayout(); this.splitContainer1.Panel2.ResumeLayout(false); - this.splitContainer1.Panel2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); this.splitContainer1.ResumeLayout(false); this.procedureGroupBox.ResumeLayout(false); @@ -265,14 +415,22 @@ this.fromGroupBox.PerformLayout(); this.purchaseOrderGroupBox.ResumeLayout(false); this.purchaseOrderGroupBox.PerformLayout(); + this.splitContainer2.Panel1.ResumeLayout(false); + this.splitContainer2.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit(); + this.splitContainer2.ResumeLayout(false); + this.splitContainer3.Panel1.ResumeLayout(false); + this.splitContainer3.Panel2.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).EndInit(); + this.splitContainer3.ResumeLayout(false); + this.reportFileGroupBox.ResumeLayout(false); this.ResumeLayout(false); } #endregion - private System.Windows.Forms.Button queryButton; - private System.Windows.Forms.TextBox outputTextBox; + private System.Windows.Forms.Button queryButton; private System.Windows.Forms.SplitContainer splitContainer1; private System.Windows.Forms.GroupBox fromGroupBox; private System.Windows.Forms.Label label2; @@ -289,6 +447,18 @@ private System.Windows.Forms.GroupBox procedureGroupBox; private System.Windows.Forms.CheckBox procedureCheckBox; private System.Windows.Forms.ComboBox procedureComboBox; + private System.Windows.Forms.SplitContainer splitContainer2; + private System.Windows.Forms.SplitContainer splitContainer3; + private System.Windows.Forms.Button addOracleDataButton; + private System.Windows.Forms.Button makeReportButton; + private System.Windows.Forms.ListBox queryResultsListBox; + private System.Windows.Forms.ListBox reportListBox; + private System.Windows.Forms.GroupBox reportFileGroupBox; + private System.Windows.Forms.Button browseFileButton; + private System.Windows.Forms.ComboBox reportFileComboBox; + private System.Windows.Forms.Button removeFromQueryButton; + private System.Windows.Forms.Button addToReportButton; + private System.Windows.Forms.Button removeFromReportButton; } } diff --git a/ResultsBrowser/MainWnd.cs b/ResultsBrowser/MainWnd.cs index e784ab27b..97bfeac08 100644 --- a/ResultsBrowser/MainWnd.cs +++ b/ResultsBrowser/MainWnd.cs @@ -3,9 +3,13 @@ /// using System; using System.Collections.Generic; +using System.IO; +using System.Text; using System.Windows.Forms; using log4net; using NHibernate; +using Oracle.DataAccess.Client; // ODP.NET Oracle managed provider +using Oracle.DataAccess.Types; using Config; using Config.Entities; @@ -26,7 +30,10 @@ namespace ResultsBrowser private void MainWnd_Load(object sender, EventArgs e) { - PreparePurchaseOrderCombo(purchaseOrderComboBox); + PrepareComboBoxHistory(Program.LocalSettings.PurchaseOrderHistory, purchaseOrderComboBox); + PrepareComboBoxHistory(Program.LocalSettings.ProcedureHistory, procedureComboBox); + PrepareComboBoxHistory(Program.LocalSettings.ReportFileNameHistory, reportFileComboBox); + ReportItems_Single = ResultItemSpec.FromStrArray(Program.LocalSettings.ReportItems_Single); ReportItems_Compound = ResultItemSpec.FromStrArray(Program.LocalSettings.ReportItems_Compound); purchaseOrderCheckBox.Checked = Program.LocalSettings.FilterPurchaseOrder; @@ -38,6 +45,9 @@ namespace ResultsBrowser private void MainWnd_FormClosing(object sender, FormClosingEventArgs e) { Program.LocalSettings.UpdateHistory(purchaseOrderComboBox.Text, ref Program.LocalSettings.PurchaseOrderHistory); + Program.LocalSettings.UpdateHistory(procedureComboBox.Text, ref Program.LocalSettings.PurchaseOrderHistory); + Program.LocalSettings.UpdateHistory(reportFileComboBox.Text, ref Program.LocalSettings.ReportFileNameHistory); + Program.LocalSettings.ReportItems_Single = ResultItemSpec.ToStrArray(ReportItems_Single); Program.LocalSettings.ReportItems_Compound = ResultItemSpec.ToStrArray(ReportItems_Compound); Program.LocalSettings.FilterPurchaseOrder = purchaseOrderCheckBox.Checked; @@ -47,16 +57,24 @@ namespace ResultsBrowser Program.LocalSettings.Save(); } + void RedrawLists() + { + queryResultsListBox.Items.Clear(); + foreach (var wmr in DataDeposit.QueryWaterMeterResults) queryResultsListBox.Items.Add(wmr); + + reportListBox.Items.Clear(); + foreach (var wmr in DataDeposit.ReportWaterMeterResults) reportListBox.Items.Add(wmr); + } + /// /// Load Purchase order combo box items from the LocalSettings PurchaseOrderHistory array /// /// Puchase order ComboBox - void PreparePurchaseOrderCombo(ComboBox comboBox) + void PrepareComboBoxHistory(string[] history, ComboBox comboBox) { - for (int i = 0; i < Program.LocalSettings.PurchaseOrderHistoryCount; i++) - { - comboBox.Items.Add(Program.LocalSettings.PurchaseOrderHistory[i]); - } + if (history == null || history.Length == 0) return; + + for (int i = 0; i < history.Length; i++) comboBox.Items.Add(history[i]); if (comboBox.Items.Count > 0) comboBox.Text = comboBox.Items[0].ToString(); } @@ -93,8 +111,8 @@ namespace ResultsBrowser { testResults = session.QueryOver() .WhereRestrictionOn(x => x.TimeStart) - .IsBetween(fromDateTimePicker.MinDate) - .And(toDateTimePicker.MaxDate) + .IsBetween(fromDateTimePicker.Value) + .And(toDateTimePicker.Value) .Where(x => (x.PurchaseOrder == purchaseOrderComboBox.Text)) .Where(x => (x.ProcedureName == procedureComboBox.Text)) .OrderBy(x => x.BatchNr).Desc @@ -104,8 +122,8 @@ namespace ResultsBrowser { testResults = session.QueryOver() .WhereRestrictionOn(x => x.TimeStart) - .IsBetween(fromDateTimePicker.MinDate) - .And(toDateTimePicker.MaxDate) + .IsBetween(fromDateTimePicker.Value) + .And(toDateTimePicker.Value) .Where(x => (x.ProcedureName == procedureComboBox.Text)) .OrderBy(x => x.BatchNr).Desc .List(); @@ -136,8 +154,8 @@ namespace ResultsBrowser { testResults = session.QueryOver() .WhereRestrictionOn(x => x.TimeStart) - .IsBetween(fromDateTimePicker.MinDate) - .And(toDateTimePicker.MaxDate) + .IsBetween(fromDateTimePicker.Value) + .And(toDateTimePicker.Value) .OrderBy(x => x.BatchNr).Desc .List(); } @@ -152,8 +170,8 @@ namespace ResultsBrowser { testResults = session.QueryOver() .WhereRestrictionOn(x => x.TimeStart) - .IsBetween(fromDateTimePicker.MinDate) - .And(toDateTimePicker.MaxDate) + .IsBetween(fromDateTimePicker.Value) + .And(toDateTimePicker.Value) .Where(x => (x.PurchaseOrder == purchaseOrderComboBox.Text)) .OrderBy(x => x.BatchNr).Desc .List(); @@ -162,7 +180,7 @@ namespace ResultsBrowser DataDeposit.ProcessQueryTestResults(testResults, resolveManuallyCheckBox.Checked); - foreach (var wm in DataDeposit.QueryWaterMeterResults) outputTextBox.Text += (wm.ToString() + Environment.NewLine); + foreach (var wm in DataDeposit.QueryWaterMeterResults) queryResultsListBox.Items.Add(wm.ToString()); } catch (Exception exc) { @@ -172,7 +190,7 @@ namespace ResultsBrowser private void clearButton_Click(object sender, EventArgs e) { - outputTextBox.Text = string.Empty; + queryResultsListBox.Items.Clear(); } private void configReportButton_Click(object sender, EventArgs e) @@ -191,5 +209,121 @@ namespace ResultsBrowser Program.LocalSettings.ReportItems_Compound = ResultItemSpec.ToStrArray(ReportItems_Compound); } } + + private void removeFromQueryButton_Click(object sender, EventArgs e) + { + /// Remove from the list (the last selected item first so that the indexes are not affected) + for (int i = queryResultsListBox.SelectedIndices.Count - 1; i >= 0; i--) + { + DataDeposit.QueryWaterMeterResults.RemoveAt(queryResultsListBox.SelectedIndices[i]); + } + + RedrawLists(); + } + + private void removeFromReportButton_Click(object sender, EventArgs e) + { + /// Remove from the list (the last selected item first so that the indexes are not affected) + for (int i = reportListBox.SelectedIndices.Count - 1; i >= 0; i--) + { + DataDeposit.ReportWaterMeterResults.RemoveAt(reportListBox.SelectedIndices[i]); + } + + RedrawLists(); + } + + private void addToReportButton_Click(object sender, EventArgs e) + { + DataDeposit.AddQueryToReport(); + RedrawLists(); + } + + + private void browseFileButton_Click(object sender, EventArgs e) + { + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Title = "Target file"; + if (dlg.ShowDialog() == DialogResult.OK) + { + reportFileComboBox.Text = dlg.FileName; + } + } + + private void addOracleDataButton_Click(object sender, EventArgs e) + { + /// Oracle database connection + OracleConnection conn = new OracleConnection("Data Source=STARA01.WORLD;User Id=deltachef;Password=deltachef;"); + conn.Open(); + + try + { + foreach (var wm in DataDeposit.ReportWaterMeterResults) + { + + IList serialNrExes = new List(); + { + OracleParameter parm = new OracleParameter(); + parm.OracleDbType = OracleDbType.Varchar2; + parm.Value = wm.SerialNr; /// PCB Nr. + + OracleCommand cmd1 = new OracleCommand("SELECT Zaehlernummer FROM VT_ZAEHLER_PD WHERE VT_Fernum = :1 AND ANBID = 4", conn); + cmd1.Parameters.Add(parm); + + OracleDataReader dr = cmd1.ExecuteReader(); + + if (dr.Read()) + { + wm.SerialNrEx = dr.GetInt32(0); + } + } + } + } + catch (Exception exc) + { + MessageBox.Show(string.Format("Error when querying Oracle database:\r\n{0}", exc.Message), + "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); + } + + conn.Close(); + + RedrawLists(); + } + + private void makeReportButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(reportFileComboBox.Text)) + { + MessageBox.Show("No report file selected.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return; + } + + if (ReportItems_Single == null || ReportItems_Single.Count == 0) + { + MessageBox.Show("Please, configure the report first", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return; + } + + using (TextWriter report = new StreamWriter(reportFileComboBox.Text, true)) + { + foreach (var wm in DataDeposit.ReportWaterMeterResults) + { + bool first = true; + StringBuilder sb = new StringBuilder(); + foreach (var mtr in wm.MeterTestResults) + { + foreach (var item in ReportItems_Single) + { + if (!first) sb.Append(';'); + else first = false; + + sb.Append(item.Print(mtr)); + } + } + report.WriteLine(sb); + } + } + + MessageBox.Show("Report saved", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); + } } } diff --git a/ResultsBrowser/ResultsBrowser.csproj b/ResultsBrowser/ResultsBrowser.csproj index 0acf44661..fab78d90e 100644 --- a/ResultsBrowser/ResultsBrowser.csproj +++ b/ResultsBrowser/ResultsBrowser.csproj @@ -57,6 +57,10 @@ False ..\packages\NHibernate.3.3.3.4001\lib\Net35\NHibernate.dll + + False + ..\packages\Oracle\Oracle.DataAccess.dll + diff --git a/ResultsBrowser/WaterMeterResult.cs b/ResultsBrowser/WaterMeterResult.cs index 299eedc05..2c5e21158 100644 --- a/ResultsBrowser/WaterMeterResult.cs +++ b/ResultsBrowser/WaterMeterResult.cs @@ -15,7 +15,7 @@ namespace ResultsBrowser /// Water meter data /// public string SerialNr; /// iPerl : This is PCB Number - public string SerialNrEx; /// iPerl : This is the serial number assigned later + public int SerialNrEx; /// iPerl : This is the serial number assigned later public int BenchId; public int BatchNr { get { return firstMeterTestResult.TestResult.BatchNr; } } public string PurchaseOrder { get { return firstMeterTestResult.TestResult.PurchaseOrder; } } @@ -44,7 +44,6 @@ namespace ResultsBrowser MeterTestResults.Add(firstMeterTestResult = meterTestResult); SerialNr = meterTestResult.SerialNr; - SerialNrEx = string.Empty; BenchId = benchId; TestStart = meterTestResult.TestResult.TimeStart; TestEnd = meterTestResult.TestResult.TimeEnd; @@ -78,7 +77,7 @@ namespace ResultsBrowser public override string ToString() { StringBuilder sb = new StringBuilder(80); - sb.AppendFormat("PCB:{0} s/n:{1} ", SerialNr, string.IsNullOrEmpty(SerialNrEx) ? "?" : SerialNrEx); + sb.AppendFormat("PCB:{0} s/n:{1} ", SerialNr, SerialNrEx); foreach (var tr in MeterTestResults) sb.AppendFormat(" {0}:{1}%", tr.TestResult.TestName, tr.VolumeErrorPct.ToString("F1")); sb.AppendFormat(" test start: {0} {1}", TestStart.ToShortDateString(), TestStart.ToShortTimeString());