using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using System.Text.RegularExpressions; using VEPROMS.CSLA.Library; namespace Volian.Controls.Library { public partial class DisplayTransition : UserControl { #region Properties private bool _CurProcSet = true; public bool CurProcSet { get { return _CurProcSet; } set { _CurProcSet = value; } } private bool _Modify = false; public bool Modify { get { return _Modify; } set { _Modify = value; } } private int _TranFmtIndx = -1; private ItemInfo _CurItem; public ItemInfo CurItem { get { return _CurItem; } set { _CurItem = value; infotabTransitionFillIn(); } } private VETreeNode _RangeNode1; private ItemInfo _tranitem1; private ItemInfo _tranitem2; private DisplayRTB _MyRTB; public DisplayRTB MyRTB { get { return _MyRTB; } set { _MyRTB = value; } } private ItemInfo _CurrentProcedure; private int _CurrentProcIndex; #endregion #region Constructors public DisplayTransition(ItemInfo curitm, bool modify, DisplayRTB rtb) { _Modify = modify; _CurItem = curitm; _MyRTB = rtb; InitializeComponent(); infotabTransitionFillIn(); } public DisplayTransition() { InitializeComponent(); } public DisplayTransition(ItemInfo curitm, string curtran, bool modify, DisplayRTB rtb) { _Modify = modify; _CurItem = curitm; ParseModifyLink(curtran); _MyRTB = rtb; InitializeComponent(); infotabTransitionFillIn(); } private void ParseModifyLink(string linktext) { Match m = Regex.Match(linktext, ".*[#]Link:([A-Za-z]*):(.*)"); _TranFmtIndx = Convert.ToInt32(m.Groups[2].Value.Split(" ".ToCharArray())[0]); int transitionID = Convert.ToInt32(m.Groups[2].Value.Split(" ".ToCharArray())[1]); Transition mytran = Transition.Get(transitionID); int itm1 = Convert.ToInt32(m.Groups[2].Value.Split(" ".ToCharArray())[2]); _tranitem1 = ItemInfo.Get(itm1); if (m.Groups[1].Value == "TransitionRange") { int itm2 = Convert.ToInt32(m.Groups[2].Value.Split(" ".ToCharArray())[3]); _tranitem2 = ItemInfo.Get(itm2); } // determine if current item & the transition point item are in the same set. // if different sets, different controls are displayed. DocVersion dv = CurItem.MyProcedure.ActiveParent as DocVersion; if (dv == null) return; // what to do if null? DocVersion dvto = _tranitem1.MyProcedure.ActiveParent as DocVersion; if (dvto == null) return; // what to do if null? if (dv.VersionID != dvto.VersionID) CurProcSet = false; else CurProcSet = true; cbCurProcSet.Checked = CurProcSet; } #endregion #region LoadControlData // infotabTransitionFillIn uses other methods to fill in all controls on the // insert/modify transition tab. private bool _InitializingTrans; private void infotabTransitionFillIn() { if (_CurItem == null) return; btnTranInsert.Text = "Select Transition"; _InitializingTrans = true; if (_RangeNode1!= null) _RangeNode1.BackColor = tvTran.BackColor; // first see if transition is within same set, i.e. if modify then check // if current item is in same set as transition to item. If not modify, // initialize is always setting to within current set. This is important // because different controls are used for same (list view) versus different // set (tree view). if (!CurProcSet) { return; } listBoxTranFmtFillIn(); // if new, use CurItem to find the section level & procedure level, // if modify, use the first transition to, _tranitem1 ItemInfo tmpitm = Modify?_tranitem1:CurItem; ItemInfo selstpitm = tmpitm; while (tmpitm.MyContent.Type >= 20000) { tmpitm = tmpitm.MyParent; } ItemInfo secitm = tmpitm; listBoxTranSectsFillIn(secitm, secitm.ItemID); ItemInfo prcitm = secitm.MyParent; _CurrentProcedure = prcitm; listBoxTranProcsFillIn(prcitm); tvTranFillIn(selstpitm); _InitializingTrans = false; } private void listBoxTranFmtFillIn() { TransTypeList ttl = _CurItem.ActiveFormat.PlantFormat.FormatData.TransData.TransTypeList; listBoxTranFmt.Items.Clear(); for (int i = 0; i < ttl.Count; i++) listBoxTranFmt.Items.Add(ttl[i].TransFormat); if (!_Modify) listBoxTranFmt.SelectedIndex = 0; else listBoxTranFmt.SelectedIndex = _TranFmtIndx; } private void tvTranFillIn(ItemInfo startitm) { tvTran.Nodes.Clear(); // if the transition to point is a section or procedure, just return if (startitm.MyContent.Type < 20000) return; // For the tree view, use parent, unless already at HLS. If at HLS, use this level. ItemInfo selitm = startitm; if (!startitm.IsHigh) { startitm = startitm.MyParent; selitm = startitm; } startitm = startitm.FirstSibling; while (startitm != null) { VETreeNode tvn = new VETreeNode(startitm); tvn.Tag = startitm; int active = this.tvTran.Nodes.Add(tvn); //new VETreeNode(curitm)); if (startitm.ItemID == selitm.ItemID) tvTran.SelectedNode = tvTran.Nodes[active]; startitm = (startitm.NextItemCount > 0 ? startitm.NextItems[0] : null); } tvTran.BeforeExpand += new TreeViewCancelEventHandler(tvTran_BeforeExpand); } private void listBoxTranSectsFillIn(ItemInfo secitm, int sectstart) { listBoxTranSects.Items.Clear(); // if the transition point 'to' is a procedure, don't list sections yet. if (secitm.MyContent.Type < 10000) return; // if sectstart is not -1, then use this as the section to select, otherwise // use the id for the item passed in. int startitm = sectstart; if (sectstart < 0) sectstart = secitm.ItemID; ItemInfo selitm = secitm; // this is the selected 'section' secitm = secitm.FirstSibling; while (secitm != null) { int active = listBoxTranSects.Items.Add(secitm); if (secitm.ItemID == sectstart) listBoxTranSects.SelectedIndex = active; secitm = (secitm.NextItemCount > 0 ? secitm.NextItems[0] : null); } } private void listBoxTranProcsFillIn(ItemInfo prcitm) { listBoxTranProcs.Items.Clear(); ItemInfo selitm = prcitm; // this is the selected 'section' prcitm = prcitm.FirstSibling; while (prcitm != null) { int active = listBoxTranProcs.Items.Add(prcitm); if (_CurrentProcedure.ContentID == prcitm.MyContent.ContentID) _CurrentProcIndex = active; if (prcitm.MyContent.ContentID == selitm.MyContent.ContentID) listBoxTranProcs.SelectedIndex = active; prcitm = (prcitm.NextItemCount > 0 ? prcitm.NextItems[0] : null); } } #endregion #region Events private void listBoxTranFmt_Click(object sender, EventArgs e) { if (_InitializingTrans) return; if (listBoxTranFmt.SelectedIndex == _TranFmtIndx) return; // if resetting format selection, null out the selected transitions. _tranitem1 = null; _tranitem2 = null; if (_RangeNode1 != null) { _RangeNode1.BackColor = tvTran.BackColor; _RangeNode1 = null; } _TranFmtIndx = listBoxTranFmt.SelectedIndex; // Determine, based on selection, i.e. select proc/section and disable associated list boxes if // enum representing the transition restricts the selection. E_TransUI etm = (E_TransUI)_CurItem.ActiveFormat.PlantFormat.FormatData.TransData.TransTypeList[listBoxTranFmt.SelectedIndex].TransUI; // do the procedure list box. (in 16-bit system it was types 0, 3, 5 if ((etm & E_TransUI.ProcMenu) == E_TransUI.ProcMenu) listBoxTranProcs.Enabled = true; else { listBoxTranProcs.SelectedIndex = _CurrentProcIndex > 0 ? _CurrentProcIndex : 0; listBoxTranProcs.Enabled = false; } // in 16-bit system it was types 0, 3, 4, 5 if (((etm & E_TransUI.SectDefault) == E_TransUI.SectDefault) || ((etm & E_TransUI.SectMenuAny) == E_TransUI.SectMenuAny) || ((etm & E_TransUI.SectMenuStep) == E_TransUI.SectMenuStep)) { // find default step section and make it the selected item - then disable from further selection. //listBoxTranSects.SelectedIndex = 1; // TEMP until default step section found. listBoxTranSects.Enabled = true; } else listBoxTranSects.Enabled = false; tvTran.Enabled = true; } private void btnUp1_Click(object sender, EventArgs e) { // if at HLS, don't do anything. ItemInfo curitm = (ItemInfo)((VETreeNode)tvTran.Nodes[0]).VEObject; if (curitm.IsHigh) return; tvTranFillIn(curitm); } private void tvTran_BeforeExpand(object sender, TreeViewCancelEventArgs e) { VETreeNode tn = ((VETreeNode)e.Node); tn.LoadChildren(false); } private void listBoxTranSects_SelectedIndexChanged(object sender, EventArgs e) { if (_InitializingTrans) return; // a different section was selected, if step section, update step list, otherwise, empty // it & disable. ItemInfo secitm = (ItemInfo)listBoxTranSects.SelectedItem; if (!secitm.IsStepSection) { tvTran.Nodes.Clear(); tvTran.Enabled = false; } else { tvTranFillIn(secitm.Steps[0]); tvTran.Enabled = true; } } private void listBoxTranProcs_SelectedIndexChanged(object sender, EventArgs e) { if (_InitializingTrans) return; ItemInfo prcitm = (ItemInfo)listBoxTranProcs.SelectedItem; ProcedureConfig pc = (ProcedureConfig)prcitm.MyConfig; int sectstartid = -1; if (pc != null) sectstartid = System.Convert.ToInt32(pc.SectionStart); IList chldrn = prcitm.GetChildren(); listBoxTranSectsFillIn((ItemInfo)chldrn[0], sectstartid); } private void btnTranInsert_Click(object sender, EventArgs e) { string trantxt = "{Resolved Transition Text}"; string linktxt = null; //int type = (int)(_CurItem.ActiveFormat.PlantFormat.FormatData.TransData.TransTypeList[listBoxTranFmt.SelectedIndex].Type); E_TransUI etm = (E_TransUI)_CurItem.ActiveFormat.PlantFormat.FormatData.TransData.TransTypeList[listBoxTranFmt.SelectedIndex].TransUI; // do the procedure list box. (in 16-bit system it was types 0, 3, 5 if (!((etm & E_TransUI.StepAllowNone) == E_TransUI.StepAllowNone)) // _tranitem1 is set from step tree node. { if (tvTran.SelectedNode==null) { MessageBox.Show("Must 'Select Step' for transition 'to'"); return; } VETreeNode vtn = (VETreeNode)tvTran.SelectedNode; _tranitem1 = (ItemInfo) vtn.VEObject; // is this cast valid? linktxt = string.Format("#Link:Transition: {0} xx {1}", listBoxTranFmt.SelectedIndex, _tranitem1.ItemID); } else if ((etm & E_TransUI.StepLast) == E_TransUI.StepLast) //range { if (_tranitem1==null) { MessageBox.Show("Must 'Select Step' for transition 'to'"); return; } // Get the second item in the range, based on current tree view selection. if (tvTran.SelectedNode == null) { MessageBox.Show("Must 'Select Step' for range transition 'to'"); return; } VETreeNode vtn = (VETreeNode)tvTran.SelectedNode; _tranitem2 = (ItemInfo)vtn.VEObject; // is this cast valid? // Check that the two items are of the below the section type. if (_tranitem1.MyContent.Type < 20000 || _tranitem2.MyContent.Type < 20000) { MessageBox.Show("Must select two items at the step level or below, i.e. no sections, procedures, etc."); return; } linktxt = string.Format("#Link:Transition: {0} xx {1} {2}", listBoxTranFmt.SelectedIndex, _tranitem1.ItemID, _tranitem2.ItemID); } else if ((etm & E_TransUI.SectMenuAny) == E_TransUI.SectMenuAny) { if (tvTran.Enabled == false || _tranitem1.IsAccPages) _tranitem1 = (ItemInfo)listBoxTranSects.SelectedItem; else { VETreeNode vtn = (VETreeNode)tvTran.SelectedNode; _tranitem1 = (ItemInfo)vtn.VEObject; // is this cast valid? } if (_tranitem1==null) { MessageBox.Show("Must 'Select Section' or 'Select Step' for transition 'to'"); return; } // check that item is a valid type based on transition type selected from format, i.e. section versus step, etc. //if (type < 4 && _tranitem1.MyContent.Type < 20000) //{ // MessageBox.Show("Must select a step type item for this transition format type"); // return; //} linktxt = string.Format("#Link:Transition: {0} xx {1}", listBoxTranFmt.SelectedIndex, _tranitem1.ItemID); } _MyRTB.InsertTran(trantxt, linktxt); } #endregion private void tvTran_AfterSelect(object sender, TreeViewEventArgs e) { if (_InitializingTrans) return; if (_RangeNode1 == null) { VETreeNode vtn = (VETreeNode)tvTran.SelectedNode; _tranitem1 = (ItemInfo)vtn.VEObject; // is this cast valid? E_TransUI etm = (E_TransUI)_CurItem.ActiveFormat.PlantFormat.FormatData.TransData.TransTypeList[listBoxTranFmt.SelectedIndex].TransUI; // if this is a range, we'll denote the first 'to' item with color on the // tree view. if ((etm & E_TransUI.StepLast) == E_TransUI.StepLast) { tvTran.SelectedNode.BackColor = Color.Aquamarine; _RangeNode1 = vtn; return; } else { return; } } else { _tranitem2 = (ItemInfo)listBoxTranSects.SelectedItem; if (tvTran.Enabled == false || _tranitem2.IsAccPages) _tranitem2 = (ItemInfo)listBoxTranSects.SelectedItem; else _tranitem2 = (ItemInfo)tvTran.SelectedNode.Tag; } TreeNode tn = tvTran.SelectedNode; tn.BackColor = Color.Aquamarine; } private void tvTran_NodeSelectionChange(object sender, vlnTreeEventArgs args) { if (_InitializingTrans) return; if (_RangeNode1 == null) { VETreeNode vtn = (VETreeNode)tvTran.SelectedNode; _tranitem1 = (ItemInfo)vtn.VEObject; // is this cast valid? E_TransUI etm = (E_TransUI)_CurItem.ActiveFormat.PlantFormat.FormatData.TransData.TransTypeList[listBoxTranFmt.SelectedIndex].TransUI; // if this is a range, we'll denote the first 'to' item with color on the // tree view. if ((etm & E_TransUI.StepLast) == E_TransUI.StepLast) { tvTran.SelectedNode.BackColor = Color.Aquamarine; _RangeNode1 = vtn; return; } else { return; } } } private void tvTran_MouseClick(object sender, MouseEventArgs e) { if (_InitializingTrans) return; if (_RangeNode1 == null) { VETreeNode vtn = (VETreeNode)tvTran.SelectedNode; _tranitem1 = (ItemInfo)vtn.VEObject; // is this cast valid? E_TransUI etm = (E_TransUI)_CurItem.ActiveFormat.PlantFormat.FormatData.TransData.TransTypeList[listBoxTranFmt.SelectedIndex].TransUI; // if this is a range, we'll denote the first 'to' item with color on the // tree view. if ((etm & E_TransUI.StepLast) == E_TransUI.StepLast) { tvTran.SelectedNode.BackColor = Color.Aquamarine; _RangeNode1 = vtn; return; } else { return; } } } } }