2008-01-31 14:31:18 +00:00

488 lines
16 KiB
C#

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 int _TranFmtIndx = -1;
private ItemInfo _CurItemFrom;
private TransitionInfo _CurTrans;
public TransitionInfo CurTrans
{
get { return _CurTrans; }
set
{
_CurTrans = value;
if (_CurTrans == null)
{
if (MyRTB == null) return;
_CurItemFrom = MyRTB.MyItem;
ClearControls();
DetermineCurProcSet();
return;
}
_TranFmtIndx = _CurTrans.TranType;
_CurItemFrom = ItemInfo.Get(_CurTrans.FromID);
TransitionFillIn();
}
}
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()
{
InitializeComponent();
}
#endregion
#region LoadControlData
// TransitionFillIn uses other methods to fill in all controls on the
// insert/modify transition tab.
private bool _InitializingTrans;
private void TransitionFillIn()
{
//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, this determines what
// controls & settings are used.
DetermineCurProcSet();
if (!CurProcSet)
return;
else
CurrentProcSetFillIn();
_InitializingTrans = false;
}
private void CurrentProcSetFillIn()
{
ListBoxTranFmtFillIn();
// if new, use _CurItemFrom to find the section level & procedure level,
// if modify, use the first transition to, _CurTrans
//ItemInfo tmpitm = _ToModify!=null?_tranitem1:_CurItem;
ItemInfo tmpitm = _CurTrans==null?_CurItemFrom:_CurTrans.MyItemToID;
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);
SetControlsEnabling();
}
private void DetermineCurProcSet()
{
// If a current transition exists then check if current from item is in same set
// as transition to item. If no current transition (new), initialize to current
// set. Different controls are used for same set (list view) versus different
// set (tree view).
if (_CurTrans != null)
{
DocVersionInfo dv = _CurItemFrom.MyProcedure.ActiveParent as DocVersionInfo;
if (dv == null) return; // what to do if null?
DocVersionInfo dvto = _CurTrans.MyItemToID.MyProcedure.ActiveParent as DocVersionInfo;
if (dv.VersionID != dvto.VersionID) CurProcSet = false;
else CurProcSet = true;
cbCurProcSet.Checked = CurProcSet;
}
else
CurProcSet = cbCurProcSet.Checked;
}
private void ListBoxTranFmtFillIn()
{
TransTypeList ttl = _CurItemFrom.ActiveFormat.PlantFormat.FormatData.TransData.TransTypeList;
listBoxTranFmt.Items.Clear();
for (int i = 0; i < ttl.Count; i++)
listBoxTranFmt.Items.Add(ttl[i].TransFormat);
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 (_CurTrans == null)
{
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);
}
}
private void SetControlsEnabling()
{
if (CurProcSet)
{
groupPanelTranFmt.Visible = true;
groupPanelTransitionProcs.Visible = true;
groupPanelTransitionSect.Visible = true;
groupPanelTranstionSteps.Visible = true;
groupPanelProcSets.Visible = false;
tvProcSets.Visible = false;
// Determine, based on selection, i.e. select proc/section and disable associated list boxes if
// enum representing the transition restricts the selection.
if (_CurItemFrom == null) return;
int indx = listBoxTranFmt.SelectedIndex;
if (listBoxTranFmt.SelectedIndex < 0 || listBoxTranFmt.SelectedIndex > listBoxTranFmt.Items.Count) indx = 0;
E_TransUI etm = (E_TransUI)_CurItemFrom.ActiveFormat.PlantFormat.FormatData.TransData.TransTypeList[indx].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;
}
else
{
groupPanelTranFmt.Visible = false;
groupPanelTransitionProcs.Visible = false;
groupPanelTransitionSect.Visible = false;
groupPanelTranstionSteps.Visible = false;
groupPanelProcSets.Visible = true;
tvProcSets.Visible = true;
tvProcSets.Dock = DockStyle.Top;
return;
}
}
private void ClearControls()
{
listBoxTranFmt.Items.Clear();
listBoxTranProcs.Items.Clear();
listBoxTranSects.Items.Clear();
tvTran.Nodes.Clear();
_TranFmtIndx = 0;
}
#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;
SetControlsEnabling();
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)_CurItemFrom.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)_CurItemFrom.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)_CurItemFrom.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)_CurItemFrom.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 btnNewTrans_Click(object sender, EventArgs e)
{
_CurItemFrom = _MyRTB.MyItem;
_CurTrans = null;
_TranFmtIndx = 0;
TransitionFillIn();
}
private void LoadProcSetTree()
{
VETreeNode tn = VETreeNode.GetFolder(1);
tvProcSets.Nodes.Add(tn);
tn.LoadChildren(true);
tvProcSets.BeforeExpand += new TreeViewCancelEventHandler(tvProcSet_BeforeExpand);
}
private void tvProcSet_BeforeExpand(object sender, TreeViewCancelEventArgs e)
{
VETreeNode tn = ((VETreeNode)e.Node);
tn.LoadChildren(true);
}
private void cbCurProcSet_CheckedChanged(object sender, EventArgs e)
{
CurProcSet = cbCurProcSet.Checked;
if (!CurProcSet && tvProcSets.Nodes.Count == 0) LoadProcSetTree();
SetControlsEnabling();
}
}
}