149 lines
4.8 KiB
C#
149 lines
4.8 KiB
C#
///
|
|
/// Copyright (c) 2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using log4net;
|
|
using TBF.Resources;
|
|
using System.Drawing;
|
|
|
|
namespace TBF.BenchControl.DataEntry.iPerl
|
|
{
|
|
public partial class CycleBeginningForm : Form, GenericDevices.IHasCompleted
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(CycleBeginningForm));
|
|
|
|
/// <summary> Number of water meters </summary>
|
|
public readonly int WaterMetersCount;
|
|
public readonly bool reversedDirection;
|
|
|
|
/// To be retrieved after the form is closed
|
|
public string PurchaseOrder;
|
|
public string[] SNText;
|
|
public bool[] Disabled;
|
|
|
|
/// Set to 'true' when the form closes
|
|
public bool Completed { get { return completed; } }
|
|
bool completed;
|
|
|
|
|
|
/// <summary> Parameterless constructor for common functionality </summary>
|
|
public CycleBeginningForm()
|
|
{
|
|
InitializeComponent();
|
|
ControlBox = false;
|
|
|
|
completed = false;
|
|
StartForceCloseHandler();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
/// <param name="waterMetersCount">Number of text boxes for serial numbers</param>
|
|
public CycleBeginningForm(int waterMetersCount, bool reversedDirection)
|
|
: this()
|
|
{
|
|
this.WaterMetersCount = waterMetersCount;
|
|
this.reversedDirection = reversedDirection;
|
|
SNText = null;
|
|
Disabled = null;
|
|
}
|
|
|
|
|
|
private void CycleBeginningForm_Load(object sender, EventArgs e)
|
|
{
|
|
Text = Strings.Data;
|
|
orderGroupBox.Text = Strings.Purchase_order;
|
|
okButton.Text = Strings.OkBtnText;
|
|
PrepareOrderCombo(orderComboBox);
|
|
|
|
///
|
|
/// Draw an appropriate test bench picture
|
|
///
|
|
Config.Entities.Side side = (TBF.BenchControl.Sequences.ProcessData.BenchInfo is DataContainers.BenchInfo.iPerl.Component)
|
|
? (TBF.BenchControl.Sequences.ProcessData.BenchInfo as DataContainers.BenchInfo.iPerl.Component).Side
|
|
: Config.Entities.Side.Left;
|
|
if (reversedDirection && (side == Config.Entities.Side.Left))
|
|
{
|
|
/// direction L->R (reversed), left side
|
|
pictureBox.Image = Image.FromFile(string.Format("{0}\\Pictures\\reversed_dir_left.jpg", Program.ExecutableDir, true));
|
|
}
|
|
else if (reversedDirection && (side == Config.Entities.Side.Right))
|
|
{
|
|
/// direction L->R (reversed), right side
|
|
pictureBox.Image = Image.FromFile(string.Format("{0}\\Pictures\\reversed_dir_right.jpg", Program.ExecutableDir, true));
|
|
}
|
|
else if (side == Config.Entities.Side.Right)
|
|
{
|
|
/// direction R->L (forward), right side
|
|
pictureBox.Image = Image.FromFile(string.Format("{0}\\Pictures\\forward_dir_right.jpg", Program.ExecutableDir, true));
|
|
}
|
|
else
|
|
{
|
|
/// direction R->L (forward), left side
|
|
pictureBox.Image = Image.FromFile(string.Format("{0}\\Pictures\\forward_dir_left.jpg", Program.ExecutableDir, true));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load Purchase order combo box items from the LocalSettings PurchaseOrderHistory array
|
|
/// </summary>
|
|
/// <param name="orderComboBox">Puchase order ComboBox</param>
|
|
void PrepareOrderCombo(ComboBox orderComboBox)
|
|
{
|
|
for (int i = 0; i < Program.LocalSettings.PurchaseOrderHistoryCount; i++)
|
|
{
|
|
orderComboBox.Items.Add(Program.LocalSettings.PurchaseOrderHistory[i]);
|
|
}
|
|
|
|
if (orderComboBox.Items.Count > 0)
|
|
{
|
|
orderComboBox.Text = orderComboBox.Items[0].ToString();
|
|
}
|
|
}
|
|
|
|
|
|
private void okButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (orderComboBox.Text.Length > 8)
|
|
{
|
|
MessageBox.Show(string.Format(Strings.Purchase_order_may_have_max_N_characters, 8),
|
|
Strings.Error,
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Exclamation);
|
|
}
|
|
else
|
|
{
|
|
PurchaseOrder = orderComboBox.Text;
|
|
Program.LocalSettings.UpdateHistory(orderComboBox.Text, ref Program.LocalSettings.PurchaseOrderHistory);
|
|
|
|
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
|
|
}
|
|
}
|