159 lines
4.7 KiB
C#
159 lines
4.7 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.BenchControl.DataEntry.Standard
|
|
{
|
|
public partial class TestEndForm : Form, GenericDevices.IHasCompleted
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(TestEndForm));
|
|
|
|
/// <summary> Number of text boxes for serial numbers </summary>
|
|
public readonly int WaterMetersCount;
|
|
public readonly Entities.UnitsVolume Units;
|
|
|
|
// To be retrieved after the form closes
|
|
public readonly string[] WMStartStateStr;
|
|
|
|
// To be retrieved after the form closes
|
|
public float[] WMEndState;
|
|
|
|
// Set to 'true' when the form closes
|
|
public bool Completed { get { return completed; } }
|
|
bool completed;
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
|
|
public TestEndForm(int waterMetersCount, Entities.UnitsVolume units, string[] wmStartStateStr)
|
|
{
|
|
this.WaterMetersCount = waterMetersCount;
|
|
this.Units = units;
|
|
this.WMStartStateStr = wmStartStateStr;
|
|
if (wmStartStateStr == null || wmStartStateStr.Length != WaterMetersCount)
|
|
throw (new Exception("Invalid 3rd argument"));
|
|
InitializeComponent();
|
|
WMEndState = new float[WaterMetersCount];
|
|
completed = false;
|
|
StartForceCloseHandler();
|
|
}
|
|
|
|
/// <summary> Parameterless constructor for all watermeters </summary>
|
|
public TestEndForm()
|
|
: this(Program.WMsCount, Entities.UnitsVolume.CubicMtr, new string[Program.WMsCount])
|
|
{
|
|
for (int i = 0; i < Program.WMsCount; i++) WMStartStateStr[i] = string.Empty;
|
|
}
|
|
|
|
private void CycleEndForm_Load(object sender, EventArgs e)
|
|
{
|
|
Localize();
|
|
|
|
Height = 95 + 90 * WaterMetersCount;
|
|
|
|
groupBox1.Visible = false;
|
|
groupBox2.Visible = false;
|
|
groupBox3.Visible = false;
|
|
groupBox4.Visible = false;
|
|
groupBox5.Visible = false;
|
|
groupBox6.Visible = false;
|
|
|
|
if (WaterMetersCount >= 1)
|
|
{
|
|
groupBox1.Visible = true;
|
|
wmStartStateTextBox1.Text = WMStartStateStr[0];
|
|
}
|
|
if (WaterMetersCount >= 2)
|
|
{
|
|
groupBox2.Visible = true;
|
|
wmStartStateTextBox2.Text = WMStartStateStr[1];
|
|
}
|
|
if (WaterMetersCount >= 3)
|
|
{
|
|
groupBox3.Visible = true;
|
|
wmStartStateTextBox3.Text = WMStartStateStr[2];
|
|
}
|
|
if (WaterMetersCount >= 4)
|
|
{
|
|
groupBox4.Visible = true;
|
|
wmStartStateTextBox4.Text = WMStartStateStr[3];
|
|
}
|
|
if (WaterMetersCount >= 5)
|
|
{
|
|
groupBox5.Visible = true;
|
|
wmStartStateTextBox5.Text = WMStartStateStr[4];
|
|
}
|
|
if (WaterMetersCount >= 6)
|
|
{
|
|
groupBox6.Visible = true;
|
|
wmStartStateTextBox6.Text = WMStartStateStr[5];
|
|
}
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
Text = Strings.Water_Meter_States;
|
|
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";
|
|
wmStateLabel1.Text = Strings.WMState;
|
|
wmStateLabel2.Text = Strings.WMState;
|
|
wmStateLabel3.Text = Strings.WMState;
|
|
wmStateLabel4.Text = Strings.WMState;
|
|
wmStateLabel5.Text = Strings.WMState;
|
|
wmStateLabel6.Text = Strings.WMState;
|
|
okButton.Text = Strings.OkBtnText;
|
|
}
|
|
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
/// Factor to convert the entered volume to liters
|
|
float factor = (Units == Entities.UnitsVolume.CubicMtr) ? 1000.0f : 1.0f;
|
|
|
|
if (WaterMetersCount >= 1) WMEndState[0] = factor * Utils.ParseUFloat(wmEndStateTextBox1.Text);
|
|
if (WaterMetersCount >= 2) WMEndState[1] = factor * Utils.ParseUFloat(wmEndStateTextBox2.Text);
|
|
if (WaterMetersCount >= 3) WMEndState[2] = factor * Utils.ParseUFloat(wmEndStateTextBox3.Text);
|
|
if (WaterMetersCount >= 4) WMEndState[3] = factor * Utils.ParseUFloat(wmEndStateTextBox4.Text);
|
|
if (WaterMetersCount >= 5) WMEndState[4] = factor * Utils.ParseUFloat(wmEndStateTextBox5.Text);
|
|
if (WaterMetersCount >= 6) WMEndState[5] = factor * Utils.ParseUFloat(wmEndStateTextBox6.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
|
|
}
|
|
}
|