Procedure.ProcedureParamsMixedCtrl added.

This commit is contained in:
Milan Hanajik 2020-12-08 11:11:53 +01:00
parent fd9a08406f
commit 18506390fa
8 changed files with 431 additions and 13 deletions

View File

@ -2306,6 +2306,7 @@
<Compile Include="UI\MainWnd.designer.cs">
<DependentUpon>MainWnd.cs</DependentUpon>
</Compile>
<Compile Include="UI\Procedures\IProcParamsCtrl.cs" />
<Compile Include="UI\Procedures\ProcedureDlg.cs">
<SubType>Form</SubType>
</Compile>
@ -2318,6 +2319,12 @@
<Compile Include="UI\Procedures\ProcedureParamsCtrl.designer.cs">
<DependentUpon>ProcedureParamsCtrl.cs</DependentUpon>
</Compile>
<Compile Include="UI\Procedures\ProcedureParamsMixedCtrl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="UI\Procedures\ProcedureParamsMixedCtrl.Designer.cs">
<DependentUpon>ProcedureParamsMixedCtrl.cs</DependentUpon>
</Compile>
<Compile Include="UI\Procedures\ProceduresCtrl.cs">
<SubType>UserControl</SubType>
</Compile>
@ -2330,6 +2337,7 @@
<Compile Include="UI\Procedures\ProceduresDlg.designer.cs">
<DependentUpon>ProceduresDlg.cs</DependentUpon>
</Compile>
<Compile Include="UI\Procedures\ProviderAndIx.cs" />
<Compile Include="UI\Procedures\TestParamsCtrl.cs">
<SubType>UserControl</SubType>
</Compile>
@ -3327,6 +3335,9 @@
<EmbeddedResource Include="UI\Procedures\ProcedureParamsCtrl.resx">
<DependentUpon>ProcedureParamsCtrl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\Procedures\ProcedureParamsMixedCtrl.resx">
<DependentUpon>ProcedureParamsMixedCtrl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\Procedures\ProceduresCtrl.resx">
<DependentUpon>ProceduresCtrl.cs</DependentUpon>
</EmbeddedResource>

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using Config.Entities;
namespace TBF.UI.Procedures
{
public interface IProcParamsCtrl
{
IList<IParamsProvider> CmpntsParams { get; }
string Name { get; }
void Initialize();
void Unlock();
void RedrawAll();
bool UpdateAll();
}
}

View File

@ -53,7 +53,7 @@ namespace TBF.UI.Procedures
IList<TransitionSequence> transitionSequences;
IList<TestParamsCtrl> testParamsCtrls;
IList<ProcedureParamsCtrl> procedureParamsCtrls;
IList<IProcParamsCtrl> 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<ProcedureParamsCtrl>(); /// Initialize the list
procedureParamsCtrls = new List<IProcParamsCtrl>(); /// 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<IComponent> other = new List<IComponent>();
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()))
{

View File

@ -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<IComponent> selectedCmpnts;
public IList<IParamsProvider> CmpntsParams;
List<IParamsProvider> cmpntsParams;
public IList<IParamsProvider> CmpntsParams { get { return cmpntsParams; } }
int paramsCount;
Control[] editors;
@ -36,7 +37,7 @@ namespace TBF.UI.Procedures
public ProcedureParamsCtrl()
{
InitializeComponent();
CmpntsParams = new List<IParamsProvider>();
cmpntsParams = new List<IParamsProvider>();
}
public ProcedureParamsCtrl(ProcedureDlg parent, IList<IComponent> selectedCmpnts, bool showSensorsColumn)

View File

@ -0,0 +1,65 @@
///
/// Copyright (c) 2020 Sensus Slovensko a.s.
///
namespace TBF.UI.Procedures
{
partial class ProcedureParamsMixedCtrl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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<IComponent> tbfComponents;
List<IParamsProvider> cmpntsParams;
public IList<IParamsProvider> CmpntsParams { get { return cmpntsParams; } }
IList<int> paramCounts;
Control[] editors;
bool unlocked;
public void Unlock() { unlocked = true; }
public ProcedureParamsMixedCtrl()
{
InitializeComponent();
cmpntsParams = new List<IParamsProvider>();
paramCounts = new List<int>();
}
public ProcedureParamsMixedCtrl(ProcedureDlg parent, IList<IComponent> 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<string> 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;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -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;
}
}
}