- new component with VZ15 and modified position of VZ13 - fixed start method evaluation OK - handling of entry forms cleaned-up
197 lines
5.8 KiB
C#
197 lines
5.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using TBF.BenchControl;
|
|
using TBF.BenchControl.GenericDevices;
|
|
|
|
namespace TBF.BenchControl.DataEntry.Munich
|
|
{
|
|
public class EntryForm : Generic.IComponent, IOperation, IDataEntry, IHasCycleBeginForm, IHasCycleEndForm, 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;
|
|
|
|
|
|
/// <summary> Not supported in Munich </summary>
|
|
public string SerialNr(int wmNr)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
/// <summary> Not supported in Munich </summary>
|
|
public float WMState(int wmNr)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
|
|
System.Windows.Forms.Form modelessDlg;
|
|
|
|
bool resultSaved;
|
|
|
|
IList<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 ShowCycleBeginFormOp(IList<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 ShowCycleEndFormOp(IList<IWaterMeter> 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 ShowWMSNsAndStatesFormOp()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
public IOperation ShowWMStatesFormOp()
|
|
{
|
|
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;
|
|
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 as IHasCompleted).Completed)
|
|
{
|
|
return Event.None; /// Return 'None' when form was not closed yet
|
|
}
|
|
|
|
if (!resultSaved) /// This is to save the result only once
|
|
{
|
|
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;
|
|
}
|
|
resultSaved = true;
|
|
}
|
|
|
|
return Event.ModelessFormClosed; /// Form closed
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop()
|
|
{
|
|
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="results">Test results to be updated with the information</param>
|
|
public void UpdateTestResults(IList<IWaterMeter> waterMeters, IList<Entities.TestResult> results)
|
|
{
|
|
foreach (var test in results)
|
|
{
|
|
if (test.MetersKind != Entities.MetersKind.Combined) continue;
|
|
|
|
/// Todo: Generalize !!! Now implemented for Munich = one combined meter.
|
|
test.Meters[0].SerialNr = waterMeters[0].SerialNr;
|
|
test.Meters[0].EndState = waterMeters[0].EndState;
|
|
test.Meters[1].SerialNr = waterMeters[1].SerialNr;
|
|
test.Meters[1].EndState = waterMeters[1].EndState;
|
|
}
|
|
}
|
|
}
|
|
}
|