Esempio n. 1
0
        public string GerarClasseCTs(string conexao, string tabela, string nomeProjeto)
        {
            //string[] item;// = new string[,];
            //string nomeColuna;
            //string tipoColuna;
            string classe = string.Empty;
            //List<string> list = peri.BuscarColunasTabela(conexao, tabela);
            string tabelaSemLixo       = peri.RetiraLixoNomeTabela(tabela);
            string colunaIdentificador = peri.cColunaIdentificador;

            classe = @"using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using " + nomeProjeto + @".DTO;
using " + nomeProjeto + @".DAO;


namespace " + nomeProjeto + @".Controller
{
    public class " + tabelaSemLixo + @"CT 
    {
        #region Atributos

        public " + tabelaSemLixo + @"DAO " + tabelaSemLixo + @"DAO = new " + tabelaSemLixo + @"DAO();

        #endregion

        #region Metodos

        #region Seleção

        public DataTable Selecionar" + tabelaSemLixo + @"PorFiltro(" + tabelaSemLixo + @"DTO p" + tabelaSemLixo + @"DTO)
        {
            try
            {     
                return " + tabelaSemLixo + @"DAO.Selecionar" + tabelaSemLixo + @"Pesquisar(p" + tabelaSemLixo + @"DTO);
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        
       public DataTable Selecionar" + tabelaSemLixo + @"PorFiltroPesquisar(" + tabelaSemLixo + @"DTO p" + tabelaSemLixo + @"DTO)
        {
            try
            {     
                return " + tabelaSemLixo + @"DAO.Selecionar" + tabelaSemLixo + @"(p" + tabelaSemLixo + @"DTO);
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        #endregion

        #region Inserção

        public Boolean Insere" + tabelaSemLixo + @"(" + tabelaSemLixo + @"DTO p" + tabelaSemLixo + @"DTO)
        {
            try
            {     
                return " + tabelaSemLixo + @"DAO.Insere" + tabelaSemLixo + @"(p" + tabelaSemLixo + @"DTO);
            }
            catch (Exception e)
            {
                throw e;
            }

        }
        #endregion

        #region Atualização
    

        public Boolean Altera" + tabelaSemLixo + @"(" + tabelaSemLixo + @"DTO p" + tabelaSemLixo + @"DTO)
        {
            try
            {     
                return " + tabelaSemLixo + @"DAO.Altera" + tabelaSemLixo + @"(p" + tabelaSemLixo + @"DTO);
            }
            catch (Exception e)
            {
                throw e;
            }
       }";



            classe = classe + @"   
                

        #endregion
        
        #region Exclusao
        
        public Boolean Excluir" + tabelaSemLixo + @"(" + tabelaSemLixo + @"DTO p" + tabelaSemLixo + @"DTO)
        {   
            try
            {     
                return " + tabelaSemLixo + @"DAO.Excluir" + tabelaSemLixo + @"(p" + tabelaSemLixo + @"DTO);
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        #endregion

        #endregion
    }
}
";

            return(classe);
        }
Esempio n. 2
0
        public string GerarClasseDTO(string conexao, string tabela, string nomeProjeto)
        {
            string[]      item;// = new string[,];
            string        tabelaClasse = peri.RetiraLixoNomeTabela(tabela);
            List <string> list         = peri.BuscarColunasTabela(conexao, tabela);

            string classe = @"using System; 
using System.Collections.Generic;
using System.Text;


namespace " + nomeProjeto + @".DTO
{
    public class " + tabelaClasse + @"DTO 
    {
        #region Atributos";


            for (int i = 0; i < list.Count; i++)
            {
                item    = list[i].ToString().Split(';');
                item[1] = peri.TratarTipos(item[1].ToString());
                switch (item[1].ToString().ToUpper())
                {
                case "DATETIME":
                    classe = classe + @"

        private DateTime c" + item[2].ToString() + @";
        public DateTime " + item[2].ToString() + @"
        {
            get { return c" + item[2].ToString() + @"; }
            set { c" + item[2].ToString() + @"= value; }
        }";
                    break;

                case "INT":
                    classe = classe + @"

        private int c" + item[2].ToString() + @";
        public int " + item[2].ToString() + @"
        {
            get { return c" + item[2].ToString() + @"; }
            set { c" + item[2].ToString() + @"= value; }
        }";
                    break;

                case "STRING":
                    classe = classe + @"

        private string c" + item[2].ToString() + @";
        public string " + item[2].ToString() + @"
        {
            get { return c" + item[2].ToString() + @"; }
            set { c" + item[2].ToString() + @"= value; }
        }";
                    break;

                case "DOUBLE":
                    classe = classe + @"

        private double c" + item[2].ToString() + @";
        public double " + item[2].ToString() + @"
        {
            get { return c" + item[2].ToString() + @"; }
            set { c" + item[2].ToString() + @"= value; }
        }";
                    break;

                case "BYTE":
                    classe = classe + @"

        private byte c" + item[2].ToString() + @";
        public byte " + item[2].ToString() + @"
        {
            get { return c" + item[2].ToString() + @"; }
            set { c" + item[2].ToString() + @"= value; Modificada = true; }
        }";
                    break;

                default:
                    classe = classe + @"

        private " + item[1].ToString() + " c" + item[2].ToString() + @";
        public " + item[1].ToString() + " " + item[2].ToString() + @"
        {
            get { if (c" + item[2].ToString() + @" == null )
                        return new " + item[1].ToString() + "();" +
                             @"else
                        return c" + item[2].ToString() + @"; }                                    
            set { c" + item[2].ToString() + @"= value; }
        }";
                    break;
                }
            }

            classe = classe + @" 
        
        public string cUsuarioInclusao;
        public string UsuarioInclusao
        {
            get { return cUsuarioInclusao; }
            set { cUsuarioInclusao = value; }
        }


        public string cUsuarioAlteracao;
        public string UsuarioAlteracao
        {
            get { return cUsuarioAlteracao; }
            set { cUsuarioAlteracao = value; }
        }


        #endregion

    }
}
                            ";

            return(classe);
        }
Esempio n. 3
0
        public string GerarClasseDAOs(string conexao, string tabela, string nomeProjeto)
        {
            string[]      item;// = new string[,];
            string        nomeColuna;
            string        tipoColuna;
            string        classe              = string.Empty;
            List <string> list                = peri.BuscarColunasTabela(conexao, tabela);
            string        tabelaSemLixo       = peri.RetiraLixoNomeTabela(tabela);
            string        colunaIdentificador = peri.cColunaIdentificador;

            classe = @"using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;
using System.Data;
using " + nomeProjeto + @".DTO;
using " + nomeProjeto + @".Exceptions;
using AttPsFw.Utils.Exceptions;// dll da framework da att


namespace " + nomeProjeto + @".DAO
{
    public class " + tabelaSemLixo + @"DAO 
    {
        #region Atributos

        private CriaConnectionString getConnection = new CriaConnectionString();
        private string ConnectionString = string.Empty;
        string StrCon;

        #endregion

        #region Construtor

        public " + tabelaSemLixo + @"DAO()
        {
            StrCon = getConnection.GetConnectionStringProd();
        }

        #endregion

        #region Metodos

        #region Seleção

        public DataTable Selecionar" + tabelaSemLixo + @"(" + tabelaSemLixo + @"DTO p" + tabelaSemLixo + @"DTO)
        {
            try
            {     
                DataTable dt = new DataTable();
                MySqlConnection Conexao = new MySqlConnection(StrCon);

                StringBuilder vSQLCommand = new StringBuilder();           
                vSQLCommand = new StringBuilder();
                vSQLCommand.AppendLine("" SELECT                    "");
";
            for (int i = 0; i < list.Count; i++)
            {
                item       = list[i].ToString().Split(';');
                nomeColuna = item[0].ToString();
                tipoColuna = item[1].ToString();

                if (nomeColuna.ToUpper() == "IDENTIFICADOR")
                {
                    nomeColuna = colunaIdentificador;
                }

                if (i + 1 < list.Count)
                {
                    classe = classe + @"
	            vSQLCommand.AppendLine("" "     + nomeColuna.ToUpper() + ",\");";
                }
                else
                {
                    classe = classe + @"
	            vSQLCommand.AppendLine("" "     + nomeColuna.ToUpper() + "\");";
                }
            }

            classe = classe + @"

                vSQLCommand.AppendLine("" FROM " + tabela.ToUpper() + @""");";

            classe = classe + @"
     
                vSQLCommand.AppendFormat("" WHERE (1=1) " + colunaIdentificador + " \");";

            // Recupera dados
            for (int i = 0; i < list.Count; i++)
            {
                item       = list[i].ToString().Split(';');
                nomeColuna = item[0].ToString();
                tipoColuna = item[1].ToString();

                if (nomeColuna.ToUpper() == "IDENTIFICADOR")
                {
                    nomeColuna = colunaIdentificador;
                }

                if (i + 1 < list.Count)
                {
                    if (tipoColuna == "Int32" || tipoColuna == "int")
                    {
                        classe = classe + @"
	            
                if (p" + tabelaSemLixo + @"DTO." + item[2].ToString() + @"!= default(int))
                    {
                        vSQLCommand.AppendLine(""and " + nomeColuna + @" = @" + nomeColuna + @" "");
                    }";
                    }

                    else if (tipoColuna == "DateTime" || tipoColuna == "dateTime")
                    {
                        classe = classe + @"
	            if (p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"!= default(DateTime))
                    {
                        vSQLCommand.AppendLine(""and " + nomeColuna + @" = @" + nomeColuna + @" "");
                    }";
                    }

                    else if (tipoColuna == "String" || tipoColuna == "string")
                    {
                        classe = classe + @"
	            if (!String.IsNullOrEmpty(p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"))
                    {
                        vSQLCommand.AppendLine(""and " + nomeColuna + @" = @" + nomeColuna + @" "");
                    }";
                    }

                    else if (tipoColuna == "Double" || tipoColuna == "double")
                    {
                        classe = classe + @"
	            if (p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"!= default(double))
                    {
                        vSQLCommand.AppendLine(""and " + nomeColuna + @" = @" + nomeColuna + @" "");
                    }";
                    }

                    else if (tipoColuna == "float" || tipoColuna == "Float")
                    {
                        classe = classe + @"
	            if (p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"!= default(float))
                    {
                        vSQLCommand.AppendLine(""and " + nomeColuna + @" = @" + nomeColuna + @" "");
                    }";
                    }
                }
            }

            classe = classe + @"
	             
                MySqlCommand com = new MySqlCommand(vSQLCommand.ToString(), Conexao);";


            for (int i = 0; i < list.Count; i++)
            {
                item       = list[i].ToString().Split(';');
                nomeColuna = item[0].ToString();
                tipoColuna = item[1].ToString();

                if (nomeColuna.ToUpper() == "IDENTIFICADOR")
                {
                    nomeColuna = colunaIdentificador;
                }

                if (i + 1 < list.Count)
                {
                    if (tipoColuna == "Int32" || tipoColuna == "int")
                    {
                        classe = classe + @"

	            if (p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"!= default(int))
                    {
                        com.Parameters.Add(new MySqlParameter(""@" + nomeColuna + @""", p" + tabelaSemLixo + @"DTO." + item[2].ToString() + @"));
                    }";
                    }

                    else if (tipoColuna == "DateTime" || tipoColuna == "dateTime")
                    {
                        classe = classe + @"
	            if (p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"!= default(DateTime))
                    {
                        com.Parameters.Add(new MySqlParameter(""@" + nomeColuna + @""", p" + tabelaSemLixo + @"DTO." + item[2].ToString() + @"));
                    }";
                    }

                    else if (tipoColuna == "String" || tipoColuna == "string")
                    {
                        classe = classe + @"
	            if (!String.IsNullOrEmpty(p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"))
                    {
                         com.Parameters.Add(new MySqlParameter(""@" + nomeColuna + @""", p" + tabelaSemLixo + @"DTO." + item[2].ToString() + @"));
                    }";
                    }

                    else if (tipoColuna == "Double" || tipoColuna == "double")
                    {
                        classe = classe + @"
	            if (p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"!= default(double))
                    {
                         com.Parameters.Add(new MySqlParameter(""@" + nomeColuna + @""", p" + tabelaSemLixo + @"DTO." + item[2].ToString() + @"));
                    }";
                    }

                    else if (tipoColuna == "float" || tipoColuna == "Float")
                    {
                        classe = classe + @"
	            if (p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"!= default(float))
                    {
                         com.Parameters.Add(new MySqlParameter(""@" + nomeColuna + @""", p" + tabelaSemLixo + @"DTO." + item[2].ToString() + @"));
                    }";
                    }
                }
            }

            classe = classe + @"     
                       
                Conexao.Open();
                dt.Load(com.ExecuteReader());
                com.ExecuteReader();
                Conexao.Close();

                return dt;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
    
        public DataTable Selecionar" + tabelaSemLixo + @"Pesquisar(" + tabelaSemLixo + @"DTO p" + tabelaSemLixo + @"DTO)
        {
            try
            {     
                DataTable dt = new DataTable();
                MySqlConnection Conexao = new MySqlConnection(StrCon);

                StringBuilder vSQLCommand = new StringBuilder();           
                vSQLCommand = new StringBuilder();
                vSQLCommand.AppendLine("" SELECT                    "");
";
            for (int i = 0; i < list.Count; i++)
            {
                item       = list[i].ToString().Split(';');
                nomeColuna = item[0].ToString();
                tipoColuna = item[1].ToString();

                if (nomeColuna.ToUpper() == "IDENTIFICADOR")
                {
                    nomeColuna = colunaIdentificador;
                }

                if (i + 1 < list.Count)
                {
                    classe = classe + @"
	            vSQLCommand.AppendLine("" "     + nomeColuna.ToUpper() + ",\");";
                }
                else
                {
                    classe = classe + @"
	            vSQLCommand.AppendLine("" "     + nomeColuna.ToUpper() + "\");";
                }
            }

            classe = classe + @"

                vSQLCommand.AppendLine("" FROM " + tabela.ToUpper() + @""");";

            classe = classe + @"
     
                vSQLCommand.AppendFormat("" WHERE (1=1) " + colunaIdentificador + " \");";

// Recupera dados
            for (int i = 0; i < list.Count; i++)
            {
                item       = list[i].ToString().Split(';');
                nomeColuna = item[0].ToString();
                tipoColuna = item[1].ToString();

                if (nomeColuna.ToUpper() == "IDENTIFICADOR")
                {
                    nomeColuna = colunaIdentificador;
                }

                if (i + 1 < list.Count)
                {
                    if (tipoColuna == "Int32" || tipoColuna == "int")
                    {
                        classe = classe + @"
	            
                if (p" + tabelaSemLixo + @"DTO." + item[2].ToString() + @"!= default(int))
                    {
                        vSQLCommand.AppendLine(""and " + nomeColuna + @" = @" + nomeColuna + @" "");
                    }";
                    }

                    else if (tipoColuna == "DateTime" || tipoColuna == "dateTime")
                    {
                        classe = classe + @"
	            if (p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"!= default(DateTime))
                    {
                        vSQLCommand.AppendLine(""and " + nomeColuna + @" = @" + nomeColuna + @" "");
                    }";
                    }

                    else if (tipoColuna == "String" || tipoColuna == "string")
                    {
                        classe = classe + @"
	            if (!String.IsNullOrEmpty(p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"))
                    {
                        vSQLCommand.AppendLine(""and " + nomeColuna + @" like @" + nomeColuna + @" "");
                    }";
                    }

                    else if (tipoColuna == "Double" || tipoColuna == "double")
                    {
                        classe = classe + @"
	            if (p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"!= default(double))
                    {
                        vSQLCommand.AppendLine(""and " + nomeColuna + @" = @" + nomeColuna + @" "");
                    }";
                    }

                    else if (tipoColuna == "float" || tipoColuna == "Float")
                    {
                        classe = classe + @"
	            if (p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"!= default(float))
                    {
                        vSQLCommand.AppendLine(""and " + nomeColuna + @" = @" + nomeColuna + @" "");
                    }";
                    }
                }
            }

            classe = classe + @"
	             
                MySqlCommand com = new MySqlCommand(vSQLCommand.ToString(), Conexao);";


            for (int i = 0; i < list.Count; i++)
            {
                item       = list[i].ToString().Split(';');
                nomeColuna = item[0].ToString();
                tipoColuna = item[1].ToString();

                if (nomeColuna.ToUpper() == "IDENTIFICADOR")
                {
                    nomeColuna = colunaIdentificador;
                }

                if (i + 1 < list.Count)
                {
                    if (tipoColuna == "Int32" || tipoColuna == "int")
                    {
                        classe = classe + @"

	            if (p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"!= default(int))
                    {
                        com.Parameters.Add(new MySqlParameter(""@" + nomeColuna + @""", p" + tabelaSemLixo + @"DTO." + item[2].ToString() + @"));
                    }";
                    }

                    else if (tipoColuna == "DateTime" || tipoColuna == "dateTime")
                    {
                        classe = classe + @"
	            if (p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"!= default(DateTime))
                    {
                        com.Parameters.Add(new MySqlParameter(""@" + nomeColuna + @""", p" + tabelaSemLixo + @"DTO." + item[2].ToString() + @"));
                    }";
                    }

                    else if (tipoColuna == "String" || tipoColuna == "string")
                    {
                        classe = classe + @"
	            if (!String.IsNullOrEmpty(p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"))
                    {
                         com.Parameters.Add(new MySqlParameter(""@" + nomeColuna + @""", ""%"" + p" + tabelaSemLixo + @"DTO." + item[2].ToString() + @" + ""%""));
                    }";
                    }

                    else if (tipoColuna == "Double" || tipoColuna == "double")
                    {
                        classe = classe + @"
	            if (p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"!= default(double))
                    {
                         com.Parameters.Add(new MySqlParameter(""@" + nomeColuna + @""", p" + tabelaSemLixo + @"DTO." + item[2].ToString() + @"));
                    }";
                    }

                    else if (tipoColuna == "float" || tipoColuna == "Float")
                    {
                        classe = classe + @"
	            if (p"     + tabelaSemLixo + @"DTO." + item[2].ToString() + @"!= default(float))
                    {
                         com.Parameters.Add(new MySqlParameter(""@" + nomeColuna + @""", p" + tabelaSemLixo + @"DTO." + item[2].ToString() + @"));
                    }";
                    }
                }
            }

            classe = classe + @"     
                       
                Conexao.Open();
                dt.Load(com.ExecuteReader());
                com.ExecuteReader();
                Conexao.Close();

                return dt;
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        #endregion

        #region Inserção

        public Boolean Insere" + tabelaSemLixo + @"(" + tabelaSemLixo + @"DTO p" + tabelaSemLixo + @"DTO)
        {
            try
            {
            MySqlConnection Conexao = new MySqlConnection(StrCon);
            StringBuilder vSQLCommand = new StringBuilder();
            vSQLCommand.AppendLine(""INSERT INTO " + tabela + @"("");";
            for (int i = 0; i < list.Count; i++)
            {
                item       = list[i].ToString().Split(';');
                nomeColuna = item[0].ToString();
                tipoColuna = item[1].ToString();

                if (nomeColuna.ToUpper() == "IDENTIFICADOR")
                {
                    nomeColuna = colunaIdentificador;
                }

                else if (i + 1 < list.Count)
                {
                    if (nomeColuna.ToUpper() != "IDENTIFICADOR")
                    {
                        classe = classe + @"
	        vSQLCommand.AppendLine("""     + nomeColuna.ToUpper() + ",\");";
                    }
                }
                else
                {
                    if (nomeColuna.ToUpper() != "IDENTIFICADOR")
                    {
                        classe = classe + @"
	        vSQLCommand.AppendLine("""     + nomeColuna.ToUpper() + ") values (\");";
                    }
                    else
                    {
                        classe = classe + @"
            vSQLCommand.AppendLine("") values (";
                    }

                    for (int x = 0; x < list.Count; x++)
                    {
                        item       = list[x].ToString().Split(';');
                        nomeColuna = item[0].ToString();
                        tipoColuna = item[1].ToString();
                        //classe = classe + "{" + x + "},";
                        //if (x + 1 == list.Count)
                        //    classe = classe + "{" + x + "})  \");";
                        if (item[2].ToString().ToUpper() == "IDENTIFICADOR")
                        {
                            classe = classe + @"
            //com.Parameters.Add(new MySqlParameter(""@" + colunaIdentificador + @""", p" + tabelaSemLixo + @"DTO.Identificador));";
                        }
                        else
                        {
                            if (x + 1 < list.Count)
                            {
                                classe = classe + @"
            vSQLCommand.AppendLine("" @" + nomeColuna + ",\");";
                            }
                            else if (x + 1 == list.Count)
                            {
                                classe = classe + @"
            vSQLCommand.AppendLine("" @" + nomeColuna + ")\");";
                            }
                        }
                    }
                }
            }

            classe = classe + @"
            MySqlCommand com = new MySqlCommand(vSQLCommand.ToString(), Conexao);";

            for (int x = 0; x < list.Count; x++)
            {
                item       = list[x].ToString().Split(';');
                nomeColuna = item[0].ToString();
                tipoColuna = item[1].ToString();
                //na acrescenta a coluna identificador
                if (item[2].ToString().ToUpper() == "IDENTIFICADOR")
                {
                    classe = classe + @"
            //com.Parameters.Add(new MySqlParameter(""@" + colunaIdentificador + @""", p" + tabelaSemLixo + @"DTO.Identificador));";
                }
                else
                {
                    //classe = classe + "{" + x + "}) where " + colunaIdentificador + " = {" + x + "}\");";
                    classe = classe + @"
                                            
            com.Parameters.Add(new MySqlParameter(""@" + nomeColuna + @""", p" + tabelaSemLixo + @"DTO." + item[2].ToString() + @"));";

                    //else
                    //    classe = classe + "{" + x + "},";
                }
            }

            classe = classe + @" 
            Conexao.Open();
            //dt.Load(com.ExecuteReader());
            com.ExecuteReader();
            Conexao.Close();

            return true;
        }
        catch (Exception e)
        {

            throw e;
        }
    }


        #endregion

        #region Atualização

        

        public Boolean Altera" + tabelaSemLixo + @"(" + tabelaSemLixo + @"DTO p" + tabelaSemLixo + @"DTO)
        {
            try
            {
                 DataTable dt = new DataTable();
                 MySqlConnection Conexao = new MySqlConnection(StrCon);
                 StringBuilder vSQLCommand = new StringBuilder();
                 vSQLCommand.AppendLine(""UPDATE " + tabela + @" SET"");";
            for (int i = 0; i < list.Count; i++)
            {
                item       = list[i].ToString().Split(';');
                nomeColuna = item[0].ToString();
                tipoColuna = item[1].ToString();

                if (nomeColuna.ToUpper() == "IDENTIFICADOR")
                {
                    nomeColuna = colunaIdentificador;
                }

                else if (nomeColuna.ToUpper() != "IDENTIFICADOR")
                {
                    if (i + 1 < list.Count)
                    {
                        classe = classe + @"
                 vSQLCommand.AppendLine(""" + nomeColuna.ToUpper() + " = @" + nomeColuna.ToUpper() + ", \");";
                    }
                    else if (i + 1 == list.Count)
                    {
                        classe = classe + @"
                 vSQLCommand.AppendLine(""" + nomeColuna.ToUpper() + " = @" + nomeColuna.ToUpper() + " \");";
                    }
                    if (i + 2 > list.Count)
                    {
                        classe = classe + @"
	             vSQLCommand.AppendLine("" WHERE 1 = 1 "");

                 if (p" + tabelaSemLixo + @"DTO.Identificador != default(int))
                       {
                          vSQLCommand.AppendLine(""and " + colunaIdentificador + @" = @" + colunaIdentificador + @" "");
                       }
                
                 MySqlCommand com = new MySqlCommand(vSQLCommand.ToString(), Conexao);";

                        for (int x = 0; x < list.Count; x++)
                        {
                            item       = list[x].ToString().Split(';');
                            nomeColuna = item[0].ToString();
                            tipoColuna = item[1].ToString();
                            //na acrescenta a coluna identificador
                            if (item[2].ToString().ToUpper() == "IDENTIFICADOR")
                            {
                                classe = classe + @"
                 com.Parameters.Add(new MySqlParameter(""@" + colunaIdentificador + @""", p" + tabelaSemLixo + @"DTO.Identificador));";
                            }
                            else
                            {
                                //classe = classe + "{" + x + "}) where " + colunaIdentificador + " = {" + x + "}\");";
                                classe = classe + @"
                                            
                 com.Parameters.Add(new MySqlParameter(""@" + nomeColuna + @""", p" + tabelaSemLixo + @"DTO." + item[2].ToString() + @"));";

                                //else
                                //    classe = classe + "{" + x + "},";
                            }
                        }

                        classe = classe + @" 
                    Conexao.Open();
                    //dt.Load(com.ExecuteReader());
                    com.ExecuteReader();
                    Conexao.Close();

                    return true;
                }
                catch (Exception e)
                {
                    throw e;
                }
            }";
                    }
                }
            }


            classe = classe + @"   
                

        #endregion
        
        #region Exclusao
        
        public Boolean Excluir" + tabelaSemLixo + @"(" + tabelaSemLixo + @"DTO p" + tabelaSemLixo + @"DTO )
        {
            try
            {
                DataTable dt = new DataTable();
                MySqlConnection Conexao = new MySqlConnection(StrCon);
                StringBuilder vSQLCommand = new StringBuilder();

                vSQLCommand.AppendLine(""DELETE FROM " + tabela + @""");

                vSQLCommand.AppendLine("" WHERE 1 = 1 "");

                if (p" + tabelaSemLixo + @"DTO.Identificador != default(int))
                {
                    vSQLCommand.AppendLine(""and " + colunaIdentificador + @" = @" + colunaIdentificador + @" "");
                }
                
                MySqlCommand com = new MySqlCommand(vSQLCommand.ToString(), Conexao);

                if (p" + tabelaSemLixo + @"DTO.Identificador != default(int))
                {
                    com.Parameters.Add(new MySqlParameter(""@" + colunaIdentificador + @""", p" + tabelaSemLixo + @"DTO.Identificador));
                }
                Conexao.Open();
                //dt.Load(com.ExecuteReader());
                com.ExecuteReader();
                Conexao.Close();

                return true;
            
            }
            catch (DataAccessException ex)
            {
                // Verifica se ocorreu erro de constraint
                if (ex.InnerException is SqlException)
                {
                    if (((SqlException)ex.InnerException).Number == 547)
                        throw new RegistroEmUso();
                    else
                        throw;
                }
                else
                    throw;
            }
            catch (Exception e)
            {
                int pos = 0;
                pos = e.Message.ToString().IndexOf(""Cannot delete or update a parent row: a foreign key constraint fails ("");
                if (pos > 0)
                {
                    throw new RegistroEmUso();
                }
                else
                throw new DataAccessException(""Ocorreu um erro ao excluir o Cliente."", DataAccessExceptionLocation.DAO, e);
            }
        }
        #endregion

        #endregion
    }
}
";

            return(classe);
        }
Esempio n. 4
0
        public void CriarClasses(string pNomeProjeto, string pCaminhoProjeto, string pConexao, string pTabela)
        {
            try
            {
                Periferica peri = new Periferica();
                //Entidade ent = new Entidade();
                //Constantes constantes = new Constantes();
                DTO        dto        = new DTO();
                DAOs       daos       = new DAOs();
                Controller controller = new Controller();
                //Mapper mappers = new Mapper();
                List <string> listLocalSalv = new List <string>();
                string        retDTO        = String.Empty;
                string        retDAO        = String.Empty;
                string        retCT         = String.Empty;

                string nomeProjeto = pNomeProjeto != string.Empty ? pNomeProjeto : comboBox1.SelectedItem.ToString();
                //nomeProjeto = nomeProjeto;

                //string retEnt = ent.GerarClasseEntidade(pConexao, pTabela, nomeProjeto);
                //string retConstantes = constantes.GerarClasseConstantesDB(pConexao, pTabela, nomeProjeto);
                if (cbDTO.Checked == true)
                {
                    retDTO = dto.GerarClasseDTO(pConexao, pTabela, nomeProjeto);
                }

                if (cbDAO.Checked == true)
                {
                    retDAO = daos.GerarClasseDAOs(pConexao, pTabela, nomeProjeto);
                }

                if (cbController.Checked == true)
                {
                    retCT = controller.GerarClasseCTs(pConexao, pTabela, nomeProjeto);
                }

                //string retMAPPER = mappers.GerarClasseConstantesDB(pConexao, pTabela, nomeProjeto);
                string path = string.Empty;

                //nomeArquivoEntidade = peri.RetiraLixoNomeTabela(pTabela) + "Entidade.cs";
                nomeArquivoDAO = peri.RetiraLixoNomeTabela(pTabela) + "DAO.cs";
                nomeArquivoDTO = peri.RetiraLixoNomeTabela(pTabela) + "DTO.cs";
                nomeArquivoCT  = peri.RetiraLixoNomeTabela(pTabela) + "CT.cs";
                //nomeArquivoMAPPER = peri.RetiraLixoNomeTabela(pTabela) + "Mapper.cs";

                if (!Directory.Exists(pCaminhoProjeto))
                {
                    Directory.CreateDirectory("D:\\GeradorClasses");
                }

                if (pCaminhoProjeto == "D:\\GeradorClasses" || pCaminhoProjeto == string.Empty)
                {
                    path = "D:\\GeradorClasses\\";
                }
                else
                {
                    path = pCaminhoProjeto + "\\";
                }

                //if (File.Exists(path + nomeProjeto + ".Entidades\\" + nomeArquivoEntidade))
                //    nomeArquivoEntidade = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + nomeArquivoEntidade + "Entidade.cs";

                if (File.Exists(path + nomeProjeto + ".DAO\\" + nomeArquivoDAO))
                {
                    nomeArquivoDAO = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + pTabela + "DAO.cs";
                }

                if (File.Exists(path + nomeProjeto + ".DTO\\" + nomeArquivoDTO))
                {
                    nomeArquivoDTO = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + pTabela + "DTO.cs";
                }

                if (File.Exists(path + nomeProjeto + ".Controller\\" + nomeArquivoCT))
                {
                    nomeArquivoCT = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + pTabela + "CT.cs";
                }



                StreamWriter stre;

                if (Directory.Exists(path + nomeProjeto + ".DAO\\"))
                {
                    stre = new StreamWriter(path + nomeProjeto + ".DAO\\" + nomeArquivoDAO);
                    listLocalSalv.Add(path + nomeProjeto + ".DAO\\" + nomeArquivoDAO);
                }
                else
                {
                    stre = new StreamWriter(path + nomeArquivoDAO);
                    listLocalSalv.Add(path + nomeProjeto + ".DAO\\" + nomeArquivoDAO);
                }

                if (cbDAO.Checked == true)
                {
                    stre.Write(retDAO);
                }

                stre.Close();


                if (Directory.Exists(path + nomeProjeto + ".DTO\\"))
                {
                    stre = new StreamWriter(path + nomeProjeto + ".DTO\\" + nomeArquivoDTO);
                    listLocalSalv.Add(path + nomeProjeto + ".DTO\\" + nomeArquivoDTO);
                }
                else
                {
                    stre = new StreamWriter(path + nomeArquivoDTO);
                    listLocalSalv.Add(path + nomeArquivoDTO);
                }


                if (cbDTO.Checked == true)
                {
                    stre.Write(retDTO);
                }

                stre.Close();


                if (Directory.Exists(path + nomeProjeto + ".Controller\\"))
                {
                    stre = new StreamWriter(path + nomeProjeto + ".Controller\\" + nomeArquivoCT);
                    listLocalSalv.Add(path + nomeProjeto + ".Controller\\" + nomeArquivoCT);
                }
                else
                {
                    stre = new StreamWriter(path + nomeArquivoDAO);
                    listLocalSalv.Add(path + nomeProjeto + ".Controller\\" + nomeArquivoCT);
                }

                if (cbController.Checked == true)
                {
                    stre.Write(retCT);
                }


                stre.Close();


                //if (Directory.Exists(path + nomeProjeto + ".Mappers\\"))
                //{
                //    stre = new StreamWriter(path + nomeProjeto + ".Mappers\\" + nomeArquivoMAPPER);
                //    listLocalSalv.Add(path + nomeProjeto + ".Mappers\\" + nomeArquivoMAPPER);
                //}
                //else
                //{
                //    stre = new StreamWriter(path + nomeArquivoMAPPER);
                //    listLocalSalv.Add(path + nomeArquivoMAPPER);
                //}

                //stre.Write(retMAPPER);

                //stre.Close();

                //if (Directory.Exists(path + nomeProjeto + ".DAOs\\"))
                //{
                //    stre = new StreamWriter(path + nomeProjeto + ".DAOs\\" + nomeArquivoDAO);
                //    listLocalSalv.Add(path + nomeProjeto + ".DAOs\\" + nomeArquivoDAO);
                //}
                //else
                //{
                //    stre = new StreamWriter(path + nomeArquivoDAO);
                //    listLocalSalv.Add(path + nomeArquivoDAO);
                //}

                //stre.Write(retDAO);

                //stre.Close();

                string msg = string.Empty;


                for (int i = 0; i < listLocalSalv.Count; i++)
                {
                    msg += Environment.NewLine + listLocalSalv[i].ToString();
                }

                //MsgBox msgB = new MsgBox(listLocalSalv, false, string.Empty);
                //msgB.Show();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }