/// <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; } } }