表A [模块]:
module_id module_name
==========================
1 Articles
2 Suppliers
3 Cash
表B [ModulesOptions]:
moduleoption_id module_id moduleoption_name
====================================================
1 1 New Article
2 1 Edit Article
3 2 New Supplier
4 2 Edit Supplier
5 3 New Invoice
表C [usersprivileges]
user_id moduleoption_id
==========================
1 1
1 3
填充TreeStateView代码:(仅创建父节点和子节点但尚未创建标记)
DataRelation DataRelation = DataSet.Relations.Add("Modules_to_Modules_Options", DataSet.Tables["Modules"].Columns["module_id"], DataSet.Tables["ModulesOptions"].Columns["module_id"]);
foreach (DataRow DataRow in DataSet.Tables["Modules"].Rows)
{
TreeNode TreeNode = new TreeNode();
TreeNode.Text = DataRow["module_name"].ToString();
TreeNode.Tag = DataRow["module_id"].ToString();
TreeNode.StateImageIndex = 0;
TreeNode.Expand();
foreach (DataRow DataRowChild in DataRow.GetChildRows("Modules_to_Modules_Options"))
{
TreeNode TreeNodeChild = new TreeNode();
TreeNodeChild.Text = DataRowChild["moduleoption_name"].ToString();
TreeNodeChild.Tag = DataRowChild["moduleoption_id"].ToString();
TreeNode.Nodes.Add(TreeNodeChild);
}
this.UsersEdit_TreeView_ModulesOptions.Nodes.Add(TreeNode);
}
TreeView控件具有属性Checkboxes = true
每个父节点都有3个状态:
TreeNode.StateImageIndex = 0; // No Checked
TreeNode.StateImageIndex = 1; // Checked
TreeNode.StateImageIndex = 2; // Mixed
我需要根据表(usersprivileges)标记每个父节点(模块)
If (user have all modulesoptions privileges)
{
TreeNode.StateImageIndex = 1; // Checked
} elseif (user have some modulesoptions checked)
{
TreeNode.StateImageIndex = 2; // Mixed
} else {
TreeNode.StateImageIndex = 0; // No Checked
}
根据用户(user_id:1)
+---Articles (Mixed)
| |
| +--------New Article <-- (Checked)
| +--------Edit Article <-- (NO Checked)
|
+---Suppliers (NO Checked)
| |
| +--------New Supplier <-- (NO Checked)
| +--------Edit Supplier <--(NO Checked)
|
+---Cash (Checked)
| |
| +--------New Invoice <-- (Checked)
|