141 lines
4.0 KiB
C#
141 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using TBF.BenchControl;
|
|
|
|
namespace TBF.BenchControl.DataEntry.Munich
|
|
{
|
|
public class EntryForm : Generic.IComponent, IOperation, GenericDevices.IDataEntry, GenericDevices.IHasProtocolTitle
|
|
{
|
|
readonly EntryFormCfg entryFormCfg;
|
|
public Generic.IComponentCfg Cfg { get { return entryFormCfg; } }
|
|
|
|
public static void ResetStaticProperties() { }
|
|
|
|
public string Name { get { return entryFormCfg.Name; } }
|
|
|
|
/// <summary>
|
|
/// Properties set by the Begin and the End form
|
|
/// </summary>
|
|
public string MainBeginStateText { get { return mainBeginStateText; } }
|
|
string mainBeginStateText;
|
|
|
|
public string AuxBegintateText { get { return auxBeginStateText; } }
|
|
string auxBeginStateText;
|
|
|
|
public string ProtocolTitle { get { return protocolTitle; } }
|
|
string protocolTitle;
|
|
|
|
|
|
System.Windows.Forms.Form modelessDlg;
|
|
|
|
IList<GenericDevices.IWaterMeter> waterMeters;
|
|
|
|
public enum CurrentOp
|
|
{
|
|
None,
|
|
ShowFormAtCycleBeginning,
|
|
ShowFormAtCycleEnd,
|
|
}
|
|
|
|
CurrentOp currentOp;
|
|
|
|
public EntryForm(EntryFormCfg cfg)
|
|
{
|
|
if (cfg == null) throw new ArgumentNullException("cfg");
|
|
this.entryFormCfg = cfg;
|
|
currentOp = CurrentOp.None;
|
|
}
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
public IOperation ShowFormAtCycleBeginningOp(IList<GenericDevices.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 ShowFormAtCycleEndOp(IList<GenericDevices.IWaterMeter> waterMeters)
|
|
{
|
|
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
|
|
currentOp = CurrentOp.ShowFormAtCycleEnd;
|
|
this.waterMeters = waterMeters;
|
|
return this;
|
|
}
|
|
|
|
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;
|
|
myRef.modelessDlg = endForm;
|
|
modelessDlg.Show();
|
|
}
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Start()
|
|
{
|
|
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 as GenericDevices.IHasCompleted).Completed) return Event.None;
|
|
|
|
if (modelessDlg is CycleBeginningForm)
|
|
{
|
|
if (waterMeters.Count >= 1 && waterMeters[0] != null)
|
|
{
|
|
mainBeginStateText = (modelessDlg as CycleBeginningForm).MainStateText;
|
|
waterMeters[0].SerialNr = (modelessDlg as CycleBeginningForm).MainSNText;
|
|
}
|
|
if (waterMeters.Count >= 2 && waterMeters[1] != null)
|
|
{
|
|
auxBeginStateText = (modelessDlg as CycleBeginningForm).AuxStateText;
|
|
waterMeters[1].SerialNr = (modelessDlg as CycleBeginningForm).AuxSNText;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (waterMeters.Count >= 1 && waterMeters[0] != null)
|
|
{
|
|
waterMeters[0].EndState = (modelessDlg as CycleEndForm).MainStateText;
|
|
}
|
|
if (waterMeters.Count >= 2 && waterMeters[1] != null)
|
|
{
|
|
waterMeters[1].EndState = (modelessDlg as CycleEndForm).AuxStateText;
|
|
}
|
|
protocolTitle = (modelessDlg as CycleEndForm).ProtocolTitle;
|
|
}
|
|
return Event.Done;
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop()
|
|
{
|
|
modelessDlg = null;
|
|
currentOp = CurrentOp.None;
|
|
}
|
|
}
|
|
}
|