コード例 #1
0
        private void CopyTree()
        {
            TreeNode[] nodes = _original.Nodes.Find("User " + _connectionID.ToString(), false);
            TreeNode   root;

            if (nodes.GetLength(0) != 1)
            {
                MessageBox.Show("Root Node not found for user id " + _connectionID.ToString());
                return;
            }
            else
            {
                root = nodes[0];
            }

            tvFolders.Nodes.Clear();
            //Add all root folders (and children) to the folders tree
            foreach (TreeNode node in root.Nodes)
            {
                TreeNode newNode = (TreeNode)node.Clone();
                tvFolders.Nodes.Add(newNode);
            }

            if (CurrentFolderNode != null)
            {
                ConfigItems.NodeDescription nodeDescription = CurrentFolderNode.Tag as ConfigItems.NodeDescription;

                TreeNode[] selected = tvFolders.Nodes.Find("folder " + ((ConfigItems.TDSQueriesTree.FoldersRow)nodeDescription.NodeData).ID, true);
                if (selected != null)
                {
                    selected[0].Expand();
                    tvFolders.SelectedNode     = selected[0];
                    tvFolders.AutoScrollOffset = tvFolders.SelectedNode.Bounds.Location;
                }
            }

            //remove query nodes from the folders tree
            RemoveQueryNodes(tvFolders.Nodes);
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: clarencemorse/myzilla
        void _catalogManager_CatalogueEvent(object sender, MyZillaSettingsEventArgs e)
        {
            try
            {
                int connID = e.SaveParameter.ConnectionRow.ConnectionId ;

                TDSettings.ConnectionRow  connection = _appSettings.GetConnectionById ( connID);
                TreeNode userNode = null;
                TreeNode[] nodes = tvQueries.Nodes.Find("User " + connID.ToString(), false);
                if (nodes.GetLength(0) == 1)
                {
                    userNode = nodes[0];
                }

                NodeDescription nodeDescr;

                switch (e.SaveParameter.Operation)
                {

                    #region Exceptions
                    case OperationType.AddConnectionThrowsError:
                        RemoveConnectingNode(connID);
                        break;
                    case OperationType.LogOnFailed :
                        LoginFailedMessage( connID, e.SaveParameter.ErrorMessage );
                        break;
                    #endregion

                    #region Add Connection event
                    case OperationType.AddConnection :

                        if (_catalogManager.AreCataloguesLoaded( connID ))
                        {
                            nodeDescr = (NodeDescription)nodes[0].Tag;

                            TDSQueriesTree.Instance().LoadDefaultDataForUserId(tvQueries, connection );

                            TDSQueriesTree.Instance().AddUserSubtree(tvQueries, (TDSettings.ConnectionRow )nodeDescr.NodeData);

                            _qTree.Save();

                            RemoveConnectingNode(connID);

                            BuildAsyncProcessForGenerateColumnListCookie(connID);

                            this.StartCountingBugsPerQuery(connID);

                        }
                        else
                        {
                            nodeDescr = new NodeDescription(NodeType.Connection, connection );

                            userNode = new TreeNode(_appSettings.GetConnectionInfo(connID), 2, 2);
                            userNode.Name = "User " + connID .ToString();
                            userNode.ToolTipText = String.Empty;
                            userNode.Tag = nodeDescr;

                            tvQueries.Nodes.Add(userNode);
                            if (connection.ActiveUser )
                                AddLoadingNode(userNode);
                        }
                        break;
                    #endregion

                    #region Delete Connection event
                    case OperationType.DeleteConnection :

                        DisconnectUser(connID );
                        _qTree.RemoveUserItems(connID);
                        userNode.Remove();

                        break;
                    #endregion

                    #region Edit User event
                    case OperationType.EditConnection :

                            if (_catalogManager.AreCataloguesLoaded( connID ))
                            {
                                Interlocked.Decrement(ref _startupLoadingThreads);

                                nodeDescr = (NodeDescription)nodes[0].Tag;

                                if (_qTree.Folders.Select("UserId = " + connID.ToString()).GetLength(0)==0)
                                    TDSQueriesTree.Instance().LoadDefaultDataForUserId(tvQueries, connection );

                                RemoveConnectingNode(connID);

                                BuildAsyncProcessForGenerateColumnListCookie(connID);

                                if (this.IsTreeConnectionNodeLoaded( connID ))
                                {
                                    // no code here
                                }
                                else
                                {
                                    TDSQueriesTree.Instance().AddUserSubtree(tvQueries, (TDSettings.ConnectionRow)nodeDescr.NodeData);

                                    this.StartCountingBugsPerQuery(connID);

                                }

                                nodes[0].Text = e.SaveParameter.ConnectionRow.ConnectionName;

                                this.SetTreeNodesExpandState(userNode.Nodes);

                                if (_startupLoadingThreads == 0)
                                {
                                    this.Visible = true;

                                    SplashManager.Close();

                                    this.CheckForNewMyZillaVersion(false);
                                }

                            }
                            else {
                                if (connection.ActiveUser)
                                {
                                    this.AddLoadingNode(userNode);
                                }
                            }
                        break;
                    #endregion
                } // end switch
            }
            catch (Exception ex)
            {
                // The thread could continue to execute after the form was closed.
                // In this case, an exception is generated. It is no need to be logged or be shown those type of exceptions.
                if (!_formClosed)
                {

                    MyLogger.Write(ex, "_catalogManager_CatalogueEvent", LoggingCategory.Exception);

                    MessageBox.Show(this, ex.Message, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                //just in case
                SplashManager.Close();
            }
        }