public void BuildTree() { ClearNodes(); if (IsFieldActive() && (Source.DataView.State != DAE.Client.DataSetState.Insert)) { // Open a dynamic navigable browse cursor on the root expression PrepareRootPlan(); IServerCursor cursor = _rootPlan.Open(_rootParams); try { DAE.Runtime.Data.IRow key; int columnIndex; string text; while (cursor.Next()) { key = new DAE.Runtime.Data.Row(_process.ValueManager, new DAE.Schema.RowType(Source.DataView.Order.Columns)); try { using (DAE.Runtime.Data.IRow row = cursor.Select()) { row.CopyTo(key); columnIndex = row.DataType.Columns.IndexOf(ColumnName); if (row.HasValue(columnIndex)) { text = ((DAE.Runtime.Data.Scalar)row.GetValue(columnIndex)).AsDisplayString; } else { text = Strings.Get("NoValue"); } } Nodes.Add(new TreeNode(this, text, key, 0, null)); } catch { key.Dispose(); throw; } } } finally { _rootPlan.Close(cursor); } foreach (TreeNode node in Nodes) { node.BuildChildren(); } SelectNode(Source.DataView.GetKey()); } }
/// <summary> Creates this nodes immediate children. Avoids duplication. </summary> public void BuildChildren() { // Open a dynamic navigable browse cursor on the child expression IServerCursor cursor = Tree.OpenChildCursor(_key); try { DAE.Runtime.Data.Row key; string text; int index = 0; int columnIndex; while (cursor.Next()) { key = new DAE.Runtime.Data.Row(Tree.Process.ValueManager, new RowType(Tree.Source.DataView.Order.Columns)); try { using (DAE.Runtime.Data.IRow row = cursor.Select()) { row.CopyTo(key); columnIndex = row.DataType.Columns.IndexOf(Tree.ColumnName); if (row.HasValue(columnIndex)) { text = ((DAE.Runtime.Data.Scalar)row.GetValue(columnIndex)).AsDisplayString; } else { text = Strings.Get("NoValue"); } } if (FindChild(key) == null) { Nodes.Insert(index, new TreeNode(Tree, text, key, _depth + 1, this)); } index++; } catch { key.Dispose(); throw; } } } finally { Tree.CloseChildCursor(cursor); } }
protected void BuildParentPath(DAE.Runtime.Data.IRow key, ArrayList path) { foreach (DAE.Runtime.Data.Row localKey in path) { if (KeysEqual(key, localKey)) { throw new WebClientException(WebClientException.Codes.TreeViewInfiniteLoop); } } path.Add(key); IServerCursor cursor = OpenParentCursor(key); try { if (cursor.Next()) { key = new DAE.Runtime.Data.Row(_process.ValueManager, new RowType(Source.DataView.Order.Columns)); using (DAE.Runtime.Data.IRow selected = cursor.Select()) selected.CopyTo(key); } else { key = null; } } finally { CloseParentCursor(cursor); } if (key != null) { if (FindChild(key) == null) { BuildParentPath(key, path); } else { path.Add(key); } } }