From 4d81a40ddf40d7b2b0c89263948ab5c396b42368 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Sat, 23 May 2015 15:44:23 +0200 Subject: [PATCH] DataEntry.Standard - code clean-up, key to moves focus between fields in CycleBeginningForm --- .../Standard/CycleBeginningForm.Designer.cs | 6 + .../DataEntry/Standard/CycleBeginningForm.cs | 109 ++--- .../Standard/CycleBeginningForm.resx | 392 +++++++++++++----- 3 files changed, 363 insertions(+), 144 deletions(-) diff --git a/TestBenchFramework/BenchControl/DataEntry/Standard/CycleBeginningForm.Designer.cs b/TestBenchFramework/BenchControl/DataEntry/Standard/CycleBeginningForm.Designer.cs index 722344258..63c09465c 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Standard/CycleBeginningForm.Designer.cs +++ b/TestBenchFramework/BenchControl/DataEntry/Standard/CycleBeginningForm.Designer.cs @@ -95,6 +95,7 @@ namespace TBF.BenchControl.DataEntry.Standard this.comboBox1.Name = "comboBox1"; this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); this.comboBox1.TextChanged += new System.EventHandler(this.comboBox1_TextChanged); + this.comboBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.comboBox1_KeyPress); // // checkBox1 // @@ -124,6 +125,7 @@ namespace TBF.BenchControl.DataEntry.Standard this.comboBox2.Name = "comboBox2"; this.comboBox2.SelectedIndexChanged += new System.EventHandler(this.comboBox2_SelectedIndexChanged); this.comboBox2.TextChanged += new System.EventHandler(this.comboBox2_TextChanged); + this.comboBox2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.comboBox2_KeyPress); // // checkBox2 // @@ -154,6 +156,7 @@ namespace TBF.BenchControl.DataEntry.Standard this.comboBox3.Name = "comboBox3"; this.comboBox3.SelectedIndexChanged += new System.EventHandler(this.comboBox3_SelectedIndexChanged); this.comboBox3.TextChanged += new System.EventHandler(this.comboBox3_TextChanged); + this.comboBox3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.comboBox3_KeyPress); // // checkBox7 // @@ -189,6 +192,7 @@ namespace TBF.BenchControl.DataEntry.Standard this.comboBox4.Name = "comboBox4"; this.comboBox4.SelectedIndexChanged += new System.EventHandler(this.comboBox4_SelectedIndexChanged); this.comboBox4.TextChanged += new System.EventHandler(this.comboBox4_TextChanged); + this.comboBox4.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.comboBox4_KeyPress); // // checkBox4 // @@ -218,6 +222,7 @@ namespace TBF.BenchControl.DataEntry.Standard this.comboBox5.Name = "comboBox5"; this.comboBox5.SelectedIndexChanged += new System.EventHandler(this.comboBox5_SelectedIndexChanged); this.comboBox5.TextChanged += new System.EventHandler(this.comboBox5_TextChanged); + this.comboBox5.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.comboBox5_KeyPress); // // checkBox5 // @@ -247,6 +252,7 @@ namespace TBF.BenchControl.DataEntry.Standard this.comboBox6.Name = "comboBox6"; this.comboBox6.SelectedIndexChanged += new System.EventHandler(this.comboBox6_SelectedIndexChanged); this.comboBox6.TextChanged += new System.EventHandler(this.comboBox6_TextChanged); + this.comboBox6.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.comboBox6_KeyPress); // // checkBox6 // diff --git a/TestBenchFramework/BenchControl/DataEntry/Standard/CycleBeginningForm.cs b/TestBenchFramework/BenchControl/DataEntry/Standard/CycleBeginningForm.cs index 4be717be7..2678782ef 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Standard/CycleBeginningForm.cs +++ b/TestBenchFramework/BenchControl/DataEntry/Standard/CycleBeginningForm.cs @@ -2,6 +2,7 @@ /// Copyright (c) 2013-2015 Sensus Metering Systems /// using System; +using System.Collections.Generic; using System.Windows.Forms; using log4net; using TBF.Resources; @@ -24,6 +25,8 @@ namespace TBF.BenchControl.DataEntry.Standard public bool Completed { get { return completed; } } bool completed; + IList enabledComboBoxes; + /// /// Constructor /// @@ -35,6 +38,8 @@ namespace TBF.BenchControl.DataEntry.Standard SNText = new string[WaterMetersCount]; Disabled = new bool[WaterMetersCount]; completed = false; + enabledComboBoxes = new List(); + StartForceCloseHandler(); Height = 147 + WaterMetersCount * 90; @@ -62,12 +67,12 @@ namespace TBF.BenchControl.DataEntry.Standard if (WaterMetersCount >= 6) comboBox6.Items.Add(Program.LocalSettings.LastSNTexts[5]); } - if (WaterMetersCount < 1) groupBox1.Visible = false; - if (WaterMetersCount < 2) groupBox2.Visible = false; - if (WaterMetersCount < 3) groupBox3.Visible = false; - if (WaterMetersCount < 4) groupBox4.Visible = false; - if (WaterMetersCount < 5) groupBox5.Visible = false; - if (WaterMetersCount < 6) groupBox6.Visible = false; + if (WaterMetersCount < 1) { groupBox1.Visible = false; } else { enabledComboBoxes.Add(comboBox1); } + if (WaterMetersCount < 2) { groupBox2.Visible = false; } else { enabledComboBoxes.Add(comboBox2); } + if (WaterMetersCount < 3) { groupBox3.Visible = false; } else { enabledComboBoxes.Add(comboBox3); } + if (WaterMetersCount < 4) { groupBox4.Visible = false; } else { enabledComboBoxes.Add(comboBox4); } + if (WaterMetersCount < 5) { groupBox5.Visible = false; } else { enabledComboBoxes.Add(comboBox5); } + if (WaterMetersCount < 6) { groupBox6.Visible = false; } else { enabledComboBoxes.Add(comboBox6); } } void Localize() @@ -164,97 +169,63 @@ namespace TBF.BenchControl.DataEntry.Standard } } - private void comboBox1_TextChanged(object sender, EventArgs e) - { - checkBox1.Checked = true; - } + private void comboBox1_TextChanged(object sender, EventArgs e) { checkBox1.Checked = true; } + private void comboBox2_TextChanged(object sender, EventArgs e) { checkBox2.Checked = true; } + private void comboBox3_TextChanged(object sender, EventArgs e) { checkBox3.Checked = true; } + private void comboBox4_TextChanged(object sender, EventArgs e) { checkBox4.Checked = true; } + private void comboBox5_TextChanged(object sender, EventArgs e) { checkBox5.Checked = true; } + private void comboBox6_TextChanged(object sender, EventArgs e) { checkBox6.Checked = true; } + private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (Program.LocalSettings.LastSNTextsCount == WaterMetersCount) { if (comboBox1.Text.Equals(Program.LocalSettings.LastSNTexts[0])) - { UpdateAllCombos(); - } } } - - - private void comboBox2_TextChanged(object sender, EventArgs e) - { - checkBox2.Checked = true; - } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { if (Program.LocalSettings.LastSNTextsCount == WaterMetersCount) { if (comboBox2.Text.Equals(Program.LocalSettings.LastSNTexts[1])) - { UpdateAllCombos(); - } } } - - private void comboBox3_TextChanged(object sender, EventArgs e) - { - checkBox3.Checked = true; - } private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) { if (Program.LocalSettings.LastSNTextsCount == WaterMetersCount) { if (comboBox3.Text.Equals(Program.LocalSettings.LastSNTexts[2])) - { UpdateAllCombos(); - } } } - - private void comboBox4_TextChanged(object sender, EventArgs e) - { - checkBox4.Checked = true; - } private void comboBox4_SelectedIndexChanged(object sender, EventArgs e) { if (Program.LocalSettings.LastSNTextsCount == WaterMetersCount) { if (comboBox4.Text.Equals(Program.LocalSettings.LastSNTexts[3])) - { UpdateAllCombos(); - } } } - - private void comboBox5_TextChanged(object sender, EventArgs e) - { - checkBox5.Checked = true; - } - private void comboBox5_SelectedIndexChanged(object sender, EventArgs e) + private void comboBox5_SelectedIndexChanged(object sender, EventArgs e) { if (Program.LocalSettings.LastSNTextsCount == WaterMetersCount) { if (comboBox5.Text.Equals(Program.LocalSettings.LastSNTexts[4])) - { UpdateAllCombos(); - } } } - - private void comboBox6_TextChanged(object sender, EventArgs e) - { - checkBox6.Checked = true; - } private void comboBox6_SelectedIndexChanged(object sender, EventArgs e) { if (Program.LocalSettings.LastSNTextsCount == WaterMetersCount) { if (comboBox6.Text.Equals(Program.LocalSettings.LastSNTexts[5])) - { UpdateAllCombos(); - } } } + private void clearButton_Click(object sender, EventArgs e) { if (WaterMetersCount >= 1) { comboBox1.Text = string.Empty; checkBox1.Checked = false; } @@ -284,5 +255,43 @@ namespace TBF.BenchControl.DataEntry.Standard } #endregion - } + + + /// + /// Process a key press within any enabled text boxe + /// + /// + /// + /// TextBox control which received the event + private void ProcKeyPress(object sender, KeyPressEventArgs e, ComboBox currentFocusOwner) + { + if (e.KeyChar == '+') + { + /// Process '+' key ..... Form completed + okButton_Click(sender, e); + } + if (e.KeyChar == '\r') + { + /// Process key ..... Next text field + if (enabledComboBoxes.Count < 2) return; /// There is just one enabled textbox + + for (int i = 0; i < enabledComboBoxes.Count; i++) + { + if (enabledComboBoxes[i] == currentFocusOwner) + { + /// Change focus to the next enabled text box + enabledComboBoxes[(i + 1) % enabledComboBoxes.Count].Focus(); + return; + } + } + } + } + + private void comboBox1_KeyPress(object sndr, KeyPressEventArgs e) { ProcKeyPress(sndr, e, comboBox1); } + private void comboBox2_KeyPress(object sndr, KeyPressEventArgs e) { ProcKeyPress(sndr, e, comboBox2); } + private void comboBox3_KeyPress(object sndr, KeyPressEventArgs e) { ProcKeyPress(sndr, e, comboBox3); } + private void comboBox4_KeyPress(object sndr, KeyPressEventArgs e) { ProcKeyPress(sndr, e, comboBox4); } + private void comboBox5_KeyPress(object sndr, KeyPressEventArgs e) { ProcKeyPress(sndr, e, comboBox5); } + private void comboBox6_KeyPress(object sndr, KeyPressEventArgs e) { ProcKeyPress(sndr, e, comboBox6); } + } } diff --git a/TestBenchFramework/BenchControl/DataEntry/Standard/CycleBeginningForm.resx b/TestBenchFramework/BenchControl/DataEntry/Standard/CycleBeginningForm.resx index 9c8cab89a..5eb91cb2d 100644 --- a/TestBenchFramework/BenchControl/DataEntry/Standard/CycleBeginningForm.resx +++ b/TestBenchFramework/BenchControl/DataEntry/Standard/CycleBeginningForm.resx @@ -146,6 +146,69 @@ 8 + + comboBox1 + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 0 + + + checkBox1 + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 1 + + + label1 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox1 + + + 2 + + + Verdana, 14.25pt + + + 28, 110 + + + 444, 77 + + + 1 + + + Watermeter 1 + + + groupBox1 + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 7 + 187, 29 @@ -221,32 +284,68 @@ 2 - - Verdana, 14.25pt + + comboBox2 - - 28, 110 + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 444, 77 + + groupBox2 - + + 0 + + + checkBox2 + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox2 + + 1 - - Watermeter 1 + + label2 - - groupBox1 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + groupBox2 + + + 2 + + + Verdana, 14.25pt + + + 28, 200 + + + 444, 77 + + + 2 + + + Watermeter 2 + + + groupBox2 + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - - 7 + + 6 187, 29 @@ -327,32 +426,80 @@ 2 - - Verdana, 14.25pt + + comboBox3 - - 28, 200 + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 444, 77 + + groupBox3 - + + 0 + + + checkBox7 + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox3 + + + 1 + + + checkBox3 + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox3 + + 2 - - Watermeter 2 + + label3 - - groupBox2 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + groupBox3 + + + 3 + + + Verdana, 14.25pt + + + 28, 290 + + + 444, 77 + + + 3 + + + Watermeter 3 + + + groupBox3 + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - - 6 + + 5 187, 31 @@ -465,32 +612,68 @@ 3 - + + comboBox4 + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox4 + + + 0 + + + checkBox4 + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox4 + + + 1 + + + label4 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox4 + + + 2 + + Verdana, 14.25pt - - 28, 290 + + 28, 380 - + 444, 77 - - 3 + + 4 - - Watermeter 3 + + Watermeter 4 - - groupBox3 + + groupBox4 - + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - - 5 + + 4 187, 29 @@ -570,32 +753,68 @@ 2 - + + comboBox5 + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox5 + + + 0 + + + checkBox5 + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox5 + + + 1 + + + label5 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + groupBox5 + + + 2 + + Verdana, 14.25pt - - 28, 380 + + 28, 470 - + 444, 77 - - 4 + + 5 - - Watermeter 4 + + Watermeter 5 - - groupBox4 + + groupBox5 - + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + $this - - 4 + + 3 187, 29 @@ -675,33 +894,6 @@ 2 - - Verdana, 14.25pt - - - 28, 470 - - - 444, 77 - - - 5 - - - Watermeter 5 - - - groupBox5 - - - System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 3 - 187, 29 @@ -807,15 +999,6 @@ 2 - - 90, 31 - - - 260, 31 - - - 0 - orderComboBox @@ -855,6 +1038,27 @@ 1 + + 90, 31 + + + 260, 31 + + + 0 + + + orderComboBox + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + orderGroupBox + + + 0 + Verdana, 14.25pt