205 lines
5.8 KiB
C#
205 lines
5.8 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
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();
|
|
|
|
radioButton1.Checked = true;
|
|
radioButton2.Checked = false;
|
|
radioButton3.Checked = false;
|
|
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 Q1 = Utils.ParseUDouble(qFromTextBox.Text);
|
|
double Q2 = Utils.ParseUDouble(qToTextBox.Text);
|
|
|
|
switch (qSpec)
|
|
{
|
|
case QSpec.Qfrom_Qto:
|
|
test.Qfrom = (float)Q1;
|
|
test.Qto = (float)Q2;
|
|
break;
|
|
case QSpec.Q_dQ:
|
|
test.Qfrom = (float)(Q1 - Q2);
|
|
test.Qto = (float)(Q1 + Q2);
|
|
break;
|
|
case QSpec.Q_dPct:
|
|
test.Qfrom = (float)(Q1 * (1 - Q2 / 100.0f));
|
|
test.Qto = (float)(Q1 * (1 + Q2 / 100.0f));
|
|
break;
|
|
}
|
|
|
|
if (sensorsComboBox.Items.Contains(sensorsComboBox.Text))
|
|
{
|
|
test.MetersPath = sensorsComboBox.Text;
|
|
}
|
|
}
|
|
|
|
bool IsFormValid()
|
|
{
|
|
float dummy;
|
|
return Utils.TryParseUFloat(qFromTextBox.Text, out dummy) &&
|
|
Utils.TryParseUFloat(qToTextBox.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 radioButton1_CheckedChanged(object sender, EventArgs e) { if (radioButton1.Checked) ReadRadioButtons(); }
|
|
private void radioButton2_CheckedChanged(object sender, EventArgs e) { if (radioButton2.Checked) ReadRadioButtons(); }
|
|
private void radioButton3_CheckedChanged(object sender, EventArgs e) { if (radioButton3.Checked) ReadRadioButtons(); }
|
|
|
|
void ReadRadioButtons()
|
|
{
|
|
double Q1 = 0;
|
|
double Q2 = 0;
|
|
bool floatDataOk = Utils.TryParseUDouble(qFromTextBox.Text, out Q1)
|
|
&& Utils.TryParseUDouble(qToTextBox.Text, out Q2);
|
|
|
|
if (radioButton1.Checked)
|
|
{
|
|
if (floatDataOk && qSpec == QSpec.Q_dQ)
|
|
{
|
|
qFromTextBox.Text = (Q1 - Q2).ToString();
|
|
qToTextBox.Text = (Q1 + Q2).ToString();
|
|
}
|
|
else if (floatDataOk && qSpec == QSpec.Q_dPct)
|
|
{
|
|
qFromTextBox.Text = (Q1 * (1 - Q2 / 100.0)).ToString();
|
|
qToTextBox.Text = (Q1 * (1 + Q2 / 100.0)).ToString();
|
|
}
|
|
|
|
qSpec = QSpec.Qfrom_Qto;
|
|
qFromLabel.Text = Strings.Q_from_m3h;
|
|
qToLabel.Text = Strings.Q_to_m3h;
|
|
}
|
|
else if (radioButton2.Checked)
|
|
{
|
|
if (floatDataOk && qSpec == QSpec.Qfrom_Qto)
|
|
{
|
|
qFromTextBox.Text = ((Q1 + Q2) / 2.0).ToString();
|
|
qToTextBox.Text = ((Q2 - Q1) / 2.0).ToString();
|
|
}
|
|
else if (floatDataOk && qSpec == QSpec.Q_dPct)
|
|
{
|
|
qToTextBox.Text = (Q1 * Q2 / 100.0).ToString();
|
|
}
|
|
|
|
qSpec = QSpec.Q_dQ;
|
|
qFromLabel.Text = "Q [m3/h]";
|
|
qToLabel.Text = "dQ [m3/h]";
|
|
}
|
|
else if (radioButton3.Checked)
|
|
{
|
|
if (floatDataOk && qSpec == QSpec.Qfrom_Qto)
|
|
{
|
|
qFromTextBox.Text = ((Q1 + Q2) / 2.0).ToString();
|
|
qToTextBox.Text = (100.0 * (Q2 - Q1) / (Q1 + Q2)).ToString();
|
|
}
|
|
else if (floatDataOk && qSpec == QSpec.Q_dQ)
|
|
{
|
|
qToTextBox.Text = (100.0 * Q2 / Q1).ToString();
|
|
}
|
|
|
|
qSpec = QSpec.Q_dPct;
|
|
qFromLabel.Text = "Q [m3/h]";
|
|
qToLabel.Text = "dQ [%]";
|
|
}
|
|
}
|
|
}
|
|
}
|