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 _DicStepRtb; private Dictionary _DicCheckBox; private Dictionary _DicComboBox; private Dictionary _DicSingleRO; public frmEPAnnotationDetails(AnnotationInfo currAnn) { InitializeComponent(); _DicStepRtb = new Dictionary(); _DicCheckBox = new Dictionary(); _DicComboBox = new Dictionary(); _DicSingleRO = new Dictionary(); 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); string val = MyConfig.GetValue("EP", EP.name); if (val != null && val != "") cmb.SelectedItem = val; _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; cmb.DisplayMember = "Value"; cmb.ValueMember = "Key"; Dictionary tmps = EP.getROList(currAnn); //foreach (var t in tmps) // cmb.Items.Add(t); tmps.Add(-1, ""); cmb.DataSource = new BindingSource(tmps, null); string val = MyConfig.GetValue("EP", EP.name); if (val != null && val != "" && int.TryParse(val, out int n)) cmb.SelectedValue = n; else cmb.SelectedValue = -1; //cmb.SelectedItem = null; _DicSingleRO.Add(EP.name, cmb); panelEP.Controls.Add(cmb, 1, panelEP.RowCount - 1); } } } 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); // C2020-001: added 'false' // compare to original and if different, save in proc config. 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 != oldval) { isDirty = true; MyConfig.SetValue("EP", EP.name, newval); } } } 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; } } } }