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 MethodSelection : Form { Entities.Test test; IList methods; IList sensorPaths; public MethodSelection() { InitializeComponent(); } public MethodSelection(Entities.Test test, IList methods, IList sensorPaths) : this() { this.test = test; this.methods = methods; this.sensorPaths = sensorPaths; } private void MethodSelection_Load(object sender, EventArgs e) { if (test == null) return; Text = Strings.Method_selection; testMethodLabel.Text = Strings.Test_method; sensorsLabel.Text = Strings.Sensors; backButton.Text = Strings.BackBtnText; nextButton.Text = Strings.NextBtnText; cancelButton.Text = Strings.CancelBtnText; foreach (var method in methods) testMethodComboBox.Items.Add(method.Cfg.Name); foreach (var path in sensorPaths) sensorsComboBox.Items.Add(path.Name); RefreshWizardPage(); } void RefreshWizardPage() { nextButton.Enabled = IsFormValid(); } void UpdateTest() { if (testMethodComboBox.Items.Contains(testMethodComboBox.Text)) { test.Method = testMethodComboBox.Text; } if (sensorsComboBox.Items.Contains(sensorsComboBox.Text)) { test.MetersPath = sensorsComboBox.Text; } } bool IsFormValid() { return testMethodComboBox.Items.Contains(testMethodComboBox.Text) && sensorsComboBox.Items.Contains(sensorsComboBox.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 testMethodComboBox_TextChanged(object sender, EventArgs e) { nextButton.Enabled = IsFormValid(); } private void sensorsComboBox_TextChanged(object sender, EventArgs e) { nextButton.Enabled = IsFormValid(); } } }