166 lines
4.9 KiB
C#
166 lines
4.9 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.BenchControl.DataEntry.StandardCamera
|
|
{
|
|
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;
|
|
readonly int lineSize;
|
|
|
|
// To be retrieved after the form closes
|
|
public string[] EndStateText;
|
|
|
|
// Set to 'true' when the form closes
|
|
public bool Completed { get { return completed; } }
|
|
bool completed;
|
|
|
|
int textBoxesCount;
|
|
Label[] labels;
|
|
TextBox[] textBoxes;
|
|
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
|
|
public CycleEndForm()
|
|
{
|
|
InitializeComponent();
|
|
ControlBox = false;
|
|
|
|
labels = new Label[]
|
|
{
|
|
label1, label2, label3, label4, label5, label6, label7, label8, label9, label10,
|
|
label11, label12, label13, label14, label15, label16, label17, label18, label19, label20,
|
|
label21, label22, label23, label24,
|
|
};
|
|
textBoxes = new TextBox[]
|
|
{
|
|
textBox1, textBox2, textBox3, textBox4, textBox5, textBox6,
|
|
textBox7, textBox8, textBox9, textBox10, textBox11, textBox12,
|
|
textBox13, textBox14, textBox15, textBox16, textBox17, textBox18,
|
|
textBox19, textBox20, textBox21, textBox22, textBox23, textBox24,
|
|
};
|
|
textBoxesCount = textBoxes.Length;
|
|
this.WaterMetersCount = textBoxesCount;
|
|
this.lineSize = textBoxesCount / 2;
|
|
|
|
completed = false;
|
|
StartForceCloseHandler();
|
|
}
|
|
|
|
/// <summary> Parameterless constructor for 3 watermeters </summary>
|
|
public CycleEndForm(int waterMetersCount, int lineSize)
|
|
: this()
|
|
{
|
|
this.WaterMetersCount = waterMetersCount;
|
|
this.lineSize = lineSize;
|
|
ShuffleTextBoxes(waterMetersCount, lineSize);
|
|
EndStateText = new string[WaterMetersCount];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Make sure the layout of labels/text boxes on the screen
|
|
/// corresponds to the layout of watermeters of the test bench.
|
|
/// </summary>
|
|
/// <param name="wmsCount">Number of watermeters</param>
|
|
/// <param name="lineSize">Number of watermeters in one line</param>
|
|
void ShuffleTextBoxes(int wmsCount, int lineSize)
|
|
{
|
|
for (int i = 0; i < textBoxesCount; i++)
|
|
{
|
|
labels[i].Visible = false;
|
|
textBoxes[i].Visible = false;
|
|
}
|
|
|
|
if (wmsCount < textBoxesCount && lineSize > 0)
|
|
{
|
|
int nrLines;
|
|
int realLineSize;
|
|
if (WaterMetersCount <= 6)
|
|
{
|
|
realLineSize = WaterMetersCount;
|
|
nrLines = 1;
|
|
}
|
|
else
|
|
{
|
|
nrLines = (wmsCount + lineSize - 1) / lineSize;
|
|
realLineSize = lineSize;
|
|
}
|
|
int gap = (textBoxesCount - wmsCount) / nrLines;
|
|
|
|
int dest = 0;
|
|
for (int l = 0; l < nrLines; l++)
|
|
{
|
|
for (int i = 0; i < realLineSize; i++)
|
|
{
|
|
labels[dest] = labels[l * lineSize + l * gap + i];
|
|
textBoxes[dest] = textBoxes[l * lineSize + l * gap + i];
|
|
labels[dest].Visible = true;
|
|
textBoxes[dest].Visible = true;
|
|
dest++;
|
|
}
|
|
}
|
|
textBoxesCount = wmsCount;
|
|
|
|
Height = 60 + 36 * realLineSize;
|
|
}
|
|
}
|
|
|
|
private void CycleEndForm_Load(object sender, EventArgs e)
|
|
{
|
|
Localize();
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
Text = Strings.Data;
|
|
okButton.Text = Strings.OkBtnText;
|
|
|
|
for (int i = 0; i < WaterMetersCount; i++)
|
|
{
|
|
labels[i].Text = string.Format("{0} {1}:", Strings.Water_Meter, (i + 1).ToString());
|
|
}
|
|
}
|
|
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
{
|
|
for (int i = 0; i < WaterMetersCount; i++)
|
|
{
|
|
EndStateText[i] = textBoxes[i].Text;
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|