tbf/TBF/BenchControl/DataEntry/Munich/CycleEndForm.cs
2021-09-20 14:29:01 +02:00

207 lines
7.7 KiB
C#

///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Windows.Forms;
using log4net;
using TBF.Resources;
#pragma warning disable 162 /// Disables 'Unreachable code detected' warning
namespace TBF.BenchControl.DataEntry.Munich
{
public partial class CycleEndForm : Form, GenericDevices.IHasCompleted
{
private static readonly ILog log = LogManager.GetLogger(typeof(CycleEndForm));
// To be set before the form opens
public string ProtocolName1;
public string ProtocolName2;
public string ProtocolName3;
public string ProtocolName4;
// To be retrieved after the form closes
public string ProtocolTitle;
public string[] MainStateText;
public string[] AuxStateText;
public float[] QRise;
public float[] QFall;
public int[] YearOfProduction;
// Set to 'true' when the form closes
public bool Completed { get { return completed; } }
bool completed;
public CycleEndForm()
{
InitializeComponent();
ControlBox = false;
MainStateText = new string[TBF.Data.CompoundWMsCount];
AuxStateText = new string[TBF.Data.CompoundWMsCount];
QRise = new float[TBF.Data.CompoundWMsCount];
QFall = new float[TBF.Data.CompoundWMsCount];
YearOfProduction = new int[TBF.Data.CompoundWMsCount];
completed = false;
StartForceCloseHandler();
Localize();
}
void Localize()
{
Text = Strings.Data;
protocolGroupBox.Text = Strings.Protocol;
groupBox1.Text = Strings.Water_Meter + " 1";
mainState1Label.Text = Strings.Main_Water_Meter_State;
auxState1Label.Text = Strings.Aux_Water_Meter_State;
qRise1Label.Text = Strings.Qrise;
qFall1Label.Text = Strings.Qfall;
yearOfProduction1Label.Text = Strings.Year_of_production;
groupBox2.Text = Strings.Water_Meter + " 2";
mainState2Label.Text = Strings.Main_Water_Meter_State;
auxState2Label.Text = Strings.Aux_Water_Meter_State;
qRise2Label.Text = Strings.Qrise;
qFall2Label.Text = Strings.Qfall;
yearOfProduction2Label.Text = Strings.Year_of_production;
groupBox3.Text = Strings.Water_Meter + " 3";
mainState3Label.Text = Strings.Main_Water_Meter_State;
auxState3Label.Text = Strings.Aux_Water_Meter_State;
qRise3Label.Text = Strings.Qrise;
qFall3Label.Text = Strings.Qfall;
yearOfProduction3Label.Text = Strings.Year_of_production;
AnyRadioButtonChanged();
}
private void CycleEndForm_Load(object sender, EventArgs e)
{
radioButton1.Text = ProtocolName1;
radioButton2.Text = ProtocolName2;
radioButton3.Text = ProtocolName3;
radioButton4.Text = ProtocolName4;
if (Sequences.ProcessData.BatchRslts.Batch.WaterMeters.Count >= 1 && !Sequences.ProcessData.BatchRslts.Batch.WaterMeters[0].Disabled)
{
qRise1TextBox.Text = Utils.DoubleToStr(Sequences.ProcessData.BatchRslts.Batch.WaterMeters[0].QRise, 3);
qFall1TextBox.Text = Utils.DoubleToStr(Sequences.ProcessData.BatchRslts.Batch.WaterMeters[0].QFall, 3);
YearOfProduction[0] = Sequences.ProcessData.BatchRslts.Batch.WaterMeters[0].YearOfProduction;
yearOfProduction1TextBox.Text = YearOfProduction[0].ToString();
}
if (Sequences.ProcessData.BatchRslts.Batch.WaterMeters.Count >= 2 && !Sequences.ProcessData.BatchRslts.Batch.WaterMeters[1].Disabled)
{
qRise2TextBox.Text = Utils.DoubleToStr(Sequences.ProcessData.BatchRslts.Batch.WaterMeters[1].QRise, 3);
qFall2TextBox.Text = Utils.DoubleToStr(Sequences.ProcessData.BatchRslts.Batch.WaterMeters[1].QFall, 3);
YearOfProduction[1] = Sequences.ProcessData.BatchRslts.Batch.WaterMeters[1].YearOfProduction;
yearOfProduction2TextBox.Text = YearOfProduction[1].ToString();
}
else
{
groupBox2.Visible = false;
Height = 305;
}
if (Sequences.ProcessData.BatchRslts.Batch.WaterMeters.Count >= 3 && !Sequences.ProcessData.BatchRslts.Batch.WaterMeters[2].Disabled)
{
qRise3TextBox.Text = Utils.DoubleToStr(Sequences.ProcessData.BatchRslts.Batch.WaterMeters[2].QRise, 3);
qFall3TextBox.Text = Utils.DoubleToStr(Sequences.ProcessData.BatchRslts.Batch.WaterMeters[2].QFall, 3);
YearOfProduction[2] = Sequences.ProcessData.BatchRslts.Batch.WaterMeters[2].YearOfProduction;
yearOfProduction3TextBox.Text = YearOfProduction[2].ToString();
}
else
{
groupBox3.Visible = false;
}
}
private void okButton_Click(object sender, EventArgs e)
{
float ftmp;
int year;
bool allOK = true;
MainStateText[0] = mainState1TextBox.Text;
AuxStateText[0] = auxState1TextBox.Text;
if (Utils.TryParseUFloat(qRise1TextBox.Text, out ftmp)) { QRise[0] = ftmp; } else { allOK = false; }
if (Utils.TryParseUFloat(qFall1TextBox.Text, out ftmp)) { QFall[0] = ftmp; } else { allOK = false; }
if (ShowYear() && int.TryParse(yearOfProduction1TextBox.Text, out year))
{
YearOfProduction[0] = year;
}
if (TBF.Data.CompoundWMsCount >= 2)
{
MainStateText[1] = mainState2TextBox.Text;
AuxStateText[1] = auxState2TextBox.Text;
if (Utils.TryParseUFloat(qRise2TextBox.Text, out ftmp)) { QRise[1] = ftmp; } else { allOK = false; }
if (Utils.TryParseUFloat(qFall2TextBox.Text, out ftmp)) { QFall[1] = ftmp; } else { allOK = false; }
if (ShowYear() && int.TryParse(yearOfProduction2TextBox.Text, out year))
{
YearOfProduction[1] = year;
}
}
if (TBF.Data.CompoundWMsCount >= 3)
{
MainStateText[2] = mainState3TextBox.Text;
AuxStateText[2] = auxState3TextBox.Text;
if (Utils.TryParseUFloat(qRise3TextBox.Text, out ftmp)) { QRise[2] = ftmp; } else { allOK = false; }
if (Utils.TryParseUFloat(qFall3TextBox.Text, out ftmp)) { QFall[2] = ftmp; } else { allOK = false; }
if (ShowYear() && int.TryParse(yearOfProduction3TextBox.Text, out year))
{
YearOfProduction[2] = year;
}
}
if (radioButton1.Checked) ProtocolTitle = ProtocolName1;
else if (radioButton2.Checked) ProtocolTitle = ProtocolName2;
else if (radioButton3.Checked) ProtocolTitle = ProtocolName3;
else if (radioButton4.Checked) ProtocolTitle = ProtocolName4;
if (allOK)
{
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 radioButton1_CheckedChanged(object sender, EventArgs e) { AnyRadioButtonChanged(); }
private void radioButton2_CheckedChanged(object sender, EventArgs e) { AnyRadioButtonChanged(); }
private void radioButton3_CheckedChanged(object sender, EventArgs e) { AnyRadioButtonChanged(); }
private void radioButton4_CheckedChanged(object sender, EventArgs e) { AnyRadioButtonChanged(); }
bool ShowYear()
{
return radioButton2.Checked || radioButton3.Checked || radioButton4.Checked;
}
void AnyRadioButtonChanged()
{
yearOfProduction1TextBox.Visible = yearOfProduction2TextBox.Visible = yearOfProduction3TextBox.Visible =
yearOfProduction1Label.Visible = yearOfProduction2Label.Visible = yearOfProduction3Label.Visible = ShowYear();
}
}
}