private Boolean TestaConexao() { Boolean ConexaoOK = false; try { string p = cboProviders.Items[cboProviders.SelectedIndex].ToString(); string c = getConnectionString(p, txtServidor.Text, txtUsuario.Text, txtSenha.Text, txtBancoDados.Text); clData objData = new clData(); objData.ConnectionString = c; objData.DbProvider = p; DataTable dt = objData.GetTables(); if (dt.Rows.Count > 0) { ConexaoOK = true; } } catch { ConexaoOK = false; } return(ConexaoOK); }
private void btnCreate_Click(object sender, EventArgs e) { if (lstTabelasSelecionadas.Items.Count > 0) { clData objData = new clData(); objData.ConnectionString = connectionString; objData.DbProvider = providerName; DataTable dtAux = objData.GetTables("COLUMNS"); TabelasSelecioandas = new DataTable(); TabelasSelecioandas.Columns.Add("NOME_TABELA", typeof(string)); TabelasSelecioandas.Columns.Add("NOME_COLUNA", typeof(string)); TabelasSelecioandas.Columns.Add("TIPO_COLUNA", typeof(string)); TabelasSelecioandas.Columns.Add("AUTONUMERACAO", typeof(bool)); TabelasSelecioandas.TableName = txtNomeClasse.Text; foreach (DataRow row in dtAux.Rows) { //string IS_NULLABLE = row["IS_NULLABLE"].ToString(); string DATA_TYPE = row["DATA_TYPE"].ToString(); //string NUMERIC_PRECISION = row["NUMERIC_PRECISION"].ToString(); //string NUMERIC_PRECISION_RADIX = row["NUMERIC_PRECISION_RADIX"].ToString(); //string NUMERIC_SCALE = row["NUMERIC_SCALE"].ToString(); //Boolean AUTONUMBER = (IS_NULLABLE.ToUpper() == "NO" && DATA_TYPE.ToUpper() == "INT" && NUMERIC_PRECISION == "10" && NUMERIC_PRECISION_RADIX == "10" && NUMERIC_SCALE == "0"); DataRow newRow = TabelasSelecioandas.NewRow(); newRow["NOME_TABELA"] = row["TABLE_NAME"].ToString().ToUpper(); newRow["NOME_COLUNA"] = row["COLUMN_NAME"].ToString(); newRow["TIPO_COLUNA"] = getDataType(DATA_TYPE); //newRow["AUTONUMERACAO"] = AUTONUMBER; TabelasSelecioandas.Rows.Add(newRow); } List <string> ListaTabelasSelecionadas = new List <string>(); foreach (object Tabela in lstTabelasSelecionadas.Items) { ListaTabelasSelecionadas.Add(Tabela.ToString()); } TabelasSelecioandas.AcceptChanges(); CreateClass(txtNomeClasse.Text, Functions.CreateCode(TabelasSelecioandas, ListaTabelasSelecionadas.ToArray(), providerName)); this.Close(); } else { MessageBox.Show("Selecione as tabelas para gerar a classe"); } }
private void ListaTabelas() { lstTabelasExistentes.Items.Clear(); lstTabelasSelecionadas.Items.Clear(); btnCreate.Enabled = false; txtConnectionString.Text = connectionString; clData objData = new clData(); objData.ConnectionString = connectionString; objData.DbProvider = providerName; DataTable dtAux = objData.GetTables("COLUMNS"); TabelasExistentes = new DataTable(); TabelasExistentes.Columns.Add("NOME_TABELA", typeof(string)); foreach (DataRow row in dtAux.Rows) { DataRow newRow = TabelasExistentes.NewRow(); newRow["NOME_TABELA"] = row["TABLE_NAME"].ToString().ToUpper(); TabelasExistentes.Rows.Add(newRow); } TabelasExistentes.AcceptChanges(); DataView dv = new DataView(TabelasExistentes); DataTable dt = dv.ToTable(true, new string[] { "NOME_TABELA" }); foreach (DataRow row in dt.Rows) { lstTabelasExistentes.Items.Add(row["NOME_TABELA"]); } TabelasExistentes = dt; }