Previous results : Possibility to save tracing records into a tracing DB (similarly to saving to Oracle).

This commit is contained in:
Milan Hanajik 2023-08-16 12:13:25 +02:00
parent 426bb0cce9
commit 78772df3a0
3 changed files with 147 additions and 58 deletions

View File

@ -280,51 +280,58 @@ namespace TBF.UI.ResultsMI
{ {
if (b.BatchNr == data.BatchNr) if (b.BatchNr == data.BatchNr)
{ {
#if ORACLE_DB
if (ProcessData.OracleDB == null)
{
MessageBox.Show("No database");
return;
}
var dlg = new SendAgainDBAndWMSelectionForm(); var dlg = new SendAgainDBAndWMSelectionForm();
if (dlg.ShowDialog() != DialogResult.OK) return; if (dlg.ShowDialog() != DialogResult.OK) return;
OracleConnection conn; bool isSuccessful = true;
switch (dlg.SelectedDB) #if ORACLE_DB
if (dlg.SaveToOracle)
{ {
default: if (ProcessData.OracleDB != null)
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")
{ {
docVersion = (cmp as TBF.Rig.Output.Printers.Munich.Printer).Version; OracleConnection conn;
break; 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 #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<PreviousResultIdEventArgs> ShowResultsHandler; public event EventHandler<PreviousResultIdEventArgs> ShowResultsHandler;

View File

@ -34,12 +34,16 @@
this.waterMetersComboBox = new System.Windows.Forms.ComboBox(); this.waterMetersComboBox = new System.Windows.Forms.ComboBox();
this.okButton = new System.Windows.Forms.Button(); this.okButton = new System.Windows.Forms.Button();
this.cancelButton = 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(); this.SuspendLayout();
// //
// databaseComboBox // databaseComboBox
// //
this.databaseComboBox.FormattingEnabled = true; 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.Name = "databaseComboBox";
this.databaseComboBox.Size = new System.Drawing.Size(163, 21); this.databaseComboBox.Size = new System.Drawing.Size(163, 21);
this.databaseComboBox.TabIndex = 0; this.databaseComboBox.TabIndex = 0;
@ -47,7 +51,7 @@
// databaseLabel // databaseLabel
// //
this.databaseLabel.AutoSize = true; 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.Name = "databaseLabel";
this.databaseLabel.Size = new System.Drawing.Size(53, 13); this.databaseLabel.Size = new System.Drawing.Size(53, 13);
this.databaseLabel.TabIndex = 1; this.databaseLabel.TabIndex = 1;
@ -56,7 +60,7 @@
// waterMetersLabel // waterMetersLabel
// //
this.waterMetersLabel.AutoSize = true; 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.Name = "waterMetersLabel";
this.waterMetersLabel.Size = new System.Drawing.Size(70, 13); this.waterMetersLabel.Size = new System.Drawing.Size(70, 13);
this.waterMetersLabel.TabIndex = 2; this.waterMetersLabel.TabIndex = 2;
@ -65,7 +69,7 @@
// waterMetersComboBox // waterMetersComboBox
// //
this.waterMetersComboBox.FormattingEnabled = true; 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.Name = "waterMetersComboBox";
this.waterMetersComboBox.Size = new System.Drawing.Size(163, 21); this.waterMetersComboBox.Size = new System.Drawing.Size(163, 21);
this.waterMetersComboBox.TabIndex = 3; this.waterMetersComboBox.TabIndex = 3;
@ -73,7 +77,7 @@
// okButton // okButton
// //
this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 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.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(92, 40); this.okButton.Size = new System.Drawing.Size(92, 40);
this.okButton.TabIndex = 4; this.okButton.TabIndex = 4;
@ -84,7 +88,7 @@
// cancelButton // cancelButton
// //
this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 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.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(92, 40); this.cancelButton.Size = new System.Drawing.Size(92, 40);
this.cancelButton.TabIndex = 5; this.cancelButton.TabIndex = 5;
@ -92,20 +96,54 @@
this.cancelButton.UseVisualStyleBackColor = true; this.cancelButton.UseVisualStyleBackColor = true;
this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); 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 // SendAgainDBAndWMSelectionForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 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.cancelButton);
this.Controls.Add(this.okButton); 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.Name = "SendAgainDBAndWMSelectionForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Database and water meter selection"; this.Text = "Database and water meter selection";
this.oracleDbGroupBox.ResumeLayout(false);
this.oracleDbGroupBox.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@ -119,5 +157,8 @@
private System.Windows.Forms.ComboBox waterMetersComboBox; private System.Windows.Forms.ComboBox waterMetersComboBox;
private System.Windows.Forms.Button okButton; private System.Windows.Forms.Button okButton;
private System.Windows.Forms.Button cancelButton; private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.GroupBox oracleDbGroupBox;
private System.Windows.Forms.CheckBox oracleDbCheckBox;
private System.Windows.Forms.CheckBox productionTracingCheckBox;
} }
} }

View File

@ -1,22 +1,28 @@
/// ///
/// Copyright (c) 2021 Sensus Slovensko a.s. /// Copyright (c) 2021-2023 Sensus Slovensko a.s.
/// ///
using System; using System;
using System.Windows.Forms; using System.Windows.Forms;
using TBF.Rig.Output.DB.SensusOracle; using TBF.Rig.Output.DB.SensusOracle;
using TBF.Resources; using TBF.Resources;
using System.Drawing;
namespace TBF.UI.ResultsMI namespace TBF.UI.ResultsMI
{ {
public partial class SendAgainDBAndWMSelectionForm : Form public partial class SendAgainDBAndWMSelectionForm : Form
{ {
public bool SaveToOracle;
public DBUsed SelectedDB; public DBUsed SelectedDB;
public WMKind SelectedWM; public WMKind SelectedWM;
public bool SaveToProductionTracing;
public SendAgainDBAndWMSelectionForm() public SendAgainDBAndWMSelectionForm()
{ {
InitializeComponent(); InitializeComponent();
ManageCheckGroupBox(oracleDbCheckBox, oracleDbGroupBox);
Localize(); Localize();
databaseComboBox.Items.Add(DBUsed.Production); databaseComboBox.Items.Add(DBUsed.Production);
@ -40,25 +46,40 @@ namespace TBF.UI.ResultsMI
private void okButton_Click(object sender, EventArgs e) 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; if (db.ToString() == databaseComboBox.Text)
for (WMKind wm = WMKind.iPERL; wm < WMKind.Count; wm++)
{ {
if (wm.ToString() == waterMetersComboBox.Text) SelectedDB = db;
for (WMKind wm = WMKind.iPERL; wm < WMKind.Count; wm++)
{ {
SelectedWM = wm; if (wm.ToString() == waterMetersComboBox.Text)
DialogResult = DialogResult.OK; {
Close(); SelectedWM = wm;
return; 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) private void cancelButton_Click(object sender, EventArgs e)
@ -66,5 +87,25 @@ namespace TBF.UI.ResultsMI
DialogResult = DialogResult.Cancel; DialogResult = DialogResult.Cancel;
Close(); 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);
}
} }
} }