/// /// 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; /// /// Properties set by the Begin and the End form /// public string PurchaseOrder { get { return string.Empty; } } /// Not supported in Munich 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; bool resultSaved; /// Set in Run() when results are saved Results.Entities.WaterMeter[] wMeters; /// Reference to ...ProcessData.BatchRslts.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.Debug(this.ToString()); } /// Reference to the operation public IOperation ShowCycleBeginFormOp() { if (currentOp != CurrentOp.None) throw new Exception("Sequence error"); currentOp = CurrentOp.ShowFormAtCycleBeginning; this.wMeters = TBF.BenchControl.Sequences.ProcessData.BatchRslts.WaterMeters; return this; } /// Reference to the operation public IOperation ShowCycleEndFormOp() { if (currentOp != CurrentOp.None) throw new Exception("Sequence error"); currentOp = CurrentOp.ShowFormAtCycleEnd; this.wMeters = TBF.BenchControl.Sequences.ProcessData.BatchRslts.WaterMeters; return this; } /// Reference to the operation 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(); } /// Start this operation 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; } } /// Run this operation /// Event.ResultsPrinted 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.Length, 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 } /// Stop this operation public void Stop() { if (modelessDlg is IHasCompleted) { UiBridge.Bridge.OnCloseModelessForm(this, null); modelessDlg = null; } currentOp = CurrentOp.None; } /// /// Updates test results with the information collected in watermeters. /// /// Watermetes with information entered in the forms /// Test results to be updated with the information public void UpdateTestResults(Results.BatchResults results) { /// Nothing to be done } } }