306 lines
11 KiB
C#
306 lines
11 KiB
C#
///
|
|
/// Copyright (c) 2013-2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.BenchControl.DataEntry.Standard6
|
|
{
|
|
public partial class CycleBeginningForm : Form, GenericDevices.IHasCompleted
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(CycleBeginningForm));
|
|
|
|
/// <summary> Number of text boxes for serial numbers </summary>
|
|
public readonly int WaterMetersCount;
|
|
|
|
/// To be retrieved after the form is closed
|
|
public string PurchaseOrder;
|
|
public string[] SNText;
|
|
public bool[] Disabled;
|
|
|
|
/// Set to 'true' when the form closes
|
|
public bool Completed { get { return completed; } }
|
|
bool completed;
|
|
|
|
IList<ComboBox> enabledComboBoxes;
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
|
|
public CycleBeginningForm(int waterMetersCount)
|
|
{
|
|
InitializeComponent();
|
|
ControlBox = false;
|
|
|
|
this.WaterMetersCount = waterMetersCount;
|
|
SNText = new string[WaterMetersCount];
|
|
Disabled = new bool[WaterMetersCount];
|
|
enabledComboBoxes = new List<ComboBox>();
|
|
|
|
Height = 147 + WaterMetersCount * 90;
|
|
|
|
completed = false;
|
|
StartForceCloseHandler();
|
|
}
|
|
|
|
/// <summary> Parameterless constructor for all watermeters </summary>
|
|
public CycleBeginningForm()
|
|
: this(Config.Data.WMsCount)
|
|
{
|
|
}
|
|
|
|
private void CycleBeginningForm_Load(object sender, EventArgs e)
|
|
{
|
|
Localize();
|
|
|
|
PrepareOrderCombo(orderComboBox);
|
|
|
|
if (Program.LocalSettings.LastSNTextsCount == WaterMetersCount)
|
|
{
|
|
if (WaterMetersCount >= 1) comboBox1.Items.Add(Program.LocalSettings.LastSNTexts[0]);
|
|
if (WaterMetersCount >= 2) comboBox2.Items.Add(Program.LocalSettings.LastSNTexts[1]);
|
|
if (WaterMetersCount >= 3) comboBox3.Items.Add(Program.LocalSettings.LastSNTexts[2]);
|
|
if (WaterMetersCount >= 4) comboBox4.Items.Add(Program.LocalSettings.LastSNTexts[3]);
|
|
if (WaterMetersCount >= 5) comboBox5.Items.Add(Program.LocalSettings.LastSNTexts[4]);
|
|
if (WaterMetersCount >= 6) comboBox6.Items.Add(Program.LocalSettings.LastSNTexts[5]);
|
|
}
|
|
|
|
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); }
|
|
|
|
Height = 147 + WaterMetersCount * 90;
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
Text = Strings.Data;
|
|
orderGroupBox.Text = Strings.Purchase_order;
|
|
|
|
groupBox1.Text = Strings.Water_Meter + " 1";
|
|
groupBox2.Text = Strings.Water_Meter + " 2";
|
|
groupBox3.Text = Strings.Water_Meter + " 3";
|
|
groupBox4.Text = Strings.Water_Meter + " 4";
|
|
groupBox5.Text = Strings.Water_Meter + " 5";
|
|
groupBox6.Text = Strings.Water_Meter + " 6";
|
|
|
|
label1.Text = Strings.Serial_Number;
|
|
label2.Text = Strings.Serial_Number;
|
|
label3.Text = Strings.Serial_Number;
|
|
label4.Text = Strings.Serial_Number;
|
|
label5.Text = Strings.Serial_Number;
|
|
label6.Text = Strings.Serial_Number;
|
|
|
|
okButton.Text = Strings.OkBtnText;
|
|
clearButton.Text = Strings.ClearBtnText;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load Purchase order combo box items from the LocalSettings PurchaseOrderHistory array
|
|
/// </summary>
|
|
/// <param name="orderComboBox">Puchase order ComboBox</param>
|
|
void PrepareOrderCombo(ComboBox orderComboBox)
|
|
{
|
|
for (int i = 0; i < Program.LocalSettings.PurchaseOrderHistoryCount; i++)
|
|
{
|
|
orderComboBox.Items.Add(Program.LocalSettings.PurchaseOrderHistory[i]);
|
|
}
|
|
|
|
if (orderComboBox.Items.Count > 0)
|
|
{
|
|
orderComboBox.Text = orderComboBox.Items[0].ToString();
|
|
}
|
|
}
|
|
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
{
|
|
PurchaseOrder = orderComboBox.Text;
|
|
Program.LocalSettings.UpdateHistory(orderComboBox.Text,
|
|
ref Program.LocalSettings.PurchaseOrderHistory
|
|
#if FUZHOU150 || FUZHOU300
|
|
, 20
|
|
#endif
|
|
);
|
|
|
|
Program.LocalSettings.LastSNTexts = SNText;
|
|
|
|
if (WaterMetersCount >= 1) { SNText[0] = comboBox1.Text; Disabled[0] = !checkBox1.Checked; }
|
|
if (WaterMetersCount >= 2) { SNText[1] = comboBox2.Text; Disabled[1] = !checkBox2.Checked; }
|
|
if (WaterMetersCount >= 3) { SNText[2] = comboBox3.Text; Disabled[2] = !checkBox3.Checked; }
|
|
if (WaterMetersCount >= 4) { SNText[3] = comboBox4.Text; Disabled[3] = !checkBox4.Checked; }
|
|
if (WaterMetersCount >= 5) { SNText[4] = comboBox5.Text; Disabled[4] = !checkBox5.Checked; }
|
|
if (WaterMetersCount >= 6) { SNText[5] = comboBox6.Text; Disabled[5] = !checkBox6.Checked; }
|
|
|
|
completed = true;
|
|
Close();
|
|
}
|
|
|
|
|
|
private void UpdateAllCombos()
|
|
{
|
|
if (WaterMetersCount >= 1)
|
|
{
|
|
comboBox1.Text = Program.LocalSettings.LastSNTexts[0];
|
|
checkBox1.Checked = !string.IsNullOrEmpty(comboBox1.Text);
|
|
}
|
|
if (WaterMetersCount >= 2)
|
|
{
|
|
comboBox2.Text = Program.LocalSettings.LastSNTexts[1];
|
|
checkBox2.Checked = !string.IsNullOrEmpty(comboBox2.Text);
|
|
}
|
|
if (WaterMetersCount >= 3)
|
|
{
|
|
comboBox3.Text = Program.LocalSettings.LastSNTexts[2];
|
|
checkBox3.Checked = !string.IsNullOrEmpty(comboBox3.Text);
|
|
}
|
|
if (WaterMetersCount >= 4)
|
|
{
|
|
comboBox4.Text = Program.LocalSettings.LastSNTexts[3];
|
|
checkBox4.Checked = !string.IsNullOrEmpty(comboBox4.Text);
|
|
}
|
|
if (WaterMetersCount >= 5)
|
|
{
|
|
comboBox5.Text = Program.LocalSettings.LastSNTexts[4];
|
|
checkBox5.Checked = !string.IsNullOrEmpty(comboBox5.Text);
|
|
}
|
|
if (WaterMetersCount >= 6)
|
|
{
|
|
comboBox6.Text = Program.LocalSettings.LastSNTexts[5];
|
|
checkBox6.Checked = !string.IsNullOrEmpty(comboBox6.Text);
|
|
}
|
|
}
|
|
|
|
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_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (Program.LocalSettings.LastSNTextsCount == WaterMetersCount)
|
|
{
|
|
if (comboBox2.Text.Equals(Program.LocalSettings.LastSNTexts[1]))
|
|
UpdateAllCombos();
|
|
}
|
|
}
|
|
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_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (Program.LocalSettings.LastSNTextsCount == WaterMetersCount)
|
|
{
|
|
if (comboBox4.Text.Equals(Program.LocalSettings.LastSNTexts[3]))
|
|
UpdateAllCombos();
|
|
}
|
|
}
|
|
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_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; }
|
|
if (WaterMetersCount >= 2) { comboBox2.Text = string.Empty; checkBox2.Checked = false; }
|
|
if (WaterMetersCount >= 3) { comboBox3.Text = string.Empty; checkBox3.Checked = false; }
|
|
if (WaterMetersCount >= 4) { comboBox4.Text = string.Empty; checkBox4.Checked = false; }
|
|
if (WaterMetersCount >= 5) { comboBox5.Text = string.Empty; checkBox5.Checked = false; }
|
|
if (WaterMetersCount >= 6) { comboBox6.Text = string.Empty; checkBox6.Checked = false; }
|
|
}
|
|
|
|
|
|
#region Forced close handling
|
|
|
|
public void StartForceCloseHandler()
|
|
{
|
|
UiBridge.Bridge.CloseModelessFormHandler += delegate(object sender, EventArgs args)
|
|
{
|
|
if (InvokeRequired) { Invoke(new EventHandler<EventArgs>(OnForceClose), sender, args); }
|
|
else OnForceClose(sender, args);
|
|
};
|
|
}
|
|
|
|
private void OnForceClose(object sender, EventArgs args)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
/// <summary>
|
|
/// Process a key press within any enabled text boxe
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
/// <param name="currentFocusOwner">TextBox control which received the event</param>
|
|
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 <enter> 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); }
|
|
}
|
|
}
|