From 18506390faecf2a8f212c6f2474a0b6687e725cd Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Tue, 8 Dec 2020 11:11:53 +0100 Subject: [PATCH] Procedure.ProcedureParamsMixedCtrl added. --- TBF/TBF.csproj | 11 ++ TBF/UI/Procedures/IProcParamsCtrl.cs | 16 ++ TBF/UI/Procedures/ProcedureDlg.cs | 26 ++- TBF/UI/Procedures/ProcedureParamsCtrl.cs | 7 +- .../ProcedureParamsMixedCtrl.Designer.cs | 65 +++++++ TBF/UI/Procedures/ProcedureParamsMixedCtrl.cs | 180 ++++++++++++++++++ .../Procedures/ProcedureParamsMixedCtrl.resx | 120 ++++++++++++ TBF/UI/Procedures/ProviderAndIx.cs | 19 ++ 8 files changed, 431 insertions(+), 13 deletions(-) create mode 100644 TBF/UI/Procedures/IProcParamsCtrl.cs create mode 100644 TBF/UI/Procedures/ProcedureParamsMixedCtrl.Designer.cs create mode 100644 TBF/UI/Procedures/ProcedureParamsMixedCtrl.cs create mode 100644 TBF/UI/Procedures/ProcedureParamsMixedCtrl.resx create mode 100644 TBF/UI/Procedures/ProviderAndIx.cs diff --git a/TBF/TBF.csproj b/TBF/TBF.csproj index 3f61018df..a5c41425c 100644 --- a/TBF/TBF.csproj +++ b/TBF/TBF.csproj @@ -2306,6 +2306,7 @@ MainWnd.cs + Form @@ -2318,6 +2319,12 @@ ProcedureParamsCtrl.cs + + UserControl + + + ProcedureParamsMixedCtrl.cs + UserControl @@ -2330,6 +2337,7 @@ ProceduresDlg.cs + UserControl @@ -3327,6 +3335,9 @@ ProcedureParamsCtrl.cs + + ProcedureParamsMixedCtrl.cs + ProceduresCtrl.cs diff --git a/TBF/UI/Procedures/IProcParamsCtrl.cs b/TBF/UI/Procedures/IProcParamsCtrl.cs new file mode 100644 index 000000000..4ceeedc31 --- /dev/null +++ b/TBF/UI/Procedures/IProcParamsCtrl.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using Config.Entities; + +namespace TBF.UI.Procedures +{ + public interface IProcParamsCtrl + { + IList CmpntsParams { get; } + string Name { get; } + void Initialize(); + void Unlock(); + void RedrawAll(); + bool UpdateAll(); + } +} diff --git a/TBF/UI/Procedures/ProcedureDlg.cs b/TBF/UI/Procedures/ProcedureDlg.cs index eadfe58a3..d54e916d3 100644 --- a/TBF/UI/Procedures/ProcedureDlg.cs +++ b/TBF/UI/Procedures/ProcedureDlg.cs @@ -53,7 +53,7 @@ namespace TBF.UI.Procedures IList transitionSequences; IList testParamsCtrls; - IList procedureParamsCtrls; + IList procedureParamsCtrls; bool unlocked; @@ -218,7 +218,7 @@ namespace TBF.UI.Procedures { if (method.Cfg.GetRuntimeTestParamsProvider() != null) { - TestParamsCtrl nwCtrl = new TestParamsCtrl(this, method, true); + var nwCtrl = new TestParamsCtrl(this, method, true); testParamsCtrls.Add(nwCtrl); TabPage nwTab = new TabPage(method.Cfg.Name); @@ -233,7 +233,7 @@ namespace TBF.UI.Procedures { if ((cmpnt.Cfg.GetRuntimeTestParamsProvider() != null) && !(cmpnt is ITestMethod)) { - TestParamsCtrl nwCtrl = new TestParamsCtrl(this, cmpnt, true); + var nwCtrl = new TestParamsCtrl(this, cmpnt, true); testParamsCtrls.Add(nwCtrl); TabPage nwTab = new TabPage(cmpnt.Cfg.Name); @@ -247,7 +247,7 @@ namespace TBF.UI.Procedures ///----------------------- Tab pages with procedure parameters ------------------------ ///-------------------------------------------------------------------------------------- - procedureParamsCtrls = new List(); /// Initialize the list + procedureParamsCtrls = new List(); /// Initialize the list ///---------------- /// Water meters @@ -261,7 +261,7 @@ namespace TBF.UI.Procedures } { - ProcedureParamsCtrl newCtrl = new ProcedureParamsCtrl(this, waterMeters, false); + var newCtrl = new ProcedureParamsCtrl(this, waterMeters, false); procedureParamsCtrls.Add(newCtrl); TabPage newTab = new TabPage(Strings.Water_meters); @@ -297,7 +297,7 @@ namespace TBF.UI.Procedures cmpntsInMPath.Add(sensor); } - ProcedureParamsCtrl nwCtrl = new ProcedureParamsCtrl(this, cmpntsInMPath, true); + var nwCtrl = new ProcedureParamsCtrl(this, cmpntsInMPath, true); procedureParamsCtrls.Add(nwCtrl); TabPage nwTab = new TabPage(usedPathName); @@ -311,7 +311,7 @@ namespace TBF.UI.Procedures /// Other components ///--------------------- - /// Create a control for the water meters and add it to the list. + /// Create a control for some other components and add it to the list. IList other = new List(); foreach (var cmpnt in TbfComponents) { @@ -321,7 +321,7 @@ namespace TBF.UI.Procedures if (other.Count > 0) { - ProcedureParamsCtrl newCtrl = new ProcedureParamsCtrl(this, other, false); + var newCtrl = new ProcedureParamsMixedCtrl(this, other); procedureParamsCtrls.Add(newCtrl); TabPage newTab = new TabPage("More..."); @@ -1960,8 +1960,14 @@ namespace TBF.UI.Procedures case ProcedureTabs.Parameters: UpdateFromParametersTab(); break; } - foreach (var ctrl in testParamsCtrls) if (!ctrl.UpdateAll()) MessageBox.Show(string.Format(Strings.Error_saving_parameters_of_0, ctrl.Name)); - foreach (var ctrl in procedureParamsCtrls) if (!ctrl.UpdateAll()) MessageBox.Show(string.Format(Strings.Error_saving_parameters_of_0, ctrl.Name)); + foreach (var ctrl in testParamsCtrls) + { + if (!ctrl.UpdateAll()) MessageBox.Show(string.Format(Strings.Error_saving_parameters_of_0, ctrl.Name)); + } + foreach (var ctrl in procedureParamsCtrls) + { + if (!ctrl.UpdateAll()) MessageBox.Show(string.Format(Strings.Error_saving_parameters_of_0, ctrl.Name)); + } if (usedNames != null && usedNames.Contains(LoadedProcedure.Name.ToLower())) { diff --git a/TBF/UI/Procedures/ProcedureParamsCtrl.cs b/TBF/UI/Procedures/ProcedureParamsCtrl.cs index f88963b30..8bafe5d5d 100644 --- a/TBF/UI/Procedures/ProcedureParamsCtrl.cs +++ b/TBF/UI/Procedures/ProcedureParamsCtrl.cs @@ -19,14 +19,15 @@ namespace TBF.UI.Procedures /// Component2 | /// ... | /// - public partial class ProcedureParamsCtrl : UserControl + public partial class ProcedureParamsCtrl : UserControl, IProcParamsCtrl { ProcedureDlg parent; bool showSensorsColumn; int nrFixedColumns; IList selectedCmpnts; - public IList CmpntsParams; + List cmpntsParams; + public IList CmpntsParams { get { return cmpntsParams; } } int paramsCount; Control[] editors; @@ -36,7 +37,7 @@ namespace TBF.UI.Procedures public ProcedureParamsCtrl() { InitializeComponent(); - CmpntsParams = new List(); + cmpntsParams = new List(); } public ProcedureParamsCtrl(ProcedureDlg parent, IList selectedCmpnts, bool showSensorsColumn) diff --git a/TBF/UI/Procedures/ProcedureParamsMixedCtrl.Designer.cs b/TBF/UI/Procedures/ProcedureParamsMixedCtrl.Designer.cs new file mode 100644 index 000000000..9831647c9 --- /dev/null +++ b/TBF/UI/Procedures/ProcedureParamsMixedCtrl.Designer.cs @@ -0,0 +1,65 @@ +/// +/// Copyright (c) 2020 Sensus Slovensko a.s. +/// +namespace TBF.UI.Procedures +{ + partial class ProcedureParamsMixedCtrl + { + /// + /// 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 Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.listViewEx = new Results.Forms.ListViewEx(); + this.SuspendLayout(); + // + // listViewEx + // + this.listViewEx.AllowColumnReorder = true; + this.listViewEx.Dock = System.Windows.Forms.DockStyle.Fill; + this.listViewEx.DoubleClickActivation = false; + this.listViewEx.FullRowSelect = true; + this.listViewEx.GridLines = true; + this.listViewEx.Location = new System.Drawing.Point(0, 0); + this.listViewEx.Name = "listViewEx"; + this.listViewEx.Size = new System.Drawing.Size(150, 150); + this.listViewEx.TabIndex = 1; + this.listViewEx.UseCompatibleStateImageBehavior = false; + this.listViewEx.View = System.Windows.Forms.View.Details; + // + // ProcedureParams + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.listViewEx); + this.Name = "ProcedureParams"; + this.ResumeLayout(false); + + } + + #endregion + + private Results.Forms.ListViewEx listViewEx; + } +} diff --git a/TBF/UI/Procedures/ProcedureParamsMixedCtrl.cs b/TBF/UI/Procedures/ProcedureParamsMixedCtrl.cs new file mode 100644 index 000000000..7ce2c25bf --- /dev/null +++ b/TBF/UI/Procedures/ProcedureParamsMixedCtrl.cs @@ -0,0 +1,180 @@ +/// +/// Copyright (c) 2020 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using Config.Entities; +using Results.Forms; +using TBF.BenchControl.Generic; +using TBF.Resources; + +namespace TBF.UI.Procedures +{ + /// ----------- + /// / More... \ + /// |------------------------------ + /// | Component1 + /// | param1 + /// | param2 + /// | ... + /// | Component2 + /// | param1 + /// + public partial class ProcedureParamsMixedCtrl : UserControl, IProcParamsCtrl + { + ProcedureDlg parent; + IList tbfComponents; + + List cmpntsParams; + public IList CmpntsParams { get { return cmpntsParams; } } + IList paramCounts; + + Control[] editors; + bool unlocked; + public void Unlock() { unlocked = true; } + + public ProcedureParamsMixedCtrl() + { + InitializeComponent(); + cmpntsParams = new List(); + paramCounts = new List(); + } + + public ProcedureParamsMixedCtrl(ProcedureDlg parent, IList tbfComponents) + : this() + { + this.parent = parent; + this.tbfComponents = tbfComponents; + unlocked = false; + + this.SuspendLayout(); + Dock = System.Windows.Forms.DockStyle.Fill; + listViewEx.Dock = System.Windows.Forms.DockStyle.Fill; + listViewEx.AllowColumnReorder = false; + listViewEx.DoubleClickActivation = false; + listViewEx.FullRowSelect = true; + listViewEx.GridLines = true; + listViewEx.Location = new System.Drawing.Point(0, 0); + listViewEx.TabIndex = 0; + listViewEx.UseCompatibleStateImageBehavior = false; + listViewEx.View = System.Windows.Forms.View.Details; + ResumeLayout(false); + } + + public void Initialize() + { + if (tbfComponents == null) return; + + int totalParamsCount = 0; + foreach (var cmpnt in tbfComponents) + { + IParamsProvider procedureParams = cmpnt.Cfg.GetUIProcParamsProvider(parent.LoadedProcedure); + cmpntsParams.Add(procedureParams); + int pCount = procedureParams != null ? procedureParams.ParamsCount() : 0; + paramCounts.Add(pCount); + totalParamsCount += (pCount + 1); + } + + listViewEx.Columns.Add(Strings.Name, 200); + listViewEx.Columns.Add(Strings.Value, 200); + + editors = new Control[totalParamsCount]; + + int k = 0; + for (int i = 0; i < tbfComponents.Count; i++) + { + k++; + for (int j = 0; j < paramCounts[i]; j++) + { + IList values = cmpntsParams[i].ParamValues(j); + if (values == null) + { + editors[k] = new TextBox(); + } + else + { + ComboBox cb = new ComboBox(); + foreach (var v in values) cb.Items.Add(v); + editors[k] = cb; + } + editors[k].Visible = false; + this.Controls.Add(editors[k]); + k++; + } + } + + listViewEx.SubItemClicked += new SubItemEventHandler(listViewEx_SubItemClicked); + listViewEx.SubItemEndEditing += new SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing); + + RedrawAll(); + } + + private void listViewEx_SubItemClicked(object sender, SubItemEventArgs e) + { + ProviderAndIx ppp = e.Item.Tag as ProviderAndIx; + if (!unlocked || e.SubItem == 0 || ppp == null) return; + listViewEx.StartEditing(editors[ppp.Row], e.Item, e.SubItem); + } + + private void listViewEx_SubItemEndEditing(object sender, SubItemEndEditingEventArgs e) + { + ProviderAndIx ppp = e.Item.Tag as ProviderAndIx; + if (ppp == null) return; + + string message; + if (ppp.Provider.ValidateParam(ppp.Index, e.DisplayText, out message)) + { + ppp.Provider.UpdateParam(ppp.Index, e.DisplayText); + } + else + { + MessageBox.Show(message); + e.DisplayText = e.Item.SubItems[e.SubItem].Text; + e.Cancel = true; + return; /// NOK + } + } + + + public void RedrawAll() + { + listViewEx.Items.Clear(); + + int k = 0; + for (int i = 0; i < tbfComponents.Count; i++) + { + ListViewItem lvi = new ListViewItem(tbfComponents[i].Name); + lvi.SubItems.Add(string.Empty); + lvi.Tag = null; + lvi.BackColor = System.Drawing.Color.LightGray; + listViewEx.Items.Add(lvi); + k++; + + for (int j = 0; j < paramCounts[i]; j++) + { + lvi = new ListViewItem(cmpntsParams[i].ParamName(j)); + lvi.SubItems.Add(cmpntsParams[i].ToString(j)); + lvi.Tag = new ProviderAndIx(cmpntsParams[i], j, k); + listViewEx.Items.Add(lvi); + k++; + } + } + } + + public bool UpdateAll() + { + if (!unlocked) return false; + + for (int i = 0; i < cmpntsParams.Count; i++ ) + { + if (cmpntsParams[i] != null) + { + if (!cmpntsParams[i].UpdateEmbeddedDbEntity()) return false; + } + } + + return true; + } + } +} diff --git a/TBF/UI/Procedures/ProcedureParamsMixedCtrl.resx b/TBF/UI/Procedures/ProcedureParamsMixedCtrl.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TBF/UI/Procedures/ProcedureParamsMixedCtrl.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/UI/Procedures/ProviderAndIx.cs b/TBF/UI/Procedures/ProviderAndIx.cs new file mode 100644 index 000000000..c91f856cc --- /dev/null +++ b/TBF/UI/Procedures/ProviderAndIx.cs @@ -0,0 +1,19 @@ +using System; +using Config.Entities; + +namespace TBF.UI.Procedures +{ + public class ProviderAndIx + { + public readonly IParamsProvider Provider; + public readonly int Index; + public readonly int Row; + + public ProviderAndIx(IParamsProvider provider, int index, int row) + { + Provider = provider; + Index = index; + Row = row; + } + } +}