201 lines
7.4 KiB
C#
201 lines
7.4 KiB
C#
///
|
|
/// Copyright (c) 2013-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.Munich
|
|
{
|
|
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.Munich({0})", Cfg.ToString(1)); }
|
|
|
|
public bool UsesCameras() { return false; }
|
|
|
|
readonly EntryFormCfg entryFormCfg;
|
|
|
|
/// <summary>
|
|
/// Properties set by the Begin and the End form
|
|
/// </summary>
|
|
string[] serialNr;
|
|
public string SerialNr(int wmNr) { return (wmNr >= 0 && wmNr < serialNr.Length) ? serialNr[wmNr] : string.Empty; }
|
|
|
|
public bool Disabled(int wmNr) { return false; } /// Not supported in Munich
|
|
|
|
string[] wmEndState;
|
|
public string WMCycleEndState(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;
|
|
public bool Completed { get { return (modelessDlg is IHasCompleted) ? (modelessDlg as IHasCompleted).Completed : true; } }
|
|
|
|
bool resultSaved; /// Set in Run() when results are saved
|
|
|
|
IList<Results.Entities.WaterMeter> wMeters; /// Reference to ...ProcessData.BatchRslts.Batch.WaterMeters[]
|
|
|
|
public enum CurrentOp
|
|
{
|
|
None,
|
|
ShowFormAtCycleBeginning,
|
|
ShowFormAtCycleEnd,
|
|
}
|
|
|
|
CurrentOp currentOp;
|
|
|
|
|
|
public EntryForm()
|
|
{
|
|
}
|
|
|
|
public EntryForm(Generic.IComponentCfg cfg)
|
|
: base(cfg)
|
|
{
|
|
entryFormCfg = cfg as EntryFormCfg;
|
|
|
|
serialNr = new string[Config.Data.CompoundWMsCount];
|
|
wmEndState = new string[Config.Data.CompoundWMsCount];
|
|
|
|
currentOp = CurrentOp.None;
|
|
log.Warn(this.ToString());
|
|
}
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
public IOperation ShowCycleBeginFormOp()
|
|
{
|
|
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
|
|
currentOp = CurrentOp.ShowFormAtCycleBeginning;
|
|
this.wMeters = TBF.BenchControl.Sequences.ProcessData.BatchRslts.Batch.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.wMeters = TBF.BenchControl.Sequences.ProcessData.BatchRslts.Batch.WaterMeters;
|
|
return this;
|
|
}
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
public IOperation ShowWMSNsAndStatesFormOp()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
delegate void EntryFormDlgt(EntryForm myRef);
|
|
///
|
|
void OpenBeginningDlg(EntryForm myRef)
|
|
{
|
|
myRef.modelessDlg = new CycleBeginningForm();
|
|
modelessDlg.Show();
|
|
}
|
|
///
|
|
void OpenEndDlg(EntryForm myRef)
|
|
{
|
|
CycleEndForm endForm = new CycleEndForm();
|
|
endForm.ProtocolName1 = entryFormCfg.ProtocolTitle1;
|
|
endForm.ProtocolName2 = entryFormCfg.ProtocolTitle2;
|
|
endForm.ProtocolName3 = entryFormCfg.ProtocolTitle3;
|
|
endForm.ProtocolName4 = entryFormCfg.ProtocolTitle4;
|
|
myRef.modelessDlg = endForm;
|
|
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
|
|
{
|
|
int count = Math.Min(3, Math.Min(wMeters.Count, Config.Data.CompoundWMsCount));
|
|
if (modelessDlg is CycleBeginningForm)
|
|
{
|
|
if (count >= 1 && wMeters[0] != null) wMeters[0].SerialNr = (modelessDlg as CycleBeginningForm).MainSNText[0];
|
|
if (count >= 1 && wMeters[0] != null) wMeters[0].SerialNrAux = (modelessDlg as CycleBeginningForm).AuxSNText[0];
|
|
if (count >= 2 && wMeters[1] != null) wMeters[1].SerialNr = (modelessDlg as CycleBeginningForm).MainSNText[1];
|
|
if (count >= 2 && wMeters[1] != null) wMeters[1].SerialNrAux = (modelessDlg as CycleBeginningForm).AuxSNText[1];
|
|
if (count >= 3 && wMeters[2] != null) wMeters[2].SerialNr = (modelessDlg as CycleBeginningForm).MainSNText[2];
|
|
if (count >= 3 && wMeters[2] != null) wMeters[2].SerialNrAux = (modelessDlg as CycleBeginningForm).AuxSNText[2];
|
|
}
|
|
else if (modelessDlg is CycleEndForm)
|
|
{
|
|
Sequences.ProcessData.BatchRslts.Batch.ProtocolTitle = (modelessDlg as CycleEndForm).ProtocolTitle;
|
|
|
|
if (count >= 1 && wMeters[0] != null)
|
|
{
|
|
wMeters[0].EndState = (modelessDlg as CycleEndForm).MainStateText[0];
|
|
wMeters[0].EndStateAux = (modelessDlg as CycleEndForm).AuxStateText[0];
|
|
wMeters[0].QRise = (modelessDlg as CycleEndForm).QRise[0];
|
|
wMeters[0].QFall = (modelessDlg as CycleEndForm).QFall[0];
|
|
wMeters[0].YearOfProduction = (modelessDlg as CycleEndForm).YearOfProduction[0];
|
|
}
|
|
if (count >= 2 && wMeters[1] != null)
|
|
{
|
|
wMeters[1].EndState = (modelessDlg as CycleEndForm).MainStateText[1];
|
|
wMeters[1].EndStateAux = (modelessDlg as CycleEndForm).AuxStateText[1];
|
|
wMeters[1].QRise = (modelessDlg as CycleEndForm).QRise[1];
|
|
wMeters[1].QFall = (modelessDlg as CycleEndForm).QFall[1];
|
|
wMeters[1].YearOfProduction = (modelessDlg as CycleEndForm).YearOfProduction[1];
|
|
}
|
|
if (count >= 3 && wMeters[2] != null)
|
|
{
|
|
wMeters[2].EndState = (modelessDlg as CycleEndForm).MainStateText[2];
|
|
wMeters[2].EndStateAux = (modelessDlg as CycleEndForm).AuxStateText[2];
|
|
wMeters[2].QRise = (modelessDlg as CycleEndForm).QRise[2];
|
|
wMeters[2].QFall = (modelessDlg as CycleEndForm).QFall[2];
|
|
wMeters[2].YearOfProduction = (modelessDlg as CycleEndForm).YearOfProduction[2];
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
}
|