From b1f3b72a960493cea3a4d6580bfc844d805bf928 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Mon, 27 Nov 2023 12:16:33 +0100 Subject: [PATCH] 1. bool WaterMeter.PrintLabel, DataEntry.Uni: 2. "Auto s/n" function, 3. common check box, 4. Ct.PrintLabel (yes/no) --- Results/Entities/WaterMeter.cs | 5 + SharedDatabase/Entities/WaterMeter.cs | 5 + TBF/Rig/DataEntry/DEItem.cs | 2 + TBF/Rig/DataEntry/DEUtils.cs | 12 +- TBF/Rig/DataEntry/Uni/CycleBgEnForm.cs | 151 ++++++++++++++++-- .../DataEntry/Uni/CycleBgEnForm.designer.cs | 11 ++ TBF/Rig/DataEntry/Uni/CycleBgEnForm.resx | 38 ++++- TBF/Rig/DataEntry/Uni/EntryFormCfg.cs | 1 + 8 files changed, 208 insertions(+), 17 deletions(-) diff --git a/Results/Entities/WaterMeter.cs b/Results/Entities/WaterMeter.cs index a15c906cf..7a75f8864 100644 --- a/Results/Entities/WaterMeter.cs +++ b/Results/Entities/WaterMeter.cs @@ -109,6 +109,7 @@ namespace Results.Entities /// public virtual string Workflow { get; set; } /// Not mapped to DB !!! Production tracing workflow name 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; } @@ -467,6 +468,7 @@ namespace Results.Entities #if IPERL FWVersion = string.Empty; #endif + PrintLabel = true; } @@ -529,6 +531,7 @@ namespace Results.Entities Workflow = src.Workflow; /// Not mapped to DB LastRecordIsNok = src.LastRecordIsNok; /// Not mapped to DB + PrintLabel = src.PrintLabel; /// Not mapped to DB foreach (var mtr in MeterTestRslts) { @@ -723,6 +726,7 @@ namespace Results.Entities writer.Write(Workflow); writer.Write(LastRecordIsNok); + writer.Write(PrintLabel); /// Save WaterMeterData or WaterMeterData.Id if (WaterMeterData != null && savedWMDatas != null && !savedWMDatas.Contains(WaterMeterData)) @@ -823,6 +827,7 @@ namespace Results.Entities Workflow = reader.ReadString(); LastRecordIsNok = reader.ReadBoolean(); + PrintLabel = reader.ReadBoolean(); /// Retrieve TestData if (reader.ReadBoolean()) diff --git a/SharedDatabase/Entities/WaterMeter.cs b/SharedDatabase/Entities/WaterMeter.cs index 7d4eb6d55..0d321935d 100644 --- a/SharedDatabase/Entities/WaterMeter.cs +++ b/SharedDatabase/Entities/WaterMeter.cs @@ -108,6 +108,7 @@ namespace SharedDatabase.Entities /// public virtual string Workflow { get; set; } /// Not mapped to DB !!! Production tracing workflow name 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; } @@ -469,6 +470,7 @@ namespace SharedDatabase.Entities #if IPERL FWVersion = string.Empty; #endif + PrintLabel = true; } @@ -531,6 +533,7 @@ namespace SharedDatabase.Entities Workflow = src.Workflow; /// Not mapped to DB LastRecordIsNok = src.LastRecordIsNok; /// Not mapped to DB + PrintLabel = src.PrintLabel; /// Not mapped to DB foreach (var mtr in MeterTestRslts) { @@ -725,6 +728,7 @@ namespace SharedDatabase.Entities writer.Write(Workflow); writer.Write(LastRecordIsNok); + writer.Write(PrintLabel); /// Save WaterMeterData or WaterMeterData.Id if (WaterMeterData != null && savedWMDatas != null && !savedWMDatas.Contains(WaterMeterData)) @@ -825,6 +829,7 @@ namespace SharedDatabase.Entities Workflow = reader.ReadString(); 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 483315a04..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, } @@ -39,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, diff --git a/TBF/Rig/DataEntry/DEUtils.cs b/TBF/Rig/DataEntry/DEUtils.cs index 5baa2b422..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 { @@ -30,9 +31,10 @@ namespace TBF.Rig.DataEntry 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; @@ -77,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 129a4d195..1cc9a229f 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,10 +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); } /// @@ -327,7 +365,7 @@ namespace TBF.Rig.DataEntry.Uni /// 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), + Size = new Size(Math.Max(meterWidth * linesCount + margin * (linesCount + 1), margin + groupBoxWidth + this.buttonsWidth), titleBarHeight + columnsTop + lineSize * (meterHeight + spacing) + margin); Localize(); @@ -445,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; } } @@ -472,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; } } @@ -577,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; @@ -599,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 37b45f6fb..69dfc1c5b 100644 --- a/TBF/Rig/DataEntry/Uni/EntryFormCfg.cs +++ b/TBF/Rig/DataEntry/Uni/EntryFormCfg.cs @@ -563,6 +563,7 @@ namespace TBF.Rig.DataEntry.Uni Ct.ArchivePath.ToDescription(), Ct.WmOrder.ToDescription(), Ct.WmRemark.ToDescription(), + Ct.PrintLabel.ToDescription(), }; } case 2: