コード例 #1
0
        public void ListarTxt()
        {
            Sped          sped    = new Sped();
            TxtRepository TxtRepo = new TxtRepository();

            var spedFiles = Directory.EnumerateFiles(sped.SourcePath, "*.txt*", SearchOption.AllDirectories);

            foreach (string arquivoTxt in spedFiles)
            {
                sped = TxtRepo.ObterInfoSped(arquivoTxt);
                sped.SourceFileName = Path.GetFullPath(arquivoTxt);
                sped.NomeDoArquivo  = Path.GetFileName(arquivoTxt);

                //System.Console.WriteLine(sped.CNPJ);
                //System.Console.WriteLine(sped.Status);

                _org.MoverSped(sped);
            }
        }
コード例 #2
0
        public void MoverSped(Sped sped)
        {
            sped.DestFileName = sped.CaminhoCriarPasta
                                + "\\" + DateTime.Now.ToString("dd-MM-yyy hhmmss")
                                + " " + sped.NomeDoArquivo;

            if (Directory.Exists(sped.CaminhoCriarPasta))
            {
                File.Move(sped.SourceFileName, sped.DestFileName);
                Console.WriteLine("Movido");
            }

            else
            {
                Directory.CreateDirectory(sped.CaminhoCriarPasta);

                File.Move(sped.SourceFileName, sped.DestFileName);
            }
        }
コード例 #3
0
        public Sped ObterInfoSped(string caminho)
        {
            Sped sped = new Sped();

            string[] line = File.ReadAllLines(caminho, Encoding.UTF7);

            foreach (string linhaDoArquivo in line)         //Para cada arquivo
            {
                var ehBloco0 = line[0].StartsWith("|0000"); //Se o bloco iniciar com |0000

                if (ehBloco0)
                {
                    string[] Linha = line[0].Split("|"); // Divide a linha em pedaços

                    sped.Identificador = Linha[14];      // Atribui o valor identificador
                    sped.TesteEcf      = Linha[2];

                    if (sped.TesteEcf == "LECF")
                    {
                        break;
                    }

                    int  num;
                    bool isNum = Int32.TryParse(sped.Identificador, out num);
                    if (isNum)
                    {
                        for (int i = 0; i < sped.EhPIS.Length; i++)
                        {
                            if (sped.Identificador == sped.EhPIS[i])
                            {
                                sped.RazaoSocial    = Linha[8];
                                sped.CNPJ           = Linha[9];
                                sped.MesCompetencia = Linha[6].Substring(2, 2);
                                sped.AnoCompetencia = Linha[6].Substring(4, 4);
                                sped.Status         = sped.ValidaStatus(Linha[3]);
                                sped.TipoSped       = "PISCOFINS";
                                sped.CriarCaminhoICMS(sped.TargetPath, sped.CNPJ, sped.AnoCompetencia, sped.MesCompetencia);
                            }
                        }
                    }

                    else
                    {
                        for (int j = 0; j < sped.EhICMS.Length; j++)
                        {
                            if (sped.Identificador == sped.EhICMS[j])
                            {
                                sped.RazaoSocial    = Linha[6];
                                sped.CNPJ           = Linha[7];
                                sped.MesCompetencia = Linha[4].Substring(2, 2);
                                sped.AnoCompetencia = Linha[4].Substring(4, 4);
                                sped.Status         = sped.ValidaStatus(Linha[3]);
                                sped.TipoSped       = "ICMS";
                                sped.CriarCaminhoICMS(sped.TargetPath, sped.CNPJ, sped.AnoCompetencia, sped.MesCompetencia);
                            }
                        }
                    }
                }
                else
                {
                    return(null);
                }
            }
            return(sped);
        }
コード例 #4
0
ファイル: Log.cs プロジェクト: MarceloHadad/MoverSpedProgram
        public void GerarLog()
        {
            Sped          sped    = new Sped();
            TxtRepository TxtRepo = new TxtRepository();

            var caminhoNomeArquivo = File.Create(@"C:\MoverSped\Log\" + DateTime.Now.ToString("dd-MM-yyy HHmmss") + " Auditoria.xlsx");

            ExcelPackage package = new ExcelPackage(caminhoNomeArquivo);

            ExcelWorkbook workbook = package.Workbook;

            ExcelWorksheet sheet = workbook.Worksheets.Add("AuditoriaFiscal");

            var row = 2;

            for (int i = 1; i <= 10; i++)
            {
                sheet.Cells[1, i].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                sheet.Cells[1, i].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Red);
                sheet.Cells[1, i].Style.Font.Bold = true;
                sheet.Cells[1, i].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin);
                sheet.Cells[1, i].Style.Font.Color.SetColor(System.Drawing.Color.White);
            }
            sheet.Cells[1, 1].Value  = "CodCliente";
            sheet.Cells[1, 2].Value  = "RazaoSocial";
            sheet.Cells[1, 3].Value  = "Grupo";
            sheet.Cells[1, 4].Value  = "CNPJ";
            sheet.Cells[1, 5].Value  = "InicioVigencia";
            sheet.Cells[1, 6].Value  = "MesCompetencia";
            sheet.Cells[1, 7].Value  = "AnoCompetencia";
            sheet.Cells[1, 8].Value  = "Status";
            sheet.Cells[1, 9].Value  = "Movimento";
            sheet.Cells[1, 10].Value = "Tipo";


            var spedFiles = Directory.EnumerateFiles(sped.SourcePath, "*.txt*", SearchOption.AllDirectories);

            foreach (string arquivoTxt in spedFiles)
            {
                Encoding utf8 = Encoding.UTF8;

                sped = TxtRepo.ObterInfoSped(arquivoTxt);

                if (sped != null)
                {
                    sheet.Cells[row, 1].Value  = "Inacessível";
                    sheet.Cells[row, 2].Value  = sped.RazaoSocial;
                    sheet.Cells[row, 3].Value  = "Inacessível";
                    sheet.Cells[row, 4].Value  = sped.CNPJ;
                    sheet.Cells[row, 5].Value  = "Inacessível";
                    sheet.Cells[row, 6].Value  = sped.MesCompetencia;
                    sheet.Cells[row, 7].Value  = sped.AnoCompetencia;
                    sheet.Cells[row, 8].Value  = sped.Status;
                    sheet.Cells[row, 9].Value  = "Validando...";
                    sheet.Cells[row, 10].Value = sped.TipoSped;

                    for (int i = 1; i <= 10; i++)
                    {
                        sheet.Cells[row, i].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin);
                    }
                    row++;
                }
            }
            package.Save();
        }