461 lines
15 KiB
C#
461 lines
15 KiB
C#
///
|
|
/// Copyright (c) 2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.BenchControl.DataEntry.Standard24
|
|
{
|
|
public partial class TestStartEndForm : Form, GenericDevices.IHasCompleted
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(TestStartEndForm));
|
|
|
|
// Set to 'true' when the form closes
|
|
public bool Completed { get { return completed; } }
|
|
bool completed;
|
|
|
|
/// <summary> Number of text boxes for serial numbers </summary>
|
|
public readonly int WaterMetersCount;
|
|
|
|
readonly bool[] disabled;
|
|
|
|
// To be retrieved after the form closes
|
|
public float[] WMStartState;
|
|
|
|
// To be retrieved after the form closes
|
|
public readonly string[] WMStartStateStr;
|
|
|
|
// To be retrieved after the form closes
|
|
public float[] WMEndState;
|
|
|
|
bool endStates; /// false=start states, true=end states
|
|
float refVolume;
|
|
float warningLimLo; /// limit to display exclamation mark, typically 2x errLimLo
|
|
float warningLimHi; /// limit to display exclamation mark, typically 2x errLimHi
|
|
|
|
/// <summary>
|
|
/// Constructor to fill in start states
|
|
/// </summary>
|
|
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
|
|
public TestStartEndForm(int waterMetersCount, bool[] disabled)
|
|
{
|
|
endStates = false;
|
|
|
|
this.WaterMetersCount = waterMetersCount;
|
|
this.disabled = disabled;
|
|
|
|
InitializeComponent();
|
|
WMStartState = new float[waterMetersCount];
|
|
WMStartStateStr = new string[waterMetersCount];
|
|
completed = false;
|
|
StartForceCloseHandler();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructor to fill in end states
|
|
/// </summary>
|
|
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
|
|
public TestStartEndForm(int waterMetersCount, string[] wmStartStateStr, bool[] disabled,
|
|
float refVolume, float errLimLo, float errLimHi)
|
|
{
|
|
endStates = true;
|
|
|
|
this.WaterMetersCount = waterMetersCount;
|
|
this.WMStartStateStr = wmStartStateStr;
|
|
if (wmStartStateStr == null || wmStartStateStr.Length != waterMetersCount)
|
|
throw (new Exception("Invalid 'wmStartStateStr' argument"));
|
|
this.disabled = disabled;
|
|
this.refVolume = refVolume;
|
|
this.warningLimLo = 2 * errLimLo;
|
|
this.warningLimHi = 2 * errLimHi;
|
|
|
|
InitializeComponent();
|
|
WMEndState = new float[waterMetersCount];
|
|
completed = false;
|
|
StartForceCloseHandler();
|
|
}
|
|
|
|
/// <summary> Parameterless constructor for all watermeters </summary>
|
|
public TestStartEndForm()
|
|
: this(Program.WMsCount, null)
|
|
{
|
|
}
|
|
|
|
private void CycleEndForm_Load(object sender, EventArgs e)
|
|
{
|
|
Localize();
|
|
|
|
Height = 115 + 90 * WaterMetersCount;
|
|
|
|
if (WaterMetersCount < 1) { label1.Visible = startTextBox1.Visible = endTextBox1.Visible = false; }
|
|
if (WaterMetersCount < 2) { label2.Visible = startTextBox2.Visible = endTextBox2.Visible = false; }
|
|
if (WaterMetersCount < 3) { label3.Visible = startTextBox3.Visible = endTextBox3.Visible = false; }
|
|
if (WaterMetersCount < 4) { label4.Visible = startTextBox4.Visible = endTextBox4.Visible = false; }
|
|
if (WaterMetersCount < 5) { label5.Visible = startTextBox5.Visible = endTextBox5.Visible = false; }
|
|
if (WaterMetersCount < 6) { label6.Visible = startTextBox6.Visible = endTextBox6.Visible = false; }
|
|
|
|
if (endStates)
|
|
{
|
|
if (WaterMetersCount >= 1) startTextBox1.Text = WMStartStateStr[0];
|
|
if (WaterMetersCount >= 2) startTextBox2.Text = WMStartStateStr[1];
|
|
if (WaterMetersCount >= 3) startTextBox3.Text = WMStartStateStr[2];
|
|
if (WaterMetersCount >= 4) startTextBox4.Text = WMStartStateStr[3];
|
|
if (WaterMetersCount >= 5) startTextBox5.Text = WMStartStateStr[4];
|
|
if (WaterMetersCount >= 6) startTextBox6.Text = WMStartStateStr[5];
|
|
endTextBox1.Enabled = (disabled == null || disabled.Length < 1 || !disabled[0]);
|
|
endTextBox2.Enabled = (disabled == null || disabled.Length < 2 || !disabled[1]);
|
|
endTextBox3.Enabled = (disabled == null || disabled.Length < 3 || !disabled[2]);
|
|
endTextBox4.Enabled = (disabled == null || disabled.Length < 4 || !disabled[3]);
|
|
endTextBox5.Enabled = (disabled == null || disabled.Length < 5 || !disabled[4]);
|
|
endTextBox6.Enabled = (disabled == null || disabled.Length < 6 || !disabled[5]);
|
|
}
|
|
else
|
|
{
|
|
startTextBox1.Enabled = (disabled == null || disabled.Length < 1 || !disabled[0]);
|
|
startTextBox2.Enabled = (disabled == null || disabled.Length < 2 || !disabled[1]);
|
|
startTextBox3.Enabled = (disabled == null || disabled.Length < 3 || !disabled[2]);
|
|
startTextBox4.Enabled = (disabled == null || disabled.Length < 4 || !disabled[3]);
|
|
startTextBox5.Enabled = (disabled == null || disabled.Length < 5 || !disabled[4]);
|
|
startTextBox6.Enabled = (disabled == null || disabled.Length < 6 || !disabled[5]);
|
|
}
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
Text = Strings.Water_Meter_States;
|
|
label1.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.WMState;
|
|
label2.Text = Strings.WMState;
|
|
label3.Text = Strings.WMState;
|
|
label4.Text = Strings.WMState;
|
|
label5.Text = Strings.WMState;
|
|
label6.Text = Strings.WMState;
|
|
startLabel.Text = Strings.Start;
|
|
endLabel.Text = Strings.End;
|
|
okButton.Text = Strings.OkBtnText;
|
|
}
|
|
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (endStates)
|
|
{
|
|
if (endTextBox1.Enabled) WMEndState[0] = Utils.ParseUFloat(endTextBox1.Text);
|
|
if (endTextBox2.Enabled) WMEndState[1] = Utils.ParseUFloat(endTextBox2.Text);
|
|
if (endTextBox3.Enabled) WMEndState[2] = Utils.ParseUFloat(endTextBox3.Text);
|
|
if (endTextBox4.Enabled) WMEndState[3] = Utils.ParseUFloat(endTextBox4.Text);
|
|
if (endTextBox5.Enabled) WMEndState[4] = Utils.ParseUFloat(endTextBox5.Text);
|
|
if (endTextBox6.Enabled) WMEndState[5] = Utils.ParseUFloat(endTextBox6.Text);
|
|
}
|
|
else
|
|
{
|
|
if (startTextBox1.Enabled)
|
|
{
|
|
WMStartStateStr[0] = startTextBox1.Text;
|
|
WMStartState[0] = Utils.ParseUFloat(startTextBox1.Text);
|
|
}
|
|
if (startTextBox2.Enabled)
|
|
{
|
|
WMStartStateStr[1] = startTextBox2.Text;
|
|
WMStartState[1] = Utils.ParseUFloat(startTextBox2.Text);
|
|
}
|
|
if (startTextBox3.Enabled)
|
|
{
|
|
WMStartStateStr[2] = startTextBox3.Text;
|
|
WMStartState[2] = Utils.ParseUFloat(startTextBox3.Text);
|
|
}
|
|
if (startTextBox4.Enabled)
|
|
{
|
|
WMStartStateStr[3] = startTextBox4.Text;
|
|
WMStartState[3] = Utils.ParseUFloat(startTextBox4.Text);
|
|
}
|
|
if (startTextBox5.Enabled)
|
|
{
|
|
WMStartStateStr[4] = startTextBox5.Text;
|
|
WMStartState[4] = Utils.ParseUFloat(startTextBox5.Text);
|
|
}
|
|
if (startTextBox6.Enabled)
|
|
{
|
|
WMStartStateStr[5] = startTextBox6.Text;
|
|
WMStartState[5] = Utils.ParseUFloat(startTextBox6.Text);
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
return;
|
|
}
|
|
|
|
completed = true;
|
|
Close();
|
|
}
|
|
|
|
#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);
|
|
};
|
|
}
|
|
|
|
void OnForceClose(object sender, EventArgs args)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
#endregion
|
|
|
|
private void wmEndStateTextBox1_TextChanged(object sender, EventArgs e)
|
|
{
|
|
float err = 0;
|
|
try
|
|
{
|
|
float endState = Utils.ParseUFloat(endTextBox1.Text);
|
|
float startState = Utils.ParseUFloat(startTextBox1.Text);
|
|
err = 100.0f * (endState - startState - refVolume) / refVolume;
|
|
}
|
|
catch { };
|
|
|
|
exclamation1.Visible = (err < warningLimLo) || (warningLimHi < err);
|
|
}
|
|
|
|
private void wmEndStateTextBox2_TextChanged(object sender, EventArgs e)
|
|
{
|
|
float err = 0;
|
|
try
|
|
{
|
|
float endState = Utils.ParseUFloat(endTextBox2.Text);
|
|
float startState = Utils.ParseUFloat(startTextBox2.Text);
|
|
err = 100.0f * (endState - startState - refVolume) / refVolume;
|
|
}
|
|
catch { err = 1000.0f; };
|
|
|
|
exclamation2.Visible = (err < warningLimLo) || (warningLimHi < err);
|
|
}
|
|
|
|
private void wmEndStateTextBox3_TextChanged(object sender, EventArgs e)
|
|
{
|
|
float err = 0;
|
|
try
|
|
{
|
|
float endState = Utils.ParseUFloat(endTextBox3.Text);
|
|
float startState = Utils.ParseUFloat(startTextBox3.Text);
|
|
err = 100.0f * (endState - startState - refVolume) / refVolume;
|
|
}
|
|
catch { err = 1000.0f; };
|
|
|
|
exclamation3.Visible = (err < warningLimLo) || (warningLimHi < err);
|
|
}
|
|
|
|
private void wmEndStateTextBox4_TextChanged(object sender, EventArgs e)
|
|
{
|
|
float err = 0;
|
|
try
|
|
{
|
|
float endState = Utils.ParseUFloat(endTextBox4.Text);
|
|
float startState = Utils.ParseUFloat(startTextBox4.Text);
|
|
err = 100.0f * (endState - startState - refVolume) / refVolume;
|
|
}
|
|
catch { err = 1000.0f; };
|
|
|
|
exclamation4.Visible = (err < warningLimLo) || (warningLimHi < err);
|
|
}
|
|
|
|
private void wmEndStateTextBox5_TextChanged(object sender, EventArgs e)
|
|
{
|
|
float err = 0;
|
|
try
|
|
{
|
|
float endState = Utils.ParseUFloat(endTextBox5.Text);
|
|
float startState = Utils.ParseUFloat(startTextBox5.Text);
|
|
err = 100.0f * (endState - startState - refVolume) / refVolume;
|
|
}
|
|
catch { err = 1000.0f; };
|
|
|
|
exclamation5.Visible = (err < warningLimLo) || (warningLimHi < err);
|
|
}
|
|
|
|
private void wmEndStateTextBox6_TextChanged(object sender, EventArgs e)
|
|
{
|
|
float err = 0;
|
|
try
|
|
{
|
|
float endState = Utils.ParseUFloat(endTextBox6.Text);
|
|
float startState = Utils.ParseUFloat(startTextBox6.Text);
|
|
err = 100.0f * (endState - startState - refVolume) / refVolume;
|
|
}
|
|
catch { err = 1000.0f; };
|
|
|
|
exclamation6.Visible = (err < warningLimLo) || (warningLimHi < err);
|
|
}
|
|
|
|
private void wmStartStateTextBox1_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (e.KeyChar == '\r')
|
|
{
|
|
if (startTextBox2.Enabled) startTextBox2.Focus();
|
|
else if (startTextBox3.Enabled) startTextBox3.Focus();
|
|
else if (startTextBox4.Enabled) startTextBox4.Focus();
|
|
else if (startTextBox5.Enabled) startTextBox5.Focus();
|
|
else if (startTextBox6.Enabled) startTextBox6.Focus();
|
|
}
|
|
else if (e.KeyChar == '+') okButton_Click(sender, e);
|
|
}
|
|
|
|
private void wmStartStateTextBox2_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (e.KeyChar == '\r')
|
|
{
|
|
if (startTextBox3.Enabled) startTextBox3.Focus();
|
|
else if (startTextBox4.Enabled) startTextBox4.Focus();
|
|
else if (startTextBox5.Enabled) startTextBox5.Focus();
|
|
else if (startTextBox6.Enabled) startTextBox6.Focus();
|
|
else if (startTextBox1.Enabled) startTextBox1.Focus();
|
|
}
|
|
else if (e.KeyChar == '+') okButton_Click(sender, e);
|
|
}
|
|
|
|
private void wmStartStateTextBox3_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (e.KeyChar == '\r')
|
|
{
|
|
if (startTextBox4.Enabled) startTextBox4.Focus();
|
|
else if (startTextBox5.Enabled) startTextBox5.Focus();
|
|
else if (startTextBox6.Enabled) startTextBox6.Focus();
|
|
else if (startTextBox1.Enabled) startTextBox1.Focus();
|
|
else if (startTextBox2.Enabled) startTextBox2.Focus();
|
|
}
|
|
else if (e.KeyChar == '+') okButton_Click(sender, e);
|
|
}
|
|
|
|
private void wmStartStateTextBox4_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (e.KeyChar == '\r')
|
|
{
|
|
if (startTextBox5.Enabled) startTextBox5.Focus();
|
|
else if (startTextBox6.Enabled) startTextBox6.Focus();
|
|
else if (startTextBox1.Enabled) startTextBox1.Focus();
|
|
else if (startTextBox2.Enabled) startTextBox2.Focus();
|
|
else if (startTextBox3.Enabled) startTextBox3.Focus();
|
|
}
|
|
else if (e.KeyChar == '+') okButton_Click(sender, e);
|
|
}
|
|
|
|
private void wmStartStateTextBox5_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (e.KeyChar == '\r')
|
|
{
|
|
if (startTextBox6.Enabled) startTextBox6.Focus();
|
|
else if (startTextBox1.Enabled) startTextBox1.Focus();
|
|
else if (startTextBox2.Enabled) startTextBox2.Focus();
|
|
else if (startTextBox3.Enabled) startTextBox3.Focus();
|
|
else if (startTextBox4.Enabled) startTextBox4.Focus();
|
|
}
|
|
else if (e.KeyChar == '+') okButton_Click(sender, e);
|
|
}
|
|
|
|
private void wmStartStateTextBox6_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (e.KeyChar == '\r')
|
|
{
|
|
if (startTextBox1.Enabled) startTextBox1.Focus();
|
|
else if (startTextBox1.Enabled) startTextBox1.Focus();
|
|
else if (startTextBox3.Enabled) startTextBox3.Focus();
|
|
else if (startTextBox4.Enabled) startTextBox4.Focus();
|
|
else if (startTextBox5.Enabled) startTextBox5.Focus();
|
|
}
|
|
else if (e.KeyChar == '+') okButton_Click(sender, e);
|
|
}
|
|
|
|
private void wmEndStateTextBox1_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (e.KeyChar == '\r')
|
|
{
|
|
if (endTextBox2.Enabled) endTextBox2.Focus();
|
|
else if (endTextBox3.Enabled) endTextBox3.Focus();
|
|
else if (endTextBox4.Enabled) endTextBox4.Focus();
|
|
else if (endTextBox5.Enabled) endTextBox5.Focus();
|
|
else if (endTextBox6.Enabled) endTextBox6.Focus();
|
|
}
|
|
else if (e.KeyChar == '+') okButton_Click(sender, e);
|
|
}
|
|
|
|
private void wmEndStateTextBox2_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (e.KeyChar == '\r')
|
|
{
|
|
if (endTextBox3.Enabled) endTextBox3.Focus();
|
|
else if (endTextBox4.Enabled) endTextBox4.Focus();
|
|
else if (endTextBox5.Enabled) endTextBox5.Focus();
|
|
else if (endTextBox6.Enabled) endTextBox6.Focus();
|
|
else if (endTextBox1.Enabled) endTextBox1.Focus();
|
|
}
|
|
else if (e.KeyChar == '+') okButton_Click(sender, e);
|
|
}
|
|
|
|
private void wmEndStateTextBox3_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (e.KeyChar == '\r')
|
|
{
|
|
if (endTextBox4.Enabled) endTextBox4.Focus();
|
|
else if (endTextBox5.Enabled) endTextBox5.Focus();
|
|
else if (endTextBox6.Enabled) endTextBox6.Focus();
|
|
else if (endTextBox1.Enabled) endTextBox1.Focus();
|
|
else if (endTextBox2.Enabled) endTextBox2.Focus();
|
|
}
|
|
else if (e.KeyChar == '+') okButton_Click(sender, e);
|
|
}
|
|
|
|
private void wmEndStateTextBox4_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (e.KeyChar == '\r')
|
|
{
|
|
if (endTextBox5.Enabled) endTextBox5.Focus();
|
|
else if (endTextBox6.Enabled) endTextBox6.Focus();
|
|
else if (endTextBox1.Enabled) endTextBox1.Focus();
|
|
else if (endTextBox2.Enabled) endTextBox2.Focus();
|
|
else if (endTextBox3.Enabled) endTextBox3.Focus();
|
|
}
|
|
else if (e.KeyChar == '+') okButton_Click(sender, e);
|
|
}
|
|
|
|
private void wmEndStateTextBox5_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (e.KeyChar == '\r')
|
|
{
|
|
if (endTextBox6.Enabled) endTextBox6.Focus();
|
|
else if (endTextBox1.Enabled) endTextBox1.Focus();
|
|
else if (endTextBox2.Enabled) endTextBox2.Focus();
|
|
else if (endTextBox3.Enabled) endTextBox3.Focus();
|
|
else if (endTextBox4.Enabled) endTextBox4.Focus();
|
|
}
|
|
else if (e.KeyChar == '+') okButton_Click(sender, e);
|
|
}
|
|
|
|
private void wmEndStateTextBox6_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (e.KeyChar == '\r')
|
|
{
|
|
if (endTextBox1.Enabled) endTextBox1.Focus();
|
|
else if (endTextBox1.Enabled) endTextBox1.Focus();
|
|
else if (endTextBox3.Enabled) endTextBox3.Focus();
|
|
else if (endTextBox4.Enabled) endTextBox4.Focus();
|
|
else if (endTextBox5.Enabled) endTextBox5.Focus();
|
|
}
|
|
else if (e.KeyChar == '+') okButton_Click(sender, e);
|
|
}
|
|
}
|
|
}
|