Example #1
0
        /// <summary>
        /// Classe Dao
        /// </summary>
        /// <param name="NomeTabela"></param>
        /// <param name="NameSpace"></param>
        /// <returns></returns>
        public string CriandoClasseDao(string NomeTabela, string NameSpace, string NameSchema)
        {
            Using            = string.Empty;
            NameSpaceProjeto = string.Empty;
            NomeClasse       = string.Empty;
            Atributo         = string.Empty;

            NomeTabelaSemSchema = string.Empty;

            if (NameSchema.Equals(NomeTabela.Substring(0, 3)))
            {
                var _NomeTabela   = NomeTabela.Remove(0, 3);
                var _PrimeiroNome = _NomeTabela.Substring(0, 1);
                var _RestoNome    = NomeTabela.Remove(0, 4);
                NomeTabelaSemSchema = _PrimeiroNome + _RestoNome.ToLower();
            }
            else
            {
                //var _NomeTabela = NomeTabela.Remove(0, 3);
                var _PrimeiroNome = NomeTabela.Substring(0, 1);
                var _RestoNome    = NomeTabela.Remove(0, 1);
                NomeTabelaSemSchema = _PrimeiroNome + _RestoNome.ToLower();
            }

            dir = new Diretorio();
            string _NameSpacesFisico = path + dir.DirInfraDaoFisico(NameSpace);
            string _NameSpacesLogico = dir.DirInfraDaoLogico(NameSpace);

            NaoExisteClasse = _NameSpacesFisico + NomeTabelaSemSchema + "Dao.cs";

            //// Determine whether the directory exists.
            //if (Directory.Exists(@path))
            //{
            //    ExisteArquivo = System.IO.File.Exists(NaoExisteClasse);
            //    if (ExisteArquivo)
            //        return "Essa classe já existe.";
            //}

            Using += "using SEACore.Contexto;" + Environment.NewLine;
            Using += "using SEACore.Infra.Entidades;" + Environment.NewLine;
            Using += "using SEACore.Infra.Interfaces;" + Environment.NewLine;
            Using += "using SEACore.Repositorio;" + Environment.NewLine;

            NameSpaceProjeto += "namespace " + dir.DirInfraDaoLogico(NameSpace);
            NameSpaceProjeto += Environment.NewLine;
            NameSpaceProjeto += "{";
            NameSpaceProjeto += Environment.NewLine;

            //Nome da classe
            NomeClasse  = "\tpublic class " + NomeTabelaSemSchema + "Dao " + ": Repositorio<" + NomeTabelaSemSchema + ">, " + "I" + NomeTabelaSemSchema + Environment.NewLine;
            NomeClasse += "\t{";
            NomeClasse += Environment.NewLine;

            //Método Construtor da Classe
            NomeClasse += "\t\tpublic " + NomeTabelaSemSchema + "Dao(SEAContexto db) : base(db) { }" + Environment.NewLine;

            NomeClasse       += "\t}";
            NameSpaceProjeto += NomeClasse;
            NameSpaceProjeto += Environment.NewLine;
            NameSpaceProjeto += "}";
            Using            += NameSpaceProjeto;

            using (FileStream fs = new FileStream(NaoExisteClasse, FileMode.Create))
            {
                using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
                {
                    w.WriteLine(Using);
                }
            }
            return("Classe " + NomeTabelaSemSchema + "Dao.cs criada com sucesso. Caminho: " + _NameSpacesFisico + NomeTabelaSemSchema + "Dao.cs");
        }