Exemplo n.º 1
0
        private void DisconnectFromServer(TreeNode serverNode)
        {
            if ((serverNode == null))
            {
                return;
            }

            NodeData data = NodeDataFactory.GetNodeData(serverNode.Tag);

            if (data == null || data.Type != DBObjectType.Server)
            {
                return;
            }

            ConnectionParams cp = data.ConnParams;

            if (!_connections.Keys.Contains(cp.Name))
            {
                return;
            }

            SqlConnection conn = _connections[cp.Name];

            conn.Close();
            conn.Dispose();

            _connections.Remove(cp.Name);
            serverNode.Nodes.Clear();
            tv.Nodes.Remove(serverNode);
        }
Exemplo n.º 2
0
        private bool IsSelectedObjectScriptable()
        {
            if (tv.SelectedNode == null)
            {
                return(false);
            }

            NodeData data = NodeDataFactory.GetNodeData(tv.SelectedNode.Tag);

            if (data == null)
            {
                return(false);
            }

            if (data.Type == DBObjectType.View ||
                data.Type == DBObjectType.Trigger ||
                data.Type == DBObjectType.StoredProc ||
                data.Type == DBObjectType.TableValuedFunction ||
                data.Type == DBObjectType.ScalarValuedFunction
                )
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        private TreeNode AddGroupingFolder(TreeNode parentNode, string name, int nodeType, string dbName, bool addFakeChild, int parentType)
        {
            if ((parentNode == null) || (nodeType != DBObjectType.GroupingFolderB && nodeType != DBObjectType.GroupingFolderY))
            {
                return(null);
            }

            NodeData parentData = NodeDataFactory.GetNodeData(parentNode.Tag);

            if (parentData == null)
            {
                return(AddErrorNode(parentNode.Nodes, name, "Parent data is empty"));
            }


            TreeNode node = AddNode(parentNode.Nodes, name, nodeType);

            if (addFakeChild)
            {
                node.Nodes.Add("...");
            }

            NodeData data = NodeDataFactory.Create(parentData.ConnParams, name, nodeType, dbName);

            data.ConnParams = ((NodeData)parentNode.Tag).ConnParams;
            data.ParentType = parentType;
            data.ID         = parentData.ID;
            node.Tag        = data;

            return(node);
        }
Exemplo n.º 4
0
        private void PopulateDatabase(TreeNode parentNode)
        {
            if (parentNode == null)
            {
                return;
            }

            NodeData parentData = NodeDataFactory.GetNodeData(parentNode.Tag);

            if (parentData == null)
            {
                AddErrorNode(parentNode.Nodes, String.Empty, "Parent node data is null!");
                return;
            }

            TreeNode tblsNode = AddGroupingFolderY(parentNode, FolderType.Tables, parentData.DBName, true, DBObjectType.Database);

            tblsNode.Nodes.Clear();
            AddGroupingFolderY(tblsNode, FolderType.SystemTables, parentData.DBName, true, DBObjectType.Database);
            AddGroupingFolderY(tblsNode, FolderType.UserTables, parentData.DBName, true, DBObjectType.Database);

            AddGroupingFolderY(parentNode, FolderType.Views, parentData.DBName, true, DBObjectType.Database);
            AddGroupingFolderY(parentNode, FolderType.Procedures, parentData.DBName, true, DBObjectType.Database);

            TreeNode fnNode = AddGroupingFolderY(parentNode, FolderType.Functions, parentData.DBName, true, DBObjectType.Database);

            fnNode.Nodes.Clear();
            AddGroupingFolderY(fnNode, FolderType.TableValuedFunctions, parentData.DBName, true, DBObjectType.Database);
            AddGroupingFolderY(fnNode, FolderType.ScalarValuedFunctions, parentData.DBName, true, DBObjectType.Database);
        }
Exemplo n.º 5
0
        private TreeNode AddServerNode(ConnectionParams cp)
        {
            if (cp == null)
            {
                return(null);
            }

            TreeNode node = AddNode(null, cp.Name, DBObjectType.Server);
            NodeData data = NodeDataFactory.Create(cp, cp.Name, DBObjectType.Server, String.Empty);

            node.Tag = data;

            return(node);
        }
Exemplo n.º 6
0
        private void OnHelpStatisticsClick(object sender, EventArgs e)
        {
            FireBeforeContextMenuActionExecuted(sender, ObjectExplorerAction.Statistics);

            NodeData data = SelectedNode != null?NodeDataFactory.GetNodeData(SelectedNode.Tag) : null;

            if (data == null)
            {
                return;
            }

            frmScriptEditor editor = CreateScriptEditorForObjectInfo("sp_statistics", "STATISTICS", true, data.Name, data.Owner);

            editor.Icon = global::PragmaSQL.Properties.Resources.Help;
            FireAfterContextMenuActionExecuted(sender, ObjectExplorerAction.Statistics);
        }
Exemplo n.º 7
0
        private void OnHelpForeignKeysClick(object sender, EventArgs e)
        {
            FireBeforeContextMenuActionExecuted(sender, ObjectExplorerAction.ForeignKeys);
            NodeData data = SelectedNode != null?NodeDataFactory.GetNodeData(SelectedNode.Tag) : null;

            if (data == null)
            {
                return;
            }

            string[] parameters = new string[2] {
                String.Format("@fktable_name = N'{0}'", data.Name), String.Format("@fktable_owner = N'{0}'", data.Owner)
            };
            frmScriptEditor editor = CreateScriptEditorForObjectInfo("sp_fkeys ", "FOREIGN_KEYS", true, true, parameters);

            editor.Icon = global::PragmaSQL.Properties.Resources.Help;
            FireAfterContextMenuActionExecuted(sender, ObjectExplorerAction.ForeignKeys);
        }
Exemplo n.º 8
0
        private void PopulateUsers(ConnectionParams cp, TreeNode parentNode)
        {
            if (cp == null || parentNode == null)
            {
                return;
            }

            if (!_connections.Keys.Contains(cp.Name))
            {
                return;
            }

            SqlConnection conn = _connections[cp.Name];

            if (conn.State != ConnectionState.Open)
            {
                throw new InvalidConnectionState("Can not populate users!");
            }

            TreeNode usersNode = AddNode(parentNode.Nodes, FolderType.Users, DBObjectType.UsersGroup);

            usersNode.Nodes.Clear();
            NodeData parentData    = NodeDataFactory.GetNodeData(parentNode.Tag);
            NodeData usersNodeData = NodeDataFactory.Create(parentData.ConnParams, FolderType.Users, DBObjectType.UsersGroup, parentData.DBName);

            usersNodeData.Populated = true;
            usersNode.Tag           = usersNodeData;

            DataTable users = conn.GetSchema("Users");

            users.DefaultView.Sort = "user_name";
            users = users.DefaultView.ToTable();

            foreach (DataRow row in users.Rows)
            {
                string   userName = (string)row["user_name"];
                TreeNode node     = AddNode(usersNode.Nodes, userName, DBObjectType.User);

                NodeData userNodeData = NodeDataFactory.Create(parentData.ConnParams, userName, DBObjectType.User, parentData.DBName);
                userNodeData.Populated = false;

                node.Tag = userNodeData;
            }
        }
Exemplo n.º 9
0
        private frmScriptEditor CreateNewScriptEditor()
        {
            TreeNode node = tv.SelectedNode;

            if (node == null)
            {
                CreateNewConnectionFromRepository(false);
            }

            node = tv.SelectedNode;
            if (node == null)
            {
                return(null);
            }


            NodeData data = NodeDataFactory.GetNodeData(node.Tag);

            if (data == null)
            {
                MessageBox.Show("Can not create connection!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            frmScriptEditor editor = new frmScriptEditor();

            editor.Text    = "Script " + (++_scriptEditorCnt).ToString();
            editor.TabText = editor.Text;

            if (DockPanel.DocumentStyle == DocumentStyles.SystemMdi)
            {
                editor.MdiParent = this;
                editor.Show();
            }
            else
            {
                editor.Show(DockPanel);
            }
            editor.InitializeScriptEditor(String.Empty, DBObjectType.None, data.ConnParams, data.DBName);
            return(editor);
        }
Exemplo n.º 10
0
        private TreeNode TryToAddTriggerGroupingFolder(TreeNode parentNode)
        {
            if (parentNode == null)
            {
                return(null);
            }

            NodeData parentData = NodeDataFactory.GetNodeData(parentNode.Tag);

            if (parentData == null)
            {
                return(null);
            }

            if (!((parentData.Type == DBObjectType.UserTable) ||
                  (parentData.Type == DBObjectType.SystemTable) ||
                  (parentData.Type == DBObjectType.View))
                )
            {
                return(null);
            }


            TreeNode node     = AddGroupingFolderY(parentNode, FolderType.Triggers, parentData.DBName, false, parentData.Type);
            NodeData nodeData = NodeDataFactory.Create(parentData.ConnParams, FolderType.Triggers, DBObjectType.GroupingFolderY, parentData.DBName);

            nodeData.ID = parentData.ID;
            node.Tag    = nodeData;

            if (!PopulateTriggers(node))
            {
                parentNode.Nodes.Remove(node);
                return(null);
            }
            else
            {
                return(node);
            }
        }
Exemplo n.º 11
0
        private void ModifySelectedObjectInScriptWindow()
        {
            TreeNode node = tv.SelectedNode;

            if (node == null)
            {
                return;
            }

            NodeData data = NodeDataFactory.GetNodeData(node.Tag);

            if (data == null)
            {
                MessageBox.Show("Node data not assigned", "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            frmScriptEditor editor = new frmScriptEditor();

            editor.Text    = data.Name;
            editor.TabText = editor.Text;

            if (DockPanel.DocumentStyle == DocumentStyles.SystemMdi)
            {
                editor.MdiParent = this;
                editor.Show();
            }
            else
            {
                editor.Show(DockPanel);
            }

            ProgrammabilityHelper.SqlConn = _connections[data.ConnParams.Name];
            string script = ProgrammabilityHelper.GetObjectCreateScript(data.ID);

            script = ProgrammabilityHelper.ReplaceCreateWithAlter(data.Type, script);

            editor.InitializeScriptEditor(script, data.Type, data.ConnParams, data.DBName);
        }
Exemplo n.º 12
0
        private void OnAnyReferenceClick(object sender, EventArgs e)
        {
            FireBeforeContextMenuActionExecuted(sender, ObjectExplorerAction.References);

            TreeNode node = SelectedNode;

            if (node == null)
            {
                return;
            }
            node = SelectedNode;
            if (node == null)
            {
                return;
            }

            NodeData data = NodeDataFactory.GetNodeData(node.Tag);

            frmObjectReferencesViewer frm = ObjectReferenceViewerFactory.CreateObjectReferencesViewer("References {" + data.Name + "}", data.Name, data.ConnParams, data.DBName, RefDetail.Any, true);

            ObjectReferenceViewerFactory.ShowViewer(frm);
            FireAfterContextMenuActionExecuted(sender, ObjectExplorerAction.References);
        }
Exemplo n.º 13
0
        private void OnAddSerlectedObjectsToGroup(object sender, EventArgs e)
        {
            if (tv.SelNodes.Count == 0)
            {
                return;
            }

            FireBeforeContextMenuActionExecuted(sender, ObjectExplorerAction.AddObjectsToGroup);
            ConnectionParams cp    = null;
            IList <TreeNode> nodes = new List <TreeNode>();

            foreach (MWTreeNodeWrapper nodeWrapper in tv.SelNodes.Values)
            {
                if (cp == null)
                {
                    NodeData data = NodeDataFactory.GetNodeData(nodeWrapper.Node.Tag);
                    cp          = data.ConnParams.CreateCopy();
                    cp.Database = data.DBName;
                }
                nodes.Add(nodeWrapper.Node);
            }
            frmObjGroupDlg.ShowObjectGroupingDlg(cp, nodes, "Add To Object Group");
            FireAfterContextMenuActionExecuted(sender, ObjectExplorerAction.AddObjectsToGroup);
        }
Exemplo n.º 14
0
        private void PopulateObjects(TreeNode parentNode, int nodeType)
        {
            if (parentNode == null)
            {
                return;
            }

            NodeData parentData = NodeDataFactory.GetNodeData(parentNode.Tag);

            if (parentData == null)
            {
                AddErrorNode(parentNode.Nodes, String.Empty, "Parent data is null.");
                return;
            }

            if (!_connections.Keys.Contains(parentData.ConnParams.Name))
            {
                return;
            }

            SqlConnection conn = _connections[parentData.ConnParams.Name];

            if (conn.State != ConnectionState.Open)
            {
                throw new InvalidConnectionState("Can not populate table-valued function!");
            }


            string script = String.Empty;

            switch (nodeType)
            {
            case DBObjectType.UserTable:
                script = global::PragmaSQL.Properties.Resources.Script_GetUserTables;
                break;

            case DBObjectType.SystemTable:
                script = global::PragmaSQL.Properties.Resources.Script_GetSystemTables;
                break;

            case DBObjectType.View:
                script = global::PragmaSQL.Properties.Resources.Script_GetViews;
                break;

            case DBObjectType.StoredProc:
                script = global::PragmaSQL.Properties.Resources.Script_GetStoredProcedures;
                break;

            case DBObjectType.TableValuedFunction:
                script = global::PragmaSQL.Properties.Resources.Script_GetTableValuedFunctions;
                break;

            case DBObjectType.ScalarValuedFunction:
                script = global::PragmaSQL.Properties.Resources.Script_GetScalarValuedFunctions;
                break;

            default:
                AddErrorNode(parentNode.Nodes, String.Empty, String.Format("Invalid object type. \"{0}\" ", nodeType));
                return;
            }

            if (conn.Database.ToLowerInvariant() != parentData.DBName.ToLowerInvariant())
            {
                try
                {
                    conn.ChangeDatabase(parentData.DBName);
                }
                catch (Exception ex)
                {
                    AddErrorNode(parentNode.Nodes, String.Empty, ex.Message);
                    return;
                }
            }

            SqlCommand    cmd      = new SqlCommand(script, conn);
            SqlDataReader reader   = cmd.ExecuteReader();
            int           objCount = 0;

            while (reader.Read())
            {
                string   objName = (string)reader["name"];
                TreeNode node    = AddNode(parentNode.Nodes, objName, nodeType);

                NodeData nodeData = NodeDataFactory.Create(parentData.ConnParams, objName, nodeType, parentData.DBName);
                nodeData.ID = (int)reader["id"];
                nodeData.HasParamsOrCols = true;

                node.Tag = nodeData;
                objCount++;

                AddNode(node.Nodes, "...", -1);
            }

            reader.Close();
            parentData.Populated = true;
            parentNode.Text      = parentData.Name + " (" + objCount.ToString() + ")";
        }
Exemplo n.º 15
0
        private void PopulateDatabases(ConnectionParams cp, TreeNode parentNode)
        {
            if (cp == null || parentNode == null)
            {
                return;
            }

            if (!_connections.Keys.Contains(cp.Name))
            {
                return;
            }

            SqlConnection conn = _connections[cp.Name];

            if (conn.State != ConnectionState.Open)
            {
                throw new InvalidConnectionState("Can not populate databases!");
            }

            NodeData parentData     = NodeDataFactory.GetNodeData(parentNode);
            TreeNode sysDbGroupNode = AddGroupingFolder(parentNode, "System Databases", DBObjectType.GroupingFolderB, true, DBObjectType.Server);

            sysDbGroupNode.Nodes.Clear();

            DataTable dbs = conn.GetSchema("Databases");

            dbs.DefaultView.Sort = "database_name";
            dbs = dbs.DefaultView.ToTable();

            foreach (DataRow row in dbs.Rows)
            {
                string   dbName = (string)row["database_name"];
                TreeNode node   = null;
                if (DBConstants.SystemDbNames.Contains(dbName.ToLowerInvariant()))
                {
                    node = AddNode(sysDbGroupNode.Nodes, dbName, DBObjectType.Database);
                }
                else
                {
                    node = AddNode(parentNode.Nodes, dbName, DBObjectType.Database);
                }

                NodeData data = NodeDataFactory.Create(cp, dbName, DBObjectType.Database, dbName);
                data.Populated = true;
                node.Tag       = data;

                TreeNode tblsNode = AddGroupingFolderY(node, FolderType.Tables, dbName, true, DBObjectType.Database);
                tblsNode.Nodes.Clear();
                AddGroupingFolderY(tblsNode, FolderType.SystemTables, dbName, true, DBObjectType.Database);
                AddGroupingFolderY(tblsNode, FolderType.UserTables, dbName, true, DBObjectType.Database);

                AddGroupingFolderY(node, FolderType.Views, dbName, true, DBObjectType.Database);
                AddGroupingFolderY(node, FolderType.Procedures, dbName, true, DBObjectType.Database);

                TreeNode fnNode = AddGroupingFolderY(node, FolderType.Functions, dbName, true, DBObjectType.Database);
                fnNode.Nodes.Clear();
                AddGroupingFolderY(fnNode, FolderType.TableValuedFunctions, dbName, true, DBObjectType.Database);
                AddGroupingFolderY(fnNode, FolderType.ScalarValuedFunctions, dbName, true, DBObjectType.Database);

                if (cp.InitialCatalog.ToLowerInvariant() == dbName.ToLowerInvariant())
                {
                    node.Expand();
                    tv.SelectedNode = node;
                }
            }
        }
Exemplo n.º 16
0
        private void LoadNodeDataDynamically(TreeNode node, bool forceRefresh)
        {
            if (_tvInitializing)
            {
                return;
            }

            if (node == null)
            {
                return;
            }

            NodeData data = NodeDataFactory.GetNodeData(node.Tag);

            if (data == null)
            {
                return;
            }

            bool oldExpandedState = node.IsExpanded;

            try
            {
                Cursor = Cursors.AppStarting;
                tv.BeginUpdate();
                if (data.Type == DBObjectType.GroupingFolderB || data.Type == DBObjectType.GroupingFolderY)
                {
                    if (data.Populated && !forceRefresh)
                    {
                        return;
                    }

                    if (data.Name == FolderType.SystemTables)
                    {
                        node.Nodes.Clear();
                        PopulateObjects(node, DBObjectType.SystemTable);
                    }
                    else if (data.Name == FolderType.UserTables)
                    {
                        node.Nodes.Clear();
                        PopulateObjects(node, DBObjectType.UserTable);
                    }
                    else if (data.Name == "Views")
                    {
                        node.Nodes.Clear();
                        PopulateObjects(node, DBObjectType.View);
                    }
                    else if (data.Name == FolderType.Procedures)
                    {
                        node.Nodes.Clear();
                        PopulateObjects(node, DBObjectType.StoredProc);
                    }
                    else if (data.Name == FolderType.TableValuedFunctions)
                    {
                        node.Nodes.Clear();
                        PopulateObjects(node, DBObjectType.TableValuedFunction);
                    }
                    else if (data.Name == FolderType.ScalarValuedFunctions)
                    {
                        node.Nodes.Clear();
                        PopulateObjects(node, DBObjectType.ScalarValuedFunction);
                    }
                    else if (data.Name == FolderType.Triggers)
                    {
                        node.Nodes.Clear();
                        PopulateTriggers(node);
                    }
                    else if (data.Name == FolderType.Columns)
                    {
                        node.Nodes.Clear();
                        PopulateParamsAndColumns(node, data.ParentType);
                    }
                    else if (data.Name == FolderType.Parameters)
                    {
                        node.Nodes.Clear();
                        PopulateParamsAndColumns(node, data.ParentType);
                    }
                }
                else if (data.HasParamsOrCols)
                {
                    if (data.Populated && !forceRefresh)
                    {
                        return;
                    }

                    node.Nodes.Clear();
                    TryToAddTriggerGroupingFolder(node);
                    TryToAddObjectFolders(data.Type, node, data);
                }
                else if (data.Type == DBObjectType.Server)
                {
                    if (data.Populated && !forceRefresh)
                    {
                        return;
                    }

                    node.Nodes.Clear();
                    PopulateDatabases(data.ConnParams, node);
                    PopulateUsers(data.ConnParams, node);
                }
                else if (data.Type == DBObjectType.Database)
                {
                    if (data.Populated && !forceRefresh)
                    {
                        return;
                    }
                    node.Nodes.Clear();
                    PopulateDatabase(node);
                }


                if (oldExpandedState)
                {
                    node.Expand();
                }
            }
            finally
            {
                tv.EndUpdate();
                Cursor = Cursors.Default;
            }
        }
Exemplo n.º 17
0
        public void AddObjectFromObjectExplorer(TreeNode source, TreeNode dropNode)
        {
            if (source == null)
            {
                return;
            }

            NodeData sourceData = NodeDataFactory.GetNodeData(source);

            if (sourceData == null)
            {
                return;
            }

            try
            {
                tv.BeginUpdate();
                ObjectGroupingItemData dropData = ObjectGroupingItemDataFactory.GetNodeData(dropNode);

                int?     parentID   = null;
                TreeNode parentNode = null;


                if (dropNode != null && dropData != null)
                {
                    if (dropData.Type == DBObjectType.GroupingFolderY)
                    {
                        parentID   = dropData.ID;
                        parentNode = dropNode;
                    }
                    else
                    {
                        parentID   = dropData.ParentID;
                        parentNode = dropNode.Parent;
                    }
                }

                string tableName = String.Empty;
                if (sourceData.Type == DBObjectType.Trigger)
                {
                    tableName = sourceData.ParentName;
                }


                ObjectGroupingItemData data = ObjectGroupingItemDataFactory.Create(sourceData.Name, sourceData.Type, null, tableName, parentID, _connParams.CurrentUsername);
                try
                {
                    _grpFacade.AddItem(data);
                    AddNode(parentNode, data);
                    if (parentNode != null && !parentNode.IsExpanded)
                    {
                        parentNode.Expand();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            finally
            {
                tv.EndUpdate();
                UpdateSelectedItemInfo();
            }
        }
Exemplo n.º 18
0
        private void PopulateParamsAndColumns(TreeNode parentNode, int nodeType)
        {
            if (parentNode == null)
            {
                return;
            }

            NodeData parentData = NodeDataFactory.GetNodeData(parentNode.Tag);

            if (parentData == null)
            {
                AddErrorNode(parentNode.Nodes, String.Empty, "Parent data is null.");
                return;
            }

            if (!_connections.Keys.Contains(parentData.ConnParams.Name))
            {
                return;
            }

            SqlConnection conn = _connections[parentData.ConnParams.Name];

            if (conn.State != ConnectionState.Open)
            {
                throw new InvalidConnectionState("Can not populate table-valued function!");
            }


            string script = global::PragmaSQL.Properties.Resources.Script_GetColsAndParams;



            if (conn.Database.ToLowerInvariant() != parentData.DBName.ToLowerInvariant())
            {
                try
                {
                    conn.ChangeDatabase(parentData.DBName);
                }
                catch (Exception ex)
                {
                    AddErrorNode(parentNode.Nodes, String.Empty, ex.Message);
                    return;
                }
            }

            SqlCommand   cmd   = new SqlCommand(script, conn);
            SqlParameter param = cmd.Parameters.Add("@id", SqlDbType.Int);

            param.Value = parentData.ID;
            SqlDataReader reader = cmd.ExecuteReader();


            while (reader.Read())
            {
                string pName = (string)reader["name"];

                pName = pName + " [ " + (string)reader["typename"] + " (" + ((short)reader["length"]).ToString() + ") " + "]";

                int type = -1;


                if ((int)reader["isoutparam"] == 1)
                {
                    type = DBObjectType.ParameterOut;
                }
                else if (nodeType == DBObjectType.StoredProc || nodeType == DBObjectType.ScalarValuedFunction || nodeType == DBObjectType.TableValuedFunction)
                {
                    if (nodeType == DBObjectType.TableValuedFunction)
                    {
                        if (parentData.Name == FolderType.Columns)
                        {
                            if (!pName.StartsWith("@"))
                            {
                                type = DBObjectType.ParameterOut;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else if (parentData.Name == FolderType.Parameters)
                        {
                            if (pName.StartsWith("@"))
                            {
                                type = DBObjectType.ParameterOut;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (pName.StartsWith("@"))
                        {
                            type = DBObjectType.ParameterIn;
                        }
                        else
                        {
                            type = DBObjectType.ParameterOut;
                        }
                    }
                }
                else if (nodeType == DBObjectType.UserTable || nodeType == DBObjectType.SystemTable || nodeType == DBObjectType.View)
                {
                    byte status = (byte)reader["status"];
                    if ((status & 128) == 128)
                    {
                        type = DBObjectType.IdentityCol;
                    }
                    else
                    {
                        type = DBObjectType.Column;
                    }
                }

                TreeNode node = AddNode(parentNode.Nodes, pName, type);

                NodeData nodeData = NodeDataFactory.Create(parentData.ConnParams, pName, type, parentData.DBName);
                nodeData.ID = parentData.ID;
                node.Tag    = nodeData;
            }

            reader.Close();
            parentData.Populated = true;
        }
Exemplo n.º 19
0
        private bool PopulateTriggers(TreeNode parentNode)
        {
            if (parentNode == null)
            {
                return(false);
            }

            NodeData parentData = NodeDataFactory.GetNodeData(parentNode.Tag);

            if (parentData == null)
            {
                AddErrorNode(parentNode.Nodes, String.Empty, "Parent data is null.");
                return(false);
            }

            if (!_connections.Keys.Contains(parentData.ConnParams.Name))
            {
                return(false);
            }

            SqlConnection conn = _connections[parentData.ConnParams.Name];

            if (conn.State != ConnectionState.Open)
            {
                throw new InvalidConnectionState("Can not populate table-valued function!");
            }


            string script = global::PragmaSQL.Properties.Resources.Script_GetTriggers;

            if (conn.Database.ToLowerInvariant() != parentData.DBName.ToLowerInvariant())
            {
                try
                {
                    conn.ChangeDatabase(parentData.DBName);
                }
                catch (Exception ex)
                {
                    AddErrorNode(parentNode.Nodes, String.Empty, ex.Message);
                    return(true);
                }
            }

            SqlCommand   cmd   = new SqlCommand(script, conn);
            SqlParameter param = cmd.Parameters.Add("@parentid", SqlDbType.Int);

            param.Value = parentData.ID;

            SqlDataReader reader   = cmd.ExecuteReader();
            int           objCount = 0;

            while (reader.Read())
            {
                string   objName = (string)reader["name"];
                TreeNode node    = AddNode(parentNode.Nodes, objName, DBObjectType.Trigger);

                NodeData nodeData = NodeDataFactory.Create(parentData.ConnParams, objName, DBObjectType.Trigger, parentData.DBName);
                nodeData.ID = (int)reader["id"];

                node.Tag = nodeData;
                objCount++;
            }

            reader.Close();
            parentData.Populated = true;
            parentNode.Text      = parentData.Name + " (" + objCount.ToString() + ")";

            if (objCount == 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 20
0
        private void tv_DragOver(object sender, DragEventArgs e)
        {
            Hashtable sourceNodes = e.Data.GetData(typeof(Hashtable)) as Hashtable;

            if (sourceNodes == null || sourceNodes.Count == 0)
            {
                e.Effect = DragDropEffects.None;
                return;
            }

            TreeNode firstNode = null;

            foreach (TreeNode node in sourceNodes.Values)
            {
                firstNode = node;
                if (firstNode != null)
                {
                    break;
                }
            }

            if (firstNode == null)
            {
                e.Effect = DragDropEffects.None;
                return;
            }

            Point pos = new Point();

            pos.X = e.X;
            pos.Y = e.Y;
            pos   = tv.PointToClient(pos);

            TreeNode dropNode = tv.GetNodeAt(pos);

            if (dropNode == null)
            {
                e.Effect = DragDropEffects.None;
                return;
            }

            // This is an object from ObjectExplorer
            if (firstNode.Tag is NodeData)
            {
                foreach (TreeNode node in sourceNodes.Values)
                {
                    NodeData sourceData = NodeDataFactory.GetNodeData(node);
                    if (sourceData == null || sourceData.ConnParams == null || _connParams == null)
                    {
                        e.Effect = DragDropEffects.None;
                        return;
                    }

                    if (
                        (sourceData.ConnParams.Server.ToLowerInvariant() != _connParams.Server.ToLowerInvariant())
                        ||
                        (sourceData.DBName.ToLowerInvariant() != _connParams.Database.ToLowerInvariant())
                        )
                    {
                        e.Effect = DragDropEffects.None;
                        return;
                    }
                }
                e.Effect = DragDropEffects.Copy;
            }
            // This is a node from own MWTreeView
            else if (firstNode.Tag is ObjectGroupingItemData)
            {
                ObjectGroupingItemData dropData      = ObjectGroupingItemDataFactory.GetNodeData(dropNode);
                ObjectGroupingItemData firstNodeData = ObjectGroupingItemDataFactory.GetNodeData(firstNode);

                if (dropData == null || (firstNodeData.ID == dropData.ParentID || firstNodeData.ID == dropData.ID))
                {
                    e.Effect = DragDropEffects.None;
                    return;
                }

                if (dropData == null || dropData.Type != DBObjectType.GroupingFolderY)
                {
                    e.Effect = DragDropEffects.None;
                    return;
                }

                e.Effect = DragDropEffects.Move;
            }
            // Unknown
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }