tbf/TestBenchFramework/BenchControl/DataEntry/Munich3/EntryForm.cs

133 lines
4.7 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using TBF.BenchControl;
namespace TBF.BenchControl.DataEntry.Munich3
{
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 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(Program.WMsCount);
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)
{
CycleBeginningForm dlg = (modelessDlg as CycleBeginningForm);
if (dlg.WaterMetersCount > 0 && waterMeters[0] != null) waterMeters[0].SerialNr = dlg.SNText[0];
if (dlg.WaterMetersCount > 1 && waterMeters[1] != null) waterMeters[1].SerialNr = dlg.SNText[1];
if (dlg.WaterMetersCount > 2 && waterMeters[2] != null) waterMeters[2].SerialNr = dlg.SNText[2];
if (dlg.WaterMetersCount > 3 && waterMeters[3] != null) waterMeters[3].SerialNr = dlg.SNText[3];
if (dlg.WaterMetersCount > 4 && waterMeters[4] != null) waterMeters[4].SerialNr = dlg.SNText[4];
if (dlg.WaterMetersCount > 5 && waterMeters[5] != null) waterMeters[5].SerialNr = dlg.SNText[5];
}
else if (modelessDlg is CycleEndForm)
{
CycleEndForm dlg = (modelessDlg as CycleEndForm);
protocolTitle = dlg.ProtocolTitle;
if (dlg.WaterMetersCount > 0 && waterMeters[0] != null) waterMeters[0].EndState = dlg.EndStateText[0];
if (dlg.WaterMetersCount > 1 && waterMeters[1] != null) waterMeters[1].EndState = dlg.EndStateText[1];
if (dlg.WaterMetersCount > 2 && waterMeters[2] != null) waterMeters[2].EndState = dlg.EndStateText[2];
if (dlg.WaterMetersCount > 3 && waterMeters[3] != null) waterMeters[3].EndState = dlg.EndStateText[3];
if (dlg.WaterMetersCount > 4 && waterMeters[4] != null) waterMeters[4].EndState = dlg.EndStateText[4];
if (dlg.WaterMetersCount > 5 && waterMeters[5] != null) waterMeters[5].EndState = dlg.EndStateText[5];
}
return Event.Done;
}
/// <summary>Stop this operation</summary>
public void Stop()
{
modelessDlg = null;
currentOp = CurrentOp.None;
}
}
}