今天在做一个权限管理模块里面,有关权限分配的时候,涉及到重复权限的判断,故以此文记之。
//添加 void btnAdd_Click(object sender, EventArgs e) { if (_dt == null) return; //把选中的权限添加到权限树上 //把选中的权限添加到权限树上 DataRow row, newRow; foreach (TreeNode itemp in TreeViewAllMenu.Nodes) { if (itemp.Checked) //判断是否选中 { row = (DataRow)itemp.Tag; newRow = _dt.NewRow(); newRow["Nodeid"] = row["NodeId"]; newRow["ParentNode"] = row["ParentNode"]; newRow["NodeName"] = row["NodeName"]; newRow["Isendnode"] = row["Isendnode"]; //权限重复判断 string str = "NodeName='" + row["NodeName"] + "'"; //模糊查询 //string str=" id like 's%'"; DataRow[] drws = _dt.Select(str); if (drws.Length > 0) { XtraMessageBox.Show("不能重复添加权限!","系统提示:"); continue; } _dt.Rows.Add(newRow); foreach (TreeNode itemch in itemp.Nodes) { if (itemch.Checked) { row = (DataRow)itemch.Tag; newRow = _dt.NewRow(); newRow["Nodeid"] = row["Nodeid"]; newRow["ParentNode"] = row["ParentNode"]; newRow["NodeName"] = row["NodeName"]; newRow["Isendnode"] = row["Isendnode"]; _dt.Rows.Add(newRow); foreach (TreeNode itemMenu in itemch.Nodes) { if (itemMenu.Checked) { row = (DataRow)itemMenu.Tag; newRow = _dt.NewRow(); newRow["Nodeid"] = row["Nodeid"]; newRow["ParentNode"] = row["ParentNode"]; newRow["NodeName"] = row["NodeName"]; newRow["Isendnode"] = row["Isendnode"]; _dt.Rows.Add(newRow); } } } } } } TreeViewBinding(_dt, TreeViewAlready); }