Ejemplo n.º 1
0
        /// <summary>
        /// 工具栏-移除数据库连接
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btiRemoveConn_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            UserConn conn = trvDatabase.SelectedNode.Tag as UserConn;

            if (conn != null)
            {
                if (XtraMessageBox.Show(this, "您确定要移除此连接吗?", "信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    trvDatabase.Nodes.Remove(trvDatabase.SelectedNode);
                    conn.Delete();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 点击数据库节点时检测无效的数据库连接
        /// </summary>
        /// <param name="curNode"></param>
        private void NodeDatabaseClick(TreeNode curNode)
        {
            UserConn conn = curNode.Tag as UserConn;

            if (curNode.IsExpanded)
            {
                this.Cursor = Cursors.WaitCursor;
                try
                {
                    DataSchema dataSchema = DataSchema.GetInstance(conn);

                    //--如果数据库架构初始化完成,则更新数据表或则视图节点
                    if (dataSchema.InitStatus == DataSchemaInitStatus.Initialized)
                    {
                        UpdateNodeText(curNode, dataSchema.TableCount, dataSchema.ViewCount);
                    }
                    else //--如果数据库架构没有初始化完成则订阅其完成事件,用以更新数据表或视图节点
                    {
                        dataSchema.AddStatusChangeHandler(new EventHandler <StatusChangeEventArgs>((sender, e) =>
                        {
                            this.Invoke(new DelegateUpdateNodeText(UpdateNodeText), curNode, dataSchema.TableCount, dataSchema.ViewCount);
                        }));
                    }
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show("此连接已经失效将被移除,具体原因如下:\r\n" + ex.Message,
                                        "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    conn.Database.Delete();
                    conn.Delete();
                    trvDatabase.Nodes.Remove(curNode);
                }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }
        }