118 lines
3.1 KiB
C#
118 lines
3.1 KiB
C#
///
|
|
/// Copyright (c) 2019 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using Results.Entities;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.BenchControl.TestMethods.ManualEntry
|
|
{
|
|
public partial class ManualEntryForm : Form, GenericDevices.IHasCompleted
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(ManualEntryForm));
|
|
|
|
///
|
|
/// Set to 'true' when the form closes
|
|
///
|
|
public bool Completed { get { return completed; } }
|
|
bool completed;
|
|
|
|
MeterTestRslt meterTestRslt;
|
|
string prompt;
|
|
IList<Results.ManualEntryItemSpec> items;
|
|
|
|
GroupBox[] groupBoxes;
|
|
Label[] labels;
|
|
TextBox[] textBoxes;
|
|
|
|
/// <summary>
|
|
/// Default constructor
|
|
/// </summary>
|
|
public ManualEntryForm()
|
|
{
|
|
InitializeComponent();
|
|
|
|
groupBoxes = new GroupBox[] { groupBox1, groupBox2, groupBox3, groupBox4, groupBox5, groupBox6, groupBox7 };
|
|
labels = new Label[] { label1, label2, label3, label4, label5, label6, label7 };
|
|
textBoxes = new TextBox[] { textBox1, textBox2, textBox3, textBox4, textBox5, textBox6, textBox7 };
|
|
|
|
ControlBox = false;
|
|
completed = false;
|
|
StartForceCloseHandler();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
|
|
public ManualEntryForm(MeterTestRslt meterTestRslt, string prompt, IList<Results.ManualEntryItemSpec> items)
|
|
: this()
|
|
{
|
|
this.meterTestRslt = meterTestRslt;
|
|
this.prompt = prompt;
|
|
this.items = items;
|
|
|
|
Localize();
|
|
promptLabel.Text = prompt;
|
|
|
|
if (items != null)
|
|
{
|
|
for (int i = 0; i < Math.Min(items.Count, groupBoxes.Length); i++)
|
|
{
|
|
labels[i].Text = items[i].Caption;
|
|
groupBoxes[i].Visible = true;
|
|
}
|
|
|
|
Height = 100 + 90 * items.Count;
|
|
}
|
|
}
|
|
|
|
void Localize()
|
|
{
|
|
okButton.Text = Strings.OkBtnText;
|
|
}
|
|
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
{
|
|
bool ok = true;
|
|
|
|
if (items != null)
|
|
{
|
|
for (int i = 0; i < Math.Min(items.Count, groupBoxes.Length); i++)
|
|
{
|
|
ok = ok &= items[i].Update(textBoxes[i].Text, meterTestRslt);
|
|
}
|
|
}
|
|
|
|
if (ok)
|
|
{
|
|
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
|
|
}
|
|
}
|