2022-04-01 10:31:58 +00:00
|
|
|
|
///
|
2023-02-08 12:37:43 +00:00
|
|
|
|
/// Copyright (c) 2023 Sensus Slovensko a.s.
|
2022-04-01 10:31:58 +00:00
|
|
|
|
///
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using log4net;
|
|
|
|
|
|
using Config.Entities;
|
|
|
|
|
|
using TBF.Rig;
|
|
|
|
|
|
using TBF.Rig.GenericDevices;
|
|
|
|
|
|
|
2023-02-08 12:37:43 +00:00
|
|
|
|
namespace TBF.Rig.DataEntry.Uni
|
2022-04-01 10:31:58 +00:00
|
|
|
|
{
|
|
|
|
|
|
public class EntryFormNoStartEnd : ComponentBase, IOperation, IDataEntry, IHasCycleBeginForm, IHasCycleEndForm
|
|
|
|
|
|
{
|
|
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(EntryFormNoStartEnd));
|
|
|
|
|
|
public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); }
|
|
|
|
|
|
|
|
|
|
|
|
public bool UsesCameras() { return false; }
|
|
|
|
|
|
|
2023-02-08 12:37:43 +00:00
|
|
|
|
readonly EntryFormCfg myCfg;
|
2022-04-01 10:31:58 +00:00
|
|
|
|
IRegReader[] regReaders;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Properties set by the Begin, End and WMStates form
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
bool[] disabled; /// This array is shared between forms
|
|
|
|
|
|
|
|
|
|
|
|
string[] wmCycleEndState;
|
|
|
|
|
|
public string WMCycleEndState(int wmNr) { return (wmNr >= 0 && wmNr < wmCycleEndState.Length) ? wmCycleEndState[wmNr] : string.Empty; }
|
|
|
|
|
|
|
|
|
|
|
|
double[] wmStartState;
|
|
|
|
|
|
public double WMStartState(int wmNr) { return (wmNr >= 0 && wmNr < wmStartState.Length) ? wmStartState[wmNr] : 0; }
|
|
|
|
|
|
|
|
|
|
|
|
double[] wmEndState;
|
|
|
|
|
|
public double WMEndState(int wmNr) { return (wmNr >= 0 && wmNr < wmEndState.Length) ? wmEndState[wmNr] : 0; }
|
|
|
|
|
|
|
|
|
|
|
|
string[] wmStartStateStr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.Windows.Forms.Form modelessDlg;
|
|
|
|
|
|
public bool Completed { get { return (modelessDlg is IHasCompleted) ? (modelessDlg as IHasCompleted).Completed : true; } }
|
|
|
|
|
|
|
2023-02-08 12:37:43 +00:00
|
|
|
|
Common.Unit volumeUnit;
|
|
|
|
|
|
double refVolume;
|
2022-04-01 10:31:58 +00:00
|
|
|
|
double errLimLo;
|
|
|
|
|
|
double errLimHi;
|
|
|
|
|
|
|
|
|
|
|
|
bool resultSaved; /// Set in Run() when results are saved
|
|
|
|
|
|
|
|
|
|
|
|
IList<Results.Entities.WaterMeter> waterMeters; /// Reference to ...ProcessData.BatchRslts.WaterMeters[]
|
|
|
|
|
|
|
|
|
|
|
|
public enum CurrentOp
|
|
|
|
|
|
{
|
|
|
|
|
|
None,
|
|
|
|
|
|
ShowFormAtCycleBeginning,
|
|
|
|
|
|
ShowFormAtCycleEnd,
|
|
|
|
|
|
EnterTestStartStates,
|
|
|
|
|
|
EnterTestEndStates,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CurrentOp currentOp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public EntryFormNoStartEnd() { }
|
|
|
|
|
|
|
|
|
|
|
|
public EntryFormNoStartEnd(Generic.IComponentCfg cfg)
|
|
|
|
|
|
: base(cfg)
|
|
|
|
|
|
{
|
2023-02-08 12:37:43 +00:00
|
|
|
|
myCfg = cfg as EntryFormCfg;
|
2022-04-01 10:31:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
disabled = new bool[TBF.Data.WMsCount];
|
|
|
|
|
|
wmStartState = new double[TBF.Data.WMsCount];
|
|
|
|
|
|
wmStartStateStr = new string[TBF.Data.WMsCount];
|
|
|
|
|
|
wmEndState = new double[TBF.Data.WMsCount];
|
|
|
|
|
|
wmCycleEndState = new string[TBF.Data.WMsCount];
|
2023-02-08 12:37:43 +00:00
|
|
|
|
volumeUnit = (TBF.Rig.Sequences.ProcessData.BenchInfo != null) ? TBF.Rig.Sequences.ProcessData.BenchInfo.VolumeUnit : Common.Unit.l;
|
2022-04-01 10:31:58 +00:00
|
|
|
|
currentOp = CurrentOp.None;
|
|
|
|
|
|
log.FatalFormat("{0} initialized: {1}", Name, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
|
|
|
|
public IOperation ShowCycleBeginFormOp()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
|
|
|
|
|
|
currentOp = CurrentOp.ShowFormAtCycleBeginning;
|
|
|
|
|
|
this.waterMeters = TBF.Rig.Sequences.ProcessData.BatchRslts.Batch.WaterMeters;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
|
|
|
|
public IOperation ShowCycleEndFormOp(IList<Results.Entities.WaterMeter> 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 ShowTestStartFormOp(IRegReader[] regReaders)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
|
|
|
|
|
|
currentOp = CurrentOp.EnterTestStartStates;
|
2023-02-08 12:37:43 +00:00
|
|
|
|
this.waterMeters = TBF.Rig.Sequences.ProcessData.BatchRslts.Batch.WaterMeters;
|
|
|
|
|
|
this.regReaders = regReaders;
|
|
|
|
|
|
return this;
|
2022-04-01 10:31:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
|
|
|
|
public IOperation ShowTestEndFormOp(IRegReader[] regReaders, double refVolume, double errLimLo, double errLimHi)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
|
|
|
|
|
|
currentOp = CurrentOp.EnterTestEndStates;
|
2023-02-08 12:37:43 +00:00
|
|
|
|
this.waterMeters = TBF.Rig.Sequences.ProcessData.BatchRslts.Batch.WaterMeters;
|
|
|
|
|
|
this.regReaders = regReaders;
|
2022-04-01 10:31:58 +00:00
|
|
|
|
this.refVolume = refVolume;
|
|
|
|
|
|
this.errLimLo = errLimLo;
|
|
|
|
|
|
this.errLimHi = errLimHi;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IOperation ShowAdvancedTestStartFormOp(IRegReader[] regReaders, IList<Results.Entities.WaterMeter> waterMeters, bool isCondOp = false)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delegate void EntryFormDlgt(EntryFormNoStartEnd myRef);
|
|
|
|
|
|
///
|
|
|
|
|
|
void OpenBeginningDlg(EntryFormNoStartEnd myRef)
|
|
|
|
|
|
{
|
2023-05-12 13:36:27 +00:00
|
|
|
|
DEItem.ClearItems();
|
|
|
|
|
|
for (int i = 0; i < myCfg.GetBgItemsCount(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (myCfg.BgItemContent[i] != Ct.None)
|
|
|
|
|
|
{
|
|
|
|
|
|
DEItem.AddItem(myCfg.BgItemContent[i], myCfg.BgItemCaption[i], myCfg.BgItemAction[i], myCfg.BgItemWidth[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-02-08 12:37:43 +00:00
|
|
|
|
|
|
|
|
|
|
DEItem.ClearColumns();
|
2023-05-12 13:36:27 +00:00
|
|
|
|
for (int i = 0; i < myCfg.GetBgColumnsCount(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (myCfg.BgColumnContent[i] != Ct.None)
|
|
|
|
|
|
{
|
|
|
|
|
|
DEItem.AddColumn(myCfg.BgColumnContent[i], myCfg.BgColumnCaption[i], myCfg.BgColumnAction[i], myCfg.BgColumnWidth[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-02-08 12:37:43 +00:00
|
|
|
|
|
|
|
|
|
|
modelessDlg = new CycleBgEnForm(waterMeters, TBF.Data.LineSize, myCfg.BgTitle, myCfg.BgSize, myCfg.BgIsLrOrder, myCfg.BgFormCloseKeys,
|
2023-05-12 13:36:27 +00:00
|
|
|
|
DEItem.GetItems(), DEItem.GetColumns(), false);
|
2022-04-01 10:31:58 +00:00
|
|
|
|
modelessDlg.Show();
|
|
|
|
|
|
}
|
|
|
|
|
|
///
|
|
|
|
|
|
void OpenEndDlg(EntryFormNoStartEnd myRef)
|
|
|
|
|
|
{
|
2023-05-12 13:36:27 +00:00
|
|
|
|
DEItem.ClearItems();
|
|
|
|
|
|
for (int i = 0; i < myCfg.GetEnItemsCount(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (myCfg.EnItemContent[i] != Ct.None)
|
|
|
|
|
|
{
|
|
|
|
|
|
DEItem.AddItem(myCfg.EnItemContent[i], myCfg.EnItemCaption[i], myCfg.EnItemAction[i], myCfg.EnItemWidth[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-02-08 12:37:43 +00:00
|
|
|
|
|
|
|
|
|
|
DEItem.ClearColumns();
|
2023-05-12 13:36:27 +00:00
|
|
|
|
for (int i = 0; i < myCfg.GetEnColumnsCount(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (myCfg.EnColumnContent[i] != Ct.None)
|
|
|
|
|
|
{
|
|
|
|
|
|
DEItem.AddColumn(myCfg.EnColumnContent[i], myCfg.EnColumnCaption[i], myCfg.EnColumnAction[i], myCfg.EnColumnWidth[i]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-02-08 12:37:43 +00:00
|
|
|
|
|
|
|
|
|
|
modelessDlg = new CycleBgEnForm(waterMeters, TBF.Data.LineSize, myCfg.EnTitle, myCfg.EnSize, myCfg.EnIsLrOrder, myCfg.EnFormCloseKeys,
|
2023-05-12 13:36:27 +00:00
|
|
|
|
DEItem.GetItems(), DEItem.GetColumns(), true);
|
2022-04-01 10:31:58 +00:00
|
|
|
|
modelessDlg.Show();
|
|
|
|
|
|
}
|
|
|
|
|
|
///
|
|
|
|
|
|
void OpenTestStartStatesDlg(EntryFormNoStartEnd myRef)
|
|
|
|
|
|
{
|
2023-02-08 12:37:43 +00:00
|
|
|
|
myRef.modelessDlg = new TestStartEndForm(waterMeters, myRef.regReaders,
|
|
|
|
|
|
myRef.myCfg.TestFormCloseKeys, volumeUnit);
|
2022-04-01 10:31:58 +00:00
|
|
|
|
modelessDlg.Show();
|
|
|
|
|
|
}
|
|
|
|
|
|
///
|
|
|
|
|
|
void OpenTestEndStatesDlg(EntryFormNoStartEnd myRef)
|
|
|
|
|
|
{
|
2023-02-08 12:37:43 +00:00
|
|
|
|
modelessDlg = new TestStartEndForm(waterMeters, myRef.regReaders, wmStartStateStr,
|
|
|
|
|
|
refVolume, errLimLo, errLimHi, volumeUnit);
|
2022-04-01 10:31:58 +00:00
|
|
|
|
modelessDlg.Show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Start this operation</summary>
|
|
|
|
|
|
public void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
resultSaved = false;
|
|
|
|
|
|
switch (currentOp)
|
|
|
|
|
|
{
|
|
|
|
|
|
case CurrentOp.ShowFormAtCycleBeginning:
|
2023-05-12 13:36:27 +00:00
|
|
|
|
if (myCfg.BgShowForm)
|
2022-04-01 10:31:58 +00:00
|
|
|
|
{
|
|
|
|
|
|
Program.MainWnd.Invoke(new EntryFormDlgt(OpenBeginningDlg), this);
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case CurrentOp.ShowFormAtCycleEnd:
|
2023-05-12 13:36:27 +00:00
|
|
|
|
if (myCfg.EnShowForm)
|
2022-04-01 10:31:58 +00:00
|
|
|
|
{
|
|
|
|
|
|
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
|
|
|
|
|
|
{
|
2023-02-08 12:37:43 +00:00
|
|
|
|
if (modelessDlg is TestStartEndForm && currentOp == CurrentOp.EnterTestStartStates)
|
2022-04-01 10:31:58 +00:00
|
|
|
|
{
|
|
|
|
|
|
/// Fixed start test - start
|
|
|
|
|
|
TestStartEndForm dlg = (modelessDlg as TestStartEndForm);
|
|
|
|
|
|
if (dlg != null)
|
|
|
|
|
|
{
|
2023-02-08 12:37:43 +00:00
|
|
|
|
volumeUnit = dlg.VolumeUnit;
|
2022-04-01 10:31:58 +00:00
|
|
|
|
for (int i = 0; i < dlg.WMsCount; i++)
|
|
|
|
|
|
{
|
2023-02-08 12:37:43 +00:00
|
|
|
|
if (!((i < waterMeters.Count && waterMeters[i].Disabled) || (i < regReaders.Length && regReaders[i] == null)))
|
2022-04-01 10:31:58 +00:00
|
|
|
|
{
|
|
|
|
|
|
wmStartState[i] = dlg.WMStartState[i];
|
|
|
|
|
|
wmStartStateStr[i] = dlg.WMStartStateStr[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (modelessDlg is TestStartEndForm && currentOp == CurrentOp.EnterTestEndStates)
|
|
|
|
|
|
{
|
|
|
|
|
|
/// Fixed start test - end
|
|
|
|
|
|
TestStartEndForm dlg = (modelessDlg as TestStartEndForm);
|
|
|
|
|
|
if (dlg != null)
|
|
|
|
|
|
{
|
2023-02-08 12:37:43 +00:00
|
|
|
|
volumeUnit = dlg.VolumeUnit;
|
2022-04-01 10:31:58 +00:00
|
|
|
|
for (int i = 0; i < dlg.WMsCount; i++)
|
|
|
|
|
|
{
|
2023-02-08 12:37:43 +00:00
|
|
|
|
if (!((i < waterMeters.Count && waterMeters[i].Disabled) || (i < regReaders.Length && regReaders[i] == null)))
|
2022-04-01 10:31:58 +00:00
|
|
|
|
{
|
|
|
|
|
|
wmEndState[i] = dlg.WMEndState[i];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-02-08 12:37:43 +00:00
|
|
|
|
|
2022-04-01 10:31:58 +00:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|