/// <summary> /// 创建数据源 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void createDataSourceToolStripButton_Click(object sender, EventArgs e) { CreateDataSourceForm dsForm = new CreateDataSourceForm(true); if (dsForm.ShowDialog() != DialogResult.OK) { return; } IConnectionInfo ci = new ConnectionInfo(); switch (dsForm.ConnectionType) { case "gviConnectionMySql5x": ci.ConnectionType = gviConnectionType.gviConnectionMySql5x; break; case "gviConnectionFireBird2x": ci.ConnectionType = gviConnectionType.gviConnectionFireBird2x; break; case "gviConnectionSQLite3": ci.ConnectionType = gviConnectionType.gviConnectionSQLite3; break; } ci.Server = dsForm.Server; ci.Port = dsForm.Port; ci.Database = dsForm.Database; ci.UserName = dsForm.UserName; ci.Password = dsForm.Password; IDataSource ds = null; try { if (!dsFactory.HasDataSource(ci)) { ds = dsFactory.CreateDataSource(ci, null); if (ds != null && CreateLogicTreeTable(ds)) { myTreeNode sourceNode = null; if (ci.ConnectionType == gviConnectionType.gviConnectionMySql5x) { sourceNode = new myTreeNode(ci.Database + "@" + ci.Server, ci); } else { sourceNode = new myTreeNode(ci.Database, ci); } this.treeView1.Nodes.Add(sourceNode); sourceNode.ContextMenuStrip = this.contextMenuStrip1; } } else { MessageBox.Show("数据源已存在"); } } catch (COMException ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } finally { if (ds != null) { //Marshal.ReleaseComObject(ds); ds = null; } } }