public static int Build(XmlDocument CfgDom, string strProjectName, out QuickRights quickrights, out string strError) { quickrights = null; strError = ""; string strXPath = "//style[@name='" + strProjectName + "']"; XmlNode parent = CfgDom.DocumentElement.SelectSingleNode(strXPath); if (parent == null) { strError = "名字为 '" + strProjectName + "' 的方案没有找到"; return(-1); } quickrights = new QuickRights(); quickrights.dom = new XmlDocument(); quickrights.dom.LoadXml(parent.OuterXml); return(0); }
// ???????? void ModiRights(List <ObjectInfo> aName, QuickRights quickrights) { List <TreeNode> nodes = new List <TreeNode>(); for (int i = 0; i < aName.Count; i++) { ObjectInfo objectinfo = aName[i]; string strName = objectinfo.Path; // 将名字转换为节点对象指针 TreeNode node = null; if (objectinfo.ImageIndex == ResTree.RESTYPE_SERVER) { node = this.treeView_resRightTree.Nodes[0]; } else { node = TreeViewUtil.GetTreeNode(this.treeView_resRightTree.Nodes[0], strName); } if (node == null) { MessageBox.Show(this, "节点路径 '" + strName + "' 没有找到对应的对象..."); continue; } nodes.Add(node); } ModiRights(nodes, quickrights); }
// 按照预定模式修改一个节点以及以下的全部子节点的权限 void ModiRights(List <TreeNode> nodes, QuickRights quickrights) { quickrights.GetNodeStyle += new GetNodeStyleEventHandle(quickrights_GetNodeStyle); quickrights.SetRights += new SetRightsEventHandle(quickrights_SetRights); try { quickrights.ModiRights(nodes, this.treeView_resRightTree.Nodes[0]); } finally { quickrights.GetNodeStyle -= new GetNodeStyleEventHandle(quickrights_GetNodeStyle); quickrights.SetRights -= new SetRightsEventHandle(quickrights_SetRights); } /* * for (int j = 0; j < quickrights.Count; j++) * { * QuickRightsItem item = quickrights[j]; * * bool bRet = QuickRights.MatchType(parent.ImageIndex, * item.Type); * if (bRet == false) * continue; * * if (item.Style != 0) * { * if (item.Style != ResRightTree.GetNodeStyle(parent)) * continue; * } * * this.treeView_resRightTree.SetNodeRights(parent, * item.Rights); * * } * * * for (int i = 0; i < parent.Nodes.Count; i++) * { * TreeNode node = parent.Nodes[i]; * ModiRights(node, * quickrights); * } */ }
public static int Build(XmlDocument CfgDom, string strProjectName, out QuickRights quickrights, out string strError) { quickrights = null; strError = ""; string strXPath = "//style[@name='" + strProjectName + "']"; XmlNode parent = CfgDom.DocumentElement.SelectSingleNode(strXPath); if (parent == null) { strError = "名字为 '" + strProjectName + "' 的方案没有找到"; return -1; } quickrights = new QuickRights(); quickrights.dom = new XmlDocument(); quickrights.dom.LoadXml(parent.OuterXml); return 0; }
void ModiRights(TreeNode parent, ArrayList aUserName, QuickRights quickrights) { for(int i=0;i<aUserName.Count;i++) { string strUserName = (string)aUserName[i]; this.m_strTempUserName = strUserName; List<TreeNode> nodes = new List<TreeNode>(); nodes.Add(parent); quickrights.GetNodeStyle += new GetNodeStyleEventHandle(quickrights_GetNodeStyle); quickrights.SetRights += new SetRightsEventHandle(quickrights_SetRights); try { quickrights.ModiRights(nodes, this.treeView_objects.Nodes[0]); } finally { quickrights.GetNodeStyle -= new GetNodeStyleEventHandle(quickrights_GetNodeStyle); quickrights.SetRights -= new SetRightsEventHandle(quickrights_SetRights); } /* for (int j = 0; j < quickrights.Count; j++) { QuickRightsItem item = quickrights[j]; bool bRet = QuickRights.MatchType(parent.ImageIndex, item.Type); if (bRet == false) continue; if (item.Style != 0) { if (item.Style != ResRightTree.GetNodeStyle(parent)) continue; } SetRights(TreeViewUtil.GetPath(parent), strUserName, item.Rights); } */ } /* for(int i=0;i<parent.Nodes.Count;i++) { TreeNode node = parent.Nodes[i]; ModiRights(node, aUserName, quickrights); } */ }
// 按照预定模式修改一个节点以及以下的全部子节点的权限 void ModiRights(List<TreeNode> nodes, QuickRights quickrights) { quickrights.GetNodeStyle += new GetNodeStyleEventHandle(quickrights_GetNodeStyle); quickrights.SetRights +=new SetRightsEventHandle(quickrights_SetRights); try { quickrights.ModiRights(nodes, this.treeView_resRightTree.Nodes[0]); } finally { quickrights.GetNodeStyle -= new GetNodeStyleEventHandle(quickrights_GetNodeStyle); quickrights.SetRights -= new SetRightsEventHandle(quickrights_SetRights); } /* for (int j = 0; j < quickrights.Count; j++) { QuickRightsItem item = quickrights[j]; bool bRet = QuickRights.MatchType(parent.ImageIndex, item.Type); if (bRet == false) continue; if (item.Style != 0) { if (item.Style != ResRightTree.GetNodeStyle(parent)) continue; } this.treeView_resRightTree.SetNodeRights(parent, item.Rights); } for (int i = 0; i < parent.Nodes.Count; i++) { TreeNode node = parent.Nodes[i]; ModiRights(node, quickrights); } */ }
// ???????? void ModiRights(List<ObjectInfo> aName, QuickRights quickrights) { List<TreeNode> nodes = new List<TreeNode>(); for (int i = 0; i < aName.Count; i++) { ObjectInfo objectinfo = aName[i]; string strName = objectinfo.Path; // 将名字转换为节点对象指针 TreeNode node = null; if (objectinfo.ImageIndex == ResTree.RESTYPE_SERVER) node = this.treeView_resRightTree.Nodes[0]; else node = TreeViewUtil.GetTreeNode(this.treeView_resRightTree.Nodes[0], strName); if (node == null) { MessageBox.Show(this, "节点路径 '" +strName+ "' 没有找到对应的对象..."); continue; } nodes.Add(node); } ModiRights(nodes, quickrights); }
// 按照预定模式修改一个节点以及以下的全部子节点的权限 void ModiRights(int nFound, List <TreeNode> selectedTreeNodes, TreeNode curtreenode, List <XmlNode> cfgnodes) { for (int i = 0; i < cfgnodes.Count; i++) { // 当前xml节点信息 XmlNode node = cfgnodes[i]; string strType = DomUtil.GetAttr(node, "type"); string strName = DomUtil.GetAttr(node, "name"); string strRights = DomUtil.GetAttrDiff(node, "rights"); int nStyle = QuickRights.GetStyleInt(DomUtil.GetAttr(node, "style")); // 匹配对象名 if (strName != "" && strName != "*") { // @ if (strName != curtreenode.Text) { continue; } } // 匹配对象类型 bool bRet = QuickRights.MatchType(curtreenode.ImageIndex, strType); if (bRet == false) { continue; } // 匹配对象风格 if (nStyle != 0) { if (this.GetNodeStyle == null) { // 缺省行为 /* * if (nStyle != ResRightTree.GetNodeStyle(curtreenode)) * continue; */ } else { GetNodeStyleEventArgs e = new GetNodeStyleEventArgs(); e.Node = curtreenode; e.Style = 0; this.GetNodeStyle(this, e); if (nStyle != e.Style) { continue; } } } int nIndex = -1; if (nFound == 0) { nIndex = selectedTreeNodes.IndexOf(curtreenode); } // 触发事件 // 如果strRights == null,表示当前对象不需修改其rights值,但是递归仍然要进行 if (strRights != null && (nIndex != -1 || nFound > 0)) { if (this.SetRights != null) { SetRightsEventArgs e = new SetRightsEventArgs(); e.Node = curtreenode; if (strRights == "{clear}" || strRights == "{null}") { e.Rights = null; } else { e.Rights = strRights; } this.SetRights(this, e); } } // DOCHILDREN: // 组织树子对象数组 List <TreeNode> nodes = new List <TreeNode>(); for (int j = 0; j < curtreenode.Nodes.Count; j++) { nodes.Add(curtreenode.Nodes[j]); } // 递归 if (nodes.Count != 0) { List <XmlNode> chidrencfgnodes = new List <XmlNode>(); for (int j = 0; j < node.ChildNodes.Count; j++) { XmlNode cur = node.ChildNodes[j]; if (cur.NodeType != XmlNodeType.Element) { continue; } if (cur.Name != "object") { continue; } chidrencfgnodes.Add(cur); } if (nIndex != -1) { nFound++; } ModiRights(nFound, selectedTreeNodes, nodes, chidrencfgnodes); if (nIndex != -1) { nFound--; } } } }