tbf/TestBenchFramework/TestWizard/FlowSelection.cs

114 lines
2.4 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
{
Test test;
IList<MetersPath> sensorPaths;
public FlowSelection()
{
InitializeComponent();
}
public FlowSelection(bool first, bool last,
Test test,
IList<MetersPath> sensorPaths)
: this()
{
this.test = test;
this.sensorPaths = sensorPaths;
Text = Strings.Flow_selection;
qFromLabel.Text = Strings.Q_from_m3h;
qToLabel.Text = Strings.Q_to_m3h;
sensorsLabel.Text = Strings.Sensors;
backButton.Text = Strings.BackBtnText;
nextButton.Text = Strings.NextBtnText;
cancelButton.Text = Strings.CancelBtnText;
if (first) backButton.Visible = false;
if (last) nextButton.Text = Strings.FinishBtnText;
}
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()
{
test.Qfrom = Utils.ParseUFloat(qFromTextBox.Text);
test.Qto = Utils.ParseUFloat(qToTextBox.Text);
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();
}
}
}