private void HandleSelectionChanged(GridListControl gridList) { if (gridList.SelectedIndex < 0) { return; } var role = _listOfRole[gridList.SelectedIndex]; EnabledObject(true); lblRole.Text = "Hak akses : "; if (role != null) { if (IsAdministrator(role.nama_role)) { EnabledObject(false); } lblRole.Text = string.Format("Hak akses : {0}", role.nama_role); IRolePrivilegeBll rolePrivilegeBll = new RolePrivilegeBll(_log); _listOfRolePrivilege = rolePrivilegeBll.GetByRole(role.role_id); foreach (TreeNodeAdv node in treeViewAdv.Nodes) { CheckRecursive(node, false); } } }
private void CheckRecursive(TreeNodeAdv treeNode, bool isSave) { var nodeParent = treeNode.Parent; if (isSave) { if (!base.IsSelectedItem(this.gridList.SelectedIndex, this.Text)) { return; } var obj = _listOfRole[this.gridList.SelectedIndex]; if (nodeParent.Tag != null) { var rolePrivilege = new RolePrivilege { role_id = obj.role_id, menu_id = nodeParent.Tag.ToString(), grant_id = Convert.ToInt32(treeNode.Tag), is_grant = treeNode.CheckState == CheckState.Checked }; IRolePrivilegeBll rolePrivilegeBll = new RolePrivilegeBll(_log); var result = rolePrivilegeBll.Save(rolePrivilege); } } else { treeNode.CheckState = CheckState.Unchecked; if (_listOfRolePrivilege != null) { if (nodeParent.Tag != null) { if (treeNode.Tag != null) { var role = _listOfRole[this.gridList.SelectedIndex]; var rolePrivilege = _listOfRolePrivilege.Where(f => f.role_id == role.role_id && f.menu_id == nodeParent.Tag.ToString() && f.grant_id == Convert.ToInt32(treeNode.Tag)) .SingleOrDefault(); if (rolePrivilege != null) { treeNode.CheckState = rolePrivilege.is_grant ? CheckState.Checked : CheckState.Unchecked; } } } } } // Print each node recursively. foreach (TreeNodeAdv tn in treeNode.Nodes) { CheckRecursive(tn, isSave); } }