81 lines
3.0 KiB
C#
81 lines
3.0 KiB
C#
using Castle.Core.Configuration;
|
|
using Microsoft.VisualBasic;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Drawing.Imaging;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using tsUtilidades.Extensiones;
|
|
|
|
namespace bdGrupoSanchoToro.Importaciones
|
|
{
|
|
public class ImportaARTICULOS
|
|
{
|
|
public static void Importar(byte[] Fichero)
|
|
{
|
|
try
|
|
{
|
|
var bd = tscGrupoSanchoToro.NuevoContexto();
|
|
var lp = bd.productos.Where(x=> x.Tipo!=(int)db.productos.TipoProductoEnum.GRUA).ToList();
|
|
var la = bd.articulos.ToList();
|
|
|
|
var ds = new XSD.ARTICULOS();
|
|
ds.ReadXml(new System.IO.MemoryStream(Fichero));
|
|
int i = 1;
|
|
int Ultimalinea = ds.Tables["Datos"].Rows.Count;
|
|
foreach (XSD.ARTICULOS.DatosRow ar in ds.Tables["Datos"].Rows)
|
|
{
|
|
try
|
|
{
|
|
|
|
var pr = lp.FirstOrDefault(x => x.Codigo == ar.ARCPR || x.Descripcion == ar.ARDES.Trim());
|
|
if (pr == null)
|
|
{
|
|
string sDes = ImportaPRODUCTOS.pros.FirstOrDefault(x=>x.PRCOD == ar.ARCPR )?.PRDES;
|
|
pr = lp.FirstOrDefault(x => x.Descripcion == sDes);
|
|
}
|
|
if (pr != null)
|
|
{
|
|
var art = la.FirstOrDefault(x => x.idProducto == pr.idProducto && x.CodigoArticulo == ar.ARNSE.Trim()) ;
|
|
if (art == null)
|
|
{
|
|
art = new bdGrupoSanchoToro.db.articulos();
|
|
bd.articulos.Add(art);
|
|
la.Add(art);
|
|
}
|
|
art.idProductoNavigation = pr;
|
|
art.CodigoArticulo = ar.ARNSE.Trim();
|
|
art.NumeroSerie = ar.ARNSE.Trim();
|
|
art.FechaBaja = ar.ARFEN.FechaStringADateOnly();
|
|
//art.FechaBaja = ar.CPFBA.FechaStringADateOnly();
|
|
// art.Matricula = ar.CPMAT;
|
|
i = i + 1;
|
|
if (i > 1000)
|
|
{
|
|
bd.SaveChanges();
|
|
i = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.Write("aqui");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message, ex);
|
|
}
|
|
}
|
|
bd.SaveChanges();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message, ex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|