using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace EFCDesk.Classes { public static class SaaiM3Helper { public class Registro { public string Tipo { get; set; } public string[] Campos { get; set; } } // ----------------------------- // Cargar archivo completo // ----------------------------- public static List LeerArchivo(string rutaArchivo) { var registros = new List(); foreach (var linea in File.ReadLines(rutaArchivo)) { if (String.IsNullOrWhiteSpace(linea)) continue; var partes = linea.Split('|'); registros.Add(new Registro { Tipo = partes[0], Campos = partes }); } return registros; } // -------------------------------------- // Buscar por tipo (ej. "551") // -------------------------------------- public static List BuscarPorTipo(List registros, string tipo) { var lista = new List(); foreach (var r in registros) { if (r.Tipo == tipo) lista.Add(r); } return lista; } // ----------------------------------------------------------------------------------- // Buscar por tipo y por valor en un campo específico // Ej: Buscar "551" donde Campos[2] == "4000204" // ----------------------------------------------------------------------------------- public static List BuscarPorTipoYCampo(List registros, string tipo, int indexCampo, string valor) { var lista = new List(); foreach (var r in registros) { if (r.Tipo == tipo) { if (r.Campos.Length > indexCampo && r.Campos[indexCampo] == valor) { lista.Add(r); } } } return lista; } // ---------------------------------------- // Búsqueda parcial (contiene) // ---------------------------------------- public static List BuscarPorTipoYCampoParcial(List registros, string tipo, int indexCampo, string contiene) { var lista = new List(); foreach (var r in registros) { if (r.Tipo == tipo) { if (r.Campos.Length > indexCampo && r.Campos[indexCampo].Contains(contiene)) { lista.Add(r); } } } return lista; } } }