tbf/TBF/BenchControl/DataEntry/Munich3/CycleEndForm.cs

195 lines
8.0 KiB
C#

///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Windows.Forms;
using log4net;
using TBF.Resources;
namespace TBF.BenchControl.DataEntry.Munich3
{
public partial class CycleEndForm : Form, GenericDevices.IHasCompleted
{
private static readonly ILog log = LogManager.GetLogger(typeof(CycleEndForm));
/// <summary> Number of text boxes for serial numbers </summary>
public readonly int WaterMetersCount;
// 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[] EndStateText;
public int[] YearOfProduction;
// 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 CycleEndForm(int waterMetersCount)
{
InitializeComponent();
ControlBox = false;
this.WaterMetersCount = waterMetersCount;
EndStateText = new string[WaterMetersCount];
YearOfProduction = new int[WaterMetersCount];
completed = false;
StartForceCloseHandler();
}
/// <summary> Parameterless constructor for 3 watermeters </summary>
public CycleEndForm()
: this(3)
{
}
private void CycleEndForm_Load(object sender, EventArgs e)
{
Localize();
radioButton1.Text = ProtocolName1;
radioButton2.Text = ProtocolName2;
radioButton3.Text = ProtocolName3;
radioButton4.Text = ProtocolName4;
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 (Sequences.ProcessData.BatchRslts.Batch.WaterMeters.Count >= 1)
{
YearOfProduction[0] = Sequences.ProcessData.BatchRslts.Batch.WaterMeters[0].YearOfProduction;
yearOfProduction1TextBox.Text = YearOfProduction[0].ToString();
}
if (Sequences.ProcessData.BatchRslts.Batch.WaterMeters.Count >= 2)
{
YearOfProduction[1] = Sequences.ProcessData.BatchRslts.Batch.WaterMeters[1].YearOfProduction;
yearOfProduction2TextBox.Text = YearOfProduction[1].ToString();
}
if (Sequences.ProcessData.BatchRslts.Batch.WaterMeters.Count >= 3)
{
YearOfProduction[2] = Sequences.ProcessData.BatchRslts.Batch.WaterMeters[2].YearOfProduction;
yearOfProduction3TextBox.Text = YearOfProduction[2].ToString();
}
if (Sequences.ProcessData.BatchRslts.Batch.WaterMeters.Count >= 4)
{
YearOfProduction[3] = Sequences.ProcessData.BatchRslts.Batch.WaterMeters[3].YearOfProduction;
yearOfProduction4TextBox.Text = YearOfProduction[3].ToString();
}
if (Sequences.ProcessData.BatchRslts.Batch.WaterMeters.Count >= 5)
{
YearOfProduction[4] = Sequences.ProcessData.BatchRslts.Batch.WaterMeters[4].YearOfProduction;
yearOfProduction5TextBox.Text = YearOfProduction[4].ToString();
}
if (Sequences.ProcessData.BatchRslts.Batch.WaterMeters.Count >= 6)
{
YearOfProduction[5] = Sequences.ProcessData.BatchRslts.Batch.WaterMeters[5].YearOfProduction;
yearOfProduction6TextBox.Text = YearOfProduction[5].ToString();
}
Height = 228 + 90 * WaterMetersCount;
AnyRadioButtonChanged();
}
void Localize()
{
Text = Strings.Data;
protocolGroupBox.Text = Strings.Protocol;
okButton.Text = Strings.OkBtnText;
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 = label2.Text = label3.Text = label4.Text
= label5.Text = label6.Text = Strings.State;
yearOfProduction1Label.Text = yearOfProduction2Label.Text
= yearOfProduction3Label.Text = yearOfProduction4Label.Text
= yearOfProduction5Label.Text = yearOfProduction6Label.Text = Strings.Year_of_production;
}
private void okButton_Click(object sender, EventArgs e)
{
if (radioButton1.Checked) ProtocolTitle = ProtocolName1;
else if (radioButton2.Checked) ProtocolTitle = ProtocolName2;
else if (radioButton3.Checked) ProtocolTitle = ProtocolName3;
else if (radioButton4.Checked) ProtocolTitle = ProtocolName4;
if (WaterMetersCount >= 1) EndStateText[0] = textBox1.Text;
if (WaterMetersCount >= 2) EndStateText[1] = textBox2.Text;
if (WaterMetersCount >= 3) EndStateText[2] = textBox3.Text;
if (WaterMetersCount >= 4) EndStateText[3] = textBox4.Text;
if (WaterMetersCount >= 5) EndStateText[4] = textBox5.Text;
if (WaterMetersCount >= 6) EndStateText[5] = textBox6.Text;
if (ShowYear())
{
int year;
if (WaterMetersCount >= 1 && int.TryParse(yearOfProduction1TextBox.Text, out year)) YearOfProduction[0] = year;
if (WaterMetersCount >= 2 && int.TryParse(yearOfProduction2TextBox.Text, out year)) YearOfProduction[1] = year;
if (WaterMetersCount >= 3 && int.TryParse(yearOfProduction3TextBox.Text, out year)) YearOfProduction[2] = year;
if (WaterMetersCount >= 4 && int.TryParse(yearOfProduction4TextBox.Text, out year)) YearOfProduction[3] = year;
if (WaterMetersCount >= 5 && int.TryParse(yearOfProduction5TextBox.Text, out year)) YearOfProduction[4] = year;
if (WaterMetersCount >= 6 && int.TryParse(yearOfProduction6TextBox.Text, out year)) YearOfProduction[5] = year;
}
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 =
yearOfProduction4TextBox.Visible = yearOfProduction5TextBox.Visible = yearOfProduction6TextBox.Visible =
yearOfProduction1Label.Visible = yearOfProduction2Label.Visible = yearOfProduction3Label.Visible =
yearOfProduction4Label.Visible = yearOfProduction5Label.Visible = yearOfProduction6Label.Visible = ShowYear();
}
}
}