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

121 lines
6.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bdGrupoSanchoToro.Importaciones
{
public static class ImportarTodo
{
public delegate void DelegadoErroresImportacion(Exception ex);
delegate void DelegadoImportar(Byte[] Datos);
public static void Importar(DelegadoErroresImportacion de)
{
tscGrupoSanchoToro bd = tscGrupoSanchoToro.NuevoContexto();
//00
//Importa("GRUASGC", bdGrupoSanchoToro.Importaciones.ImportaGRUASGC.Importar, de); //00
//Importa("FAMILIAS", bdGrupoSanchoToro.Importaciones.ImportaFAMILIAS.Importar, de); //00
//Importa("FAMILIAS", bdGrupoSanchoToro.Importaciones.ImportaFAMILIAS.Importar, de); //00
//Importa("CTESGESL", bdGrupoSanchoToro.Importaciones.ImportaCTESGESL.Importar, de); //00
Importa("PRODUCTOS", bdGrupoSanchoToro.Importaciones.ImportaPRODUCTOS.Importar, de); //00
//Importa("GRUPRO", bdGrupoSanchoToro.Importaciones.ImportaGrupoProductos.Importar, de); //01
//Importa("CAMPAÑAS", bdGrupoSanchoToro.Importaciones.ImportaCampañas.Importar, de); //02
//Importa("PRODUCTOS", bdGrupoSanchoToro.Importaciones.ImportaProductos.Importar, de); //03
//Importa("PROBRU", bdGrupoSanchoToro.Importaciones.ImportaProductosBrutos.Importar, de); //04
//Importa("CTESFABC", bdGrupoSanchoToro.Importaciones.ImportaGrupoEnumeraciones.Importar, de); //00
//Importa("CTESFABL", bdGrupoSanchoToro.Importaciones.ImportaEnumeraciones.Importar, de); //00
//Importa("PROELA1", bdGrupoSanchoToro.Importaciones.ImportaProductosElaborados.Importar, de); //05
//Importa("PROELA2", bdGrupoSanchoToro.Importaciones.ImportaProductosElaborados.Importar, de); //05
//Importa("CODAGRU", bdGrupoSanchoToro.Importaciones.ImportaCodigosDeAccesoriosAgrupados.Importar, de); //07
//Importa("ALMACENAC", bdGrupoSanchoToro.Importaciones.ImportaAccesorios.Importar, de); //06
//Importa("TABLASC", bdGrupoSanchoToro.Importaciones.ImportaTablas.Importar, de); //08
//Importa("TABLASL", bdGrupoSanchoToro.Importaciones.ImportaParametrosDeTablas.Importar, de); //09
//Importa("ENTIBAN", bdGrupoSanchoToro.Importaciones.ImportaEntidadesBancarias.Importar, de); //10
//Importa("AGEBAN", bdGrupoSanchoToro.Importaciones.ImportaAgenciasBancarias.Importar, de); //11
//Importa("BANCOSEMP", bdGrupoSanchoToro.Importaciones.ImportaBancosEmpresa.Importar, de); //12
//Importa("FPAGO", bdGrupoSanchoToro.Importaciones.ImportaFormasDePago.Importar, de); //13
//Importa("PROVEEDORES", bdGrupoSanchoToro.Importaciones.ImportaProveedores.Importar, de); //14
//Importa("PROVEEDORH", bdGrupoSanchoToro.Importaciones.ImportaProveedoresh.Importar, de); //25
//Importa("CLIENTES", bdGrupoSanchoToro.Importaciones.ImportaClientes.Importar, de); //15
//Importa("CLIENTESH", bdGrupoSanchoToro.Importaciones.ImportaClientesh.Importar, de); //26
// Importa("PERSONAL", bdGrupoSanchoToro.Importaciones.ImportaClientesh.Importar, de); //26
}
//public static void ImportarPersonal(DelegadoErroresImportacion de)
//{
// tscGrupoSanchoToro bd = tscGrupoSanchoToro.NuevoContexto();
// Importa("PERSONAL", bdGrupoSanchoToro.Importaciones.ImportaPersonal.Importar, de);
//}
static void Importa(string NombreFicheroEnHP, DelegadoImportar di, DelegadoErroresImportacion de)
{
tscGrupoSanchoToro bd = tscGrupoSanchoToro.NuevoContexto();
byte[]? datos = null;
try
{
datos = DescargarDeHP(bd, NombreFicheroEnHP);
if (datos != null) di(datos);
}
catch (Exception ex)
{
de(ex);
}
}
public static byte[]? DescargarDeHP(tscGrupoSanchoToro bd, string Fichero)
{
string Fich = "/var/tecnosis/DATAXML/PENDIENTES/" + Fichero + ".DATA";
string Fichi = "/var/tecnosis/DATAXML/PENDIENTES/" + Fichero + ".IGUAL";
string Fichh = "/var/tecnosis/DATAXML/HISTORICO/" + Fichero + ".DATA";
var sftp = ConfiguraFTPHP(bd);
var st = new MemoryStream();
var std = new MemoryStream();
if (tsFluentFTP.ftp.ExisteFichero(Fich, sftp))
{
tsFluentFTP.ftp.DescargaFichero(Fich, st, sftp);
st.Seek(0, 0);
tsUtilidades.Ficheros.EliminaCaracteresInvalidosXML(st, std);
std.Seek(0, 0);
// tsFluentFTP.ftp.RenombraFichero(Fich,Fichh, sftp);
return std.ToArray();
}
else
{
if (!tsFluentFTP.ftp.ExisteFichero(Fichi, sftp)) throw new Exception("No se ha Generado el Fichero " + Fichero);
return null;
}
}
public static tsFluentFTP.ServidorFTP ConfiguraFTPHP(tscGrupoSanchoToro bd)
{
try
{
string sCadServidor = (from c in bd.enumeraciones
where c.Codigo == "CONF.HP9000"
select c).First().ValorAlfabeticoLargo;
string Servidor = sCadServidor.Split("@")[0];
string Usuario = sCadServidor.Split("@")[1].Split(":")[0];
string contraseña = sCadServidor.Split("@")[1].Split(":")[1];
int Puerto = 21;
bool Pasivo = false;
tsFluentFTP.SeguridadFTP Seguridad;
Seguridad = tsFluentFTP.SeguridadFTP.Ninguna;
int Timeout = 60000;
var ftp = new tsFluentFTP.ServidorFTP(Servidor, Puerto, Usuario, contraseña, Seguridad, Pasivo, Timeout);
return ftp;
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
}
}
}