Esempio n. 1
0
        private static void processaPasta(string pasta, Simple.Sqlite.SqliteDB db)
        {
            foreach (var arquivo in Directory.GetFiles(pasta, "*.zip"))
            {
                bool militar = arquivo.Contains("_Militares");

                processaArquivo(arquivo, militar, db);
            }
        }
Esempio n. 2
0
        public static void run(Simple.Sqlite.SqliteDB db)
        {
            db.CreateTables()
            .Add <ServidoresCadastroModel>()
            .Commit();

            Console.WriteLine("Entre com a pasta:");
            string pasta = Console.ReadLine();

            uids = new HashSet <string>();
            processaPasta(pasta, db);
        }
Esempio n. 3
0
        private static void processaArquivo(string zipName, bool militar, Simple.Sqlite.SqliteDB db)
        {
            var zip = new LeitorZipTransparencia(zipName);

            zip.ShouldProcessFile     = n => n.Contains("_Cadastro");
            zip.IgnoreFirstLine       = true;
            zip.InicioLeituraArquivo += (s, a) => Console.WriteLine($"Lendo {a}");

            var zipLines = zip.ReadLines();
            var rows     = CSVHelper.DelimiterSplit(zipLines, ';');

            var buffer = new DataBuffer <ServidoresCadastroModel>(10000, data => db.BulkInsert(data, addReplace: true));

            foreach (var row in rows)
            {
                var cad = new ServidoresCadastroModel()
                {
                    ServidorCadastroMilitar = militar,

                    ID_ServidorPortal = row[0].ToInt(),
                    Nome         = row[1],
                    CPF_6D       = row[2],
                    Matricula_3D = row[3],
                    CodigoOrgaoSuperiorLotacao      = row[19].ToInt(),
                    CodigoOrgaoLotacao              = row[17].ToInt(),
                    DocumentoIngressoServicoPublico = row[36],
                    TipoVinculo = row[27].ToInt(),
                };

                if (uids.Contains(cad.UIID))
                {
                    continue;
                }
                uids.Add(cad.UIID);

                buffer.Add(cad);
                qtd++;

                if (qtd % buffer.Quantity == 0)
                {
                    Console.WriteLine($"{DateTime.Now.ToLongTimeString()} Processado: {qtd}");
                }
            }
            buffer.Flush();
        }
Esempio n. 4
0
 private static void processaPasta(string pasta, Simple.Sqlite.SqliteDB db)
 {
     foreach (var arquivo in Directory.GetFiles(pasta, "*.zip"))
     {
         if (arquivo.Contains("202004"))
         {
             continue;                             // already done
         }
         if (arquivo.Contains("202005"))
         {
             continue;                             // already done
         }
         if (arquivo.Contains("202006"))
         {
             continue;                             // already done
         }
         if (arquivo.Contains("202007"))
         {
             continue;                             // already done
         }
         processaArquivo(arquivo, db);
     }
 }
Esempio n. 5
0
        public static void run(Simple.Sqlite.SqliteDB db)
        {
            db.CreateTables()
            .Add <AuxilioModel>()
            .Commit();

            string pasta = "";

            while (!Directory.Exists(pasta))
            {
                Console.WriteLine("Entre com a pasta:");
                pasta = Console.ReadLine();
            }

            {
                // recovery from where it stopped
                var allNis = db.Query <string>("SELECT NIS FROM AuxilioModel WHERE NIS IS NOT NULL", null)
                             .Select(nis => long.Parse(nis));
                uids = new HashSet <long>(allNis);
            }

            processaPasta(pasta, db);
        }
Esempio n. 6
0
        // One dot per line
        void run()
        {
            var view = new Lib.Aula08.ProdutoView_SQLite();

            // don't do that ....
            Console.WriteLine(view.BuscarProdutoParteNome("a").First().Nome);

            // do that
            var produtosBuscados = view.BuscarProdutoParteNome("a");
            var primeiro         = produtosBuscados.First();

            Console.WriteLine(primeiro.Nome);

            // Exceção:
            // 1. Linq pode .... mas não exagera

            var items = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            //não fazer
            items.Where(i => i % 2 == 0).Select(i => i.ToString()).OrderBy(o => o);

            //fazer
            items.Where(i => i % 2 == 0)
            .Select(i => i.ToString())
            .OrderBy(o => o);


            // 2. Chaining
            var db = new Simple.Sqlite.SqliteDB("f**k");

            // chaining ... ... vai...
            db.CreateTables()
            .Add <int>()
            .Add <decimal>()
            .Commit();
        }
Esempio n. 7
0
        private static void processaArquivo(string zipName, Simple.Sqlite.SqliteDB db)
        {
            var zip = new LeitorZipTransparencia(zipName);

            //zip.ShouldProcessFile = n => n.Contains("_Cadastro");
            zip.IgnoreFirstLine       = true;
            zip.InicioLeituraArquivo += (s, a) => Console.WriteLine($"Lendo {a}");

            var zipLines = zip.ReadLines();
            var rows     = CSVHelper.DelimiterSplit(zipLines, ';');

            var buffer = new DataBuffer <AuxilioModel>(20000, data =>
            {
                db.BulkInsert(data, addReplace: true);
                Console.WriteLine($"# Data Write ");
            });

            foreach (var row in rows)
            {
                var cad = new AuxilioModel()
                {
                    UF                 = row[1],
                    Municipio          = row[2].ToInt(0),
                    NIS                = row[4],
                    CPF_6D             = row[5],
                    Nome               = row[6],
                    NIS_Responsavel    = row[7],
                    CPF_6D_Responsavel = row[8],
                    Nome_Responsavel   = row[9],
                    Enquadramento      = row[10],
                };

                if (cad.NIS == "00000000000")
                {
                    cad.NIS = null;
                }
                if (cad.NIS_Responsavel == "-2")
                {
                    cad.NIS_Responsavel = null;
                }
                if (cad.Nome_Responsavel == "Não se aplica")
                {
                    cad.Nome_Responsavel = null;
                }

                if (cad.NIS_Responsavel == cad.NIS)
                {
                    cad.NIS_Responsavel = null;
                }
                if (cad.CPF_6D_Responsavel == cad.NIS)
                {
                    cad.CPF_6D_Responsavel = null;
                }
                if (cad.Nome_Responsavel == cad.Nome)
                {
                    cad.Nome_Responsavel = null;
                }

                qtd++;
                if (qtd % buffer.Quantity == 0)
                {
                    Console.WriteLine($"{DateTime.Now.ToLongTimeString()} Processado: {qtd:N0} {cad.Nome}");
                }

                if (uids.Contains(cad.Key()))
                {
                    continue;
                }
                uids.Add(cad.Key());

                buffer.Add(cad);
            }
            buffer.Flush();
        }