diff --git a/Config/Formulas.cs b/Config/Formulas.cs index 971177d57..9357d5203 100644 --- a/Config/Formulas.cs +++ b/Config/Formulas.cs @@ -214,9 +214,9 @@ namespace Config /// public static double ErrorFromVolumes(double measuredVolume, double trueVolume) { - if (trueVolume <= float.Epsilon) + if (-float.Epsilon <= trueVolume && trueVolume <= float.Epsilon) { - if (measuredVolume <= float.Epsilon) + if (-float.Epsilon <= measuredVolume && measuredVolume <= float.Epsilon) { log.WarnFormat("ErrorFromVolumes({0},{1}) returns {2}", measuredVolume, trueVolume, -100.0); return -100.0; diff --git a/Results/Entities/Batch.cs b/Results/Entities/Batch.cs index 72dd57829..43abe6b51 100644 --- a/Results/Entities/Batch.cs +++ b/Results/Entities/Batch.cs @@ -24,6 +24,8 @@ namespace Results.Entities public virtual int UserNumber { get; set; } public virtual string ProcedureName { get; set; } public virtual bool IsRemoteProcedure { get; set; } /// Stara Tura, not mapped to DB + public virtual string PurchaseOrder { get; set; } /// Stara Tura, Nanjing, not mapped to DB + public virtual string Workflow { get; set; } /// Stara Tura, Nanjing, not mapped to DB public virtual string ProcedureDescription { get; set; } /// CEVAK, not mapped to DB public virtual int ProcedureRevision { get; set; } public virtual string WatermetersStr { get; set; } /// CEVAK, not mapped to DB diff --git a/Results/Entities/WaterMeter.cs b/Results/Entities/WaterMeter.cs index de109113a..9170ace6b 100644 --- a/Results/Entities/WaterMeter.cs +++ b/Results/Entities/WaterMeter.cs @@ -109,7 +109,13 @@ namespace Results.Entities /// /// Wrappers /// - public virtual string ProductName() { return WaterMeterData.ProductName; } + public virtual string GetEndStateAux() { return Compound() ? EndStateAux : string.Empty; } + public virtual void SetEndStateAux(string s) { if (Compound()) EndStateAux = s; } + + public virtual string GetStartState() { return Compound() ? string.Empty : EndStateAux; } + public virtual void SetStartState(string s) { if (!Compound()) EndStateAux = s; } + + public virtual string ProductName() { return WaterMeterData.ProductName; } public virtual string Producer() { return WaterMeterData.Producer; } public virtual string MetrologicalClass() { return WaterMeterData.MetrologicalClass; } public virtual string ApprovalInfo() { return WaterMeterData.ApprovalInfo; } diff --git a/TBF/LocalSettings.cs b/TBF/LocalSettings.cs index 320241952..656cd417a 100644 --- a/TBF/LocalSettings.cs +++ b/TBF/LocalSettings.cs @@ -231,6 +231,27 @@ namespace TBF public string LastText3; public string LastRemark; + /// DataEntry.Uni history + public string[] LastBgComm1; + public string[] LastBgComm2; + public string[] LastBgComm3; + /// + public string[] LastBgColA; + public string[] LastBgColB; + public string[] LastBgColC; + public string[] LastBgColD; + public string[] LastBgColE; + /// + public string[] LastEnComm1; + public string[] LastEnComm2; + public string[] LastEnComm3; + /// + public string[] LastEnColA; + public string[] LastEnColB; + public string[] LastEnColC; + public string[] LastEnColD; + public string[] LastEnColE; + /// Purchase order history public string[] PurchaseOrderHistory; [XmlIgnore] diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index 570afeb65..88996732c 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("2.33.2061.0")] -[assembly: AssemblyFileVersion("2.33.2061.0")] +[assembly: AssemblyVersion("2.33.2070.0")] +[assembly: AssemblyFileVersion("2.33.2070.0")] diff --git a/TBF/Rig/DataEntry/DEItem.cs b/TBF/Rig/DataEntry/DEItem.cs new file mode 100644 index 000000000..fcadb3098 --- /dev/null +++ b/TBF/Rig/DataEntry/DEItem.cs @@ -0,0 +1,95 @@ +/// +/// Copyright (c) 2023 Sensus Slovensko a.s. +/// +using System.Collections.Generic; +using Common; + +namespace TBF.Rig.DataEntry +{ + /// + /// Ac = Action + /// + public enum Ac + { + [Description("Clear")] Clear, /// Clear when the form is open, save on OK + [Description("Last from history")] HistoryLast, + [Description("Load")] Load, /// Load from water meters when the form is open, save on OK + [Description("Load (readonly)")] LoadReadOnly, /// Load from water meters when the form is open, prevent changes, do not save + Count, + } + + /// + /// Ct = Content + /// + public enum Ct + { + [Description("None")] None, + [Description("Serial nr.")] SerialNr, + [Description("Serial nr. aux")] SerialNrAux, + [Description("Radio address")] RadioAddress, + [Description("Year of calibration")] YearOfCalibration, + [Description("Start state")] StartState, + [Description("End state")] EndState, + [Description("Archive path")] ArchivePath, + [Description("WM Order")] WmOrder, + [Description("Batch order")] BatchOrder, + [Description("Batch and WM order")] BatchAndWmOrder, + [Description("WM Remark")] WmRemark, + [Description("Batch remark")] BatchRemark, + [Description("Batch and WM remark")] BatchAndWmRemark, +#if ORACLE_DB + [Description("Prefix")] Prefix, + [Description("Suffix")] Suffix, +#endif + Count + } + + public class DEItem + { + public readonly Ct Content; + public readonly string Caption; + public readonly Ac Action; + public readonly int Width; + + public DEItem(Ct content, string caption, Ac action, int width) + { + Content = content; + Caption = caption; + Action = action; + Width = width; + } + + + static IList items = new List(); + /// + public static void ClearItems() { items.Clear(); } + public static void AddItem(DEItem item) { items.Add(item); } + public static void AddItem(Ct content, string caption, Ac action, int width) + { + items.Add(new DEItem(content, caption, action, width)); + } + public static IList GetItems() { return items; } + + + static IList columns = new List(); + /// + public static void ClearColumns() { columns.Clear(); } + public static void AddColumn(DEItem column) { columns.Add(column); } + public static void AddColumn(Ct content, string caption, Ac action, int width) + { + columns.Add(new DEItem(content, caption, action, width)); + } + public static IList GetColumns() { return columns; } + + + static IList summaryColumns = new List(); + /// + public static void ClearSummaryColumns() { summaryColumns.Clear(); } + public static void AddSummaryColumn(DEItem column) { summaryColumns.Add(column); } + public static void AddSummaryColumn(Ct content, string caption, Ac action, int width) + { + summaryColumns.Add(new DEItem(content, caption, action, width)); + } + public static IList GetSummaryColumns() { return summaryColumns; } + } +} diff --git a/TBF/Rig/DataEntry/DEUtils.cs b/TBF/Rig/DataEntry/DEUtils.cs index a808ada34..da8a432fe 100644 --- a/TBF/Rig/DataEntry/DEUtils.cs +++ b/TBF/Rig/DataEntry/DEUtils.cs @@ -1,13 +1,85 @@ /// -/// Copyright (c) 2018 Sensus Slovensko a.s. +/// Copyright (c) 2018-2023 Sensus Slovensko a.s. /// -using System; using System.Windows.Forms; +using Results.Entities; namespace TBF.Rig.DataEntry { public class DEUtils { + public static string GetContent(Ct content, WaterMeter wm) + { + if (wm == null) return string.Empty; + + switch (content) + { + default: + case Ct.None: return string.Empty; + case Ct.SerialNr: return (!wm.Disabled && wm.SerialNr != null) ? wm.SerialNr : string.Empty; + case Ct.SerialNrAux: return (!wm.Disabled && wm.SerialNrAux != null) ? wm.SerialNrAux : string.Empty; + case Ct.RadioAddress: return (!wm.Disabled && wm.RadioAddress != null) ? wm.RadioAddress : string.Empty; + case Ct.YearOfCalibration: return (!wm.Disabled) ? wm.YearOfProduction.ToString() : string.Empty; + case Ct.StartState: return (!wm.Disabled && wm.GetStartState() != null) ? wm.GetStartState() : string.Empty; + case Ct.EndState: return (!wm.Disabled && wm.EndState != null) ? wm.EndState : string.Empty; + case Ct.ArchivePath: return (!wm.Disabled && wm.ArchivePath != null) ? wm.ArchivePath : string.Empty; + + case Ct.WmOrder: return (!wm.Disabled && wm.PurchaseOrder != null) ? wm.PurchaseOrder : string.Empty; + case Ct.BatchOrder: return (wm.Batch != null && wm.Batch.PurchaseOrder != null) ? wm.Batch.PurchaseOrder : string.Empty; + case Ct.BatchAndWmOrder: return (wm.Batch != null && wm.Batch.PurchaseOrder != null) ? wm.Batch.PurchaseOrder : string.Empty; + + case Ct.WmRemark: return (!wm.Disabled && wm.Remark != null) ? wm.Remark : string.Empty; + case Ct.BatchRemark: return (wm.Batch != null && wm.Batch.Remark != null) ? wm.Batch.Remark : string.Empty; + case Ct.BatchAndWmRemark: return (wm.Batch != null && wm.Batch.Remark != null) ? wm.Batch.Remark : string.Empty; +#if ORACLE_DB + case Ct.Prefix: return (!wm.Disabled && wm.Prefix != null) ? wm.Prefix : string.Empty; + case Ct.Suffix: return (!wm.Disabled && wm.Suffix != null) ? wm.Suffix : string.Empty; +#endif + } + } + + public static void PutContent(Ct content, WaterMeter wm, string value) + { + if (wm == null || wm.Disabled) return; + + int year; + + switch (content) + { + default: + case Ct.None: return; + case Ct.SerialNr: wm.SerialNr = value; return; + case Ct.SerialNrAux: wm.SerialNrAux = value; return; + case Ct.RadioAddress: wm.RadioAddress = value; return; + case Ct.YearOfCalibration: if (int.TryParse(value, out year)) wm.YearOfProduction = year; return; + case Ct.StartState: wm.SetStartState(value); return; + case Ct.EndState: wm.EndState = value; return; + case Ct.ArchivePath: wm.ArchivePath = value; return; + + case Ct.WmOrder: + wm.PurchaseOrder = value; + return; + + case Ct.BatchOrder: + case Ct.BatchAndWmOrder: + if (wm.Batch != null) wm.Batch.PurchaseOrder = value; + return; + + case Ct.WmRemark: + wm.Remark = value; + return; + + case Ct.BatchRemark: + case Ct.BatchAndWmRemark: + if (wm.Batch != null) wm.Batch.Remark = value; + return; +#if ORACLE_DB + case Ct.Prefix: wm.Prefix = value; return; + case Ct.Suffix: wm.Suffix = value; return; +#endif + } + } + /// /// Load Purchase order combo box items from the LocalSettings PurchaseOrderHistory array /// diff --git a/TBF/Rig/DataEntry/Uni/CycleBgEnForm.cs b/TBF/Rig/DataEntry/Uni/CycleBgEnForm.cs new file mode 100644 index 000000000..7ada3da43 --- /dev/null +++ b/TBF/Rig/DataEntry/Uni/CycleBgEnForm.cs @@ -0,0 +1,736 @@ +/// +/// Copyright (c) 2023 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using log4net; +using Results.Entities; +using TBF.Resources; + +namespace TBF.Rig.DataEntry.Uni +{ + public partial class CycleBgEnForm : Form, GenericDevices.IHasCompleted + { + private static readonly ILog log = LogManager.GetLogger(typeof(CycleBgEnForm)); + + /// Arguments + public readonly IList WaterMeters; + readonly int lineSize; + readonly Sz sz; + readonly bool isLrOrder; /// true = controls obtain focus after ENTER key in left-right order, false = top-down order + readonly IList commonItems; + readonly IList colItems; + readonly bool isEnd; + readonly string formCloseKeys; + + /// Derived from arguments in the constructor + readonly WaterMeter firstValidWM; + readonly int wmsCount; + readonly int linesCount; + readonly int commonItemsCount; + + /// Size and layout related values + readonly Font font; + readonly int meterHeight; + readonly int meterWidth; + readonly int margin; + readonly int spacing; + readonly int buttonsWidth; + readonly int hdrHeight; + readonly int labelWid; + readonly int checkBoxWid; + + /// UI elements + readonly Label[] commonLabels; + readonly ComboBox[] commonComboBoxes; + readonly Label[] labels; /// Labels for water meter numbers + readonly ComboBox[,] comboBoxes; /// Combo boxes for values in columns + readonly CheckBox[] checkBoxes; /// Check boxes for water meter enable/disable + + readonly LocalSettings ls; + + bool isHandlersEnabled; /// Initially false, set to true after ComboBoxes are filled with data + + /// Set to 'true' when the form closes + public bool Completed { get { return completed; } } + bool completed; + + + /// + /// Parameterless constructor for common functionality + /// + public CycleBgEnForm() + { + InitializeComponent(); + ControlBox = false; + completed = false; + StartForceCloseHandler(); + } + + /// + /// Constructor + /// + /// Water meters + /// Number of water meters in one (test bencch) line + /// Form title + /// Font size + /// true = controls obtain focus in left-right order, forls = top-down order + /// String containing keys to close this form + /// Common items displayed in the upper part of the form + /// Water meter items displayed in columns (in the matrix in the main part of the form) + /// true = This form is displayed at the end of cycle + public CycleBgEnForm(IList waterMeters, int lineSize, string title, Sz sz, bool isLrOrder, string formCloseKeys, + IList commonItems, IList colItems, bool isEnd = false) + : this() + { + /// Arguments + this.WaterMeters = waterMeters; + this.lineSize = lineSize; + this.Text = !string.IsNullOrEmpty(title) ? title : string.Empty; + this.sz = sz; + this.isLrOrder = isLrOrder; + this.formCloseKeys = !string.IsNullOrEmpty(formCloseKeys) ? formCloseKeys : string.Empty; + this.commonItems = commonItems; + this.colItems = colItems; + this.isEnd = isEnd; + + /// Preserve column items for use in SummaryResults + if (!isEnd) + { + /// cycle beginning + DEItem.ClearSummaryColumns(); + foreach (var it in colItems) if (it.Content != Ct.SerialNr) DEItem.AddSummaryColumn(it); + } + else + { + /// cycle end + foreach (var it in colItems) if (it.Content != Ct.SerialNr) DEItem.AddSummaryColumn(it); + } + + ls = Program.LocalSettings; + + /// Readonly variables derived from arguments + commonItemsCount = (commonItems == null) ? 0 : commonItems.Count; + wmsCount = (waterMeters == null) ? 0 : waterMeters.Count; + linesCount = (wmsCount + Math.Max(1, lineSize) - 1) / Math.Max(1, lineSize); + firstValidWM = (waterMeters != null) ? waterMeters.FirstOrDefault(x => (x != null && !x.Disabled)) : null; + /// + commonLabels = new Label[commonItemsCount]; + commonComboBoxes = new ComboBox[commonItemsCount]; + labels = new Label[wmsCount]; + comboBoxes = new ComboBox[colItems.Count, wmsCount]; + checkBoxes = new CheckBox[wmsCount]; + + /// Layout related readonly variables derived from argument 'sz' + switch (sz) + { + case Sz.S: + font = new Font("Verdana", 12, FontStyle.Regular); + meterHeight = 26; /// Height of a ComboBox control + margin = 20; + spacing = 8; + buttonsWidth = 350; + hdrHeight = 120; + labelWid = 31; + checkBoxWid = 23; + break; + + default: + case Sz.M: + font = new Font("Verdana", 14, FontStyle.Regular); + meterHeight = 31; /// Height of a ComboBox control + margin = 25; + spacing = 10; + buttonsWidth = 350; + hdrHeight = 140; + labelWid = 34; + checkBoxWid = 23; + break; + + case Sz.L: + font = new Font("Verdana", 18, FontStyle.Regular); + meterHeight = 37; /// Height of a ComboBox control + margin = 30; + spacing = 12; + buttonsWidth = 350; + hdrHeight = 160; + labelWid = 40; + checkBoxWid = 23; + break; + } + meterWidth = labelWid + checkBoxWid + spacing; + foreach (var ci in colItems) { meterWidth += ci.Width + spacing; } + + int tabIndex = 1; + + /// + /// Group box with common items + /// + int groupBoxWidth = 0; + int groupBoxHeight = 0; + if (commonItemsCount > 0) + { + var groupBox = new GroupBox(); + + int labelsWidth = 0; + for (int ix = 0; ix < commonItemsCount; ix++) + { + int oneLabelWidth = Convert.ToInt32(Graphics.FromImage(new Bitmap(1, 1)).MeasureString(commonItems[ix].Caption, font).Width); + var oneLabel = new Label + { + Text = commonItems[ix].Caption, + Font = font, + Location = new Point(margin, (ix + 2) * spacing + ix * meterHeight), + Size = new Size(oneLabelWidth + spacing, meterHeight), + TextAlign = ContentAlignment.MiddleLeft, + TabIndex = tabIndex++, + Parent = groupBox, + }; + groupBox.Controls.Add(oneLabel); + labelsWidth = Math.Max(labelsWidth, oneLabelWidth); + } + + int combosWidth = 0; + for (int ix = 0; ix < commonItemsCount; ix++) + { + var cb = new ComboBox + { + Name = string.Format("-1~{0}", ix + 1), + Location = new Point(margin + spacing + labelsWidth, (ix + 2) * spacing + ix * meterHeight), + Size = new Size(commonItems[ix].Width, meterHeight), + Enabled = (commonItems[ix].Action != Ac.LoadReadOnly), + Font = font, + TabIndex = tabIndex++, + Parent = groupBox, + }; + + cb.SelectedIndexChanged += new System.EventHandler(comboBox_SelectedIndexChanged); + cb.TextChanged += new System.EventHandler(comboBox_TextChanged); + cb.KeyPress += new System.Windows.Forms.KeyPressEventHandler(comboBox_KeyPress); + + switch (ix) + { + case 0: AddHistoryToCombo(cb, isEnd ? ls.LastEnComm1 : ls.LastBgComm1); break; + case 1: AddHistoryToCombo(cb, isEnd ? ls.LastEnComm2 : ls.LastBgComm2); break; + case 2: AddHistoryToCombo(cb, isEnd ? ls.LastEnComm3 : ls.LastBgComm3); break; + } + + commonComboBoxes[ix] = cb; + groupBox.Controls.Add(cb); + combosWidth = Math.Max(combosWidth, commonItems[ix].Width); + } + /// + groupBox.Location = new Point(margin, margin - spacing); + groupBoxWidth = labelsWidth + combosWidth + 2 * margin + spacing; + groupBoxHeight = commonItemsCount * meterHeight + (commonItemsCount + 2) * spacing; + groupBox.Size = new Size(groupBoxWidth, groupBoxHeight); + groupBox.Font = font; + groupBox.TabIndex = tabIndex++; + groupBox.Parent = this; + this.Controls.Add(groupBox); + } + + /// + /// Table + /// + int columnsTop = Math.Max(hdrHeight, groupBoxHeight + 2 * margin + spacing); + for (int j = 0; j < linesCount; j++) + { + /// Captions + int capX = margin + j * (meterWidth + margin / 2) + labelWid + spacing; + int capY = columnsTop - meterHeight; + for (int k = 0; k < colItems.Count; k++) + { + int labelWidth = Convert.ToInt32(Graphics.FromImage(new Bitmap(1, 1)).MeasureString(colItems[k].Caption, font).Width); + var label = new Label + { + Text = colItems[k].Caption, + Location = new Point(capX, capY), + Size = new Size(labelWidth + spacing, meterHeight), + Font = font, + TabIndex = tabIndex++, + Parent = this, + }; + capX += colItems[k].Width + spacing; + } + + /// Water meters + for (int i = 0; i < lineSize; i++) + { + int wmPos0 = i + lineSize * j; + if (wmPos0 > wmsCount) continue; + + int left = margin + j * (meterWidth + margin / 2); + int top = columnsTop + i * (meterHeight + spacing); + + var label = new Label + { + Text = (wmPos0 + 1).ToString(), + Location = new Point(left, top), + Size = new Size(labelWid, meterHeight), + Font = font, + TextAlign = ContentAlignment.MiddleLeft, + TabIndex = tabIndex++, + Parent = this, + }; + left += labelWid + spacing / 2; + labels[wmPos0] = label; + this.Controls.Add(label); + + /// Columns + for (int k = 0; k < colItems.Count; k++) + { + DEItem ci = colItems[k]; + var comboBox = new ComboBox + { + Name = string.Format("{0}~{1}", k, wmPos0), + Location = new Point(left, top), + Size = new Size(ci.Width, meterHeight), + Enabled = (ci.Action != Ac.LoadReadOnly && !waterMeters[wmPos0].Disabled), + Font = font, + TabIndex = tabIndex++, + Parent = this, + }; + + comboBox.SelectedIndexChanged += new System.EventHandler(this.comboBox_SelectedIndexChanged); + comboBox.TextChanged += new System.EventHandler(this.comboBox_TextChanged); + comboBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.comboBox_KeyPress); + + var lastVals = GetHistoryFromLS(isEnd, k); + comboBox.Items.Add(lastVals.Length > wmPos0 ? lastVals[wmPos0] : string.Empty); /// History in drop-down menu + + left += ci.Width + spacing; + comboBoxes[k, wmPos0] = comboBox; + this.Controls.Add(comboBox); + } + + var checkBox = new CheckBox + { + Location = new Point(left, top + 6), + Size = new Size(checkBoxWid, 23), + TabIndex = tabIndex++, + Parent = this, + }; + checkBoxes[wmPos0] = checkBox; + this.Controls.Add(checkBox); + } + } + + /// + /// Adjust window size + /// + Rectangle screenRectangle = this.RectangleToScreen(this.ClientRectangle); + int titleBarHeight = screenRectangle.Top - this.Top; + Size = new Size(Math.Max(meterWidth * linesCount + margin * (linesCount + 1), margin + groupBoxWidth + buttonsWidth), + titleBarHeight + columnsTop + lineSize * (meterHeight + spacing) + margin); + + Localize(); + InitializeBoxes(); + + /// Set focus to the first enabled ComboBox + bool activeControlFound = false; + for (int ix = 0; ix < commonItemsCount; ix++) + { + if (commonComboBoxes[ix].Enabled) + { + ActiveControl = commonComboBoxes[ix]; + activeControlFound = true; + break; + } + } + if (!activeControlFound) + { + /// Initialize k,j so that after the 1st increment k = 0 and j = 0 + int k, j; + if (isLrOrder) { k = -1; j = 0; } + else { k = 0; j = -1; } + + /// Change focus + if (FindNextEnabledCombo(comboBoxes, ref k, ref j, isLrOrder)) + { + ActiveControl = okButton; + } + else + { + ActiveControl = comboBoxes[k, j]; + } + } + } + + /// + /// Add combo box items from a history stored in a string array (obtained usually from LocalSettings) + /// + /// ComboBox to prepare + /// String array with a history + void AddHistoryToCombo(ComboBox comboBox, string[] history) + { + if (history != null) + { + for (int i = 0; i < history.Length; i++) comboBox.Items.Add(history[i]); + } + } + + /// + /// Returns an array of strings from ls. + /// Never returns null, null is converted to new string[0]. + /// + /// false = Beginning of cycle, true = End of cycle + /// Column number (0-based) + /// Array of strings + string[] GetHistoryFromLS(bool isEnd, int k) + { + if (isEnd) + { + switch (k) + { + case 0: if (ls.LastEnColA == null) ls.LastEnColA = new string[0]; return ls.LastEnColA; + case 1: if (ls.LastEnColB == null) ls.LastEnColB = new string[0]; return ls.LastEnColB; + case 2: if (ls.LastEnColC == null) ls.LastEnColC = new string[0]; return ls.LastEnColC; + case 3: if (ls.LastEnColD == null) ls.LastEnColD = new string[0]; return ls.LastEnColD; + case 4: if (ls.LastEnColE == null) ls.LastEnColE = new string[0]; return ls.LastEnColE; + default: return new string[0]; + } + } + else + { + switch (k) + { + case 0: if (ls.LastBgColA == null) ls.LastBgColA = new string[0]; return ls.LastBgColA; + case 1: if (ls.LastBgColB == null) ls.LastBgColB = new string[0]; return ls.LastBgColB; + case 2: if (ls.LastBgColC == null) ls.LastBgColC = new string[0]; return ls.LastBgColC; + case 3: if (ls.LastBgColD == null) ls.LastBgColD = new string[0]; return ls.LastBgColD; + case 4: if (ls.LastBgColE == null) ls.LastBgColE = new string[0]; return ls.LastBgColE; + default: return new string[0]; + } + } + } + + void Localize() + { + okButton.Text = Strings.OkBtnText; + clearButton.Text = Strings.ClearBtnText; + } + + /// + /// Initialize combo boxes state defined by related 'Action'. + /// Clear check boxes. + /// + void InitializeBoxes() + { + isHandlersEnabled = false; + + /// Common combo boxes + for (int ix = 0; ix < commonItemsCount; ix++) + { + switch (commonItems[ix].Action) + { + default: + case Ac.Clear: + commonComboBoxes[ix].Text = string.Empty; + break; + + case Ac.HistoryLast: + commonComboBoxes[ix].Text = (commonComboBoxes[ix].Items.Count > 0) + ? commonComboBoxes[ix].Items[0].ToString() + : string.Empty; + break; + + case Ac.Load: + case Ac.LoadReadOnly: + commonComboBoxes[ix].Text = DEUtils.GetContent(commonItems[ix].Content, firstValidWM); + break; + } + } + + /// Table + for (int k = 0; k < colItems.Count; k++) + { + switch (colItems[k].Action) + { + default: + case Ac.Clear: + for (int i = 0; i < wmsCount; i++) comboBoxes[k, i].Text = string.Empty; + break; + + case Ac.HistoryLast: + for (int i = 0; i < wmsCount; i++) + { + comboBoxes[k, i].Text = comboBoxes[k, i].Items.Count > 0 ? comboBoxes[k, i].Items[0].ToString() : string.Empty; + } + break; + + case Ac.Load: + case Ac.LoadReadOnly: + for (int i = 0; i < wmsCount; i++) + { + comboBoxes[k, i].Text = DEUtils.GetContent(colItems[k].Content, WaterMeters[i]); + } + break; + } + } + + for (int i = 0; i < wmsCount; i++) + { + checkBoxes[i].Checked = isEnd ? (WaterMeters[i] != null && !WaterMeters[i].Disabled) : false; + } + + isHandlersEnabled = true; + } + + /// + /// When one combo box is updated using drop-down menu, all combo boxes + /// are updated by this function. + /// + void UpdateWMsFromBoxes() + { + for (int ix = 0; ix < commonItemsCount; ix++ ) + { + DEUtils.PutContent(commonItems[ix].Content, firstValidWM, commonComboBoxes[ix].Text); + if (commonItems[ix].Action != Ac.LoadReadOnly) + { + if (isEnd) + { + switch (ix) + { + case 0: ls.UpdateHistory(commonComboBoxes[ix].Text, ref ls.LastEnComm1); break; + case 1: ls.UpdateHistory(commonComboBoxes[ix].Text, ref ls.LastEnComm2); break; + case 2: ls.UpdateHistory(commonComboBoxes[ix].Text, ref ls.LastEnComm3); break; + } + } + else + { + switch (ix) + { + case 0: ls.UpdateHistory(commonComboBoxes[ix].Text, ref ls.LastBgComm1); break; + case 1: ls.UpdateHistory(commonComboBoxes[ix].Text, ref ls.LastBgComm2); break; + case 2: ls.UpdateHistory(commonComboBoxes[ix].Text, ref ls.LastBgComm3); break; + } + } + } + + /// + /// Propagate common (batch) values to water meters in case of + /// Content.BatchAndWmOrder, Content.BatchAndWmRemark, Content.YearOfCalibration and Content.ArchivePath + /// + foreach (var wm in WaterMeters) + { + if (wm != null && !wm.Disabled) + { + switch (commonItems[ix].Content) + { + case Ct.BatchAndWmOrder: wm.PurchaseOrder = firstValidWM.Batch.PurchaseOrder; break; + case Ct.BatchAndWmRemark: wm.Remark = firstValidWM.Batch.Remark; break; + case Ct.YearOfCalibration: wm.YearOfProduction = firstValidWM.YearOfProduction; break; + case Ct.ArchivePath: wm.ArchivePath = firstValidWM.ArchivePath; break; + } + } + } + } + + for (int k = 0; k < colItems.Count; k++) + { + /// Store values to water meters and prepare an array for a history in the LocalSettings + var currentVals = new string[wmsCount]; + for (int i = 0; i < wmsCount; i++) + { + DEUtils.PutContent(colItems[k].Content, WaterMeters[i], comboBoxes[k, i].Text); + currentVals[i] = comboBoxes[k, i].Text; + } + + /// Update history + if (colItems[k].Action != Ac.LoadReadOnly) + { + if (isEnd) + { + switch (k) + { + case 0: ls.LastEnColA = currentVals; break; + case 1: ls.LastEnColB = currentVals; break; + case 2: ls.LastEnColC = currentVals; break; + case 3: ls.LastEnColD = currentVals; break; + case 4: ls.LastEnColE = currentVals; break; + } + } + else + { + switch (k) + { + case 0: ls.LastBgColA = currentVals; break; + case 1: ls.LastBgColB = currentVals; break; + case 2: ls.LastBgColC = currentVals; break; + case 3: ls.LastBgColD = currentVals; break; + case 4: ls.LastBgColE = currentVals; break; + } + } + } + } + + for (int i = 0; i < wmsCount; i++) + { + if (WaterMeters[i] != null) WaterMeters[i].Disabled = !checkBoxes[i].Checked; + } + } + + private void clearButton_Click(object sender, EventArgs e) + { + InitializeBoxes(); + } + + private void okButton_Click(object sender, EventArgs e) + { + UpdateWMsFromBoxes(); + + completed = true; + Close(); + } + private void comboBox_SelectedIndexChanged(object sndr, EventArgs e) + { + if (!isHandlersEnabled) return; + + string[] kj = (sndr as ComboBox).Name.Split(new char[] { '~' }); + int k = int.Parse(kj[0]); + int j = int.Parse(kj[1]); + + isHandlersEnabled = false; + + if (k >= 0 && comboBoxes[k, j].Text == comboBoxes[k, j].Items[0].ToString()) + { + for (int i = 0; i < wmsCount; i++) + { + comboBoxes[k, i].Text = comboBoxes[k, i].Items[0].ToString(); + if (!string.IsNullOrEmpty(comboBoxes[k, i].Text)) checkBoxes[i].Checked = true; + } + } + + isHandlersEnabled = true; + } + + private void comboBox_KeyPress(object sndr, KeyPressEventArgs e) + { + if (!isHandlersEnabled) return; + + string[] kj = (sndr as ComboBox).Name.Split(new char[] { '~' }); + int k = int.Parse(kj[0]); + int j = int.Parse(kj[1]); + + /// Close the form if any 'form close key' was pressed + for (int ix = 0; ix < formCloseKeys.Length; ix++) + { + if (e.KeyChar == formCloseKeys[ix]) + { + okButton_Click(sndr, e); + return; + } + } + + if (e.KeyChar == '\r') + { + if (k < 0) + { + for (int ix = j; ix < commonItemsCount; ix++) + { + if (commonComboBoxes[ix].Enabled) + { + commonComboBoxes[ix].Focus(); + return; + } + } + + /// No next enabled common item found: + /// Initialize k,j so that after the 1st increment k = 0 and j = 0 + if (isLrOrder) { k = -1; j = 0; } + else { k = 0; j = -1; } + } + + /// Change focus + if (FindNextEnabledCombo(comboBoxes, ref k, ref j, isLrOrder)) + { + okButton.Focus(); + } + else + { + comboBoxes[k, j].Focus(); + } + } + } + + private void comboBox_TextChanged(object sndr, EventArgs e) + { + if (!isHandlersEnabled) return; + + string[] kj = (sndr as ComboBox).Name.Split(new char[] { '~' }); + int k = int.Parse(kj[0]); + int j = int.Parse(kj[1]); + + if (k >= 0) checkBoxes[j].Checked = true; + } + + /// + /// Find the next enabled combo box, update k and i. + /// Return true (=pastTheEndOfArray) when there is no such next combo box. + /// + /// 2-dimensional array of combo boxes + /// 0-nased column + /// 0-based row + /// Order of progress to the next combo: true = left-right, false = top-down + /// true (=pastTheEndOfArray) when there is no such next combo box, otherwise false + bool FindNextEnabledCombo(ComboBox[,] comboBoxes, ref int k, ref int i, bool isLrOrder) + { + bool pastTheEndOfArray = false; + do + { + if (isLrOrder) + { + if (++k == comboBoxes.GetLength(0)) + { + k = 0; + if (++i == comboBoxes.GetLength(1)) + { + i = 0; + pastTheEndOfArray = true; + break; + } + } + } + else + { + if (++i == comboBoxes.GetLength(1)) + { + i = 0; + if (++k == comboBoxes.GetLength(0)) + { + k = 0; + pastTheEndOfArray = true; + break; + } + } + } + } + while (!comboBoxes[k, i].Enabled); + + return pastTheEndOfArray; + } + + #region Forced close handling + + public void StartForceCloseHandler() + { + UiBridge.Bridge.CloseModelessFormHandler += delegate(object sender, EventArgs args) + { + if (InvokeRequired) { Invoke(new EventHandler(OnForceClose), sender, args); } + else OnForceClose(sender, args); + }; + } + + private void OnForceClose(object sender, EventArgs args) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + #endregion + } +} diff --git a/TBF/Rig/DataEntry/Uni/CycleBgEnForm.designer.cs b/TBF/Rig/DataEntry/Uni/CycleBgEnForm.designer.cs new file mode 100644 index 000000000..012ebb410 --- /dev/null +++ b/TBF/Rig/DataEntry/Uni/CycleBgEnForm.designer.cs @@ -0,0 +1,75 @@ +/// +/// Copyright (c) 2023 Sensus Slovensko a.s. +/// +namespace TBF.Rig.DataEntry.Uni +{ + partial class CycleBgEnForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CycleBgEnForm)); + this.okButton = new System.Windows.Forms.Button(); + this.clearButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // okButton + // + resources.ApplyResources(this.okButton, "okButton"); + this.okButton.ForeColor = System.Drawing.Color.Black; + this.okButton.Name = "okButton"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.okButton_Click); + // + // clearButton + // + resources.ApplyResources(this.clearButton, "clearButton"); + this.clearButton.ForeColor = System.Drawing.Color.Black; + this.clearButton.Name = "clearButton"; + this.clearButton.UseVisualStyleBackColor = true; + this.clearButton.Click += new System.EventHandler(this.clearButton_Click); + // + // CycleBgEnForm + // + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.DarkGray; + this.Controls.Add(this.clearButton); + this.Controls.Add(this.okButton); + this.ForeColor = System.Drawing.Color.Black; + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; + this.Name = "CycleBgEnForm"; + this.TopMost = true; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button okButton; + private System.Windows.Forms.Button clearButton; + } +} \ No newline at end of file diff --git a/TBF/Rig/DataEntry/Uni/CycleBgEnForm.resx b/TBF/Rig/DataEntry/Uni/CycleBgEnForm.resx new file mode 100644 index 000000000..4cd233af3 --- /dev/null +++ b/TBF/Rig/DataEntry/Uni/CycleBgEnForm.resx @@ -0,0 +1,210 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + Top, Right + + + + Verdana, 14.25pt + + + 942, 26 + + + 112, 63 + + + + 7 + + + OK + + + okButton + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + Top, Right + + + Verdana, 14.25pt + + + NoControl + + + 795, 26 + + + 112, 63 + + + 8 + + + Clear + + + clearButton + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + True + + + 6, 13 + + + GrowAndShrink + + + 1094, 561 + + + 10000, 10000 + + + Batch data + + + CycleBgEnForm + + + System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TBF/Rig/DataEntry/Uni/EntryForm.cs b/TBF/Rig/DataEntry/Uni/EntryForm.cs new file mode 100644 index 000000000..8ce0d984b --- /dev/null +++ b/TBF/Rig/DataEntry/Uni/EntryForm.cs @@ -0,0 +1,20 @@ +/// +/// Copyright (c) 2023 Sensus Slovensko a.s. +/// +using TBF.Rig.GenericDevices; + +namespace TBF.Rig.DataEntry.Uni +{ + public class EntryForm : EntryFormNoStartEnd, IHasWMStatesForm + { + public EntryForm() + : base() + { + } + + public EntryForm(Generic.IComponentCfg cfg) + : base(cfg) + { + } + } +} diff --git a/TBF/Rig/DataEntry/Uni/EntryFormCfg.cs b/TBF/Rig/DataEntry/Uni/EntryFormCfg.cs new file mode 100644 index 000000000..f817a25d3 --- /dev/null +++ b/TBF/Rig/DataEntry/Uni/EntryFormCfg.cs @@ -0,0 +1,1012 @@ +/// +/// Copyright (c) 2023 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.Xml.Serialization; +using Common; +using Config; +using Config.Entities; +using TBF.Resources; +using TBF.Rig.Generic; + +namespace TBF.Rig.DataEntry.Uni +{ + public enum Sz + { + [Description("Small")] S, + [Description("Medium")] M, + [Description("Large")] L, + Count, + } + + public class EntryFormCfg : ComponentCfgBase, Generic.IComponentCfg, IParamsProvider + { + public static XmlSerializer Serializer = XmlSerializer.FromTypes(new[] { typeof(EntryFormCfg) })[0]; + public override XmlSerializer GetSerializer() { return Serializer; } + + public IComponentCfgCtrl GetControl(IList cmpntEntities) + { + return new Configs.ParamsProvider.ComponentCfgCtrl(this, null); + } + + /// + /// Serialized parameters + /// + public bool BgShowForm; /// 0 + public string BgTitle; /// 1 + public Sz BgSize; /// 2 + // int BgItemsCount; /// 3 + // int BgColumnsCount; /// 4 + public bool BgIsLrOrder; /// 5 + public bool BgIsVertArrangement; /// 6 + public string BgFormCloseKeys; /// 7 + + public bool EnShowForm; /// 8 + public string EnTitle; /// 9 + public Sz EnSize; /// 10 + // int EnItemsCount; /// 11 + // int EnColumnsCount; /// 12 + public bool EnIsLrOrder; /// 13 + public bool EnIsVertArrangement; /// 14 + public string EnFormCloseKeys; /// 15 + + public bool TestStartEndShowForm; /// 16 + public string TestTitle; /// 17 + public Sz TestSize; /// 18 + // int TestColumnsCount; /// 19 + public bool TestStartBoxAlwaysEn; /// 20 + public bool TestIsLrOrder; /// 21 + public bool TestIsVertArrangement; /// 22 + public string TestFormCloseKeys; /// 23 + + public Ct[] BgItemContent; /// 24 + 4 * ix + public string[] BgItemCaption; /// 25 + 4 * ix + public Ac[] BgItemAction; /// 26 + 4 * ix + public int[] BgItemWidth; /// 27 + 4 * ix + + public Ct[] BgColumnContent; /// 24 + 4 * ix + public string[] BgColumnCaption; /// 25 + 4 * ix + public Ac[] BgColumnAction; /// 26 + 4 * ix + public int[] BgColumnWidth; /// 27 + 4 * ix + + public Ct[] EnItemContent; /// 24 + 4 * ix + public string[] EnItemCaption; /// 25 + 4 * ix + public Ac[] EnItemAction; /// 26 + 4 * ix + public int[] EnItemWidth; /// 27 + 4 * ix + + public Ct[] EnColumnContent; /// 24 + 4 * ix + public string[] EnColumnCaption; /// 25 + 4 * ix + public Ac[] EnColumnAction; /// 26 + 4 * ix + public int[] EnColumnWidth; /// 27 + 4 * ix + + public Ct[] TestColumnContent; /// 24 + 4 * ix + public string[] TestColumnCaption; /// 25 + 4 * ix + public Ac[] TestColumnAction; /// 26 + 4 * ix + public int[] TestColumnWidth; /// 27 + 4 * ix + + /// + /// Not serialized + /// + int oriBgItemsCount = -1; + int oriBgColumnsCount = -1; + int oriEnItemsCount = -1; + int oriEnColumnsCount = -1; + int oriTestColumnsCount = -1; + + /// + /// Wrappers + /// + public int GetBgItemsCount() { return (BgItemContent == null) ? 0 : BgItemContent.Length; } + public int GetBgColumnsCount() { return (BgColumnContent == null) ? 0 : BgColumnContent.Length; } + public int GetEnItemsCount() { return (EnItemContent == null) ? 0 : EnItemContent.Length; } + public int GetEnColumnsCount() { return (EnColumnContent == null) ? 0 : EnColumnContent.Length; } + public int GetTestColumnsCount() { return (TestColumnContent == null) ? 0 : TestColumnContent.Length; } + /// + void SetBgItemsCount(int newCount) + { + if (oriBgItemsCount < 0) oriBgItemsCount = GetBgItemsCount(); + if (newCount == GetBgItemsCount()) return; + + int oldCount = (BgItemContent == null) ? 0 : BgItemContent.Length; + var oldContent = BgItemContent; + var oldCaption = BgItemCaption; + var oldAction = BgItemAction; + var oldWidth = BgItemWidth; + + BgItemContent = new Ct[newCount]; + BgItemCaption = new string[newCount]; + BgItemAction = new Ac[newCount]; + BgItemWidth = new int[newCount]; + + for (int i = 0; i < newCount; i++) + { + if (i < oldCount) + { + BgItemContent[i] = oldContent[i]; + BgItemCaption[i] = oldCaption[i]; + BgItemAction[i] = oldAction[i]; + BgItemWidth[i] = oldWidth[i]; + } + else + { + BgItemContent[i] = Ct.None; + BgItemCaption[i] = string.Empty; + BgItemAction[i] = Ac.Clear; + BgItemWidth[i] = 0; + } + } + } + /// + void SetBgColumnsCount(int newCount) + { + if (oriBgColumnsCount < 0) oriBgColumnsCount = GetBgColumnsCount(); + if (newCount == GetBgColumnsCount()) return; + + int oldCount = (BgColumnContent == null) ? 0 : BgColumnContent.Length; + var oldContent = BgColumnContent; + var oldCaption = BgColumnCaption; + var oldAction = BgColumnAction; + var oldWidth = BgColumnWidth; + + BgColumnContent = new Ct[newCount]; + BgColumnCaption = new string[newCount]; + BgColumnAction = new Ac[newCount]; + BgColumnWidth = new int[newCount]; + + for (int i = 0; i < newCount; i++) + { + if (i < oldCount) + { + BgColumnContent[i] = oldContent[i]; + BgColumnCaption[i] = oldCaption[i]; + BgColumnAction[i] = oldAction[i]; + BgColumnWidth[i] = oldWidth[i]; + } + else + { + BgColumnContent[i] = Ct.None; + BgColumnCaption[i] = string.Empty; + BgColumnAction[i] = Ac.Clear; + BgColumnWidth[i] = 0; + } + } + } + /// + void SetEnItemsCount(int newCount) + { + if (oriEnItemsCount < 0) oriEnItemsCount = GetEnItemsCount(); + if (newCount == GetEnItemsCount()) return; + + int oldCount = (EnItemContent == null) ? 0 : EnItemContent.Length; + var oldContent = EnItemContent; + var oldCaption = EnItemCaption; + var oldAction = EnItemAction; + var oldWidth = EnItemWidth; + + EnItemContent = new Ct[newCount]; + EnItemCaption = new string[newCount]; + EnItemAction = new Ac[newCount]; + EnItemWidth = new int[newCount]; + + for (int i = 0; i < newCount; i++) + { + if (i < oldCount) + { + EnItemContent[i] = oldContent[i]; + EnItemCaption[i] = oldCaption[i]; + EnItemAction[i] = oldAction[i]; + EnItemWidth[i] = oldWidth[i]; + } + else + { + EnItemContent[i] = Ct.None; + EnItemCaption[i] = string.Empty; + EnItemAction[i] = Ac.Clear; + EnItemWidth[i] = 0; + } + } + } + /// + void SetEnColumnsCount(int newCount) + { + if (oriEnColumnsCount < 0) oriEnColumnsCount = GetEnColumnsCount(); + if (newCount == GetEnColumnsCount()) return; + + int oldCount = (EnColumnContent == null) ? 0 : EnColumnContent.Length; + var oldContent = EnColumnContent; + var oldCaption = EnColumnCaption; + var oldAction = EnColumnAction; + var oldWidth = EnColumnWidth; + + EnColumnContent = new Ct[newCount]; + EnColumnCaption = new string[newCount]; + EnColumnAction = new Ac[newCount]; + EnColumnWidth = new int[newCount]; + + for (int i = 0; i < newCount; i++) + { + if (i < oldCount) + { + EnColumnContent[i] = oldContent[i]; + EnColumnCaption[i] = oldCaption[i]; + EnColumnAction[i] = oldAction[i]; + EnColumnWidth[i] = oldWidth[i]; + } + else + { + EnColumnContent[i] = Ct.None; + EnColumnCaption[i] = string.Empty; + EnColumnAction[i] = Ac.Clear; + EnColumnWidth[i] = 0; + } + } + } + /// + void SetTestColumnsCount(int newCount) + { + if (oriTestColumnsCount < 0) oriTestColumnsCount = GetTestColumnsCount(); + if (newCount == GetTestColumnsCount()) return; + + int oldCount = (TestColumnContent == null) ? 0 : TestColumnContent.Length; + var oldContent = TestColumnContent; + var oldCaption = TestColumnCaption; + var oldAction = TestColumnAction; + var oldWidth = TestColumnWidth; + + TestColumnContent = new Ct[newCount]; + TestColumnCaption = new string[newCount]; + TestColumnAction = new Ac[newCount]; + TestColumnWidth = new int[newCount]; + + for (int i = 0; i < newCount; i++) + { + if (i < oldCount) + { + TestColumnContent[i] = oldContent[i]; + TestColumnCaption[i] = oldCaption[i]; + TestColumnAction[i] = oldAction[i]; + TestColumnWidth[i] = oldWidth[i]; + } + else + { + TestColumnContent[i] = Ct.None; + TestColumnCaption[i] = string.Empty; + TestColumnAction[i] = Ac.Clear; + TestColumnWidth[i] = 0; + } + } + } + /// + int GetOriBgItemsCount() + { + if (oriBgItemsCount < 0) oriBgItemsCount = GetBgItemsCount(); + return oriBgItemsCount; + } + int GetOriBgColumnsCount() + { + if (oriBgColumnsCount < 0) oriBgColumnsCount = GetBgColumnsCount(); + return oriBgColumnsCount; + } + int GetOriEnItemsCount() + { + if (oriEnItemsCount < 0) oriEnItemsCount = GetEnItemsCount(); + return oriEnItemsCount; + } + int GetOriEnColumnsCount() + { + if (oriEnColumnsCount < 0) oriEnColumnsCount = GetEnColumnsCount(); + return oriEnColumnsCount; + } + int GetOriTestColumnsCount() + { + if (oriTestColumnsCount < 0) oriTestColumnsCount = GetTestColumnsCount(); + return oriTestColumnsCount; + } + + + /// + /// Private parameterless constructor invoked by all other (public) constructors + /// + EntryFormCfg() { } + + public EntryFormCfg(IComponentFactory factory, string name) + : this() + { + this.Factory = factory; + this.Name = name; + ParentName = string.Empty; + InitializeAll(); + } + + public string ComponentName { get { return Name; } } + + public void InitializeAll() + { + BgShowForm = true; + BgTitle = "Enter water meter data"; + BgSize = Sz.M; + BgIsLrOrder = false; + BgIsVertArrangement = false; + BgFormCloseKeys = string.Empty; + + EnShowForm = false; + EnTitle = "Enter water meter data"; + EnSize = Sz.M; + EnIsLrOrder = false; + EnIsVertArrangement = false; + EnFormCloseKeys = string.Empty; + + TestStartEndShowForm = true; + TestTitle = "Enter states of water meters"; + TestSize = Sz.M; + TestStartBoxAlwaysEn = false; + TestIsLrOrder = false; + TestIsVertArrangement = false; + TestFormCloseKeys = string.Empty; + + BgItemContent = new Ct[1] { Ct.BatchAndWmOrder }; + BgItemCaption = new string[1] { "Order nr." }; + BgItemAction = new Ac[1] { Ac.Clear }; + BgItemWidth = new int[1] { 200 }; + + BgColumnContent = new Ct[1] { Ct.SerialNr }; + BgColumnCaption = new string[1] { "S/N" }; + BgColumnAction = new Ac[1] { Ac.Clear }; + BgColumnWidth = new int[1] { 200 }; + + EnItemContent = new Ct[2] { Ct.BatchAndWmOrder, Ct.BatchRemark }; + EnItemCaption = new string[2] { "Order nr.","Remark" }; + EnItemAction = new Ac[2] { Ac.LoadReadOnly, Ac.HistoryLast }; + EnItemWidth = new int[2] { 200, 200 }; + + EnColumnContent = new Ct[2] { Ct.SerialNr, Ct.EndState }; + EnColumnCaption = new string[2] { "S/N", "End state" }; + EnColumnAction = new Ac[2] { Ac.LoadReadOnly, Ac.Clear }; + EnColumnWidth = new int[2] { 200, 200 }; + + TestColumnContent = new Ct[3] { Ct.SerialNr, Ct.StartState, Ct.EndState }; + TestColumnCaption = new string[3] { "S/N", "Start state", "End state" }; + TestColumnAction = new Ac[3] { Ac.LoadReadOnly, Ac.Clear, Ac.Clear }; + TestColumnWidth = new int[3] { 200, 200, 200 }; + } + + string[] paramNames = new string[] + { + "Beginning: Show form", + "Beginning: Form title", + "Beginning: Font ize", + "Beginning: Common items count", + "Beginning: Columns count", + "Beginning: Left-to-right order", + "Beginning: Vertical arrangement", + "Beginning: Keys to close the form", + + "End: Show form", + "End: Form title", + "End: Font size", + "End: Common items count", + "End: Columns count", + "End: Left-to-right order", + "End: Vertical arrangement", + "End: Keys to close the form", + + "Test start/end: Show form", + "Test start/end: Form title", + "Test start/end: Font size", + "Test start/end: Columns count", + "Test start/end: Start text box always enabled", + "Test start/end: Left-to-right order", + "Test start/end: Vertical arrangement", + "Test start/end: Keys to close the form", + }; + public string ParamName(int i) + { + if (i < paramNames.Length) return paramNames[i]; + int ix = i - paramNames.Length; + + if (ix < 4 * GetOriBgItemsCount()) + { + int j = ix / 4 + 1; + switch (ix % 4) + { + case 0: return string.Format("Beginning: Item {0} content", j); + case 1: return string.Format("Beginning: Item {0} caption", j); + case 2: return string.Format("Beginning: Item {0} action", j); + case 3: return string.Format("Beginning: Item {0} width", j); + } + } + ix -= 4 * GetOriBgItemsCount(); + + if (ix < 4 * GetOriBgColumnsCount()) + { + char c = Convert.ToChar(ix / 4 + 65); + switch (ix % 4) + { + case 0: return string.Format("Beginning: Column {0} content", c); + case 1: return string.Format("Beginning: Column {0} caption", c); + case 2: return string.Format("Beginning: Column {0} action", c); + case 3: return string.Format("Beginning: Column {0} width", c); + } + } + ix -= 4 * GetOriBgColumnsCount(); + + if (ix < 4 * GetOriEnItemsCount()) + { + int j = ix / 4 + 1; + switch (ix % 4) + { + case 0: return string.Format("End: Item {0} content", j); + case 1: return string.Format("End: Item {0} caption", j); + case 2: return string.Format("End: Item {0} action", j); + case 3: return string.Format("End: Item {0} width", j); + } + } + ix -= 4 * GetOriEnItemsCount(); + + if (ix < 4 * GetOriEnColumnsCount()) + { + char c = Convert.ToChar(ix / 4 + 65); + switch (ix % 4) + { + case 0: return string.Format("End: Column {0} content", c); + case 1: return string.Format("End: Column {0} caption", c); + case 2: return string.Format("End: Column {0} action", c); + case 3: return string.Format("End: Column {0} width", c); + } + } + ix -= 4 * GetOriEnColumnsCount(); + + if (ix < 4 * GetOriTestColumnsCount()) + { + char c = Convert.ToChar(ix / 4 + 65); + switch (ix % 4) + { + case 0: return string.Format("Test start/end: Column {0} content", c); + case 1: return string.Format("Test start/end: Column {0} caption", c); + case 2: return string.Format("Test start/end: Column {0} action", c); + case 3: return string.Format("Test start/end: Column {0} width", c); + } + } + + return string.Empty; + } + + public int ParamsCount() + { + int itemsCount = GetOriBgItemsCount() + GetOriBgColumnsCount() + + GetOriEnItemsCount() + GetOriEnColumnsCount() + GetOriTestColumnsCount(); + return paramNames.Length + 4 * itemsCount; + } + + public ICollection ParamValues(int i) + { + var list = new List(); + + if (i < paramNames.Length) + { + switch (i) + { + case 0: + case 5: + case 6: + case 8: + case 13: + case 14: + case 16: + case 20: + case 21: + case 22: + return new string[] { Strings.yes, Strings.no }; + case 2: + case 10: + case 18: + for (Sz sz = 0; sz < Sz.Count; sz++) list.Add(sz.ToDescription()); + return list; + default: + return null; + } + } + + i -= paramNames.Length; + + switch (i % 4) + { + case 0: + bool isCommon = (i < 4 * GetOriBgItemsCount()) + || (i >= 4 * (GetOriBgItemsCount() + GetOriBgColumnsCount()) + && i < 4 * (GetOriBgItemsCount() + GetOriBgColumnsCount() + GetOriEnItemsCount())); + if (isCommon) + { + return new string[] + { + Ct.None.ToDescription(), + Ct.YearOfCalibration.ToDescription(), + Ct.ArchivePath.ToDescription(), + Ct.BatchOrder.ToDescription(), + Ct.BatchAndWmOrder.ToDescription(), + Ct.BatchRemark.ToDescription(), + Ct.BatchAndWmRemark.ToDescription(), + }; + } + else + { + return new string[] + { + Ct.None.ToDescription(), + Ct.SerialNr.ToDescription(), + Ct.SerialNrAux.ToDescription(), + Ct.RadioAddress.ToDescription(), + Ct.YearOfCalibration.ToDescription(), + Ct.StartState.ToDescription(), + Ct.EndState.ToDescription(), + Ct.ArchivePath.ToDescription(), + Ct.WmOrder.ToDescription(), + Ct.WmRemark.ToDescription(), + }; + } + case 2: + for (Ac a = 0; a < Ac.Count; a++) list.Add(a.ToDescription()); + return list; + case 1: + case 3: + default: + return null; + } + } + + public string ToString(int i) + { + if (i < 0) + { + return string.Format("Name={0}, Show cycle beginning form={1}, Show cycle end form={2}", + Name, BgShowForm, EnShowForm); + } + + if (i < paramNames.Length) + { + switch (i) + { + case 0: return BgShowForm ? Strings.yes : Strings.no; + case 1: return BgTitle; + case 2: return BgSize.ToDescription(); + case 3: return GetBgItemsCount().ToString(); + case 4: return GetBgColumnsCount().ToString(); + case 5: return BgIsLrOrder ? Strings.yes : Strings.no; + case 6: return BgIsVertArrangement ? Strings.yes : Strings.no; + case 7: return BgFormCloseKeys; + + case 8: return EnShowForm ? Strings.yes : Strings.no; + case 9: return EnTitle; + case 10: return EnSize.ToDescription(); + case 11: return GetEnItemsCount().ToString(); + case 12: return GetEnColumnsCount().ToString(); + case 13: return EnIsLrOrder ? Strings.yes : Strings.no; + case 14: return EnIsVertArrangement ? Strings.yes : Strings.no; + case 15: return EnFormCloseKeys; + + case 16: return TestStartEndShowForm ? Strings.yes : Strings.no; + case 17: return TestTitle; + case 18: return TestSize.ToDescription(); + case 19: return GetTestColumnsCount().ToString(); + case 20: return TestStartBoxAlwaysEn ? Strings.yes : Strings.no; + case 21: return TestIsLrOrder ? Strings.yes : Strings.no; + case 22: return TestIsVertArrangement ? Strings.yes : Strings.no; + case 23: return TestFormCloseKeys; + + default: return string.Empty; + } + } + + int ix = i - paramNames.Length; + + if (ix < 4 * GetOriBgItemsCount()) + { + int j = ix / 4; + switch (ix % 4) + { + case 0: return (j < GetBgItemsCount()) ? BgItemContent[j].ToDescription() : Ct.None.ToDescription(); + case 1: return (j < GetBgItemsCount()) ? BgItemCaption[j] : string.Empty; + case 2: return (j < GetBgItemsCount()) ? BgItemAction[j].ToDescription() : Ac.Clear.ToDescription(); + case 3: return (j < GetBgItemsCount()) ? BgItemWidth[j].ToString() : "0"; + } + } + ix -= 4 * GetOriBgItemsCount(); + + if (ix < 4 * GetOriBgColumnsCount()) + { + int j = ix / 4; + switch (ix % 4) + { + case 0: return (j < GetBgColumnsCount()) ? BgColumnContent[j].ToDescription() : Ct.None.ToDescription(); + case 1: return (j < GetBgColumnsCount()) ? BgColumnCaption[j] : string.Empty; + case 2: return (j < GetBgColumnsCount()) ? BgColumnAction[j].ToDescription() : Ac.Clear.ToDescription(); + case 3: return (j < GetBgColumnsCount()) ? BgColumnWidth[j].ToString() : "0"; + } + } + ix -= 4 * GetOriBgColumnsCount(); + + if (ix < 4 * GetOriEnItemsCount()) + { + int j = ix / 4; + switch (ix % 4) + { + case 0: return (j < GetEnItemsCount()) ? EnItemContent[j].ToDescription() : Ct.None.ToDescription(); + case 1: return (j < GetEnItemsCount()) ? EnItemCaption[j] : string.Empty; + case 2: return (j < GetEnItemsCount()) ? EnItemAction[j].ToDescription() : Ac.Clear.ToDescription(); + case 3: return (j < GetEnItemsCount()) ? EnItemWidth[j].ToString() : "0"; + } + } + ix -= 4 * GetOriEnItemsCount(); + + if (ix < 4 * GetOriEnColumnsCount()) + { + int j = ix / 4; + switch (ix % 4) + { + case 0: return (j < GetEnColumnsCount()) ? EnColumnContent[j].ToDescription() : Ct.None.ToDescription(); + case 1: return (j < GetEnColumnsCount()) ? EnColumnCaption[j] : string.Empty; + case 2: return (j < GetEnColumnsCount()) ? EnColumnAction[j].ToDescription() : Ac.Clear.ToDescription(); + case 3: return (j < GetEnColumnsCount()) ? EnColumnWidth[j].ToString() : "0"; + } + } + ix -= 4 * GetOriEnColumnsCount(); + + if (ix < 4 * GetOriTestColumnsCount()) + { + int j = ix / 4; + switch (ix % 4) + { + case 0: return (j < GetTestColumnsCount()) ? TestColumnContent[j].ToDescription() : Ct.None.ToDescription(); + case 1: return (j < GetTestColumnsCount()) ? TestColumnCaption[j] : string.Empty; + case 2: return (j < GetTestColumnsCount()) ? TestColumnAction[j].ToDescription() : Ac.Clear.ToDescription(); + case 3: return (j < GetTestColumnsCount()) ? TestColumnWidth[j].ToString() : "0"; + } + } + + return string.Empty; + } + + + public CfgUpdateFlags UpdateParam(int i, string str) + { + if (i < paramNames.Length) + { + switch (i) + { + case 0: BgShowForm = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd; + case 1: BgTitle = str; return CfgUpdateFlags.RestartRqrd; + case 2: + for (Sz sz = 0; sz < Sz.Count; sz++) + { + if (str == sz.ToDescription()) + { + BgSize = sz; + return CfgUpdateFlags.RestartRqrd; + } + } + return CfgUpdateFlags.None; + case 3: SetBgItemsCount(int.Parse(str)); return CfgUpdateFlags.RestartRqrd; + case 4: SetBgColumnsCount(int.Parse(str)); return CfgUpdateFlags.RestartRqrd; + case 5: BgIsLrOrder = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd; + case 6: BgIsVertArrangement = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd; + case 7: BgFormCloseKeys = str; return CfgUpdateFlags.RestartRqrd; + + case 8: EnShowForm = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd; + case 9: EnTitle = str; return CfgUpdateFlags.RestartRqrd; + case 10: + for (Sz sz = 0; sz < Sz.Count; sz++) + { + if (str == sz.ToDescription()) + { + EnSize = sz; + return CfgUpdateFlags.RestartRqrd; + } + } + return CfgUpdateFlags.None; + case 11: SetEnItemsCount(int.Parse(str)); return CfgUpdateFlags.RestartRqrd; + case 12: SetEnColumnsCount(int.Parse(str)); return CfgUpdateFlags.RestartRqrd; + case 13: EnIsLrOrder = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd; + case 14: EnIsVertArrangement = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd; + case 15: EnFormCloseKeys = str; return CfgUpdateFlags.RestartRqrd; + + case 16: TestStartEndShowForm = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd; + case 17: TestTitle = str; return CfgUpdateFlags.RestartRqrd; + case 18: + for (Sz sz = 0; sz < Sz.Count; sz++) + { + if (str == sz.ToDescription()) + { + TestSize = sz; + return CfgUpdateFlags.RestartRqrd; + } + } + return CfgUpdateFlags.None; + case 19: SetTestColumnsCount(int.Parse(str)); return CfgUpdateFlags.RestartRqrd; + case 20: TestStartBoxAlwaysEn = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd; + case 21: TestIsLrOrder = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd; + case 22: TestIsVertArrangement = (str == Strings.yes); return CfgUpdateFlags.RestartRqrd; + case 23: TestFormCloseKeys = str; return CfgUpdateFlags.RestartRqrd; + + default: + return CfgUpdateFlags.None; + } + } + + int ix = i - paramNames.Length; + + if (ix < 4 * GetOriBgItemsCount()) + { + int j = ix / 4; + if (j < GetBgItemsCount()) + { + switch (ix % 4) + { + case 0: BgItemContent[j] = Str2Content(str); return CfgUpdateFlags.RestartRqrd; + case 1: BgItemCaption[j] = str; return CfgUpdateFlags.RestartRqrd; + case 2: BgItemAction[j] = Str2Action(str); return CfgUpdateFlags.RestartRqrd; + case 3: BgItemWidth[j] = int.Parse(str); return CfgUpdateFlags.RestartRqrd; + } + } + } + ix -= 4 * GetOriBgItemsCount(); + + if (ix < 4 * GetOriBgColumnsCount()) + { + int j = ix / 4; + if (j < GetBgColumnsCount()) + { + switch (ix % 4) + { + case 0: BgColumnContent[j] = Str2Content(str); return CfgUpdateFlags.RestartRqrd; + case 1: BgColumnCaption[j] = str; return CfgUpdateFlags.RestartRqrd; + case 2: BgColumnAction[j] = Str2Action(str); return CfgUpdateFlags.RestartRqrd; + case 3: BgColumnWidth[j] = int.Parse(str); return CfgUpdateFlags.RestartRqrd; + } + } + } + ix -= 4 * GetOriBgColumnsCount(); + + if (ix < 4 * GetOriEnItemsCount()) + { + int j = ix / 4; + if (j < GetEnItemsCount()) + { + switch (ix % 4) + { + case 0: EnItemContent[j] = Str2Content(str); return CfgUpdateFlags.RestartRqrd; + case 1: EnItemCaption[j] = str; return CfgUpdateFlags.RestartRqrd; + case 2: EnItemAction[j] = Str2Action(str); return CfgUpdateFlags.RestartRqrd; + case 3: EnItemWidth[j] = int.Parse(str); return CfgUpdateFlags.RestartRqrd; + } + } + } + ix -= 4 * GetOriEnItemsCount(); + + if (ix < 4 * GetOriEnColumnsCount()) + { + int j = ix / 4; + if (j < GetEnColumnsCount()) + { + switch (ix % 4) + { + case 0: EnColumnContent[j] = Str2Content(str); return CfgUpdateFlags.RestartRqrd; + case 1: EnColumnCaption[j] = str; return CfgUpdateFlags.RestartRqrd; + case 2: EnColumnAction[j] = Str2Action(str); return CfgUpdateFlags.RestartRqrd; + case 3: EnColumnWidth[j] = int.Parse(str); return CfgUpdateFlags.RestartRqrd; + } + } + } + ix -= 4 * GetOriEnColumnsCount(); + + if (ix < 4 * GetOriTestColumnsCount()) + { + int j = ix / 4; + if (j < GetTestColumnsCount()) + { + switch (ix % 4) + { + case 0: TestColumnContent[j] = Str2Content(str); return CfgUpdateFlags.RestartRqrd; + case 1: TestColumnCaption[j] = str; return CfgUpdateFlags.RestartRqrd; + case 2: TestColumnAction[j] = Str2Action(str); return CfgUpdateFlags.RestartRqrd; + case 3: TestColumnWidth[j] = int.Parse(str); return CfgUpdateFlags.RestartRqrd; + } + } + } + + return CfgUpdateFlags.RestartRqrd; + } + + Ct Str2Content(string str) + { + for (Ct c = 0; c < Ct.Count; c++) + { + if (str == c.ToDescription()) return c; + } + return Ct.None; + } + + Ac Str2Action(string str) + { + for (Ac a = 0; a < Ac.Count; a++) + { + if (str == a.ToDescription()) return a; + } + return Ac.Clear; + } + + public bool ValidateParam(int i, string str, out string message) + { + int idummy; + + if (i < paramNames.Length) + { + switch (i) + { + case 0: + case 2: + case 5: + case 6: + case 8: + case 10: + case 13: + case 14: + case 16: + case 18: + case 20: + case 21: + case 22: + message = string.Empty; + if (ParamValues(i).Contains(str)) return true; + break; + case 3: + case 4: + case 11: + case 12: + case 19: + message = string.Empty; + if (int.TryParse(str, out idummy)) return true; + break; + case 1: + case 7: + case 9: + case 15: + case 17: + case 23: + message = string.Empty; + return true; + default: + message = "Invalid index"; + return false; + } + } + + if (i < ParamsCount()) + { + switch ((i - paramNames.Length) % 4) + { + case 0: + case 2: + message = string.Empty; + if (ParamValues(i).Contains(str)) return true; + break; + case 1: + message = string.Empty; + return true; + case 3: + message = string.Empty; + if (int.TryParse(str, out idummy)) return true; + break; + default: + message = "Invalid index"; + return false; + } + } + + message = string.Format(Strings.Invalid_0, ParamName(i)) ; + return false; + } + + void CopyContentTo(EntryFormCfg prms) + { + prms.BgShowForm = BgShowForm; + prms.BgTitle = BgTitle; + prms.BgSize = BgSize; + prms.BgIsLrOrder = BgIsLrOrder; + prms.BgIsVertArrangement = BgIsVertArrangement; + prms.BgFormCloseKeys = BgFormCloseKeys; + + prms.EnShowForm = EnShowForm; + prms.EnTitle = EnTitle; + prms.EnSize = EnSize; + prms.EnIsLrOrder = EnIsLrOrder; + prms.EnIsVertArrangement = EnIsVertArrangement; + prms.EnFormCloseKeys = EnFormCloseKeys; + + prms.TestStartEndShowForm = TestStartEndShowForm; + prms.TestTitle = TestTitle; + prms.TestSize = TestSize; + prms.TestStartBoxAlwaysEn = TestStartBoxAlwaysEn; + prms.TestIsLrOrder = TestIsLrOrder; + prms.TestIsVertArrangement = TestIsVertArrangement; + prms.TestFormCloseKeys = TestFormCloseKeys; + + prms.BgItemContent = new Ct[GetBgItemsCount()]; + prms.BgItemCaption = new string[GetBgItemsCount()]; + prms.BgItemAction = new Ac[GetBgItemsCount()]; + prms.BgItemWidth = new int[GetBgItemsCount()]; + /// + for (int ix = 0; ix < GetBgItemsCount(); ix++) + { + prms.BgItemContent[ix] = BgItemContent[ix]; + prms.BgItemCaption[ix] = BgItemCaption[ix]; + prms.BgItemAction[ix] = BgItemAction[ix]; + prms.BgItemWidth[ix] = BgItemWidth[ix]; + } + + prms.BgColumnContent = new Ct[GetBgColumnsCount()]; + prms.BgColumnCaption = new string[GetBgColumnsCount()]; + prms.BgColumnAction = new Ac[GetBgColumnsCount()]; + prms.BgColumnWidth = new int[GetBgColumnsCount()]; + /// + for (int ix = 0; ix < GetBgColumnsCount(); ix++) + { + prms.BgColumnContent[ix] = BgColumnContent[ix]; + prms.BgColumnCaption[ix] = BgColumnCaption[ix]; + prms.BgColumnAction[ix] = BgColumnAction[ix]; + prms.BgColumnWidth[ix] = BgColumnWidth[ix]; + } + + prms.EnItemContent = new Ct[GetEnItemsCount()]; + prms.EnItemCaption = new string[GetEnItemsCount()]; + prms.EnItemAction = new Ac[GetEnItemsCount()]; + prms.EnItemWidth = new int[GetEnItemsCount()]; + /// + for (int ix = 0; ix < GetEnItemsCount(); ix++) + { + prms.EnItemContent[ix] = EnItemContent[ix]; + prms.EnItemCaption[ix] = EnItemCaption[ix]; + prms.EnItemAction[ix] = EnItemAction[ix]; + prms.EnItemWidth[ix] = EnItemWidth[ix]; + } + + prms.EnColumnContent = new Ct[GetEnColumnsCount()]; + prms.EnColumnCaption = new string[GetEnColumnsCount()]; + prms.EnColumnAction = new Ac[GetEnColumnsCount()]; + prms.EnColumnWidth = new int[GetEnColumnsCount()]; + /// + for (int ix = 0; ix < GetEnColumnsCount(); ix++) + { + prms.EnColumnContent[ix] = EnColumnContent[ix]; + prms.EnColumnCaption[ix] = EnColumnCaption[ix]; + prms.EnColumnAction[ix] = EnColumnAction[ix]; + prms.EnColumnWidth[ix] = EnColumnWidth[ix]; + } + + prms.TestColumnContent = new Ct[GetTestColumnsCount()]; + prms.TestColumnCaption = new string[GetTestColumnsCount()]; + prms.TestColumnAction = new Ac[GetTestColumnsCount()]; + prms.TestColumnWidth = new int[GetTestColumnsCount()]; + /// + for (int ix = 0; ix < GetTestColumnsCount(); ix++) + { + prms.TestColumnContent[ix] = TestColumnContent[ix]; + prms.TestColumnCaption[ix] = TestColumnCaption[ix]; + prms.TestColumnAction[ix] = TestColumnAction[ix]; + prms.TestColumnWidth[ix] = TestColumnWidth[ix]; + } + } + + public IParamsProvider Clone() + { + EntryFormCfg pars = new EntryFormCfg(); + CopyContentTo(pars); + return pars; + } + + public bool UpdateEmbeddedDbEntity() + { + return true; /// =OK, do nothing + } + } +} diff --git a/TBF/Rig/DataEntry/Uni/EntryFormNoStartEnd.cs b/TBF/Rig/DataEntry/Uni/EntryFormNoStartEnd.cs new file mode 100644 index 000000000..00f175f7c --- /dev/null +++ b/TBF/Rig/DataEntry/Uni/EntryFormNoStartEnd.cs @@ -0,0 +1,305 @@ +/// +/// Copyright (c) 2023 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using log4net; +using TBF.Rig.GenericDevices; + +namespace TBF.Rig.DataEntry.Uni +{ + public class EntryFormNoStartEnd : ComponentBase, IOperation, IDataEntry, IHasCycleBeginForm, IHasCycleEndForm + { + private static readonly ILog log = LogManager.GetLogger(typeof(EntryFormNoStartEnd)); + public override string ToString() { return string.Format("{0}({1})", ClassName, Cfg.ToString(-1)); } + + public bool UsesCameras() { return false; } + + readonly EntryFormCfg myCfg; + IRegReader[] regReaders; + + /// + /// Properties set by the Begin, End and WMStates form + /// + bool[] disabled; /// This array is shared between forms + + string[] wmCycleEndState; + public string WMCycleEndState(int wmNr) { return (wmNr >= 0 && wmNr < wmCycleEndState.Length) ? wmCycleEndState[wmNr] : string.Empty; } + + double[] wmStartState; + public double WMStartState(int wmNr) { return (wmNr >= 0 && wmNr < wmStartState.Length) ? wmStartState[wmNr] : 0; } + + double[] wmEndState; + public double WMEndState(int wmNr) { return (wmNr >= 0 && wmNr < wmEndState.Length) ? wmEndState[wmNr] : 0; } + + string[] wmStartStateStr; + + + System.Windows.Forms.Form modelessDlg; + public bool Completed { get { return (modelessDlg is IHasCompleted) ? (modelessDlg as IHasCompleted).Completed : true; } } + + Common.Unit volumeUnit; + double refVolume; + double errLimLo; + double errLimHi; + + bool resultSaved; /// Set in Run() when results are saved + + IList waterMeters; /// Reference to ...ProcessData.BatchRslts.WaterMeters[] + + public enum CurrentOp + { + None, + ShowFormAtCycleBeginning, + ShowFormAtCycleEnd, + EnterTestStartStates, + EnterTestEndStates, + } + + CurrentOp currentOp; + + + public EntryFormNoStartEnd() { } + + public EntryFormNoStartEnd(Generic.IComponentCfg cfg) + : base(cfg) + { + myCfg = cfg as EntryFormCfg; + } + + public override void Initialize() + { + disabled = new bool[TBF.Data.WMsCount]; + wmStartState = new double[TBF.Data.WMsCount]; + wmStartStateStr = new string[TBF.Data.WMsCount]; + wmEndState = new double[TBF.Data.WMsCount]; + wmCycleEndState = new string[TBF.Data.WMsCount]; + volumeUnit = (TBF.Rig.Sequences.ProcessData.BenchInfo != null) ? TBF.Rig.Sequences.ProcessData.BenchInfo.VolumeUnit : Common.Unit.l; + currentOp = CurrentOp.None; + log.FatalFormat("{0} initialized: {1}", Name, this); + } + + + /// Reference to the operation + public IOperation ShowCycleBeginFormOp() + { + if (currentOp != CurrentOp.None) throw new Exception("Sequence error"); + currentOp = CurrentOp.ShowFormAtCycleBeginning; + waterMeters = TBF.Rig.Sequences.ProcessData.BatchRslts.Batch.WaterMeters; + return this; + } + + /// Reference to the operation + public IOperation ShowCycleEndFormOp() + { + if (currentOp != CurrentOp.None) throw new Exception("Sequence error"); + currentOp = CurrentOp.ShowFormAtCycleEnd; + waterMeters = TBF.Rig.Sequences.ProcessData.BatchRslts.Batch.WaterMeters; + return this; + } + + /// Reference to the operation + public IOperation ShowTestStartFormOp(IRegReader[] regReaders) + { + if (currentOp != CurrentOp.None) throw new Exception("Sequence error"); + currentOp = CurrentOp.EnterTestStartStates; + this.waterMeters = TBF.Rig.Sequences.ProcessData.BatchRslts.Batch.WaterMeters; + this.regReaders = regReaders; + return this; + } + + /// Reference to the operation + public IOperation ShowTestEndFormOp(IRegReader[] regReaders, double refVolume, double errLimLo, double errLimHi) + { + if (currentOp != CurrentOp.None) throw new Exception("Sequence error"); + currentOp = CurrentOp.EnterTestEndStates; + this.waterMeters = TBF.Rig.Sequences.ProcessData.BatchRslts.Batch.WaterMeters; + this.regReaders = regReaders; + this.refVolume = refVolume; + this.errLimLo = errLimLo; + this.errLimHi = errLimHi; + return this; + } + + public IOperation ShowAdvancedTestStartFormOp(IRegReader[] regReaders, IList waterMeters, bool isCondOp = false) + { + return null; + } + + delegate void EntryFormDlgt(EntryFormNoStartEnd myRef); + /// + void OpenBeginningDlg(EntryFormNoStartEnd myRef) + { + DEItem.ClearItems(); + for (int i = 0; i < myCfg.GetBgItemsCount(); i++) + { + if (myCfg.BgItemContent[i] != Ct.None) + { + DEItem.AddItem(myCfg.BgItemContent[i], myCfg.BgItemCaption[i], myCfg.BgItemAction[i], myCfg.BgItemWidth[i]); + } + } + + DEItem.ClearColumns(); + for (int i = 0; i < myCfg.GetBgColumnsCount(); i++) + { + if (myCfg.BgColumnContent[i] != Ct.None) + { + DEItem.AddColumn(myCfg.BgColumnContent[i], myCfg.BgColumnCaption[i], myCfg.BgColumnAction[i], myCfg.BgColumnWidth[i]); + } + } + + modelessDlg = new CycleBgEnForm(waterMeters, TBF.Data.LineSize, myCfg.BgTitle, myCfg.BgSize, myCfg.BgIsLrOrder, myCfg.BgFormCloseKeys, + DEItem.GetItems(), DEItem.GetColumns(), false); + modelessDlg.Show(); + } + /// + void OpenEndDlg(EntryFormNoStartEnd myRef) + { + DEItem.ClearItems(); + for (int i = 0; i < myCfg.GetEnItemsCount(); i++) + { + if (myCfg.EnItemContent[i] != Ct.None) + { + DEItem.AddItem(myCfg.EnItemContent[i], myCfg.EnItemCaption[i], myCfg.EnItemAction[i], myCfg.EnItemWidth[i]); + } + } + + DEItem.ClearColumns(); + for (int i = 0; i < myCfg.GetEnColumnsCount(); i++) + { + if (myCfg.EnColumnContent[i] != Ct.None) + { + DEItem.AddColumn(myCfg.EnColumnContent[i], myCfg.EnColumnCaption[i], myCfg.EnColumnAction[i], myCfg.EnColumnWidth[i]); + } + } + + modelessDlg = new CycleBgEnForm(waterMeters, TBF.Data.LineSize, myCfg.EnTitle, myCfg.EnSize, myCfg.EnIsLrOrder, myCfg.EnFormCloseKeys, + DEItem.GetItems(), DEItem.GetColumns(), true); + modelessDlg.Show(); + } + /// + void OpenTestStartStatesDlg(EntryFormNoStartEnd myRef) + { + DEItem.ClearColumns(); + for (int i = 0; i < myCfg.GetTestColumnsCount(); i++) + { + if (myCfg.TestColumnContent[i] != Ct.None) + { + DEItem.AddColumn(myCfg.TestColumnContent[i], myCfg.TestColumnCaption[i], myCfg.TestColumnAction[i], myCfg.TestColumnWidth[i]); + } + } + + modelessDlg = new TestStartEndForm(waterMeters, myRef.regReaders, TBF.Data.LineSize, myCfg.TestTitle, myCfg.TestSize, + myCfg.TestStartBoxAlwaysEn, myCfg.TestIsLrOrder, myCfg.TestFormCloseKeys, DEItem.GetColumns(), + volumeUnit); + modelessDlg.Show(); + } + /// + void OpenTestEndStatesDlg(EntryFormNoStartEnd myRef) + { + DEItem.ClearColumns(); + for (int i = 0; i < myCfg.GetTestColumnsCount(); i++) + { + if (myCfg.TestColumnContent[i] != Ct.None) + { + DEItem.AddColumn(myCfg.TestColumnContent[i], myCfg.TestColumnCaption[i], myCfg.TestColumnAction[i], myCfg.TestColumnWidth[i]); + } + } + + modelessDlg = new TestStartEndForm(waterMeters, myRef.regReaders, TBF.Data.LineSize, myCfg.TestTitle, myCfg.TestSize, + myCfg.TestStartBoxAlwaysEn, myCfg.TestIsLrOrder, myCfg.TestFormCloseKeys, DEItem.GetColumns(), + volumeUnit, wmStartStateStr, refVolume, errLimLo, errLimHi); + modelessDlg.Show(); + } + + /// Start this operation + public void Start() + { + resultSaved = false; + switch (currentOp) + { + case CurrentOp.ShowFormAtCycleBeginning: + if (myCfg.BgShowForm) + { + Program.MainWnd.Invoke(new EntryFormDlgt(OpenBeginningDlg), this); + } + break; + case CurrentOp.ShowFormAtCycleEnd: + if (myCfg.EnShowForm) + { + Program.MainWnd.Invoke(new EntryFormDlgt(OpenEndDlg), this); + } + break; + case CurrentOp.EnterTestStartStates: + Program.MainWnd.Invoke(new EntryFormDlgt(OpenTestStartStatesDlg), this); + break; + case CurrentOp.EnterTestEndStates: + Program.MainWnd.Invoke(new EntryFormDlgt(OpenTestEndStatesDlg), 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 + { + if (modelessDlg is TestStartEndForm && currentOp == CurrentOp.EnterTestStartStates) + { + /// Fixed start test - start + TestStartEndForm dlg = (modelessDlg as TestStartEndForm); + if (dlg != null) + { + volumeUnit = dlg.VolumeUnit; + for (int i = 0; i < waterMeters.Count; i++) + { + if (!((i < waterMeters.Count && waterMeters[i].Disabled) || (i < regReaders.Length && regReaders[i] == null))) + { + wmStartState[i] = dlg.WMStartState[i]; + wmStartStateStr[i] = dlg.WMStartStateStr[i]; + } + } + } + } + else if (modelessDlg is TestStartEndForm && currentOp == CurrentOp.EnterTestEndStates) + { + /// Fixed start test - end + TestStartEndForm dlg = (modelessDlg as TestStartEndForm); + if (dlg != null) + { + volumeUnit = dlg.VolumeUnit; + for (int i = 0; i < waterMeters.Count; i++) + { + if (!((i < waterMeters.Count && waterMeters[i].Disabled) || (i < regReaders.Length && regReaders[i] == null))) + { + wmEndState[i] = dlg.WMEndState[i]; + } + } + } + } + + 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; + } + } +} diff --git a/TBF/Rig/DataEntry/Uni/Factory.cs b/TBF/Rig/DataEntry/Uni/Factory.cs new file mode 100644 index 000000000..6cc5a990b --- /dev/null +++ b/TBF/Rig/DataEntry/Uni/Factory.cs @@ -0,0 +1,25 @@ +/// +/// Copyright (c) 2023 Sensus Slovensko a.s. +/// +using System.Collections.Generic; +using TBF.Rig.Generic; + +namespace TBF.Rig.DataEntry.Uni +{ + public class Factory : IComponentFactory + { + public string ClassName { get { return GetType().Namespace.Substring(8); } } + public override string ToString() { return ClassName; } + + public IComponent DummyComponent() { return new EntryFormNoStartEnd(); } + + public IComponent GetComponent(IComponentCfg cfg, IList components) { return new EntryForm(cfg); } + + public IComponentCfg DefaultConfig() { return new EntryFormCfg(this, GetType().Namespace.Substring(8)); } + + public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component) + { + return ComponentCfgBase.CreateFromDbEntity(EntryFormCfg.Serializer, component, this); + } + } +} diff --git a/TBF/Rig/DataEntry/Uni/FactoryNoStartEnd.cs b/TBF/Rig/DataEntry/Uni/FactoryNoStartEnd.cs new file mode 100644 index 000000000..36be6179f --- /dev/null +++ b/TBF/Rig/DataEntry/Uni/FactoryNoStartEnd.cs @@ -0,0 +1,24 @@ +/// +/// Copyright (c) 2023 Sensus Slovensko a.s. +/// +using System.Collections.Generic; +using TBF.Rig.Generic; + +namespace TBF.Rig.DataEntry.Uni +{ + public class FactoryNoStartEnd : IComponentFactory + { + public string ClassName { get { return GetType().Namespace.Substring(8) + "-NoStartEnd"; } } + + public IComponent DummyComponent() { return new EntryFormNoStartEnd(); } + + public IComponent GetComponent(IComponentCfg cfg, IList components) { return new EntryFormNoStartEnd(cfg); } + + public IComponentCfg DefaultConfig() { return new EntryFormCfg(this, GetType().Namespace.Substring(8) + "-NoStartEnd"); } + + public IComponentCfg CmpntCfgFromCmpntEntity(Config.Entities.Component component) + { + return ComponentCfgBase.CreateFromDbEntity(EntryFormCfg.Serializer, component, this); + } + } +} diff --git a/TBF/Rig/DataEntry/Uni/TestStartEndForm.cs b/TBF/Rig/DataEntry/Uni/TestStartEndForm.cs new file mode 100644 index 000000000..d1d2c8bbd --- /dev/null +++ b/TBF/Rig/DataEntry/Uni/TestStartEndForm.cs @@ -0,0 +1,600 @@ +/// +/// Copyright (c) 2023 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using log4net; +using Common; +using Results.Entities; +using TBF.Rig.GenericDevices; +using TBF.Resources; + +namespace TBF.Rig.DataEntry.Uni +{ + public partial class TestStartEndForm : Form, GenericDevices.IHasCompleted + { + private static readonly ILog log = LogManager.GetLogger(typeof(TestStartEndForm)); + + /// Arguments + public readonly IList waterMeters; + readonly IRegReader[] regReaders; + readonly int lineSize; + readonly Sz sz; + readonly bool isStartBoxAlwaysEn; + readonly bool isLrOrder; /// true = controls obtain focus after ENTER key in left-right order, false = top-down order + readonly IList colItems; + readonly string formCloseKeys; + public readonly string[] WMStartStateStr; + readonly double refVolume; + readonly double warningLimLo; /// limit to display exclamation mark, typically 2x errLimLo + readonly double warningLimHi; /// limit to display exclamation mark, typically 2x errLimHi + + /// Derived from arguments in the constructor + readonly bool isEnd; + readonly WaterMeter firstValidWM; + readonly int wmsCount; + readonly int linesCount; + readonly bool fixedErrorLimits; /// false in case of calculated error limits + + /// To be retrieved after the form closes + public double[] WMStartState; + public double[] WMEndState; + public Unit VolumeUnit; + int startStateColumn; + int endStateColumn; + + /// Size and layout related values + readonly int meterHeight; + readonly int meterWidth; + readonly int margin; + readonly int spacing; + readonly int hdrHeight; + readonly int labelWid; + readonly int checkBoxWid; + + /// UI elements + readonly Label[] labels; /// Labels for water meter numbers + readonly TextBox[,] textBoxes; /// Text boxes for values in columns + readonly Label[] exclamations; + + readonly LocalSettings ls; + + bool isHandlersEnabled; /// Initially false, set to true after ComboBoxes are filled with data + + // Set to 'true' when the form closes + public bool Completed { get { return completed; } } + bool completed; + + + /// + /// Parameterless constructor for common functionality + /// + public TestStartEndForm() + { + InitializeComponent(); + ControlBox = false; + completed = false; + StartForceCloseHandler(); + } + + /// + /// Constructor + /// + /// Water meters + /// Array of register readers + /// Number of water meters in one (test bencch) line + /// Form title + /// Font size + /// true = controls obtain focus in left-right order, forls = top-down order + /// String containing keys to close this form + /// Water meter items displayed in columns (in the matrix in the main part of the form) + /// Volume unit preset initially + /// Information entered on test start + /// Reference volume, it is used to verify the end state, show/hide exclamation if necessary + /// Error limit low, it is used to verify the end state, show/hide exclamation if necessary + /// Error limit high, it is used to verify the end state, show/hide exclamation if necessary + public TestStartEndForm(IList waterMeters, IRegReader[] regReaders, int lineSize, string title, Sz sz, + bool isStartBoxAlwaysEn, bool isLrOrder, string formCloseKeys, IList colItems, + Unit initialVolumeUnit, string[] wmStartStateStr = null, + double refVolume = 0, double errLimLo = 0, double errLimHi = 0) + : this() + { + this.waterMeters = waterMeters; + this.regReaders = regReaders; + this.lineSize = lineSize; + this.Text = !string.IsNullOrEmpty(title) ? title : string.Empty; + this.sz = sz; + this.isStartBoxAlwaysEn = isStartBoxAlwaysEn; + this.isLrOrder = isLrOrder; + this.formCloseKeys = !string.IsNullOrEmpty(formCloseKeys) ? formCloseKeys : string.Empty; + this.colItems = colItems; + this.VolumeUnit = initialVolumeUnit; + this.WMStartStateStr = wmStartStateStr; + this.refVolume = refVolume; + this.warningLimLo = 2 * errLimLo; + this.warningLimHi = 2 * errLimHi; + + if (waterMeters == null || regReaders == null || + (wmStartStateStr != null && wmStartStateStr.Length != waterMeters.Count)) + { + throw new Exception("Invalid argument"); + } + + ls = Program.LocalSettings; + + /// Readonly variables derived from arguments + isEnd = (wmStartStateStr != null); + wmsCount = waterMeters.Count; + if (WMStartStateStr == null) WMStartStateStr = new string[wmsCount]; + fixedErrorLimits = (errLimHi > errLimLo); + linesCount = (wmsCount + Math.Max(1, lineSize) - 1) / Math.Max(1, lineSize); + firstValidWM = waterMeters.FirstOrDefault(x => (x != null && !x.Disabled)); + WMStartState = new double[wmsCount]; + WMEndState = new double[wmsCount]; + /// + unitComboBox.Text = VolumeUnit.ToDescription(); + labels = new Label[wmsCount]; + textBoxes = new TextBox[colItems.Count, wmsCount]; + exclamations = new Label[wmsCount]; + + /// Layout related readonly variables derived from argument 'sz' + Font font; + Font exclamationFont; + switch (sz) + { + case Sz.S: + font = new Font("Verdana", 12, FontStyle.Regular); + //exclamationFont = new Font("Verdana", 24F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(238))); + exclamationFont = new Font("Verdana", 18, FontStyle.Bold); + meterHeight = 26; /// Height of a ComboBox control + margin = 20; + spacing = 8; + hdrHeight = 160; + labelWid = 31; + checkBoxWid = 23; + break; + + default: + case Sz.M: + font = new Font("Verdana", 14, FontStyle.Regular); + exclamationFont = new Font("Verdana", 20, FontStyle.Bold); + meterHeight = 31; /// Height of a ComboBox control + margin = 25; + spacing = 10; + hdrHeight = 160; + labelWid = 34; + checkBoxWid = 23; + break; + + case Sz.L: + font = new Font("Verdana", 18, FontStyle.Regular); + exclamationFont = new Font("Verdana", 24, FontStyle.Bold); + meterHeight = 37; /// Height of a ComboBox control + margin = 30; + spacing = 12; + hdrHeight = 160; + labelWid = 40; + checkBoxWid = 23; + break; + } + meterWidth = labelWid + checkBoxWid + spacing; + foreach (var ci in colItems) { meterWidth += ci.Width + spacing; } + + int tabIndex = 1; + + /// + /// Table + /// + int columnsTop = hdrHeight; + for (int j = 0; j < linesCount; j++) + { + /// Captions + int capX = margin + j * (meterWidth + margin / 2) + labelWid + spacing; + int capY = columnsTop - meterHeight; + for (int k = 0; k < colItems.Count; k++) + { + int labelWidth = Convert.ToInt32(Graphics.FromImage(new Bitmap(1, 1)).MeasureString(colItems[k].Caption, font).Width); + var label = new Label + { + Text = colItems[k].Caption, + Location = new Point(capX, capY), + Size = new Size(labelWidth + spacing, meterHeight), + Font = font, + TabIndex = tabIndex++, + Parent = this, + }; + capX += colItems[k].Width + spacing; + } + + /// Water meters + for (int i = 0; i < lineSize; i++) + { + int wmPos0 = i + lineSize * j; + if (wmPos0 > wmsCount) continue; + + int left = margin + j * (meterWidth + margin / 2); + int top = columnsTop + i * (meterHeight + spacing); + + var label = new Label + { + Text = (wmPos0 + 1).ToString(), + Location = new Point(left, top), + Size = new Size(labelWid, meterHeight), + Font = font, + TextAlign = ContentAlignment.MiddleLeft, + TabIndex = tabIndex++, + Parent = this, + }; + left += labelWid + spacing / 2; + labels[wmPos0] = label; + this.Controls.Add(label); + + /// Columns + for (int k = 0; k < colItems.Count; k++) + { + DEItem ci = colItems[k]; + var textBox = new TextBox + { + Name = string.Format("{0}~{1}", k, wmPos0), + Location = new Point(left, top), + Size = new Size(ci.Width, meterHeight), + Enabled = (ci.Action != Ac.LoadReadOnly && !waterMeters[wmPos0].Disabled), + Font = font, + TabIndex = tabIndex++, + Parent = this, + }; + + textBox.TextChanged += new System.EventHandler(textBox_TextChanged); + textBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(textBox_KeyPress); + textBox.MouseClick += new System.Windows.Forms.MouseEventHandler(textBox_MouseClick); + + left += ci.Width + spacing; + textBoxes[k, wmPos0] = textBox; + this.Controls.Add(textBox); + } + + var exclamation = new Label + { + AutoSize = true, + Font = exclamationFont, + ForeColor = System.Drawing.Color.Red, + Location = new Point(left, top), + Parent = this, + TabIndex = tabIndex++, + Text = "!", + Visible = false, + }; + exclamations[wmPos0] = exclamation; + this.Controls.Add(exclamation); + } + } + + /// + /// Adjust window size + /// + Rectangle screenRectangle = this.RectangleToScreen(this.ClientRectangle); + int titleBarHeight = screenRectangle.Top - this.Top; + Size = new Size(Math.Max(meterWidth * linesCount + margin * (linesCount + 1), 1300), + titleBarHeight + columnsTop + lineSize * (meterHeight + spacing) + margin); + + Localize(); + InitializeBoxes(); + + /// Set focus to the first enabled ComboBox + } + + void Localize() + { + okButton.Text = Strings.OkBtnText; + } + + /// + /// Initialize combo boxes state defined by related 'Action'. + /// Clear check boxes. + /// + void InitializeBoxes() + { + isHandlersEnabled = false; + + /// Table + startStateColumn = -1; + endStateColumn = -1; + for (int k = 0; k < colItems.Count; k++) + { + if (colItems[k].Content == Ct.StartState) + { + startStateColumn = k; + for (int i = 0; i < wmsCount; i++) + { + textBoxes[k, i].Text = (!isEnd || waterMeters[i] == null + || waterMeters[i].Disabled + || i >= regReaders.Length + || regReaders[i] == null + || string.IsNullOrEmpty(WMStartStateStr[i])) ? string.Empty : WMStartStateStr[i]; + + textBoxes[k, i].Enabled = (isStartBoxAlwaysEn || !isEnd) && waterMeters[i] != null && !waterMeters[i].Disabled + && i < regReaders.Length && regReaders[i] != null; + } + } + else if (colItems[k].Content == Ct.EndState) + { + endStateColumn = k; + for (int i = 0; i < wmsCount; i++) + { + textBoxes[k, i].Text = string.Empty; + textBoxes[k, i].Enabled = isEnd && waterMeters[i] != null && !waterMeters[i].Disabled + && i < regReaders.Length && regReaders[i] != null; + } + } + else + { + switch (colItems[k].Action) + { + default: + case Ac.Clear: + case Ac.HistoryLast: + for (int i = 0; i < wmsCount; i++) textBoxes[k, i].Text = string.Empty; + break; + + case Ac.Load: + case Ac.LoadReadOnly: + for (int i = 0; i < wmsCount; i++) + { + textBoxes[k, i].Text = DEUtils.GetContent(colItems[k].Content, waterMeters[i]); + } + break; + } + } + } + + if (isEnd && isStartBoxAlwaysEn) + { + int k = 0; + int j = 0; + if (!FindNextEnabledTextBox(textBoxes, ref k, ref j, isLrOrder, true)) + { + ActiveControl = textBoxes[k, j]; + } + + } + + isHandlersEnabled = true; + } + + /// + /// When one combo box is updated using drop-down menu, all combo boxes + /// are updated by this function. + /// + void UpdateWMsFromBoxes() + { + for (int k = 0; k < colItems.Count; k++) + { + for (int i = 0; i < wmsCount; i++) + { + if (colItems[k].Content == Ct.StartState) + { + /// Water meter start state + double startVol; + if (textBoxes[k, i].Enabled && Utils.TryParseUDouble(textBoxes[k, i].Text, out startVol)) + { + WMStartStateStr[i] = textBoxes[k, i].Text; + WMStartState[i] = Units.ConvertFrom(VolumeUnit, startVol); + } + } + else if (colItems[k].Content == Ct.EndState) + { + /// Water meter end state + double endVol; + if (textBoxes[k, i].Enabled && Utils.TryParseUDouble(textBoxes[k, i].Text, out endVol)) + { + WMEndState[i] = Units.ConvertFrom(VolumeUnit, endVol); + } + } + else + { + /// Other value - store values to a water meter structure + DEUtils.PutContent(colItems[k].Content, waterMeters[i], textBoxes[k, i].Text); + } + } + } + } + + private void okButton_Click(object sender, EventArgs eArgs) + { + UpdateWMsFromBoxes(); + + completed = true; + Close(); + } + + private void unitComboBox_TextChanged(object sender, EventArgs e) + { + unitComboBox_SelectedIndexChanged(sender, e); + } + + private void unitComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + var newUnit = Units.FromDescription(unitComboBox.Text); + + if (Units.IsVolume(newUnit)) + { + VolumeUnit = newUnit; + + if (!isHandlersEnabled) return; + + /// Update exclamation marks + if (isEnd && startStateColumn >= 0 && endStateColumn >= 0) + { + for (int i = 0; i < wmsCount; i++) + { + double startVol, endVol; + + if (Utils.TryParseUDouble(textBoxes[startStateColumn, i].Text, out startVol) && + Utils.TryParseUDouble(textBoxes[endStateColumn, i].Text, out endVol)) + { + double startState = Units.ConvertFrom(VolumeUnit, startVol); + double endState = Units.ConvertFrom(VolumeUnit, endVol); + double err = (refVolume != 0) ? 100.0 * (endState - startState - refVolume) / refVolume : 1000.0; + exclamations[i].Visible = fixedErrorLimits ? ((err < warningLimLo) || (warningLimHi < err)) : ((err < -6) || (+6 < err)); + } + else + { + exclamations[i].Visible = !string.IsNullOrEmpty(textBoxes[endStateColumn, i].Text); + } + } + + largeTextBox.Text = string.Empty; + largeExclamationLabel.Visible = false; + } + } + } + + private void textBox_KeyPress(object sndr, KeyPressEventArgs e) + { + if (!isHandlersEnabled) return; + + string[] kj = (sndr as TextBox).Name.Split(new char[] { '~' }); + int k = int.Parse(kj[0]); + int j = int.Parse(kj[1]); + + /// Close the form if any 'form close key' was pressed + if (!string.IsNullOrEmpty(formCloseKeys)) + { + /// Close the form if any 'close form key' was pressed + for (int ix = 0; ix < formCloseKeys.Length; ix++) + { + if (e.KeyChar == formCloseKeys[ix]) + { + okButton_Click(sndr, e); + return; + } + } + } + + if (e.KeyChar == '\r') + { + /// Change focus + if (FindNextEnabledTextBox(textBoxes, ref k, ref j, isLrOrder)) + { + okButton.Focus(); + } + else + { + textBoxes[k, j].Focus(); + largeTextBox.Text = string.Format("{0}: {1}", j + 1, textBoxes[k, j].Text); + largeExclamationLabel.Visible = false; + } + } + } + + /// Handle mouse clicks so that the large text box and the large exclamation mark are updated + private void textBox_MouseClick(object sndr, MouseEventArgs e) + { + textBox_TextChanged(sndr, e); + } + + private void textBox_TextChanged(object sndr, EventArgs e) + { + if (!isHandlersEnabled) return; + + string[] kj = (sndr as TextBox).Name.Split(new char[] { '~' }); + int k = int.Parse(kj[0]); + int j = int.Parse(kj[1]); + + largeTextBox.Text = string.Format("{0}: {1}", j + 1, textBoxes[k, j].Text); + + if (isEnd && (k == startStateColumn || k == endStateColumn)) + { + double startVol, endVol; + + if (startStateColumn >= 0 && Utils.TryParseUDouble(textBoxes[startStateColumn, j].Text, out startVol) && + endStateColumn >= 0 && Utils.TryParseUDouble(textBoxes[endStateColumn, j].Text, out endVol)) + { + double startState = Units.ConvertFrom(VolumeUnit, startVol); + double endState = Units.ConvertFrom(VolumeUnit, endVol); + double err = (refVolume != 0) ? 100.0 * (endState - startState - refVolume) / refVolume : 1000.0; + largeExclamationLabel.Visible = + exclamations[j].Visible = fixedErrorLimits ? ((err < warningLimLo) || (warningLimHi < err)) : ((err < -6) || (+6 < err)); + } + else + { + largeExclamationLabel.Visible = + exclamations[j].Visible = !string.IsNullOrEmpty(textBoxes[endStateColumn, j].Text); + } + } + else + { + largeExclamationLabel.Visible = false; + } + } + + + /// + /// Find the next enabled combo box, update k and i. + /// Return true (=pastTheEndOfArray) when there is no such next combo box. + /// + /// 2-dimensional array of combo boxes + /// 0-nased column + /// 0-based row + /// Order of progress to the next combo: true = left-right, false = top-down + /// true (=pastTheEndOfArray) when there is no such next combo box, otherwise false + bool FindNextEnabledTextBox(TextBox[,] textBoxes, ref int k, ref int i, bool isLrOrder, bool skipStartColumn = false) + { + bool pastTheEndOfArray = false; + do + { + if (isLrOrder) + { + if (++k == textBoxes.GetLength(0)) + { + k = 0; + if (++i == textBoxes.GetLength(1)) + { + i = 0; + pastTheEndOfArray = true; + break; + } + } + } + else + { + if (++i == textBoxes.GetLength(1)) + { + i = 0; + if (++k == textBoxes.GetLength(0)) + { + k = 0; + pastTheEndOfArray = true; + break; + } + } + } + } + while (!textBoxes[k, i].Enabled || (skipStartColumn && k == startStateColumn)); + + return pastTheEndOfArray; + } + + #region Forced close handling + + public void StartForceCloseHandler() + { + UiBridge.Bridge.CloseModelessFormHandler += delegate(object sender, EventArgs args) + { + if (InvokeRequired) { Invoke(new EventHandler(OnForceClose), sender, args); } + else OnForceClose(sender, args); + }; + } + + void OnForceClose(object sender, EventArgs args) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + #endregion + } +} diff --git a/TBF/Rig/DataEntry/Uni/TestStartEndForm.designer.cs b/TBF/Rig/DataEntry/Uni/TestStartEndForm.designer.cs new file mode 100644 index 000000000..4e0f316d6 --- /dev/null +++ b/TBF/Rig/DataEntry/Uni/TestStartEndForm.designer.cs @@ -0,0 +1,114 @@ +/// +/// Copyright (c) 2023 Sensus Slovensko a.s. +/// +namespace TBF.Rig.DataEntry.Uni +{ + partial class TestStartEndForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.okButton = new System.Windows.Forms.Button(); + this.largeTextBox = new System.Windows.Forms.TextBox(); + this.largeExclamationLabel = new System.Windows.Forms.Label(); + this.unitComboBox = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // okButton + // + this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.okButton.Font = new System.Drawing.Font("Verdana", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.okButton.ForeColor = System.Drawing.Color.Black; + this.okButton.Location = new System.Drawing.Point(1120, 29); + this.okButton.Name = "okButton"; + this.okButton.Size = new System.Drawing.Size(123, 63); + this.okButton.TabIndex = 100; + this.okButton.Text = "OK"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.okButton_Click); + // + // largeTextBox + // + this.largeTextBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.largeTextBox.Location = new System.Drawing.Point(35, 29); + this.largeTextBox.Name = "largeTextBox"; + this.largeTextBox.Size = new System.Drawing.Size(849, 80); + this.largeTextBox.TabIndex = 101; + // + // largeExclamationLabel + // + this.largeExclamationLabel.AutoSize = true; + this.largeExclamationLabel.Font = new System.Drawing.Font("Verdana", 48F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.largeExclamationLabel.ForeColor = System.Drawing.Color.Red; + this.largeExclamationLabel.Location = new System.Drawing.Point(890, 28); + this.largeExclamationLabel.Name = "largeExclamationLabel"; + this.largeExclamationLabel.Size = new System.Drawing.Size(59, 78); + this.largeExclamationLabel.TabIndex = 102; + this.largeExclamationLabel.Text = "!"; + this.largeExclamationLabel.Visible = false; + // + // unitComboBox + // + this.unitComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.unitComboBox.Font = new System.Drawing.Font("Verdana", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.unitComboBox.FormattingEnabled = true; + this.unitComboBox.Location = new System.Drawing.Point(962, 46); + this.unitComboBox.Name = "unitComboBox"; + this.unitComboBox.Size = new System.Drawing.Size(123, 31); + this.unitComboBox.TabIndex = 103; + this.unitComboBox.SelectedIndexChanged += new System.EventHandler(this.unitComboBox_SelectedIndexChanged); + this.unitComboBox.TextChanged += new System.EventHandler(this.unitComboBox_TextChanged); + // + // TestStartEndForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.DarkGray; + this.ClientSize = new System.Drawing.Size(1284, 676); + this.Controls.Add(this.unitComboBox); + this.Controls.Add(this.largeExclamationLabel); + this.Controls.Add(this.largeTextBox); + this.Controls.Add(this.okButton); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; + this.Name = "TestStartEndForm"; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "End States"; + this.TopMost = true; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button okButton; + private System.Windows.Forms.TextBox largeTextBox; + private System.Windows.Forms.Label largeExclamationLabel; + private System.Windows.Forms.ComboBox unitComboBox; + + } +} \ No newline at end of file diff --git a/TBF/Rig/DataEntry/Uni/TestStartEndForm.resx b/TBF/Rig/DataEntry/Uni/TestStartEndForm.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TBF/Rig/DataEntry/Uni/TestStartEndForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TBF/Rig/Sequences/MainSeqUtils.cs b/TBF/Rig/Sequences/MainSeqUtils.cs index 70bc42515..f4b81fcd9 100644 --- a/TBF/Rig/Sequences/MainSeqUtils.cs +++ b/TBF/Rig/Sequences/MainSeqUtils.cs @@ -273,6 +273,8 @@ namespace TBF.Rig.Sequences if (cmpnt is ISessionDataMngmnt) (cmpnt as ISessionDataMngmnt).StartSession(); } + DataEntry.DEItem.ClearSummaryColumns(); + IsQ2PreCorrectionCalculated = false; CalculatedQ2PreCorrectionLR = 0; CalculatedQ2PreCorrectionRL = 0; diff --git a/TBF/Rig/Sequences/SequenceBase.cs b/TBF/Rig/Sequences/SequenceBase.cs index a41cb33b1..5fbb0367c 100644 --- a/TBF/Rig/Sequences/SequenceBase.cs +++ b/TBF/Rig/Sequences/SequenceBase.cs @@ -8,6 +8,7 @@ using log4net; using Common; using Config; using Config.Entities; +using TBF.Rig.DataEntry; using TBF.Rig.GenericDevices; using TBF.Rig.Operations; using TBF.Boxes; @@ -1352,31 +1353,35 @@ namespace TBF.Rig.Sequences //sb.Append(";"); sb.Append((tstRslt.TotalPulsesMstr != 0) ? tstRslt.TotalPulsesMstr.ToString() : " "); /// CD - '' - pre druhy (Prolonged : celkovy pocet) sb.Append(";"); sb.Append(1000 * tstRslt.TestTimeCorrection); /// CD [ms] Diverter test time correction - for (int i = 0; i < ProcessData.BatchRslts.WMPositionsCount; i++) + var smryItems = DEItem.GetSummaryColumns(); + + for (int i = 0; i < BatchRslts.WMPositionsCount; i++) { - if (ProcessData.BatchRslts.Batch.WaterMeters != null && - ProcessData.BatchRslts.Batch.WaterMeters.Count > i && - ProcessData.BatchRslts.Batch.WaterMeters[i] != null && - !ProcessData.BatchRslts.Batch.WaterMeters[i].Disabled) + if (BatchRslts.Batch.WaterMeters != null && + BatchRslts.Batch.WaterMeters.Count > i && + BatchRslts.Batch.WaterMeters[i] != null && + !BatchRslts.Batch.WaterMeters[i].Disabled) { - if (!ProcessData.BatchRslts.Batch.WaterMeters[i].Compound() && !ProcessData.BatchRslts.Batch.WaterMeters[i].HeatMeter()) + var wm = BatchRslts.Batch.WaterMeters[i]; + + if (!wm.Compound() && !wm.HeatMeter()) { /// If this is a single meter - Results.Entities.MeterTestRslt mtrRslt = ProcessData.BatchRslts.GetMeterTestRslt(tstRslt.Name(), i, CompoundMeterId.Single); + Results.Entities.MeterTestRslt mtrRslt = BatchRslts.GetMeterTestRslt(tstRslt.Name(), i, CompoundMeterId.Single); if (mtrRslt != null) { bool isCamera = (mtrRslt.RegReaderType == (int)RegisterReaderType.Camera); - sb.Append(";"); sb.Append(ProcessData.BatchRslts.Batch.WaterMeters[i].SerialNr);/// CE WM Ser.No. + sb.Append(";"); sb.Append(wm.SerialNr);/// CE WM Ser.No. sb.Append(";"); sb.Append(mtrRslt.VolumeStart); /// CF WM Vstart - pociatocny stav pri pevnom starte alebo zachyteny pri data streame sb.Append(";"); sb.Append(mtrRslt.VolumeEnd); /// CG WM Vend - konecny stav pri pevnom starte alebo zachyteny pri data streame sb.Append(";"); sb.Append(mtrRslt.VolumeMeter); /// CH WM Vmer - objem namerany vodomerom sb.Append(";"); sb.Append(mtrRslt.VolumeRef); /// CI WM Vref - objem namerany stanicou sb.Append(";"); sb.Append(mtrRslt.Error); /// CJ WM Emt - chyba vodomerom nameraneho objemu #if IPERL - sb.Append(";"); sb.Append(ProcessData.BatchRslts.Batch.WaterMeters[i].CalibFactor); /// CK iPerl calibration factor used during the test / ... + sb.Append(";"); sb.Append(wm.CalibFactor); /// CK iPerl calibration factor used during the test / ... #else sb.Append(";"); sb.Append(" "); /// CK nechat prazdne #endif @@ -1391,7 +1396,7 @@ namespace TBF.Rig.Sequences #endif sb.Append(";"); sb.Append(isCamera ? mtrRslt.VolumeStart * mtrRslt.PulsesPerLiter /// CQ WM Phi_start (pri hodnotach z kamery) - : ProcessData.BatchRslts.Batch.WaterMeters[i].WMPosition); /// CQ WMPosition (normalne) + : wm.WMPosition); /// CQ WMPosition (normalne) sb.Append(";"); sb.Append(isCamera ? mtrRslt.VolumeEnd * mtrRslt.PulsesPerLiter /// CR WM Phi_end (pri hodnotach z kamery) : 0); /// CR not used/spare (normalne) @@ -1399,15 +1404,15 @@ namespace TBF.Rig.Sequences sb.Append(";"); sb.Append(mtrRslt.TimestampStart); /// CS WM Time_start - ' ' - sb.Append(";"); sb.Append(mtrRslt.TimestampEnd); /// CT WM Time_end - ' ' - - sb.Append(";"); sb.Append(isCamera ? mtrRslt.PulsesPerLiter : 0); /// CU WM Degree per liter - - sb.Append(";"); sb.Append(0); /// CV Analog out 1 (max mA) - sb.Append(";"); sb.Append(0); /// CW Analog out 2 (V) - sb.Append(";"); sb.Append(0); /// CX Analog out 3 (min mA) - sb.Append(";"); sb.Append(0); /// CY Analog out 4 (max Q) + //sb.Append(";"); sb.Append(isCamera ? mtrRslt.PulsesPerLiter : 0); /// CU camera: WM Degree per liter + sb.Append(";"); sb.Append(smryItems.Count < 1 ? "0" : DEUtils.GetContent(smryItems[0].Content, wm)); /// CU + sb.Append(";"); sb.Append(smryItems.Count < 2 ? "0" : DEUtils.GetContent(smryItems[1].Content, wm)); /// CV + sb.Append(";"); sb.Append(smryItems.Count < 3 ? "0" : DEUtils.GetContent(smryItems[2].Content, wm)); /// CW + sb.Append(";"); sb.Append(smryItems.Count < 4 ? "0" : DEUtils.GetContent(smryItems[3].Content, wm)); /// CX + sb.Append(";"); sb.Append(smryItems.Count < 5 ? "0" : DEUtils.GetContent(smryItems[4].Content, wm)); /// CY } } - else if (ProcessData.BatchRslts.Batch.WaterMeters[i].Compound()) + else if (wm.Compound()) { /// Else if this is a compound meter @@ -1421,13 +1426,13 @@ namespace TBF.Rig.Sequences switch ((CompoundMeterId)b) { case CompoundMeterId.CompoundMain: - sb.Append(ProcessData.BatchRslts.Batch.WaterMeters[i].SerialNr); /// CE + sb.Append(wm.SerialNr); /// CE break; case CompoundMeterId.CompoundAux: - sb.Append(ProcessData.BatchRslts.Batch.WaterMeters[i].SerialNrAux); /// CE + sb.Append(wm.SerialNrAux); /// CE break; case CompoundMeterId.Compound: - sb.Append(ProcessData.BatchRslts.Batch.WaterMeters[i].SerialNr); /// CE + sb.Append(wm.SerialNr); /// CE break; } sb.Append(";"); sb.Append(mtrRslt.VolumeStart); /// CF WM Vinit - pri pevnom starte pociatocny stav natukany alebo cez inteligentny system @@ -1456,7 +1461,7 @@ namespace TBF.Rig.Sequences } } } - else /// if (ProcessData.BatchRslts.WaterMeters[i].HeatMeter()) + else /// if (wm.HeatMeter()) { /// Else this is a heat meter @@ -1465,14 +1470,14 @@ namespace TBF.Rig.Sequences if (volumeMtr != null) { - sb.Append(";"); sb.Append(ProcessData.BatchRslts.Batch.WaterMeters[i].SerialNr); /// WM Ser.No. + sb.Append(";"); sb.Append(wm.SerialNr); /// WM Ser.No. sb.Append(";"); sb.Append(volumeMtr.VolumeStart); /// WM Vstart - pociatocny stav pri pevnom starte alebo zachyteny pri data streame sb.Append(";"); sb.Append(volumeMtr.VolumeEnd); /// WM Vend - konecny stav pri pevnom starte alebo zachyteny pri data streame sb.Append(";"); sb.Append(volumeMtr.VolumeMeter); /// WM Vmer - objem namerany vodomerom sb.Append(";"); sb.Append(volumeMtr.VolumeRef); /// WM Vref - objem namerany stanicou sb.Append(";"); sb.Append(volumeMtr.Error); /// WM Emt - chyba vodomerom nameraneho objemu #if IPERL - sb.Append(";"); sb.Append(ProcessData.BatchRslts.Batch.WaterMeters[i].CalibFactor); /// iPerl calibration factor used during the test / ... + sb.Append(";"); sb.Append(wm.CalibFactor); /// iPerl calibration factor used during the test / ... #else sb.Append(";"); sb.Append(" "); /// nechat prazdne #endif @@ -1500,7 +1505,7 @@ namespace TBF.Rig.Sequences sb.Append(";"); sb.Append(energyMtr.VolumeRef); /// WM Vref - objem namerany stanicou sb.Append(";"); sb.Append(energyMtr.Error); /// WM Emt - chyba vodomerom nameraneho objemu #if IPERL - sb.Append(";"); sb.Append(ProcessData.BatchRslts.Batch.WaterMeters[i].CalibFactor); /// iPerl calibration factor used during the test / ... + sb.Append(";"); sb.Append(wm.CalibFactor); /// iPerl calibration factor used during the test / ... #else sb.Append(";"); sb.Append(" "); /// nechat prazdne #endif diff --git a/TBF/Rig/StateMachine.cs b/TBF/Rig/StateMachine.cs index 2bfeb2285..eb02469be 100644 --- a/TBF/Rig/StateMachine.cs +++ b/TBF/Rig/StateMachine.cs @@ -52,6 +52,7 @@ namespace TBF.Rig /// Public components public static Elde.ControlBoardDev ControlBoard; + public static IWaterMeter WaterMeterCmpnt; public static GenericDevices.IAmbient Ambient; public static IOperation BenchWaitingOp; public static IOperation BenchErrorOp; @@ -358,7 +359,9 @@ namespace TBF.Rig } } - if (cmpnt is IScaleOrTank) + if (WaterMeterCmpnt == null && cmpnt is IWaterMeter) WaterMeterCmpnt = cmpnt as IWaterMeter; + + if (cmpnt is IScaleOrTank) { IScaleOrTank tank = cmpnt as IScaleOrTank; diff --git a/TBF/Rig/TbfComponents.cs b/TBF/Rig/TbfComponents.cs index f6ed1a036..59782ead1 100644 --- a/TBF/Rig/TbfComponents.cs +++ b/TBF/Rig/TbfComponents.cs @@ -44,6 +44,7 @@ namespace TBF.Rig Factories.Add(new DataEntry.Standard48.Factory()); Factories.Add(new DataEntry.Standard48.FactoryNoStartEnd()); Factories.Add(new DataEntry.StandardCamera.Factory()); + Factories.Add(new DataEntry.Uni.Factory()); Factories.Add(new DataEntry.WMStates.EntryFormFactory()); Factories.Add(new RegisterReaders.KPackE.DataEntryForRadio.Factory()); /// DataEntry for KPackE radio Factories.Add(new Dummy.Balance.Factory()); diff --git a/TBF/Rig/TestMethods/DiverterTest/DiverterTestSeq.cs b/TBF/Rig/TestMethods/DiverterTest/DiverterTestSeq.cs index 93b1e9c7a..fa699f758 100644 --- a/TBF/Rig/TestMethods/DiverterTest/DiverterTestSeq.cs +++ b/TBF/Rig/TestMethods/DiverterTest/DiverterTestSeq.cs @@ -526,11 +526,11 @@ namespace TBF.Rig.TestMethods.DiverterTest /// Delay 'TimeFlow2Mass', min. 5 seconds State.Create(string.Format("{0}({1}) : Delay {2}", test.Method, test.Name, divRepetNr)) - .AddOperation(checkUiOp) - .AddOperations(readTempPressOps) - .AddOperation(processDataLoggingOp) - .AddOperation(new Operations.TimerOp(Math.Max(5, test.TimeFlow2Mass))) - .EnterState(); + .AddOperation(checkUiOp) + .AddOperations(readTempPressOps) + .AddOperation(processDataLoggingOp) + .AddOperation(new Operations.TimerOp(Math.Max(5, test.TimeFlow2Mass))) + .EnterState(); do { e = StateMachine.WaitRunDevsRunOps(); if (e.Contains(Event.Error)) { retVal = Event.Error; goto stopTest; } diff --git a/TBF/Rig/TestMethods/iPerlCommunication/OpticalHeadTest.cs b/TBF/Rig/TestMethods/iPerlCommunication/OpticalHeadTest.cs index 35fef0ecd..15574a102 100644 --- a/TBF/Rig/TestMethods/iPerlCommunication/OpticalHeadTest.cs +++ b/TBF/Rig/TestMethods/iPerlCommunication/OpticalHeadTest.cs @@ -54,7 +54,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication string payload = "03"; RfidCommunicationService rfidCommunicationService = new RfidCommunicationService { ComPort = $"COM{iHead.RfidComPortNr}", WaitTimeAfterFailure = 2200, PassThroughWaitTime = 1500, MaxRetries = 3, TimeOut = 5000 }; rfidCommunicationService.RfidWrite(Params.u8_WakeUpInterval, payload); - return rfidCommunicationService.RfidRead(Params.u8_WakeUpInterval) == payload? "OK" : "Error"; + return rfidCommunicationService.RfidRead(Params.u8_WakeUpInterval).ToString() == payload? "OK" : "Error"; } catch (Exception ex) { @@ -70,7 +70,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication RfidCommunicationService rfidCommunicationService = new RfidCommunicationService { ComPort = $"COM{iHead.RfidComPortNr}", WaitTimeAfterFailure = 2200, PassThroughWaitTime = 1500, MaxRetries = 3, TimeOut = 5000 }; rfidCommunicationService.RfidWrite(SystemInfo.u8_system_state, payload); Thread.Sleep(1000); // must be for pass thru params - return rfidCommunicationService.RfidRead(SystemInfo.u8_system_state) == payload ? "OK" : "Error"; + return rfidCommunicationService.RfidRead(SystemInfo.u8_system_state).ToString() == payload ? "OK" : "Error"; } catch (Exception ex) { @@ -88,7 +88,7 @@ namespace TBF.Rig.TestMethods.iPerlCommunication { RfidCommunicationService rfidCommunicationService = new RfidCommunicationService { ComPort = $"COM{iHead.RfidComPortNr}", WaitTimeAfterFailure = 2200, PassThroughWaitTime = 1500, MaxRetries = 3, TimeOut = 5000 }; //rfidCommunicationService.RfidWrite(Params.u8_Customer_Text, custText); - return rfidCommunicationService.RfidRead(Params.u8_Customer_Text); + return rfidCommunicationService.RfidRead(Params.u8_Customer_Text).ToString(); } } catch (Exception ex) diff --git a/TBF/TBF.csproj b/TBF/TBF.csproj index 49b320d5c..a9969864f 100644 --- a/TBF/TBF.csproj +++ b/TBF/TBF.csproj @@ -117,6 +117,7 @@ False ..\packages\log4net.2.0.2\lib\net40-full\log4net.dll + True @@ -241,6 +242,7 @@ TestStartEndForm.cs + Form @@ -556,6 +558,23 @@ TestStartEndForm.cs + + Form + + + CycleBgEnForm.cs + + + + + + + + Form + + + TestStartEndForm.cs + @@ -2980,6 +2999,12 @@ TestStartEndForm.cs + + CycleBgEnForm.cs + + + TestStartEndForm.cs + EntryFormCfgCtrl.cs diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs b/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs index de41809f2..7ebc3a23c 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlgPressMeterTab.cs @@ -194,8 +194,9 @@ namespace TBF.UI.Bench.Metrology double correction; /// Correction in default unit double error = 0; - if (subItem == 1 && Utils.TryParseEDouble(strValue, out oriMeasurement) && (measurement = Units.ConvertFrom(currentUnit, oriMeasurement)) >= 0) + if (subItem == 1 && Utils.TryParseEDouble(strValue, out oriMeasurement)) { + measurement = Units.ConvertFrom(currentUnit, oriMeasurement); (item.Tag as MeasurementCorrection).Measurement = measurement; /// Update error (if possible) diff --git a/TBF/UI/Bench/TestProfiles/TestProfilesCtrl.cs b/TBF/UI/Bench/TestProfiles/TestProfilesCtrl.cs index 90637d337..bdf3dc6c0 100644 --- a/TBF/UI/Bench/TestProfiles/TestProfilesCtrl.cs +++ b/TBF/UI/Bench/TestProfiles/TestProfilesCtrl.cs @@ -140,28 +140,31 @@ namespace TBF.UI.Bench.TestProfiles { base.OkBtnClicked(); - using (ITransaction transaction = session.BeginTransaction()) + if (session != null && session.IsOpen) { - try + using (ITransaction transaction = session.BeginTransaction()) { - foreach (var entity in ToBeRemovedItems) session.Delete(entity); - ToBeRemovedItems.Clear(); - - int itemNr = 0; - foreach (var entity in MyItems) + try { - (entity as Profile).ItemNr = itemNr++; - session.SaveOrUpdate(entity); - } + foreach (var entity in ToBeRemovedItems) session.Delete(entity); + ToBeRemovedItems.Clear(); - transaction.Commit(); - session.Flush(); - } - catch (Exception exc) - { - transaction.Rollback(); - log.ErrorFormat("Cannot save changes to DB: {0}", exc.Message); - MessageBox.Show(Strings.Cannot_save_changes, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + int itemNr = 0; + foreach (var entity in MyItems) + { + (entity as Profile).ItemNr = itemNr++; + session.SaveOrUpdate(entity); + } + + transaction.Commit(); + session.Flush(); + } + catch (Exception exc) + { + transaction.Rollback(); + log.ErrorFormat("Cannot save changes to DB: {0}", exc.Message); + MessageBox.Show(Strings.Cannot_save_changes, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } } } diff --git a/TBF/UI/MainWnd.Designer.cs b/TBF/UI/MainWnd.Designer.cs index 8005a86ac..2cd5be43a 100644 --- a/TBF/UI/MainWnd.Designer.cs +++ b/TBF/UI/MainWnd.Designer.cs @@ -107,6 +107,16 @@ namespace TBF.UI this.resultsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.graphsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.calendarTSMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.profileLabel = new System.Windows.Forms.Label(); + this.profileComboBox = new System.Windows.Forms.ComboBox(); + this.producerLabel = new System.Windows.Forms.Label(); + this.mclassLabel = new System.Windows.Forms.Label(); + this.q3Label = new System.Windows.Forms.Label(); + this.dnLabel = new System.Windows.Forms.Label(); + this.producerComboBox = new System.Windows.Forms.ComboBox(); + this.mclassComboBox = new System.Windows.Forms.ComboBox(); + this.q3ComboBox = new System.Windows.Forms.ComboBox(); + this.dnComboBox = new System.Windows.Forms.ComboBox(); ((System.ComponentModel.ISupportInitialize)(this.topVerticalSplitContainer)).BeginInit(); this.topVerticalSplitContainer.Panel1.SuspendLayout(); this.topVerticalSplitContainer.Panel2.SuspendLayout(); @@ -235,6 +245,16 @@ namespace TBF.UI // // descriptionGroupBox // + this.descriptionGroupBox.Controls.Add(this.profileLabel); + this.descriptionGroupBox.Controls.Add(this.profileComboBox); + this.descriptionGroupBox.Controls.Add(this.producerLabel); + this.descriptionGroupBox.Controls.Add(this.mclassLabel); + this.descriptionGroupBox.Controls.Add(this.q3Label); + this.descriptionGroupBox.Controls.Add(this.dnLabel); + this.descriptionGroupBox.Controls.Add(this.producerComboBox); + this.descriptionGroupBox.Controls.Add(this.mclassComboBox); + this.descriptionGroupBox.Controls.Add(this.q3ComboBox); + this.descriptionGroupBox.Controls.Add(this.dnComboBox); this.descriptionGroupBox.Controls.Add(this.descriptionLabel); resources.ApplyResources(this.descriptionGroupBox, "descriptionGroupBox"); this.descriptionGroupBox.Name = "descriptionGroupBox"; @@ -580,10 +600,10 @@ namespace TBF.UI resources.ApplyResources(this.upgradeTSMenuItem, "upgradeTSMenuItem"); this.upgradeTSMenuItem.Click += new System.EventHandler(this.upgradeTSMenuItem_Click); // - // iPerlHeadsToolStripMenuItem + // optoHeadsToolStripMenuItem // - this.optoHeadsToolStripMenuItem.Name = "iPerlHeadsToolStripMenuItem"; - resources.ApplyResources(this.optoHeadsToolStripMenuItem, "iPerlHeadsToolStripMenuItem"); + this.optoHeadsToolStripMenuItem.Name = "optoHeadsToolStripMenuItem"; + resources.ApplyResources(this.optoHeadsToolStripMenuItem, "optoHeadsToolStripMenuItem"); this.optoHeadsToolStripMenuItem.Click += new System.EventHandler(this.optoHeadsToolStripMenuItem_Click); // // clearCountersToolStripMenuItem @@ -651,6 +671,71 @@ namespace TBF.UI resources.ApplyResources(this.calendarTSMenuItem, "calendarTSMenuItem"); this.calendarTSMenuItem.Click += new System.EventHandler(this.calendarTSMenuItem_Click); // + // profileLabel + // + resources.ApplyResources(this.profileLabel, "profileLabel"); + this.profileLabel.Name = "profileLabel"; + // + // profileComboBox + // + this.profileComboBox.FormattingEnabled = true; + resources.ApplyResources(this.profileComboBox, "profileComboBox"); + this.profileComboBox.Name = "profileComboBox"; + this.profileComboBox.SelectedIndexChanged += new System.EventHandler(this.profileComboBox_SelectedIndexChanged); + this.profileComboBox.TextChanged += new System.EventHandler(this.profileComboBox_TextChanged); + // + // producerLabel + // + resources.ApplyResources(this.producerLabel, "producerLabel"); + this.producerLabel.Name = "producerLabel"; + // + // mclassLabel + // + resources.ApplyResources(this.mclassLabel, "mclassLabel"); + this.mclassLabel.Name = "mclassLabel"; + // + // q3Label + // + resources.ApplyResources(this.q3Label, "q3Label"); + this.q3Label.Name = "q3Label"; + // + // dnLabel + // + resources.ApplyResources(this.dnLabel, "dnLabel"); + this.dnLabel.Name = "dnLabel"; + // + // producerComboBox + // + this.producerComboBox.FormattingEnabled = true; + resources.ApplyResources(this.producerComboBox, "producerComboBox"); + this.producerComboBox.Name = "producerComboBox"; + this.producerComboBox.SelectedIndexChanged += new System.EventHandler(this.producerComboBox_SelectedIndexChanged); + this.producerComboBox.TextChanged += new System.EventHandler(this.producerComboBox_TextChanged); + // + // mclassComboBox + // + this.mclassComboBox.FormattingEnabled = true; + resources.ApplyResources(this.mclassComboBox, "mclassComboBox"); + this.mclassComboBox.Name = "mclassComboBox"; + this.mclassComboBox.SelectedIndexChanged += new System.EventHandler(this.mclassComboBox_SelectedIndexChanged); + this.mclassComboBox.TextChanged += new System.EventHandler(this.mclassComboBox_TextChanged); + // + // q3ComboBox + // + this.q3ComboBox.FormattingEnabled = true; + resources.ApplyResources(this.q3ComboBox, "q3ComboBox"); + this.q3ComboBox.Name = "q3ComboBox"; + this.q3ComboBox.SelectedIndexChanged += new System.EventHandler(this.q3ComboBox_SelectedIndexChanged); + this.q3ComboBox.TextChanged += new System.EventHandler(this.q3ComboBox_TextChanged); + // + // dnComboBox + // + this.dnComboBox.FormattingEnabled = true; + resources.ApplyResources(this.dnComboBox, "dnComboBox"); + this.dnComboBox.Name = "dnComboBox"; + this.dnComboBox.SelectedIndexChanged += new System.EventHandler(this.dnComboBox_SelectedIndexChanged); + this.dnComboBox.TextChanged += new System.EventHandler(this.dnComboBox_TextChanged); + // // MainWnd // resources.ApplyResources(this, "$this"); @@ -807,6 +892,16 @@ namespace TBF.UI private System.Windows.Forms.ToolStripMenuItem benchUncertaintyTSMItem; private System.Windows.Forms.ToolStripMenuItem calendarTSMenuItem; private System.Windows.Forms.TabPage calendarTabPage; + private System.Windows.Forms.Label profileLabel; + private System.Windows.Forms.ComboBox profileComboBox; + private System.Windows.Forms.Label producerLabel; + private System.Windows.Forms.Label mclassLabel; + private System.Windows.Forms.Label q3Label; + private System.Windows.Forms.Label dnLabel; + private System.Windows.Forms.ComboBox producerComboBox; + private System.Windows.Forms.ComboBox mclassComboBox; + private System.Windows.Forms.ComboBox q3ComboBox; + private System.Windows.Forms.ComboBox dnComboBox; } } diff --git a/TBF/UI/MainWnd.cs b/TBF/UI/MainWnd.cs index 19e229fff..32a8f5eb2 100644 --- a/TBF/UI/MainWnd.cs +++ b/TBF/UI/MainWnd.cs @@ -29,8 +29,17 @@ namespace TBF.UI public static IDictionary ProcedureNrs = new Dictionary(); /// Used in PreviousResultsDlg public BenchControlPanel BenchControlPanel; + + string selectedProfile; + float selectedDN; + double selectedQ3; + string selectedMClass; + string selectedProducer; + public IList AllProcedures; /// List of all active procedures + public IList Procedures; /// List of procedures satisfying filter criteria public ProcedureInfo SelectedProcedure; public Procedure CurrentProcedure; + public bool IsShutdownDisabled; public bool IsShutdownPCAfterClosingTbf; @@ -103,8 +112,8 @@ namespace TBF.UI Text = string.Format("Test Bench Framework ver. {0} - {1}{2}", Program.Version, - TBF.DB.CurrentBench.BenchName, - TBF.DB.CurrentBench.IsRealBench ? "" : Strings._offline); + DB.CurrentBench.BenchName, + DB.CurrentBench.IsRealBench ? "" : Strings._offline); /// /// Customize menu items /// @@ -117,13 +126,13 @@ namespace TBF.UI helpTSMenuItem.Text = Strings.Help; #if CAMERA /// Add 'Camera' menu item - cameraTSMItem = new System.Windows.Forms.ToolStripMenuItem(); + cameraTSMItem = new ToolStripMenuItem(); cameraTSMItem.Name = "cameraTSMItem"; cameraTSMItem.Text = Strings.Camera; - cameraTSMItem.Click += new System.EventHandler(this.cameraTSMItem_Click); + cameraTSMItem.Click += new EventHandler(this.cameraTSMItem_Click); - mainMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {this.cameraTSMItem}); + mainMenuStrip.Items.AddRange(new ToolStripItem[] {this.cameraTSMItem}); #endif UpdateMenuItemsVisibility(); @@ -133,14 +142,14 @@ namespace TBF.UI IsShutdownDisabled = true; IsShutdownPCAfterClosingTbf = false; - Rig.StateMachine.MachineState = TBF.DB.CurrentBench.IsRealBench ? Rig.MachineState.StartingUp : Rig.MachineState.Disabled; + Rig.StateMachine.MachineState = DB.CurrentBench.IsRealBench ? Rig.MachineState.StartingUp : Rig.MachineState.Disabled; TBF.Data.SetData(); /// if (Rig.StateMachine.MachineState == Rig.MachineState.StartingUp) { try { - startupSession = TBF.DB.ConfigDBSessionFactory.OpenSession(); + startupSession = DB.ConfigDBSessionFactory.OpenSession(); /// Load components, initialize the control board, etc. Rig.StateMachine.InitializeBoardEtc(startupSession, ctrlBrdComponent); @@ -180,9 +189,41 @@ namespace TBF.UI MessageBox.Show(errMsg, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } + + /// Profile + selectedProfile = null; + ComboBox cb = profileComboBox; + cb.Items.Add(Strings.any); + cb.Items.Add(Strings.no_profile); + cb.Items.Add(Strings.any_profile); + cb.Text = cb.Items[0].ToString(); + + /// DN + selectedDN = 0; + cb = dnComboBox; + cb.Items.Add(Strings.any); + cb.Text = cb.Items[0].ToString(); + + /// Q3 / Qn + selectedQ3 = 0; + cb = q3ComboBox; + cb.Items.Add(Strings.any); + cb.Text = cb.Items[0].ToString(); + + /// Metrological class + selectedMClass = null; + cb = mclassComboBox; + cb.Items.Add(Strings.any); + cb.Text = cb.Items[0].ToString(); + + /// Producer + selectedProducer = null; + cb = producerComboBox; + cb.Items.Add(Strings.any); + cb.Text = cb.Items[0].ToString(); } - void Localize() + void Localize() { procedureGroupBox.Text = Strings.Procedure; activityGroupBox.Text = Strings.Activity; @@ -213,7 +254,7 @@ namespace TBF.UI Top = (ls.MainWndTop != 0) ? ls.MainWndTop : 5; } - if (TBF.Rig.StateMachine.MachineState == TBF.Rig.MachineState.StartingUp) + if (Rig.StateMachine.MachineState == Rig.MachineState.StartingUp) { var form = new Shared.ModelessActivityForm() { @@ -284,7 +325,7 @@ namespace TBF.UI } catch (Exception exc) { - TBF.Rig.StateMachine.MachineState = TBF.Rig.MachineState.FailedToStart; + Rig.StateMachine.MachineState = Rig.MachineState.FailedToStart; form.CloseForm(null, new EventArgs()); formThread.Join(); @@ -295,9 +336,7 @@ namespace TBF.UI Environment.NewLine + exc.Message, innerExcMsg); log.Fatal(errMsg); - MessageBox.Show(errMsg, Strings.Error, - System.Windows.Forms.MessageBoxButtons.OK, - System.Windows.Forms.MessageBoxIcon.Exclamation); + MessageBox.Show(errMsg, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } @@ -309,9 +348,9 @@ namespace TBF.UI /// Initialize bench control user interface(s) BenchControlPanel = new BenchControlPanel(); - BenchControlPanel.BalancesCount = TBF.Rig.MettlerToledo.Standard.BalanceDev.BalancesCount - + TBF.Rig.MettlerToledo.Multi.BalanceDev.BalancesCount - + TBF.Rig.Various.TankWithLevelMsrmnt.Tank.TanksCount; + BenchControlPanel.BalancesCount = Rig.MettlerToledo.Standard.BalanceDev.BalancesCount + + Rig.MettlerToledo.Multi.BalanceDev.BalancesCount + + Rig.Various.TankWithLevelMsrmnt.Tank.TanksCount; new System.ComponentModel.ComponentResourceManager(typeof(MainWnd)).ApplyResources(BenchControlPanel, "benchControlPanel"); BenchControlPanel.Name = "benchControlPanel"; rightHorizSplitContainer.Panel2.Controls.Add(BenchControlPanel); @@ -324,15 +363,15 @@ namespace TBF.UI UpdateUser(); mainTabControl.SelectTab((int)MainTabPageId.Hydraulics); - if (TBF.Rig.StateMachine.MachineState == TBF.Rig.MachineState.StartingUp) + if (Rig.StateMachine.MachineState == Rig.MachineState.StartingUp) { /// /// Populate calendar with calendar events from components /// var calEvents = new List(); - foreach (var cmpnt in TBF.Rig.StateMachine.Components) + foreach (var cmpnt in Rig.StateMachine.Components) { - var cmpntWithEvents = cmpnt as TBF.Rig.GenericDevices.IHasCalendarEvents; + var cmpntWithEvents = cmpnt as Rig.GenericDevices.IHasCalendarEvents; if (cmpntWithEvents != null) { foreach (var evnt in cmpntWithEvents.GetCalendarEvents()) calEvents.Add(evnt); @@ -345,13 +384,10 @@ namespace TBF.UI Rig.StateMachine.Start(); log.Info("Test bench started"); } - else if (TBF.Rig.StateMachine.MachineState == TBF.Rig.MachineState.FailedToStart) + else if (Rig.StateMachine.MachineState == Rig.MachineState.FailedToStart) { BenchControlPanel.OnButtonsEtc(null, new ButtonsEtcEventArgs(ButtonsEtc.None)); - MessageBox.Show(Strings.Bench_is_not_running, - Strings.Warning, - System.Windows.Forms.MessageBoxButtons.OK, - System.Windows.Forms.MessageBoxIcon.Exclamation); + MessageBox.Show(Strings.Bench_is_not_running, Strings.Warning, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } @@ -379,7 +415,7 @@ namespace TBF.UI /// /// Invoked from the UiBridge to update the activity label. /// - void OnActivity(object sender, UiBridge.ActivityEventArgs args) + void OnActivity(object sender, ActivityEventArgs args) { switch (args.Cmd) { @@ -407,7 +443,7 @@ namespace TBF.UI void OnStateChanged(object sender, StateChangedEventArgs args) { activityStatusLabel.Text = string.Format("{0}: {1}, {2}", - TBF.Resources.Strings.Batch, TBF.Rig.Sequences.ProcessData.BatchNr, args.StateChangedMsg); + Strings.Batch, Rig.Sequences.ProcessData.BatchNr, args.StateChangedMsg); } void OnTestProgress(object sender, UiBridge.TestProgressEventArgs args) @@ -436,9 +472,9 @@ namespace TBF.UI { mainProgressBar.Value = 0; - if (TBF.Rig.Sequences.ProcessData.BatchRslts != null) + if (Rig.Sequences.ProcessData.BatchRslts != null) { - var b = TBF.Rig.Sequences.ProcessData.BatchRslts.Batch; + var b = Rig.Sequences.ProcessData.BatchRslts.Batch; if (b != null && b.EndTime > b.StartTime) { progressGroupBox.Text = string.Format("{0} @ {1}", Strings.End, b.EndTime.ToShortTimeString()); @@ -479,17 +515,23 @@ namespace TBF.UI return; } - procedureComboBox.Enabled = ((args.Flags & ButtonsEtc.ProcedureCmbBoxEn) != 0); - optoHeadsToolStripMenuItem.Enabled = ((args.Flags & ButtonsEtc.ProcedureCmbBoxEn) != 0); + bool isProcSelectionEnabled = (args.Flags & ButtonsEtc.ProcedureCmbBoxEn) != 0; - if (procedureComboBox.Enabled) progressGroupBox.Text = Strings.Progress; + procedureComboBox.Enabled = isProcSelectionEnabled; - if (procedureComboBox.Enabled && ProceduresUpdated) + profileComboBox.Enabled = dnComboBox.Enabled = q3ComboBox.Enabled = + mclassComboBox.Enabled = producerComboBox.Enabled = isProcSelectionEnabled; + + optoHeadsToolStripMenuItem.Enabled = isProcSelectionEnabled; + + if (isProcSelectionEnabled) progressGroupBox.Text = Strings.Progress; + + if (isProcSelectionEnabled && ProceduresUpdated) { ReloadProcedureComboBoxItems(); } - IsShutdownDisabled = ((args.Flags & ButtonsEtc.ProcedureCmbBoxEn) == 0); + IsShutdownDisabled = !isProcSelectionEnabled; } void OnSaveSettings(object sender, SaveSettingsEventArgs args) @@ -623,7 +665,7 @@ namespace TBF.UI { default: case RemoteDBUse.LocalDBOnly: - dBase = new ISessionFactory[] { TBF.DB.ConfigDBSessionFactory }; + dBase = new ISessionFactory[] { DB.ConfigDBSessionFactory }; signature = new string[] { "" }; break; case RemoteDBUse.RemoteDBOnly: @@ -631,11 +673,11 @@ namespace TBF.UI signature = new string[] { "R" }; break; case RemoteDBUse.BothDBsLocalFirst: - dBase = new ISessionFactory[] { TBF.DB.ConfigDBSessionFactory, TBF.DB.SharedDBSessionFactory }; + dBase = new ISessionFactory[] { DB.ConfigDBSessionFactory, TBF.DB.SharedDBSessionFactory }; signature = new string[] { "L", "R" }; break; case RemoteDBUse.BothDBsRemoteFirst: - dBase = new ISessionFactory[] { TBF.DB.SharedDBSessionFactory, TBF.DB.ConfigDBSessionFactory }; + dBase = new ISessionFactory[] { TBF.DB.SharedDBSessionFactory, DB.ConfigDBSessionFactory }; signature = new string[] { "R", "L" }; break; } @@ -658,16 +700,48 @@ namespace TBF.UI foreach (var proc in procedures) { - string itemText = string.Format("{0}{1}{2}{3}", signature[i], proc.ItemNr + 1, ProcSeparator, proc.Name); - procedureComboBox.Items.Add(itemText); - if (!ProcedureNrs.ContainsKey(proc.Name)) ProcedureNrs.Add(proc.Name, proc.ItemNr + 1); - - if ((procedureNameToSelect == proc.Name) && !procedureSet) + if (Rig.StateMachine.WaterMeterCmpnt != null) { - procedureComboBox.Text = itemText; - SelectedProcedure = new ProcedureInfo(procedureNameToSelect, (dBase[i] == TBF.DB.SharedDBSessionFactory)); - BenchControlPanel.ReloadTests(session); - procedureSet = true; + var waterMeterParams = Rig.StateMachine.WaterMeterCmpnt.Cfg.GetUIProcParamsProvider(proc); + Rig.WaterMeters.WaterMeter.ProcParams wmParams = waterMeterParams as TBF.Rig.WaterMeters.WaterMeter.ProcParams; + if (wmParams != null) + { + proc.DN = wmParams.DN; + proc.Qn = wmParams.Qn; + proc.MClass = wmParams.MetrologicalClass; + proc.Producer = wmParams.Producer; + + if (!string.IsNullOrEmpty(proc.AltProcName) && !profileComboBox.Items.Contains(proc.AltProcName)) + { + profileComboBox.Items.Add(proc.AltProcName); + } + if (!dnComboBox.Items.Contains(wmParams.DN.ToString())) dnComboBox.Items.Add(wmParams.DN.ToString()); + if (!q3ComboBox.Items.Contains(wmParams.Qn.ToString())) q3ComboBox.Items.Add(wmParams.Qn.ToString()); + if (!mclassComboBox.Items.Contains(wmParams.MetrologicalClass)) mclassComboBox.Items.Add(wmParams.MetrologicalClass); + if (!producerComboBox.Items.Contains(wmParams.Producer)) producerComboBox.Items.Add(wmParams.Producer); + } + } + + if ((selectedProfile == null || + (selectedProfile == Strings.no_profile && string.IsNullOrEmpty(proc.AltProcName)) || + (selectedProfile == Strings.any_profile && !string.IsNullOrEmpty(proc.AltProcName)) || + selectedProfile == proc.AltProcName) && + (selectedDN == 0 || selectedDN == proc.DN) && + (selectedQ3 == 0 || selectedQ3 == proc.Qn) && + (selectedMClass == null || selectedMClass == proc.MClass) && + (selectedProducer == null || selectedProducer == proc.Producer)) + { + string itemText = string.Format("{0}{1}{2}{3}", signature[i], proc.ItemNr + 1, ProcSeparator, proc.Name); + procedureComboBox.Items.Add(itemText); + if (!ProcedureNrs.ContainsKey(proc.Name)) ProcedureNrs.Add(proc.Name, proc.ItemNr + 1); + + if ((procedureNameToSelect == proc.Name) && !procedureSet) + { + procedureComboBox.Text = itemText; + SelectedProcedure = new ProcedureInfo(procedureNameToSelect, (dBase[i] == TBF.DB.SharedDBSessionFactory)); + BenchControlPanel.ReloadTests(session); + procedureSet = true; + } } } @@ -718,7 +792,7 @@ namespace TBF.UI BenchControlPanel.ReloadTests(); if (CurrentProcedure != null && CurrentProcedure.Description != null) { - descriptionLabel.Text = CurrentProcedure.Description; + //descriptionLabel.Text = CurrentProcedure.Description; } if (CurrentProcedure != null && testProgressControls != null) { @@ -1047,5 +1121,53 @@ namespace TBF.UI return false; } } + + private void profileComboBox_SelectedIndexChanged(object sender, EventArgs e) { UpdateSelectedProfile(); } + private void profileComboBox_TextChanged(object sender, EventArgs e) { UpdateSelectedProfile(); } + /// + void UpdateSelectedProfile() + { + //selectedProfile = ... TODO + selectedProfile = (profileComboBox.Text != Strings.any) ? profileComboBox.Text : null; + ReloadProcedureComboBoxItems(); + } + + private void dnComboBox_SelectedIndexChanged(object sender, EventArgs e) { UpdateSelectedDN(); } + private void dnComboBox_TextChanged(object sender, EventArgs e) { UpdateSelectedDN(); } + /// + void UpdateSelectedDN() + { + uint ival; + selectedDN = uint.TryParse(dnComboBox.Text, out ival) ? ival : 0; + ReloadProcedureComboBoxItems(); + } + + private void q3ComboBox_SelectedIndexChanged(object sender, EventArgs e) { UpdateSelectedQn(); } + private void q3ComboBox_TextChanged(object sender, EventArgs e) { UpdateSelectedQn(); } + /// + void UpdateSelectedQn() + { + double fval; + selectedQ3 = Utils.TryParseUDouble(q3ComboBox.Text, out fval) ? fval : 0; + ReloadProcedureComboBoxItems(); + } + + private void mclassComboBox_SelectedIndexChanged(object sender, EventArgs e) { UpdateSelectedMClass(); } + private void mclassComboBox_TextChanged(object sender, EventArgs e) { UpdateSelectedMClass(); } + /// + void UpdateSelectedMClass() + { + selectedMClass = (mclassComboBox.Text != Strings.any) ? mclassComboBox.Text : null; + ReloadProcedureComboBoxItems(); + } + + private void producerComboBox_SelectedIndexChanged(object sender, EventArgs e) { UpdateSelectedProducer(); } + private void producerComboBox_TextChanged(object sender, EventArgs e) { UpdateSelectedProducer(); } + /// + void UpdateSelectedProducer() + { + selectedProducer = (producerComboBox.Text != Strings.any) ? producerComboBox.Text : null; + ReloadProcedureComboBoxItems(); + } } } diff --git a/TBF/UI/MainWnd.resx b/TBF/UI/MainWnd.resx index 40f1d0f72..a3c8623e9 100644 --- a/TBF/UI/MainWnd.resx +++ b/TBF/UI/MainWnd.resx @@ -429,6 +429,246 @@ 0 + + True + + + 4, 19 + + + 36, 13 + + + 19 + + + Profile + + + profileLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + descriptionGroupBox + + + 0 + + + 60, 16 + + + 133, 21 + + + 18 + + + profileComboBox + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + descriptionGroupBox + + + 1 + + + True + + + 573, 19 + + + 50, 13 + + + 17 + + + Producer + + + producerLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + descriptionGroupBox + + + 2 + + + True + + + 449, 19 + + + 32, 13 + + + 16 + + + Class + + + mclassLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + descriptionGroupBox + + + 3 + + + True + + + 317, 19 + + + 40, 13 + + + 15 + + + Q3/Qn + + + q3Label + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + descriptionGroupBox + + + 4 + + + True + + + 204, 19 + + + 23, 13 + + + 14 + + + DN + + + dnLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + descriptionGroupBox + + + 5 + + + 629, 16 + + + 133, 21 + + + 13 + + + producerComboBox + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + descriptionGroupBox + + + 6 + + + 487, 16 + + + 72, 21 + + + 12 + + + mclassComboBox + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + descriptionGroupBox + + + 7 + + + 363, 16 + + + 72, 21 + + + 11 + + + q3ComboBox + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + descriptionGroupBox + + + 8 + + + 233, 16 + + + 72, 21 + + + 10 + + + dnComboBox + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + descriptionGroupBox + + + 9 + True @@ -454,7 +694,7 @@ descriptionGroupBox - 0 + 10 Fill @@ -598,7 +838,7 @@ ctrlBrdComponent - ControlComponent3Munich.UserControl1, ControlComponent3Munich, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + ControlComponent_Torino2015.UserControl1, ControlComponent3U, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null homeTabPage @@ -652,7 +892,7 @@ processTabPageCtrl - TBF.UI.Process.ProcessTabPageCtrl6, TBF, Version=2.25.1440.0, Culture=neutral, PublicKeyToken=null + TBF.UI.Process.ProcessTabPageCtrl24, TBF, Version=2.33.2064.0, Culture=neutral, PublicKeyToken=null processTabPage @@ -730,7 +970,7 @@ resultsTabPageCtrl - TBF.UI.ResultsMI.ResultsTabPageCtrl, TBF, Version=2.25.1440.0, Culture=neutral, PublicKeyToken=null + TBF.UI.ResultsMI.ResultsTabPageCtrl, TBF, Version=2.33.2064.0, Culture=neutral, PublicKeyToken=null resultsTabPage @@ -781,7 +1021,7 @@ graphsTabPageCtrl - TBF.UI.Graphs.GraphsTabPageCtrl, TBF, Version=2.25.1440.0, Culture=neutral, PublicKeyToken=null + TBF.UI.Graphs.GraphsTabPageCtrl, TBF, Version=2.33.2064.0, Culture=neutral, PublicKeyToken=null graphsTabPage @@ -835,7 +1075,7 @@ eventLogsTabPageCtrl - TBF.UI.EventLogs.EventLogsTabPageCtrl, TBF, Version=2.25.1440.0, Culture=neutral, PublicKeyToken=null + TBF.UI.EventLogs.EventLogsTabPageCtrl, TBF, Version=2.33.2064.0, Culture=neutral, PublicKeyToken=null eventLogsTabPage @@ -886,7 +1126,7 @@ calendarTabPageCtrl - TBF.UI.Calendar.CalendarTabPageCtrl, TBF, Version=2.25.1440.0, Culture=neutral, PublicKeyToken=null + TBF.UI.Calendar.CalendarTabPageCtrl, TBF, Version=2.33.2064.0, Culture=neutral, PublicKeyToken=null calendarTabPage @@ -937,7 +1177,7 @@ picturesTabPageCtrl - TBF.UI.Camera.PicturesTabPageCtrl, TBF, Version=2.25.1440.0, Culture=neutral, PublicKeyToken=null + TBF.UI.Camera.PicturesTabPageCtrl, TBF, Version=2.33.2064.0, Culture=neutral, PublicKeyToken=null picturesTabPage @@ -1332,10 +1572,10 @@ Upgrade - + 152, 22 - + iPerl Heads @@ -1584,10 +1824,10 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - iPerlHeadsToolStripMenuItem + + optoHeadsToolStripMenuItem - + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 @@ -1644,13 +1884,4 @@ System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Logs - - - Logs - - - Settings - \ No newline at end of file diff --git a/TBF/UI/Procedures/ProceduresCtrl.cs b/TBF/UI/Procedures/ProceduresCtrl.cs index 6a6ae977f..5881ae08f 100644 --- a/TBF/UI/Procedures/ProceduresCtrl.cs +++ b/TBF/UI/Procedures/ProceduresCtrl.cs @@ -268,28 +268,31 @@ namespace TBF.UI.Procedures /// public void OkBtnClicked() { - using (ITransaction transaction = Session.BeginTransaction()) + if (Session != null && Session.IsOpen) { - try + using (ITransaction transaction = Session.BeginTransaction()) { - foreach (var entity in ToBeRemovedProcedures) Session.Delete(entity); - ToBeRemovedProcedures.Clear(); - - int itemNr = 0; - foreach (var proc in AllProcedures) + try { - (proc as Procedure).ItemNr = itemNr++; - Session.SaveOrUpdate(proc); - } + foreach (var entity in ToBeRemovedProcedures) Session.Delete(entity); + ToBeRemovedProcedures.Clear(); - transaction.Commit(); - Session.Flush(); - } - catch (Exception exc) - { - transaction.Rollback(); - log.ErrorFormat("Cannot save changes to DB: {0}", exc.Message); - MessageBox.Show(Strings.Cannot_save_changes, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + int itemNr = 0; + foreach (var proc in AllProcedures) + { + (proc as Procedure).ItemNr = itemNr++; + Session.SaveOrUpdate(proc); + } + + transaction.Commit(); + Session.Flush(); + } + catch (Exception exc) + { + transaction.Rollback(); + log.ErrorFormat("Cannot save changes to DB: {0}", exc.Message); + MessageBox.Show(Strings.Cannot_save_changes, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } } } diff --git a/packages/ControlBoard/Roma200/ControlComponent3U.dll b/packages/ControlBoard/Roma200/ControlComponent3U.dll index 018ef812e..fda4a86ae 100644 Binary files a/packages/ControlBoard/Roma200/ControlComponent3U.dll and b/packages/ControlBoard/Roma200/ControlComponent3U.dll differ