private void refreshToolStripMenuItem_refresh_Click(object sender, EventArgs e) { var tag = ((sender as ToolStripItem).Owner as ContextMenuStrip).Tag; if (tag != null) { var tab_page = tag as TabPage; var control = (tab_page.Tag as DBObjectControl); DBObjectManager.Refresh(control.DBObject); control.RefreshDisplay(); } }
private void ShowNode(TreeNode node, bool refresh = false, bool open = true) { if (node == null) { return; } if (node.Tag is DBObject) { if (((node.Tag as DBObject).State == DBObject.DBObjectState.None || refresh)) { DBObjectManager.Refresh((node.Tag as DBObject)); //only refresh when needed or forced var db_obj = (node.Tag as IGenerateTreeNode); node.Nodes.Clear(); foreach (TreeNode n in db_obj.GetTree().Nodes) { node.Nodes.Add(n); } IconizeTreeNodes(node); AttachTreeNodesContextMenus(node); } //else //{ // if(node.Tag is IContainsColumns) //refresh tables if their columns collection is empty // { // if ((node.Tag as IContainsColumns).Columns.Count == 0) // { // (node.Tag as IRefreshableObject).Refresh(); // } // } //} } UpdatePropertyGrid(node.Tag); if (node.Tag is DBObject) { if (refresh || open) { var childForm = CreateNewForm(node.Tag as DBObject); //update the details view of the object if (refresh) { //add tab childForm.RefreshDisplay(); } } } if (node.Tag is IGenerateTreeNode) { //reload nodes /*var db_obj = (node.Tag as IGenerateTreeNode); * * node.Nodes.Clear(); * foreach (TreeNode n in db_obj.GetTree().Nodes) * node.Nodes.Add(n);*/ } }
private void refresh_grids() { if (DBObject != null) { //get selected record DBObjectManager.Refresh(DBObject); var column_permissions_sql = string.Format(@" declare @actual table (role_name nvarchar(100), [column] nvarchar(100), [permission_name] nvarchar(100), [permission_state] nvarchar(100)) insert @actual SELECT [role_name] = roleprinc.[name] COLLATE SQL_Latin1_General_CP1_CI_AS, [column] = c.name, [permission_name] = perm.[permission_name] COLLATE SQL_Latin1_General_CP1_CI_AS, [permission_state] = perm.[state_desc] COLLATE SQL_Latin1_General_CP1_CI_AS FROM sys.database_principals roleprinc join sys.database_permissions perm ON perm.[grantee_principal_id] = roleprinc.[principal_id] join sys.objects o on perm.major_id = o.object_id join sys.schemas s on o.schema_id = s.schema_id join sys.columns c on c.object_id = o.object_id and perm.minor_id = c.column_id where roleprinc.principal_id <> 0 and s.name = N'{0}' and o.name = N'{1}' and roleprinc.name = '{2}' select * from ( select * from @actual union all select [role_name] = roleprinc.[name], [column] = c.name, p.permission_name, s.permission_state from sys.database_principals roleprinc cross join (values('SELECT'),('UPDATE')) p(permission_name) cross join (values('REVOKE')) s(permission_state) cross join (select c.name from sys.columns c where object_schema_name(c.object_id) = N'{0}' and object_name(c.object_id) = N'{1}') c where roleprinc.type = 'R' and roleprinc.is_fixed_role = 0 and roleprinc.principal_id <> 0 and roleprinc.name + c.name + p.permission_name not in(select role_name + [column] + permission_name from @actual) and roleprinc.name = '{2}' ) t order by [role_name], [column], [permission_name] ", DBObject.Schema.Name, DBObject.Name, Role.Name); this.column_permissions = this.DBObject.Connection.GetDataTable(column_permissions_sql).AsEnumerable().Select(x => new DBColumnPermission { DBColumn = (this.DBObject as IContainsColumns).Columns.Where(c => c.Name == x["column"].ToString()).FirstOrDefault(), Role = Role, //roles.Where(r => r.Name == x["role_name"].ToString()).FirstOrDefault(), PermissionName = (DBColumnPermission.PermissionNames)Enum.Parse(typeof(DBColumnPermission.PermissionNames), x["permission_name"].ToString().Replace(" ", "_"), true), Grant = x["permission_state"].ToString().Equals("GRANT"), Deny = x["permission_state"].ToString().Equals("DENY"), State = EngineManager.DBObject.DBObjectState.Intact } ).ToList(); } //columns select permissions dataGridView_columns_select.AutoGenerateColumns = false; dataGridView_columns_select.DataSource = new BindingSource(column_permissions.Where(p => p.Role == listBox_roles.SelectedValue as DBRole && p.PermissionName == DBColumnPermission.PermissionNames.Select).ToList(), null); //columns update permissions dataGridView_columns_update.AutoGenerateColumns = false; dataGridView_columns_update.DataSource = new BindingSource(column_permissions.Where(p => p.Role == listBox_roles.SelectedValue as DBRole && p.PermissionName == DBColumnPermission.PermissionNames.Update).ToList(), null); }