Example #1
0
        public static bool MontaTextoESalvaArquivo(IRelatorio relatorio, ref string textoTabelas)
        {
            int             i           = 0;
            int             somaMudadas = 0;
            BinaryFormatter binario     = new BinaryFormatter();

            textoTabelas += string.Format(ConstStringHtml.tituloEUrl, relatorio.Nome, relatorio.Url);

            foreach (HtmlNodeCollection noTabela in Crawler.RetornaNodeHTML(relatorio))
            {
                int mudadas = 0;

                string textoTabela = string.Format(ConstStringHtml.tituloTabela, relatorio.NomeTabelas[i]);

                //Não mova esse i++ de lugar!!
                i++;

                if (noTabela == null)
                {
                    textoTabela += Formatador.PrintaLinha(new LinhaDadosBCB("Erro na leitura do nó", "Verifique o serviço", "Tabela " + i.ToString()));
                    somaMudadas++;
                    continue;
                }

                relatorio.Html = noTabela;

                string nomeArquivo = string.Format(ConstStringHtml.nomeBin, relatorio.Nome, i);

                DadosBCB dadosBCB = new DadosBCB(relatorio);

                if (!File.Exists(nomeArquivo))
                {
                    Stream tmp = File.Create(nomeArquivo);
                    tmp.Close();
                }

                using (Stream stream = File.OpenRead(nomeArquivo))
                {
                    DadosBCB dadoRecuperadosBCB = null;

                    if (!(stream.Length == 0))
                    {
                        dadoRecuperadosBCB = (DadosBCB)binario.Deserialize(stream);
                    }

                    textoTabela += ConstStringHtml.abreTabela + ConstStringHtml.abreTR;

                    textoTabela += Formatador.PrintaCabecalho(relatorio.Cabecalho);

                    textoTabela += "</tr>";
                    textoTabela += MontaTextoTabela(ref mudadas, dadosBCB, dadoRecuperadosBCB);
                    textoTabela += "</table>";
                }

                using (Stream stream = File.OpenWrite(nomeArquivo))
                {
                    binario.Serialize(stream, dadosBCB);
                }

                somaMudadas += mudadas;
                if (mudadas == 0)
                {
                    textoTabela = string.Empty;

                    if (i == relatorio.NumeroTabelas && somaMudadas == 0)
                    {
                        textoTabela = string.Format(ConstStringHtml.nenuhmaAlteracao, relatorio.Nome);
                    }
                }

                textoTabelas += textoTabela;
            }

            return(!(somaMudadas == 0));
        }
Example #2
0
        private static string MontaTabelasESalvaArquivos(IRelatorio relatorio, StringBuilder textoTabelas, BinaryFormatter binario)
        {
            int     i           = 0;
            int     somaMudadas = 0;
            Crawler crawler     = new Crawler();

            foreach (HtmlNodeCollection noTabela in crawler.RetornaNodeRelatorio(relatorio))
            {
                int mudadas = 0;

                StringBuilder textoTabela = new StringBuilder(string.Format(ConstStringHtml.tituloTabela, relatorio.NomeTabelas[i]));

                //Não mova esse i++ de lugar!!
                i++;

                if (noTabela == null)
                {
                    return(string.Empty);
                }

                relatorio.Html = noTabela;

                string nomeArquivo = string.Format(ConstStringHtml.nomeBinTabelas, relatorio.Nome, i);

                DadosBCB dadosBCB = new DadosBCB(relatorio);

                if (!File.Exists(nomeArquivo))
                {
                    Stream tmp = File.Create(nomeArquivo);
                    tmp.Close();
                }

                using (Stream stream = File.OpenRead(nomeArquivo))
                {
                    DadosBCB dadoRecuperadosBCB = null;

                    if (!(stream.Length == 0))
                    {
                        dadoRecuperadosBCB = (DadosBCB)binario.Deserialize(stream);
                    }

                    textoTabela.Append(ConstStringHtml.abreTabela + ConstStringHtml.abreTR);

                    textoTabela.Append(Formatador.PrintaCabecalho(relatorio.Cabecalho) + "</tr>");

                    textoTabela.Append(Formatador.RetornaTextoTabela(ref mudadas, dadosBCB, dadoRecuperadosBCB) + "</table>");
                }

                using (Stream stream = File.OpenWrite(nomeArquivo))
                {
                    binario.Serialize(stream, dadosBCB);
                }

                somaMudadas += mudadas;
                if (mudadas == 0)
                {
                    textoTabela.Clear();

                    if (i == relatorio.NumeroTabelas && somaMudadas == 0)
                    {
                        textoTabela.Append(string.Format(ConstStringHtml.nenuhmaAlteracao, relatorio.Nome));
                    }
                }

                textoTabelas.Append(textoTabela);
            }

            return(textoTabelas.ToString());
        }