C2025-023 - Electronic Procedures - Modifications to PROMS

Working on Adding functionality for EP input for tables #2
This commit is contained in:
Matthew Schill 2025-04-25 15:07:29 -04:00
parent 6db9567eb9
commit 62ae81c7b3
3 changed files with 91 additions and 41 deletions

View File

@ -98,12 +98,15 @@ namespace Volian.Controls.Library
// //
this.dataview.AllowUserToAddRows = false; this.dataview.AllowUserToAddRows = false;
this.dataview.AllowUserToDeleteRows = false; this.dataview.AllowUserToDeleteRows = false;
this.dataview.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataview.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataview.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataview.ColumnHeadersVisible = false; this.dataview.ColumnHeadersVisible = false;
this.dataview.Location = new System.Drawing.Point(3, 73); this.dataview.Location = new System.Drawing.Point(3, 73);
this.dataview.Name = "dataview"; this.dataview.Name = "dataview";
this.dataview.Size = new System.Drawing.Size(240, 150); this.dataview.Size = new System.Drawing.Size(316, 150);
this.dataview.TabIndex = 5; this.dataview.TabIndex = 5;
this.dataview.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataview_CellEndEdit);
// //
// lbltitle // lbltitle
// //

View File

@ -11,34 +11,48 @@ using System.Windows.Forms;
namespace Volian.Controls.Library namespace Volian.Controls.Library
{ {
//C2025-023 Electronic Procedures
//Control for designating which cells in a table require EP input
public partial class TablePropertiesControl : UserControl public partial class TablePropertiesControl : UserControl
{ {
//defines the type of possible inputs from an EP viewer
public enum EPinputtype
{
none,
textbox,
checkbox
};
private DataTable values; private DataTable values;
private BindingSource bindingSource = null; private BindingSource bindingSource = null;
private int totalrows = 1; private int totalrows = 1;
private int totalcols = 1; private int totalcols = 1;
public readonly string epname;
private bool IsInitializing;
//initialization / data will be: //initialization / data will be in the format:
// totalnumrows,totalnumcols;(row,col):value|(row,col):value... // totalnumrows,totalnumcols;(row,col):value|(row,col):value...
public TablePropertiesControl(string title, string initialvalues) public TablePropertiesControl(string name, string title, string initialvalues)
{ {
InitializeComponent(); InitializeComponent();
IsInitializing = true;
epname = name;
lbltitle.Text = title; lbltitle.Text = title;
initializevalues(initialvalues); initializevalues(initialvalues);
bindingSource = new BindingSource(); bindingSource = new BindingSource(values, "");
bindingSource.DataSource = values;
dataview.DataSource = bindingSource; dataview.DataSource = bindingSource;
dataview.AutoGenerateColumns = false; dataview.AutoGenerateColumns = false;
Load += new EventHandler(FormLoad_setDefaults); Load += new EventHandler(FormLoad_setDefaults);
} }
//initialization / data will be: //initialization / data will be in the format:
// totalnumrows,totalnumcols;(row,col):value|(row,col):value... // totalnumrows,totalnumcols;(row,col):value|(row,col):value...
private void initializevalues(string initialvalues) private void initializevalues(string initialvalues)
{ {
values = new DataTable(); values = new DataTable("values");
if (!string.IsNullOrEmpty(initialvalues)) if (!string.IsNullOrEmpty(initialvalues))
{ {
@ -51,7 +65,7 @@ namespace Volian.Controls.Library
//(row,col):value //(row,col):value
foreach (string pair in ivs) foreach (string pair in ivs)
{ {
Match m = Regex.Match(pair, @"\(([\d]),([\d])\):([\w])"); Match m = Regex.Match(pair, @"\(([\d]),([\d])\):([\w]+)");
if (m.Success) if (m.Success)
{ {
int row = int.Parse(m.Groups[1].Value); int row = int.Parse(m.Groups[1].Value);
@ -61,6 +75,8 @@ namespace Volian.Controls.Library
} }
} }
values.AcceptChanges();
} }
else else
{ {
@ -74,23 +90,11 @@ namespace Volian.Controls.Library
totalrows = numrows; totalrows = numrows;
totalcols = numcols; totalcols = numcols;
BindingSource bindingSourceDropDown = new BindingSource();
bindingSourceDropDown.DataSource = Enum.GetNames(typeof(EPinputtype));
var cName = new DataGridViewComboBoxColumn();
cName.DataSource = bindingSourceDropDown;
//foreach (string n in Enum.GetNames(typeof(EPinputtype))) cName.Items.Add(n);
cName.DefaultCellStyle.NullValue = "none";
for (int c = 0; c < totalcols; c++) for (int c = 0; c < totalcols; c++)
{ {
dataview.Columns.Add(cName); values.Columns.Add(new DataColumn($"Column{c}") { DefaultValue = "none" });
values.Columns.Add();
//dataview.Columns[c].CellTemplate = new DataGridViewComboBoxCell() { DataSource = bindingSourceDropDown };
} }
//values.Columns.Add(new DataColumn() { DefaultValue = "none" });
for (int rw = 0; rw < totalrows; rw++) for (int rw = 0; rw < totalrows; rw++)
{ {
values.Rows.Add(); values.Rows.Add();
@ -103,22 +107,50 @@ namespace Volian.Controls.Library
BindingSource bindingSourceDropDown = new BindingSource(); BindingSource bindingSourceDropDown = new BindingSource();
bindingSourceDropDown.DataSource = Enum.GetNames(typeof(EPinputtype)); bindingSourceDropDown.DataSource = Enum.GetNames(typeof(EPinputtype));
var cName = new DataGridViewComboBoxColumn(); //in order to achieve a dropdown of possible values need
cName.DataSource = bindingSourceDropDown; //to remove the auto-inserted columns
cName.DefaultCellStyle.NullValue = "none"; //that were auto-generated of type type text
//when values was bound to the datagrid
for (int c = 0; c < totalcols; c++) for (int c = 0; c < totalcols; c++)
{ {
dataview.Columns.RemoveAt(c); dataview.Columns.RemoveAt(c);
var cName = new DataGridViewComboBoxColumn();
cName.DataSource = bindingSourceDropDown;
cName.DefaultCellStyle.NullValue = "none";
dataview.Columns.Insert(c, cName); dataview.Columns.Insert(c, cName);
} }
NumRows.Value = totalrows;
NumCols.Value = totalcols;
IsInitializing = false;
setDataViewtoValues();
}
//set the display cells to match the values in the datatable for initialization
//and resize of the dataviewgrid
void setDataViewtoValues()
{
if (!IsInitializing)
{
for (int c = 0; c < totalcols; c++)
{
for (int rw = 0; rw < totalrows; rw++)
{
dataview.Rows[rw].Cells[c].Value = values.Rows[rw][c];
}
}
}
} }
//Get storage string for storing table values in db //Get storage string for storing table values in db
// data will be: // data will be returned in the format:
// totalnumrows,totalnumcols;(row,col):value|(row,col):value... // totalnumrows,totalnumcols;(row,col):value|(row,col):value...
public string GetStorageValue() public string GetStorageValue()
{ {
//force any in progress editing to commit.
((BindingSource)dataview.DataSource).EndEdit();
StringBuilder bldr = new StringBuilder(); StringBuilder bldr = new StringBuilder();
bldr.Append($"{totalrows},{totalcols}"); bldr.Append($"{totalrows},{totalcols}");
List<string> points = new List<string>(); List<string> points = new List<string>();
@ -160,6 +192,7 @@ namespace Volian.Controls.Library
} }
totalrows = endNumRows; totalrows = endNumRows;
setDataViewtoValues();
} }
private void NumCols_ValueChanged(object sender, EventArgs e) private void NumCols_ValueChanged(object sender, EventArgs e)
@ -170,10 +203,6 @@ namespace Volian.Controls.Library
BindingSource bindingSourceDropDown = new BindingSource(); BindingSource bindingSourceDropDown = new BindingSource();
bindingSourceDropDown.DataSource = Enum.GetNames(typeof(EPinputtype)); bindingSourceDropDown.DataSource = Enum.GetNames(typeof(EPinputtype));
var cName = new DataGridViewComboBoxColumn();
cName.DataSource = bindingSourceDropDown;
cName.DefaultCellStyle.NullValue = "none";
//remove cols till equal //remove cols till equal
while (curNumCols > endNumCols) while (curNumCols > endNumCols)
{ {
@ -184,24 +213,28 @@ namespace Volian.Controls.Library
//add cols till equal //add cols till equal
while (curNumCols < endNumCols) while (curNumCols < endNumCols)
{ {
values.Columns.Add(new DataColumn() { DefaultValue = "none"}); values.Columns.Add(new DataColumn($"Column{curNumCols + 1}") { DefaultValue = "none"});
if (dataview.Columns.Count > curNumCols) dataview.Columns.RemoveAt(curNumCols); if (dataview.Columns.Count > curNumCols) dataview.Columns.RemoveAt(curNumCols);
var cName = new DataGridViewComboBoxColumn();
cName.DataSource = bindingSourceDropDown;
cName.DefaultCellStyle.NullValue = "none";
dataview.Columns.Add(cName); dataview.Columns.Add(cName);
curNumCols++; curNumCols++;
} }
totalcols = endNumCols; totalcols = endNumCols;
setDataViewtoValues();
} }
public enum EPinputtype //set the datatable value to match the changed datagridview value
//for some reason despite being bound, does not automatically update
// (it may be that datatable as a bindingsource does not implement INotifyProperty
// and thus needs manually set like this)
private void dataview_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{ {
none, values.Rows[e.RowIndex][e.ColumnIndex] = (string) dataview.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
textbox, }
checkbox
};
} }
} }

View File

@ -25,6 +25,7 @@ namespace Volian.Controls.Library
private Dictionary<string, ComboBox> _DicComboBox; private Dictionary<string, ComboBox> _DicComboBox;
private Dictionary<string, ComboBox> _DicSingleRO; private Dictionary<string, ComboBox> _DicSingleRO;
private Dictionary<string, ListBoxMulti> _DicMultiRO; private Dictionary<string, ListBoxMulti> _DicMultiRO;
private TablePropertiesControl _TablePropControl;
private string multiseparator = ","; private string multiseparator = ",";
@ -150,10 +151,13 @@ namespace Volian.Controls.Library
panelEP.Controls.Add(lb, 1, panelEP.RowCount - 1); panelEP.Controls.Add(lb, 1, panelEP.RowCount - 1);
} }
if (EP.type.ToLower() == "tableinput") //note will allow only 1 tableproperties control since it is a 1:1 match with the table that is in the step
if (EP.type.ToLower() == "tableinput" && _TablePropControl == null)
{ {
TablePropertiesControl tp = new TablePropertiesControl(EP.text, null); string val = MyConfig.GetValue("EP", EP.name);
panelEP.Controls.Add(tp, 1, panelEP.RowCount - 1); _TablePropControl = new TablePropertiesControl(EP.name, EP.text, val);
_TablePropControl.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
panelEP.Controls.Add(_TablePropControl, 1, panelEP.RowCount - 1);
} }
@ -265,6 +269,16 @@ namespace Volian.Controls.Library
MyConfig.SetValue("EP", EP.name, newvalues); MyConfig.SetValue("EP", EP.name, newvalues);
} }
} }
else if (EP.type.ToLower() == "tableinput" && EP.name == _TablePropControl.epname)
{
string newvalues = _TablePropControl.GetStorageValue();
string oldvalues = MyConfig.GetValue("EP", EP.name);
if (newvalues != oldvalues)
{
isDirty = true;
MyConfig.SetValue("EP", EP.name, newvalues);
}
}
} }
if (isDirty) if (isDirty)
{ {