270 lines
8.1 KiB
C#
270 lines
8.1 KiB
C#
///
|
|
/// Copyright (c) 2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using log4net;
|
|
using Config.Entities;
|
|
using TBF.BenchControl;
|
|
using TBF.BenchControl.GenericDevices;
|
|
|
|
namespace TBF.BenchControl.DataEntry.iPerl
|
|
{
|
|
public class EntryForm : ComponentBase, IOperation, IDataEntry, IHasCycleBeginForm, IHasCycleEndForm, IHasWMStatesForm
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(EntryForm));
|
|
public override string ToString() { return string.Format("DataEntry.iPerl({0})", Cfg.ToString(1)); }
|
|
|
|
readonly EntryFormCfg entryFormCfg;
|
|
|
|
/// <summary>
|
|
/// Properties set by the Begin, End and WMStates 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[] wmCycleEndState;
|
|
public string WMCycleEndState(int wmNr) { return (wmNr >= 0 && wmNr < wmCycleEndState.Length) ? wmCycleEndState[wmNr] : string.Empty; }
|
|
|
|
float[] wmStartState;
|
|
public float WMStartState(int wmNr) { return (wmNr >= 0 && wmNr < wmStartState.Length) ? wmStartState[wmNr] : 0; }
|
|
|
|
float[] wmEndState;
|
|
public float WMEndState(int wmNr) { return (wmNr >= 0 && wmNr < wmEndState.Length) ? wmEndState[wmNr] : 0; }
|
|
|
|
string[] wmStartStateStr;
|
|
|
|
|
|
System.Windows.Forms.Form modelessDlg;
|
|
|
|
double refVolume;
|
|
double errLimLo;
|
|
double errLimHi;
|
|
|
|
bool resultSaved; /// Set in Run() when results are saved
|
|
|
|
Results.Entities.WaterMeter[] waterMeters; /// Reference to ...ProcessData.BatchRslts.WaterMeters[]
|
|
|
|
public enum CurrentOp
|
|
{
|
|
None,
|
|
ShowFormAtCycleBeginning,
|
|
ShowFormAtCycleEnd,
|
|
EnterTestStartStates,
|
|
EnterTestEndStates,
|
|
}
|
|
|
|
CurrentOp currentOp;
|
|
|
|
|
|
public EntryForm()
|
|
{
|
|
}
|
|
|
|
public EntryForm(Generic.IComponentCfg cfg)
|
|
: base(cfg)
|
|
{
|
|
entryFormCfg = cfg as EntryFormCfg;
|
|
|
|
serialNr = new string[Config.Data.WMsCount];
|
|
disabled = new bool[Config.Data.WMsCount];
|
|
wmStartState = new float[Config.Data.WMsCount];
|
|
wmStartStateStr = new string[Config.Data.WMsCount];
|
|
wmEndState = new float[Config.Data.WMsCount];
|
|
wmCycleEndState = new string[Config.Data.WMsCount];
|
|
|
|
currentOp = CurrentOp.None;
|
|
log.Debug(this.ToString());
|
|
}
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
public IOperation ShowCycleBeginFormOp()
|
|
{
|
|
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
|
|
currentOp = CurrentOp.ShowFormAtCycleBeginning;
|
|
this.waterMeters = TBF.BenchControl.Sequences.ProcessData.BatchRslts.WaterMeters;
|
|
return this;
|
|
}
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
public IOperation ShowCycleEndFormOp()
|
|
{
|
|
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
|
|
currentOp = CurrentOp.ShowFormAtCycleEnd;
|
|
this.waterMeters = TBF.BenchControl.Sequences.ProcessData.BatchRslts.WaterMeters;
|
|
return this;
|
|
}
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
public IOperation ShowTestStartFormOp()
|
|
{
|
|
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
|
|
currentOp = CurrentOp.EnterTestStartStates;
|
|
return this;
|
|
}
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
public IOperation ShowTestEndFormOp(double refVolume, double errLimLo, double errLimHi)
|
|
{
|
|
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
|
|
currentOp = CurrentOp.EnterTestEndStates;
|
|
this.refVolume = refVolume;
|
|
this.errLimLo = errLimLo;
|
|
this.errLimHi = errLimHi;
|
|
return this;
|
|
}
|
|
|
|
delegate void EntryFormDlgt(EntryForm myRef);
|
|
///
|
|
void OpenBeginningDlg(EntryForm myRef)
|
|
{
|
|
myRef.modelessDlg = new CycleBeginningForm(Config.Data.WMsCount);
|
|
modelessDlg.Show();
|
|
}
|
|
///
|
|
void OpenEndDlg(EntryForm myRef)
|
|
{
|
|
myRef.modelessDlg = new CycleEndForm(Config.Data.WMsCount);
|
|
modelessDlg.Show();
|
|
}
|
|
///
|
|
void OpenTestStartStatesDlg(EntryForm myRef)
|
|
{
|
|
myRef.modelessDlg = new TestStartEndForm(Config.Data.WMsCount, disabled);
|
|
modelessDlg.Show();
|
|
}
|
|
///
|
|
void OpenTestEndStatesDlg(EntryForm myRef)
|
|
{
|
|
myRef.modelessDlg = new TestStartEndForm(Config.Data.WMsCount, wmStartStateStr, disabled, refVolume, errLimLo, errLimHi);
|
|
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:
|
|
if (entryFormCfg.ShowCycleEndForm)
|
|
{
|
|
Program.MainWnd.Invoke(new EntryFormDlgt(OpenEndDlg), this);
|
|
}
|
|
break;
|
|
case CurrentOp.EnterTestStartStates:
|
|
Program.MainWnd.Invoke(new EntryFormDlgt(OpenTestStartStatesDlg), this);
|
|
break;
|
|
case CurrentOp.EnterTestEndStates:
|
|
Program.MainWnd.Invoke(new EntryFormDlgt(OpenTestEndStatesDlg), 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 (currentOp == CurrentOp.ShowFormAtCycleBeginning)
|
|
{
|
|
CycleBeginningForm dlg = (modelessDlg as CycleBeginningForm);
|
|
|
|
if (dlg != null)
|
|
{
|
|
purchaseOrder = dlg.PurchaseOrder;
|
|
}
|
|
}
|
|
else if (currentOp == CurrentOp.ShowFormAtCycleEnd)
|
|
{
|
|
}
|
|
else if (modelessDlg is TestStartEndForm && currentOp == CurrentOp.EnterTestStartStates)
|
|
{
|
|
}
|
|
else if (modelessDlg is TestStartEndForm && currentOp == CurrentOp.EnterTestEndStates)
|
|
{
|
|
}
|
|
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="testResults">Test results to be updated with the information</param>
|
|
public void UpdateTestResults(Results.BatchResults batchResults)
|
|
{
|
|
foreach (var wm in batchResults.WaterMeters)
|
|
{
|
|
if (wm != null && !wm.Disabled)
|
|
{
|
|
wm.PurchaseOrder = PurchaseOrder;
|
|
|
|
if (Sequences.SequenceBase.WaterMeters != null &&
|
|
wm.WMPosition > 0 &&
|
|
wm.WMPosition <= Sequences.SequenceBase.WaterMeters.Count)
|
|
{
|
|
WaterMeters.iPerl.WaterMeter iPerl = Sequences.SequenceBase.WaterMeters[wm.WMPosition - 1] as WaterMeters.iPerl.WaterMeter;
|
|
if (iPerl != null)
|
|
{
|
|
#if IPERLST || IPERLST_SPECIAL
|
|
wm.OrigCalibFactor = iPerl.OriginalCalibFactor;
|
|
wm.CalibFactor = iPerl.CalibrationFactor;
|
|
wm.Q2ErrWOCorrection = iPerl.Q2ErrorWOCorrection;
|
|
wm.Q2CorrectionDone = iPerl.Q2CorrectionDone;
|
|
wm.Q2Correction = iPerl.Q2CorrectionFactor;
|
|
wm.Diff2Hz8Hz = iPerl.Diff2Hz8Hz;
|
|
wm.Hz2CorrectionDone = iPerl.Hz2CorrectionDone;
|
|
wm.Hz2Correction = iPerl.Hz2CorrectionFactor;
|
|
|
|
if (iPerl.CalibrationStruct == null)
|
|
{
|
|
wm.Q2CorrFlowRight = 0;
|
|
}
|
|
else if (iPerl.CalibrationStruct.FlowArrow == WaterMeters.iPerl.FlowArrow.Left)
|
|
{
|
|
wm.Q2CorrFlowRight = iPerl.PositiveCounting ? 1 : 2;
|
|
}
|
|
else
|
|
{
|
|
wm.Q2CorrFlowRight = iPerl.PositiveCounting ? 2 : 1;
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|