From a625e2dfdb6c9e7a0d0639bdca1d6b29fcc86db0 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Tue, 28 Nov 2023 14:52:13 +0100 Subject: [PATCH] bool WaterMeter.PrintLabel (initially set), DataEntry.Uni : 1. "Auto s/n" function, 2. common check box, 3. Ct.PrintLabel (yes/no) --- Results/Entities/WaterMeter.cs | 5 + TBF/Rig/DataEntry/DEItem.cs | 26 +++ TBF/Rig/DataEntry/DEUtils.cs | 36 +++-- TBF/Rig/DataEntry/Uni/CycleBgEnForm.cs | 152 ++++++++++++++++-- .../DataEntry/Uni/CycleBgEnForm.designer.cs | 11 ++ TBF/Rig/DataEntry/Uni/CycleBgEnForm.resx | 38 ++++- TBF/Rig/DataEntry/Uni/EntryFormCfg.cs | 3 + 7 files changed, 245 insertions(+), 26 deletions(-) diff --git a/Results/Entities/WaterMeter.cs b/Results/Entities/WaterMeter.cs index bba14d4bd..d3a25ae45 100644 --- a/Results/Entities/WaterMeter.cs +++ b/Results/Entities/WaterMeter.cs @@ -100,6 +100,7 @@ namespace Results.Entities #endif public virtual int ProcessId { get; set; } /// Not mapped to DB !!! Tracing DB Process ID public virtual bool LastRecordIsNok { get; set; } /// Not mapped to DB !!! Previous record verification result + public virtual bool PrintLabel { get; set; } /// Not mapped to DB !!! public virtual WaterMeterData WaterMeterData { get; set; } public virtual Batch Batch { get; set; } @@ -458,6 +459,7 @@ namespace Results.Entities #endif ProcessId = 0; LastRecordIsNok = false; + PrintLabel = true; } @@ -519,6 +521,7 @@ namespace Results.Entities #endif ProcessId = src.ProcessId; /// Not mapped to DB LastRecordIsNok = src.LastRecordIsNok; /// Not mapped to DB + PrintLabel = src.PrintLabel; /// Not mapped to DB foreach (var mtr in MeterTestRslts) { @@ -698,6 +701,7 @@ namespace Results.Entities #endif writer.Write(ProcessId); writer.Write(LastRecordIsNok); + writer.Write(PrintLabel); /// Save WaterMeterData or WaterMeterData.Id if (WaterMeterData != null && savedWMDatas != null && !savedWMDatas.Contains(WaterMeterData)) @@ -777,6 +781,7 @@ namespace Results.Entities #endif ProcessId = reader.ReadInt32(); LastRecordIsNok = reader.ReadBoolean(); + PrintLabel = reader.ReadBoolean(); /// Retrieve TestData if (reader.ReadBoolean()) diff --git a/TBF/Rig/DataEntry/DEItem.cs b/TBF/Rig/DataEntry/DEItem.cs index fcadb3098..0e8933ab3 100644 --- a/TBF/Rig/DataEntry/DEItem.cs +++ b/TBF/Rig/DataEntry/DEItem.cs @@ -15,6 +15,7 @@ namespace TBF.Rig.DataEntry [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 + [Description("Set")] Set, /// Set to 'yes' when the form is open Count, } @@ -29,7 +30,9 @@ namespace TBF.Rig.DataEntry [Description("Radio address")] RadioAddress, [Description("Year of calibration")] YearOfCalibration, [Description("Start state")] StartState, + [Description("Start state aux")] StartStateAux, [Description("End state")] EndState, + [Description("End state aux")] EndStateAux, [Description("Archive path")] ArchivePath, [Description("WM Order")] WmOrder, [Description("Batch order")] BatchOrder, @@ -37,6 +40,7 @@ namespace TBF.Rig.DataEntry [Description("WM Remark")] WmRemark, [Description("Batch remark")] BatchRemark, [Description("Batch and WM remark")] BatchAndWmRemark, + [Description("Print label")] PrintLabel, #if ORACLE_DB [Description("Prefix")] Prefix, [Description("Suffix")] Suffix, @@ -44,6 +48,28 @@ namespace TBF.Rig.DataEntry Count } + /// + /// Identifies image instance + /// + public enum Tst + { + Start, + End, + Both, + } + + /// + /// Image rotation + /// + public enum Rotation + { + R0, + R90, + R180, + R270, + Count + } + public class DEItem { public readonly Ct Content; diff --git a/TBF/Rig/DataEntry/DEUtils.cs b/TBF/Rig/DataEntry/DEUtils.cs index da8a432fe..80b13b4c7 100644 --- a/TBF/Rig/DataEntry/DEUtils.cs +++ b/TBF/Rig/DataEntry/DEUtils.cs @@ -3,6 +3,7 @@ /// using System.Windows.Forms; using Results.Entities; +using TBF.Resources; namespace TBF.Rig.DataEntry { @@ -15,22 +16,25 @@ namespace TBF.Rig.DataEntry 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.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.StartState: return (!wm.Disabled && wm.GetStartState() != null) ? wm.GetStartState() : string.Empty; + case Ct.StartStateAux: return string.Empty; + case Ct.EndState: return (!wm.Disabled && wm.EndState != null) ? wm.EndState : string.Empty; + case Ct.EndStateAux: return (!wm.Disabled && wm.GetEndStateAux() != null) ? wm.GetEndStateAux() : 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.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; + 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; + case Ct.PrintLabel: return wm.PrintLabel ? Strings.yes : Strings.no; #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; @@ -53,7 +57,9 @@ namespace TBF.Rig.DataEntry 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.StartStateAux: return; case Ct.EndState: wm.EndState = value; return; + case Ct.EndStateAux: wm.SetEndStateAux(value); return; case Ct.ArchivePath: wm.ArchivePath = value; return; case Ct.WmOrder: @@ -73,6 +79,10 @@ namespace TBF.Rig.DataEntry case Ct.BatchAndWmRemark: if (wm.Batch != null) wm.Batch.Remark = value; return; + + case Ct.PrintLabel: + wm.PrintLabel = (value == Strings.yes); + return; #if ORACLE_DB case Ct.Prefix: wm.Prefix = value; return; case Ct.Suffix: wm.Suffix = value; return; diff --git a/TBF/Rig/DataEntry/Uni/CycleBgEnForm.cs b/TBF/Rig/DataEntry/Uni/CycleBgEnForm.cs index 7ada3da43..71e3a5ab0 100644 --- a/TBF/Rig/DataEntry/Uni/CycleBgEnForm.cs +++ b/TBF/Rig/DataEntry/Uni/CycleBgEnForm.cs @@ -124,6 +124,18 @@ namespace TBF.Rig.DataEntry.Uni comboBoxes = new ComboBox[colItems.Count, wmsCount]; checkBoxes = new CheckBox[wmsCount]; + /// Make Auto s/n button visible if there is either Ct.SerialNr or Ct.SerialNrAux column + int buttonsWidth = 350; + for (int k = 0; k < colItems.Count; k++) + { + if ((colItems[k].Content == Ct.SerialNr || colItems[k].Content == Ct.SerialNrAux) && colItems[k].Action != Ac.LoadReadOnly) + { + autoSNButton.Visible = true; + buttonsWidth += 147; + break; + } + } + /// Layout related readonly variables derived from argument 'sz' switch (sz) { @@ -132,7 +144,7 @@ namespace TBF.Rig.DataEntry.Uni meterHeight = 26; /// Height of a ComboBox control margin = 20; spacing = 8; - buttonsWidth = 350; + this.buttonsWidth = buttonsWidth; hdrHeight = 120; labelWid = 31; checkBoxWid = 23; @@ -144,7 +156,7 @@ namespace TBF.Rig.DataEntry.Uni meterHeight = 31; /// Height of a ComboBox control margin = 25; spacing = 10; - buttonsWidth = 350; + this.buttonsWidth = buttonsWidth; hdrHeight = 140; labelWid = 34; checkBoxWid = 23; @@ -155,7 +167,7 @@ namespace TBF.Rig.DataEntry.Uni meterHeight = 37; /// Height of a ComboBox control margin = 30; spacing = 12; - buttonsWidth = 350; + this.buttonsWidth = buttonsWidth; hdrHeight = 160; labelWid = 40; checkBoxWid = 23; @@ -236,6 +248,8 @@ namespace TBF.Rig.DataEntry.Uni /// /// Table /// + int commonCheckBoxLeft = 0; + int commonCheckBoxTop = 0; int columnsTop = Math.Max(hdrHeight, groupBoxHeight + 2 * margin + spacing); for (int j = 0; j < linesCount; j++) { @@ -294,14 +308,22 @@ namespace TBF.Rig.DataEntry.Uni 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 - + + if (ci.Content == Ct.PrintLabel) + { + comboBox.Items.Add(Strings.yes); + comboBox.Items.Add(Strings.no); + } + else + { + 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); @@ -316,7 +338,26 @@ namespace TBF.Rig.DataEntry.Uni }; checkBoxes[wmPos0] = checkBox; this.Controls.Add(checkBox); + + if (commonCheckBoxLeft == 0) + { + commonCheckBoxLeft = left; + commonCheckBoxTop = columnsTop - meterHeight; + } } + + okButton.TabIndex = tabIndex++; + clearButton.TabIndex = tabIndex++; + + var commonCheckBox = new CheckBox + { + Location = new Point(commonCheckBoxLeft, commonCheckBoxTop + 6), + Size = new Size(checkBoxWid, 23), + TabIndex = tabIndex++, + Parent = this, + }; + commonCheckBox.CheckedChanged += new System.EventHandler(commonCheckBox_CheckedChanged); + this.Controls.Add(commonCheckBox); } /// @@ -442,6 +483,10 @@ namespace TBF.Rig.DataEntry.Uni case Ac.LoadReadOnly: commonComboBoxes[ix].Text = DEUtils.GetContent(commonItems[ix].Content, firstValidWM); break; + + case Ac.Set: + commonComboBoxes[ix].Text = Strings.yes; + break; } } @@ -469,6 +514,13 @@ namespace TBF.Rig.DataEntry.Uni comboBoxes[k, i].Text = DEUtils.GetContent(colItems[k].Content, WaterMeters[i]); } break; + + case Ac.Set: + for (int i = 0; i < wmsCount; i++) + { + comboBoxes[k, i].Text = Strings.yes; + } + break; } } @@ -574,18 +626,94 @@ namespace TBF.Rig.DataEntry.Uni } } - private void clearButton_Click(object sender, EventArgs e) + private void commonCheckBox_CheckedChanged(object sender, EventArgs e) { - InitializeBoxes(); + bool state = (sender as CheckBox).Checked; + for (int i = 0; i < wmsCount; i++) + { + checkBoxes[i].Checked = state; + } } - private void okButton_Click(object sender, EventArgs e) + private void okButton_Click(object sender, EventArgs e) { UpdateWMsFromBoxes(); completed = true; Close(); } + + private void clearButton_Click(object sender, EventArgs e) + { + InitializeBoxes(); + } + + private void autoSNButton_Click(object sender, EventArgs e) + { + /// + /// Find the 1st enabled water meter + /// + int firstIx; + for (firstIx = 0; firstIx < wmsCount; firstIx++) + { + if (checkBoxes[firstIx].Checked) break; + } + if (firstIx == wmsCount) + { + return; /// There is not any enabled water meter + } + + char[] digits = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; + + /// + /// Find a column with serial numbers + /// + for (int k = 0; k < colItems.Count; k++) + { + if ((colItems[k].Content == Ct.SerialNr || colItems[k].Content == Ct.SerialNrAux) && colItems[k].Action != Ac.LoadReadOnly) + { + /// + /// Column with serial numbers found => perform an auto s/n assignment + /// + string firstSN = comboBoxes[k, firstIx].Text; + + int firstSnNr; + int startIx = firstSN.IndexOfAny(digits); + if (startIx >= 0) + { + int lastDigitPosPlus1 = startIx + 1; + var listOfDigits = new List(digits); + while (lastDigitPosPlus1 < firstSN.Length && listOfDigits.Contains(firstSN[lastDigitPosPlus1])) + { + lastDigitPosPlus1++; + } + int digitsCount = lastDigitPosPlus1 - startIx; + + if (int.TryParse(firstSN.Substring(startIx, digitsCount), out firstSnNr) && firstSnNr >= 0) + { + for (int ix = firstIx + 1; ix < wmsCount; ix++) + { + if (checkBoxes[ix].Checked) + { + firstSnNr++; + string newSN = firstSnNr.ToString(); + int len = newSN.Length; + if (len <= digitsCount) + { + comboBoxes[k, ix].Text = firstSN.Substring(0, startIx + digitsCount - len) + newSN + firstSN.Substring(startIx + digitsCount); + } + else + { + comboBoxes[k, ix].Text = firstSN.Substring(0, startIx) + newSN + firstSN.Substring(startIx + digitsCount); ; + } + } + } + } + } + } + } + } + private void comboBox_SelectedIndexChanged(object sndr, EventArgs e) { if (!isHandlersEnabled) return; @@ -596,7 +724,7 @@ namespace TBF.Rig.DataEntry.Uni isHandlersEnabled = false; - if (k >= 0 && comboBoxes[k, j].Text == comboBoxes[k, j].Items[0].ToString()) + if (k >= 0 && colItems[k].Content != Ct.PrintLabel && comboBoxes[k, j].Text == comboBoxes[k, j].Items[0].ToString()) { for (int i = 0; i < wmsCount; i++) { diff --git a/TBF/Rig/DataEntry/Uni/CycleBgEnForm.designer.cs b/TBF/Rig/DataEntry/Uni/CycleBgEnForm.designer.cs index 012ebb410..852499f4c 100644 --- a/TBF/Rig/DataEntry/Uni/CycleBgEnForm.designer.cs +++ b/TBF/Rig/DataEntry/Uni/CycleBgEnForm.designer.cs @@ -34,6 +34,7 @@ namespace TBF.Rig.DataEntry.Uni 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.autoSNButton = new System.Windows.Forms.Button(); this.SuspendLayout(); // // okButton @@ -52,11 +53,20 @@ namespace TBF.Rig.DataEntry.Uni this.clearButton.UseVisualStyleBackColor = true; this.clearButton.Click += new System.EventHandler(this.clearButton_Click); // + // autoSNButton + // + resources.ApplyResources(this.autoSNButton, "autoSNButton"); + this.autoSNButton.ForeColor = System.Drawing.Color.Black; + this.autoSNButton.Name = "autoSNButton"; + this.autoSNButton.UseVisualStyleBackColor = true; + this.autoSNButton.Click += new System.EventHandler(this.autoSNButton_Click); + // // CycleBgEnForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.DarkGray; + this.Controls.Add(this.autoSNButton); this.Controls.Add(this.clearButton); this.Controls.Add(this.okButton); this.ForeColor = System.Drawing.Color.Black; @@ -71,5 +81,6 @@ namespace TBF.Rig.DataEntry.Uni private System.Windows.Forms.Button okButton; private System.Windows.Forms.Button clearButton; + private System.Windows.Forms.Button autoSNButton; } } \ No newline at end of file diff --git a/TBF/Rig/DataEntry/Uni/CycleBgEnForm.resx b/TBF/Rig/DataEntry/Uni/CycleBgEnForm.resx index 4cd233af3..fdb7af35b 100644 --- a/TBF/Rig/DataEntry/Uni/CycleBgEnForm.resx +++ b/TBF/Rig/DataEntry/Uni/CycleBgEnForm.resx @@ -148,7 +148,7 @@ $this - 1 + 2 Top, Right @@ -181,6 +181,42 @@ $this + 1 + + + Top, Right + + + Verdana, 14.25pt + + + NoControl + + + 648, 26 + + + 112, 63 + + + 9 + + + Auto s/n + + + False + + + autoSNButton + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0 diff --git a/TBF/Rig/DataEntry/Uni/EntryFormCfg.cs b/TBF/Rig/DataEntry/Uni/EntryFormCfg.cs index f817a25d3..b81af94cd 100644 --- a/TBF/Rig/DataEntry/Uni/EntryFormCfg.cs +++ b/TBF/Rig/DataEntry/Uni/EntryFormCfg.cs @@ -539,10 +539,13 @@ namespace TBF.Rig.DataEntry.Uni Ct.RadioAddress.ToDescription(), Ct.YearOfCalibration.ToDescription(), Ct.StartState.ToDescription(), + Ct.StartStateAux.ToDescription(), Ct.EndState.ToDescription(), + Ct.EndStateAux.ToDescription(), Ct.ArchivePath.ToDescription(), Ct.WmOrder.ToDescription(), Ct.WmRemark.ToDescription(), + Ct.PrintLabel.ToDescription(), }; } case 2: