private List <string> RetornaTabelaReferenciadas(string nomeTabela, string conexao)
        {
            /*
             * SELECT
             * KCU1.CONSTRAINT_NAME AS 'FK_Nome_Constraint'
             * , KCU1.TABLE_NAME AS 'FK_Nome_Tabela'
             * , KCU1.COLUMN_NAME AS 'FK_Nome_Coluna'
             * , FK.is_disabled AS 'FK_Esta_Desativada'
             * , KCU2.CONSTRAINT_NAME AS 'PK_Nome_Constraint_Referenciada'
             * , KCU2.TABLE_NAME AS 'PK_Nome_Tabela_Referenciada'
             * , KCU2.COLUMN_NAME AS 'PK_Nome_Coluna_Referenciada'
             * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC
             * JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU1
             * ON KCU1.CONSTRAINT_CATALOG = RC.CONSTRAINT_CATALOG
             * AND KCU1.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA
             * AND KCU1.CONSTRAINT_NAME = RC.CONSTRAINT_NAME
             * JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU2
             * ON KCU2.CONSTRAINT_CATALOG = RC.UNIQUE_CONSTRAINT_CATALOG
             * AND KCU2.CONSTRAINT_SCHEMA = RC.UNIQUE_CONSTRAINT_SCHEMA
             * AND KCU2.CONSTRAINT_NAME = RC.UNIQUE_CONSTRAINT_NAME
             * AND KCU2.ORDINAL_POSITION = KCU1.ORDINAL_POSITION
             * JOIN sys.foreign_keys FK on FK.name = KCU1.CONSTRAINT_NAME
             * WHERE KCU1.TABLE_NAME = 'Permissao' AND KCU1.COLUMN_NAME = 'ModuloId'
             * Order by
             * KCU1.TABLE_NAME
             */
            List <string> listaRetorno = new List <string>();

            string sql = string.Format(@"
            SELECT  
                KCU2.TABLE_NAME
            FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC
            JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU1
            ON KCU1.CONSTRAINT_CATALOG = RC.CONSTRAINT_CATALOG 
                AND KCU1.CONSTRAINT_SCHEMA = RC.CONSTRAINT_SCHEMA
                AND KCU1.CONSTRAINT_NAME = RC.CONSTRAINT_NAME
            JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU2
            ON KCU2.CONSTRAINT_CATALOG = RC.UNIQUE_CONSTRAINT_CATALOG 
                AND KCU2.CONSTRAINT_SCHEMA = RC.UNIQUE_CONSTRAINT_SCHEMA
                AND KCU2.CONSTRAINT_NAME = RC.UNIQUE_CONSTRAINT_NAME
                AND KCU2.ORDINAL_POSITION = KCU1.ORDINAL_POSITION
            JOIN sys.foreign_keys FK on FK.name = KCU1.CONSTRAINT_NAME
            WHERE KCU1.TABLE_NAME = '{0}'
            ", nomeTabela);

            Banco.Banco objBanco = new Banco.Banco(conexao);
            DataSet     retorno  = objBanco.GetDataSet(sql, nomeTabela);

            for (int i = 0; i < retorno.Tables[0].Rows.Count; i++)
            {
                listaRetorno.Add(retorno.Tables[0].Rows[i][0].ToString());
            }
            objBanco.CloseConn();
            return(listaRetorno);
        }
        public void preencherUmTree(int cod_tipo)
        {
            conjItem = new List<ListViewItem>();

            tvTipado.ImageList = imageList1;
            tvTipado.Nodes.Clear();
            string av = new Banco.Banco().carregarCodigoUM(cod_tipo).Rows[0].ItemArray.GetValue(0).ToString();
            tvTipado.Nodes.Add(av);
            tvTipado.Nodes[0].ImageIndex = (Convert.ToInt16(new Banco.Banco().carregarCodigoUM(cod_tipo).Rows[0].ItemArray.GetValue(1))) - 1;
            tvTipado.Nodes[0].SelectedImageIndex = (Convert.ToInt16(new Banco.Banco().carregarCodigoUM(cod_tipo).Rows[0].ItemArray.GetValue(1))) - 1;
            tvTipado.Nodes[0].Tag = "RootDB";
        }
        public void carregarProdutos(string nome)
        {
            conjProduto = new List<ListViewItem>();
            lvCodigo.Items.Clear();
            lvCodigo.LargeImageList = imageList2;
            DataTable produtos = new Banco.Banco().carregarNomeProdutoPeloTipo(nome);
            for (int i = 0; i < produtos.Rows.Count; i++)
            {
                conjProduto.Add(
                  new ListViewItem(
                      produtos.Rows[i].ItemArray.GetValue(0).ToString() + " : " + produtos.Rows[i].ItemArray.GetValue(1).ToString()
                      , new Banco.Banco().carregarCodigoFoto(Convert.ToInt16(produtos.Rows[i].ItemArray.GetValue(0))))
                           );
                lvCodigo.Items.Add(conjProduto.Last());

            }
        }
Example #4
0
        private void btnLerBanco_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < lstTabelas.Items.Count; i++)
            {
                lstTabelas.Items.RemoveAt(i);
            }

            if ((txtServidor.Text.Trim() != "") || (txtBanco.Text.Trim() != ""))
            {
                // Monta a string de conexão
                //Data Source=ELNBSBSRV12;Initial Catalog=Eletronorte;User ID=elnweb; Password=elnweb;
                strConnstring = new StringBuilder();
                strConnstring.Append("Data Source=" + txtServidor.Text.Replace("'", "") + ";");
                strConnstring.Append("Initial Catalog=" + txtBanco.Text.Replace("'", "") + ";");

                if ((ckAutentica.Checked == false) && (txtUsuario.Text.Trim() != ""))
                {
                    strConnstring.Append("User ID=" + txtUsuario.Text.Replace("'", "") + ";");
                    strConnstring.Append("Password="******"'", "") + ";");
                }
                else
                {
                    // Usar autenticação segura
                    strConnstring.Append("Integrated Security=True;");
                }

                // Conecta com o banco
                try
                {
                    objBanco = new Banco.Banco(strConnstring.ToString());

                    try
                    {
                        // Ler as tabelas
                        dr = objBanco.QueryConsulta("SELECT * FROM SYSOBJECTS WHERE TYPE = 'U' ORDER BY NAME");
                        while (dr.Read())
                        {
                            lstTabelas.Items.Add(dr["NAME"].ToString());
                        }
                    }
                    catch (SqlException)
                    {
                        MessageBox.Show("Erro ao ler o banco de dados.");
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Erro encontrado.");
                    }
                }
                catch (SqlException sqlerr)
                {
                    MessageBox.Show(sqlerr.ToString());
                }
                finally
                {
                    lblConnstring.Text = strConnstring.ToString();
                }
            }
            else
            {
                MessageBox.Show("Informe a string de conexão com o banco.");
            }
        }
        private void preencherTreeView()
        {
            tvTipado.ImageList =  imageList1;
            tvTipado.Nodes.Clear();

            DataTable t = new DataTable();
            t = new Banco.Banco().carregarCodigo();
            for (int i = 0; i < t.Rows.Count; i++)
            {
                tvTipado.Nodes.Add(t.Rows[i].ItemArray.GetValue(0).ToString());
                tvTipado.Nodes[i].ImageIndex = Convert.ToInt16(t.Rows[i].ItemArray.GetValue(1).ToString()) - 1;
                tvTipado.Nodes[i].SelectedImageIndex = Convert.ToInt16(t.Rows[i].ItemArray.GetValue(1).ToString()) - 1;
                tvTipado.Nodes[i].Tag = "RootDB";
            }
        }
