//Cantidad de caracteres 41 public Deuda(Header header, List <Detalle> detalles, Footer footer) { this.header = header; this.detalles = detalles; this.footer = footer; }
public bool Leer(string archivo, out Deuda deuda) { bool retorno = false; Header header = null; List <Detalle> miListaDeDetalle = new List <Detalle>(); Footer footer = null; try { using (StreamReader sr = new StreamReader(archivo)) { string line; while ((line = sr.ReadLine()) != null) { string auxiliarLine = line; string tipoLinea = line.Substring(0, 1); if (tipoLinea == "0") { string tipoDeHeader = line.Substring(0, 1); string valorFijo = line.Substring(1, 3); string numComercio = line.Substring(4, 4); string fecha = line.Substring(8, 8); header = new Header(tipoDeHeader, valorFijo, numComercio, fecha); } if (tipoLinea == "5") { string tipoDeDetalle = line.Substring(0, 1); //1 Caracater string numCliente = line.Substring(1, 19); //19 Caracater string documento = line.Substring(20, 20); //20 Caracater string moneda = line.Substring(40, 1); //1 Caracater string primerVencimiento = line.Substring(41, 8); //8 Caracater //string importePrimerVencimiento = line.Substring(49, 11); //11 Caracater string importePrimerVencimientoEntero = line.Substring(49, 9); //9 Caracater string importePrimerVencimientoCentavo = line.Substring(58, 2); //2 Caracater string importePrimerVencimiento = importePrimerVencimientoEntero + "," + importePrimerVencimientoCentavo; string segundoVencimiento = line.Substring(60, 8); //8 Caracater //string importeSegundoVencimiento = line.Substring(68, 11); //11 Caracater string importeSegundoVencimientoEntero = line.Substring(68, 9); //11 Caracater string importeSegundoVencimientoCentavo = line.Substring(77, 2); //11 Caracater string importeSegundoVencimiento = importeSegundoVencimientoEntero + "," + importeSegundoVencimientoCentavo; //11 Caracater string tercerVencimiento = line.Substring(79, 8); //8 Caracater //string importeTercerVencimiento = line.Substring(87, 11); //11 Caracater string importeTercerVencimientoEntero = line.Substring(87, 9); //11 Caracater string importeTercerVencimientoCentavo = line.Substring(96, 2); //11 Caracater string importeTercerVencimiento = importeTercerVencimientoEntero + "," + importeTercerVencimientoCentavo; //11 Caracater string valorFijoSegundo = line.Substring(98, 19); //19 Caracater string numReferencia = line.Substring(117, 19); //19 Caracater string mensajeTicket = line.Substring(136, 55); //55 Caracater string codBarras = line.Substring(191, 38); //38 Caracater Detalle detalle = new Detalle(tipoDeDetalle, numCliente, documento, moneda, primerVencimiento, importePrimerVencimiento, segundoVencimiento, importeSegundoVencimiento, tercerVencimiento, importeTercerVencimiento, valorFijoSegundo, numReferencia, mensajeTicket, codBarras); miListaDeDetalle.Add(detalle); } if (tipoLinea == "9") { string tipoDeFooter = line.Substring(0, 1); //1 Caracater string valorFijoFooter = line.Substring(1, 3); //3 Caracater string comercio = line.Substring(4, 4); //4 Caracater string fechaFotter = line.Substring(8, 8); //8 Caracater formato AAAAMMDD string cantRegistros = line.Substring(16, 7); //7 Caracater string valorFijoSegundoDelFooter = line.Substring(23, 7); //7 Caracater string importe = line.Substring(30, 11); //11 Caracater footer = new Footer(tipoDeFooter, valorFijoFooter, comercio, fechaFotter, cantRegistros, valorFijoSegundoDelFooter, importe); } } Deuda deudaArchivo = new Deuda(header, miListaDeDetalle, footer); retorno = true; deuda = deudaArchivo; } } catch (Exception) { throw new Exception("Error Leer"); } return(retorno); }