Files
SanchoToro/bdGrupoSanchoToro/Importaciones/ImportaCTESGESL.cs
2026-01-29 13:04:08 +01:00

62 lines
2.2 KiB
C#

using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bdGrupoSanchoToro.Importaciones
{
public class ImportaCTESGESL
{
public static void Importar(byte[] Fichero)
{
try
{
var bd = tscGrupoSanchoToro.NuevoContexto();
var le = bd.enumeraciones.ToList();
var grs = bd.gruposenumeraciones.ToList();
var dsprueba = new XSD.CTESGESL();
dsprueba.ReadXml(new System.IO.MemoryStream(Fichero));
int i = 1;
int Ultimalinea = dsprueba.Tables["Datos"].Rows.Count;
foreach (XSD.CTESGESL.DatosRow Proant in dsprueba.Tables["Datos"].Rows)
{
try
{
bdGrupoSanchoToro.db.enumeraciones Pronue;
Pronue = le.FirstOrDefault(x => x.Codigo == Proant.LCCOD.Trim());
if (Pronue == null)
{
Pronue = new bdGrupoSanchoToro.db.enumeraciones();
bd.enumeraciones.Add(Pronue);
}
Pronue.Codigo = Proant.LCCOD.Trim();
int idgrupo = grs.First(x => x.Grupo == Proant.LCGRU.Trim()).idGrupoEnumeracion;
Pronue.idGrupoEnumeracion = idgrupo;
Pronue.ValorAlfabetico1 = Proant.LCDES.Trim();
Pronue.Descripcion = Proant.LCVAA.Trim();
Pronue.Orden = int.Parse(Proant.LCORD);
i = i + 1;
if (i > 1000)
{
bd.SaveChanges();
i = 0;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}
bd.SaveChanges();
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}
}
}