Example #6
0
 public void DadoEstouNoBanco()
 {
     _banco = new Banco.Banco();
 }
        // Metodos
        public StringBuilder GeraCodigoDto(string _tabela, string _conexao, string _banco)
        {
            string strTabela = _tabela;

            objCodigo = new StringBuilder();

            objCodigo.AppendLine("using System;");
            objCodigo.AppendLine("using System.Collections.Generic;");
            objCodigo.AppendLine("using System.ComponentModel.DataAnnotations;");
            objCodigo.AppendLine("using System.Text;");
            objCodigo.AppendLine();
            objCodigo.AppendLine("namespace DTO");
            objCodigo.AppendLine("{");

            string tabelaFormatada = strTabela.Replace("_", "").Replace("-", "");

            // Abre conexão com o banco
            objBanco = new Banco.Banco(_conexao);
            // Cria o objeto da classe Library
            objLib = new Library.Library();

            //objCodigo.AppendLine();
            objCodigo.AppendLine(tb + "/// <summary>");
            objCodigo.AppendLine(tb + "/// Classe DTO gerada automática: Tab" + strTabela);
            if (Environment.MachineName == "MARQUESNOTE-PC")
            {
                objCodigo.AppendLine(tb + "/// Criador: Marques Silva Fonseca");
            }
            else
            {
                objCodigo.AppendLine(tb + "/// Criador: " + Environment.UserName);
            }
            objCodigo.AppendLine(tb + "/// Criada em " + strData);
            //objCodigo.AppendLine(tb + "/// Contato: [email protected]");
            objCodigo.AppendLine(tb + "/// </summary>");
            objCodigo.AppendLine(tb + "public class Tab" + tabelaFormatada);
            objCodigo.AppendLine(tb + "{");
            objCodigo.AppendLine(tb + tb + "// Atributos");

            // Faz a leitura de todas as colunas da tabela
            objDr = objBanco.QueryConsulta("SELECT * FROM " + strTabela);
            // Conta o número de colunas
            int nunrec = objDr.FieldCount;

            for (int i = 0; i < nunrec; i++)
            {
                #region modelo1
                var ColunaIsNullable = objBanco.RetornaValor("IF(EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + strTabela + "' AND COLUMN_NAME = '" + objDr.GetName(i) + "' AND IS_NULLABLE = 'YES')) SELECT 1 IsNullable ELSE SELECT 0 IsNullable", new System.Collections.ArrayList()
                {
                }, new System.Collections.ArrayList {
                });
                string tipoObjeto = objLib.DefineTipo(objDr.GetDataTypeName(i).ToString());
                // o campo aceita nullo
                if (Convert.ToBoolean(ColunaIsNullable) && tipoObjeto == "DateTime")
                {
                    objCodigo.AppendLine(tb + tb + "private " + tipoObjeto + "?" + " _" + objDr.GetName(i) + ";");
                }
                // o campo aceita nullo
                else
                {
                    objCodigo.AppendLine(tb + tb + "private " + objLib.DefineTipo(objDr.GetDataTypeName(i).ToString()) + " _" + objDr.GetName(i) + ";");
                }
                #endregion
            }

            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + "// Propriedades");

            for (int i = 0; i < nunrec; i++)
            {
                #region modelo1
                objCodigo.AppendLine(tb + tb + "#region " + objDr.GetName(i) + "");

                var ColunaIsNullable = objBanco.RetornaValor("IF(EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + strTabela + "' AND COLUMN_NAME = '" + objDr.GetName(i) + "' AND IS_NULLABLE = 'YES')) SELECT 1 IsNullable ELSE SELECT 0 IsNullable", new System.Collections.ArrayList()
                {
                }, new System.Collections.ArrayList {
                });
                string tipoObjeto = objLib.DefineTipo(objDr.GetDataTypeName(i).ToString());
                // o campo aceita nullo
                if (Convert.ToBoolean(ColunaIsNullable))
                {
                    //objCodigo.AppendLine(tb + tb + "[Atributos(ChavePrimaria = false, DescricaoCampo = \"\", ChaveEstrangeira = false, ClasseChaveEstrangeira = \"\", DescricaoExibirChaveEstrangeira = \"\", RelacionarChaveEstrangeiraNovoCadastro = true)]");
                    objCodigo.AppendLine(tb + tb + "//[Required(ErrorMessage = \"Informe o campo " + objDr.GetName(i) + "\")]");
                    objCodigo.AppendLine(tb + tb + "[Display(Name = \"" + objDr.GetName(i) + "\")]");

                    if (tipoObjeto == "DateTime")
                    {
                        objCodigo.AppendLine(tb + tb + "public " + objLib.DefineTipo(objDr.GetDataTypeName(i).ToString()) + "?" + " " + objDr.GetName(i) + "{" + "get { return _" + objDr.GetName(i) + "; }" + "set { _" + objDr.GetName(i) + " = value; }" + " }");
                    }
                    else
                    {
                        objCodigo.AppendLine(tb + tb + "public " + objLib.DefineTipo(objDr.GetDataTypeName(i).ToString()) + " " + objDr.GetName(i) + "{" + "get { return _" + objDr.GetName(i) + "; }" + "set { _" + objDr.GetName(i) + " = value; }" + " }");
                    }
                }
                else
                {
                    //objCodigo.AppendLine(tb + tb + "[Atributos(ChavePrimaria = false, DescricaoCampo = \"\", ChaveEstrangeira = false, ClasseChaveEstrangeira = \"\", DescricaoExibirChaveEstrangeira = \"\", RelacionarChaveEstrangeiraNovoCadastro = true)]");
                    objCodigo.AppendLine(tb + tb + "[Required(ErrorMessage = \"Informe o campo " + objDr.GetName(i) + "\")]");
                    objCodigo.AppendLine(tb + tb + "[Display(Name = \"" + objDr.GetName(i) + "\")]");

                    objCodigo.AppendLine(tb + tb + "public " + objLib.DefineTipo(objDr.GetDataTypeName(i).ToString()) + " " + objDr.GetName(i) + "{" + "get { return _" + objDr.GetName(i) + "; }" + "set { _" + objDr.GetName(i) + " = value; }" + " }");
                }

                objCodigo.AppendLine(tb + tb + "#endregion");
                objCodigo.AppendLine("");
                #endregion



                #region modelo2
                //objCodigo.AppendLine(tb + tb + "#region " + objDr.GetName(i) + "");
                ////objCodigo.AppendLine(tb + tb + "[Atributos(ChavePrimaria = false, DescricaoCampo = \"\", ChaveEstrangeira = false, ClasseChaveEstrangeira = \"\", DescricaoExibirChaveEstrangeira = \"\", RelacionarChaveEstrangeiraNovoCadastro = true)]");
                //objCodigo.AppendLine(tb + tb + "[Display(Name = \"" + objDr.GetName(i) + "\")]");
                //objCodigo.AppendLine(tb + tb + "[Required(ErrorMessage = \"Informe o campo " + objDr.GetName(i) + "\")]");
                //var ColunaIsNullable = objBanco.RetornaValor("IF(EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + strTabela + "' AND COLUMN_NAME = '" + objDr.GetName(i) + "' AND IS_NULLABLE = 'YES')) SELECT 1 IsNullable ELSE SELECT 0 IsNullable", new System.Collections.ArrayList() { }, new System.Collections.ArrayList { });
                //string tipoObjeto = objLib.DefineTipo(objDr.GetDataTypeName(i).ToString());
                //// o campo aceita nullo
                //if (Convert.ToBoolean(ColunaIsNullable) && tipoObjeto == "DateTime")
                //    objCodigo.AppendLine(tb + tb + "public " + tipoObjeto + "?" + " " + objDr.GetName(i) + " { get; set; }");
                //else
                //    objCodigo.AppendLine(tb + tb + "public " + objLib.DefineTipo(objDr.GetDataTypeName(i).ToString()) + " " + objDr.GetName(i) + " { get; set; }");
                //objCodigo.AppendLine(tb + tb + "#endregion");
                //objCodigo.AppendLine("");
                #endregion
            }
            objCodigo.AppendLine(tb + "}");
            // fecha conexão
            objBanco.CloseConn();
            objLib = null;

            objCodigo.AppendLine("}");

            return(objCodigo);
        }
        private void btProduto_Click(object sender, EventArgs e)
        {
            if (!livre)
                cod_novaVenda = new Banco.Banco().codigoDaVendaPelaMesa(cbMesas.Text);
            if (cod_novaVenda == 0)
            {
                this.cod_novaVenda = new Banco.Banco().novaVenda(vendas.cod_caixa, new Banco.Banco().cod_mesa(mesas.ToArray()));//venda aberta
                new Banco.BancoVenda().superVenda(this.cod_novaVenda);//cria a super venda e associa a venda criada
            }
            codigosCompleto = new int[lvItensOld.Items.Count];//os codigos dos produtos
            for (int i = 0; i < codigosCompleto.Length; i++)
                codigosCompleto[i] = vendas.Completos[Convert.ToInt16(lvItensOld.Items[i].Text) - 1].cod_completo;
            // codigos[i] = Convert.ToInt16(lvInfo.Items[i].Text);

            qtd = new double[lvItensOld.Items.Count];//as quantidades
            for (int i = 0; i < qtd.Length; i++)
                qtd[i] = Convert.ToDouble(lvItensOld.Items[i].SubItems[3].Text);
            //tenho q mover ou deletar

            if (existe(codigosCompleto[Convert.ToInt16(mtCodigo.Text) - 1]))
            {
                if ( Double.Parse(  tbQuantidade.Text) <= quantidade(codigosCompleto[Convert.ToInt16(mtCodigo.Text) - 1]))
                {
                    new Banco.BancoInformacao().transferirCompleto(codigosCompleto[Convert.ToInt16(mtCodigo.Text) - 1],
                            Double.Parse(tbQuantidade.Text), this.cod_novaVenda);

                    MessageBox.Show("ALTERAÇÃO CONCLUÍDA", "MENSAGEM");
                    vendas = new Banco.BancoVenda().carregaVenda(vendas.cod_venda);
                    carregar();
                    new Banco.BancoInformacao().unirProdutosIguais(new Banco.BancoVenda().carregaVenda(cod_novaVenda));
                    carregarNovaVenda();
                }
                else
                    MessageBox.Show("QUANDITADE DE ITENS RETIRADOS ALÉM DA QUANTIA EXISTENTE", "MENSAGEM DE ERRO");
            }
            else MessageBox.Show("CODIGO NÃO IDENTIFICADO NESTA VENDA ", "MENSAGEM DE ERRO");
            mtCodigo.Clear();
            mtCodigo.Focus();
        }
        // Metodos
        public StringBuilder GeraCodigoBLL(string _tabela, string _conexao, string _banco, bool chkAtualizarCampoDataCadastro = true)
        {
            string strTabela = _tabela;

            objCodigo = new StringBuilder();

            objCodigo.AppendLine("using System;");
            objCodigo.AppendLine("using System.Collections.Generic;");
            objCodigo.AppendLine("using System.Text;");
            objCodigo.AppendLine("using System.Data;");
            objCodigo.AppendLine("using System.Data.SqlClient;");
            objCodigo.AppendLine("using DTO;");
            objCodigo.AppendLine("using DAL;");
            objCodigo.AppendLine();
            objCodigo.AppendLine("namespace BLL");
            objCodigo.AppendLine("{");

            string tabelaFormatada = strTabela.Replace("_", "").Replace("-", "");

            //objCodigo.AppendLine();
            objCodigo.AppendLine(tb + "/// <summary>");
            objCodigo.AppendLine(tb + "/// Classe da BLL gerada automática: " + strTabela);
            if (Environment.MachineName == "MARQUESNOTE-PC")
            {
                objCodigo.AppendLine(tb + "/// Criador: Marques Silva Fonseca");
            }
            else
            {
                objCodigo.AppendLine(tb + "/// Criador: " + Environment.UserName);
            }
            objCodigo.AppendLine(tb + "/// Criada em " + strData);
            //objCodigo.AppendLine(tb + "/// Contato: [email protected]");
            objCodigo.AppendLine(tb + "/// </summary>");
            objCodigo.AppendLine(tb + "public class " + tabelaFormatada + "BO<T>");
            objCodigo.AppendLine(tb + "{");
            objCodigo.AppendLine(tb + tb + "// Atributos");
            // atributos
            objCodigo.AppendLine(tb + tb + "private DAL.Dao objDO = null;");
            objCodigo.AppendLine(tb + tb + "private StringBuilder strSql = null;");


            #region metodo FindAllGenerico
            // metodo FindAll--------------------------------
            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + "//Métodos");
            objCodigo.AppendLine(tb + tb + "/// <summary>");
            objCodigo.AppendLine(tb + tb + "/// Seleciona todos os registros e retorna um DataSet.");
            objCodigo.AppendLine(tb + tb + "/// </summary>");
            objCodigo.AppendLine(tb + tb + "/// <returns>DataSet</returns>");
            objCodigo.AppendLine(tb + tb + "public IEnumerable<Tab" + tabelaFormatada + "> FindAllLista()");
            objCodigo.AppendLine(tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + "try");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = new StringBuilder();");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" SELECT \"); ");
            //objCodigo.AppendLine(tb + tb + tb + tb + "// colunas");
            objCodigo.Append(tb + tb + tb + tb + "strSql.Append(\" ");

            // pega todas as colunas da tabela

            // Abre conexão
            objBanco = new Banco.Banco(_conexao);
            // Faz a leitura de todas as colunas da tabela
            objDr = objBanco.QueryConsulta("SELECT * FROM " + strTabela);

            nunrec = objDr.FieldCount;

            for (int i = 0; i < nunrec - 1; i++)
            {
                // lista as colunas
                objCodigo.Append(objDr.GetName(i) + ", ");
            }

            // lista a última coluna sem a virgula
            objCodigo.Append(objDr.GetName(nunrec - 1) + " ");

            // Fecha conexão
            objBanco.CloseConn();
            objBanco = null;

            objCodigo.AppendLine(" \"); ");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" FROM  " + strTabela + "  \");");
            objCodigo.AppendLine(tb + tb + tb + tb + "string sql = strSql.ToString();");
            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "IEnumerable<Tab" + tabelaFormatada + "> lista = new DAL.Dao<Tab" + tabelaFormatada + ">().RetornaLista(strSql.ToString(), new List<Tab" + tabelaFormatada + ">());");
            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "// retorna lista do tipo do objeto");
            objCodigo.AppendLine(tb + tb + tb + tb + "return lista;");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "catch (Exception er)");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "throw new Exception(\"Aconteceu um erro:\" + er.Message.ToString()); ");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "finally");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = null;");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + "}");
            objCodigo.AppendLine();
            #endregion

            #region metodo FindAllGenerico com where
            // metodo FindAll--------------------------------
            objCodigo.AppendLine(tb + tb + "//Métodos");
            objCodigo.AppendLine(tb + tb + "/// <summary>");
            objCodigo.AppendLine(tb + tb + "/// Seleciona todos os registros e retorna um DataSet.");
            objCodigo.AppendLine(tb + tb + "/// </summary>");
            objCodigo.AppendLine(tb + tb + "/// <returns>DataSet</returns>");
            objCodigo.AppendLine(tb + tb + "public IEnumerable<Tab" + tabelaFormatada + "> FindAllLista(string _filtro)");
            objCodigo.AppendLine(tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + "try");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = new StringBuilder();");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" SELECT \"); ");
            //objCodigo.AppendLine(tb + tb + tb + tb + "// colunas");
            objCodigo.Append(tb + tb + tb + tb + "strSql.Append(\" ");

            // pega todas as colunas da tabela

            // Abre conexão
            objBanco = new Banco.Banco(_conexao);
            // Faz a leitura de todas as colunas da tabela
            objDr = objBanco.QueryConsulta("SELECT * FROM " + strTabela);

            nunrec = objDr.FieldCount;

            for (int i = 0; i < nunrec - 1; i++)
            {
                // lista as colunas
                objCodigo.Append(objDr.GetName(i) + ", ");
            }

            // lista a última coluna sem a virgula
            objCodigo.Append(objDr.GetName(nunrec - 1) + " ");

            // Fecha conexão
            objBanco.CloseConn();
            objBanco = null;

            objCodigo.AppendLine(" \"); ");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" FROM  " + strTabela + "  \");");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" WHERE ( \" + _filtro + \" ) \");");
            objCodigo.AppendLine(tb + tb + tb + tb + "string sql = strSql.ToString();");
            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "IEnumerable<Tab" + tabelaFormatada + "> lista = new DAL.Dao<Tab" + tabelaFormatada + ">().RetornaLista(strSql.ToString(), new List<Tab" + tabelaFormatada + ">());");
            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "// retorna lista do tipo do objeto");
            objCodigo.AppendLine(tb + tb + tb + tb + "return lista;");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "catch (Exception er)");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "throw new Exception(\"Aconteceu um erro:\" + er.Message.ToString()); ");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "finally");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = null;");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + "}");
            objCodigo.AppendLine();
            #endregion


            // metodo FindAll--------------------------------
            objCodigo.AppendLine(tb + tb + "//Métodos");
            objCodigo.AppendLine(tb + tb + "/// <summary>");
            objCodigo.AppendLine(tb + tb + "/// Seleciona todos os registros e retorna um DataSet.");
            objCodigo.AppendLine(tb + tb + "/// </summary>");
            objCodigo.AppendLine(tb + tb + "/// <returns>DataSet</returns>");
            objCodigo.AppendLine(tb + tb + "public DataSet FindAll()");
            objCodigo.AppendLine(tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + "try");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = new StringBuilder();");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" SELECT \"); ");
            //objCodigo.AppendLine(tb + tb + tb + tb + "// colunas");
            objCodigo.Append(tb + tb + tb + tb + "strSql.Append(\" ");

            // pega todas as colunas da tabela

            // Abre conexão
            objBanco = new Banco.Banco(_conexao);
            // Faz a leitura de todas as colunas da tabela
            objDr = objBanco.QueryConsulta("SELECT * FROM " + strTabela);

            nunrec = objDr.FieldCount;

            for (int i = 0; i < nunrec - 1; i++)
            {
                // lista as colunas
                objCodigo.Append(objDr.GetName(i) + ", ");
            }

            // lista a última coluna sem a virgula
            objCodigo.Append(objDr.GetName(nunrec - 1) + " ");

            // Fecha conexão
            objBanco.CloseConn();
            objBanco = null;

            objCodigo.AppendLine(" \"); ");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" FROM  " + strTabela + "  \");");
            objCodigo.AppendLine(tb + tb + tb + tb + "string sql = strSql.ToString();");
            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "objDO = new DAL.Dao();");
            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "// executa consulta e retorna um DataSet");
            objCodigo.AppendLine(tb + tb + tb + tb + "return objDO.GetDataSet(strSql.ToString(), \"" + strTabela + "\");");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "catch (Exception er)");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "throw new Exception(\"Aconteceu um erro:\" + er.Message.ToString()); ");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "finally");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = null;");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + "}");
            objCodigo.AppendLine();

            // metodo FindAll com orderby--------------------------------
            objCodigo.AppendLine(tb + tb + "/// <summary>");
            objCodigo.AppendLine(tb + tb + "/// Seleciona todos os registros com ordenação e retorna um DataSet.");
            objCodigo.AppendLine(tb + tb + "/// </summary>");
            objCodigo.AppendLine(tb + tb + "/// <param name=\"_orderby\">campo de ordenação</param>");
            objCodigo.AppendLine(tb + tb + "/// <returns>DataSet</returns>");
            objCodigo.AppendLine(tb + tb + "public DataSet FindAll(string _orderby)");
            objCodigo.AppendLine(tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + "try");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = new StringBuilder();");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" SELECT \"); ");
            //objCodigo.AppendLine(tb + tb + tb + tb + "// colunas");
            objCodigo.Append(tb + tb + tb + tb + "strSql.Append(\" ");

            // pega todas as colunas da tabela

            // Abre conexão
            objBanco = new Banco.Banco(_conexao);
            // Faz a leitura de todas as colunas da tabela
            objDr = objBanco.QueryConsulta("SELECT * FROM " + strTabela);

            nunrec = objDr.FieldCount;

            for (int i = 0; i < nunrec - 1; i++)
            {
                // lista as colunas
                objCodigo.Append(objDr.GetName(i) + ", ");
            }

            // lista a última coluna sem a virgula

            objCodigo.Append(objDr.GetName(nunrec - 1) + " ");

            // Fecha conexão
            objBanco.CloseConn();
            objBanco = null;

            objCodigo.AppendLine(" \"); ");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" FROM  " + strTabela + "  \");");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" ORDER BY \" + _orderby);");
            objCodigo.AppendLine(tb + tb + tb + tb + "string sql = strSql.ToString();");
            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "objDO = new DAL.Dao();");
            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "// executa consulta e retorna um DataSet");
            objCodigo.AppendLine(tb + tb + tb + tb + "return objDO.GetDataSet(strSql.ToString(), \"" + strTabela + "\");");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "catch (Exception er)");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "throw new Exception(\"Aconteceu um erro:\" + er.Message.ToString()); ");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "finally");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = null;");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + "}");
            objCodigo.AppendLine();

            // metodo FindAllByWhere--------------------------------
            objCodigo.AppendLine(tb + tb + "/// <summary>");
            objCodigo.AppendLine(tb + tb + "/// Seleciona todos os registros com filtro.");
            objCodigo.AppendLine(tb + tb + "/// </summary>");
            objCodigo.AppendLine(tb + tb + "/// <param name=\"_filtro (\"id_campo = 1 AND campo1 = 'texto' OR campo2 LIKE 'r%'\")\">filtro da consulta</param>");
            objCodigo.AppendLine(tb + tb + "/// <returns>DataSet</returns>");
            objCodigo.AppendLine(tb + tb + "public DataSet FindByWhere(string _filtro)");
            objCodigo.AppendLine(tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + "try");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = new StringBuilder();");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" SELECT \"); ");
            //objCodigo.AppendLine(tb + tb + tb + tb + "// colunas");
            objCodigo.Append(tb + tb + tb + tb + "strSql.Append(\" ");

            // pega todas as colunas da tabela

            // Abre conexão
            objBanco = new Banco.Banco(_conexao);
            // Faz a leitura de todas as colunas da tabela
            objDr = objBanco.QueryConsulta("SELECT * FROM " + strTabela);

            nunrec = objDr.FieldCount;

            for (int i = 0; i < nunrec - 1; i++)
            {
                // lista as colunas
                objCodigo.Append(objDr.GetName(i) + ", ");
            }

            // lista a última coluna sem a virgula

            objCodigo.Append(objDr.GetName(nunrec - 1) + " ");

            // Fecha conexão
            objBanco.CloseConn();
            objBanco = null;

            objCodigo.AppendLine(" \"); ");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" FROM  " + strTabela + "  \");");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" WHERE ( \" + _filtro + \" ) \");");
            objCodigo.AppendLine(tb + tb + tb + tb + "string sql = strSql.ToString();");
            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "objDO = new DAL.Dao();");
            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "// executa consulta e retorna um DataSet");
            objCodigo.AppendLine(tb + tb + tb + tb + "return objDO.GetDataSet(strSql.ToString(), \"" + strTabela + "\");");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "catch (Exception er)");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "throw new Exception(\"Aconteceu um erro:\" + er.Message.ToString()); ");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "finally");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = null;");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + "}");
            objCodigo.AppendLine();

            // metodo FindAllByWhere com ordenação--------------------------------
            objCodigo.AppendLine(tb + tb + "/// <summary>");
            objCodigo.AppendLine(tb + tb + "/// Seleciona todos os registros com filtro e ordenação.");
            objCodigo.AppendLine(tb + tb + "/// </summary>");
            objCodigo.AppendLine(tb + tb + "/// <param name=\"_filtro (\"id_campo = 1 AND campo1 = 'texto' OR campo2 LIKE 'r%'\")\">filtro da consulta</param>");
            objCodigo.AppendLine(tb + tb + "/// <param name=\"_orderby\">campo de ordenação</param>");
            objCodigo.AppendLine(tb + tb + "/// <returns>DataSet</returns>");
            objCodigo.AppendLine(tb + tb + "public DataSet FindByWhere(string _filtro, string _orderby)");
            objCodigo.AppendLine(tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + "try");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = new StringBuilder();");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" SELECT \"); ");
            //objCodigo.AppendLine(tb + tb + tb + tb + "// colunas");
            objCodigo.Append(tb + tb + tb + tb + "strSql.Append(\" ");

            // pega todas as colunas da tabela

            // Abre conexão
            objBanco = new Banco.Banco(_conexao);
            // Faz a leitura de todas as colunas da tabela
            objDr = objBanco.QueryConsulta(" SELECT * FROM " + strTabela);

            nunrec = objDr.FieldCount;

            for (int i = 0; i < nunrec - 1; i++)
            {
                // lista as colunas
                objCodigo.Append(objDr.GetName(i) + ", ");
            }

            // lista a última coluna sem a virgula

            objCodigo.Append(objDr.GetName(nunrec - 1) + " ");

            // Fecha conexão
            objBanco.CloseConn();
            objBanco = null;

            objCodigo.AppendLine(" \"); ");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" FROM  " + strTabela + "  \");");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" WHERE ( \" + _filtro + \" ) \");");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" ORDER BY \" + _orderby);");
            objCodigo.AppendLine(tb + tb + tb + tb + "string sql = strSql.ToString();");
            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "objDO = new DAL.Dao();");
            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "// executa consulta e retorna um DataSet");
            objCodigo.AppendLine(tb + tb + tb + tb + "return objDO.GetDataSet(strSql.ToString(), \"" + strTabela + "\");");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "catch (Exception er)");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "throw new Exception(\"Aconteceu um erro:\" + er.Message.ToString()); ");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "finally");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = null;");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + "}");
            objCodigo.AppendLine();

            // MÉTODOS DE SELEÇÃO INDIVIDUAL
            // faz um método de filtro para cada coluna da tabela

            // pega todas as colunas da tabela

            // Abre conexão
            objBanco = new Banco.Banco(_conexao);
            // Faz a leitura de todas as colunas da tabela
            objDr = objBanco.QueryConsulta("SELECT * FROM " + strTabela);
            // Objeto da clase library
            objLib = new Library.Library();
            nunrec = objDr.FieldCount;

            for (int i = 0; i < nunrec; i++)
            {
                // lista as colunas
                // metodo FindAllBy "campo" --------------------------------
                objCodigo.AppendLine(tb + tb + "/// <summary>");
                objCodigo.AppendLine(tb + tb + "/// Seleciona todos os registros por " + objDr.GetName(i) + ".");
                objCodigo.AppendLine(tb + tb + "/// </summary>");
                objCodigo.AppendLine(tb + tb + "/// <param name=\"_" + objDr.GetName(i) + "\">filtro da consulta</param>");
                objCodigo.AppendLine(tb + tb + "/// <returns>DataSet</returns>");
                objCodigo.AppendLine(tb + tb + "public DataSet FindBy_" + objDr.GetName(i) + "(" + objLib.DefineTipo(objDr.GetDataTypeName(i).ToString()) + " _" + objDr.GetName(i) + ")");
                objCodigo.AppendLine(tb + tb + "{");
                objCodigo.AppendLine(tb + tb + tb + "try");
                objCodigo.AppendLine(tb + tb + tb + "{");
                objCodigo.AppendLine(tb + tb + tb + tb + "strSql = new StringBuilder();");
                objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" SELECT \"); ");
                //objCodigo.AppendLine(tb + tb + tb + tb + "// colunas");
                objCodigo.Append(tb + tb + tb + tb + "strSql.Append(\" ");

                for (int j = 0; j < nunrec - 1; j++)
                {
                    // lista as colunas
                    objCodigo.Append(objDr.GetName(j) + ", ");
                }

                // lista a última coluna sem a virgula
                objCodigo.Append(objDr.GetName(nunrec - 1) + " ");

                objCodigo.AppendLine(" \"); ");
                objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" FROM  " + strTabela + "  \");");
                objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" WHERE ( " + objLib.SelectParam(objDr.GetName(i).ToString(), objDr.GetDataTypeName(i).ToString()) + " ) \");");
                objCodigo.AppendLine(tb + tb + tb + tb + "string sql = strSql.ToString();");
                objCodigo.AppendLine();
                objCodigo.AppendLine(tb + tb + tb + tb + "objDO = new DAL.Dao();");
                objCodigo.AppendLine();
                objCodigo.AppendLine(tb + tb + tb + tb + "// executa consulta e retorna um DataSet");
                objCodigo.AppendLine(tb + tb + tb + tb + "return objDO.GetDataSet(strSql.ToString(), \"" + strTabela + "\");");
                objCodigo.AppendLine(tb + tb + tb + "}");
                objCodigo.AppendLine(tb + tb + tb + "catch (Exception er)");
                objCodigo.AppendLine(tb + tb + tb + "{");
                objCodigo.AppendLine(tb + tb + tb + tb + "throw new Exception(\"Aconteceu um erro:\" + er.Message.ToString()); ");
                objCodigo.AppendLine(tb + tb + tb + "}");
                objCodigo.AppendLine(tb + tb + tb + "finally");
                objCodigo.AppendLine(tb + tb + tb + "{");
                objCodigo.AppendLine(tb + tb + tb + tb + "strSql = null;");
                objCodigo.AppendLine(tb + tb + tb + "}");
                objCodigo.AppendLine(tb + tb + "}");
                objCodigo.AppendLine();

                // lista as colunas
                // metodo FindAllBy "campo" --------------------------------
                objCodigo.AppendLine(tb + tb + "/// <summary>");
                objCodigo.AppendLine(tb + tb + "/// Seleciona todos os registros por " + objDr.GetName(i) + ".");
                objCodigo.AppendLine(tb + tb + "/// </summary>");
                objCodigo.AppendLine(tb + tb + "/// <param name=\"_" + objDr.GetName(i) + "\">filtro da consulta</param>");
                objCodigo.AppendLine(tb + tb + "/// <param name=\"_orderby\">campo de ordenação</param>");
                objCodigo.AppendLine(tb + tb + "/// <returns>DataSet</returns>");
                objCodigo.AppendLine(tb + tb + "public DataSet FindBy_" + objDr.GetName(i) + "(" + objLib.DefineTipo(objDr.GetDataTypeName(i).ToString()) + " _" + objDr.GetName(i) + ", string _orderby)");
                objCodigo.AppendLine(tb + tb + "{");
                objCodigo.AppendLine(tb + tb + tb + "try");
                objCodigo.AppendLine(tb + tb + tb + "{");
                objCodigo.AppendLine(tb + tb + tb + tb + "strSql = new StringBuilder();");
                objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" SELECT \"); ");
                //objCodigo.AppendLine(tb + tb + tb + tb + "// colunas");
                objCodigo.Append(tb + tb + tb + tb + "strSql.Append(\" ");

                for (int j = 0; j < nunrec - 1; j++)
                {
                    // lista as colunas
                    objCodigo.Append(objDr.GetName(j) + ", ");
                }

                // lista a última coluna sem a virgula
                objCodigo.Append(objDr.GetName(nunrec - 1) + " ");

                objCodigo.AppendLine(" \"); ");
                objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" FROM  " + strTabela + "  \");");
                objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" WHERE ( " + objLib.SelectParam(objDr.GetName(i).ToString(), objDr.GetDataTypeName(i).ToString()) + " ) \");");
                objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" ORDER BY \" + _orderby);");
                objCodigo.AppendLine(tb + tb + tb + tb + "string sql = strSql.ToString();");
                objCodigo.AppendLine();
                objCodigo.AppendLine(tb + tb + tb + tb + "objDO = new DAL.Dao();");
                objCodigo.AppendLine();
                objCodigo.AppendLine(tb + tb + tb + tb + "// executa consulta e retorna um DataSet");
                objCodigo.AppendLine(tb + tb + tb + tb + "return objDO.GetDataSet(strSql.ToString(), \"" + strTabela + "\");");
                objCodigo.AppendLine(tb + tb + tb + "}");
                objCodigo.AppendLine(tb + tb + tb + "catch (Exception er)");
                objCodigo.AppendLine(tb + tb + tb + "{");
                objCodigo.AppendLine(tb + tb + tb + tb + "throw new Exception(\"Aconteceu um erro:\" + er.Message.ToString()); ");
                objCodigo.AppendLine(tb + tb + tb + "}");
                objCodigo.AppendLine(tb + tb + tb + "finally");
                objCodigo.AppendLine(tb + tb + tb + "{");
                objCodigo.AppendLine(tb + tb + tb + tb + "strSql = null;");
                objCodigo.AppendLine(tb + tb + tb + "}");
                objCodigo.AppendLine(tb + tb + "}");
                objCodigo.AppendLine();
            }

            // lista a última coluna sem a virgula

            // Fecha conexão
            objBanco.CloseConn();
            objBanco = null;

            // fazer toda validação dos campos
            // metodo Insert--------------------------------
            objCodigo.AppendLine(tb + tb + "/// <summary>");
            objCodigo.AppendLine(tb + tb + "/// Insere os registros do banco e retorna o número de linhas afetadas.");
            objCodigo.AppendLine(tb + tb + "/// </summary>");
            objCodigo.AppendLine(tb + tb + "/// <param name=\"tab\">objetos vo do banco</param>");
            objCodigo.AppendLine(tb + tb + "/// <returns>int</returns>");
            objCodigo.AppendLine(tb + tb + "public int Insert(Tab" + tabelaFormatada + " tab)");
            objCodigo.AppendLine(tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + "try");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = new StringBuilder();");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" INSERT INTO  " + strTabela + "  \"); ");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" (\"); ");

            // pega todas as colunas da tabela

            // Abre conexão
            objBanco = new Banco.Banco(_conexao);
            // Faz a leitura de todas as colunas da tabela
            objDr = objBanco.QueryConsulta("SELECT * FROM " + strTabela);

            nunrec = objDr.FieldCount;

            for (int i = 0; i < nunrec - 1; i++)
            {
                // lista as colunas
                objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" " + objDr.GetName(i) + ", \"); ");
            }

            // lista a última coluna sem a virgula
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" " + objDr.GetName(nunrec - 1) + " \"); ");

            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" ) \"); ");

            // Valores
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" VALUES (\"); ");

            // objeto da classe Libary
            objLib = new Library.Library();

            for (int i = 0; i < nunrec - 1; i++)
            {
                object valorDefaultColuna = objBanco.RetornaValor("SELECT COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @Tabela AND COLUMN_NAME = @Coluna ",
                                                                  new System.Collections.ArrayList()
                {
                    "@Tabela", "@Coluna"
                }, new System.Collections.ArrayList()
                {
                    strTabela, objDr.GetName(i).ToString()
                });
                if (valorDefaultColuna != DBNull.Value)
                {
                    objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" " + "DEFAULT" + ", \"); ");
                }
                else
                {
                    // lista as colunas
                    objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" " + objLib.InsertParam(objDr.GetName(i).ToString(), objDr.GetDataTypeName(i).ToString()).Replace("_vo", "tab") + ", \"); ");
                }
            }

            object valorDefaultColuna2 = objBanco.RetornaValor("SELECT COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @Tabela AND COLUMN_NAME = @Coluna ",
                                                               new System.Collections.ArrayList()
            {
                "@Tabela", "@Coluna"
            }, new System.Collections.ArrayList()
            {
                strTabela, objDr.GetName(nunrec - 1).ToString()
            });
            if (valorDefaultColuna2 != DBNull.Value)
            {
                objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" " + "DEFAULT" + " )\"); ");
            }
            else
            {
                // lista a última coluna sem a virgula
                objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" " + objLib.InsertParam(objDr.GetName(nunrec - 1).ToString(), objDr.GetDataTypeName(nunrec - 1).ToString()).Replace("_vo", "tab") + " )\"); ");
            }

            //objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" ) \"); ");

            // Fecha conexão
            objBanco.CloseConn();
            objBanco = null;

            objCodigo.AppendLine(tb + tb + tb + tb + "objDO = new DAL.Dao();");
            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "// executa comando e retorna o número de linhas afetadas.");
            objCodigo.AppendLine(tb + tb + tb + tb + "object retorno = objDO.ExecultarScript(strSql.ToString());");
            objCodigo.AppendLine(tb + tb + tb + tb + "return Convert.ToInt32(retorno.ToString() == \"\" ? 1 : 0 );");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "catch (Exception er)");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "throw new Exception(\"Aconteceu um erro:\" + er.Message.ToString()); ");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "finally");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = null;");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + "}");
            objCodigo.AppendLine();


            // metodo Update--------------------------------
            objCodigo.AppendLine(tb + tb + "/// <summary>");
            objCodigo.AppendLine(tb + tb + "/// Atualiza os registros do banco e retorna o número de linhas afetadas.");
            objCodigo.AppendLine(tb + tb + "/// </summary>");
            objCodigo.AppendLine(tb + tb + "/// <param name=\"tab\">objetos vo do banco</param>");
            objCodigo.AppendLine(tb + tb + "/// <returns>int</returns>");
            objCodigo.AppendLine(tb + tb + "public int Update(Tab" + tabelaFormatada + " tab)");
            objCodigo.AppendLine(tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + "try");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = new StringBuilder();");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" UPDATE  " + strTabela + "  \"); ");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" SET \"); ");

            // Abre conexão
            objBanco = new Banco.Banco(_conexao);
            // Faz a leitura de todas as colunas da tabela
            objDr = objBanco.QueryConsulta("SELECT * FROM " + strTabela);
            // Cria o objeto da classe Library
            objLib = new Library.Library();

            nunrec = objDr.FieldCount;

            for (int i = 0; i < nunrec; i++)
            {
                if (i == 0)//1º linha
                {
                    if (objDr.GetName(i).ToString() == "DataCadastro")
                    {
                        if (chkAtualizarCampoDataCadastro)
                        {
                            //sem virgula
                            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" " + objLib.UpdateParam(objDr.GetName(i).ToString(), objDr.GetDataTypeName(i).ToString()) + " " + " \"); ");
                        }
                        if (!chkAtualizarCampoDataCadastro)
                        {
                            objCodigo.AppendLine(tb + tb + tb + tb + "//strSql.Append(\" " + objLib.UpdateParam(objDr.GetName(i).ToString(), objDr.GetDataTypeName(i).ToString()) + " " + " \"); ");
                        }
                    }
                    else
                    {
                        //sem virgula
                        objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" " + objLib.UpdateParam(objDr.GetName(i).ToString(), objDr.GetDataTypeName(i).ToString()) + " " + " \"); ");
                    }
                }
                else
                {
                    if (objDr.GetName(i).ToString() == "DataCadastro")
                    {
                        if (chkAtualizarCampoDataCadastro)
                        {
                            //com virgula
                            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\"," + objLib.UpdateParam(objDr.GetName(i).ToString(), objDr.GetDataTypeName(i).ToString()) + " " + " \"); ");
                        }
                        if (!chkAtualizarCampoDataCadastro)
                        {
                            objCodigo.AppendLine(tb + tb + tb + tb + "//strSql.Append(\"," + objLib.UpdateParam(objDr.GetName(i).ToString(), objDr.GetDataTypeName(i).ToString()) + " " + " \"); ");
                        }
                    }
                    else
                    {
                        //com virgula
                        objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\"," + objLib.UpdateParam(objDr.GetName(i).ToString(), objDr.GetDataTypeName(i).ToString()) + " " + " \"); ");
                    }
                }
            }

            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" WHERE (" + objLib.UpdateParam(objDr.GetName(0).ToString(), objDr.GetDataTypeName(0).ToString()) + " ) \");");

            // Fecha conexão
            objBanco.CloseConn();
            objBanco = null;
            objLib   = null;

            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "objDO = new DAL.Dao();");
            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "// executa comando e retorna o número de linhas afetadas.");
            objCodigo.AppendLine(tb + tb + tb + tb + "object retorno = objDO.ExecultarScript(strSql.ToString());");
            objCodigo.AppendLine(tb + tb + tb + tb + "return Convert.ToInt32(retorno.ToString() == \"\" ? 1 : 0 );");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "catch (Exception er)");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "throw new Exception(\"Aconteceu um erro:\" + er.Message.ToString()); ");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "finally");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = null;");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + "}");
            objCodigo.AppendLine();

            // metodo Delete--------------------------------
            objCodigo.AppendLine(tb + tb + "/// <summary>");
            objCodigo.AppendLine(tb + tb + "/// Deleta os registros do banco e retorna o número de linhas afetadas.");
            objCodigo.AppendLine(tb + tb + "/// </summary>");
            objCodigo.AppendLine(tb + tb + "/// <param name=\"tab\">objetos vo do banco</param>");
            objCodigo.AppendLine(tb + tb + "/// <returns>int</returns>");
            objCodigo.AppendLine(tb + tb + "public int Delete(Tab" + tabelaFormatada + " tab)");
            objCodigo.AppendLine(tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + "try");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = new StringBuilder();");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" DELETE FROM " + strTabela + "  \"); ");

            // Abre conexão
            objBanco = new Banco.Banco(_conexao);
            // Faz a leitura de todas as colunas da tabela
            objDr = objBanco.QueryConsulta("SELECT * FROM " + strTabela);

            objCodigo.AppendLine(tb + tb + tb + tb + "strSql.Append(\" WHERE ( " + objDr.GetName(0).ToString() + " = '\" + tab." + objDr.GetName(0).ToString() + " + \"' ) \");");

            // Fecha conexão
            objBanco.CloseConn();
            objBanco = null;

            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "objDO = new DAL.Dao();");
            objCodigo.AppendLine();
            objCodigo.AppendLine(tb + tb + tb + tb + "// executa comando e retorna o número de linhas afetadas.");
            objCodigo.AppendLine(tb + tb + tb + tb + "object retorno = objDO.ExecultarScript(strSql.ToString());");
            objCodigo.AppendLine(tb + tb + tb + tb + "return Convert.ToInt32(retorno.ToString() == \"\" ? 1 : 0 );");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "catch (Exception er)");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "throw new Exception(\"Aconteceu um erro:\" + er.Message.ToString()); ");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "finally");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "strSql = null;");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + "}");
            objCodigo.AppendLine();



            // Fim dos métodos BO
            objCodigo.AppendLine(tb + "}");
            objCodigo.AppendLine();

            objCodigo.AppendLine("}");

            return(objCodigo);
        }
