Beispiel #1
0
 public void CreateAdmin_PasswordIsNull_ThrowsArgumentNullException()
 {
     using (var library = new Library.Library())
     {
         library.CreateAdmin(null);
     }
 }
 static int Main(string[] args)
 {
     if (args.Length >= 3 && args[0].Equals("run"))
     {
         var             library = new Library.Library();
         List <string[]> files   = ReadFile(args.Skip(1).ToArray());
         if (files == null)
         {
             return(1);
         }
         foreach (string[] test in files)
         {
             PrintArray(test);
         }
         if (library.CheckFiles(files))
         {
             string[] combined = library.CombineFiles(files);
             PrintArray(combined);
         }
         else
         {
             Console.WriteLine("ERROR: The file have no equals sizes");
         }
     }
     else
     {
         Console.WriteLine("ERROR: To less arguments");
     }
     return(0);
 }
Beispiel #3
0
 public void CreateAdmin_PasswordIsEmpty_ThrowsArgumentException()
 {
     using (var library = new Library.Library())
     {
         library.CreateAdmin(String.Empty);
     }
 }
Beispiel #4
0
 public void CreateAdmin_PasswordIsWhitespace_ThrowsArgumentException()
 {
     using (var library = new Library.Library())
     {
         library.CreateAdmin(" ");
     }
 }
Beispiel #5
0
 public void PlayPreviousSong_PlaylistIsEmpty_ThrowsInvalidOperationException()
 {
     using (var library = new Library.Library())
     {
         library.PlayPreviousSong();
     }
 }
Beispiel #6
0
 public void PlaySong_IndexIsLessThanZero_ThrowsArgumentOutOfRangeException()
 {
     using (var library = new Library.Library())
     {
         library.PlaySong(-1);
     }
 }
Beispiel #7
0
        public void AutoNextSong_SongIsCaching_SwapSongs()
        {
            var eventWait = new ManualResetEvent(false); // We need this, because Library.PlaySong() pops up a new thread interally and then returns

            var jumpAudioPlayer = new JumpAudioPlayer();

            var jumpSong = new Mock<Song>("JumpSong", AudioType.Mp3, TimeSpan.Zero);
            jumpSong.Setup(p => p.CreateAudioPlayer()).Returns(jumpAudioPlayer);
            jumpSong.SetupGet(p => p.HasToCache).Returns(false);

            var foreverAudioPlayer = new Mock<AudioPlayer>();
            foreverAudioPlayer.SetupProperty(p => p.Volume);
            foreverAudioPlayer.Setup(p => p.Play()).Callback(() => { }); // Never raises SongFinished

            var cachingSong = new Mock<Song>("CachingSong", AudioType.Mp3, TimeSpan.Zero);
            cachingSong.SetupGet(p => p.HasToCache).Returns(true);
            cachingSong.Setup(p => p.CreateAudioPlayer()).Returns(foreverAudioPlayer.Object);

            var cachingSong2 = new Mock<Song>("CachingSong2", AudioType.Mp3, TimeSpan.Zero);
            cachingSong2.SetupGet(p => p.HasToCache).Returns(true);

            var nextSong = new Mock<Song>("NextSong", AudioType.Mp3, TimeSpan.Zero);
            nextSong.Setup(p => p.CreateAudioPlayer()).Returns(jumpAudioPlayer);
            nextSong.SetupGet(p => p.HasToCache).Returns(false);

            using (var library = new Library.Library())
            {
                int finished = 0;

                // We need to wait till the second played song has finished and then release our lock,
                // otherwise it would directly call the assertion, without anything changed
                library.SongFinished += (sender, e) =>
                {
                    finished++;

                    if (finished == 2)
                    {
                        eventWait.Set();
                    }
                };

                IEnumerable<Song> songs = new[]
                {
                    jumpSong.Object, cachingSong.Object, cachingSong2.Object, nextSong.Object
                };

                library.AddSongsToPlaylist(songs);

                library.PlaySong(0);

                eventWait.WaitOne();

                IEnumerable<Song> expectedSongs = new[]
                {
                    jumpSong.Object, nextSong.Object, cachingSong.Object, cachingSong2.Object
                };

                Assert.IsTrue(expectedSongs.SequenceEqual(library.Playlist));
            }
        }
Beispiel #8
0
 // Constructor
 public Book(int bookId, string title, string summary, Library.Library library)
 {
     this.bookId    = bookId;
     this.title     = title;
     this.summary   = summary;
     this.library   = library;
     this.libraryId = library.LibraryId;
 }
