diff --git a/TBF/UI/ResultsMI/PreviousResultsDlg.cs b/TBF/UI/ResultsMI/PreviousResultsDlg.cs index 14bc61f44..0cfd4ed90 100644 --- a/TBF/UI/ResultsMI/PreviousResultsDlg.cs +++ b/TBF/UI/ResultsMI/PreviousResultsDlg.cs @@ -280,51 +280,58 @@ namespace TBF.UI.ResultsMI { if (b.BatchNr == data.BatchNr) { -#if ORACLE_DB - if (ProcessData.OracleDB == null) - { - MessageBox.Show("No database"); - return; - } - var dlg = new SendAgainDBAndWMSelectionForm(); if (dlg.ShowDialog() != DialogResult.OK) return; - OracleConnection conn; - switch (dlg.SelectedDB) + bool isSuccessful = true; +#if ORACLE_DB + if (dlg.SaveToOracle) { - default: - case DBUsed.Production: conn = ProcessData.OracleDB.ProductionDB; break; - case DBUsed.Quality: conn = ProcessData.OracleDB.QualityDB; break; - case DBUsed.Test: conn = ProcessData.OracleDB.TestDB; break; - } - - if (ProcessData.OracleDB.WriteResultsToDB(conn, b, dlg.SelectedWM, true) == Retv.OK) - { - b.RsltsSent = true; /// Result was successfully sent - session.SaveOrUpdate(b); /// Update MySQL DB - session.Flush(); - (sender as PreviousResultCtrl).Sent = true; /// Update UI - Redraw(); - } -#elif MUNICH - string docVersion = string.Empty; - foreach (var cmp in TBF.Rig.StateMachine.Components) - { - if (cmp.ClassName == "Output.Printers.Munich") + if (ProcessData.OracleDB != null) { - docVersion = (cmp as TBF.Rig.Output.Printers.Munich.Printer).Version; - break; + OracleConnection conn; + switch (dlg.SelectedDB) + { + default: + case DBUsed.Production: conn = ProcessData.OracleDB.ProductionDB; break; + case DBUsed.Quality: conn = ProcessData.OracleDB.QualityDB; break; + case DBUsed.Test: conn = ProcessData.OracleDB.TestDB; break; + } + + isSuccessful = isSuccessful && (ProcessData.OracleDB.WriteResultsToDB(conn, b, dlg.SelectedWM, true) == Rig.Output.DB.SensusOracle.Retv.OK); + } + else + { + isSuccessful = false; + MessageBox.Show("No Oracle database"); } } - foreach (var wm in b.WaterMeters) - { - new Results.Output.Printers.Munich.MunichPrintDocument(docVersion, wm, PageOrientation.Portrait).Print(); - } #endif + + if (dlg.SaveToProductionTracing) + { + if (ProcessData.TracingDB != null) + { + isSuccessful = isSuccessful && (ProcessData.TracingDB.SaveTracingRecords(b) == Rig.Output.DB.ProductionTracing.Retv.OK); + } + else + { + isSuccessful = false; + MessageBox.Show("No production tracing database"); + } + } + + if (isSuccessful) + { + b.RsltsSent = true; /// Result was successfully sent + session.SaveOrUpdate(b); /// Update MySQL DB + session.Flush(); + (sender as PreviousResultCtrl).Sent = true; /// Update UI + Redraw(); + } } - } - } + } + } public event EventHandler ShowResultsHandler; diff --git a/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.Designer.cs b/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.Designer.cs index 4e41323a3..4e71a64fd 100644 --- a/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.Designer.cs +++ b/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.Designer.cs @@ -34,12 +34,16 @@ this.waterMetersComboBox = new System.Windows.Forms.ComboBox(); this.okButton = new System.Windows.Forms.Button(); this.cancelButton = new System.Windows.Forms.Button(); + this.oracleDbGroupBox = new System.Windows.Forms.GroupBox(); + this.oracleDbCheckBox = new System.Windows.Forms.CheckBox(); + this.productionTracingCheckBox = new System.Windows.Forms.CheckBox(); + this.oracleDbGroupBox.SuspendLayout(); this.SuspendLayout(); // // databaseComboBox // this.databaseComboBox.FormattingEnabled = true; - this.databaseComboBox.Location = new System.Drawing.Point(151, 27); + this.databaseComboBox.Location = new System.Drawing.Point(191, 17); this.databaseComboBox.Name = "databaseComboBox"; this.databaseComboBox.Size = new System.Drawing.Size(163, 21); this.databaseComboBox.TabIndex = 0; @@ -47,7 +51,7 @@ // databaseLabel // this.databaseLabel.AutoSize = true; - this.databaseLabel.Location = new System.Drawing.Point(36, 30); + this.databaseLabel.Location = new System.Drawing.Point(76, 20); this.databaseLabel.Name = "databaseLabel"; this.databaseLabel.Size = new System.Drawing.Size(53, 13); this.databaseLabel.TabIndex = 1; @@ -56,7 +60,7 @@ // waterMetersLabel // this.waterMetersLabel.AutoSize = true; - this.waterMetersLabel.Location = new System.Drawing.Point(36, 65); + this.waterMetersLabel.Location = new System.Drawing.Point(76, 48); this.waterMetersLabel.Name = "waterMetersLabel"; this.waterMetersLabel.Size = new System.Drawing.Size(70, 13); this.waterMetersLabel.TabIndex = 2; @@ -65,7 +69,7 @@ // waterMetersComboBox // this.waterMetersComboBox.FormattingEnabled = true; - this.waterMetersComboBox.Location = new System.Drawing.Point(151, 62); + this.waterMetersComboBox.Location = new System.Drawing.Point(191, 44); this.waterMetersComboBox.Name = "waterMetersComboBox"; this.waterMetersComboBox.Size = new System.Drawing.Size(163, 21); this.waterMetersComboBox.TabIndex = 3; @@ -73,7 +77,7 @@ // okButton // this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.okButton.Location = new System.Drawing.Point(106, 115); + this.okButton.Location = new System.Drawing.Point(261, 119); this.okButton.Name = "okButton"; this.okButton.Size = new System.Drawing.Size(92, 40); this.okButton.TabIndex = 4; @@ -84,7 +88,7 @@ // cancelButton // this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.cancelButton.Location = new System.Drawing.Point(222, 115); + this.cancelButton.Location = new System.Drawing.Point(377, 119); this.cancelButton.Name = "cancelButton"; this.cancelButton.Size = new System.Drawing.Size(92, 40); this.cancelButton.TabIndex = 5; @@ -92,20 +96,54 @@ this.cancelButton.UseVisualStyleBackColor = true; this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); // + // oracleDbGroupBox + // + this.oracleDbGroupBox.Controls.Add(this.oracleDbCheckBox); + this.oracleDbGroupBox.Controls.Add(this.waterMetersComboBox); + this.oracleDbGroupBox.Controls.Add(this.databaseComboBox); + this.oracleDbGroupBox.Controls.Add(this.databaseLabel); + this.oracleDbGroupBox.Controls.Add(this.waterMetersLabel); + this.oracleDbGroupBox.Location = new System.Drawing.Point(19, 13); + this.oracleDbGroupBox.Name = "oracleDbGroupBox"; + this.oracleDbGroupBox.Size = new System.Drawing.Size(417, 75); + this.oracleDbGroupBox.TabIndex = 6; + this.oracleDbGroupBox.TabStop = false; + // + // oracleDbCheckBox + // + this.oracleDbCheckBox.AutoSize = true; + this.oracleDbCheckBox.Location = new System.Drawing.Point(23, -1); + this.oracleDbCheckBox.Name = "oracleDbCheckBox"; + this.oracleDbCheckBox.Size = new System.Drawing.Size(115, 17); + this.oracleDbCheckBox.TabIndex = 7; + this.oracleDbCheckBox.Text = "Save to Oracle DB"; + this.oracleDbCheckBox.UseVisualStyleBackColor = true; + this.oracleDbCheckBox.CheckedChanged += new System.EventHandler(this.oracleDbCheckBox_CheckedChanged); + // + // productionTracingCheckBox + // + this.productionTracingCheckBox.AutoSize = true; + this.productionTracingCheckBox.Location = new System.Drawing.Point(42, 105); + this.productionTracingCheckBox.Name = "productionTracingCheckBox"; + this.productionTracingCheckBox.Size = new System.Drawing.Size(169, 17); + this.productionTracingCheckBox.TabIndex = 7; + this.productionTracingCheckBox.Text = "Save to production tracing DB"; + this.productionTracingCheckBox.UseVisualStyleBackColor = true; + // // SendAgainDBAndWMSelectionForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(347, 181); + this.ClientSize = new System.Drawing.Size(502, 181); + this.Controls.Add(this.productionTracingCheckBox); + this.Controls.Add(this.oracleDbGroupBox); this.Controls.Add(this.cancelButton); this.Controls.Add(this.okButton); - this.Controls.Add(this.waterMetersComboBox); - this.Controls.Add(this.waterMetersLabel); - this.Controls.Add(this.databaseLabel); - this.Controls.Add(this.databaseComboBox); this.Name = "SendAgainDBAndWMSelectionForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Database and water meter selection"; + this.oracleDbGroupBox.ResumeLayout(false); + this.oracleDbGroupBox.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -119,5 +157,8 @@ private System.Windows.Forms.ComboBox waterMetersComboBox; private System.Windows.Forms.Button okButton; private System.Windows.Forms.Button cancelButton; + private System.Windows.Forms.GroupBox oracleDbGroupBox; + private System.Windows.Forms.CheckBox oracleDbCheckBox; + private System.Windows.Forms.CheckBox productionTracingCheckBox; } } \ No newline at end of file diff --git a/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.cs b/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.cs index 991af7385..04ba978b6 100644 --- a/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.cs +++ b/TBF/UI/ResultsMI/SendAgainDBAndWMSelectionForm.cs @@ -1,22 +1,28 @@ /// -/// Copyright (c) 2021 Sensus Slovensko a.s. +/// Copyright (c) 2021-2023 Sensus Slovensko a.s. /// using System; using System.Windows.Forms; using TBF.Rig.Output.DB.SensusOracle; using TBF.Resources; +using System.Drawing; namespace TBF.UI.ResultsMI { public partial class SendAgainDBAndWMSelectionForm : Form { + public bool SaveToOracle; public DBUsed SelectedDB; public WMKind SelectedWM; + public bool SaveToProductionTracing; + public SendAgainDBAndWMSelectionForm() { InitializeComponent(); + ManageCheckGroupBox(oracleDbCheckBox, oracleDbGroupBox); + Localize(); databaseComboBox.Items.Add(DBUsed.Production); @@ -40,25 +46,40 @@ namespace TBF.UI.ResultsMI private void okButton_Click(object sender, EventArgs e) { - for (DBUsed db = DBUsed.Production; db < DBUsed.Count; db++) + bool isValid = true; + + SaveToOracle = oracleDbCheckBox.Checked; + SaveToProductionTracing = productionTracingCheckBox.Checked; + + if (SaveToOracle) { - if (db.ToString() == databaseComboBox.Text) + isValid = false; + for (DBUsed db = DBUsed.Production; db < DBUsed.Count; db++) { - SelectedDB = db; - for (WMKind wm = WMKind.iPERL; wm < WMKind.Count; wm++) + if (db.ToString() == databaseComboBox.Text) { - if (wm.ToString() == waterMetersComboBox.Text) + SelectedDB = db; + for (WMKind wm = WMKind.iPERL; wm < WMKind.Count; wm++) { - SelectedWM = wm; - DialogResult = DialogResult.OK; - Close(); - return; + if (wm.ToString() == waterMetersComboBox.Text) + { + SelectedWM = wm; + isValid = true; + } } } } } - MessageBox.Show("Invalid selection"); + if (isValid) + { + DialogResult = DialogResult.OK; + Close(); + } + else + { + MessageBox.Show("Invalid selection"); + } } private void cancelButton_Click(object sender, EventArgs e) @@ -66,5 +87,25 @@ namespace TBF.UI.ResultsMI DialogResult = DialogResult.Cancel; Close(); } + + + private void ManageCheckGroupBox(CheckBox chk, GroupBox grp) + { + /// Make sure the CheckBox isn't in the GroupBox. This will only happen the first time. + if (chk.Parent == grp) + { + grp.Parent.Controls.Add(chk); /// Reparent the CheckBox so it's not in the GroupBox. + chk.Location = new Point(chk.Left + grp.Left, chk.Top + grp.Top); /// Adjust the CheckBox's location. + chk.BringToFront(); /// Move the CheckBox to the top of the stacking order. + } + + /// Enable or disable the GroupBox. + grp.Enabled = chk.Checked; + } + + private void oracleDbCheckBox_CheckedChanged(object sender, EventArgs e) + { + ManageCheckGroupBox(oracleDbCheckBox, oracleDbGroupBox); + } } }