Example #10
0
        private void ListaTabelas()
        {
            //for (int i = 0; i < lstTabelas.Items.Count; i++)
            //{
            //    lstTabelas.Items.RemoveAt();
            //}
            if (lstTabelas != null)
            {
                lstTabelas.Items.Clear();
            }

            listaTabelasGeral     = new List <string>();
            _bindingsourceTabelas = new BindingSource();

            if ((txtServidor.Text.Trim() != "") || (txtBanco.Text.Trim() != ""))
            {
                // Monta a string de conexão
                txtServidor.Text = txtServidor.Text.Contains("Erro no leitura do Registro.") ? "" : txtServidor.Text;
                txtBanco.Text    = txtBanco.Text.Contains("Erro no leitura do Registro.") ? "" : txtBanco.Text;
                txtUsuario.Text  = txtUsuario.Text.Contains("Erro no leitura do Registro.") ? "" : txtUsuario.Text;
                txtSenha.Text    = txtSenha.Text.Contains("Erro no leitura do Registro.") ? "" : txtSenha.Text;

                strConnstring = new StringBuilder();
                strConnstring.Append("Data Source=" + txtServidor.Text.Replace("'", "") + ";");
                strConnstring.Append("Initial Catalog=" + txtBanco.Text.Replace("'", "") + ";");

                if ((ckAutentica.Checked == false) && (txtUsuario.Text.Trim() != ""))
                {
                    strConnstring.Append("User ID=" + txtUsuario.Text.Replace("'", "") + ";");
                    strConnstring.Append("Password="******"'", "") + ";");
                }
                else
                {
                    // Usar autenticação segura
                    strConnstring.Append("Integrated Security=True;");
                }

                // Conecta com o banco
                try
                {
                    if (strConnstring.ToString().Contains("Data Source=;Initial Catalog=;Integrated Security=True;"))
                    {
                        //Configurações de banco vazia... não tem conexao...
                        txtServidor.Focus();
                        return;
                    }
                    objBanco = new Banco.Banco(strConnstring.ToString());

                    try
                    {
                        // Ler as tabelas
                        dr = objBanco.QueryConsulta("SELECT NAME, TYPE FROM SYSOBJECTS WHERE (TYPE = 'U' OR TYPE = 'V') AND name <> 'sysdiagrams' ORDER BY NAME");
                        while (dr.Read())
                        {
                            lstTabelas.Items.Add(dr["NAME"].ToString());
                            listaTabelasGeral.Add(dr["NAME"].ToString());
                        }
                        // Ler as tabelas
                        //listaTabelasGeral = tabelas.AsEnumerable().Select(M => M[0].ToString()).ToList();
                        _bindingsourceTabelas.DataSource = listaTabelasGeral;
                    }
                    catch (SqlException)
                    {
                        MessageBox.Show("Erro ao ler o banco de dados.");
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Erro encontrado.");
                    }
                }
                catch (SqlException sqlerr)
                {
                    MessageBox.Show(sqlerr.ToString());
                }
                finally
                {
                    lblConnstring.Text = strConnstring.ToString();
                }
            }
            else
            {
                MessageBox.Show("Informe a string de conexão com o banco.");
            }
        }
        // Metodos
        public StringBuilder GeraCodigoController(string _nomeNameSpaceProjeto, string _tabela, string _conexao, string _banco)
        {
            string strTabela = _tabela;

            objCodigo = new StringBuilder();

            #region Inicial...
            objCodigo.AppendLine("using System;");
            objCodigo.AppendLine("using System.Collections.Generic;");
            objCodigo.AppendLine("using System.Collections;");
            objCodigo.AppendLine("using System.Linq;");
            objCodigo.AppendLine("using System.Text;");
            objCodigo.AppendLine("using System.Web.Mvc;");
            objCodigo.AppendLine("using DTO;");
            objCodigo.AppendLine("using BLL;");
            objCodigo.AppendLine();
            objCodigo.AppendLine("/// <summary>");
            objCodigo.AppendLine("/// Classe Controller gerada automática: " + strTabela);
            if (Environment.MachineName == "MARQUESNOTE-PC")
            {
                objCodigo.AppendLine("/// Criador: Marques Silva Fonseca");
            }
            else
            {
                objCodigo.AppendLine("/// Criador: " + Environment.UserName);
            }
            objCodigo.AppendLine("/// Criada em " + strData);
            //objCodigo.AppendLine("/// Contato: [email protected]");
            objCodigo.AppendLine("/// </summary>");
            objCodigo.AppendLine("namespace " + _nomeNameSpaceProjeto + ".Controllers");
            objCodigo.AppendLine("{");

            string tabelaFormatada = strTabela.Replace("_", "").Replace("-", "");

            string objtoBLLAtual  = tabelaFormatada + "BO";                                      //TabelaBO
            string objetoDTOAtual = "Tab" + tabelaFormatada;                                     //TabTabela
            System.Globalization.CultureInfo cultureinfo = System.Threading.Thread.CurrentThread.CurrentCulture;
            string tabelaMinusculo   = tabelaFormatada.ToLower();                                //tabela
            string tabelaMinusculoBO = cultureinfo.TextInfo.ToTitleCase(tabelaFormatada) + "BO"; //tabelaBO

            // Abre conexão com o banco
            objBanco = new Banco.Banco(_conexao);
            // Cria o objeto da classe Library
            objLib = new Library.Library();

            objCodigo.AppendLine(tb + "[Authorize]");
            objCodigo.AppendLine(tb + "public class " + tabelaFormatada + "Controller : Controller");
            objCodigo.AppendLine(tb + "{");
            if (strTabela.Substring(0, 2).ToLower() != "vw")
            {
                objCodigo.AppendLine(tb + tb + string.Format("//{0}<{1}> {2} = new {3}<{4}>();", "Vw" + objtoBLLAtual, "Tab" + "Vw" + tabelaFormatada, "Vw" + tabelaMinusculoBO, "Vw" + objtoBLLAtual, "Tab" + "Vw" + tabelaFormatada));
            }
            objCodigo.AppendLine(tb + tb + string.Format("{0}<{1}> {2} = new {3}<{4}>();", objtoBLLAtual, objetoDTOAtual, tabelaMinusculoBO, objtoBLLAtual, objetoDTOAtual));
            objCodigo.AppendLine();
            #endregion


            #region Index
            objCodigo.AppendLine(tb + "// GET: " + tabelaFormatada + "");
            objCodigo.AppendLine(tb + "public ActionResult Index()");
            objCodigo.AppendLine(tb + "{");
            //objCodigo.AppendLine(tb + tb + "ViewBag.Qtd = new DAL.Dao().ExecultarScript(\"Select count(*) from Modulo\");");
            if (strTabela.Substring(0, 2).ToLower() != "vw")
            {
                objCodigo.AppendLine(tb + tb + "//IEnumerable<" + "Tab" + "Vw" + tabelaFormatada + "> listaRetornada = " + "Vw" + tabelaMinusculoBO + ".FindAllLista().AsEnumerable<" + "Tab" + "Vw" + tabelaFormatada + ">().OrderByDescending(M => M.DataCadastro);");
            }
            objCodigo.AppendLine(tb + tb + "IEnumerable<" + objetoDTOAtual + "> listaRetornada = " + tabelaMinusculoBO + ".FindAllLista().AsEnumerable<" + objetoDTOAtual + ">().OrderByDescending(M => M.DataCadastro);");
            objCodigo.AppendLine(tb + tb + "return View(listaRetornada);");
            objCodigo.AppendLine(tb + "}");
            objCodigo.AppendLine();
            #endregion


            #region Details
            // Abre conexão
            objBanco = new Banco.Banco(_conexao);
            // Faz a leitura de todas as colunas da tabela
            objDr  = objBanco.QueryConsulta("SELECT * FROM " + strTabela);
            nunrec = objDr.FieldCount;
            // objeto da classe Libary
            objLib = new Library.Library();

            objCodigo.AppendLine(tb + "// GET: " + tabelaFormatada + "/Details/5");
            if (nunrec > 0)
            {
                string tipoParametro = objLib.DefineTipo(objDr.GetDataTypeName(0).ToString());
                if (tipoParametro == "Guid")
                {
                    objCodigo.AppendLine(tb + "public ActionResult Details(string id)");
                    objCodigo.AppendLine(tb + "{");
                    //objCodigo.AppendLine(tb + tb + "System.Data.DataSet dsRetornado = " + tabelaMinusculoBO + ".FindBy_" + tabelaFormatada + "Id(new Guid(id));");
                }
                else if (tipoParametro == "string")
                {
                    objCodigo.AppendLine(tb + "public ActionResult Details(string id)");
                    objCodigo.AppendLine(tb + "{");
                    //objCodigo.AppendLine(tb + tb + "System.Data.DataSet dsRetornado = " + tabelaMinusculoBO + ".FindBy_" + tabelaFormatada + "Id(id);");
                }
                else
                {
                    objCodigo.AppendLine(tb + "public ActionResult Details(int id)");
                    objCodigo.AppendLine(tb + "{");
                    //objCodigo.AppendLine(tb + tb + "System.Data.DataSet dsRetornado = " + tabelaMinusculoBO + ".FindBy_" + tabelaFormatada + "Id(id);");
                }
            }
            if (strTabela.Substring(0, 2).ToLower() != "vw")
            {
                objCodigo.AppendLine(tb + tb + "//List<" + "Tab" + "Vw" + tabelaFormatada + "> listaRetornada = " + "Vw" + tabelaMinusculoBO + ".FindAllLista(string.Format(\"" + objDr.GetName(0) + " = '{0}'\", id)).ToList();");
            }
            objCodigo.AppendLine(tb + tb + "List<" + objetoDTOAtual + "> listaRetornada = " + tabelaMinusculoBO + ".FindAllLista(string.Format(\"" + objDr.GetName(0) + " = '{0}'\", id)).ToList();");
            objCodigo.AppendLine("");
            objCodigo.AppendLine(tb + tb + "if (listaRetornada.Count() > 0)");
            objCodigo.AppendLine(tb + tb + "{");
            objCodigo.AppendLine(tb + tb + "    return View(listaRetornada[0]);");
            objCodigo.AppendLine(tb + tb + "}");
            objCodigo.AppendLine(tb + tb + "else");
            objCodigo.AppendLine(tb + tb + "{");
            objCodigo.AppendLine(tb + tb + "    //Não retornou nenhum registro");
            objCodigo.AppendLine(tb + tb + "    return RedirectToAction(\"Index\");");
            objCodigo.AppendLine(tb + tb + "}");
            objCodigo.AppendLine(tb + "}");
            objCodigo.AppendLine("");

            // Fecha conexão
            objBanco.CloseConn();
            objBanco = null;

            #endregion


            #region Create
            objCodigo.AppendLine(tb + "// GET: " + tabelaFormatada + "/Create");
            objCodigo.AppendLine(tb + "public ActionResult Create()");
            objCodigo.AppendLine(tb + "{");
            List <string> ColunasRelacionadasForengKey = RetornaColunasRelacionadasForengKey(nomeTabela: strTabela, conexao: _conexao);
            List <string> ColunasReferenciadas         = RetornaColunasReferenciadas(nomeTabela: strTabela, conexao: _conexao);
            List <string> TabelaReferenciada           = RetornaTabelaReferenciadas(nomeTabela: strTabela, conexao: _conexao);
            for (int i = 0; i < ColunasRelacionadasForengKey.Count; i++)
            {
                objCodigo.AppendLine(tb + tb + "ViewBag." + ColunasRelacionadasForengKey[i] + " = new SelectList(new " + TabelaReferenciada[i] + "BO<Tab" + TabelaReferenciada[i] + ">().FindAllLista(), \"" + ColunasReferenciadas[0] + "\", \"Descricao\");");
            }
            objCodigo.AppendLine(tb + tb + "return View();");
            objCodigo.AppendLine(tb + "}");
            objCodigo.AppendLine();
            #endregion


            #region Create
            // Abre conexão
            objBanco = new Banco.Banco(_conexao);
            // Faz a leitura de todas as colunas da tabela
            objDr  = objBanco.QueryConsulta("SELECT * FROM " + strTabela);
            nunrec = objDr.FieldCount;
            // objeto da classe Libary
            objLib = new Library.Library();

            objCodigo.AppendLine(tb + "// POST: " + tabelaFormatada + "/Create");
            objCodigo.AppendLine(tb + "[HttpPost]");
            objCodigo.AppendLine(tb + "public ActionResult Create(" + objetoDTOAtual + " tab)");
            objCodigo.AppendLine(tb + "{");
            objCodigo.AppendLine(tb + tb + "    try");
            objCodigo.AppendLine(tb + tb + "    {");
            objCodigo.AppendLine(tb + tb + "        #region Validações e regras específicas para essa operação");
            objCodigo.AppendLine(tb + tb + "        //if (string.IsNullOrEmpty(Convert.ToString(tab.Descricao)))");
            objCodigo.AppendLine(tb + tb + "        //{");
            objCodigo.AppendLine(tb + tb + "        //    ModelState.AddModelError(\"Descricao\", \"Informe uma descrição!\");");
            objCodigo.AppendLine(tb + tb + "        //}");
            objCodigo.AppendLine(tb + tb + "        #endregion");
            objCodigo.AppendLine(tb + tb + "        ");
            objCodigo.AppendLine(tb + tb + "        if (!ModelState.IsValid)");
            objCodigo.AppendLine(tb + tb + "            return Create();");
            objCodigo.AppendLine("");
            objCodigo.AppendLine(tb + tb + "tab." + objDr.GetName(0) + " = Guid.NewGuid();");
            objCodigo.AppendLine("");
            objCodigo.AppendLine(tb + tb + "        #region modelo anterior");
            objCodigo.AppendLine(tb + tb + tb + "//" + objetoDTOAtual + " " + tabelaMinusculo + " = new " + objetoDTOAtual + "();");


            for (int i = 0; i < nunrec; i++)
            {
                //string colunaAtual = objDr.GetName(i).ToString();
                //string tipo = objLib.DefineTipo(objDr.GetDataTypeName(i).ToString());
                //colunaPrimaria = objDr.GetName(0).ToString();
                //// lista as colunas
                //if (objDr.GetName(i).ToString() == objDr.GetName(0).ToString() && objLib.DefineTipo(objDr.GetDataTypeName(0).ToString()) == "Guid")//se for a 1º linha
                //    objCodigo.AppendLine(tb + tb + tb + "" + tabelaMinusculo + "." + colunaAtual + " = Guid.NewGuid();");
                //else
                //    objCodigo.AppendLine(tb + tb + tb + "" + tabelaMinusculo + "." + colunaAtual + " = " + objLib.RetornaConvertCollectionsForm(colunaAtual, tipo) + ";");

                colunaPrimaria = objDr.GetName(0);
                string tipo        = objDr.GetDataTypeName(i);
                string colunaAtual = objDr.GetName(i).ToString();
                // lista as colunas
                if (objDr.GetName(i) == objDr.GetName(0))
                {
                    //se for a 1º linha
                    if (objLib.DefineTipo(objDr.GetDataTypeName(0).ToString()) == "Guid")
                    {
                        objCodigo.AppendLine(tb + tb + tb + "//" + tabelaMinusculo + "." + colunaAtual + " = Guid.NewGuid();");
                    }
                    else if (objLib.DefineTipo(objDr.GetDataTypeName(0).ToString()) == "string")
                    {
                        objCodigo.AppendLine(tb + tb + tb + "//" + tabelaMinusculo + "." + colunaAtual + " = id;");
                    }
                    else
                    {
                        objCodigo.AppendLine(tb + tb + tb + "//" + tabelaMinusculo + "." + colunaAtual + " = " + objLib.RetornaConvertCollectionsForm(colunaAtual, tipo) + ";");
                    }
                }
                else
                {
                    objCodigo.AppendLine(tb + tb + tb + "//" + tabelaMinusculo + "." + colunaAtual + " = " + objLib.RetornaConvertCollectionsForm(colunaAtual, tipo) + ";");
                }
            }
            objCodigo.AppendLine(tb + tb + "        #endregion");
            objCodigo.AppendLine("");

            objCodigo.AppendLine(tb + tb + tb + "        int retorno = " + tabelaMinusculoBO + ".Insert(tab);");
            objCodigo.AppendLine(tb + tb + tb + "        if (retorno == 1)");
            objCodigo.AppendLine(tb + tb + tb + "            return RedirectToAction(\"Details\", new { id = tab." + colunaPrimaria + " });");
            objCodigo.AppendLine(tb + tb + tb + "        else");
            objCodigo.AppendLine(tb + tb + tb + "            {");
            objCodigo.AppendLine(tb + tb + tb + "               //Ocorreu algum erro.....");
            objCodigo.AppendLine(tb + tb + tb + "               ModelState.AddModelError(\"\", \"Ocorreu algum erro no procedimento atual. Se o problema persistir procure o administrador do sistema.\");");
            objCodigo.AppendLine(tb + tb + tb + "               return Create();");
            objCodigo.AppendLine(tb + tb + tb + "            }");
            objCodigo.AppendLine(tb + tb + "    }");
            objCodigo.AppendLine(tb + tb + "    catch (Exception ex)");
            objCodigo.AppendLine(tb + tb + "    {");
            objCodigo.AppendLine(tb + tb + "        ModelState.AddModelError(\"\", ex.Message);");
            objCodigo.AppendLine(tb + tb + "        return Create();");
            objCodigo.AppendLine(tb + tb + "    }");
            objCodigo.AppendLine(tb + tb + "}");
            objCodigo.AppendLine();

            // Fecha conexão
            objBanco.CloseConn();
            objBanco = null;

            #endregion


            #region Edit
            // Abre conexão
            objBanco = new Banco.Banco(_conexao);
            // Faz a leitura de todas as colunas da tabela
            objDr  = objBanco.QueryConsulta("SELECT * FROM " + strTabela);
            nunrec = objDr.FieldCount;
            // objeto da classe Libary
            objLib = new Library.Library();

            objCodigo.AppendLine(tb + "// GET: " + tabelaFormatada + "/Edit/5");
            objCodigo.AppendLine(tb + "public ActionResult Edit(string id)");
            objCodigo.AppendLine(tb + "{");
            objCodigo.AppendLine(tb + tb + "List<" + objetoDTOAtual + "> listaRetornada = " + tabelaMinusculoBO + ".FindAllLista(string.Format(\"" + objDr.GetName(0) + " = '{0}'\", id)).ToList();");
            objCodigo.AppendLine("");
            objCodigo.AppendLine(tb + tb + "if (listaRetornada.Count() > 0)");
            objCodigo.AppendLine(tb + tb + "{");
            //List<string> ColunasRelacionadasForengKey = RetornaColunasRelacionadasForengKey(nomeTabela: strTabela, conexao: _conexao); List<string> ColunasRelacionadasForengKey = RetornaColunasRelacionadasForengKey(nomeTabela: strTabela, conexao: _conexao);
            //List<string> ColunasReferenciadas = RetornaColunasReferenciadas(nomeTabela: strTabela, conexao: _conexao);
            //List<string> TabelaReferenciada = RetornaTabelaReferenciadas(nomeTabela: strTabela, conexao: _conexao);
            for (int i = 0; i < ColunasRelacionadasForengKey.Count; i++)
            {
                objCodigo.AppendLine(tb + tb + "ViewBag." + ColunasRelacionadasForengKey[i] + " = new SelectList(new " + TabelaReferenciada[i] + "BO<Tab" + TabelaReferenciada[i] + ">().FindAllLista(), \"" + ColunasReferenciadas[0] + "\", \"Descricao\");");
            }
            objCodigo.AppendLine(tb + tb + "    return View(listaRetornada[0]);");
            objCodigo.AppendLine(tb + tb + "}");
            objCodigo.AppendLine(tb + tb + "else");
            objCodigo.AppendLine(tb + tb + "{");
            objCodigo.AppendLine(tb + tb + "    //Não retornou nenhum registro");
            objCodigo.AppendLine(tb + tb + "    return RedirectToAction(\"Index\");");
            objCodigo.AppendLine(tb + tb + "}");
            objCodigo.AppendLine(tb + "}");
            objCodigo.AppendLine();

            // Fecha conexão
            objBanco.CloseConn();
            objBanco = null;
            #endregion


            #region Edit
            // Abre conexão
            objBanco = new Banco.Banco(_conexao);
            // Faz a leitura de todas as colunas da tabela
            objDr  = objBanco.QueryConsulta("SELECT * FROM " + strTabela);
            nunrec = objDr.FieldCount;
            // objeto da classe Libary
            objLib = new Library.Library();

            objCodigo.AppendLine(tb + "// POST: " + tabelaFormatada + "/Edit/5");
            objCodigo.AppendLine(tb + "[HttpPost]");
            if (nunrec > 0)
            {
                string tipoParametro = objLib.DefineTipo(objDr.GetDataTypeName(0).ToString());
                tipoParametro = tipoParametro == "Guid" || tipoParametro == "string" ? "string" : "int";
                objCodigo.AppendLine(tb + "public ActionResult Edit(" + tipoParametro + " id, " + objetoDTOAtual + " tab)");
            }
            objCodigo.AppendLine(tb + "{");
            objCodigo.AppendLine(tb + tb + "    try");
            objCodigo.AppendLine(tb + tb + "    {");
            objCodigo.AppendLine(tb + tb + "        #region Validações e regras específicas para essa operação");
            objCodigo.AppendLine(tb + tb + "        //if (string.IsNullOrEmpty(Convert.ToString(tab.Descricao)))");
            objCodigo.AppendLine(tb + tb + "        //{");
            objCodigo.AppendLine(tb + tb + "        //    ModelState.AddModelError(\"Descricao\", \"Informe uma descrição!\");");
            objCodigo.AppendLine(tb + tb + "        //}");
            objCodigo.AppendLine(tb + tb + "        #endregion");
            objCodigo.AppendLine(tb + tb + "        ");
            objCodigo.AppendLine(tb + tb + "        if (!ModelState.IsValid)");
            objCodigo.AppendLine(tb + tb + "            return Edit(id);");
            objCodigo.AppendLine("");
            objCodigo.AppendLine("tab." + objDr.GetName(0) + " = new Guid(id);");
            objCodigo.AppendLine("#region modelo anterior");
            objCodigo.AppendLine(tb + tb + tb + "//" + objetoDTOAtual + " " + tabelaMinusculo + " = new " + objetoDTOAtual + "();");

            for (int i = 0; i < nunrec; i++)
            {
                colunaPrimaria = objDr.GetName(0);
                string tipo        = objDr.GetDataTypeName(i);
                string colunaAtual = objDr.GetName(i).ToString();
                // lista as colunas
                if (objDr.GetName(i) == objDr.GetName(0))
                {
                    //se for a 1º linha
                    if (objLib.DefineTipo(objDr.GetDataTypeName(0).ToString()) == "Guid")
                    {
                        objCodigo.AppendLine(tb + tb + tb + "//" + tabelaMinusculo + "." + colunaAtual + " = new Guid(id);");
                    }
                    else if (objLib.DefineTipo(objDr.GetDataTypeName(0).ToString()) == "string")
                    {
                        objCodigo.AppendLine(tb + tb + tb + "//" + tabelaMinusculo + "." + colunaAtual + " = id;");
                    }
                    else
                    {
                        objCodigo.AppendLine(tb + tb + tb + "//" + tabelaMinusculo + "." + colunaAtual + " = " + objLib.RetornaConvertCollectionsForm(colunaAtual, tipo) + ";");
                    }
                }
                else
                {
                    objCodigo.AppendLine(tb + tb + tb + "//" + tabelaMinusculo + "." + colunaAtual + " = " + objLib.RetornaConvertCollectionsForm(colunaAtual, tipo) + ";");
                }
            }
            objCodigo.AppendLine("#endregion");
            objCodigo.AppendLine(tb + tb + tb + "        int retorno = " + tabelaMinusculoBO + ".Update(tab);");
            objCodigo.AppendLine(tb + tb + tb + "        if (retorno == 1)");
            objCodigo.AppendLine(tb + tb + tb + "            return RedirectToAction(\"Details\", new { id = tab." + colunaPrimaria + " });");
            objCodigo.AppendLine(tb + tb + tb + "        else");
            objCodigo.AppendLine(tb + tb + tb + "            {");
            objCodigo.AppendLine(tb + tb + tb + "            //Ocorreu algum erro.....");
            objCodigo.AppendLine(tb + tb + tb + "            ModelState.AddModelError(\"\", \"Ocorreu algum erro no procedimento atual. Se o problema persistir procure o administrador do sistema.\");");
            objCodigo.AppendLine(tb + tb + tb + "            return Edit(id);");
            objCodigo.AppendLine(tb + tb + tb + "            }");
            objCodigo.AppendLine(tb + tb + "    }");
            objCodigo.AppendLine(tb + tb + "    catch (Exception ex)");
            objCodigo.AppendLine(tb + tb + "    {");
            objCodigo.AppendLine(tb + tb + "        ModelState.AddModelError(\"\", ex.Message);");
            objCodigo.AppendLine(tb + tb + "        return Edit(id);");
            objCodigo.AppendLine(tb + tb + "    }");
            objCodigo.AppendLine(tb + "}");
            objCodigo.AppendLine();

            // Fecha conexão
            objBanco.CloseConn();
            objBanco = null;
            #endregion


            #region Delete
            // Abre conexão
            objBanco = new Banco.Banco(_conexao);
            // Faz a leitura de todas as colunas da tabela
            objDr  = objBanco.QueryConsulta("SELECT * FROM " + strTabela);
            nunrec = objDr.FieldCount;
            // objeto da classe Libary
            objLib = new Library.Library();

            objCodigo.AppendLine(tb + "// GET: " + tabelaFormatada + "/Delete/5");
            if (nunrec > 0)
            {
                string tipoParametro = objLib.DefineTipo(objDr.GetDataTypeName(0).ToString());
                tipoParametro = tipoParametro == "Guid" || tipoParametro == "string" ? "string" : "int";
                objCodigo.AppendLine(tb + "public ActionResult Delete(" + tipoParametro + " id)");
            }
            objCodigo.AppendLine(tb + "{");
            objCodigo.AppendLine(tb + tb + "try");
            objCodigo.AppendLine(tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + "List<" + objetoDTOAtual + "> listaRetornada = this." + tabelaMinusculoBO + ".FindAllLista(string.Format(\"" + objDr.GetName(0) + " = '{0}'\", id)).Take(1).ToList();");
            objCodigo.AppendLine("");
            objCodigo.AppendLine(tb + tb + tb + "if (listaRetornada.Count > 0)");
            objCodigo.AppendLine(tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + "int retorno = this." + tabelaMinusculoBO + ".Delete(listaRetornada[0]);");
            objCodigo.AppendLine(tb + tb + tb + tb + "if (retorno == 0)");
            objCodigo.AppendLine(tb + tb + tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + tb + tb + "//Ocorreu algum erro.....");
            objCodigo.AppendLine(tb + tb + tb + tb + tb + "return RedirectToAction(\"Index\");");
            objCodigo.AppendLine(tb + tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "}");
            objCodigo.AppendLine(tb + tb + tb + "//Não retornou nenhum registro");
            objCodigo.AppendLine(tb + tb + tb + "return RedirectToAction(\"Index\");");
            objCodigo.AppendLine(tb + tb + "}");
            objCodigo.AppendLine(tb + tb + "catch");
            objCodigo.AppendLine(tb + tb + "{");
            objCodigo.AppendLine(tb + tb + tb + "return RedirectToAction(\"Index\");");
            objCodigo.AppendLine(tb + tb + "}");
            objCodigo.AppendLine(tb + "}");
            objCodigo.AppendLine();

            // Fecha conexão
            objBanco.CloseConn();
            objBanco = null;
            #endregion


            objCodigo.AppendLine(tb + "}");

            objCodigo.AppendLine("}");

            return(objCodigo);
        }