private TableNode CreateTableNode(Table table)
        {
            TableNode node = new TableNode(table);

            node.ContextMenuStrip = tableContextMenu;

            TreeNodeController controller = new TreeNodeController();

            controller.Populate += delegate { AddColumns(node); };
            controller.Refresh  += delegate { table.Refresh(); Unpopulate(node); };
            controller.Tag       = table;
            node.Tag             = controller;

            return(node);
        }
        private void AddColumns(TableNode node)
        {
            try {
                treeView.BeginUpdate();

                foreach (Column column in node.Table.Columns)
                {
                    TreeNode columnNode = CreateColumnNode(column);
                    node.Nodes.Add(columnNode);
                }
                if (node.Table.Triggers.Count > 0)
                {
                    TreeNode triggers = node.Nodes.Add("Triggers");
                    triggers.SelectedImageKey = triggers.ImageKey = "folder";
                    foreach (Trigger trigger in node.Table.Triggers)
                    {
                        TreeNode triggerNode = CreateTriggerNode(trigger);
                        triggers.Nodes.Add(triggerNode);
                    }
                }
                if (node.Table.ForeignKeys.Count > 0)
                {
                    TreeNode keys = node.Nodes.Add("Foreign Keys");
                    keys.SelectedImageKey = keys.ImageKey = "folder";
                    foreach (ForeignKey key in node.Table.ForeignKeys)
                    {
                        TreeNode keyNode = CreateKeyNode(key);
                        keyNode.ContextMenuStrip = this.foreignKeyMenuStrip;
                        keys.Nodes.Add(keyNode);
                    }
                }
                if (node.Table.Indexes.Count > 0)
                {
                    var indexes = node.Nodes.Add("Indexes");
                    indexes.SelectedImageKey = indexes.ImageKey = "folder";
                    foreach (var index in node.Table.Indexes)
                    {
                        var indexNode = CreateTreeNode(index.Name, index.IsPrimaryKey ? "primaryKey" : "index", null);
                        indexNode.Tag = new TreeNodeController(index);
                        indexes.Nodes.Add(indexNode);
                    }
                }
            } catch (DbException ex) {
                MessageBox.Show(ex.Message);
            } finally {
                treeView.EndUpdate();
            }
        }
Exemple #3
0
        private void AddColumns(TableNode node)
        {
            try {
                treeView.BeginUpdate();

                foreach (Column column in node.Table.Columns)
                {
                    TreeNode columnNode = CreateColumnNode(column);
                    node.Nodes.Add(columnNode);
                }
                if (node.Table.Triggers.Count > 0)
                {
                    TreeNode triggers = node.Nodes.Add("Triggers");
                    triggers.SelectedImageKey = triggers.ImageKey = "folder";
                    foreach (Trigger trigger in node.Table.Triggers)
                    {
                        TreeNode triggerNode = CreateTriggerNode(trigger);
                        triggers.Nodes.Add(triggerNode);
                    }
                }
                if (node.Table.ForeignKeys.Count > 0)
                {
                    TreeNode keys = node.Nodes.Add("Foreign Keys");
                    keys.SelectedImageKey = keys.ImageKey = "folder";
                    foreach (ForeignKey key in node.Table.ForeignKeys)
                    {
                        TreeNode keyNode = CreateKeyNode(key);
                        keyNode.ContextMenuStrip = this.foreignKeyMenuStrip;
                        keys.Nodes.Add(keyNode);
                    }
                }
            } catch (DbException ex) {
                MessageBox.Show(ex.Message);
            } finally {
                treeView.EndUpdate();
            }
        }
        private void AddTables(DatabaseNode node)
        {
            node.Nodes.Clear();
            node.RunAsyncOperation("expanding",
                                   delegate
            {
                if (!node.Database.IsConnected)
                {
                    node.Database.Connect();
                }
                foreach (var table in node.Database.Tables)
                {
                    break;
                }
            },
                                   delegate
            {
                if (!node.Database.IsConnected)
                {
                    return;
                }
                node.SetImage(true);
                Cursor normal   = treeView.Cursor;
                treeView.Cursor = Cursors.WaitCursor;

                try {
                    treeView.BeginUpdate();
                    TreeNode views = null;
                    foreach (Table table in node.Database.Tables)
                    {
                        TableNode tableNode = CreateTableNode(table);
                        tableNode.Nodes.Add(String.Empty);
                        if (table.IsView)
                        {
                            if (views == null)
                            {
                                views = CreateFolderNode("Views");
                            }
                            views.Nodes.Add(tableNode);
                        }
                        else
                        {
                            node.Nodes.Add(tableNode);
                        }
                    }
                    if (views != null)
                    {
                        node.Nodes.Add(views);
                    }
                    if (node.Database.SupportStoredProcedures)
                    {
                        node.Nodes.Add(CreateStoredProceduresFolderNode(node.Database));
                    }
                    if (node.Database.SupportUserDefinedFunctions)
                    {
                        node.Nodes.Add(CreateUserDefinedFunctionsFolderNode(node.Database));
                    }
                } catch (Exception ex) {
                    MessageBox.Show(this, ex.Message, this.ProductName);
                    node.Nodes.Clear();
                } finally {
                    treeView.EndUpdate();
                    treeView.Cursor = normal;
                    node.Expand();
                }
            }, null);
        }