168 lines
4.1 KiB
C#
168 lines
4.1 KiB
C#
///
|
|
/// Copyright (c) 2017 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using TBF.Resources;
|
|
using System.Drawing;
|
|
|
|
namespace TBF.BenchControl.Network.Camera.Display
|
|
{
|
|
public partial class DisplayForm : Form, GenericDevices.IHasCompleted
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(DisplayForm));
|
|
|
|
/// <summary> Number of text boxes for serial numbers </summary>
|
|
readonly string[] imageFileNames;
|
|
readonly int imagesCount;
|
|
|
|
readonly GroupBox[] groupBoxes;
|
|
readonly PictureBox[] pictureBoxes;
|
|
readonly CheckBox[] checkBoxes;
|
|
readonly int boxesCount;
|
|
|
|
Timer myTimer;
|
|
|
|
|
|
public bool[] SelectedImages;
|
|
public DialogResult Result; /// DialogResult.None OK Retry or Cancel
|
|
|
|
|
|
/// 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 DisplayForm(string[] imageFileNames, string title)
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.imageFileNames = imageFileNames;
|
|
this.imagesCount = (imageFileNames == null) ? 0 : imageFileNames.Length;
|
|
|
|
groupBoxes = new GroupBox[] { groupBox1, groupBox2, groupBox3, groupBox4, groupBox5, groupBox6 };
|
|
pictureBoxes = new PictureBox[] { pictureBox1, pictureBox2, pictureBox3, pictureBox4, pictureBox5, pictureBox6 };
|
|
checkBoxes = new CheckBox[] { checkBox1, checkBox2, checkBox3, checkBox4, checkBox5, checkBox6 };
|
|
boxesCount = pictureBoxes.Length;
|
|
|
|
SelectedImages = new bool[imagesCount];
|
|
|
|
Text = title;
|
|
|
|
Result = DialogResult.None;
|
|
|
|
completed = false;
|
|
StartForceCloseHandler();
|
|
}
|
|
|
|
/// <summary> Parameterless constructor for all watermeters </summary>
|
|
public DisplayForm()
|
|
: this(null, string.Empty)
|
|
{
|
|
}
|
|
|
|
private void CycleBeginningForm_Load(object sender, EventArgs e)
|
|
{
|
|
okButton.Text = Strings.OkBtnText;
|
|
retryButton.Text = Strings.Retry;
|
|
abortButton.Text = Strings.Abort;
|
|
|
|
for (int i = 0; i < boxesCount; i++)
|
|
{
|
|
if (i < imagesCount && !string.IsNullOrEmpty(imageFileNames[i]))
|
|
{
|
|
groupBoxes[i].Text = string.Format("{0} {1}", Strings.Water_Meter, i + 1);
|
|
checkBoxes[i].Checked = true;
|
|
}
|
|
else
|
|
{
|
|
groupBoxes[i].Visible = false;
|
|
checkBoxes[i].Checked = false;
|
|
}
|
|
}
|
|
|
|
myTimer = new Timer();
|
|
myTimer.Interval = (500); // 45 mins
|
|
myTimer.Tick += new EventHandler(MyTimer_Tick);
|
|
myTimer.Start();
|
|
}
|
|
|
|
private void MyTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
for (int i = 0; i < Math.Min(imagesCount, boxesCount); i++)
|
|
{
|
|
if (imageFileNames[i] != null &&
|
|
System.IO.File.Exists(imageFileNames[i]) &&
|
|
pictureBoxes[i] != null &&
|
|
pictureBoxes[i].Image == null)
|
|
{
|
|
pictureBoxes[i].Image = Image.FromFile(imageFileNames[i]); ;
|
|
checkBoxes[i].Checked = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void UpdateData()
|
|
{
|
|
for (int i = 0; i < Math.Min(imagesCount, boxesCount); i++)
|
|
{
|
|
SelectedImages[i] = checkBoxes[i].Checked;
|
|
}
|
|
}
|
|
|
|
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (myTimer != null) myTimer.Stop();
|
|
UpdateData();
|
|
Result = DialogResult.OK;
|
|
completed = true;
|
|
Close();
|
|
}
|
|
|
|
private void abortButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (myTimer != null) myTimer.Stop();
|
|
UpdateData();
|
|
Result = DialogResult.Abort;
|
|
completed = true;
|
|
Close();
|
|
}
|
|
|
|
private void retryButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (myTimer != null) myTimer.Stop();
|
|
UpdateData();
|
|
Result = DialogResult.Retry;
|
|
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);
|
|
};
|
|
}
|
|
|
|
private void OnForceClose(object sender, EventArgs args)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|