375 lines
14 KiB
C#
375 lines
14 KiB
C#
///
|
|
/// Copyright (c) 2019-2022 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
#if MANAGED
|
|
using Oracle.ManagedDataAccess.Client;
|
|
#else
|
|
using Oracle.DataAccess.Client;
|
|
#endif
|
|
using Common;
|
|
using Common.Forms;
|
|
using Config.Entities;
|
|
using Results.Output;
|
|
using TBF.Rig.GenericDevices;
|
|
using TBF.Rig.Output;
|
|
using TBF.Rig.Output.DB.SensusOracle;
|
|
using TBF.Resources;
|
|
using TBF.Rig.TestMethods.iPerlCommunication.iPerlHead;
|
|
|
|
namespace TBF.UI.Procedures.TestWizard
|
|
{
|
|
public partial class OracleWZTypSelection : Form
|
|
{
|
|
static readonly ILog log = LogManager.GetLogger(typeof(OracleWZTypSelection));
|
|
|
|
public IList<SensusTestInfo> SelectedTestInfos;
|
|
public int WMTypeId;
|
|
public string MetrolKlasse;
|
|
public string Zulasszeichen;
|
|
public double Q3;
|
|
public MeterType MeterType;
|
|
|
|
|
|
Procedure loadedProcedure;
|
|
IList<ITestMethod> testMethods;
|
|
|
|
TextBox uncertaintyTB;
|
|
ComboBox testMethodCB;
|
|
|
|
public OracleWZTypSelection(Procedure loadedProcedure, IList<ITestMethod> testMethods)
|
|
{
|
|
this.loadedProcedure = loadedProcedure;
|
|
this.testMethods = testMethods;
|
|
|
|
InitializeComponent();
|
|
|
|
Text = Strings.Method_selection;
|
|
backButton.Text = Strings.BackBtnText;
|
|
nextButton.Text = Strings.NextBtnText;
|
|
cancelButton.Text = Strings.CancelBtnText;
|
|
|
|
for (MeterType mt = 0; mt < MeterType.Count; mt++)
|
|
{
|
|
meterTypeComboBox.Items.Add(mt.ToString());
|
|
}
|
|
meterTypeComboBox.Text = MeterType.AutoDetect.ToString();
|
|
|
|
listViewEx.Columns.Add("ID", 30);
|
|
listViewEx.Columns.Add("Test name", 70);
|
|
listViewEx.Columns.Add("QBezeichnung", 85);
|
|
listViewEx.Columns.Add(string.Format("{0} [m3/h]", Strings.Q_from), 80);
|
|
listViewEx.Columns.Add(string.Format("{0} [m3/h]", Strings.Q_to), 70);
|
|
listViewEx.Columns.Add(Strings.Test_time_s_chdr, 70);
|
|
listViewEx.Columns.Add(string.Format("{0} [l]", Strings.Volume, 60));
|
|
listViewEx.Columns.Add(Strings.Err_limit_neg_pct_chdr, 80);
|
|
listViewEx.Columns.Add(Strings.Err_limit_pos_pct_chdr, 80);
|
|
listViewEx.Columns.Add(Strings.Uncertainty_pct_chdr, 85);
|
|
listViewEx.Columns.Add(Strings.Test_method, 200);
|
|
|
|
uncertaintyTB = new TextBox();
|
|
Controls.Add(uncertaintyTB);
|
|
|
|
testMethodCB = new ComboBox();
|
|
if (testMethods != null)
|
|
{
|
|
foreach (var tm in testMethods) testMethodCB.Items.Add(tm.Name);
|
|
}
|
|
Controls.Add(testMethodCB);
|
|
|
|
backButton.Visible = false;
|
|
nextButton.Enabled = false;
|
|
|
|
SelectedTestInfos = null;
|
|
}
|
|
|
|
private void OracleWZTypSelection_Load(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
bool IsFormValidForSearch()
|
|
{
|
|
if (idWZTypRadioButton.Checked)
|
|
{
|
|
int idummy;
|
|
return (int.TryParse(idWZTypTextBox.Text, out idummy) && (idummy > 0));
|
|
}
|
|
else
|
|
{
|
|
return (materialCodeTextBox.Text.Length == 25);
|
|
}
|
|
}
|
|
|
|
bool IsFormValid()
|
|
{
|
|
double dummy;
|
|
|
|
return IsFormValidForSearch() &&
|
|
(listViewEx.Items.Count > 0) &&
|
|
Utils.TryParseUDouble(q3TextBox.Text, out dummy) &&
|
|
!string.IsNullOrEmpty(metroClassTextBox.Text) &&
|
|
!string.IsNullOrEmpty(approvalTextBox.Text) &&
|
|
meterTypeComboBox.Items.Contains(meterTypeComboBox.Text);
|
|
}
|
|
|
|
private void idWZTypRadioButton_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (idWZTypRadioButton.Checked)
|
|
{
|
|
idWZTypTextBox.Enabled = true;
|
|
materialCodeTextBox.Enabled = false;
|
|
}
|
|
else
|
|
{
|
|
idWZTypTextBox.Enabled = false;
|
|
materialCodeTextBox.Enabled = true;
|
|
}
|
|
|
|
searchButton.Enabled = IsFormValidForSearch();
|
|
nextButton.Enabled = false;
|
|
}
|
|
|
|
private void wzTypTextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
searchButton.Enabled = IsFormValidForSearch();
|
|
nextButton.Enabled = false;
|
|
}
|
|
|
|
private void productCodeTextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
searchButton.Enabled = IsFormValidForSearch();
|
|
nextButton.Enabled = false;
|
|
}
|
|
|
|
private void backButton_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Retry;
|
|
Close();
|
|
}
|
|
|
|
private void nextButton_Click(object sender, EventArgs e)
|
|
{
|
|
MetrolKlasse = metroClassTextBox.Text;
|
|
Zulasszeichen = approvalTextBox.Text;
|
|
Q3 = Utils.ParseUDouble(q3TextBox.Text);
|
|
for (MeterType mt = 0; mt < MeterType.Count; mt++)
|
|
{
|
|
if (meterTypeComboBox.Text == mt.ToString())
|
|
{
|
|
MeterType = mt;
|
|
break;
|
|
}
|
|
}
|
|
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
}
|
|
|
|
private void cancelButton_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
private void searchButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (!IsFormValidForSearch())
|
|
{
|
|
MessageBox.Show("Invalid data");
|
|
nextButton.Enabled = false;
|
|
return;
|
|
}
|
|
|
|
bool found = ReadTestInfosFromOracle();
|
|
if (!found)
|
|
{
|
|
MessageBox.Show("No water meter specification found in Oracle");
|
|
}
|
|
|
|
nextButton.Enabled = IsFormValid();
|
|
}
|
|
|
|
bool ReadTestInfosFromOracle()
|
|
{
|
|
IList<string> wmTestNames = new List<string>();
|
|
StringBuilder procedureSignatureSB = new StringBuilder();
|
|
|
|
foreach (var t in loadedProcedure.Tests)
|
|
{
|
|
if (t.Publish != (byte)Publish.Never &&
|
|
t.Publish != (byte)Publish.Internal &&
|
|
t.IsRegular())
|
|
{
|
|
/// This is a regular test,
|
|
/// not an internal/unpublished test, neither an auto action test
|
|
wmTestNames.Add(Results.Utils.GetTestName(t.Name, 1, 1));
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
WMTypeId = int.Parse(idWZTypTextBox.Text);
|
|
|
|
int wmTypeRevision;
|
|
string wzTypStr;
|
|
string materialNr;
|
|
DateTime timeStamp;
|
|
string remark;
|
|
string testInfoName;
|
|
|
|
OracleConnection conn = new OracleConnection("Data Source=STARA01.WORLD;User Id=deltachef;Password=deltachef;");
|
|
conn.Open();
|
|
SelectedTestInfos = TBF.Rig.Sequences.ProcessData.OracleDB.GetOracleTestInfo(conn, WMTypeId,
|
|
out wmTypeRevision, out wzTypStr, out MetrolKlasse, out Zulasszeichen, out materialNr, out Q3, out timeStamp, out remark);
|
|
conn.Close();
|
|
|
|
SensusTestInfo[] completeTestInfos = SensusTestInfo.GetBestMatch(SelectedTestInfos, wmTestNames, out testInfoName);
|
|
foreach (var sti in SelectedTestInfos)
|
|
{
|
|
foreach (var cti in completeTestInfos) if (cti.PruefungsNrOpto == sti.PruefungsNrDB) sti.TestName = cti.TestName;
|
|
}
|
|
|
|
materialCodeTextBox.Text = materialNr;
|
|
revWZTypTextBox.Text = wmTypeRevision.ToString();
|
|
wzTypTextBox.Text = wzTypStr;
|
|
metroClassTextBox.Text = MetrolKlasse;
|
|
approvalTextBox.Text = Zulasszeichen;
|
|
q3TextBox.Text = Q3.ToString();
|
|
remarkTextBox.Text = remark;
|
|
timeStampTextBox.Text = timeStamp.ToString("dd.MM.yyyy HH:mm");
|
|
testInfoNameLabel.Text = testInfoName;
|
|
|
|
listViewEx.Items.Clear();
|
|
foreach (var ti in SelectedTestInfos)
|
|
{
|
|
double Qfrom, Qto;
|
|
switch (ti.Range)
|
|
{
|
|
case Range.R90_100:
|
|
Qfrom = 0.9 * ti.Flow;
|
|
Qto = ti.Flow;
|
|
break;
|
|
|
|
case Range.R95_105:
|
|
Qfrom = 0.95 * ti.Flow;
|
|
Qto = 1.05 * ti.Flow;
|
|
break;
|
|
|
|
case Range.R100_110:
|
|
Qfrom = ti.Flow;
|
|
Qto = 1.1 * ti.Flow;
|
|
break;
|
|
|
|
default:
|
|
Qfrom = Qto = ti.Flow;
|
|
break;
|
|
}
|
|
|
|
double volumeLtr = ti.TestTime * (Qfrom + Qto) / 7.2;
|
|
|
|
ListViewItem lvi = new ListViewItem(new string[] { ti.PruefungsNrDB.ToString(),
|
|
(string.IsNullOrEmpty(ti.TestName) ? string.Empty : ti.TestName),
|
|
ti.QBezeichnungDB,
|
|
Qfrom.ToString(),
|
|
Qto.ToString(),
|
|
ti.TestTime.ToString(),
|
|
volumeLtr.ToString(Common.Utils.SignificantDigitsToFmt(volumeLtr, 4)),
|
|
(ti.ErrLimLoFromDB - ti.Uncertainty).ToString(),
|
|
(ti.ErrLimHiFromDB + ti.Uncertainty).ToString(),
|
|
ti.Uncertainty.ToString(),
|
|
ti.TestMethod,
|
|
});
|
|
lvi.Tag = ti;
|
|
listViewEx.Items.Add(lvi);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
revWZTypTextBox.Text = string.Empty;
|
|
wzTypTextBox.Text = "No info found";
|
|
metroClassTextBox.Text = string.Empty;
|
|
approvalTextBox.Text = string.Empty;
|
|
q3TextBox.Text = string.Empty;
|
|
remarkTextBox.Text = string.Empty;
|
|
timeStampTextBox.Text = string.Empty;
|
|
testInfoNameLabel.Text = string.Empty;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private void listViewEx_SubItemClicked(object sender, SubItemEventArgs e)
|
|
{
|
|
if (e.SubItem == listViewEx.Columns.Count - 2)
|
|
{
|
|
/// Uncertainty column clicked (column before the last one)
|
|
listViewEx.StartEditing(uncertaintyTB, e.Item, e.SubItem);
|
|
}
|
|
else if (e.SubItem == listViewEx.Columns.Count - 1)
|
|
{
|
|
/// Test method column clicked (the last column)
|
|
listViewEx.StartEditing(testMethodCB, e.Item, e.SubItem);
|
|
}
|
|
}
|
|
|
|
private void listViewEx_SubItemEndEditing(object sender, SubItemEndEditingEventArgs e)
|
|
{
|
|
if (e.SubItem == listViewEx.Columns.Count - 2)
|
|
{
|
|
double uncertainty;
|
|
if (Utils.TryParseUDouble(e.DisplayText, out uncertainty))
|
|
{
|
|
/// Uncertainty OK
|
|
SensusTestInfo ti = e.Item.Tag as SensusTestInfo;
|
|
if (ti != null) ti.Uncertainty = uncertainty;
|
|
e.Item.SubItems[listViewEx.Columns.Count - 4].Text = (ti.ErrLimLoFromDB - ti.Uncertainty).ToString();
|
|
e.Item.SubItems[listViewEx.Columns.Count - 3].Text = (ti.ErrLimHiFromDB + ti.Uncertainty).ToString();
|
|
}
|
|
else
|
|
{
|
|
/// Uncertainty NOK -> revert changes
|
|
e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
|
e.Cancel = true;
|
|
return;
|
|
}
|
|
}
|
|
else if (e.SubItem == listViewEx.Columns.Count - 1)
|
|
{
|
|
if (testMethodCB.Items.Contains(e.DisplayText))
|
|
{
|
|
/// TestMethod OK
|
|
SensusTestInfo ti = e.Item.Tag as SensusTestInfo;
|
|
if (ti != null) ti.TestMethod = e.DisplayText;
|
|
}
|
|
else
|
|
{
|
|
/// TestMethod NOK -> revert changes
|
|
e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
|
e.Cancel = true;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void q3TextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
nextButton.Enabled = IsFormValid();
|
|
}
|
|
|
|
private void metroClassTextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
nextButton.Enabled = IsFormValid();
|
|
}
|
|
|
|
private void approvalTextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
nextButton.Enabled = IsFormValid();
|
|
}
|
|
}
|
|
}
|