first commit
This commit is contained in:
100
Classes/SaaiM3Helper.cs
Normal file
100
Classes/SaaiM3Helper.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
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<Registro> LeerArchivo(string rutaArchivo)
|
||||
{
|
||||
var registros = new List<Registro>();
|
||||
|
||||
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<Registro> BuscarPorTipo(List<Registro> registros, string tipo)
|
||||
{
|
||||
var lista = new List<Registro>();
|
||||
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<Registro> BuscarPorTipoYCampo(List<Registro> registros, string tipo, int indexCampo, string valor)
|
||||
{
|
||||
var lista = new List<Registro>();
|
||||
|
||||
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<Registro> BuscarPorTipoYCampoParcial(List<Registro> registros, string tipo, int indexCampo, string contiene)
|
||||
{
|
||||
var lista = new List<Registro>();
|
||||
|
||||
foreach (var r in registros)
|
||||
{
|
||||
if (r.Tipo == tipo)
|
||||
{
|
||||
if (r.Campos.Length > indexCampo &&
|
||||
r.Campos[indexCampo].Contains(contiene))
|
||||
{
|
||||
lista.Add(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lista;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user