Exemplo n.º 1
0
        /// <summary>
        /// 获取服务器信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ServerClick(object sender, RoutedEventArgs e)
        {
            TreeViewExNode item = sender as TreeViewExNode;

            if (!item.IsSelected)
            {
                return;
            }

            var dataBases = new List <string>();

            string connStr = string.Empty;

            var connection = LoadingConnection.GetConnectionById(item.ConnectionId, out connStr);

            item.DataType      = connection.DataType;
            item.ConnectionStr = connStr;

            if (BaseUnity.GetConnection(connection))
            {
                if (connection.DataType == DataTypes.ORACLE)
                {
                    TreeItemClick(item, ItemTypes.DataBase);
                }
                else
                {
                    TreeItemClick(item, ItemTypes.Server);
                }
            }
            else
            {
                MessageBox.Show("无法与目标服务建立链接!");
            }
        }
Exemplo n.º 2
0
        public void Init()
        {
            this.ModelList = new ObservableCollection <TreeViewEx.TreeViewExNode>();

            var connection = LoadingConnection.GetConnectionList();

            foreach (var item in connection)
            {
                var            id   = GuidExtend.NewId();
                TreeViewExNode node = new TreeViewExNode()
                {
                    ID           = id,
                    Name         = "N" + id,
                    ConnectionId = item.Id,
                    IsExpanded   = false,
                    Level        = 1,
                    Header       = item.ConnectionName,
                    DataSource   = item.DataSource,
                    DataBase     = item.DataBase,
                    FontSize     = 18
                };

                node.MouseDoubleClick += ServerClick;

                ModelList.Add(node);
            }
            this.DataContext = this;
        }
Exemplo n.º 3
0
        private void ContextMenuClose(object sender, RoutedEventArgs e)
        {
            MenuItemEx menuItem = sender as MenuItemEx;

            var name = "N" + menuItem.Name.Split('_')[1];

            TreeViewExNode item = DataBaseList.FindName(name) as TreeViewExNode;

            var removeItems = new List <TabItemEx>();

            // 关闭关联视图
            if (menuItem.ItemType == ItemTypes.Server)
            {
                foreach (TabItemEx temp in TabController.Items)
                {
                    if (temp.DataSource == item.DataSource &&
                        temp.ConnectionId == item.ConnectionId)
                    {
                        removeItems.Add(temp);
                    }
                }
            }
            else if (menuItem.ItemType == ItemTypes.DataBase)
            {
                foreach (TabItemEx temp in TabController.Items)
                {
                    if (temp.DataBase == item.DataBase &&
                        temp.DataSource == item.DataSource &&
                        temp.ConnectionId == item.ConnectionId)
                    {
                        removeItems.Add(temp);
                    }
                }
            }

            foreach (TabItemEx temp in removeItems)
            {
                TabController.Items.Remove(temp);
            }

            if (item != null)
            {
                DockPanel1.UnregisterName(name);
                item.Items.Clear();
            }
        }
Exemplo n.º 4
0
        private void TreeItemClick(TreeViewExNode item, ItemTypes itemTypes)
        {
            if (!item.IsSelected || item.HasItems)
            {
                return;
            }

            item.Items.Clear();

            var data = new List <string>();

            switch (itemTypes)
            {
            case ItemTypes.Server:
                data = Service.GetDataBases(item.ConnectionStr, item.DataType);
                break;

            case ItemTypes.DataBase:
                data = Service.GetTables(item.ConnectionStr, item.DataType, item.DataBase);
                break;
            }

            DockPanel1.RegisterName(item.Name, item);

            ContextMenu menu = GetOpenItemContextMenu(item.ID, itemTypes);

            item.ContextMenu = menu;

            foreach (var dataItem in data)
            {
                var            id   = GuidExtend.NewId();
                TreeViewExNode node = new TreeViewExNode();
                node.ID            = id;
                node.DataType      = item.DataType;
                node.Name          = "N" + id;
                node.IsExpanded    = false;
                node.Level         = item.Level + 1;
                node.Header        = dataItem;
                node.FontSize      = item.FontSize - 2;
                node.DataSource    = item.DataSource;
                node.ConnectionId  = item.ConnectionId;
                node.ConnectionStr = item.ConnectionStr;

                switch (itemTypes)
                {
                case ItemTypes.Server:
                    node.MouseDoubleClick += DataBaseClick;
                    node.DataBase          = dataItem;
                    break;

                case ItemTypes.DataBase:
                    node.MouseDoubleClick += TableClick;
                    node.DataBase          = item.DataBase;
                    node.TableKey          = dataItem;
                    break;
                }

                item.Items.Add(node);
            }

            item.IsExpanded = true;
        }