224 lines
7.0 KiB
C#
224 lines
7.0 KiB
C#
///
|
|
/// Copyright (c) 2013-2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using Config.Entities;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.TestWizard
|
|
{
|
|
public partial class FlowSelection : Form
|
|
{
|
|
enum QSpec
|
|
{
|
|
Qfrom_Qto,
|
|
Q_dQ,
|
|
Q_dPct
|
|
}
|
|
|
|
Test test;
|
|
IList<MetersPath> sensorPaths;
|
|
QSpec qSpec;
|
|
|
|
public FlowSelection()
|
|
{
|
|
InitializeComponent();
|
|
|
|
qSpec = QSpec.Qfrom_Qto;
|
|
|
|
Text = Strings.Flow_selection;
|
|
qFromLabel.Text = Strings.Q_from_m3h;
|
|
qToLabel.Text = Strings.Q_to_m3h;
|
|
sensorsLabel.Text = Strings.Sensors;
|
|
}
|
|
|
|
public FlowSelection(bool first, bool last,
|
|
Test test,
|
|
IList<MetersPath> sensorPaths)
|
|
: this()
|
|
{
|
|
this.test = test;
|
|
this.sensorPaths = sensorPaths;
|
|
|
|
if (first) backButton.Visible = false;
|
|
|
|
backButton.Text = Strings.BackBtnText;
|
|
nextButton.Text = last ? Strings.FinishBtnText : Strings.NextBtnText;
|
|
cancelButton.Text = Strings.CancelBtnText;
|
|
}
|
|
|
|
private void FlowSelection_Load(object sender, EventArgs e)
|
|
{
|
|
if (test == null) return;
|
|
|
|
foreach (var path in sensorPaths) sensorsComboBox.Items.Add(path.Name);
|
|
|
|
RefreshWizardPage();
|
|
}
|
|
|
|
void RefreshWizardPage()
|
|
{
|
|
qFromTextBox.Text = test.Qfrom.ToString();
|
|
qToTextBox.Text = test.Qto.ToString();
|
|
nextButton.Enabled = IsFormValid();
|
|
}
|
|
|
|
void UpdateTest()
|
|
{
|
|
double Q, dQ;
|
|
switch (qSpec)
|
|
{
|
|
default:
|
|
case QSpec.Qfrom_Qto:
|
|
test.Qfrom = (float)Utils.ParseUDouble(qFromTextBox.Text);
|
|
test.Qto = (float)Utils.ParseUDouble(qToTextBox.Text);
|
|
break;
|
|
|
|
case QSpec.Q_dQ:
|
|
Q = Utils.ParseUDouble(q2TextBox.Text);
|
|
dQ = Utils.ParseUDouble(dQTextBox.Text);
|
|
test.Qfrom = (float)(Q - dQ);
|
|
test.Qto = (float)(Q + dQ);
|
|
break;
|
|
|
|
case QSpec.Q_dPct:
|
|
Q = Utils.ParseUDouble(q3TextBox.Text);
|
|
dQ = Utils.ParseUDouble(dQpctTextBox.Text);
|
|
test.Qfrom = (float)(Q * (1 - dQ / 100.0f));
|
|
test.Qto = (float)(Q * (1 + dQ / 100.0f));
|
|
break;
|
|
}
|
|
|
|
if (sensorsComboBox.Items.Contains(sensorsComboBox.Text))
|
|
{
|
|
test.MetersPath = sensorsComboBox.Text;
|
|
}
|
|
}
|
|
|
|
bool IsFormValid()
|
|
{
|
|
float dummy;
|
|
switch (qSpec)
|
|
{
|
|
default:
|
|
case QSpec.Qfrom_Qto:
|
|
return Utils.TryParseUFloat(qFromTextBox.Text, out dummy) &&
|
|
Utils.TryParseUFloat(qToTextBox.Text, out dummy) &&
|
|
sensorsComboBox.Items.Contains(sensorsComboBox.Text);
|
|
|
|
case QSpec.Q_dQ:
|
|
return Utils.TryParseUFloat(q2TextBox.Text, out dummy) &&
|
|
Utils.TryParseUFloat(dQTextBox.Text, out dummy) &&
|
|
sensorsComboBox.Items.Contains(sensorsComboBox.Text);
|
|
|
|
case QSpec.Q_dPct:
|
|
return Utils.TryParseUFloat(q3TextBox.Text, out dummy) &&
|
|
Utils.TryParseUFloat(dQpctTextBox.Text, out dummy) &&
|
|
sensorsComboBox.Items.Contains(sensorsComboBox.Text);
|
|
}
|
|
}
|
|
|
|
private void backButton_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Retry;
|
|
Close();
|
|
}
|
|
|
|
private void nextButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (test != null && IsFormValid())
|
|
{
|
|
UpdateTest();
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
}
|
|
else
|
|
{
|
|
DialogResult = DialogResult.None;
|
|
}
|
|
}
|
|
|
|
private void cancelButton_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
private void anyTextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
nextButton.Enabled = IsFormValid();
|
|
}
|
|
|
|
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
double Q1,Q2;
|
|
|
|
switch ((QSpec)tabControl1.SelectedIndex)
|
|
{
|
|
default:
|
|
case QSpec.Qfrom_Qto:
|
|
if (qSpec == QSpec.Q_dQ &&
|
|
Utils.TryParseUDouble(q2TextBox.Text, out Q1) &&
|
|
Utils.TryParseUDouble(dQTextBox.Text, out Q2))
|
|
{
|
|
qFromTextBox.Text = (Q1 - Q2).ToString();
|
|
qToTextBox.Text = (Q1 + Q2).ToString();
|
|
}
|
|
else if (qSpec == QSpec.Q_dPct &&
|
|
Utils.TryParseUDouble(q3TextBox.Text, out Q1) &&
|
|
Utils.TryParseUDouble(dQpctTextBox.Text, out Q2))
|
|
{
|
|
qFromTextBox.Text = (Q1 * (1 - Q2 / 100.0)).ToString();
|
|
qToTextBox.Text = (Q1 * (1 + Q2 / 100.0)).ToString();
|
|
}
|
|
|
|
qSpec = QSpec.Qfrom_Qto;
|
|
break;
|
|
|
|
case QSpec.Q_dQ:
|
|
if (qSpec == QSpec.Qfrom_Qto &&
|
|
Utils.TryParseUDouble(qFromTextBox.Text, out Q1) &&
|
|
Utils.TryParseUDouble(qToTextBox.Text, out Q2))
|
|
{
|
|
q2TextBox.Text = ((Q1 + Q2) / 2.0).ToString();
|
|
dQTextBox.Text = ((Q2 - Q1) / 2.0).ToString();
|
|
}
|
|
else if (qSpec == QSpec.Q_dPct &&
|
|
Utils.TryParseUDouble(q3TextBox.Text, out Q1) &&
|
|
Utils.TryParseUDouble(dQpctTextBox.Text, out Q2))
|
|
{
|
|
q2TextBox.Text = q3TextBox.Text;
|
|
dQTextBox.Text = (Q1 * Q2 / 100.0).ToString();
|
|
}
|
|
|
|
qSpec = QSpec.Q_dQ;
|
|
break;
|
|
|
|
case QSpec.Q_dPct:
|
|
if (qSpec == QSpec.Qfrom_Qto &&
|
|
Utils.TryParseUDouble(qFromTextBox.Text, out Q1) &&
|
|
Utils.TryParseUDouble(qToTextBox.Text, out Q2))
|
|
{
|
|
q3TextBox.Text = ((Q1 + Q2) / 2.0).ToString();
|
|
dQpctTextBox.Text = (Q1 + Q2 != 0) ? (100.0 * (Q2 - Q1) / (Q1 + Q2)).ToString() : string.Empty;
|
|
}
|
|
else if (qSpec == QSpec.Q_dQ &&
|
|
Utils.TryParseUDouble(q2TextBox.Text, out Q1) &&
|
|
Utils.TryParseUDouble(dQTextBox.Text, out Q2) &&
|
|
Q1 != 0)
|
|
{
|
|
q3TextBox.Text = q2TextBox.Text;
|
|
dQpctTextBox.Text = (Q1 != 0) ? (100.0 * Q2 / Q1).ToString() : string.Empty;
|
|
}
|
|
|
|
qSpec = QSpec.Q_dPct;
|
|
break;
|
|
}
|
|
|
|
nextButton.Enabled = IsFormValid();
|
|
}
|
|
}
|
|
}
|