private string MontarTrailer() { TransacoesEloDAO transacaoDAO = new TransacoesEloDAO(arquivo.IdEmissor); InformacaoRegistro trailerIncoming = infRegDAO.BuscarTrailerArquivo(arquivo.IdArquivo); if (trailerIncoming.Equals(null)) { throw new Exception("Trailer não localizado"); } trailerIncoming.IdInformacaoRegistro = 0; int totalTransacoesCredReal, totalTransacoesCredDolar, totalTransacoesDebReal, totalTransacoesDebDolar; decimal valorTransacaoesCredReal, valorTransacoesCredDolar, valorTransacoesDebReal, valorTransacoesDedDolar; string trailerReal = LAB5Utils.StringUtils.Unzip(trailerIncoming.Valor); string strValorCredReal, strValorCredDolar, strValorDebReal, strValorDebDolar; totalTransacoesCredReal = transacaoDAO.TransacoesCredito(arquivo.NomeArquivo).Where(t => t.CodigoMoeda == 986).ToList().Count; valorTransacaoesCredReal = Math.Round(transacaoDAO.TransacoesCredito(arquivo.NomeArquivo).Where(t => t.CodigoMoeda == 986).ToList().Sum(t => t.Valor), 2); totalTransacoesCredDolar = transacaoDAO.TransacoesCredito(arquivo.NomeArquivo).Where(t => t.CodigoMoeda == 840).ToList().Count; valorTransacoesCredDolar = Math.Round(transacaoDAO.TransacoesCredito(arquivo.NomeArquivo).Where(t => t.CodigoMoeda == 840).ToList().Sum(t => t.Valor), 2); totalTransacoesDebReal = transacaoDAO.TransacoesDebito(arquivo.NomeArquivo).Where(t => t.CodigoMoeda == 986).ToList().Count; totalTransacoesDebDolar = transacaoDAO.TransacoesDebito(arquivo.NomeArquivo).Where(t => t.CodigoMoeda == 840).ToList().Count; valorTransacoesDebReal = Math.Round(transacaoDAO.TransacoesDebito(arquivo.NomeArquivo).Where(t => t.CodigoMoeda == 986).Sum(t => t.Valor), 2); valorTransacoesDedDolar = Math.Round(transacaoDAO.TransacoesDebito(arquivo.NomeArquivo).Where(t => t.CodigoMoeda == 840).Sum(t => t.Valor), 2); strValorCredDolar = valorTransacoesCredDolar > 0 ? valorTransacoesCredDolar.ToString().Remove(valorTransacoesCredDolar.ToString().IndexOf(','), 1).PadLeft(15, '0') : new string('0', 15); strValorCredReal = valorTransacaoesCredReal > 0 ? valorTransacaoesCredReal.ToString().Remove(valorTransacaoesCredReal.ToString().IndexOf(','), 1).PadLeft(15, '0') : new string('0', 15); strValorDebReal = valorTransacoesDebReal > 0 ? valorTransacoesDebReal.ToString().Remove(valorTransacoesDebReal.ToString().IndexOf(','), 1).PadLeft(15, '0') : new string('0', 15); strValorDebDolar = valorTransacoesDedDolar > 0 ? valorTransacoesDedDolar.ToString().Remove(valorTransacoesDedDolar.ToString().IndexOf(','), 1).PadLeft(15, '0') : new string('0', 15); trailerReal = LAB5Utils.ArquivoUtils.AlterarInformacao(trailerReal, totalTransacoesCredReal.ToString().PadLeft(8, '0'), 9, 16); trailerReal = LAB5Utils.ArquivoUtils.AlterarInformacao(trailerReal, strValorCredReal, 17, 31); trailerReal = LAB5Utils.ArquivoUtils.AlterarInformacao(trailerReal, totalTransacoesDebReal.ToString().PadLeft(8, '0'), 32, 39); trailerReal = LAB5Utils.ArquivoUtils.AlterarInformacao(trailerReal, strValorDebReal, 40, 54); trailerReal = LAB5Utils.ArquivoUtils.AlterarInformacao(trailerReal, totalTransacoesCredDolar.ToString().PadLeft(8, '0'), 55, 62); trailerReal = LAB5Utils.ArquivoUtils.AlterarInformacao(trailerReal, strValorCredDolar, 63, 77); trailerReal = LAB5Utils.ArquivoUtils.AlterarInformacao(trailerReal, totalTransacoesDebDolar.ToString().PadLeft(8, '0'), 78, 85); trailerReal = LAB5Utils.ArquivoUtils.AlterarInformacao(trailerReal, strValorDebDolar, 86, 100); trailerReal = LAB5Utils.ArquivoUtils.AlterarInformacao(trailerReal, totalRegistros.ToString().PadLeft(8, '0'), 101, 108); trailerReal = LAB5Utils.ArquivoUtils.AlterarInformacao(trailerReal, new string(' ', (116 - 109) + 1), 109, 116); trailerReal = LAB5Utils.ArquivoUtils.AlterarInformacao(trailerReal, new string(' ', (131 - 117) + 1), 117, 131); trailerReal = LAB5Utils.ArquivoUtils.AlterarInformacao(trailerReal, new string(' ', (167 - 132) + 1), 132, 167); trailerReal = LAB5Utils.ArquivoUtils.AlterarInformacao(trailerReal, "2", 168, 168); trailerIncoming.Valor = LAB5Utils.StringUtils.Zip(trailerReal); try { infRegDAO.Salvar(trailerIncoming); return(LAB5Utils.StringUtils.Unzip(trailerIncoming.Valor)); } catch (Exception ex) { throw new Exception("Não foi possível gerar o trailer do arquivo de retorno. " + ex.Message + " - " + ex.InnerException); } }