128 lines
3.1 KiB
C#
128 lines
3.1 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Senus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using Common;
|
|
using Config;
|
|
using Config.Entities;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.UI.Procedures.TestWizard
|
|
{
|
|
public partial class PressureSelection : Form
|
|
{
|
|
Test test;
|
|
Unit pressUnit;
|
|
|
|
public PressureSelection()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public PressureSelection(bool first, bool last, Test test)
|
|
: this()
|
|
{
|
|
this.test = test;
|
|
|
|
Text = Strings.Pressure_selection;
|
|
pressureLoLabel.Text = Strings.Pressure_lo_bar;
|
|
pressureHiLabel.Text = Strings.Pressure_hi_bar;
|
|
durationLabel.Text = Strings.Duration_s;
|
|
backButton.Text = Strings.BackBtnText;
|
|
nextButton.Text = Strings.NextBtnText;
|
|
cancelButton.Text = Strings.CancelBtnText;
|
|
|
|
if (first) backButton.Visible = false;
|
|
if (last) nextButton.Text = Strings.FinishBtnText;
|
|
|
|
for (Unit u = 0; u < Unit.Count; u++)
|
|
{
|
|
if (Units.IsPressure(u)) unitComboBox.Items.Add(u.ToDescription());
|
|
}
|
|
}
|
|
|
|
private void PressureSelection_Load(object sender, EventArgs e)
|
|
{
|
|
if (test == null) return;
|
|
|
|
pressUnit = test.PressUnit;
|
|
unitComboBox.Text = pressUnit.ToDescription();
|
|
|
|
RefreshWizardPage();
|
|
}
|
|
|
|
void RefreshWizardPage()
|
|
{
|
|
pressureLoTextBox.Text = Units.ConvertTo(pressUnit, (double)1.0f).ToString(); /// TODO: replace constants
|
|
pressureHiTextBox.Text = Units.ConvertTo(pressUnit, (double)2.0f).ToString();
|
|
durationTextBox.Text = 10.ToString();
|
|
nextButton.Enabled = IsFormValid();
|
|
}
|
|
|
|
void UpdateTest()
|
|
{
|
|
test.PressUnit = pressUnit;
|
|
/// TODO: complete
|
|
//test.Qfrom = Utils.ParseUFloat(pressureLoTextBox.Text);
|
|
//test.Qto = Utils.ParseUFloat(pressureHiTextBox.Text);
|
|
//test.TstTime = int.Parse(durationTextBox.Text);
|
|
}
|
|
|
|
bool IsFormValid()
|
|
{
|
|
float dummy;
|
|
int iDummy;
|
|
return Utils.TryParseSFloat(pressureLoTextBox.Text, out dummy) &&
|
|
Utils.TryParseSFloat(pressureHiTextBox.Text, out dummy) &&
|
|
int.TryParse(durationTextBox.Text, out iDummy);
|
|
}
|
|
|
|
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 unitComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
var newUnit = Units.FromDescription(unitComboBox.Text);
|
|
|
|
if (Units.IsPressure(newUnit))
|
|
{
|
|
pressUnit = newUnit;
|
|
}
|
|
}
|
|
|
|
private void unitComboBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
unitComboBox_SelectedIndexChanged(sender, e);
|
|
}
|
|
}
|
|
}
|