//数据库下拉列表选择事件 private void cboSqlDataBase_SelectedIndexChanged(object sender, EventArgs e) { string resultMsg = string.Empty; string strDataBaseType = ConfigurationManager.AppSettings["DataAccess"]; string strDataBaseName = cboSqlDataBase.Text; if (strDataBaseType.Equals(BaseDict.SqlServerData) && (cboSqlDataBase.Text.Equals("Please select") || string.IsNullOrWhiteSpace(cboSqlDataBase.Text))) { return; } try { CodeGenerators gener = new CodeGenerators(); var list = gener.QueryTablesAll(out resultMsg, strDataBaseType, strDataBaseName); list.Insert(0, new ModelGeneration() { TableName = "Please select" }); cboSqlDataTable.DisplayMember = "TableName"; cboSqlDataTable.ValueMember = "TableName"; cboSqlDataTable.DataSource = list; cboSqlDataTable.SelectedValue = "Please select"; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// 数据库连接 /// </summary> private void Connection() { CodeGenerators gen = new CodeGenerators(); string resultMsg = string.Empty; string strDataAccess = ConfigurationManager.AppSettings["DataAccess"]; if (strDataAccess.Equals(BaseDict.OracleData)) { var list = gen.QueryTablesAll(out resultMsg, strDataAccess); if (string.IsNullOrWhiteSpace(resultMsg) || resultMsg.Contains(BaseDict.SuccessPrefix)) { list.Insert(0, new ModelGeneration() { TableName = "Please select" }); cboSqlDataTable.DisplayMember = "TableName"; cboSqlDataTable.ValueMember = "TableName"; cboSqlDataTable.DataSource = list; cboSqlDataTable.SelectedValue = "Please select"; MessageBox.Show("连接成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(resultMsg, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (strDataAccess.Equals(BaseDict.SqlServerData)) { var list = gen.QueryDataBaseAll(out resultMsg, strDataAccess); cboSqlDataBase.DataSource = list; } }
/// <summary> /// 数据库连接测试 /// </summary> private void DBConnectionTest() { var strDataAccess = ConfigurationManager.AppSettings["DataAccess"]; var resultMsg = string.Empty; CodeGenerators gen = new CodeGenerators(); var list = gen.QueryTablesAll(out resultMsg, strDataAccess); if (string.IsNullOrWhiteSpace(resultMsg) || resultMsg.Contains(BaseDict.SuccessPrefix)) { MessageBox.Show("连接成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(resultMsg, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }