public static IList <AutoahorroDato> ParseoGanadores(Stream input, ref ArchivoAutoahorro archivoAutoahorro) { if (archivoAutoahorro.NombreArchivo.ToLower().EndsWith("txt")) { return(ParseoGanadoresTXT(input, ref archivoAutoahorro)); } else if (archivoAutoahorro.NombreArchivo.ToLower().EndsWith("xls") || archivoAutoahorro.NombreArchivo.ToLower().EndsWith("xlsx")) { return(ParseoGanadoresXLS(input, ref archivoAutoahorro)); } return(null); }
public static List <AutoahorroDato> ParseoGanadoresTXT(Stream input, ref ArchivoAutoahorro archivoAutoahorro) { using (StreamReader streamReader = new StreamReader(input)) { string archivo = streamReader.ReadToEnd(); string pattern = @"Fecha (?<Fecha>\d{2}/\d{2}/\d{2})"; foreach (Match m in Regex.Matches(archivo, pattern)) { archivoAutoahorro.Fecha = DateTime.ParseExact(m.Groups["Fecha"].Value.Trim(), "dd/MM/yy", null); archivoAutoahorro.Fecha = new DateTime(archivoAutoahorro.Fecha.Year, archivoAutoahorro.Fecha.Month, 20); archivoAutoahorro.OfertasRecibidas = DateTime.ParseExact(m.Groups["Fecha"].Value.Trim(), "dd/MM/yy", null); archivoAutoahorro.FechaAlta = DateTime.Now; break; } pattern = @"(?<GRUPO>\d{1,4})-(?<ORDEN>\d{1,3})[ ]*(?<ADJUDICADO>.{38})(?<TIPOADJ>.{12})(?<IMPORTE>.{8})(?<GRILLA>.{10})(?<CONCESIONARIO>.{7})"; int i = 0; List <AutoahorroDato> res = new List <AutoahorroDato>(); AutoahorroGanador ganador; foreach (Match m in Regex.Matches(archivo, pattern)) { ganador = new AutoahorroGanador(); ganador.Grupo = int.Parse(m.Groups["GRUPO"].Value.Trim()); ganador.Orden = int.Parse(m.Groups["ORDEN"].Value.Trim()); ganador.Nombre = m.Groups["ADJUDICADO"].Value.Trim(); ganador.Tipo = m.Groups["TIPOADJ"].Value.Trim(); ganador.Monto = (m.Groups["IMPORTE"].Value.Trim() != string.Empty) ? float.Parse(m.Groups["IMPORTE"].Value, CultureInfo.InvariantCulture) : 0; ganador.Grilla = int.Parse(m.Groups["GRILLA"].Value.Trim()); ganador.Concesionario = m.Groups["CONCESIONARIO"].Value.Trim(); res.Add(ganador); i++; } return(res); } }
public ActionResult Archivo_Crear(HttpPostedFileBase[] ArchivosPosteados, int Tipo) { if (Tipo == 1) { if (ArchivosPosteados.Length > 0 && ArchivosPosteados[0].ContentLength > 0) { ArchivoAutoahorro archivoAutoahorro = new ArchivoAutoahorro(); archivoAutoahorro.NombreArchivo = ArchivosPosteados[0].FileName; archivoAutoahorro.FechaAlta = DateTime.Now; archivoAutoahorro.Activo = true; int i = 0; //string sql = string.Format("exec BuscarArchivoYBorrarlo @archivo = '{0}'", archivoAutoahorro.NombreArchivo); //ServicioSistema<ArchivoAutoahorro>.ExecuteSQLQueryUniqueResult(sql); IList <AutoahorroDato> listaAutoahorro = new List <AutoahorroDato>(); listaAutoahorro = HelperWeb.Parseo.ParseoOfertas(ArchivosPosteados[0].InputStream, ref archivoAutoahorro); DateTime inicio, fin; inicio = DateTime.Now; try { if (listaAutoahorro != null) { ServicioSistema <AutoahorroDato> .BeginTransaction(); archivoAutoahorro.CantidadRegistros = listaAutoahorro.Count; //foreach (AutoahorroDato dato in listaAutoahorro.Where(aad => ((AutoahorroOferta)aad).Concesionario == "01411").ToList()) foreach (AutoahorroDato dato in listaAutoahorro) { dato.ArchivoAutoahorro = archivoAutoahorro; ServicioSistema <AutoahorroDato> .SaveOrUpdateWithoutFlush(dato); if (++i % 500 == 0) { ServicioSistema <AutoahorroDato> .Flush(); } } archivoAutoahorro.CantidadRegistros = listaAutoahorro.Count; ServicioSistema <ArchivoAutoahorro> .SaveOrUpdate(archivoAutoahorro); ServicioSistema <AutoahorroDato> .CommitTransaction(); } else { throw new ApplicationException("Error en el archivo de ofertas."); } } catch (Exception ex) { ServicioSistema <AutoahorroDato> .RollbackTransaction(); throw ex; } fin = DateTime.Now; } } else if (Tipo == 2) { if (ArchivosPosteados.Length > 0 && ArchivosPosteados[0].ContentLength > 0) { ArchivoAutoahorro archivoAutoahorro = new ArchivoAutoahorro(); archivoAutoahorro.NombreArchivo = ArchivosPosteados[0].FileName; archivoAutoahorro.FechaAlta = DateTime.Now; archivoAutoahorro.Activo = true; int i = 0; //string sql = string.Format("exec BuscarArchivoYBorrarlo @archivo = '{0}'", archivoAutoahorro.NombreArchivo); //ServicioSistema<ArchivoAutoahorro>.ExecuteSQLQueryUniqueResult(sql); List <AutoahorroDato> listaAutoahorro = new List <AutoahorroDato>(); listaAutoahorro = HelperWeb.Parseo.ParseoEmisiones(ArchivosPosteados[0].InputStream, ref archivoAutoahorro); try { if (listaAutoahorro != null) { ServicioSistema <AutoahorroDato> .BeginTransaction(); foreach (AutoahorroDato dato in listaAutoahorro) { dato.ArchivoAutoahorro = archivoAutoahorro; ServicioSistema <AutoahorroDato> .SaveOrUpdateWithoutFlush(dato); if (++i % 500 == 0) { ServicioSistema <AutoahorroDato> .Flush(); } } archivoAutoahorro.CantidadRegistros = listaAutoahorro.Count; ServicioSistema <ArchivoAutoahorro> .SaveOrUpdate(archivoAutoahorro); ServicioSistema <AutoahorroDato> .CommitTransaction(); } else { throw new ApplicationException("Error en el archivo de emisiones."); } } catch (Exception ex) { ServicioSistema <AutoahorroDato> .RollbackTransaction(); throw ex; } } } else if (Tipo == 3) { if (ArchivosPosteados.Length > 0 && ArchivosPosteados[0].ContentLength > 0) { ArchivoAutoahorro archivoAutoahorro = new ArchivoAutoahorro(); archivoAutoahorro.NombreArchivo = ArchivosPosteados[0].FileName; archivoAutoahorro.FechaAlta = DateTime.Now; archivoAutoahorro.Activo = true; int i = 0; //string sql = string.Format("exec BuscarArchivoYBorrarlo @archivo = '{0}'", archivoAutoahorro.NombreArchivo); //ServicioSistema<ArchivoAutoahorro>.ExecuteSQLQueryUniqueResult(sql); IList <AutoahorroDato> listaAutoahorro = new List <AutoahorroDato>(); listaAutoahorro = HelperWeb.Parseo.ParseoGanadores(ArchivosPosteados[0].InputStream, ref archivoAutoahorro); try { ServicioSistema <AutoahorroDato> .BeginTransaction(); foreach (AutoahorroDato dato in listaAutoahorro.Where(aad => ((AutoahorroGanador)aad).Concesionario == "01411").ToList()) { dato.ArchivoAutoahorro = archivoAutoahorro; ServicioSistema <AutoahorroDato> .SaveOrUpdateWithoutFlush(dato); if (++i % 500 == 0) { ServicioSistema <AutoahorroDato> .Flush(); } } archivoAutoahorro.CantidadRegistros = listaAutoahorro.Count; ServicioSistema <ArchivoAutoahorro> .SaveOrUpdate(archivoAutoahorro); ServicioSistema <AutoahorroDato> .CommitTransaction(); //litCantidadGanadores.Text = string.Format("{0} ganadores cargados", listaAutoahorro.Count); } catch (Exception ex) { ServicioSistema <AutoahorroDato> .RollbackTransaction(); throw ex; } } } return(RedirectToAction("ListarArchivos", new { Tipo = Tipo })); }
public ActionResult CargaArchivos(Matassi.Web.Areas.Admin.Models.ArchivosAutoahorro archivosAutoahorro) { //Proceso Ofertas de Autoahorro ArchivoAutoahorro archivoAutoahorro; string sql; if (archivosAutoahorro.ArchivoOfertas != null && archivosAutoahorro.ArchivoOfertas.ContentLength > 0) { archivoAutoahorro = new ArchivoAutoahorro(); archivoAutoahorro.NombreArchivo = archivosAutoahorro.ArchivoOfertas.FileName; archivoAutoahorro.FechaAlta = DateTime.Now; archivoAutoahorro.Activo = true; int i = 0; //sql = string.Format("exec BuscarArchivoYBorrarlo @archivo = '{0}'", archivoAutoahorro.NombreArchivo); //ServicioSistema<ArchivoAutoahorro>.ExecuteSQLQueryUniqueResult(sql); IList <AutoahorroDato> listaAutoahorro = new List <AutoahorroDato>(); listaAutoahorro = HelperWeb.Parseo.ParseoOfertas(archivosAutoahorro.ArchivoOfertas.InputStream, ref archivoAutoahorro); try { if (listaAutoahorro != null) { ServicioSistema <AutoahorroDato> .BeginTransaction(); archivoAutoahorro.CantidadRegistros = listaAutoahorro.Count; foreach (AutoahorroDato dato in listaAutoahorro) { dato.ArchivoAutoahorro = archivoAutoahorro; ServicioSistema <AutoahorroDato> .SaveOrUpdateWithoutFlush(dato); if (++i % 20 == 0) { ServicioSistema <AutoahorroDato> .Flush(); } } archivoAutoahorro.CantidadRegistros = listaAutoahorro.Count; ServicioSistema <ArchivoAutoahorro> .SaveOrUpdate(archivoAutoahorro); ServicioSistema <AutoahorroDato> .CommitTransaction(); } else { throw new ApplicationException("Error en el archivo de ofertas."); } } catch (Exception ex) { ServicioSistema <AutoahorroDato> .RollbackTransaction(); throw ex; } } if (archivosAutoahorro.ArchivoEmisiones != null && archivosAutoahorro.ArchivoEmisiones.ContentLength > 0) { archivoAutoahorro = new ArchivoAutoahorro(); archivoAutoahorro.NombreArchivo = archivosAutoahorro.ArchivoEmisiones.FileName; archivoAutoahorro.FechaAlta = DateTime.Now; archivoAutoahorro.Activo = true; int i = 0; //sql = string.Format("exec BuscarArchivoYBorrarlo @archivo = '{0}'", archivoAutoahorro.NombreArchivo); //ServicioSistema<ArchivoAutoahorro>.ExecuteSQLQueryUniqueResult(sql); List <AutoahorroDato> listaAutoahorro = new List <AutoahorroDato>(); listaAutoahorro = HelperWeb.Parseo.ParseoEmisiones(archivosAutoahorro.ArchivoEmisiones.InputStream, ref archivoAutoahorro); try { ServicioSistema <AutoahorroDato> .BeginTransaction(); foreach (AutoahorroDato dato in listaAutoahorro) { dato.ArchivoAutoahorro = archivoAutoahorro; ServicioSistema <AutoahorroDato> .SaveOrUpdateWithoutFlush(dato); if (++i % 20 == 0) { ServicioSistema <AutoahorroDato> .Flush(); } } archivoAutoahorro.CantidadRegistros = listaAutoahorro.Count; ServicioSistema <ArchivoAutoahorro> .SaveOrUpdate(archivoAutoahorro); ServicioSistema <AutoahorroDato> .CommitTransaction(); //litCantidadEmisiones.Text = string.Format("{0} emisiones cargadas", listaAutoahorro.Count); } catch (Exception ex) { ServicioSistema <AutoahorroDato> .RollbackTransaction(); throw ex; } } if (archivosAutoahorro.ArchivoGanadores != null && archivosAutoahorro.ArchivoGanadores.ContentLength > 0) { archivoAutoahorro = new ArchivoAutoahorro(); archivoAutoahorro.NombreArchivo = archivosAutoahorro.ArchivoGanadores.FileName; archivoAutoahorro.FechaAlta = DateTime.Now; archivoAutoahorro.Activo = true; int i = 0; //sql = string.Format("exec BuscarArchivoYBorrarlo @archivo = '{0}'", archivoAutoahorro.NombreArchivo); //ServicioSistema<ArchivoAutoahorro>.ExecuteSQLQueryUniqueResult(sql); IList <AutoahorroDato> listaAutoahorro = new List <AutoahorroDato>(); listaAutoahorro = HelperWeb.Parseo.ParseoGanadores(archivosAutoahorro.ArchivoGanadores.InputStream, ref archivoAutoahorro); try { ServicioSistema <AutoahorroDato> .BeginTransaction(); foreach (AutoahorroDato dato in listaAutoahorro) { dato.ArchivoAutoahorro = archivoAutoahorro; ServicioSistema <AutoahorroDato> .SaveOrUpdateWithoutFlush(dato); if (++i % 20 == 0) { ServicioSistema <AutoahorroDato> .Flush(); } } archivoAutoahorro.CantidadRegistros = listaAutoahorro.Count; ServicioSistema <ArchivoAutoahorro> .SaveOrUpdate(archivoAutoahorro); ServicioSistema <AutoahorroDato> .CommitTransaction(); //litCantidadGanadores.Text = string.Format("{0} ganadores cargados", listaAutoahorro.Count); } catch (Exception ex) { ServicioSistema <AutoahorroDato> .RollbackTransaction(); throw ex; } } ObtenerArchivosCargados(); return(View()); }
public static IList <AutoahorroDato> ParseoGanadoresXLS(Stream input, ref ArchivoAutoahorro archivoAutoahorro) { IWorkbook hssfwb = WorkbookFactory.Create(input); //HSSFWorkbook hssfwb = new HSSFWorkbook(input); ISheet sheet = hssfwb.GetSheetAt(0); if (sheet.LastRowNum > 3) { //ACTO N° 460 - REALIZADO EL 11-3-2016 CONCESIONARIO: AUTOTAG S.A. string pattern = @"ACTO.+(?<Acto>\d{3}).+REALIZADO EL (?<Fecha>\d{1,2}-\d{1,2}-\d{4}).+CONCESIONARIO:(?<Concesionario>.+).+"; Regex regEx = new Regex(pattern, RegexOptions.IgnoreCase); Match m = regEx.Match(sheet.GetRow(0).GetCell(0).StringCellValue); while (m.Success) { archivoAutoahorro.Acto = int.Parse(m.Groups["Acto"].Value.Trim()); archivoAutoahorro.Fecha = DateTime.ParseExact(m.Groups["Fecha"].Value.Trim(), new string[] { "dd-M-yyyy", "dd-MM-yyyy", "d-M-yyyy", "d-MM-yyyy" }, CultureInfo.InvariantCulture, DateTimeStyles.None); archivoAutoahorro.Concesionario = m.Groups["Concesionario"].Value.Trim(); m = m.NextMatch(); } pattern = @".+ASAMBLEA (?<ofertasRecibidas>\d{1,2}/\d{4})"; regEx = new Regex(pattern, RegexOptions.IgnoreCase); m = regEx.Match(sheet.GetRow(1).GetCell(0).StringCellValue); while (m.Success) { archivoAutoahorro.OfertasRecibidas = DateTime.ParseExact(m.Groups["ofertasRecibidas"].Value.Trim(), new string[] { "MM/yyyy", "M/yyyy" }, CultureInfo.InvariantCulture, DateTimeStyles.None); m = m.NextMatch(); } List <AutoahorroDato> ganadores = new List <AutoahorroDato>(); AutoahorroGanador ganador = null; for (int row = 3; row <= sheet.LastRowNum; row++) { if (sheet.GetRow(row) != null) //null is when the row only contains empty cells { if (Regex.IsMatch(sheet.GetRow(row).GetCell(0).StringCellValue.Trim(), "^\\d{4}\\-\\d{3}$")) { ganador = new AutoahorroGanador(); ganador.Grupo = (sheet.GetRow(row).GetCell(0) != null) ? int.Parse(sheet.GetRow(row).GetCell(0).StringCellValue.Substring(0, 4)) : 0; ganador.Orden = (sheet.GetRow(row).GetCell(0) != null) ? int.Parse(sheet.GetRow(row).GetCell(0).StringCellValue.Substring(5, 3)) : 0; ganador.Tipo = (sheet.GetRow(row).GetCell(1) != null) ? sheet.GetRow(row).GetCell(1).StringCellValue : string.Empty; ganador.Monto = (sheet.GetRow(row).GetCell(2) != null) ? float.Parse(sheet.GetRow(row).GetCell(2).StringCellValue, CultureInfo.InvariantCulture) : 0; ganador.Grilla = (sheet.GetRow(row).GetCell(3) != null) ? int.Parse(sheet.GetRow(row).GetCell(3).StringCellValue) : 0; ganador.Concesionario = (sheet.GetRow(row).GetCell(4) != null) ? sheet.GetRow(row).GetCell(4).StringCellValue : string.Empty; ganadores.Add(ganador); } else if (Regex.IsMatch(sheet.GetRow(row).GetCell(0).StringCellValue.Trim(), "^\\d{4}$")) { ganador = new AutoahorroGanador(); ganador.Grupo = (sheet.GetRow(row).GetCell(0) != null) ? int.Parse(sheet.GetRow(row).GetCell(0).StringCellValue.Trim()) : 0; ganador.Orden = (sheet.GetRow(row).GetCell(1) != null) ? int.Parse(sheet.GetRow(row).GetCell(1).StringCellValue.Trim()) : 0; ganador.Tipo = (sheet.GetRow(row).GetCell(2) != null) ? sheet.GetRow(row).GetCell(2).StringCellValue.Trim() : string.Empty; ganador.Monto = (sheet.GetRow(row).GetCell(3) != null) ? float.Parse(sheet.GetRow(row).GetCell(3).StringCellValue.Trim(), CultureInfo.InvariantCulture) : 0; ganador.Grilla = (sheet.GetRow(row).GetCell(4) != null) ? int.Parse(sheet.GetRow(row).GetCell(4).StringCellValue.ToString().Trim()) : 0; ganador.Concesionario = (sheet.GetRow(row).GetCell(5) != null) ? sheet.GetRow(row).GetCell(5).StringCellValue.ToString().Trim() : string.Empty; ganadores.Add(ganador); } } } return(ganadores); } return(null); }
//public static IList<AutoahorroEmision> ParseoEmisiones(Stream input) public static List <AutoahorroDato> ParseoEmisiones(Stream input, ref ArchivoAutoahorro archivoAutoahorro) { using (StreamReader streamReader = new StreamReader(input)) { //string archivo = streamReader.ReadToEnd(); //string grupo, orden, modelo, observacion, concesionario; //float tAjustado, tLicitado; bool fechaEnArchivo = false; string linea; string[] patterns = new string[3]; patterns[0] = @"[ ]*(?<GPO>\d{4})[ ]*(?<ORD>\d{3})[ ]*(?<DC>\d{1})[ ]*(?<DESV>\d{2})[ ]*(?<CUOT>\d{2})[ ]*(?<DC2>\d{1})[ ]*(?<PLAN>\d{2})[ ]*(?<MOD>[A-Za-z0-9]{5})[ ]*(?<VENCE>[0-9]{2}/[0-9]{2}/[0-9]{4})[ ]*(?<NOMBRE>.{32})(?<BANCO>.{14})(?<SUCURSAL>.{19})(?<CUENTA>.+).*"; patterns[1] = @"[ ]*(?<ALICUOTA>[0-9]+,[0-9]{2})[ ]*(?<CARGOS>[0-9]+,[0-9]{2})[ ]*(?<ACTALICUOTA>[0-9]+,[0-9]{2})[ ]*(?<CAACTALIC>[0-9]+,[0-9]{2})[ ]*(?<SEGVIDA>[0-9]+,[0-9]{2})[ ]*(?<SEGBIEN>[0-9]+,[0-9]{2})[ ]*(?<MORA>[0-9]+,[0-9]{2})[ ]*(?<DEBCRED>[-]?[0-9]+,[0-9]{2})[ ]*(?<INTLIQUID>[0-9]+,[0-9]{2})[ ]*(?<OTROS>[0-9]+,[0-9]{2})"; patterns[2] = @".+(TOTAL :)[ ]+(?<TOTAL>([0-9]+\.)?[0-9]+,[0-9]{2}).*"; int patternActual = 0; int i = 0; //IList<AutoahorroEmision> listaEmisiones = new List<AutoahorroEmision>(); List <AutoahorroDato> listaEmisiones = new List <AutoahorroDato>(); AutoahorroEmision emision = null; bool flag1, flag2, flag3; flag1 = flag2 = flag3 = false; while ((linea = streamReader.ReadLine()) != null) { Match matchPattern = Regex.Match(linea, patterns[patternActual]); if (patternActual == 0 && matchPattern.Success) { patternActual = 1; emision = new AutoahorroEmision(); emision.Gpo = int.Parse(matchPattern.Groups["GPO"].Value); emision.Ord = int.Parse(matchPattern.Groups["ORD"].Value); emision.Dc = int.Parse(matchPattern.Groups["DC"].Value); emision.Desv = int.Parse(matchPattern.Groups["DESV"].Value); emision.Cuot = int.Parse(matchPattern.Groups["CUOT"].Value); emision.Dc2 = int.Parse(matchPattern.Groups["DC2"].Value); emision.Plan = matchPattern.Groups["PLAN"].Value; emision.Mod = matchPattern.Groups["MOD"].Value; emision.Vence = DateTime.ParseExact(matchPattern.Groups["VENCE"].Value, "dd/MM/yyyy", null); emision.Nombre = matchPattern.Groups["NOMBRE"].Value.Substring(0, 32).Trim(); emision.Banco = matchPattern.Groups["BANCO"].Value.Substring(0, 14).Trim(); emision.Sucursal = matchPattern.Groups["SUCURSAL"].Value.Substring(0, 19).Trim(); emision.Cuenta = matchPattern.Groups["CUENTA"].Value; emision.Cuenta = emision.Cuenta.Substring(0, (emision.Cuenta.Length > 13) ? 13 : emision.Cuenta.Length).Trim(); flag1 = true; } else if (patternActual == 1 && matchPattern.Success) { patternActual = 2; if (emision != null) { emision.Alicuota = float.Parse(matchPattern.Groups["ALICUOTA"].Value); emision.Cargos = float.Parse(matchPattern.Groups["CARGOS"].Value); emision.Actalicuota = float.Parse(matchPattern.Groups["ACTALICUOTA"].Value); emision.Caactalic = float.Parse(matchPattern.Groups["CAACTALIC"].Value); emision.SegVida = float.Parse(matchPattern.Groups["SEGVIDA"].Value); emision.SegBien = float.Parse(matchPattern.Groups["SEGBIEN"].Value); emision.Mora = float.Parse(matchPattern.Groups["MORA"].Value); emision.DebCred = float.Parse(matchPattern.Groups["DEBCRED"].Value); emision.Intliquid = float.Parse(matchPattern.Groups["INTLIQUID"].Value); emision.Otros = float.Parse(matchPattern.Groups["OTROS"].Value); } flag2 = true; } else if (patternActual == 2 && matchPattern.Success) { patternActual = 0; if (emision != null) { emision.Total = float.Parse(matchPattern.Groups["TOTAL"].Value); } flag3 = true; } if (flag1 && flag2 && flag3) { //Console.WriteLine(string.Format("gpo = {0}\nord = {1}\ndc = {2}\ndesv = {3}\ncuot = {4}\ndc2 = {5}\nplan = {6}\nmod = {7}\nvence = {8}\nnombre = {9}\nbanco = {10}\nsucursal = {11}\ncuenta = {12}\nalicuota = {13}\ncargos = {14}\nactalicuota = {15}\ncaactalic = {16}\nsegvida = {17}\nsegbien = {18}\nmora = {19}\ndebcred = {20}\nintliquid = {21}\notros = {22}\ntotal = {23}\n", gpo, ord, dc, desv, cuot, dc2, plan, mod, vence, nombre, banco, sucursal, cuenta, alicuota, cargos, actalicuota, caactalic, segvida, segbien, mora, debcred, intliquid, otros, total)); listaEmisiones.Add(emision); flag1 = flag2 = flag3 = false; i++; if (!fechaEnArchivo) { archivoAutoahorro.Fecha = emision.Vence; archivoAutoahorro.Concesionario = "1411-03 - MATASSI E IMPERIALE S.A."; archivoAutoahorro.OfertasRecibidas = emision.Vence; fechaEnArchivo = true; } } } //Console.Write(string.Format("Cantidad: {0}", i)); return(listaEmisiones); } }
public static IList <AutoahorroDato> ParseoOfertasTXT(Stream input, ref ArchivoAutoahorro archivoAutoahorro) { using (StreamReader streamReader = new StreamReader(input)) { string archivo = streamReader.ReadToEnd(); string pattern = @"Acto.+(?<Acto>\d{3}).+Fecha (?<Fecha>\d{2}/\d{2}/\d{2}).+Concesionario:(?<Concesionario>.+)\n.+Ofertas Recibidas (?<ofertasRecibidas>\d{2}/\d{2})"; foreach (Match m in Regex.Matches(archivo, pattern)) { archivoAutoahorro.Acto = int.Parse(m.Groups["Acto"].Value.Trim()); archivoAutoahorro.Fecha = DateTime.ParseExact(m.Groups["Fecha"].Value.Trim(), "dd/MM/yy", null); archivoAutoahorro.Concesionario = m.Groups["Concesionario"].Value.Trim(); archivoAutoahorro.OfertasRecibidas = DateTime.ParseExact(m.Groups["ofertasRecibidas"].Value.Trim(), "MM/yy", null); break; } string[] patterns = new string[3]; patterns[0] = @"[ ]*(?<SECNRO>\d{1,4})[ ]*(?<GRUPO>\d{4})-(?<ORDEN>\d{3}).*"; patterns[1] = @"[ ]*(?<MODELO>[A-Za-z0-9]{5})[ ]*(?<TAJUSTADO>[0-9]+\.[0-9]{2})[ ]*(?<TLICITADO>[0-9]+\.[0-9]{2})(?<OBSERVACION>.{10})[ ]*(?<CONCESIONARIO>\d{0,5})"; int patternActual = 0; int i = 0; List <AutoahorroDato> res = new List <AutoahorroDato>(); AutoahorroOferta oferta = null; string linea; bool flag1, flag2; flag1 = flag2 = false; streamReader.BaseStream.Seek(0, SeekOrigin.Begin); while ((linea = streamReader.ReadLine()) != null) { Match matchPattern = Regex.Match(linea, patterns[patternActual]); if (patternActual == 0 && matchPattern.Success) { patternActual = 1; oferta = new AutoahorroOferta(); oferta.SecNro = matchPattern.Groups["SECNRO"].Value.Trim(); oferta.Grupo = matchPattern.Groups["GRUPO"].Value.Trim(); oferta.Orden = matchPattern.Groups["ORDEN"].Value.Trim(); flag1 = true; } else if (patternActual == 1 && matchPattern.Success) { patternActual = 2; if (oferta != null) { patternActual = 0; oferta.Modelo = matchPattern.Groups["MODELO"].Value.Trim(); oferta.TAjustado = float.Parse(matchPattern.Groups["TAJUSTADO"].Value, CultureInfo.InvariantCulture); oferta.TLicitado = float.Parse(matchPattern.Groups["TLICITADO"].Value, CultureInfo.InvariantCulture); oferta.Observacion = matchPattern.Groups["OBSERVACION"].Value.Trim(); oferta.Concesionario = matchPattern.Groups["CONCESIONARIO"].Value.Trim(); } flag2 = true; } if (flag1 && flag2) { //Console.WriteLine(string.Format("gpo = {0}\nord = {1}\ndc = {2}\ndesv = {3}\ncuot = {4}\ndc2 = {5}\nplan = {6}\nmod = {7}\nvence = {8}\nnombre = {9}\nbanco = {10}\nsucursal = {11}\ncuenta = {12}\nalicuota = {13}\ncargos = {14}\nactalicuota = {15}\ncaactalic = {16}\nsegvida = {17}\nsegbien = {18}\nmora = {19}\ndebcred = {20}\nintliquid = {21}\notros = {22}\ntotal = {23}\n", gpo, ord, dc, desv, cuot, dc2, plan, mod, vence, nombre, banco, sucursal, cuenta, alicuota, cargos, actalicuota, caactalic, segvida, segbien, mora, debcred, intliquid, otros, total)); res.Add(oferta); flag1 = flag2 = false; i++; } } return(res); } }
public static IList <AutoahorroDato> ParseoOfertasXLS(Stream input, ref ArchivoAutoahorro archivoAutoahorro) { HSSFWorkbook hssfwb; hssfwb = new HSSFWorkbook(input); ISheet sheet = hssfwb.GetSheetAt(0); if (sheet.LastRowNum > 3) { //ACTO N° 460 - REALIZADO EL 11-3-2016 CONCESIONARIO: AUTOTAG S.A. string pattern = @"ACTO.+(?<Acto>\d{3}).+REALIZADO EL (?<Fecha>\d{1,2}-\d{1,2}-\d{4}).+CONCESIONARIO:(?<Concesionario>.+).+"; Regex regEx = new Regex(pattern, RegexOptions.IgnoreCase); Match m = regEx.Match(sheet.GetRow(0).GetCell(0).StringCellValue); while (m.Success) { archivoAutoahorro.Acto = int.Parse(m.Groups["Acto"].Value.Trim()); archivoAutoahorro.Fecha = DateTime.ParseExact(m.Groups["Fecha"].Value.Trim(), new string[] { "dd-M-yyyy", "dd-MM-yyyy", "d-M-yyyy", "d-MM-yyyy" }, CultureInfo.InvariantCulture, DateTimeStyles.None); archivoAutoahorro.Concesionario = m.Groups["Concesionario"].Value.Trim(); m = m.NextMatch(); } pattern = @".+ASAMBLEA (?<ofertasRecibidas>\d{1,2}/\d{4})"; regEx = new Regex(pattern, RegexOptions.IgnoreCase); m = regEx.Match(sheet.GetRow(1).GetCell(0).StringCellValue); while (m.Success) { archivoAutoahorro.OfertasRecibidas = DateTime.ParseExact(m.Groups["ofertasRecibidas"].Value.Trim(), new string [] { "MM/yyyy", "M/yyyy" }, CultureInfo.InvariantCulture, DateTimeStyles.None); m = m.NextMatch(); } List <AutoahorroDato> ofertas = new List <AutoahorroDato>(); AutoahorroOferta oferta = null; for (int row = 3; row <= sheet.LastRowNum; row++) { if (sheet.GetRow(row) != null) //null is when the row only contains empty cells { if (Regex.IsMatch(sheet.GetRow(row).GetCell(0).StringCellValue, "^\\d+$")) { oferta = new AutoahorroOferta(); oferta.SecNro = (sheet.GetRow(row).GetCell(0) != null) ? sheet.GetRow(row).GetCell(0).StringCellValue.Trim() : string.Empty; oferta.Grupo = (sheet.GetRow(row).GetCell(1) != null) ? sheet.GetRow(row).GetCell(1).StringCellValue.Trim() : string.Empty; oferta.Orden = (sheet.GetRow(row).GetCell(2) != null) ? sheet.GetRow(row).GetCell(2).StringCellValue.Trim() : string.Empty; oferta.Modelo = (sheet.GetRow(row).GetCell(3) != null) ? sheet.GetRow(row).GetCell(3).StringCellValue.Trim() : string.Empty; oferta.TAjustado = (sheet.GetRow(row).GetCell(4) != null) ? float.Parse(sheet.GetRow(row).GetCell(4).StringCellValue.Trim(), CultureInfo.InvariantCulture) : 0; oferta.TLicitado = (sheet.GetRow(row).GetCell(5) != null) ? float.Parse(sheet.GetRow(row).GetCell(5).StringCellValue.Trim(), CultureInfo.InvariantCulture) : 0; oferta.Observacion = (sheet.GetRow(row).GetCell(6) != null) ? (sheet.GetRow(row).GetCell(6).CellType == CellType.Numeric) ? sheet.GetRow(row).GetCell(6).NumericCellValue.ToString().Trim() : sheet.GetRow(row).GetCell(6).StringCellValue.Trim() : string.Empty; oferta.Concesionario = (sheet.GetRow(row).GetCell(7) != null) ? sheet.GetRow(row).GetCell(7).StringCellValue.Trim() : string.Empty; ofertas.Add(oferta); } } } return(ofertas); } return(null); }