Beispiel #9
0
        public void ChangeToAdmin_PasswordIsNotCorrent_ThrowsInvalidOperationException()
        {
            using (var library = new Library.Library())
            {
                library.CreateAdmin("TestPassword");

                library.ChangeToAdmin("WrongPassword");
            }
        }
Beispiel #10
0
        public void CreateAdmin_PasswordIsTestPassword_AdministratorIsCreated()
        {
            using (var library = new Library.Library())
            {
                library.CreateAdmin("TestPassword");

                Assert.IsTrue(library.IsAdministratorCreated);
            }
        }
Beispiel #11
0
 public void PlayNextSong_UserIsNotAdministrator_ThrowsInvalidOperationException()
 {
     using (var library = new Library.Library())
     {
         library.CreateAdmin("TestPassword");
         library.ChangeToParty();
         library.PlayNextSong();
     }
 }
Beispiel #12
0
        public void ChangeToAdmin_PasswordIsCorrent_AccessModeIsAdministrator()
        {
            using (var library = new Library.Library())
            {
                library.CreateAdmin("TestPassword");
                library.ChangeToAdmin("TestPassword");

                Assert.AreEqual(AccessMode.Administrator, library.AccessMode);
            }
        }
Beispiel #13
0
        public void AddSongsToPlaylist_PartyModeAndMultipleSongsAdded_ThrowsInvalidOperationException()
        {
            var songs = new[] { new LocalSong("TestPath", AudioType.Mp3, TimeSpan.Zero), new LocalSong("TestPath", AudioType.Mp3, TimeSpan.Zero) };

            using (var library = new Library.Library())
            {
                library.CreateAdmin("TestPassword");
                library.ChangeToParty();

                library.AddSongsToPlaylist(songs);
            }
        }
