2014-07-28 20:13:30 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2014-12-29 23:17:45 +00:00
|
|
|
|
using log4net;
|
2014-07-28 20:13:30 +00:00
|
|
|
|
using TBF.BenchControl;
|
2014-07-28 21:12:43 +00:00
|
|
|
|
using TBF.BenchControl.GenericDevices;
|
2014-07-28 20:13:30 +00:00
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl.DataEntry.Munich3
|
|
|
|
|
|
{
|
2014-12-31 12:46:33 +00:00
|
|
|
|
public class EntryForm : ComponentBase, IOperation, IDataEntry, IHasCycleBeginForm, IHasCycleEndForm, IHasProtocolTitle
|
2014-07-28 20:13:30 +00:00
|
|
|
|
{
|
2014-12-29 23:17:45 +00:00
|
|
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(EntryForm));
|
2014-12-31 12:46:33 +00:00
|
|
|
|
public override string ToString() { return string.Format("DataEntry.Munich3({0})", Cfg.ToString(1)); }
|
2014-12-29 23:17:45 +00:00
|
|
|
|
|
|
|
|
|
|
readonly EntryFormCfg entryFormCfg;
|
2014-07-28 20:13:30 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Properties set by the Begin and the End form
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string ProtocolTitle { get { return protocolTitle; } }
|
|
|
|
|
|
string protocolTitle;
|
|
|
|
|
|
|
2014-09-16 19:05:54 +00:00
|
|
|
|
/// <summary> Not supported in Munich </summary>
|
2014-12-31 12:46:33 +00:00
|
|
|
|
public string SerialNr(int wmNr) { return string.Empty; }
|
2014-09-16 19:05:54 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary> Not supported in Munich </summary>
|
2014-12-31 12:46:33 +00:00
|
|
|
|
public float WMState(int wmNr) { return 0; }
|
2014-09-16 19:05:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
2014-07-28 20:13:30 +00:00
|
|
|
|
System.Windows.Forms.Form modelessDlg;
|
|
|
|
|
|
|
2014-08-08 10:45:15 +00:00
|
|
|
|
bool resultSaved;
|
|
|
|
|
|
|
2014-09-23 11:16:59 +00:00
|
|
|
|
IList<IWaterMeter> waterMeters;
|
2014-07-28 20:13:30 +00:00
|
|
|
|
|
|
|
|
|
|
public enum CurrentOp
|
|
|
|
|
|
{
|
|
|
|
|
|
None,
|
|
|
|
|
|
ShowFormAtCycleBeginning,
|
|
|
|
|
|
ShowFormAtCycleEnd,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CurrentOp currentOp;
|
|
|
|
|
|
|
2014-12-31 12:46:33 +00:00
|
|
|
|
|
2014-07-28 20:13:30 +00:00
|
|
|
|
public EntryForm(EntryFormCfg cfg)
|
2014-12-31 12:46:33 +00:00
|
|
|
|
: base(cfg)
|
2014-07-28 20:13:30 +00:00
|
|
|
|
{
|
2014-12-31 12:46:33 +00:00
|
|
|
|
entryFormCfg = cfg;
|
2014-07-28 20:13:30 +00:00
|
|
|
|
currentOp = CurrentOp.None;
|
2014-12-29 23:17:45 +00:00
|
|
|
|
log.Debug(this.ToString());
|
|
|
|
|
|
}
|
2014-07-28 20:13:30 +00:00
|
|
|
|
|
|
|
|
|
|
/// <returns>Reference to the operation</returns>
|
2014-09-23 11:16:59 +00:00
|
|
|
|
public IOperation ShowCycleBeginFormOp(IList<IWaterMeter> waterMeters)
|
2014-07-28 20:13:30 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
|
|
|
|
|
|
currentOp = CurrentOp.ShowFormAtCycleBeginning;
|
|
|
|
|
|
this.waterMeters = waterMeters;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <returns>Reference to the operation</returns>
|
2014-09-23 11:16:59 +00:00
|
|
|
|
public IOperation ShowCycleEndFormOp(IList<IWaterMeter> waterMeters)
|
2014-07-28 20:13:30 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
|
|
|
|
|
|
currentOp = CurrentOp.ShowFormAtCycleEnd;
|
|
|
|
|
|
this.waterMeters = waterMeters;
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-09-16 19:05:54 +00:00
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
|
|
|
|
public IOperation ShowWMSNsAndStatesFormOp()
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <returns>Reference to the operation</returns>
|
|
|
|
|
|
public IOperation ShowWMStatesFormOp()
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-28 20:13:30 +00:00
|
|
|
|
delegate void EntryFormDlgt(EntryForm myRef);
|
|
|
|
|
|
///
|
|
|
|
|
|
void OpenBeginningDlg(EntryForm myRef)
|
|
|
|
|
|
{
|
|
|
|
|
|
myRef.modelessDlg = new CycleBeginningForm(Program.WMsCount);
|
|
|
|
|
|
modelessDlg.Show();
|
|
|
|
|
|
}
|
|
|
|
|
|
///
|
|
|
|
|
|
void OpenEndDlg(EntryForm myRef)
|
|
|
|
|
|
{
|
2014-09-16 19:05:54 +00:00
|
|
|
|
CycleEndForm endForm = new CycleEndForm(Program.WMsCount);
|
2014-07-28 20:13:30 +00:00
|
|
|
|
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()
|
|
|
|
|
|
{
|
2014-08-08 10:45:15 +00:00
|
|
|
|
resultSaved = false;
|
|
|
|
|
|
switch (currentOp)
|
2014-07-28 20:13:30 +00:00
|
|
|
|
{
|
|
|
|
|
|
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()
|
|
|
|
|
|
{
|
2014-09-23 11:16:59 +00:00
|
|
|
|
if (!(modelessDlg as IHasCompleted).Completed)
|
2014-08-08 10:45:15 +00:00
|
|
|
|
{
|
|
|
|
|
|
return Event.None; /// Return 'None' when form was not closed yet
|
|
|
|
|
|
}
|
2014-07-28 20:13:30 +00:00
|
|
|
|
|
2014-08-08 10:45:15 +00:00
|
|
|
|
if (!resultSaved) /// This is to save the result only once
|
2014-07-28 20:13:30 +00:00
|
|
|
|
{
|
2014-08-08 10:45:15 +00:00
|
|
|
|
if (modelessDlg is CycleBeginningForm)
|
|
|
|
|
|
{
|
|
|
|
|
|
CycleBeginningForm dlg = (modelessDlg as CycleBeginningForm);
|
2015-01-27 21:59:25 +00:00
|
|
|
|
int count = Math.Min(dlg.WaterMetersCount, waterMeters.Count);
|
|
|
|
|
|
|
|
|
|
|
|
if (count > 0 && waterMeters[0] != null) waterMeters[0].SerialNr = dlg.SNText[0];
|
|
|
|
|
|
if (count > 1 && waterMeters[1] != null) waterMeters[1].SerialNr = dlg.SNText[1];
|
|
|
|
|
|
if (count > 2 && waterMeters[2] != null) waterMeters[2].SerialNr = dlg.SNText[2];
|
|
|
|
|
|
if (count > 3 && waterMeters[3] != null) waterMeters[3].SerialNr = dlg.SNText[3];
|
|
|
|
|
|
if (count > 4 && waterMeters[4] != null) waterMeters[4].SerialNr = dlg.SNText[4];
|
|
|
|
|
|
if (count > 5 && waterMeters[5] != null) waterMeters[5].SerialNr = dlg.SNText[5];
|
2014-08-08 10:45:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
else if (modelessDlg is CycleEndForm)
|
|
|
|
|
|
{
|
|
|
|
|
|
CycleEndForm dlg = (modelessDlg as CycleEndForm);
|
2015-01-27 21:59:25 +00:00
|
|
|
|
int count = Math.Min(dlg.WaterMetersCount, waterMeters.Count);
|
2014-08-08 10:45:15 +00:00
|
|
|
|
protocolTitle = dlg.ProtocolTitle;
|
2015-01-27 21:59:25 +00:00
|
|
|
|
|
|
|
|
|
|
if (count > 0 && waterMeters[0] != null) waterMeters[0].EndState = dlg.EndStateText[0];
|
|
|
|
|
|
if (count > 1 && waterMeters[1] != null) waterMeters[1].EndState = dlg.EndStateText[1];
|
|
|
|
|
|
if (count > 2 && waterMeters[2] != null) waterMeters[2].EndState = dlg.EndStateText[2];
|
|
|
|
|
|
if (count > 3 && waterMeters[3] != null) waterMeters[3].EndState = dlg.EndStateText[3];
|
|
|
|
|
|
if (count > 4 && waterMeters[4] != null) waterMeters[4].EndState = dlg.EndStateText[4];
|
|
|
|
|
|
if (count > 5 && waterMeters[5] != null) waterMeters[5].EndState = dlg.EndStateText[5];
|
2014-08-08 10:45:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
resultSaved = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-08-08 14:25:51 +00:00
|
|
|
|
return Event.ModelessFormClosed; /// Form closed
|
2014-07-28 20:13:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
|
{
|
|
|
|
|
|
modelessDlg = null;
|
|
|
|
|
|
currentOp = CurrentOp.None;
|
|
|
|
|
|
}
|
2014-07-28 21:12:43 +00:00
|
|
|
|
|
|
|
|
|
|
/// <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.Single) continue;
|
|
|
|
|
|
|
2015-01-15 04:03:46 +00:00
|
|
|
|
int nrMtrsToUpdate = Math.Max(waterMeters.Count, test.Meters.Count);
|
|
|
|
|
|
for (int i = 0; i < nrMtrsToUpdate; i++)
|
2014-07-29 06:42:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
test.Meters[i].SerialNr = waterMeters[i].SerialNr;
|
|
|
|
|
|
test.Meters[i].EndState = waterMeters[i].EndState;
|
|
|
|
|
|
}
|
2014-07-28 21:12:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-07-28 20:13:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|