Пример #1
0
        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
        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
        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
        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;
        }
Пример #6
0
        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();
            }
        }
Пример #7
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;
        }
Пример #8
0
        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);
            }
        }
Пример #9
0
        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);
            }
        }
Пример #10
0
        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();
            }
        }
Пример #11
0
        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();
            }
        }
Пример #12
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();
            }
        }
Пример #13
0
        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();
            }
        }
Пример #14
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;
            }
        }