/// /// Copyright (c) 2019 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using log4net; using Results.Entities; using TBF.Resources; namespace TBF.BenchControl.TestMethods.ManualEntry { public partial class ManualEntryForm : Form, GenericDevices.IHasCompleted { private static readonly ILog log = LogManager.GetLogger(typeof(ManualEntryForm)); /// /// Set to 'true' when the form closes /// public bool Completed { get { return completed; } } bool completed; MeterTestRslt meterTestRslt; string prompt; IList items; static string[] lastValues = new string[7]; GroupBox[] groupBoxes; Label[] labels; TextBox[] textBoxes; RadioButton[] yesRadioButtons; RadioButton[] noRadioButtons; /// /// Default constructor /// public ManualEntryForm() { InitializeComponent(); groupBoxes = new GroupBox[] { groupBox1, groupBox2, groupBox3, groupBox4, groupBox5, groupBox6, groupBox7 }; labels = new Label[] { label1, label2, label3, label4, label5, label6, label7 }; textBoxes = new TextBox[] { textBox1, textBox2, textBox3, textBox4, textBox5, textBox6, textBox7 }; yesRadioButtons = new RadioButton[] { yesRadioButton1, yesRadioButton2, yesRadioButton3, yesRadioButton4, yesRadioButton5, yesRadioButton6, yesRadioButton7 }; noRadioButtons = new RadioButton[] { noRadioButton1, noRadioButton2, noRadioButton3, noRadioButton4, noRadioButton5, noRadioButton6, noRadioButton7 }; ControlBox = false; completed = false; StartForceCloseHandler(); } /// /// Constructor /// /// Number of text boxes for serial numbers public ManualEntryForm(MeterTestRslt meterTestRslt, string prompt, IList items) : this() { this.meterTestRslt = meterTestRslt; this.prompt = prompt; this.items = items; Localize(); promptLabel.Text = prompt; if (items != null) { for (int i = 0; i < Math.Min(items.Count, groupBoxes.Length); i++) { labels[i].Text = items[i].Caption; groupBoxes[i].Visible = true; if (items[i].Quantity == Config.Quantity.Boolean) { textBoxes[i].Visible = false; yesRadioButtons[i].Visible = true; noRadioButtons[i].Visible = true; } else if (!string.IsNullOrEmpty(lastValues[i])) { textBoxes[i].Text = lastValues[i]; } } Height = 100 + 90 * items.Count; } } void Localize() { okButton.Text = Strings.OkBtnText; } private void yesRadioButton1_CheckedChanged(object sender, EventArgs e) { if (yesRadioButton1.Checked) textBox1.Text = true.ToString(); } private void yesRadioButton2_CheckedChanged(object sender, EventArgs e) { if (yesRadioButton2.Checked) textBox2.Text = true.ToString(); } private void yesRadioButton3_CheckedChanged(object sender, EventArgs e) { if (yesRadioButton3.Checked) textBox3.Text = true.ToString(); } private void yesRadioButton4_CheckedChanged(object sender, EventArgs e) { if (yesRadioButton4.Checked) textBox4.Text = true.ToString(); } private void yesRadioButton5_CheckedChanged(object sender, EventArgs e) { if (yesRadioButton5.Checked) textBox5.Text = true.ToString(); } private void yesRadioButton6_CheckedChanged(object sender, EventArgs e) { if (yesRadioButton6.Checked) textBox6.Text = true.ToString(); } private void yesRadioButton7_CheckedChanged(object sender, EventArgs e) { if (yesRadioButton7.Checked) textBox7.Text = true.ToString(); } private void noRadioButton1_CheckedChanged(object sender, EventArgs e) { if (noRadioButton1.Checked) textBox1.Text = false.ToString(); } private void noRadioButton2_CheckedChanged(object sender, EventArgs e) { if (noRadioButton2.Checked) textBox2.Text = false.ToString(); } private void noRadioButton3_CheckedChanged(object sender, EventArgs e) { if (noRadioButton3.Checked) textBox3.Text = false.ToString(); } private void noRadioButton4_CheckedChanged(object sender, EventArgs e) { if (noRadioButton4.Checked) textBox4.Text = false.ToString(); } private void noRadioButton5_CheckedChanged(object sender, EventArgs e) { if (noRadioButton5.Checked) textBox5.Text = false.ToString(); } private void noRadioButton6_CheckedChanged(object sender, EventArgs e) { if (noRadioButton6.Checked) textBox6.Text = false.ToString(); } private void noRadioButton7_CheckedChanged(object sender, EventArgs e) { if (noRadioButton7.Checked) textBox7.Text = false.ToString(); } private void okButton_Click(object sender, EventArgs e) { bool ok = true; if (items != null) { for (int i = 0; i < Math.Min(items.Count, groupBoxes.Length); i++) { bool isItemOK = items[i].Update(textBoxes[i].Text, meterTestRslt); if (isItemOK) { lastValues[i] = textBoxes[i].Text; } ok = (ok && isItemOK); } } if (ok) { completed = true; Close(); } } #region Forced close handling public void StartForceCloseHandler() { UiBridge.Bridge.CloseModelessFormHandler += delegate(object sender, EventArgs args) { if (InvokeRequired) { Invoke(new EventHandler(OnForceClose), sender, args); } else OnForceClose(sender, args); }; } void OnForceClose(object sender, EventArgs args) { DialogResult = DialogResult.Cancel; Close(); } #endregion } }