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 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); }