180 lines
5.4 KiB
C#
180 lines
5.4 KiB
C#
///
|
|
/// Copyright (c) 2020 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using Config.Entities;
|
|
using Common.Forms;
|
|
using TBF.Rig.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++)
|
|
{
|
|
ICollection<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;
|
|
}
|
|
}
|
|
}
|