Beispiel #14
0
        public void DoesReturnAceOfHearts()
        {
            var cardgame = new Library.Library();

            var input = "ah";

            var expectedOutput = "Ace of Hearts";

            var actualOutput = cardgame.Returner(input);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
Beispiel #15
0
        public void AddSongsToPlaylist_PartyModeAndMultipleSongsAdded_ThrowsInvalidOperationException()
        {
            var songs = new[] { new LocalSong("TestPath", AudioType.Mp3, TimeSpan.Zero), new LocalSong("TestPath", AudioType.Mp3, TimeSpan.Zero) };

            using (var library = new Library.Library())
            {
                library.CreateAdmin("TestPassword");
                library.ChangeToParty();

                library.AddSongsToPlaylist(songs);
            }
        }
Beispiel #16
0
        public void InputCheckerShortNumber()
        {
            var cardgame = new Library.Library();

            var input = "ah";

            var expectedOutput = true;

            var actualOutput = cardgame.InputChecker(input);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
Beispiel #17
0
        public void InputCheckerLongNumber()
        {
            var cardgame = new Library.Library();

            var input = "33c";

            var expectedOutput = false;

            var actualOutput = cardgame.InputChecker(input);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
Beispiel #18
0
        public void RemoveFromPlaylist_AccessModeIsParty_ThrowsInvalidOperationException()
        {
            var songMock = new Mock <Song>("TestPath", AudioType.Mp3, TimeSpan.Zero);

            using (var library = new Library.Library())
            {
                library.ChangeToParty();

                library.AddSongsToPlaylist(new[] { songMock.Object });

                library.RemoveFromPlaylist(new[] { 0 });
            }
        }
Beispiel #19
0
        public virtual Library.Library CreateLibrary(HttpContext context)
        {
            YZRequest request          = new YZRequest(context);
            string    libType          = request.GetString("libType");
            string    FolderID         = request.GetString("FolderID", null);
            string    DocumentFolderID = request.GetString("DocumentFolderID", null);
            JObject   jPost            = request.GetPostData <JObject>();

            Library.Library libPost = jPost["data"].ToObject <Library.Library>();
            ACL             acl     = jPost["acl"].ToObject <ACL>();

            using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider)
            {
                using (IDbConnection cn = provider.OpenConnection())
                {
                    Library.Library lib = new Library.Library();
                    lib.LibType = libType;
                    lib.Name    = libPost.Name;
                    lib.Desc    = libPost.Desc;

                    if (!String.IsNullOrEmpty(FolderID))
                    {
                        Folder folder = this.CreateLibFolder(provider, cn, libPost.Name, FolderID);
                        lib.FolderID = folder.FolderID;
                    }

                    if (!String.IsNullOrEmpty(DocumentFolderID))
                    {
                        Folder folder = this.CreateLibFolder(provider, cn, libPost.Name, DocumentFolderID);
                        lib.DocumentFolderID = folder.FolderID;
                    }

                    lib.Owner       = YZAuthHelper.LoginUserAccount;
                    lib.CreateAt    = DateTime.Now;
                    lib.ImageFileID = libPost.ImageFileID;
                    lib.OrderIndex  = LibraryManager.GetLibraryNextOrderIndex(provider, cn, libType);
                    lib.Deleted     = false;

                    LibraryManager.Insert(provider, cn, lib);

                    using (BPMConnection bpmcn = new BPMConnection())
                    {
                        bpmcn.WebOpen();
                        SecurityManager.SaveACL(bpmcn, SecurityResType.Library, lib.LibID.ToString(), null, acl);
                    }

                    return(lib);
                }
            }
        }
Beispiel #20
0
        public void RemoveFromPlaylist_SongIsPlaying_CurrentPlayerIsStopped()
        {
            var audioPlayerMock = new Mock <AudioPlayer>();

            var songMock = new Mock <Song>("TestPath", AudioType.Mp3, TimeSpan.Zero);

            songMock.Setup(p => p.CreateAudioPlayer()).Returns(audioPlayerMock.Object);

            using (var library = new Library.Library())
            {
                library.AddSongsToPlaylist(new[] { songMock.Object });

                library.PlaySong(0);

                library.RemoveFromPlaylist(new[] { 0 });

                audioPlayerMock.Verify(p => p.Stop(), Times.Once());
            }
        }
Beispiel #21
0
        public virtual Library.Library UpdateLibrary(HttpContext context)
        {
            YZRequest request        = new YZRequest(context);
            int       libid          = request.GetInt32("libid");
            bool      updateProperty = request.GetBool("property", true);
            bool      updateAcl      = request.GetBool("acl", true);
            JObject   jPost          = request.GetPostData <JObject>();

            Library.Library libPost = jPost["data"].ToObject <Library.Library>();
            ACL             acl     = jPost["acl"].ToObject <ACL>();

            using (IYZDbProvider provider = YZDbProviderManager.DefaultProvider)
            {
                using (IDbConnection cn = provider.OpenConnection())
                {
                    Library.Library lib = LibraryManager.GetLibrary(provider, cn, libid);

                    if (updateProperty)
                    {
                        lib.ImageFileID = libPost.ImageFileID;
                        lib.Name        = libPost.Name;
                        lib.Desc        = libPost.Desc;

                        LibraryManager.Update(provider, cn, lib);
                    }

                    if (updateAcl)
                    {
                        using (BPMConnection bpmcn = new BPMConnection())
                        {
                            bpmcn.WebOpen();
                            SecurityManager.SaveACL(bpmcn, SecurityResType.Library, lib.LibID.ToString(), null, acl);
                        }
                    }

                    return(lib);
                }
            }
        }
Beispiel #22
0
 public void PlayPreviousSong_PlaylistIsEmpty_ThrowsInvalidOperationException()
 {
     using (var library = new Library.Library())
     {
         library.PlayPreviousSong();
     }
 }
Beispiel #23
0
        public void RemoveFromPlaylist_SongIsPlaying_CurrentPlayerIsStopped()
        {
            var audioPlayerMock = new Mock<AudioPlayer>();

            var songMock = new Mock<Song>("TestPath", AudioType.Mp3, TimeSpan.Zero);
            songMock.Setup(p => p.CreateAudioPlayer()).Returns(audioPlayerMock.Object);

            using (var library = new Library.Library())
            {
                library.AddSongsToPlaylist(new[] { songMock.Object });

                library.PlaySong(0);

                library.RemoveFromPlaylist(new[] { 0 });

                audioPlayerMock.Verify(p => p.Stop(), Times.Once());
            }
        }
        // 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);
        }
        // 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);
        }
Beispiel #26
0
        public void ChangeToAdmin_PasswordIsNotCorrent_ThrowsInvalidOperationException()
        {
            using (var library = new Library.Library())
            {
                library.CreateAdmin("TestPassword");

                library.ChangeToAdmin("WrongPassword");
            }
        }
Beispiel #27
0
        public void PlaySong_UserIsNotAdministrator_ThrowsInvalidOperationException()
        {
            using (var library = new Library.Library())
            {
                library.CreateAdmin("TestPassword");
                library.ChangeToParty();

                library.PlaySong(0);
            }
        }
