コード例 #1
0
ファイル: ucObjectGrouping.cs プロジェクト: Eisai/pragmasql
        private void DeleteItem(TreeNode node)
        {
            ObjectGroupingItemData data = ObjectGroupingItemDataFactory.GetNodeData(node);

            if (node == null || data == null)
            {
                return;
            }

            try
            {
                tv.BeginUpdate();
                _grpFacade.DeleteItem(data);

                node.Nodes.Clear();
                TreeNodeCollection parentNodeCol = null;
                if (node.Parent == null)
                {
                    parentNodeCol = tv.Nodes;
                }
                else
                {
                    parentNodeCol = node.Parent.Nodes;
                }
                parentNodeCol.Remove(node);
            }
            finally
            {
                tv.EndUpdate();
            }
        }
コード例 #2
0
        private void AddObjectToGroup()
        {
            TreeNode selNode = og.SelectedNode;

            if (selNode == null)
            {
                ShowError("Please select an object grouping folder!");
                return;
            }

            ObjectGroupingItemData selData = ObjectGroupingItemDataFactory.GetNodeData(selNode);

            if (selData.Type != DBObjectType.GroupingFolderY)
            {
                ShowError("Please select an object grouping folder!");
                return;
            }

            try
            {
                og.AddObjectToGroup(_objInfo, selNode, true);
            }
            catch (Exception ex)
            {
                GenericErrorDialog.ShowError("Object Grouping Error", "Object can not be added to the selected group folder.", ex.Message);
            }

            this.DialogResult = DialogResult.OK;
        }
