293 lines
10 KiB
C#
293 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using VEPROMS.CSLA.Library;
|
|
using Volian.Controls.Library;
|
|
using System.Linq;
|
|
|
|
namespace Volian.Controls.Library
|
|
{
|
|
//C2025-023 - Electronic Procedures - Modifications to PROMS
|
|
//Form for Dynamic Showing of EP detail controls and entry
|
|
public partial class frmEPAnnotationDetails : Form
|
|
{
|
|
private AnnotationInfo _CurrentAnnotation;
|
|
private EPFields myEPFields;
|
|
private AnnotationConfig MyConfig;
|
|
|
|
private StepTabRibbon _MyStepTabRibbon;
|
|
private Dictionary<string, StepRTB> _DicStepRtb;
|
|
private Dictionary<string, CheckBox> _DicCheckBox;
|
|
private Dictionary<string, ComboBox> _DicComboBox;
|
|
private Dictionary<string, ComboBox> _DicSingleRO;
|
|
private Dictionary<string, ListBox> _DicMultiRO;
|
|
|
|
private string multiseparator = ",";
|
|
|
|
public frmEPAnnotationDetails(AnnotationInfo currAnn)
|
|
{
|
|
InitializeComponent();
|
|
_DicStepRtb = new Dictionary<string, StepRTB>();
|
|
_DicCheckBox = new Dictionary<string, CheckBox>();
|
|
_DicComboBox = new Dictionary<string, ComboBox>();
|
|
_DicSingleRO = new Dictionary<string, ComboBox>();
|
|
_DicMultiRO = new Dictionary<string, ListBox>();
|
|
InitializeSpecificControls(currAnn);
|
|
_MyStepTabRibbon = new StepTabRibbon();
|
|
}
|
|
|
|
private void InitializeSpecificControls(AnnotationInfo currAnn)
|
|
{
|
|
_CurrentAnnotation = currAnn;
|
|
myEPFields = _CurrentAnnotation.MyItem.GetValidEPFields(_CurrentAnnotation.TypeID);
|
|
MyConfig = new AnnotationConfig(currAnn.Config);
|
|
|
|
int MaxCharsInLabel = myEPFields.Max(x => x.label.Length);
|
|
//font size 8 - make labels slightly bigger than largest label
|
|
panelEP.ColumnStyles[0].SizeType = SizeType.Absolute;
|
|
panelEP.ColumnStyles[0].Width = (8 * MaxCharsInLabel) + 5;
|
|
|
|
int RowCount = 0;
|
|
foreach (EPField EP in myEPFields)
|
|
{
|
|
RowCount += 1;
|
|
panelEP.RowCount = RowCount;
|
|
panelEP.Top = 20;
|
|
panelEP.RowStyles.Insert(0, new RowStyle(SizeType.AutoSize));
|
|
|
|
Label wlbl = new Label();
|
|
wlbl.Text = EP.label;
|
|
wlbl.Visible = true;
|
|
wlbl.TextAlign = ContentAlignment.MiddleLeft;
|
|
wlbl.Anchor = AnchorStyles.Left | AnchorStyles.Top;
|
|
panelEP.Controls.Add(wlbl, 0, panelEP.RowCount - 1);
|
|
|
|
if (EP.type.ToLower() == "text")
|
|
{
|
|
StepRTB tb = new StepRTB();
|
|
tb.Font = tb.FormatFont = new Font("Arial", 8);
|
|
tb.FieldToEdit = E_FieldToEdit.PSI; //use same right click menu as PSI
|
|
tb.BorderStyle = BorderStyle.FixedSingle;
|
|
//aligning to both left and right stretches the textbox to the width of the form
|
|
tb.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
|
|
tb.Enter += new System.EventHandler(this.FieldStepRTB_Enter);
|
|
|
|
string val = MyConfig.GetValue("EP", EP.name).Replace("\\u8209?", "-");
|
|
DisplayText dt = new DisplayText(val, new VE_Font("Arial", 10, E_Style.None, 12), false);
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.Append(@"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset2 Arial;}");
|
|
sb.Append(@"{\f1\fnil\fcharset0 Arial;}}{\colortbl ;\red255\green0\blue0;}"); //C2017-036 changed to just Arial because Microsoft removed Arial Unicode MS with Word16
|
|
sb.Append(@"\viewkind4\uc1\pard\sl-240\slmult0\fs" + (int)(this.Font.SizeInPoints * 2) + " " + dt.StartText + @"}");
|
|
tb.Rtf = sb.ToString();
|
|
tb.Visible = true;
|
|
tb.Height = EP.numlines * tb.Font.Height + 1 + tb.Margin.Vertical;
|
|
tb.MinimumSize = new Size(0, EP.numlines * tb.Font.Height + 1 + tb.Margin.Vertical);
|
|
if (EP.numlines > 1)
|
|
{
|
|
tb.Multiline = true;
|
|
tb.ScrollBars = RichTextBoxScrollBars.Both;
|
|
}
|
|
|
|
_DicStepRtb.Add(EP.name, tb);
|
|
panelEP.Controls.Add(tb, 1, panelEP.RowCount - 1);
|
|
}
|
|
if (EP.type.ToLower() == "logical")
|
|
{
|
|
CheckBox cb = new CheckBox();
|
|
cb.Text = EP.text;
|
|
cb.Visible = true;
|
|
string val = MyConfig.GetValue("EP", EP.name);
|
|
cb.Checked = val != null && val != "" && val.ToUpper()[0] == 'Y';
|
|
_DicCheckBox.Add(EP.name, cb);
|
|
cb.AutoSize = true;
|
|
panelEP.Controls.Add(cb, 1, panelEP.RowCount - 1);
|
|
}
|
|
if (EP.type.ToLower() == "combo")
|
|
{
|
|
ComboBox cmb = new ComboBox();
|
|
cmb.Visible = true;
|
|
string tmp = EP.text;
|
|
string[] tmps = tmp.Split(",".ToCharArray());
|
|
foreach (string t in tmps) cmb.Items.Add(t.Trim());
|
|
string val = MyConfig.GetValue("EP", EP.name);
|
|
if (val != null && val != "") cmb.SelectedItem = val;
|
|
cmb.DropDownWidth = TextRenderer.MeasureText(tmps.OrderByDescending(x => x.Length).First(), cmb.Font).Width + SystemInformation.VerticalScrollBarWidth;
|
|
cmb.Width = cmb.DropDownWidth;
|
|
_DicComboBox.Add(EP.name, cmb);
|
|
panelEP.Controls.Add(cmb, 1, panelEP.RowCount - 1);
|
|
}
|
|
if (EP.type.ToLower() == "rosingle")
|
|
{
|
|
ComboBox cmb = new ComboBox();
|
|
cmb.Visible = true;
|
|
|
|
List<ROListItem> tmps = EP.getROList(currAnn, true);
|
|
cmb.DisplayMember = "Text";
|
|
cmb.ValueMember = "Value";
|
|
cmb.DataSource = tmps;
|
|
cmb.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
cmb.DropDownWidth = TextRenderer.MeasureText(tmps.OrderByDescending(x => x.Text.Length).First().Text, cmb.Font).Width + SystemInformation.VerticalScrollBarWidth;
|
|
cmb.Width = cmb.DropDownWidth;
|
|
|
|
_DicSingleRO.Add(EP.name, cmb);
|
|
panelEP.Controls.Add(cmb, 1, panelEP.RowCount - 1);
|
|
}
|
|
if (EP.type.ToLower() == "romulti")
|
|
{
|
|
ListBox lb = new ListBox();
|
|
lb.Visible = true;
|
|
|
|
List<ROListItem> tmps = EP.getROList(currAnn, false);
|
|
lb.DisplayMember = "Text";
|
|
lb.ValueMember = "Value";
|
|
|
|
lb.Width = TextRenderer.MeasureText(tmps.OrderByDescending(x => x.Text.Length).First().Text, lb.Font).Width + SystemInformation.VerticalScrollBarWidth;
|
|
lb.SelectionMode = SelectionMode.MultiSimple;
|
|
//lb.IsSynchronizedWithCurrentItem = false;
|
|
|
|
lb.DataSource = tmps;
|
|
_DicMultiRO.Add(EP.name, lb);
|
|
panelEP.Controls.Add(lb, 1, panelEP.RowCount - 1);
|
|
|
|
}
|
|
}
|
|
|
|
Load += new EventHandler(Form1Load_setDefaults);
|
|
}
|
|
|
|
void Form1Load_setDefaults(object sender, EventArgs e)
|
|
{
|
|
foreach (KeyValuePair<string, ComboBox> pair in _DicSingleRO)
|
|
{
|
|
string val = MyConfig.GetValue("EP", pair.Key);
|
|
if (val != null && val != "" && int.TryParse(val, out int n))
|
|
pair.Value.SelectedValue = n;
|
|
else
|
|
pair.Value.SelectedValue = -1;
|
|
}
|
|
|
|
foreach (KeyValuePair<string, ListBox> pair in _DicMultiRO)
|
|
{
|
|
pair.Value.ClearSelected();
|
|
string val = MyConfig.GetValue("EP", pair.Key);
|
|
if (val != null && val != "")
|
|
{
|
|
var selectedvalues = val.Split(multiseparator.ToCharArray());
|
|
foreach (string item in selectedvalues)
|
|
if (int.TryParse(item, out int n))
|
|
{
|
|
string text = ((List<ROListItem>)pair.Value.DataSource).First(x => x.Value == n).Text;
|
|
pair.Value.SetSelected(pair.Value.FindString(text), true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void FieldStepRTB_Enter(object sender, EventArgs e)
|
|
{
|
|
_MyStepTabRibbon.MyStepRTB = (StepRTB)sender;
|
|
}
|
|
private void btnOk_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
// loop through all of the fields
|
|
bool isDirty = false;
|
|
foreach (EPField EP in myEPFields)
|
|
{
|
|
if (EP.type.ToLower() == "text")
|
|
{
|
|
StepRTB cur = _DicStepRtb[EP.name];
|
|
string rtf = cur.Rtf;
|
|
string newval = DisplayText.StaticStripRtfCommands(rtf, false);
|
|
string oldval = MyConfig.GetValue("EP", EP.name);
|
|
if (oldval != newval)
|
|
{
|
|
isDirty = true;
|
|
MyConfig.SetValue("EP", EP.name, newval.Replace("\\u8209?","-"));
|
|
}
|
|
}
|
|
else if (EP.type.ToLower() == "logical")
|
|
{
|
|
CheckBox cur = _DicCheckBox[EP.name];
|
|
string newval = cur.Checked ? "Y" : "N";
|
|
string oldval = MyConfig.GetValue("EP", EP.name);
|
|
if (newval != oldval)
|
|
{
|
|
isDirty = true;
|
|
MyConfig.SetValue("EP", EP.name, newval);
|
|
}
|
|
}
|
|
else if (EP.type.ToLower() == "combo")
|
|
{
|
|
ComboBox cmbcur = _DicComboBox[EP.name];
|
|
string newval = cmbcur.Text;
|
|
string oldval = MyConfig.GetValue("EP", EP.name);
|
|
if (newval != oldval)
|
|
{
|
|
isDirty = true;
|
|
MyConfig.SetValue("EP", EP.name, newval);
|
|
}
|
|
}
|
|
else if (EP.type.ToLower() == "rosingle")
|
|
{
|
|
ComboBox cmbcur = _DicSingleRO[EP.name];
|
|
string newval = cmbcur.SelectedValue.ToString();
|
|
string oldval = MyConfig.GetValue("EP", EP.name);
|
|
if (newval == "-1") newval = "";
|
|
if (newval != oldval)
|
|
{
|
|
isDirty = true;
|
|
MyConfig.SetValue("EP", EP.name, newval);
|
|
}
|
|
}
|
|
else if (EP.type.ToLower() == "romulti")
|
|
{
|
|
ListBox lbcur = _DicMultiRO[EP.name];
|
|
string newvalues = String.Join(multiseparator, lbcur.SelectedItems.OfType<ROListItem>().Select(item => item.Value));
|
|
string oldvalues = MyConfig.GetValue("EP", EP.name);
|
|
if (newvalues != oldvalues)
|
|
{
|
|
isDirty = true;
|
|
MyConfig.SetValue("EP", EP.name, newvalues);
|
|
}
|
|
}
|
|
}
|
|
if (isDirty)
|
|
{
|
|
using (Annotation annotation = _CurrentAnnotation.Get())
|
|
{
|
|
if (annotation != null)
|
|
{
|
|
annotation.Config = MyConfig.ToString();
|
|
annotation.DTS = DateTime.Now;
|
|
annotation.UserID = Volian.Base.Library.VlnSettings.UserID;
|
|
annotation.Save();
|
|
}
|
|
}
|
|
}
|
|
DialogResult = DialogResult.OK;
|
|
Close();
|
|
}
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
Close();
|
|
}
|
|
|
|
//remove events so no memory loss
|
|
private void frmEPAnnotationDetails_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
foreach (StepRTB tb in _DicStepRtb.Values)
|
|
{
|
|
tb.Enter -= FieldStepRTB_Enter;
|
|
}
|
|
|
|
Load -= Form1Load_setDefaults;
|
|
}
|
|
}
|
|
} |