IHasCycleBeginForm and IHasCycleEndForm changed, values now available directly from forms, not only from Watermeters.
203 lines
5.9 KiB
C#
203 lines
5.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using log4net;
|
|
using TBF.BenchControl;
|
|
using TBF.BenchControl.GenericDevices;
|
|
|
|
namespace TBF.BenchControl.DataEntry.Standard
|
|
{
|
|
public class EntryForm : ComponentBase, IOperation, IDataEntry, IHasCycleBeginForm, IHasCycleEndForm
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(EntryForm));
|
|
public override string ToString() { return string.Format("DataEntry.Standard({0})", Cfg.ToString(1)); }
|
|
|
|
readonly EntryFormCfg entryFormCfg;
|
|
|
|
/// <summary>
|
|
/// Properties set by the Begin and the End form
|
|
/// </summary>
|
|
string purchaseOrder;
|
|
public string PurchaseOrder { get { return purchaseOrder; } }
|
|
|
|
string[] serialNr;
|
|
public string SerialNr(int wmNr) { return (wmNr >= 0 && wmNr < serialNr.Length) ? serialNr[wmNr] : string.Empty; }
|
|
|
|
bool[] disabled;
|
|
public bool Disabled(int wmNr) { return (wmNr >= 0 && wmNr < disabled.Length) ? disabled[wmNr] : false; }
|
|
|
|
string[] wmEndState;
|
|
public string WMEndState(int wmNr) { return (wmNr >= 0 && wmNr < wmEndState.Length) ? wmEndState[wmNr] : string.Empty; }
|
|
|
|
public float WMState(int wmNr)
|
|
{
|
|
float retVal;
|
|
if (wmNr >= 0 && wmNr < wmEndState.Length && Utils.TryParseUFloat(wmEndState[wmNr], out retVal)) return retVal;
|
|
return 0;
|
|
}
|
|
|
|
|
|
System.Windows.Forms.Form modelessDlg;
|
|
|
|
bool resultSaved; /// Set in Run() when results are saved
|
|
|
|
IList<IWaterMeter> waterMeters; /// Passesd as an argument of ShowCycleBeginFormOp/ShowCycleEndFormOp constructor
|
|
|
|
public enum CurrentOp
|
|
{
|
|
None,
|
|
ShowFormAtCycleBeginning,
|
|
ShowFormAtCycleEnd,
|
|
}
|
|
|
|
CurrentOp currentOp;
|
|
|
|
|
|
public EntryForm(EntryFormCfg cfg)
|
|
: base(cfg)
|
|
{
|
|
serialNr = new string[Program.WMsCount];
|
|
disabled = new bool[Program.WMsCount];
|
|
wmEndState = new string[Program.WMsCount];
|
|
|
|
entryFormCfg = cfg;
|
|
currentOp = CurrentOp.None;
|
|
log.Debug(this.ToString());
|
|
}
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
public IOperation ShowCycleBeginFormOp(IList<IWaterMeter> waterMeters)
|
|
{
|
|
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
|
|
currentOp = CurrentOp.ShowFormAtCycleBeginning;
|
|
this.waterMeters = waterMeters;
|
|
return this;
|
|
}
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
public IOperation ShowCycleEndFormOp(IList<IWaterMeter> waterMeters)
|
|
{
|
|
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
|
|
currentOp = CurrentOp.ShowFormAtCycleEnd;
|
|
this.waterMeters = waterMeters;
|
|
return this;
|
|
}
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
public IOperation ShowWMSNsAndStatesFormOp()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
public IOperation ShowWMStatesFormOp()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
delegate void EntryFormDlgt(EntryForm myRef);
|
|
///
|
|
void OpenBeginningDlg(EntryForm myRef)
|
|
{
|
|
myRef.modelessDlg = new CycleBeginningForm(Program.WMsCount);
|
|
modelessDlg.Show();
|
|
}
|
|
///
|
|
void OpenEndDlg(EntryForm myRef)
|
|
{
|
|
myRef.modelessDlg = new CycleEndForm(Program.WMsCount);
|
|
modelessDlg.Show();
|
|
}
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Start()
|
|
{
|
|
resultSaved = false;
|
|
switch (currentOp)
|
|
{
|
|
case CurrentOp.ShowFormAtCycleBeginning:
|
|
Program.MainWnd.Invoke(new EntryFormDlgt(OpenBeginningDlg), this);
|
|
break;
|
|
case CurrentOp.ShowFormAtCycleEnd:
|
|
Program.MainWnd.Invoke(new EntryFormDlgt(OpenEndDlg), this);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// <summary>Run this operation</summary>
|
|
/// <returns>Event.ResultsPrinted</returns>
|
|
public Event Run()
|
|
{
|
|
if ((modelessDlg is IHasCompleted) && !(modelessDlg as IHasCompleted).Completed)
|
|
{
|
|
return Event.ModelessFormIsOpen;
|
|
}
|
|
|
|
if (!resultSaved) /// This is to save the result only once
|
|
{
|
|
if (modelessDlg is CycleBeginningForm)
|
|
{
|
|
CycleBeginningForm dlg = (modelessDlg as CycleBeginningForm);
|
|
|
|
purchaseOrder = dlg.PurchaseOrder;
|
|
|
|
for (int i = 0; i < Math.Min(dlg.WaterMetersCount, waterMeters.Count); i++)
|
|
{
|
|
if (waterMeters[i] != null)
|
|
{
|
|
serialNr[i] = waterMeters[i].SerialNr = dlg.SNText[i];
|
|
disabled[i] = waterMeters[i].Disabled = dlg.Disabled[i];
|
|
}
|
|
}
|
|
}
|
|
else if (modelessDlg is CycleEndForm)
|
|
{
|
|
CycleEndForm dlg = (modelessDlg as CycleEndForm);
|
|
|
|
for (int i = 0; i < Math.Min(dlg.WaterMetersCount, waterMeters.Count); i++)
|
|
{
|
|
if (waterMeters[i] != null)
|
|
{
|
|
wmEndState[i] = waterMeters[i].EndState = dlg.EndStateText[i];
|
|
}
|
|
}
|
|
}
|
|
resultSaved = true;
|
|
modelessDlg = null;
|
|
}
|
|
|
|
return Event.ModelessFormClosed; /// Form closed
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop()
|
|
{
|
|
if (modelessDlg is IHasCompleted)
|
|
{
|
|
UiBridge.Bridge.OnCloseModelessForm(this, null);
|
|
modelessDlg = null;
|
|
}
|
|
currentOp = CurrentOp.None;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates test results with the information collected in watermeters.
|
|
/// </summary>
|
|
/// <param name="waterMeters">Watermetes with information entered in the forms</param>
|
|
/// <param name="results">Test results to be updated with the information</param>
|
|
public void UpdateTestResults(IList<IWaterMeter> waterMeters, IList<Entities.TestResult> results)
|
|
{
|
|
foreach (var test in results)
|
|
{
|
|
if (test.MetersKind != Entities.MetersKind.Single) continue;
|
|
|
|
int nrMtrsToUpdate = Math.Min(waterMeters.Count, test.Meters.Count);
|
|
for (int i = 0; i < nrMtrsToUpdate; i++)
|
|
{
|
|
test.Meters[i].SerialNr = waterMeters[i].SerialNr;
|
|
test.Meters[i].EndState = waterMeters[i].EndState;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|