public void OpenOFXFileTest()
        {
            OFXFileReader ofxFileReader = new OFXFileReader(this._settings);
            OFXDocument   fileContent   = ofxFileReader.Read(Path.Combine(this._settings.OFXFileDirectory, FILE_NAME));

            Assert.NotNull(fileContent);
            Assert.NotNull(fileContent.OFXTransactionCollection);
            Assert.False(string.IsNullOrEmpty(fileContent.ACCTID));
            Assert.False(string.IsNullOrEmpty(fileContent.BANKID));
        }
        private static OFXDocument Parse(string data)
        {
            var xmlDocument = new XmlDocument();

            if (!data.StartsWith("OFXHEADER", StringComparison.CurrentCultureIgnoreCase))
            {
                throw new InvalidDataException();
            }

            //TODO: Store data information (?)
            var ofx = data.Remove(0, data.IndexOf("<", StringComparison.CurrentCultureIgnoreCase));

            ofx = ConvertSGMLTOXML(ofx);

            xmlDocument.LoadXml(ofx);

            TextReader  ofxReader   = new StringReader(xmlDocument.InnerXml);
            OFXDocument ofxDocument = (OFXDocument) new XmlSerializer(typeof(OFXDocument)).Deserialize(ofxReader);

            return(ofxDocument);
        }
