253 lines
6.3 KiB
C#
253 lines
6.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using VEPROMS.CSLA.Library;
|
|
|
|
namespace Volian.Controls.Library
|
|
{
|
|
public partial class DisplayRO : UserControl
|
|
{
|
|
#region Properties
|
|
private ROFST _CurROFST = null;
|
|
private ROFST _MyROFST;
|
|
public ROFST MyROFST
|
|
{
|
|
get { return _MyROFST; }
|
|
set
|
|
{
|
|
if (!Visible) return; // don't reset anything if the form is invisible.
|
|
_MyROFST = value; // define the tree nodes based on this rofst
|
|
LoadTree();
|
|
}
|
|
}
|
|
private string _CurROLink;
|
|
public string CurROLink
|
|
{
|
|
get { return _CurROLink; }
|
|
set
|
|
{
|
|
if (!Visible) return; // don't reset anything if the form is invisible.
|
|
if (value != null) // modify - set the controls to the current ro
|
|
{
|
|
if (_CurROLink == value) return;
|
|
_CurROLink = value;
|
|
UpdateROTree();
|
|
_SavCurROLink = _CurROLink;
|
|
}
|
|
else // insert - clear out controls
|
|
{
|
|
_CurROLink = value;
|
|
tbROValue.Text = null;
|
|
tvROFST.SelectedNode = null;
|
|
}
|
|
}
|
|
}
|
|
private string _SavCurROLink;
|
|
private StepRTB _MyRTB;
|
|
public StepRTB MyRTB
|
|
{
|
|
get { return _MyRTB; }
|
|
set
|
|
{
|
|
if (!Visible) return;
|
|
if (_MyRTB != null)
|
|
_MyRTB.LinkChanged -= new StepRTBLinkEvent(_MyRTB_LinkChanged);
|
|
if (value == null) return;
|
|
_MyRTB = value;
|
|
_MyRTB.LinkChanged += new StepRTBLinkEvent(_MyRTB_LinkChanged);
|
|
if (_MyRTB.MyLinkText == null)
|
|
{
|
|
_CurROLink = null;
|
|
}
|
|
}
|
|
}
|
|
void _MyRTB_LinkChanged(object sender, StepPanelLinkEventArgs args)
|
|
{
|
|
if (_MyRTB.MyLinkText == null)
|
|
CurROLink = null;
|
|
else
|
|
{
|
|
CurROLink = args.RoUsageid;
|
|
}
|
|
}
|
|
#endregion
|
|
#region Constructors
|
|
public DisplayRO()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
#endregion
|
|
#region Events
|
|
private void tvROFST_AfterSelect(object sender, TreeViewEventArgs e)
|
|
{
|
|
if (e.Node.Tag is ROFST.rochild)
|
|
{
|
|
ROFST.rochild chld = (ROFST.rochild)e.Node.Tag;
|
|
if (chld.type == 1 && chld.value != null) tbROValue.Text = chld.value;
|
|
else tbROValue.Text = null;
|
|
}
|
|
else
|
|
tbROValue.Text = null;
|
|
}
|
|
|
|
private void tvROFST_BeforeExpand(object sender, TreeViewCancelEventArgs e)
|
|
{
|
|
LoadChildren(e.Node);
|
|
}
|
|
private void LoadChildren(TreeNode tn)
|
|
{
|
|
object tag = tn.Tag;
|
|
if (tn.FirstNode != null && tn.FirstNode.Text != "VLN_DUMMY_FOR_TREE") return; // already loaded.
|
|
if (tn.FirstNode != null && tn.FirstNode.Text == "VLN_DUMMY_FOR_TREE") tn.FirstNode.Remove();
|
|
ROFST.rochild[] chld = null;
|
|
|
|
if (tn.Tag is ROFST.rodbi)
|
|
{
|
|
ROFST.rodbi db = (ROFST.rodbi)tn.Tag;
|
|
chld = db.children;
|
|
}
|
|
else if (tn.Tag is ROFST.rochild)
|
|
{
|
|
ROFST.rochild ch = (ROFST.rochild)tn.Tag;
|
|
chld = ch.children;
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("error - no type");
|
|
return;
|
|
}
|
|
// if children, add dummy node
|
|
if (chld != null && chld.Length > 0)
|
|
{
|
|
for (int i = 0; i < chld.Length; i++)
|
|
{
|
|
TreeNode tmp = null;
|
|
// if this is a group, i.e. type 0, add a dummy node
|
|
if (chld[i].type == 0 && chld[i].children == null)
|
|
//skip it.
|
|
// TODO: KBR how to handle this?
|
|
//Console.WriteLine("ro junk");
|
|
continue;
|
|
else if (chld[i].type == 1 && chld[i].value == null)
|
|
{
|
|
tmp = new TreeNode(chld[i].title);
|
|
tmp.Tag = chld[i];
|
|
tn.Nodes.Add(tmp);
|
|
TreeNode sub = new TreeNode("VLN_DUMMY_FOR_TREE");
|
|
tmp.Nodes.Add(sub);
|
|
}
|
|
else
|
|
{
|
|
tmp = new TreeNode(chld[i].title);
|
|
tmp.Tag = chld[i];
|
|
tn.Nodes.Add(tmp);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private void LoadTree()
|
|
{
|
|
if (_MyROFST == null) return;
|
|
if (_MyROFST == _CurROFST) return;
|
|
tvROFST.Nodes.Clear();
|
|
_CurROFST = _MyROFST;
|
|
for (int i = 0; i < _MyROFST.myHdr.myDbs.Length; i++)
|
|
{
|
|
TreeNode tn = new TreeNode(_MyROFST.myHdr.myDbs[i].dbiTitle);
|
|
tn.Tag = _MyROFST.myHdr.myDbs[i];
|
|
tvROFST.Nodes.Add(tn);
|
|
AddDummyGroup(_MyROFST.myHdr.myDbs[i], tn);
|
|
}
|
|
}
|
|
private void AddDummyGroup(ROFST.rodbi rodbi, TreeNode tn)
|
|
{
|
|
if (rodbi.children != null && rodbi.children.Length > 0)
|
|
{
|
|
TreeNode tmp = new TreeNode("VLN_DUMMY_FOR_TREE");
|
|
tn.Nodes.Add(tmp);
|
|
}
|
|
}
|
|
private void UpdateROTree()
|
|
{
|
|
// walk down from root of tree, expanding values in the string
|
|
// that represents the ro link.
|
|
string tmpstr = _CurROLink;
|
|
int sp = tmpstr.IndexOf(" "); // because parse of ro info is wrong!!
|
|
int rousageid = System.Convert.ToInt32(tmpstr.Substring(0, sp));
|
|
string roid = tmpstr.Substring(sp + 1, tmpstr.Length - sp - 1);
|
|
string db = roid.Substring(0, 4);
|
|
|
|
ROFST.rochild rochld = MyROFST.GetRoChild(roid.Substring(0, 12).ToUpper());
|
|
// use this to walk up tree until database - this is used to expand tree.
|
|
List<int> path = new List<int>();
|
|
int myid = rochld.ID;
|
|
while (myid > 0)
|
|
{
|
|
path.Insert(0,myid);
|
|
myid = rochld.ParentID;
|
|
rochld = MyROFST.GetRoChildFromID(myid);
|
|
if (rochld.ID == -1) myid = -1;
|
|
}
|
|
TreeNode tnExpand = null;
|
|
int titm = System.Convert.ToInt32(db);
|
|
// find database first
|
|
foreach (TreeNode tn in tvROFST.Nodes)
|
|
{
|
|
ROFST.rodbi thisdb = (ROFST.rodbi)tn.Tag;
|
|
if (thisdb.dbiID == titm)
|
|
{
|
|
LoadChildren(tn);
|
|
tnExpand = tn;
|
|
break;
|
|
}
|
|
}
|
|
if (tnExpand == null) return; // something went wrong?
|
|
// use the path id list to load/find the treeview's nodes.
|
|
foreach (int citm in path)
|
|
{
|
|
if (citm != System.Convert.ToInt32(db))
|
|
{
|
|
LoadChildren(tnExpand);
|
|
tnExpand.Expand();
|
|
foreach (TreeNode tn in tnExpand.Nodes)
|
|
{
|
|
ROFST.rochild chld = (ROFST.rochild)tn.Tag;
|
|
if (chld.ID == citm)
|
|
{
|
|
tnExpand = tn;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (tnExpand != null) tvROFST.SelectedNode = tnExpand;
|
|
}
|
|
private void btnSaveRO_Click(object sender, EventArgs e)
|
|
{
|
|
if (tbROValue.Text == null || tbROValue.Text == "")
|
|
{
|
|
MessageBox.Show("Must select an RO Value from the tree.");
|
|
return;
|
|
}
|
|
Object obj = tvROFST.SelectedNode.Tag;
|
|
if (obj is ROFST.rochild)
|
|
{
|
|
ROFST.rochild roch = (ROFST.rochild) obj;
|
|
string linktxt = string.Format("#Link:ReferencedObject: #xx {0}", roch.roid);
|
|
_MyRTB.InsertRO(tbROValue.Text, linktxt);
|
|
}
|
|
}
|
|
private void btnCancelRO_Click(object sender, EventArgs e)
|
|
{
|
|
_CurROLink = _SavCurROLink;
|
|
UpdateROTree();
|
|
}
|
|
#endregion
|
|
}
|
|
}
|