protected override bool OnClick(ClickEvent e) { OperationStarted?.Invoke(); Action?.Invoke(); OperationEnded?.Invoke(); return(true); }
protected void TriggerOperationEnded() => OperationEnded?.Invoke();
private void LoadObjects(DbObjectSearch search = null) { try { pbLoading.Visible = true; OperationStarted?.Invoke(this, "Loading objects..."); tvwObjects.BeginUpdate(); tvwObjects.Nodes.Clear(); var schemas = _objects .Where(obj => !string.IsNullOrEmpty(obj.Schema) && (search?.IsIncluded(obj) ?? true)) .GroupBy(obj => obj.Schema).OrderBy(grp => grp.Key); FolderNode folderNode = null; foreach (var schemaGrp in schemas) { var schemaNode = new SchemaNode(schemaGrp.Key, schemaGrp.Count()); tvwObjects.Nodes.Add(schemaNode); var tables = schemaGrp.OfType <Table>().OrderBy(obj => obj.Name); if (tables.Any()) { folderNode = new FolderNode("Tables", tables.Count()); schemaNode.Nodes.Add(folderNode); foreach (var table in tables) { var tableNode = new TableNode(table); if (_aliasManager.ContainsTable(table.ToString(), out string alias)) { tableNode.Alias = alias; } folderNode.Nodes.Add(tableNode); var foreignKeys = table.GetParentForeignKeys(_objects); tableNode.Columns.AddRange(table.Columns.Select(col => { var node = new ColumnNode(col, foreignKeys, table.IdentityColumn); if (IsUniqueMultiColumn(table, col)) { node.NodeFont = new Font(tvwObjects.Font, FontStyle.Bold); } return(node); })); var childFKs = table.GetChildForeignKeys(_objects); if (childFKs.Any()) { var childFolderNode = new TreeNode($"Child Tables ({childFKs.Count()})") { ImageKey = "join", SelectedImageKey = "join" }; tableNode.Nodes.Add(childFolderNode); foreach (var childFK in childFKs) { var fkNode = new TableNode(childFK); childFolderNode.Nodes.Add(fkNode); } } } folderNode.Expand(); } var views = schemaGrp.OfType <SqlSchema.Library.Models.View>().OrderBy(obj => obj.Name); if (views.Any()) { folderNode = new FolderNode("Views", views.Count()); schemaNode.Nodes.Add(folderNode); foreach (var view in views) { var viewNode = new ViewNode(view); folderNode.Nodes.Add(viewNode); } } var functions = schemaGrp.OfType <TableFunction>().OrderBy(obj => obj.Name); if (functions.Any()) { folderNode = new FolderNode("Functions", functions.Count()); schemaNode.Nodes.Add(folderNode); foreach (var func in functions) { var functionNode = new FunctionNode(func); folderNode.Nodes.Add(functionNode); } } var procs = schemaGrp.OfType <Procedure>().OrderBy(obj => obj.Name); if (procs.Any()) { folderNode = new FolderNode("Procedures", procs.Count()); schemaNode.Nodes.Add(folderNode); foreach (var proc in procs) { var procNode = new ProcedureNode(proc); folderNode.Nodes.Add(procNode); } } schemaNode.Expand(); } } finally { tvwObjects.EndUpdate(); pbLoading.Visible = false; OperationEnded?.Invoke(this, new EventArgs()); } }