Example #3
0
        public static OFXDocument Import(string pathFilename)
        {
            OFXDocument document = new OFXDocument();

            document.Account        = new Account();
            document.Account.BankID = "341";
            document.Transactions   = new List <Transaction>();
            document.SignOn         = new SignOn();

            string strText = string.Empty;

            string    anoFixo = String.Empty;
            PdfReader reader  = new PdfReader(pathFilename);

            for (int page = 1; page <= reader.NumberOfPages; page++)
            {
                ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.LocationTextExtractionStrategy();
                string cipherText           = PdfTextExtractor.GetTextFromPage(reader, page, its);
                cipherText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(cipherText)));
                strText    = strText + "\n" + cipherText;
            }
            int maxLength = Convert.ToString(reader.NumberOfPages).Length;

            reader.Close();

            string[]    temp        = strText.Split('\n');
            bool        head        = false;
            Transaction transaction = new Transaction();

            for (int i = 0; i < temp.Length; i++)
            {
                string value = string.Empty;

                try
                {
                    if (!head && temp[i].Contains("Nome") && temp[i].Contains("Agência/Conta"))
                    {
                        value = temp[i].ToString().Trim().Substring(temp[i].IndexOf("Agência/Conta:") + 14);
                        document.Account.BranchID  = value.ToString().Trim().Substring(0, value.IndexOf("/") - 1);
                        document.Account.AccountID = value.ToString().Trim().Substring(value.IndexOf("/"));
                    }
                    else if (!head && temp[i].Contains("Data") && temp[i].Contains("Horário"))
                    {
                        value = temp[i].ToString().Trim();
                        //DateTime.ParseExact(data.Substring(0, 10) + " 00:00:00.000", "dd/MM/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture);
                        string auxDt   = value.ToString().Trim().Substring(temp[i].IndexOf("Data") + 5, 12).Trim();
                        string auxHora = value.ToString().Trim().Substring(temp[i].IndexOf("Horário:") + 9).Trim();
                        try
                        {
                            document.SignOn.DTServer = DateTime.ParseExact(auxDt + " " + auxHora + ".000", "dd/MM/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture);
                        }
                        catch { }
                    }
                    else if (!head && temp[i].Contains("Extrato de") && temp[i].Contains("até"))
                    {
                        value = temp[i].ToString().Trim();
                        string auxInicio = value.ToString().Trim().Substring(temp[i].IndexOf("Extrato de") + 10).Trim().Substring(0, 10) + " 00:00:00.000";
                        try
                        {
                            document.StatementStart = DateTime.ParseExact(auxInicio, "dd/MM/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture);
                        }
                        catch
                        {
                            throw new Exception("'" + auxInicio + "' não corresponde a uma data válida (1)");
                        }
                        anoFixo = document.StatementStart.ToString("yyyy");
                        string auxFinal = value.ToString().Trim().Substring(value.Length - 10).Trim() + " 00:00:00.000";
                        try
                        {
                            document.StatementEnd = DateTime.ParseExact(auxFinal, "dd/MM/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture);
                        }
                        catch
                        {
                            throw new Exception("'" + auxFinal + "' não corresponde a uma data válida (2)");
                        }
                    }
                    else if (!head && temp[i].Contains("Data") && temp[i].Contains("Lançamento") && temp[i].Contains("Ag./Origem") &&
                             temp[i].Contains("Valor") && temp[i].Contains("Saldo") && temp[i].Contains("(R$)"))
                    {
                        head = true;
                    }
                    else if (head && !temp[i].Contains("ItaúEmpresas") && !(temp[i] == "") && !(temp[i].Trim().Length <= maxLength) && !(temp[i].ToString().Trim().Contains("SALDO")))
                    {
                        value = temp[i].ToString().Trim();

                        //Guardando data da linha
                        //string dsds = temp[i].Trim();
                        string aux = value.ToString().Trim().Substring(0, 5).Trim() + "/" + document.StatementStart.ToString("yyyy") + " 00:00:00.000";

                        try
                        {
                            transaction.Date = DateTime.ParseExact(aux, "dd/MM/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture);
                        }
                        catch
                        {
                            throw new Exception("'" + aux + "' não corresponde a uma data válida (3)");
                        }

                        value = value.ToString().Trim().Substring(5).Trim();
                        //List<string> colunas2 = value.Split(' ').ToList();
                        string[] colunas = value.Split(' ');


                        //Guardando valor da linha
                        if (temp[i + 1].Contains("SALDO FINAL"))
                        {
                            for (int j = colunas.Length - 2; j >= 0; j--)
                            {
                                if (colunas[j] != "")
                                {
                                    try
                                    {
                                        transaction.Amount = Convert.ToDecimal(colunas[j]);
                                    }
                                    catch
                                    {
                                        throw new Exception("'" + colunas[j] + "' não corresponde a um número válido (1)");
                                    }
                                    value = value.Trim().Substring(0, value.IndexOf(colunas[j])).Trim();
                                    break;
                                }
                            }
                        }
                        else if (temp[i + 2].Contains("(-) SALDO A LIBERAR") || (temp[i + 1].Contains("SALDO PARCIAL") && temp[i + 4].Contains("(-) SALDO A LIBERAR")) || (temp[i + 2].Contains("ItaúEmpresas") && temp[i + 5].Contains("(-) SALDO A LIBERAR")) ||
                                 (temp[i + 3].Contains("ItaúEmpresas") && temp[i + 5].Contains("(-) SALDO A LIBERAR")) || (temp[i + 2].Contains("ItaúEmpresas") && temp[i + 4].Contains("SALDO PARCIAL") && temp[i + 7].Contains("(-) SALDO A LIBERAR")) ||
                                 (temp[i + 1].Contains("SALDO PARCIAL") && temp[i + 3].Contains("ItaúEmpresas") && temp[i + 7].Contains("(-) SALDO A LIBERAR")) || (temp[i + 1].Contains("SALDO PARCIAL") && temp[i + 4].Contains("ItaúEmpresas") && temp[i + 7].Contains("(-) SALDO A LIBERAR")) ||
                                 (temp[i + 1].Contains("SALDO PARCIAL") && temp[i + 5].Contains("ItaúEmpresas") && temp[i + 7].Contains("(-) SALDO A LIBERAR")))
                        {
                            for (int j = colunas.Length - 2; j >= 0; j--)
                            {
                                if (colunas[j] != "")
                                {
                                    try
                                    {
                                        transaction.Amount = Convert.ToDecimal(colunas[j]);
                                    }
                                    catch
                                    {
                                        throw new Exception("'" + colunas[j] + "' não corresponde a um número válido (2)");
                                    }
                                    value = value.Trim().Substring(0, value.IndexOf(colunas[j])).Trim();
                                    break;
                                }
                            }
                        }
                        else if (temp[i + 1] != "" && !(temp[i + 1].Trim().Length <= maxLength) && ((temp[i].Substring(0, 5).Trim() != temp[i + 1].Substring(0, 5).Trim()) || (temp[i + 2] == "ItaúEmpresas" && temp[i].Substring(0, 5).Trim() != temp[i + 4].Substring(0, 5).Trim()) ||
                                                                                                    (temp[i + 1].Contains("SALDO PARCIAL") && temp[i].Substring(0, 5).Trim() != temp[i + 3].Substring(0, 5).Trim()) || (temp[i + 2] == "ItaúEmpresas" && temp[i + 4].Contains("SALDO PARCIAL") && temp[i].Substring(0, 5).Trim() != temp[i + 6].Substring(0, 5).Trim()) ||
                                                                                                    (temp[i + 1].Contains("SALDO PARCIAL") && temp[i + 3] == "ItaúEmpresas" && temp[i].Substring(0, 5).Trim() != temp[i + 6].Substring(0, 5).Trim()) || (temp[i + 1].Contains("SALDO PARCIAL") && temp[i + 4] == "ItaúEmpresas" && temp[i].Substring(0, 5).Trim() != temp[i + 6].Substring(0, 5).Trim())))
                        {
                            for (int j = colunas.Length - 2; j >= 0; j--)
                            {
                                if (colunas[j] != "")
                                {
                                    try
                                    {
                                        transaction.Amount = Convert.ToDecimal(colunas[j]);
                                    }
                                    catch
                                    {
                                        throw new Exception("'" + colunas[j] + "' não corresponde a um número válido (3)");
                                    }
                                    value = value.Trim().Substring(0, value.IndexOf(colunas[j])).Trim();
                                    break;
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                transaction.Amount = Convert.ToDecimal(colunas[colunas.Length - 1]);
                            }
                            catch
                            {
                                throw new Exception("'" + colunas[colunas.Length - 1] + "' não corresponde a um número válido (4)");
                            }
                            value = value.Replace(colunas[colunas.Length - 1], "").Trim();
                        }

                        // Sem número do documento
                        transaction.CheckNum = String.Empty;

                        //Guardando descrição
                        transaction.Memo = value;

                        //Guardando tipo
                        transaction.TransType = transaction.Amount > 0 ? OFXTransactionType.CREDIT : OFXTransactionType.DEBIT;

                        // Adiciona a tranction
                        document.Transactions.Add(transaction);
                        transaction = new Transaction();
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(i.ToString() + " -> " + e.Message);
                }
            }

            return(document);
        }
Example #4
0
        public static OFXDocument Import(string pathFilename)
        {
            OFXDocument document = new OFXDocument();

            document.Account        = new Account();
            document.Account.BankID = "004";
            document.Transactions   = new List <Transaction>();
            document.SignOn         = new SignOn();

            string strText            = string.Empty;
            bool   tratamento         = false;
            bool   dataGeracaoExtrato = false;
            string stringTratamento1  = String.Empty;
            string stringTratamento2  = String.Empty;
            string stringTratamento3  = String.Empty;
            string textTemp           = String.Empty;


            PdfReader reader = new PdfReader((string)pathFilename);

            for (int page = 1; page <= reader.NumberOfPages; page++)
            {
                ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.LocationTextExtractionStrategy();
                String cipherText           = PdfTextExtractor.GetTextFromPage(reader, page, its);
                cipherText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(cipherText)));
                strText    = strText + "\n" + cipherText;
            }
            reader.Close();

            List <string> temp = strText.Split('\n').ToList();

            bool        head        = false;
            Transaction transaction = new Transaction();

            for (int i = 0; i < temp.Count; i++)
            {
                string value = String.Empty;
                try
                {
                    if (i == 1)
                    {
                        // [Data de geração do extrato]
                        if (iniciaComData(temp[i].ToString()))
                        {
                            value = temp[i].ToString().TrimStart().Substring(0, 10);
                            try
                            {
                                document.SignOn.DTServer = Convert.ToDateTime(value);
                                dataGeracaoExtrato       = true;
                            }
                            catch
                            {
                                // falha ao obter data de geração do extrato
                            }
                        }
                    }
                    else if (!head && temp[i].ToString().Trim().StartsWith("Agência:"))
                    {
                        value = temp[i].ToString().Substring(temp[i].ToString().IndexOf("Agência:") + 8);
                        document.Account.BranchID = value.Trim().Substring(0, value.Trim().IndexOf(" "));
                        if (value.Contains("Conta Corrente:"))
                        {
                            value = temp[i].ToString().Substring((temp[i].ToString().IndexOf("Corrente:") + 9), 9);
                            document.Account.AccountID = value.Trim();
                        }
                    }
                    else if (!head && temp[i].ToString().Trim().StartsWith("Conta Corrente:"))
                    {
                        value = temp[i].ToString().Substring((temp[i].ToString().IndexOf("Corrente:") + 9), 9);
                        document.Account.AccountID = value.Trim();
                    }
                    else if (!head && temp[i].ToString().Trim().Contains("Período:"))
                    {
                        value = temp[i].ToString().TrimEnd();
                        value = value.Substring(value.IndexOf("Período:") + 8);
                        int indiceAte = value.IndexOf("até");
                        try
                        {
                            document.StatementStart = Convert.ToDateTime(value.Substring(0, indiceAte).Trim());
                        }
                        catch
                        {
                            // falha ao obter data início das movimentações
                        }
                        try
                        {
                            document.StatementEnd = Convert.ToDateTime(value.Substring(indiceAte + 3).Trim());
                        }
                        catch
                        {
                            // falha ao obter data final das movimentações
                        }
                    }
                    else if (!head && temp[i].ToString().Trim().Contains("Data Histórico Documento Valor R$ Saldo R$"))
                    {
                        head = true;
                    }
                    else if (head && temp[i].ToString().IndexOf("https") < 0 &&
                             !temp[i].ToString().EndsWith("Nordeste Eletrônico") &&
                             !temp[i].ToString().StartsWith("Nordeste Eletrônico Page") &&
                             !temp[i].ToString().StartsWith("Importante:") &&
                             !temp[i].ToString().StartsWith("Não constam valores de aplicações e resgates efetuados no dia.") &&
                             !temp[i].ToString().StartsWith("Banco do Nordeste - Cliente Consulta | Ouvidoria:"))
                    {
                        String cipherText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(temp[i].ToString())));

                        if (iniciaComData(cipherText))
                        {
                            try
                            {
                                transaction.Date = DateTime.ParseExact(cipherText.Substring(0, 10) + " 00:00:00.000", "dd/MM/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture);
                            }
                            catch
                            {
                                throw new Exception("'" + cipherText.Substring(0, 10) + "' não corresponde a uma data válida (1)");
                            }
                            // Procura valor e nrDocumento
                            string auxiliar = cipherText.Substring(10).TrimEnd();
                            int    index    = auxiliar.LastIndexOf(" ");
                            if (index > 1 && auxiliar[index - 1] == '-')
                            {
                                auxiliar = auxiliar.Substring(0, index) + auxiliar.Substring(index + 1);
                                index   -= 2; // valor negativo vem o '-' separado por espaço
                            }
                            decimal amount = new decimal(0.0);
                            try
                            {
                                amount = Convert.ToDecimal(auxiliar.Substring(index + 1));
                            }
                            catch
                            {
                                throw new Exception("'" + auxiliar.Substring(index + 1) + "' não corresponde a um valor monetário (1)");
                            }
                            auxiliar = auxiliar.Substring(0, index).TrimEnd();
                            index    = auxiliar.LastIndexOf(" ");
                            if (index > 1 && auxiliar[index - 1] == '-')
                            {
                                auxiliar = auxiliar.Substring(0, index) + auxiliar.Substring(index + 1);
                                index   -= 2; // valor negativo vem o '-' separado por espaço
                            }
                            try
                            {
                                Convert.ToInt32(auxiliar.Substring(index + 1));
                            }
                            catch
                            {
                                amount   = Convert.ToDecimal(auxiliar.Substring(index + 1));
                                auxiliar = auxiliar.Substring(0, index).TrimEnd();
                                index    = auxiliar.LastIndexOf(" ");
                                if (index > 1 && auxiliar[index - 1] == '-')
                                {
                                    auxiliar = auxiliar.Substring(0, index) + auxiliar.Substring(index + 1);
                                    index   -= 2; // valor negativo vem o '-' separado por espaço
                                }
                                Convert.ToInt32(auxiliar.Substring(index + 1));
                            }
                            transaction.CheckNum  = auxiliar.Substring(index + 1);
                            transaction.Amount    = amount;
                            transaction.Memo      = auxiliar.Substring(0, index).TrimEnd();
                            transaction.TransType = transaction.Amount > 0 ? OFXTransactionType.CREDIT : OFXTransactionType.DEBIT;

                            if (!tratamento && !transaction.Memo.Trim().Equals(""))
                            {
                                document.Transactions.Add(transaction);
                                transaction = new Transaction();
                            }
                        }
                        else
                        {
                            textTemp += " " + cipherText;

                            if (!tratamento)
                            {
                                tratamento = true;
                            }
                            else if (transaction.Memo != null)
                            {
                                tratamento       = false;
                                transaction.Memo = textTemp.Trim();
                                document.Transactions.Add(transaction);
                                textTemp    = String.Empty;
                                transaction = new Transaction();
                            }
                        }
                    }
                    else if (!dataGeracaoExtrato && temp[i].ToString().IndexOf("https") >= 0)
                    {
                        value = temp[i].ToString().Trim();
                        value = value.Substring(value.LastIndexOf(" ") + 1);
                        try
                        {
                            document.SignOn.DTServer = Convert.ToDateTime(value);
                            dataGeracaoExtrato       = true;
                        }
                        catch
                        {
                            // falha ao obter data de geração do extrato
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(i.ToString() + " -> " + e.Message);
                }
            }

            return(document);
        }
Example #5
0
 private IEnumerable <TransactionOfx> ExtractTransactions(OFXDocument ofxDocument)
 {
     return(ofxDocument.Bank.STMTSTRNRS.StmTrs.TranList.Transactions.Select(TransactionMapper.ToTransaction));
 }
Example #6
0
        public static OFXDocument Import(string pathFilename)
        {
            OFXDocument document = new OFXDocument();

            document.Account        = new Account();
            document.Account.BankID = "033";
            document.Transactions   = new List <Transaction>();
            document.SignOn         = new SignOn();

            string strText           = string.Empty;
            bool   tratamento        = false;
            int    rowsTratamento    = 0;
            string stringTratamento1 = String.Empty;
            string stringTratamento2 = String.Empty;
            string stringTratamento3 = String.Empty;
            int    iof = 0;

            PdfReader reader = new PdfReader((string)pathFilename);

            for (int page = 1; page <= reader.NumberOfPages; page++)
            {
                ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.LocationTextExtractionStrategy();
                String cipherText           = PdfTextExtractor.GetTextFromPage(reader, page, its);
                cipherText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(cipherText)));
                strText    = strText + "\n" + cipherText;
            }
            reader.Close();


            List <string> temp = strText.Split('\n').ToList();

            int contAjuste = 0;

            bool head = false;

            for (int i = 0; i < temp.Count; i++)
            {
                try
                {
                    //if (i == 149)
                    //    Console.WriteLine("Line: " + i + " Total: " + temp.Count + " | " + temp[i].ToString());
                    string value = String.Empty;

                    if (i == 1)
                    {
                        // [Agência e Conta Corrente]
                        if (!temp[i].ToString().Contains("Agência:"))
                        {
                            i++; contAjuste++;
                        }
                        value = temp[i].ToString().Substring((temp[i].ToString().IndexOf("Agência:") + 8), 6);
                        // Agência
                        document.Account.BranchID = value.Trim().TrimStart().TrimEnd();
                        // Conta
                        value = temp[i].ToString().Substring((temp[i].ToString().IndexOf("Corrente:") + 9), 12);
                        document.Account.AccountID = value.Trim().TrimStart().TrimEnd();
                        // Avalia se tem o código da operação antes
                        if (document.Account.AccountID.IndexOf("-") != document.Account.AccountID.LastIndexOf("-"))
                        {
                            document.Account.AccountID = document.Account.AccountID.Substring(document.Account.AccountID.IndexOf("-") + 1);
                        }
                    }
                    else if ((i == 3 && contAjuste == 0) || (contAjuste == 1 && i == 4))
                    {
                        // Período do extrato
                        if (temp[i].ToString().Contains("Período:"))
                        {
                            int    index   = temp[i].ToString().IndexOf("Período:") + "Periodo:".Length;
                            string periodo = temp[i].ToString().Substring(index);
                            if (periodo.Contains("Data/Hora"))
                            {
                                // DTSERVER
                                string dtServer = periodo.Substring(periodo.IndexOf("Data/Hora") + 10);
                                if (dtServer.Contains("às"))
                                {
                                    dtServer = dtServer.Substring(0, dtServer.IndexOf("às"));
                                }

                                document.SignOn.DTServer = Convert.ToDateTime(dtServer.Trim());

                                // Período
                                periodo = periodo.Substring(0, periodo.IndexOf("Data/Hora"));
                            }

                            index = periodo.IndexOf(" a ");
                            string dtInicio = periodo.Substring(0, index).Trim();
                            string dtFim    = periodo.Substring(index + 3).Trim();
                            document.StatementStart = DateTime.ParseExact(dtInicio + " 00:00:00.000", "dd/MM/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture);
                            document.StatementEnd   = DateTime.ParseExact(dtFim + " 00:00:00.000", "dd/MM/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture);
                        }
                    }
                    else if ((i == 4 && contAjuste == 0) || (contAjuste == 1 && i == 5))
                    {
                        // [ Início do Extrato]
                        if (temp[i].ToString().Contains("Data Histórico Docto. Valor R$"))// Saldo R$"))
                        {
                            head = true;
                        }
                    }
                    else
                    {
                        // [ Linhas do Extrato]
                        if (head && temp[i].ToString().IndexOf("SALDO ANTERIOR") < 0) //[ NÃO LEVA EM CONSIDERAÇÂO SALDOS ]
                        {
                            //LinhaExtrato row = new LinhaExtrato();
                            String cipherText = String.Empty;
                            try
                            {
                                cipherText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(temp[i].ToString())));
                            }
                            catch
                            {
                                cipherText = String.Empty;
                            }

                            if (
                                cipherText.IndexOf("Posição em:") < 0 &&
                                cipherText.IndexOf("Provisão Encargos") < 0 &&
                                cipherText.IndexOf("Limite Santander Master") < 0 &&
                                cipherText.IndexOf("a = Bloqueio Dia") < 0 &&
                                cipherText.IndexOf("b = Bloqueado") < 0 &&
                                cipherText.IndexOf("p = Lançamento Provisionado") < 0 &&
                                cipherText.IndexOf("Superlinha") < 0 &&
                                cipherText.IndexOf("Saldo Bloqueado") < 0 &&
                                cipherText.IndexOf("Saldo Bloqueio Dia") < 0 &&
                                cipherText.IndexOf("Saldo Total de Conta Corrente") < 0 &&
                                cipherText.IndexOf("Saldo de Conta Corrente") < 0 &&
                                cipherText.IndexOf("Saldo em Investimentos com Resgate") < 0 &&
                                cipherText.IndexOf("Saldo Disponível (") < 0 &&
                                cipherText.IndexOf("Saldo Disponível Conta Corrente") < 0 &&
                                cipherText.IndexOf("Saldo Disponível Total") < 0 &&
                                cipherText.IndexOf("Ouvidoria 0800") < 0
                                )
                            {
                                //if (cipherText.IndexOf("IOF") < 0 && iof == 0)
                                //{
                                //if (cipherText.Contains("01/12/2015"))
                                //    cipherText = cipherText + "";

                                if (iniciaComData(cipherText) && !tratamento)
                                {
                                    Transaction transaction = new Transaction();

                                    try
                                    {
                                        transaction.Date = DateTime.ParseExact(cipherText.Substring(0, 10) + " 00:00:00.000", "dd/MM/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture);
                                    }
                                    catch
                                    {
                                        throw new Exception("'" + cipherText.Substring(0, 10) + "' não corresponde a uma data válida (1)");
                                    }
                                    // Procura valor e nrDocumento
                                    string  auxiliar = cipherText.Substring(10).TrimEnd();
                                    int     index    = auxiliar.LastIndexOf(" ");
                                    decimal amount   = new decimal(0.0);
                                    try
                                    {
                                        amount = Convert.ToDecimal(auxiliar.Substring(index + 1));
                                    }
                                    catch
                                    {
                                        throw new Exception("'" + auxiliar.Substring(index + 1) + "' não corresponde a um valor monetário (1)");
                                    }
                                    auxiliar = auxiliar.Substring(0, index).TrimEnd();
                                    index    = auxiliar.LastIndexOf(" ");
                                    try
                                    {
                                        Convert.ToInt32(auxiliar.Substring(index + 1));
                                    }
                                    catch
                                    {
                                        amount   = Convert.ToDecimal(auxiliar.Substring(index + 1));
                                        auxiliar = auxiliar.Substring(0, index).TrimEnd();
                                        index    = auxiliar.LastIndexOf(" ");
                                        Convert.ToInt32(auxiliar.Substring(index + 1));
                                    }
                                    transaction.CheckNum = auxiliar.Substring(index + 1);
                                    transaction.Amount   = amount;
                                    transaction.Memo     = auxiliar.Substring(0, index).TrimEnd();
                                    // Legenda?
                                    if (transaction.Memo.EndsWith(" a")) // Bloqueio Dia / ADM
                                    {
                                        transaction.Memo = transaction.Memo.Substring(0, transaction.Memo.IndexOf(" a"));
                                    }
                                    else if (transaction.Memo.EndsWith(" b")) // Bloqueado
                                    {
                                        transaction.Memo = transaction.Memo.Substring(0, transaction.Memo.IndexOf(" b"));
                                    }
                                    else if (transaction.Memo.EndsWith(" p")) // Lançamento Provisionado
                                    {
                                        transaction.Memo = transaction.Memo.Substring(0, transaction.Memo.IndexOf(" p"));
                                    }
                                    //row.dsTipo = row.vlMovimento > 0 ? "CREDIT" : "DEBIT";
                                    transaction.TransType = transaction.Amount > 0 ? OFXTransactionType.CREDIT : OFXTransactionType.DEBIT;

                                    // Adiciona a transaction
                                    document.Transactions.Add(transaction);
                                }
                                else if (cipherText.StartsWith("https://www.") || cipherText.StartsWith("Internet Banking Página"))
                                {
                                    continue;
                                }
                                else
                                {
                                    tratamento = true;
                                    rowsTratamento++;

                                    if (rowsTratamento == 1)// && tratamento)
                                    {
                                        stringTratamento1 = cipherText.Replace('/', '|');
                                    }
                                    else if (rowsTratamento == 2)// && tratamento)
                                    {
                                        stringTratamento2 = cipherText;
                                    }
                                    else if (rowsTratamento == 3)// && tratamento)
                                    {
                                        if (stringTratamento1.Length > 10)
                                        {
                                            stringTratamento3 = cipherText.Replace('/', '|');
                                            cipherText        = stringTratamento2.Substring(0, 11) + stringTratamento1 + " " + stringTratamento3 + " " + stringTratamento2.Substring(11, stringTratamento2.Length - 11);

                                            Transaction transaction = new Transaction();

                                            try
                                            {
                                                transaction.Date = DateTime.ParseExact(cipherText.Substring(0, 10) + " 00:00:00.000", "dd/MM/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture);
                                            }
                                            catch
                                            {
                                                throw new Exception("'" + cipherText.Substring(0, 10) + "' não corresponde a uma data válida (2)");
                                            }

                                            // Procura valor e nrDocumento
                                            string  auxiliar = cipherText.Substring(10).TrimEnd();
                                            int     index    = auxiliar.LastIndexOf(" ");
                                            decimal amount   = new decimal(0.0);
                                            try
                                            {
                                                amount = Convert.ToDecimal(auxiliar.Substring(index + 1));
                                            }
                                            catch
                                            {
                                                throw new Exception("'" + auxiliar.Substring(index + 1) + "' não corresponde a um valor monetário (2)");
                                            }
                                            auxiliar = auxiliar.Substring(0, index).TrimEnd();
                                            index    = auxiliar.LastIndexOf(" ");
                                            try
                                            {
                                                Convert.ToInt32(auxiliar.Substring(index + 1));
                                            }
                                            catch
                                            {
                                                amount   = Convert.ToDecimal(auxiliar.Substring(index + 1));
                                                auxiliar = auxiliar.Substring(0, index).TrimEnd();
                                                index    = auxiliar.LastIndexOf(" ");
                                                Convert.ToInt32(auxiliar.Substring(index + 1));
                                            }
                                            transaction.CheckNum = auxiliar.Substring(index + 1);
                                            transaction.Amount   = amount;
                                            transaction.Memo     = auxiliar.Substring(0, index).TrimEnd();

                                            // Legenda?
                                            if (transaction.Memo.EndsWith(" a")) // Bloqueio Dia / ADM
                                            {
                                                transaction.Memo = transaction.Memo.Substring(0, transaction.Memo.IndexOf(" a"));
                                            }
                                            else if (transaction.Memo.EndsWith(" b")) // Bloqueado
                                            {
                                                transaction.Memo = transaction.Memo.Substring(0, transaction.Memo.IndexOf(" b"));
                                            }
                                            else if (transaction.Memo.EndsWith(" p")) // Lançamento Provisionado
                                            {
                                                transaction.Memo = transaction.Memo.Substring(0, transaction.Memo.IndexOf(" p"));
                                            }
                                            transaction.TransType = transaction.Amount > 0 ? OFXTransactionType.CREDIT : OFXTransactionType.DEBIT;

                                            // Adiciona a transaction
                                            document.Transactions.Add(transaction);

                                            rowsTratamento = 0;
                                            tratamento     = false;
                                        }
                                        else
                                        {
                                            rowsTratamento = 0;
                                            tratamento     = false;
                                        }
                                    }
                                }
                                //}
                                //else
                                //{
                                //    if (iof == 0)
                                //    {
                                //        iof++;
                                //        if (cipherText.IndexOf('/') > 0)
                                //        {
                                //            string[] tempFilter = cipherText.Split(':');
                                //            stringTratamento1 = tempFilter[0];
                                //        }
                                //        else
                                //            stringTratamento1 = cipherText;
                                //    }
                                //    else if (iof == 1)
                                //    {
                                //        iof++;
                                //        stringTratamento2 = cipherText;
                                //    }
                                //    else if (iof == 2)
                                //    {
                                //        iof = 0;
                                //        stringTratamento3 = cipherText.Replace('/', '-');
                                //        cipherText = stringTratamento2.Substring(0, 11) + stringTratamento1 + " " + stringTratamento3 + " " + stringTratamento2.Substring(11, stringTratamento2.Length - 11);

                                //        Transaction transaction = new Transaction();

                                //        try
                                //        {
                                //            transaction.Date = DateTime.ParseExact(cipherText.Substring(0, 10) + " 00:00:00.000", "dd/MM/yyyy HH:mm:ss.fff", CultureInfo.InvariantCulture);
                                //        }
                                //        catch
                                //        {
                                //            throw new Exception("'" + cipherText.Substring(0, 10) + "' não corresponde a uma data válida (3)");
                                //        }

                                //        // Procura valor e nrDocumento
                                //        string auxiliar = cipherText.Substring(10).TrimEnd();
                                //        int index = auxiliar.LastIndexOf(" ");
                                //        decimal amount = new decimal(0.0);
                                //        try
                                //        {
                                //            amount = Convert.ToDecimal(auxiliar.Substring(index + 1));
                                //        }
                                //        catch
                                //        {
                                //            //amount = new decimal(0.0);
                                //            throw new Exception("'" + auxiliar.Substring(index + 1) + "' não corresponde a um valor monetário (3)");
                                //        }
                                //        auxiliar = auxiliar.Substring(0, index).TrimEnd();
                                //        index = auxiliar.LastIndexOf(" ");
                                //        try
                                //        {
                                //            Convert.ToInt32(auxiliar.Substring(index + 1));
                                //        }
                                //        catch
                                //        {
                                //            amount = Convert.ToDecimal(auxiliar.Substring(index + 1));
                                //            auxiliar = auxiliar.Substring(0, index).TrimEnd();
                                //            index = auxiliar.LastIndexOf(" ");
                                //            Convert.ToInt32(auxiliar.Substring(index + 1));
                                //        }
                                //        transaction.CheckNum = auxiliar.Substring(index + 1);
                                //        transaction.Amount = amount;
                                //        transaction.Memo = auxiliar.Substring(0, index).TrimEnd();
                                //        // Legenda?
                                //        if (transaction.Memo.EndsWith(" a")) // Bloqueio Dia / ADM
                                //            transaction.Memo = transaction.Memo.Substring(0, transaction.Memo.IndexOf(" a"));
                                //        else if (transaction.Memo.EndsWith(" b")) // Bloqueado
                                //            transaction.Memo = transaction.Memo.Substring(0, transaction.Memo.IndexOf(" b"));
                                //        else if (transaction.Memo.EndsWith(" p")) // Lançamento Provisionado
                                //            transaction.Memo = transaction.Memo.Substring(0, transaction.Memo.IndexOf(" p"));

                                //        transaction.TransType = transaction.Amount > 0 ? OFXTransactionType.CREDIT : OFXTransactionType.DEBIT;

                                //        // Adiciona a transaction
                                //        document.Transactions.Add(transaction);
                                //    }
                                //}
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(i.ToString() + " -> " + e.Message);
                }
            }

            return(document);
        }