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,16 +280,15 @@ 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;
bool isSuccessful = true;
#if ORACLE_DB
if (dlg.SaveToOracle)
{
if (ProcessData.OracleDB != null)
{
OracleConnection conn;
switch (dlg.SelectedDB)
{
@ -299,7 +298,30 @@ namespace TBF.UI.ResultsMI
case DBUsed.Test: conn = ProcessData.OracleDB.TestDB; break;
}
if (ProcessData.OracleDB.WriteResultsToDB(conn, b, dlg.SelectedWM, true) == Retv.OK)
isSuccessful = isSuccessful && (ProcessData.OracleDB.WriteResultsToDB(conn, b, dlg.SelectedWM, true) == Rig.Output.DB.SensusOracle.Retv.OK);
}
else
{
isSuccessful = false;
MessageBox.Show("No Oracle database");
}
}
#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
@ -307,21 +329,6 @@ namespace TBF.UI.ResultsMI
(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;
break;
}
}
foreach (var wm in b.WaterMeters)
{
new Results.Output.Printers.Munich.MunichPrintDocument(docVersion, wm, PageOrientation.Portrait).Print();
}
#endif
}
}
}

View File

@ -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;
}
}

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.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,6 +46,14 @@ namespace TBF.UI.ResultsMI
private void okButton_Click(object sender, EventArgs e)
{
bool isValid = true;
SaveToOracle = oracleDbCheckBox.Checked;
SaveToProductionTracing = productionTracingCheckBox.Checked;
if (SaveToOracle)
{
isValid = false;
for (DBUsed db = DBUsed.Production; db < DBUsed.Count; db++)
{
if (db.ToString() == databaseComboBox.Text)
@ -50,21 +64,48 @@ namespace TBF.UI.ResultsMI
if (wm.ToString() == waterMetersComboBox.Text)
{
SelectedWM = wm;
DialogResult = DialogResult.OK;
Close();
return;
isValid = true;
}
}
}
}
}
if (isValid)
{
DialogResult = DialogResult.OK;
Close();
}
else
{
MessageBox.Show("Invalid selection");
}
}
private void cancelButton_Click(object sender, EventArgs e)
{
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);
}
}
}