Beispiel #28
0
 public void CreateAdmin_PasswordIsEmpty_ThrowsArgumentException()
 {
     using (var library = new Library.Library())
     {
         library.CreateAdmin(String.Empty);
     }
 }
Beispiel #29
0
 public void CreateAdmin_PasswordIsNull_ThrowsArgumentNullException()
 {
     using (var library = new Library.Library())
     {
         library.CreateAdmin(null);
     }
 }
Beispiel #30
0
        public void CreateAdmin_PasswordIsTestPassword_AdministratorIsCreated()
        {
            using (var library = new Library.Library())
            {
                library.CreateAdmin("TestPassword");

                Assert.IsTrue(library.IsAdministratorCreated);
            }
        }
Beispiel #31
0
        public void ChangeToAdmin_PasswordIsCorrent_AccessModeIsAdministrator()
        {
            using (var library = new Library.Library())
            {
                library.CreateAdmin("TestPassword");
                library.ChangeToAdmin("TestPassword");

                Assert.AreEqual(AccessMode.Administrator, library.AccessMode);
            }
        }
Beispiel #32
0
        public void AutoNextSong_SongIsCaching_SwapSongs()
        {
            var eventWait = new ManualResetEvent(false); // We need this, because Library.PlaySong() pops up a new thread interally and then returns

            var jumpAudioPlayer = new JumpAudioPlayer();

            var jumpSong = new Mock <Song>("JumpSong", AudioType.Mp3, TimeSpan.Zero);

            jumpSong.Setup(p => p.CreateAudioPlayer()).Returns(jumpAudioPlayer);
            jumpSong.SetupGet(p => p.HasToCache).Returns(false);

            var foreverAudioPlayer = new Mock <AudioPlayer>();

            foreverAudioPlayer.SetupProperty(p => p.Volume);
            foreverAudioPlayer.Setup(p => p.Play()).Callback(() => { }); // Never raises SongFinished

            var cachingSong = new Mock <Song>("CachingSong", AudioType.Mp3, TimeSpan.Zero);

            cachingSong.SetupGet(p => p.HasToCache).Returns(true);
            cachingSong.Setup(p => p.CreateAudioPlayer()).Returns(foreverAudioPlayer.Object);

            var cachingSong2 = new Mock <Song>("CachingSong2", AudioType.Mp3, TimeSpan.Zero);

            cachingSong2.SetupGet(p => p.HasToCache).Returns(true);

            var nextSong = new Mock <Song>("NextSong", AudioType.Mp3, TimeSpan.Zero);

            nextSong.Setup(p => p.CreateAudioPlayer()).Returns(jumpAudioPlayer);
            nextSong.SetupGet(p => p.HasToCache).Returns(false);

            using (var library = new Library.Library())
            {
                int finished = 0;

                // We need to wait till the second played song has finished and then release our lock,
                // otherwise it would directly call the assertion, without anything changed
                library.SongFinished += (sender, e) =>
                {
                    finished++;

                    if (finished == 2)
                    {
                        eventWait.Set();
                    }
                };

                IEnumerable <Song> songs = new[]
                {
                    jumpSong.Object, cachingSong.Object, cachingSong2.Object, nextSong.Object
                };

                library.AddSongsToPlaylist(songs);

                library.PlaySong(0);

                eventWait.WaitOne();

                IEnumerable <Song> expectedSongs = new[]
                {
                    jumpSong.Object, nextSong.Object, cachingSong.Object, cachingSong2.Object
                };

                Assert.IsTrue(expectedSongs.SequenceEqual(library.Playlist));
            }
        }
        // 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);
        }
Beispiel #34
0
 public void PlaySong_IndexIsLessThanZero_ThrowsArgumentOutOfRangeException()
 {
     using (var library = new Library.Library())
     {
         library.PlaySong(-1);
     }
 }
Beispiel #35
0
 public void CreateAdmin_PasswordIsWhitespace_ThrowsArgumentException()
 {
     using (var library = new Library.Library())
     {
         library.CreateAdmin(" ");
     }
 }
Beispiel #36
0
        public void RemoveFromPlaylist_AccessModeIsParty_ThrowsInvalidOperationException()
        {
            var songMock = new Mock<Song>("TestPath", AudioType.Mp3, TimeSpan.Zero);

            using (var library = new Library.Library())
            {
                library.ChangeToParty();

                library.AddSongsToPlaylist(new[] { songMock.Object });

                library.RemoveFromPlaylist(new[] { 0 });
            }
        }