// 初始化: 把xml中的信息填入treeview int InitialRights(XmlNode parentXmlNode, TreeNode parentTreeNode) { // 服务器节点特殊 if (parentTreeNode.ImageIndex == ResTree.RESTYPE_SERVER) { string strName = DomUtil.GetAttr(parentXmlNode, "name"); NodeInfo nodeinfo = null; nodeinfo = (NodeInfo)parentTreeNode.Tag; if (nodeinfo == null) { nodeinfo = new NodeInfo(); nodeinfo.TreeNode = parentTreeNode; parentTreeNode.Tag = nodeinfo; } nodeinfo.NodeState |= NodeState.Account | NodeState.Object; nodeinfo.DefElement = parentXmlNode.Name; nodeinfo.DefName = strName; nodeinfo.Rights = DomUtil.GetAttrDiff(parentXmlNode, "rights"); } for(int i=0;i<parentXmlNode.ChildNodes.Count;i++) { XmlNode childXmlNode = parentXmlNode.ChildNodes[i]; if (childXmlNode.NodeType != XmlNodeType.Element) continue; string strName = DomUtil.GetAttr(childXmlNode, "name"); int nType = 0; bool bExpandable = false; // 数据库 if (childXmlNode.Name == "database") { nType = ResTree.RESTYPE_DB; bExpandable = true; } // 目录 if (childXmlNode.Name == "dir") { nType = ResTree.RESTYPE_FOLDER; bExpandable = true; } // 文件 if (childXmlNode.Name == "file") { nType = ResTree.RESTYPE_FILE; bExpandable = true; } TreeNode childTreeNode = FindTreeNode(parentTreeNode, strName); NodeInfo nodeinfo = null; // 没有找到 if (childTreeNode == null) { // 新创建一个,但是标注为未使用的 childTreeNode = new TreeNode(strName, nType, nType); nodeinfo = new NodeInfo(); nodeinfo.TreeNode = childTreeNode; nodeinfo.Expandable = bExpandable; nodeinfo.NodeState |= NodeState.Account; childTreeNode.Tag = nodeinfo; childTreeNode.ForeColor = ControlPaint.LightLight(childTreeNode.ForeColor); // 灰色 parentTreeNode.Nodes.Add(childTreeNode); } else // 找到 { nodeinfo = (NodeInfo)childTreeNode.Tag; if (nodeinfo == null) { nodeinfo = new NodeInfo(); nodeinfo.TreeNode = childTreeNode; childTreeNode.Tag = nodeinfo; } nodeinfo.NodeState |= NodeState.Account | NodeState.Object; } nodeinfo.DefElement = childXmlNode.Name; nodeinfo.DefName = strName; nodeinfo.Rights = DomUtil.GetAttrDiff(childXmlNode, "rights"); if (nodeinfo.Rights == "" || nodeinfo.Rights == null) childTreeNode.ForeColor = SystemColors.GrayText; // ControlPaint.LightLight(nodeNew.ForeColor); else childTreeNode.ForeColor = SystemColors.WindowText; // 递归 InitialRights(childXmlNode, childTreeNode); } return 0; }
public static string GetNodeStateString(NodeInfo nodeinfo) { string strState = ""; if ((nodeinfo.NodeState & NodeState.Account) == NodeState.Account) strState = "帐户定义"; if ((nodeinfo.NodeState & NodeState.Object) == NodeState.Object) { if (strState != "") strState += ","; strState = "对象"; } return strState; }
// 递归 public int Fill(TreeNode node) { TreeNodeCollection children = null; if (node == null) { children = this.Nodes; } else { children = node.Nodes; } int i; // 填充根 if (node == null) { children.Clear(); TreeNode nodeNew = new TreeNode(this.ServerUrl, ResTree.RESTYPE_SERVER, ResTree.RESTYPE_SERVER); ResTree.SetLoading(nodeNew); NodeInfo nodeinfo = new NodeInfo(); nodeinfo.TreeNode = nodeNew; nodeinfo.Expandable = true; nodeinfo.DefElement = GetDefElementString(nodeNew.ImageIndex); nodeinfo.NodeState |= NodeState.Object; nodeNew.Tag = nodeinfo; if (EnabledIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false) nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor); children.Add(nodeNew); return 0; } // 根以下的节点类型 ResPath respath = new ResPath(node); string strPath = respath.Path; //if (node != null) // strPath = TreeViewUtil.GetPath(node); this.channel = Channels.GetChannel(this.ServerUrl); Debug.Assert(channel != null, "Channels.GetChannel() 异常"); ResInfoItem [] items = null; string strError = ""; DigitalPlatform.Stop stop = null; if (stopManager != null) { stop = new DigitalPlatform.Stop(); stop.Register(this.stopManager, true); // 和容器关联 stop.OnStop += new StopEventHandler(this.DoStop); stop.Initial("正在列目录: " + this.ServerUrl + "?" + strPath); stop.BeginLoop(); } long lRet = channel.DoDir(strPath, this.Lang, null, // 不需要列出全部语言的名字 out items, out strError); if (stopManager != null) { stop.EndLoop(); stop.OnStop -= new StopEventHandler(this.DoStop); stop.Initial(""); stop.Unregister(); // 和容器关联 } this.channel = null; if (lRet == -1) { try { MessageBox.Show(this, "Channel::DoDir() Error: " + strError); } catch { // this可能已经不存在 return -1; } if (node != null) { ResTree.SetLoading(node); // 出错的善后处理,重新出现+号 node.Collapse(); } return -1; } if (items != null) { children.Clear(); for(i=0;i<items.Length;i++) { // 忽略from类型节点 if (items[i].Type == ResTree.RESTYPE_FROM) continue; TreeNode nodeNew = new TreeNode(items[i].Name, items[i].Type, items[i].Type); NodeInfo nodeinfo = new NodeInfo(); nodeinfo.TreeNode = nodeNew; nodeinfo.Expandable = items[i].HasChildren; nodeinfo.DefElement = GetDefElementString(nodeNew.ImageIndex); nodeinfo.NodeState |= NodeState.Object; nodeinfo.Style = items[i].Style; nodeNew.Tag = nodeinfo; if (items[i].HasChildren) ResTree.SetLoading(nodeNew); if (EnabledIndices != null && StringUtil.IsInList(nodeNew.ImageIndex, EnabledIndices) == false) nodeNew.ForeColor = ControlPaint.LightLight(nodeNew.ForeColor); children.Add(nodeNew); } } return 0; }