136 lines
3.6 KiB
C#
136 lines
3.6 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 TBF.Resources;
|
|
|
|
namespace TBF.TestWizard
|
|
{
|
|
public partial class VolumeAndErrorSelection : Form
|
|
{
|
|
Entities.Test test;
|
|
|
|
public VolumeAndErrorSelection()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public VolumeAndErrorSelection(bool first, bool last, Entities.Test test)
|
|
: this()
|
|
{
|
|
this.test = test;
|
|
|
|
Text = Strings.Volume_and_error_selection;
|
|
volumeLabel.Text = Strings.Volume_ltr_chdr;
|
|
durationLabel.Text = Strings.Duration_s;
|
|
errLoPctLabel.Text = Strings.Err_limit_neg_pct_chdr;
|
|
errHiPctLabel.Text = Strings.Err_limit_pos_pct_chdr;
|
|
backButton.Text = Strings.BackBtnText;
|
|
nextButton.Text = Strings.FinishBtnText;
|
|
cancelButton.Text = Strings.CancelBtnText;
|
|
|
|
if (first) backButton.Visible = false;
|
|
if (last) nextButton.Text = Strings.FinishBtnText;
|
|
}
|
|
|
|
private void VolumeAndErrorSelection_Load(object sender, EventArgs e)
|
|
{
|
|
if (test == null) return;
|
|
|
|
RefreshWizardPage();
|
|
}
|
|
|
|
void RefreshWizardPage()
|
|
{
|
|
volumeTextBox.Text = test.Volume.ToString();
|
|
durationTextBox.Text = test.TstTime.ToString();
|
|
errLoPctTextBox.Text = test.ErrLimLo.ToString();
|
|
errHiPctTextBox.Text = test.ErrLimHi.ToString();
|
|
|
|
nextButton.Enabled = IsFormValid();
|
|
}
|
|
|
|
bool IsFormValid()
|
|
{
|
|
float dummy;
|
|
return Utils.TryParseUFloat(volumeTextBox.Text, out dummy) &&
|
|
Utils.TryParseUFloat(durationTextBox.Text, out dummy) &&
|
|
Utils.TryParseSFloat(errLoPctTextBox.Text, out dummy) &&
|
|
Utils.TryParseSFloat(errHiPctTextBox.Text, out dummy);
|
|
}
|
|
|
|
void UpdateTest()
|
|
{
|
|
test.Volume = Utils.ParseUFloat(volumeTextBox.Text);
|
|
test.TstTime = Utils.ParseUFloat(durationTextBox.Text);
|
|
test.ErrLimLo = Utils.ParseSFloat(errLoPctTextBox.Text);
|
|
test.ErrLimHi = Utils.ParseSFloat(errHiPctTextBox.Text);
|
|
}
|
|
|
|
private void backButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (test != null && IsFormValid()) UpdateTest();
|
|
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 volumeTextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
float Qave_lps = (test.Qfrom + test.Qto) / 7.2f;
|
|
float volume;
|
|
if (Utils.TryParseUFloat(volumeTextBox.Text, out volume))
|
|
{
|
|
durationTextBox.TextChanged -= new System.EventHandler(this.durationTextBox_TextChanged);
|
|
durationTextBox.Text = (volume / Qave_lps).ToString();
|
|
durationTextBox.TextChanged += new System.EventHandler(this.durationTextBox_TextChanged);
|
|
}
|
|
anyTextBox_TextChanged(sender, e);
|
|
}
|
|
|
|
private void durationTextBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
float Qave_lps = (test.Qfrom + test.Qto) / 7.2f;
|
|
float testTime;
|
|
if (Utils.TryParseUFloat(durationTextBox.Text, out testTime))
|
|
{
|
|
volumeTextBox.TextChanged -= new System.EventHandler(this.volumeTextBox_TextChanged);
|
|
volumeTextBox.Text = (testTime * Qave_lps).ToString();
|
|
volumeTextBox.TextChanged += new System.EventHandler(this.volumeTextBox_TextChanged);
|
|
}
|
|
anyTextBox_TextChanged(sender, e);
|
|
}
|
|
}
|
|
}
|