コード例 #3
0
ファイル: ucObjectGrouping.cs プロジェクト: Eisai/pragmasql
        public void SaveHelpText(bool confirmSave)
        {
            TreeNode selNode = SelectedNode;
            ObjectGroupingItemData selData = ObjectGroupingItemDataFactory.GetNodeData(SelectedNode);

            if (selData == null)
            {
                return;
            }

            if (confirmSave)
            {
                DialogResult dlgRes = MessageBox.Show("Save changes to help text?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dlgRes == DialogResult.No)
                {
                    _helpTextChanged = false;
                    return;
                }
            }

            selData.HelpText = CurrentHelpText;
            try
            {
                _grpFacade.UpdateHelpText(selData);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            UpdateSelectedItemInfo();
            _helpTextChanged = false;
        }
コード例 #4
0
ファイル: ucObjectGrouping.cs プロジェクト: Eisai/pragmasql
        public bool CanOpenSelectedObjects( )
        {
            bool result = false;

            if (tv.SelectedNodes.Count == 0)
            {
                return(result);
            }

            foreach (TreeNode node in tv.SelectedNodes)
            {
                ObjectGroupingItemData data = ObjectGroupingItemDataFactory.GetNodeData(node);
                if (data == null)
                {
                    continue;
                }

                if (DBConstants.DoesObjectTypeHoldsData(data.Type ?? -1))
                {
                    result = true;
                    break;
                }
            }

            return(result);
        }
コード例 #5
0
        public IList <ObjectGroupingItemData> GetChildren(int?parentID)
        {
            if (ConnParams == null)
            {
                throw new NullPropertyException("Connection parameters is null!");
            }

            IList <ObjectGroupingItemData> result = new List <ObjectGroupingItemData>();

            using (SqlConnection conn = new SqlConnection(_connParams.ConnectionString))
            {
                string     cmdText = ResManager.GetDBScript("spPragmaSQL_ObjectGroup_List");
                SqlCommand cmd     = new SqlCommand(cmdText, conn);
                cmd.CommandTimeout = 0;
                AddParam(cmd, "@ParentID", System.Data.SqlDbType.Int, parentID);

                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                string name           = String.Empty;
                int?   type           = null;
                int?   id             = null;
                string parentObjName  = String.Empty;
                string createdBy      = String.Empty;
                string updatedBy      = String.Empty;
                string helpText       = String.Empty;
                string helpTextFormat = String.Empty;

                ObjectGroupingItemData data = null;
                try
                {
                    while (reader.Read())
                    {
                        name          = reader["Name"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["Name"];
                        type          = reader["ObjType"].GetType() == typeof(DBNull) ? null : (int?)reader["ObjType"];
                        id            = reader["ObjectID"].GetType() == typeof(DBNull) ? null : (int?)reader["ObjectID"];
                        parentObjName = reader["ParentObjName"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["ParentObjName"];
                        createdBy     = reader["CreatedBy"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["CreatedBy"];
                        updatedBy     = reader["UpdatedBy"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["UpdatedBy"];

                        helpText       = reader["Description"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["Description"];
                        helpTextFormat = reader["DescriptionFormat"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["DescriptionFormat"];

                        data                = ObjectGroupingItemDataFactory.Create(name, type, id, parentObjName, parentID, createdBy);
                        data.HelpText       = helpText;
                        data.HelpTextFormat = helpTextFormat;
                        data.UpdatedBy      = updatedBy;
                        result.Add(data);
                    }
                }
                finally
                {
                    reader.Close();
                }
            }

            return(result);
        }
コード例 #6
0
ファイル: ucObjectGrouping.cs プロジェクト: Eisai/pragmasql
        private void LoadHelpText(TreeNode node)
        {
            ObjectGroupingItemData nodeData = ObjectGroupingItemDataFactory.GetNodeData(node);

            if (nodeData == null)
            {
                CurrentHelpText  = String.Empty;
                _helpTextChanged = false;
                HelpTextVisible  = false;
                lblHelpText.Text = "Help Text {?}";
                return;
            }
            _isInitializing = true;
            _rtbHelpText.RichTextBox.Rtf = nodeData.HelpText;
            _isInitializing = false;
        }
コード例 #7
0
        public IList <ObjectGroupingItemData> GetChildItemsOf(int?parentID)
        {
            if (ConnParams == null)
            {
                throw new NullPropertyException("Connection parameters is null!");
            }

            IList <ObjectGroupingItemData> result = new List <ObjectGroupingItemData>();

            using (SqlConnection conn = new SqlConnection(_connParams.ConnectionString))
            {
                string     cmdText = global::PragmaSQL.Scripts.Properties.Resources.spPragmaSQL_ObjectGroup_List;
                SqlCommand cmd     = new SqlCommand(cmdText, conn);
                cmd.Parameters.Add("@ParentID", System.Data.SqlDbType.Int);
                cmd.Parameters["@ParentID"].Value = parentID;
                conn.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                string name      = String.Empty;
                int?   type      = null;
                int?   id        = null;
                string tableName = String.Empty;
                string createdBy = String.Empty;

                ObjectGroupingItemData data = null;
                try
                {
                    while (reader.Read())
                    {
                        name      = reader["Name"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["Name"];
                        type      = reader["ObjType"].GetType() == typeof(DBNull) ? null : (int?)reader["ObjType"];
                        id        = reader["ObjectID"].GetType() == typeof(DBNull) ? null : (int?)reader["ObjectID"];
                        tableName = reader["TableName"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["TableName"];
                        createdBy = reader["CreatedBy"].GetType() == typeof(DBNull) ? String.Empty : (string)reader["CreatedBy"];

                        data = ObjectGroupingItemDataFactory.Create(name, type, id, tableName, parentID, createdBy);
                        result.Add(data);
                    }
                }
                finally
                {
                    reader.Close();
                }
            }

            return(result);
        }
コード例 #8
0
ファイル: ucObjectGrouping.cs プロジェクト: Eisai/pragmasql
        public void AddFolder(TreeNode parentNode)
        {
            string name     = String.Empty;
            int?   parentID = null;

            ObjectGroupingItemData parentData = ObjectGroupingItemDataFactory.GetNodeData(parentNode);

            if (parentData != null)
            {
                parentID = parentData.ID;
            }

            DialogResult dlgRes = InputDialog.ShowDialog("New Folder", "Folder Name", ref name);

            if (dlgRes != DialogResult.OK || String.IsNullOrEmpty(name))
            {
                return;
            }

            try
            {
                tv.BeginUpdate();
                ObjectGroupingItemData newFolderData = ObjectGroupingItemDataFactory.Create(name, DBObjectType.GroupingFolderY, null, String.Empty, parentID, _connParams.CurrentUsername);
                newFolderData.ParentID = parentID;
                try
                {
                    _grpFacade.AddItem(newFolderData);
                    TreeNode newFolder = AddNode(parentNode, newFolderData);
                    AddEmptyNode(newFolder);

                    if (parentNode != null && !parentNode.IsExpanded)
                    {
                        parentNode.Expand();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            finally
            {
                UpdateSelectedItemInfo();
                tv.EndUpdate();
            }
        }
コード例 #9
0
        private void AddNodesToSelectedObjectGroup()
        {
            TreeNode selNode = og.SelectedNode;

            if (selNode == null)
            {
                ShowError("Please select an object grouping folder!");
                return;
            }

            ObjectGroupingItemData selData = ObjectGroupingItemDataFactory.GetNodeData(selNode);

            if (selData.Type != DBObjectType.GroupingFolderY)
            {
                ShowError("Please select an object grouping folder!");
                return;
            }

            StringBuilder sb = new StringBuilder();

            foreach (TreeNode node in _nodes)
            {
                try
                {
                    if (_isImport)
                    {
                        og.ImportObject(node, selNode, true);
                    }
                    else
                    {
                        og.AddObjectFromObjectExplorer(node, selNode, true);
                    }
                }
                catch (Exception ex)
                {
                    sb.AppendLine("-> " + ex.Message);
                }
            }

            if (sb.Length > 0)
            {
                GenericErrorDialog.ShowError("Object Grouping Error", "Some objects can not be added to selected group folder.", sb.ToString());
            }
            this.DialogResult = DialogResult.OK;
        }
コード例 #10
0
ファイル: ucObjectGrouping.cs プロジェクト: Eisai/pragmasql
        public void OpenSelectedObjects( )
        {
            string error = String.Empty;
            IList <frmDataViewer> viewers = new List <frmDataViewer>();

            foreach (TreeNode node in tv.SelectedNodes)
            {
                ObjectGroupingItemData data = ObjectGroupingItemDataFactory.GetNodeData(node);
                if (data == null)
                {
                    continue;
                }

                ObjectInfo objInfo = ProgrammabilityHelper.GetObjectInfo(_connParams, String.Empty, data.Name);
                if (objInfo == null)
                {
                    error += " - " + data.Name + "\r\n";
                    continue;
                }

                if (!DBConstants.DoesObjectTypeHoldsData(data.Type ?? -1))
                {
                    continue;
                }
                string caption    = data.Name + "{" + cmbDatabases.Text + " on " + cmbServers.Text + "}";
                string script     = " select * from [" + data.Name + "]";
                bool   isReadOnly = (data.Type == DBObjectType.View) ? true : false;

                frmDataViewer viewer = DataViewerFactory.CreateDataViewer(_connParams, cmbDatabases.Text, data.Name, caption, script, isReadOnly, false);
                viewers.Add(viewer);
            }

            foreach (frmDataViewer viewer in viewers)
            {
                viewer.LoadData(true);
                DataViewerFactory.ShowDataViewer(viewer);
            }

            if (!String.IsNullOrEmpty(error))
            {
                MessageService.ShowError("Objects listed below do not exist in the database!\r\n" + error);
            }
        }
コード例 #11
0
ファイル: ucObjectGrouping.cs プロジェクト: Eisai/pragmasql
        public void ModifySelectedObjects( )
        {
            string error = String.Empty;

            IList <frmScriptEditor> editors = new List <frmScriptEditor>();

            foreach (TreeNode node in tv.SelectedNodes)
            {
                ObjectGroupingItemData data = ObjectGroupingItemDataFactory.GetNodeData(node);
                if (data == null)
                {
                    continue;
                }

                ObjectInfo objInfo = ProgrammabilityHelper.GetObjectInfo(_connParams, String.Empty, data.Name);
                if (objInfo == null)
                {
                    error += " - " + data.Name + "\r\n";
                    continue;
                }

                if (!DBConstants.DoesObjectTypeHasScript(data.Type ?? -1))
                {
                    continue;
                }
                string          script = ScriptingHelper.GetAlterScript(_connParams, _connParams.Database, objInfo.ObjectID, objInfo.ObjectType);
                frmScriptEditor editor = ScriptEditorFactory.Create(objInfo.ObjectName, script, objInfo.ObjectID, objInfo.ObjectType, _connParams, cmbDatabases.Text);
                editors.Add(editor);
            }

            foreach (frmScriptEditor editor in editors)
            {
                ScriptEditorFactory.ShowScriptEditor(editor);
            }

            if (!String.IsNullOrEmpty(error))
            {
                MessageService.ShowError("Objects listed below do not exist in the database!\r\n" + error);
            }
        }
コード例 #12
0
ファイル: ucObjectGrouping.cs プロジェクト: Eisai/pragmasql
        public void LoadChildren(TreeNode node, bool forceRefresh)
        {
            ObjectGroupingItemData data = ObjectGroupingItemDataFactory.GetNodeData(node);

            if (data == null)
            {
                return;
            }

            if ((data.Populated && !forceRefresh) || data.Type != DBObjectType.GroupingFolderY)
            {
                return;
            }

            try
            {
                tv.BeginUpdate();
                TreeNode childNode = null;
                node.Nodes.Clear();
                IList <ObjectGroupingItemData> children = _grpFacade.GetChildren(data.ID);
                foreach (ObjectGroupingItemData childData in children)
                {
                    childNode      = AddNode(node, childData);
                    data.Populated = true;
                    if (childData.Type == DBObjectType.GroupingFolderY)
                    {
                        AddEmptyNode(childNode);
                    }
                }
            }
            finally
            {
                UpdateSelectedItemInfo();
                tv.EndUpdate();
            }
        }
コード例 #13
0
ファイル: ucObjectGrouping.cs プロジェクト: Eisai/pragmasql
        public void ChangeNodeParent(TreeNode source, TreeNode dropNode)
        {
            if (source == null)
            {
                return;
            }

            ObjectGroupingItemData sourceData = ObjectGroupingItemDataFactory.GetNodeData(source);

            if (sourceData == null)
            {
                return;
            }

            try
            {
                int?     parentID   = null;
                TreeNode parentNode = null;

                ObjectGroupingItemData dropData = ObjectGroupingItemDataFactory.GetNodeData(dropNode);
                if (dropNode != null && dropData != null)
                {
                    parentID   = dropData.ID;
                    parentNode = dropNode;
                }


                tv.BeginUpdate();

                try
                {
                    sourceData.ParentID = parentID;
                    _grpFacade.UpdateItem(sourceData);

                    if (source.Parent != null)
                    {
                        source.Parent.Nodes.Remove(source);
                    }
                    else
                    {
                        tv.Nodes.Remove(source);
                    }

                    if (parentNode != null)
                    {
                        parentNode.Nodes.Add(source);
                        if (!parentNode.IsExpanded)
                        {
                            parentNode.Expand();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            finally
            {
                tv.EndUpdate();
            }
        }
コード例 #14
0
ファイル: ucObjectGrouping.cs プロジェクト: Eisai/pragmasql
        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();
            }
        }
コード例 #15
0
ファイル: ucObjectGrouping.cs プロジェクト: Eisai/pragmasql
        private void tv_DragDrop(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 (firstNode.Tag is NodeData)
            {
                foreach (TreeNode node in sourceNodes.Values)
                {
                    AddObjectFromObjectExplorer(node, dropNode);
                }
                e.Effect = DragDropEffects.Copy;
                tv.SelectedNodes.Clear();
            }
            // 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 != null)
                {
                    List <string> parents = _grpFacade.GetAllParents(dropData.ID.Value);
                    if (parents != null && parents.Contains(firstNodeData.ID.ToString()))
                    {
                        MessageBox.Show(String.Format("Source node '{0}' is parent of the target node '{1}'!", firstNodeData.Name, dropData.Name), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                e.Effect = DragDropEffects.Move;
                foreach (TreeNode node in sourceNodes.Values)
                {
                    ChangeNodeParent(node, dropNode);
                }
                tv.SelectedNodes.Clear();
            }
        }
コード例 #16
0
ファイル: ucObjectGrouping.cs プロジェクト: Eisai/pragmasql
        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;
            }
        }