7 using System.Collections.Generic;
16 using System.Data.SqlClient;
21 internal class OfflineUploader : OfflineUpAndDown
23 #region Métodos para el Asistente de Configuración 25 internal static bool Upload_Control_Files(
int nTipoCom,
bool isCentral,
int tnIdConf)
27 _Porcen_Progreso_Async -= OfflineUploader__Porcen_Progreso_Async;
28 _Mostrar_Progreso_Async -= OfflineUploader__Mostrar_Progreso_Async;
30 _Mostrar_Progreso_Async += OfflineUploader__Mostrar_Progreso_Async;
31 _Porcen_Progreso_Async += OfflineUploader__Porcen_Progreso_Async;
33 OfflineDatosComunicaciones datos =
new OfflineDatosComunicaciones();
35 if (!Directory.Exists(TempFolderName))
37 Directory.CreateDirectory(TempFolderName);
40 ComprobacionesPrevias(tnIdConf);
42 _cIdLog = _offlineConfig.GenerarRandomId();
44 datos._Log_ComoffID = _cIdLog;
45 datos._IdConf = tnIdConf;
46 datos._MultConf = DB.SQLValor(
"MULTCONF",
"IDCONF", tnIdConf.ToString(),
"CODIGO",
"OFFLINE").ToString();
48 datos._BdOffline = clsOfflineUtils.ObtenerNombreBdReal(
"OFFLINE");
49 datos._Sucursal =
string.Empty;
50 datos._PathFolderInicial = TempFolderName;
51 datos._IniServidor = DB._GetVariable(
"wc_iniservidor").ToString().ToLower();
52 datos._EnvioArticulos =
false;
53 datos._FechaInicial = Convert.ToDateTime(EW_GLOBAL._GetVariable(
"wd_periodoini"));
54 datos._FechaFinal = Convert.ToDateTime(EW_GLOBAL._GetVariable(
"wd_periodofin"));
55 datos._TipoCom = nTipoCom;
56 datos._IsCentral = isCentral;
59 DataTable tablaDatos =
new DataTable();
60 string lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"OFFLINE",
"SUCURSALES");
61 DB.SQLExec(lcSql, ref tablaDatos);
62 ConvertIndividualFile(tablaDatos, TempFolderName,
"SUCURSALES", FormatoExportacion.XML);
64 tablaDatos =
new DataTable();
65 lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"OFFLINE",
"SUCURALM");
66 DB.SQLExec(lcSql, ref tablaDatos);
67 ConvertIndividualFile(tablaDatos, TempFolderName,
"SUCURALM", FormatoExportacion.XML);
69 tablaDatos =
new DataTable();
70 lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"OFFLINE",
"SUCURLET");
71 DB.SQLExec(lcSql, ref tablaDatos);
72 ConvertIndividualFile(tablaDatos, TempFolderName,
"SUCURLET", FormatoExportacion.XML);
74 tablaDatos =
new DataTable();
75 lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"OFFLINE",
"SUCURCAJA");
76 DB.SQLExec(lcSql, ref tablaDatos);
77 ConvertIndividualFile(tablaDatos, TempFolderName,
"SUCURCAJA", FormatoExportacion.XML);
79 tablaDatos =
new DataTable();
80 lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"OFFLINE",
"SUCURCONF");
81 DB.SQLExec(lcSql, ref tablaDatos);
82 ConvertIndividualFile(tablaDatos, TempFolderName,
"SUCURCONF", FormatoExportacion.XML);
84 tablaDatos =
new DataTable();
85 lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"GESTION",
"ALMACEN");
86 DB.SQLExec(lcSql, ref tablaDatos);
87 ConvertIndividualFile(tablaDatos, TempFolderName,
"ALMACEN", FormatoExportacion.XML);
89 tablaDatos =
new DataTable();
90 lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"COMUNES",
"LETRAS");
91 DB.SQLExec(lcSql, ref tablaDatos);
92 ConvertIndividualFile(tablaDatos, TempFolderName,
"LETRAS", FormatoExportacion.XML);
94 tablaDatos =
new DataTable();
95 lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"OFFLINE",
"VARIABLES") +
" WHERE VARIABLE = 'ULTIMOLOG' ";
96 DB.SQLExec(lcSql, ref tablaDatos);
97 ConvertIndividualFile(tablaDatos, TempFolderName,
"VARIABLES", FormatoExportacion.XML);
99 tablaDatos =
new DataTable();
100 lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"OFFLINE",
"MULTCONF");
101 DB.SQLExec(lcSql, ref tablaDatos);
102 ConvertIndividualFile(tablaDatos, TempFolderName,
"MULTCONF", FormatoExportacion.XML);
104 tablaDatos =
new DataTable();
105 lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"OFFLINE",
"TABNETCONF");
106 DB.SQLExec(lcSql, ref tablaDatos);
107 ConvertIndividualFile(tablaDatos, TempFolderName,
"TABNETCONF", FormatoExportacion.XML);
109 tablaDatos =
new DataTable();
110 lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"OFFLINE",
"PRIORIDAD");
111 DB.SQLExec(lcSql, ref tablaDatos);
112 ConvertIndividualFile(tablaDatos, TempFolderName,
"PRIORIDAD", FormatoExportacion.XML);
117 if (datos._IsCentral)
119 _TextStepDetalle =
"Generando fichero configura_offline.xml";
120 _TextStepProgreso = _TextStepDetalle;
121 _PorcenProgreso = IncrementarBarraProgreso();
123 Subir_Fichero_Configuracion(datos, logRepository);
126 Eliminar_Carpetas_Temporales(datos, logRepository);
129 offlineUnitOfWork.Dispose();
131 _Porcen_Progreso_Async -= OfflineUploader__Porcen_Progreso_Async;
132 _Mostrar_Progreso_Async -= OfflineUploader__Mostrar_Progreso_Async;
166 internal static bool Upload_Offline_Files(clsOfflineUtils.ReportProgress progressReporter, DateTime tdFechaConf, DateTime tdFechaMin, DateTime tdFechaMax,
string tcSucursal,
bool tlImagenes,
bool tlAnterior,
bool isCentral,
int idConf,
bool tlInicial =
false, Dictionary<int, bool> prioridades = null)
168 _Mostrar_Progreso_Async -= OfflineUploader__Mostrar_Progreso_Async;
169 _Porcen_Progreso_Async -= OfflineUploader__Porcen_Progreso_Async;
171 _Mostrar_Progreso_Async += OfflineUploader__Mostrar_Progreso_Async;
172 _Porcen_Progreso_Async += OfflineUploader__Porcen_Progreso_Async;
174 _cTempFolderName =
string.Empty;
175 _cTempFileName = clsOfflineUtils.CrearNombreFicheroDatos(tcSucursal, idConf);
177 if (!Directory.Exists(TempFolderName))
179 Directory.CreateDirectory(TempFolderName);
182 ReestablecerInfoConfig();
183 Generar_Configuracion(progressReporter, tdFechaConf, tdFechaMin, tdFechaMax, isCentral, (tlInicial ?
"i" :
"e"), prioridades, tcSucursal);
187 bool llOk = GenerarDatosEnvio(tcSucursal, tlImagenes, tdFechaConf, tdFechaMin, tdFechaMax, isCentral, idConf, (tlInicial ?
"i" :
"e"), prioridades);
191 AsistenteOffEnvioDatosBizRule negocioOffline =
new AsistenteOffEnvioDatosBizRule();
193 if (negocioOffline.ValidacionEjercicioPredet())
195 string lcEjercicioPredeterminado = negocioOffline.GetEjercicioPredeterminado();
197 DataTable ldtEjercicios = negocioOffline.GetEjerciciosOffline();
199 DataRow[] rows = ldtEjercicios.Select(
"tipooff = " + DB.SQLString(isCentral ?
"CENTRAL" : tcSucursal));
201 foreach (DataRow item
in rows)
203 if (item.Field<DateTime?>(
"traspejer") == null || item.Field<DateTime>(
"traspejer") < tdFechaMin || item.Field<DateTime>(
"traspejer") > tdFechaMax)
208 GenerarDatosEnvioEjercicioPosterior(progressReporter, tdFechaConf, tdFechaMin, tdFechaMax, tcSucursal, tlImagenes, isCentral, idConf, tlInicial, prioridades, lcEjercicioPredeterminado, item);
210 GenerarDatosEnvioEjercicioAnterior(progressReporter, tdFechaConf, tdFechaMin, tdFechaMax, tcSucursal, tlImagenes, isCentral, idConf, tlInicial, prioridades, lcEjercicioPredeterminado, item);
215 _Mostrar_Progreso_Async -= OfflineUploader__Mostrar_Progreso_Async;
216 _Porcen_Progreso_Async -= OfflineUploader__Porcen_Progreso_Async;
221 private static void GenerarDatosEnvioEjercicioAnterior(clsOfflineUtils.ReportProgress progressReporter, DateTime tdFechaConf, DateTime tdFechaMin, DateTime tdFechaMax,
string tcSucursal,
bool tlImagenes,
bool isCentral,
int idConf,
bool tlInicial, Dictionary<int, bool> prioridades,
string lcEjercicioPredeterminado, DataRow item)
224 string lcEjercicioAnterior = item.Field<
string>(
"EJERCICIO");
226 if (!
string.IsNullOrWhiteSpace(lcEjercicioAnterior) && Convert.ToInt16(lcEjercicioAnterior) < Convert.ToInt16(lcEjercicioPredeterminado))
228 if (lcEjercicioAnterior != lcEjercicioPredeterminado)
231 FUNCTIONS.CambiarEjercicio(lcEjercicioPredeterminado, lcEjercicioAnterior);
233 _cTempFolderName =
string.Empty;
234 _cTempFileName = clsOfflineUtils.CrearNombreFicheroDatos(tcSucursal, idConf);
236 if (!Directory.Exists(TempFolderName))
238 Directory.CreateDirectory(TempFolderName);
241 ReestablecerInfoConfig();
242 Generar_Configuracion(progressReporter, tdFechaConf, tdFechaMin, tdFechaMax, isCentral, (tlInicial ?
"i" :
"e"), prioridades, tcSucursal);
243 GenerarDatosEnvio(tcSucursal, tlImagenes, tdFechaConf, tdFechaMin, tdFechaMax, isCentral, idConf, (tlInicial ?
"i" :
"e"), prioridades);
246 FUNCTIONS.CambiarEjercicio(lcEjercicioAnterior, lcEjercicioPredeterminado);
251 private static void GenerarDatosEnvioEjercicioPosterior(clsOfflineUtils.ReportProgress progressReporter, DateTime tdFechaConf, DateTime tdFechaMin, DateTime tdFechaMax,
string tcSucursal,
bool tlImagenes,
bool isCentral,
int idConf,
bool tlInicial, Dictionary<int, bool> prioridades,
string lcEjercicioPredeterminado, DataRow item)
254 string lcEjercicioPosterior = item.Field<
string>(
"EJERCICIO");
256 if (!
string.IsNullOrWhiteSpace(lcEjercicioPosterior) && Convert.ToInt16(lcEjercicioPosterior) > Convert.ToInt16(lcEjercicioPredeterminado))
258 if (lcEjercicioPosterior != lcEjercicioPredeterminado)
261 FUNCTIONS.CambiarEjercicio(lcEjercicioPredeterminado, lcEjercicioPosterior);
263 _cTempFolderName =
string.Empty;
264 _cTempFileName = clsOfflineUtils.CrearNombreFicheroDatos(tcSucursal, idConf);
266 if (!Directory.Exists(TempFolderName))
268 Directory.CreateDirectory(TempFolderName);
271 ReestablecerInfoConfig();
272 Generar_Configuracion(progressReporter, tdFechaConf, tdFechaMin, tdFechaMax, isCentral, (tlInicial ?
"i" :
"e"), prioridades, tcSucursal);
273 GenerarDatosEnvio(tcSucursal, tlImagenes, tdFechaConf, tdFechaMin, tdFechaMax, isCentral, idConf, (tlInicial ?
"i" :
"e"), prioridades);
276 FUNCTIONS.CambiarEjercicio(lcEjercicioPosterior, lcEjercicioPredeterminado);
281 private static void OfflineUploader__Mostrar_Progreso_Async(
string message)
286 _offBase._TextStepDetalle = message;
288 catch (Exception) { }
291 private static void OfflineUploader__Porcen_Progreso_Async(decimal porcen,
string message)
295 if (_offBase != null)
297 _offBase._TextStepProgreso = message;
298 _offBase._PorcenProgreso = porcen;
301 catch (Exception) { }
304 private static void Generar_Configuracion(clsOfflineUtils.ReportProgress progressReporter, DateTime tdFechaConf, DateTime tdFechaMin, DateTime tdFechaMax,
bool isCentral,
string cTipoEnvio, Dictionary<int, bool> prioridades,
string tcSucursal)
312 InicializarBarraProgreso();
313 _TextStepDetalle =
"Generando fichero InfoConfig.xml";
314 _TextStepProgreso = _TextStepDetalle;
315 _PorcenProgreso = IncrementarBarraProgreso();
318 List<int> lstPrioridades =
new List<int>();
320 InfoConfig._PrioridadesCentral.Clear();
321 InfoConfig._PrioridadesSucursal.Clear();
323 foreach (KeyValuePair<int, bool> valuePair
in prioridades)
325 lstPrioridades.Clear();
326 rnPrioridades.AddPrioridadesDependientes(valuePair.Key, ref lstPrioridades);
327 foreach (
int item
in lstPrioridades)
331 InfoConfig._PrioridadesCentral.Add(item);
335 InfoConfig._PrioridadesSucursal.Add(item);
345 InfoConfig._FechaEnvioInicial = tdFechaMin;
346 InfoConfig._FechaEnvioFinal = tdFechaMax;
349 string lcInfoConfig = _SerializeOfflineInfoConfig(InfoConfig);
350 byte[] bytes = Encoding.UTF8.GetBytes(lcInfoConfig);
352 string lcPath = Path.Combine(TempFolderName,
"InfoConfig.xml");
354 if (!File.Exists(lcPath))
356 FileStream loStream = File.Create(lcPath);
358 loStream.Write(bytes, 0, bytes.Length);
368 _TextStepDetalle =
"Generando fichero Config.xml";
369 _TextStepProgreso = _TextStepDetalle;
370 _PorcenProgreso = IncrementarBarraProgreso();
371 clsOfflineUtils.GenerarAmplitudCampos(TempFolderName);
374 TratarConfiguracion(
"SUCURSALES", tdFechaConf, DateTime.MaxValue);
375 TratarConfiguracion(
"SUCURALM", tdFechaConf, DateTime.MaxValue);
376 TratarConfiguracion(
"SUCURLET", tdFechaConf, DateTime.MaxValue);
377 TratarConfiguracion(
"SUCURART", tdFechaConf, DateTime.MaxValue);
378 TratarConfiguracion(
"SUCURCAJA", tdFechaConf, DateTime.MaxValue);
381 TratarConfiguracion(
"MULTCONF", tdFechaConf, DateTime.MaxValue);
382 TratarConfiguracion(
"SUCURCONF", tdFechaConf, DateTime.MaxValue);
383 TratarConfiguracion(
"TABNETCONF", tdFechaConf, DateTime.MaxValue);
385 if (cTipoEnvio ==
"i")
387 TratarConfiguracion(
"VARIABLES", tdFechaConf, DateTime.MaxValue,
" VARIABLE = 'ULTIMOLOG' ");
390 TratarConfiguracion(
"EJERCICIOS", tdFechaConf, DateTime.MaxValue,
" TIPOOFF = 'CENTRAL' ");
392 DataTable ldtPrioridades = obtenerDatosEnvio(prioridades, cTipoEnvio);
393 TratarConfiguracion(
"PRIORIDAD", tdFechaConf, DateTime.MaxValue, TabTmp: ldtPrioridades);
398 TratarConfiguracion(
"SUCURSALES", tdFechaMin, tdFechaMax,
" CODIGO = " + DB.SQLString(tcSucursal));
400 TratarConfiguracion(
"EJERCICIOS", tdFechaConf, DateTime.MaxValue,
" TIPOOFF = '" + tcSucursal +
"' ");
404 private static void TratarConfiguracion(
string nombreTabla, DateTime tdFechaMin, DateTime tdFechaMax,
string tcWhere =
" 1 = 1 ", DataTable TabTmp = null)
406 DataTable tablaDatos =
new DataTable();
407 string lcSql =
string.Empty;
408 string lcWhere =
string.Empty;
410 _TextStepDetalle =
"Generando fichero " + nombreTabla +
".xml";
411 _TextStepProgreso = _TextStepDetalle;
412 _PorcenProgreso = IncrementarBarraProgreso();
414 lcSql +=
"SELECT * FROM " + DB.SQLDatabase(
"OFFLINE", nombreTabla.ToUpper()) +
415 " WHERE " + tcWhere +
" AND MODIFIED >= " + DB.SQLString(tdFechaMin) +
" AND MODIFIED <= " + DB.SQLString(tdFechaMax) +
416 " AND (CREATED < " + DB.SQLString(tdFechaMin) +
" OR CREATED > " + DB.SQLString(tdFechaMax) +
" ) ";
418 lcSql +=
" UNION ALL ";
420 lcSql +=
"SELECT * FROM " + DB.SQLDatabase(
"OFFLINE", nombreTabla.ToUpper()) +
421 " WHERE " + tcWhere +
" AND CREATED >= " + DB.SQLString(tdFechaMin) +
" AND CREATED <= " + DB.SQLString(tdFechaMax);
423 DB.SQLExec(lcSql, ref tablaDatos);
425 if (tablaDatos.Rows.Count > 0)
427 switch (nombreTabla.ToUpper())
431 foreach (DataRow item
in tablaDatos.Rows)
434 DataRow[] r = TabTmp.Select(
"id = " + item[
"idtabrel"].ToString());
438 if (Convert.ToBoolean(r[0][
"prioridad"]))
440 item[
"prio_datos"] = 1;
444 item[
"prio_datos"] = 2;
456 ConvertIndividualFile(tablaDatos, TempFolderName, nombreTabla.ToUpper(), FormatoExportacion.XML);
460 private static bool GenerarDatosEnvio(
string tcSucursal,
bool tlImagenes, DateTime tdFechaConf, DateTime tdFechaMin, DateTime tdFechaMax,
bool isCentral,
int idConf,
string cTipoEnvio, Dictionary<int, bool> prioridades = null)
465 _cRaizDataBaseTemporal = ObtenerDataBaseName(tcSucursal);
467 Dictionary<string, object> tablaSucursales = DB.SQLREGValor(
"SUCURSALES",
"CODIGO", tcSucursal,
"OFFLINE");
469 string lcBdTabla =
string.Empty;
470 string lcPrincipal =
string.Empty;
471 string lcBd =
string.Empty;
472 string lcTabla =
string.Empty;
473 string lcClave =
string.Empty;
474 string lcVisicond =
string.Empty;
475 string lcCondEnv =
string.Empty;
476 string lcTitulo =
string.Empty;
478 string lcBdReal =
string.Empty;
479 string lcBdAnt =
string.Empty;
480 string lcTablaControl =
string.Empty;
481 string lcTipoDato =
string.Empty;
484 string lcSql =
string.Empty;
485 DataTable tablaDatosNuevos =
new DataTable();
486 DataTable tablaDatosModi =
new DataTable();
487 DataTable ldtImagenes =
new DataTable();
492 string lcTipoEnvio = (cTipoEnvio ==
"i" ?
"la carga inicial" :
"envío");
493 OfflineDatosComunicaciones datos = EstablecerConfiguracion(tcSucursal, tdFechaConf, tdFechaMin, tdFechaMax, isCentral, idConf, cTipoEnvio, logRepository);
498 logDto.
Detalle =
"Iniciando " + lcTipoEnvio +
" de datos para la sucursal " + tcSucursal +
".";
499 logRepository.Insert(logDto);
502 logDto.
Detalle =
"Obtener configuración de " + lcTipoEnvio +
" de datos para la sucursal " + tcSucursal +
".";
503 logRepository.Insert(logDto);
505 DataTable TabTmp = obtenerDatosEnvio(prioridades, cTipoEnvio);
507 Dictionary<string, bool> dicTablas =
new Dictionary<string, bool>();
508 foreach (DataRow row
in TabTmp.Rows)
510 if (!dicTablas.ContainsKey(row[0].ToString()))
511 dicTablas.Add(row[0].ToString(),
false);
514 VaciarUltimoLog(datos, logRepository);
517 if (!Directory.Exists(datos._PathFolderInicial))
519 Directory.CreateDirectory(datos._PathFolderInicial);
521 logDto.
Detalle =
"Se ha creado la carpeta temporal " + datos._PathFolderInicial +
".";
522 logRepository.Insert(logDto);
525 #region Crear_Tablas_temporales 528 Dictionary<string, DataTable> dicDt = CrearTablasTemporales();
531 #endregion Crear_Tablas_temporales 533 #region Gestionar Tablas 535 decimal nCociente = (TabTmp != null ? TabTmp.Rows.Count : 99.0M);
537 nCociente = (nCociente == 0 ? 100 : nCociente);
538 InicializarBarraProgreso(Convert.ToInt32(nCociente));
539 bool prioridadUsuarios =
false;
542 foreach (DataRow itemRow
in TabTmp.Rows)
545 if (!clsOfflineUtils.EvaluarCondicion(itemRow.Field<
string>(
"visicond").TrimEnd().ToLower()))
550 if (itemRow.Field<
string>(
"nombre").TrimEnd() ==
"COMUNES!HISSERIE")
555 RegistroTabRel registro = ComprobarFicheros(itemRow);
557 TratarTablasEnvio(itemRow, datos, registro, tcSucursal, tlImagenes, dicTablas, dicDt, ref ldtImagenes, logRepository);
562 if (itemRow.Field<
string>(
"nombre").TrimEnd() ==
"EUROWINSYS!UNIUSERS")
564 prioridadUsuarios = itemRow.Field<
bool>(
"prioridad");
569 foreach (DataRow itemRow
in TabTmp.Rows)
572 if (!clsOfflineUtils.EvaluarCondicion(itemRow.Field<
string>(
"visicond").TrimEnd().ToLower()))
577 if (itemRow.Field<
string>(
"nombre").TrimEnd() ==
"COMUNES!HISSERIE")
579 RegistroTabRel registro = ComprobarFicheros(itemRow);
581 TratarTablasEnvioEspecial(itemRow, datos, registro, tcSucursal, tlImagenes, dicTablas, dicDt, logRepository);
588 InicializarBarraProgreso();
590 TratamientoFinal_Fabricacion(datos);
592 GenerarRiesgoCliente(datos);
594 GenerarDeletesDeConfiguracion(datos, dicDt, prioridadUsuarios);
597 GenerarFicherosXML_Series(datos, logRepository);
600 GenerarFicherosXML(datos);
602 #endregion Gestionar Tablas 604 foreach (KeyValuePair<string, bool> entry
in dicTablas)
609 logDto.
TipoDato = clsOfflineUtils.ObtenerTipoDato(entry.Key.ToString().Trim());
610 logDto.
Detalle =
"No se ha incluido modificaciones de " + entry.Key.ToString().Trim() +
" en el fichero, no se ha detectado datos nuevos o modificados.";
611 logRepository.Insert(logDto);
615 GestionarXML_TablasTemporales(dicDt, datos, lcBd, logRepository);
617 Procesar_Imagenes_Envio(lcBdTabla, datos, ldtImagenes, logRepository);
619 llOk = Subir_Fichero_DatosEnvio(datos, cTipoEnvio ==
"e" ? (isCentral ?
"c" :
"s") : cTipoEnvio, logRepository);
621 Actualizar_Fecha_Envio_Sucursales(datos, cTipoEnvio, logRepository);
623 if (datos._TipoCom == 2)
625 Actualizar_Fecha_Envio_Multiconf(datos);
627 string lcBaseFicheroZip = _cTempFileName + (cTipoEnvio ==
"e" ? (isCentral ?
"c" :
"s") : cTipoEnvio);
631 EnvioEmailNotificacion(lcBaseFicheroZip, datos, logRepository);
634 Eliminar_Carpetas_Temporales(datos, logRepository);
637 EliminarDataBaseTemporal();
640 offlineUnitOfWork.Dispose();
645 private static Dictionary<string, DataTable> CrearTablasTemporales()
647 Dictionary<string, DataTable> dicDt =
new Dictionary<string, DataTable>();
648 DataTable dtAuxiliar =
new DataTable();
650 DB.SQLExec(
"SELECT * FROM " + DB.SQLDatabase(
"OFFLINE",
"DELETENET") +
" WHERE 1 = 2 ", ref dtAuxiliar);
651 dicDt.Add(
"DELETENET", dtAuxiliar);
653 dtAuxiliar =
new DataTable();
654 DB.SQLExec(
"SELECT * FROM " + DB.SQLDatabase(
"OFFLINE",
"ACTRIESGO") +
" WHERE 1 = 2 ", ref dtAuxiliar);
655 dicDt.Add(
"ACTRIESGO", dtAuxiliar);
660 private static void GenerarDeletesDeConfiguracion(OfflineDatosComunicaciones datos, Dictionary<string, DataTable> dicDt,
bool prioridadUsuarios)
662 DataTable dtDelete = dicDt.FirstOrDefault(x => x.Key ==
"DELETENET").Value;
664 if (datos._IsCentral)
666 DateTime ldFechaAux = datos._FechaInicial;
667 datos._FechaInicial = datos._FechaConf;
669 Gestionar_Tabla_DeleteNet(dtDelete, datos,
"OFFLINE!MULTCONF", dicDt,
new RegistroTabRel());
670 Gestionar_Tabla_DeleteNet(dtDelete, datos,
"OFFLINE!TABNETCONF", dicDt,
new RegistroTabRel());
672 if (datos._TipoCom == 1 && prioridadUsuarios)
674 Gestionar_Tabla_DeleteNet(dtDelete, datos,
"COMUNES!USUARIOS", dicDt,
new RegistroTabRel());
677 Gestionar_Tabla_DeleteNet(dtDelete, datos,
"OFFLINE!SUCURCONF", dicDt,
new RegistroTabRel());
678 Gestionar_Tabla_DeleteNet(dtDelete, datos,
"OFFLINE!SUCURLET", dicDt,
new RegistroTabRel());
679 Gestionar_Tabla_DeleteNet(dtDelete, datos,
"OFFLINE!SUCURALM", dicDt,
new RegistroTabRel());
680 Gestionar_Tabla_DeleteNet(dtDelete, datos,
"OFFLINE!SUCURCAJA", dicDt,
new RegistroTabRel());
682 Gestionar_Tabla_DeleteNet(dtDelete, datos,
"OFFLINE!SUCURART", dicDt,
new RegistroTabRel());
684 datos._FechaInicial = ldFechaAux;
688 private static OfflineDatosComunicaciones EstablecerConfiguracion(
string tcSucursal, DateTime tdFechaConf, DateTime tdFechaMin, DateTime tdFechaMax,
bool isCentral,
int idConf,
string cTipoEnvio,
ILog_comoffRepository logRepository)
690 OfflineDatosComunicaciones datos =
new OfflineDatosComunicaciones();
693 datos._Log_ComoffID = _cIdLog;
694 datos._IdConf = idConf;
695 datos._MultConf = DB.SQLValor(
"MULTCONF",
"IDCONF", idConf.ToString(),
"CODIGO",
"OFFLINE").ToString();
697 datos._BdOffline = clsOfflineUtils.ObtenerNombreBdReal(
"OFFLINE");
698 datos._Sucursal = tcSucursal;
699 datos._PathFolderInicial = TempFolderName;
700 datos._IniServidor = DB._GetVariable(
"wc_iniservidor").ToString().ToLower();
701 datos._EnvioArticulos = _offlineConfig.GetValorVariable(
EnumVariables.ENVIOARTICULOS) ==
".T.";
702 datos._FechaConf = tdFechaConf;
703 datos._FechaInicial = tdFechaMin;
704 datos._FechaFinal = tdFechaMax;
705 datos._Almacenes = _offlineConfig.ObtenerAlmacenesSucursal(tcSucursal);
706 datos._Series = _offlineConfig.ObtenerSeriesSucursal(tcSucursal);
707 datos._Cajas = _offlineConfig.ObtenerCajasSucursal(tcSucursal);
708 datos._TipoCom = (cTipoEnvio ==
"i" ? 1 : 2);
709 datos._IsCentral = isCentral;
713 datos._Delete_Mantes = _offlineConfig.GetValorVariable(
EnumVariables.DELETE_CEN_MANT) ==
".T.";
714 datos._Delete_Documentos = _offlineConfig.GetValorVariable(
EnumVariables.DELETE_CEN_DOC) ==
".T.";
718 datos._Delete_Mantes = _offlineConfig.GetValorVariable(
EnumVariables.DELETE_SUC_MANT) ==
".T.";
719 datos._Delete_Documentos = _offlineConfig.GetValorVariable(
EnumVariables.DELETE_SUC_DOC) ==
".T.";
722 datos._NotificacionEnvio = Convert.ToBoolean(DB.SQLValor(
"MULTCONF",
"IDCONF", idConf.ToString(),
"NOTIFICAEN",
"OFFLINE"));
723 datos._EmailNotificacionEnvio = Convert.ToString(DB.SQLValor(
"MULTCONF",
"IDCONF", idConf.ToString(),
"EMAILNOTEN",
"OFFLINE"));
725 datos._NotificacionRecepcion = Convert.ToBoolean(DB.SQLValor(
"MULTCONF",
"IDCONF", idConf.ToString(),
"NOTIFICARE",
"OFFLINE"));
726 datos._EmailNotificacionRecepcion = Convert.ToString(DB.SQLValor(
"MULTCONF",
"IDCONF", idConf.ToString(),
"EMAILNOTRE",
"OFFLINE"));
730 datos._UltimoLog = Convert.ToInt32(_offlineConfig.GetValorVariable(
EnumVariables.ULTIMOLOG));
734 datos._UltimoLog = 6;
739 string[] loClaveBackup = _offlineConfig.GetValorVariable(
EnumVariables.BACKUP_RECEP).Split(
'|');
740 if (loClaveBackup.Length == 3)
744 datos._Backup = (loClaveBackup[0].ToUpper() ==
".T." ? true :
false);
745 datos._BackupPath = loClaveBackup[1].TrimEnd();
746 datos._BackupNumArchivos = Convert.ToInt32(loClaveBackup[2]);
753 logDto.
Detalle =
"Error al leer la configuración de la variable " +
EnumVariables.BACKUP_RECEP.ToString();
754 logRepository.
Insert(logDto);
761 private static void GenerarRiesgoCliente(OfflineDatosComunicaciones datos)
763 if (!datos._IsCentral)
768 _TextStepDetalle =
"Generando riesgo de clientes";
769 _TextStepProgreso = _TextStepDetalle;
770 _PorcenProgreso = IncrementarBarraProgreso();
772 DataTable tablaDatos =
new DataTable();
773 string lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"GESTION",
"RIESGO");
774 lcSql +=
" WHERE 1 = 1 ";
775 lcSql +=
" AND MODIFIED >= " + DB.SQLString(datos._FechaInicial) +
" AND MODIFIED <= " + DB.SQLString(datos._FechaFinal);
776 lcSql +=
" AND (CREATED < " + DB.SQLString(datos._FechaInicial) +
" OR CREATED > " + DB.SQLString(datos._FechaFinal) +
")";
777 lcSql +=
" UNION ALL ";
778 lcSql +=
" SELECT * FROM " + DB.SQLDatabase(
"GESTION",
"RIESGO");
779 lcSql +=
" WHERE 1 = 1 ";
780 lcSql +=
" AND CREATED >= " + DB.SQLString(datos._FechaInicial) +
" AND CREATED <= " + DB.SQLString(datos._FechaFinal);
782 DB.SQLExec(lcSql, ref tablaDatos);
783 ConvertIndividualFile(tablaDatos, TempFolderName,
"RIESGO", FormatoExportacion.XML);
786 private static void TratamientoFinal_Fabricacion(OfflineDatosComunicaciones datos)
788 _TextStepDetalle =
"Ejecutando procesos adicionales";
789 _TextStepProgreso = _TextStepDetalle;
790 _PorcenProgreso = IncrementarBarraProgreso();
792 string lcSql =
string.Empty;
793 string[] Sufijos =
new string[] {
"_CREATED",
"_MODIFIED" };
794 DataTable table =
new DataTable();
796 foreach (
string sufijo
in Sufijos)
799 if (clsOfflineUtils.ExisteTablaOffline(
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_PARTES" + sufijo +
"]"))
801 bool llPartes1 = clsOfflineUtils.ExisteTablaOffline(
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_PARTES1_C_PARTES" + sufijo +
"]");
802 bool llPartes2 = clsOfflineUtils.ExisteTablaOffline(
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_PARTES2_C_PARTES" + sufijo +
"]");
803 bool llCostes = clsOfflineUtils.ExisteTablaOffline(
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_COSTES_C_PARTES" + sufijo +
"]");
805 if (llPartes1 && llPartes2 && llCostes)
807 lcSql =
" SELECT a.* INTO [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_PARTES" + sufijo +
"] " +
809 " SELECT * FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_PARTES1_C_PARTES" + sufijo +
"] " +
811 " SELECT * FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_PARTES2_C_PARTES" + sufijo +
"] " +
813 " SELECT * FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_COSTES_C_PARTES" + sufijo +
"] " +
820 lcSql =
" SELECT * INTO [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_PARTES" + sufijo +
"] " +
821 "FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_PARTES1_C_PARTES" + sufijo +
"] ";
826 lcSql =
" SELECT * INTO [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_PARTES" + sufijo +
"] " +
827 "FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_PARTES2_C_PARTES" + sufijo +
"] ";
832 lcSql =
" SELECT * INTO [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_PARTES" + sufijo +
"] " +
833 "FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_COSTES_C_PARTES" + sufijo +
"] ";
837 if (!
string.IsNullOrWhiteSpace(lcSql))
839 DB.SQLExec(
"DROP TABLE IF EXISTS [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_PARTES" + sufijo +
"]");
845 if (clsOfflineUtils.ExisteTablaOffline(
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_PARTES" + sufijo +
"]"))
847 bool llPartes1 = clsOfflineUtils.ExisteTablaOffline(
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_PARTES1_D_PARTES" + sufijo +
"]");
848 bool llPartes2 = clsOfflineUtils.ExisteTablaOffline(
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_PARTES2_D_PARTES" + sufijo +
"]");
849 bool llCostes = clsOfflineUtils.ExisteTablaOffline(
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_COSTES_D_PARTES" + sufijo +
"]");
851 if (llPartes1 && llPartes2 && llCostes)
853 lcSql =
" SELECT a.* INTO [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_PARTES" + sufijo +
"] " +
855 " SELECT * FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_PARTES1_D_PARTES" + sufijo +
"] " +
857 " SELECT * FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_PARTES2_D_PARTES" + sufijo +
"] " +
859 " SELECT * FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_COSTES_D_PARTES" + sufijo +
"] " +
866 lcSql =
" SELECT * INTO [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_PARTES" + sufijo +
"] " +
867 "FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_PARTES1_D_PARTES" + sufijo +
"] ";
872 lcSql =
" SELECT * INTO [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_PARTES" + sufijo +
"] " +
873 "FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_PARTES2_D_PARTES" + sufijo +
"] ";
878 lcSql =
" SELECT * INTO [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_PARTES" + sufijo +
"] " +
879 "FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_COSTES_D_PARTES" + sufijo +
"] ";
883 if (!
string.IsNullOrWhiteSpace(lcSql))
885 DB.SQLExec(
"DROP TABLE IF EXISTS [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_PARTES" + sufijo +
"]");
890 DB.SQLExec(
"DROP TABLE IF EXISTS [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_PARTES1_C_PARTES" + sufijo +
"]");
891 DB.SQLExec(
"DROP TABLE IF EXISTS [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_PARTES2_C_PARTES" + sufijo +
"]");
892 DB.SQLExec(
"DROP TABLE IF EXISTS [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_COSTES_C_PARTES" + sufijo +
"]");
893 DB.SQLExec(
"DROP TABLE IF EXISTS [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_PARTES1_D_PARTES" + sufijo +
"]");
894 DB.SQLExec(
"DROP TABLE IF EXISTS [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_PARTES2_D_PARTES" + sufijo +
"]");
895 DB.SQLExec(
"DROP TABLE IF EXISTS [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"_COSTES_D_PARTES" + sufijo +
"]");
899 private static void GenerarFicherosXML(OfflineDatosComunicaciones datos)
901 GenerarFicherosDatabaseXML(_cRaizDataBaseTemporal +
"COMUNES", datos);
902 GenerarFicherosDatabaseXML(_cRaizDataBaseTemporal +
"GESTION", datos);
905 foreach (KeyValuePair<string, DB._ModuloSchema> entry
in DB._dicCacheModulos)
907 GenerarFicherosDatabaseXML(_cRaizDataBaseTemporal + entry.Value._Nombre, datos);
910 GenerarFicherosDatabaseXML(_cRaizDataBaseTemporal +
"EUROWINSYS", datos);
913 private static void GenerarFicherosDatabaseXML(
string tcDatabase, OfflineDatosComunicaciones datos)
915 string lcSql =
string.Empty;
916 DataTable ldtDatos =
new DataTable();
918 if (clsOfflineUtils.ExisteDatabaseOffline(tcDatabase))
920 int lnPos = tcDatabase.LastIndexOf(
"_");
921 string lcNombre = tcDatabase.Substring(lnPos + 1);
922 string lcGetDate =
" GETDATE() ";
924 _TextStepDetalle =
"Generando ficheros XML de la base de datos " + lcNombre.ToUpper();
925 _TextStepProgreso = _TextStepDetalle;
926 _PorcenProgreso = IncrementarBarraProgreso();
928 DataTable table = clsOfflineUtils.ListaTablasDatabaseOffline(tcDatabase);
930 foreach (DataRow item
in table.Rows)
932 string lcCadenaCamps = ObtenerCamposSelect(lcNombre, item[
"table_name"].ToString().Trim());
934 lcSql =
"SELECT DISTINCT " + lcCadenaCamps +
", " + lcGetDate +
" as created, " + lcGetDate +
" as modified FROM [" + tcDatabase +
"].dbo.[" + item[
"table_name"].ToString().Trim() +
"] ";
935 DB.SQLExec(lcSql, ref ldtDatos);
937 ConvertIndividualFile(ldtDatos, Path.Combine(datos._PathFolderInicial, lcNombre), item[
"table_name"].ToString().Trim(), FormatoExportacion.XML);
943 private static string ObtenerCamposSelect(
string tcDBLocal,
string tcTablaLocal)
948 string lcSelect =
string.Empty;
949 string lcComa =
string.Empty;
950 DataTable ldtCampos =
new DataTable();
952 DB.SQLExec(
"SELECT column_name, data_type FROM " + _cRaizDataBaseTemporal + tcDBLocal +
".INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + tcTablaLocal +
"' ", ref ldtCampos);
955 foreach (DataRow item
in ldtCampos.Rows)
957 switch (item[
"column_name"].ToString().ToLower())
971 switch (item[
"data_type"].ToString().ToLower())
976 lcSelect += lcComa +
"CONVERT(VARCHAR(MAX), [" + item[
"column_name"].ToString().ToLower() +
"]) as [" + item[
"column_name"].ToString().ToLower() +
"] ";
981 lcSelect += lcComa +
"[" + item[
"column_name"].ToString().ToLower() +
"]";
995 private static void TratarTablasEnvio(DataRow item, OfflineDatosComunicaciones datos, RegistroTabRel registro,
string tcSucursal,
bool tlImagenes, Dictionary<string, bool> dicTablas, Dictionary<string, DataTable> dicDt, ref DataTable ldtImagenes,
ILog_comoffRepository logRepository)
997 string lcTipoDato = clsOfflineUtils.ObtenerTipoDato(registro._Clave);
999 string lcCampoEmpresa = item.Field<
string>(
"empresa").TrimEnd();
1000 string lcCampoEmpreSecun = item.Field<
string>(
"empresecun").TrimEnd();
1003 string lcBdReal = clsOfflineUtils.ObtenerNombreBdReal(registro._DBSecundaria);
1006 if (
string.IsNullOrEmpty(lcBdReal))
1011 logDto.
Detalle =
"No existe la base de datos " + registro._DBSecundaria +
".";
1012 logRepository.
Insert(logDto);
1016 _TextStepDetalle =
"Revisando datos tabla " + registro._DBSecundaria +
"!" + registro._TablaSecundaria;
1017 _TextStepProgreso = _TextStepDetalle;
1018 _PorcenProgreso = IncrementarBarraProgreso();
1020 string lcSql =
string.Empty;
1021 string lcFiltrePrincipal =
string.Empty;
1022 string lcFilterCondCtrl =
string.Empty;
1023 string lcFilterCondCtrl_2 =
string.Empty;
1024 string lcAny = EW_GLOBAL._GetVariable(
"wc_any").ToString();
1026 if (!
string.IsNullOrWhiteSpace(registro._CondCtrl))
1028 string lcOn =
string.Empty;
1030 lcOn = ObtenerInnerOn(registro._DBPrincipal, registro._DBCondCtrl, registro._TablaPrincipal, registro._TablaCondCtrl, registro._RelaCtrl, registro._Clave, datos, logRepository,
true);
1031 lcOn = lcOn +
" AND c.EJERCICIO = " + DB.SQLString(lcAny);
1033 lcFilterCondCtrl =
" INNER JOIN [" + clsOfflineUtils.ObtenerNombreBdReal(registro._DBCondCtrl) +
"].dbo." + registro._TablaCondCtrl +
" c " +
" ON " + lcOn;
1035 lcFilterCondCtrl = lcFilterCondCtrl.Replace(
"b.",
"c.");
1036 lcFilterCondCtrl = lcFilterCondCtrl.Replace(
"B.",
"C.");
1038 lcFilterCondCtrl_2 = _offlineConfig.ConstruirFiltroCaja(registro._CondCtrl, tcSucursal, datos._Cajas);
1039 lcFilterCondCtrl_2 = lcFilterCondCtrl_2.Replace(
"{TABLA}",
"c.");
1041 lcFilterCondCtrl = lcFilterCondCtrl +
" AND " + lcFilterCondCtrl_2;
1044 lcSql =
" FROM [" + lcBdReal +
"].dbo." + registro._TablaSecundaria +
" b " +
1045 " INNER JOIN [" + clsOfflineUtils.ObtenerNombreBdReal(registro._DBPrincipal) +
"].dbo." + registro._TablaPrincipal +
" a " +
1046 " ON " + ObtenerInnerOn(registro._DBPrincipal, registro._DBSecundaria, registro._TablaPrincipal, registro._TablaSecundaria, registro._Relacion, registro._Clave, datos, logRepository) +
1051 if (datos._EnvioArticulos && ((registro._DBPrincipal +
"!" + registro._TablaPrincipal) ==
"GESTION!ARTICULO" || registro._Clave ==
"STOCKINI" || registro._Clave ==
"STOCKS"))
1053 lcSql += Envio_Articulos_Sucursal(datos, registro._TablaSecundaria);
1056 if (datos._IsCentral && registro._DBPrincipal +
"!" + registro._TablaPrincipal ==
"COMUNES!LETRAS")
1058 lcSql += Envio_Series_Sucursal(datos);
1061 if (datos._IsCentral && registro._DBPrincipal +
"!" + registro._TablaPrincipal ==
"TPV!CAJAS")
1063 lcSql += Envio_Cajas_Sucursal(datos);
1066 if (registro._DBPrincipal != registro._DBSecundaria || registro._TablaPrincipal != registro._TablaSecundaria)
1069 if (!
string.IsNullOrEmpty(registro._CondSecun))
1071 lcFiltrePrincipal = registro._CondSecun;
1072 lcFiltrePrincipal = lcFiltrePrincipal.Replace(
"{TABLA}",
"b.");
1074 lcSql = lcSql +
" AND " + lcFiltrePrincipal;
1078 if (!
string.IsNullOrWhiteSpace(registro._CondEnv))
1080 lcFiltrePrincipal = registro._CondEnv;
1081 lcFiltrePrincipal = _offlineConfig.ConstruirFiltroAlmacen(lcFiltrePrincipal, tcSucursal, datos._Almacenes, registro._TablaSecundaria);
1082 lcFiltrePrincipal = _offlineConfig.ConstruirFiltroLetra(lcFiltrePrincipal, tcSucursal, datos._Series);
1083 lcFiltrePrincipal = _offlineConfig.ConstruirFiltroCaja(lcFiltrePrincipal, tcSucursal, datos._Cajas);
1085 lcFiltrePrincipal = lcFiltrePrincipal.Replace(
"{TABLA}",
"a.");
1087 lcSql = lcSql +
" AND " + lcFiltrePrincipal;
1091 clsOfflineUtils.RevisarTablasCampoEmpresa(registro._TablaPrincipal, ref lcCampoEmpresa);
1092 if (!
string.IsNullOrWhiteSpace(lcCampoEmpresa))
1094 lcSql = lcSql +
" AND a." + lcCampoEmpresa +
" NOT IN (SELECT empresa FROM [" + datos._BdOffline +
"].dbo.empexclu) ";
1097 clsOfflineUtils.RevisarTablasCampoEmpresa(registro._TablaSecundaria, ref lcCampoEmpreSecun);
1098 if (!
string.IsNullOrWhiteSpace(lcCampoEmpreSecun))
1100 lcSql = lcSql +
" AND b." + lcCampoEmpreSecun +
" NOT IN (SELECT empresa FROM [" + datos._BdOffline +
"].dbo.empexclu) ";
1103 ActualizarDatosEnvio(item, datos, registro, tcSucursal, tlImagenes, dicTablas, dicDt, ref ldtImagenes, lcSql, logRepository);
1106 DataTable dtDelete = dicDt.FirstOrDefault(x => x.Key ==
"DELETENET").Value;
1108 if (datos._IsCentral ? Convert.ToBoolean(registro._Prioridad) : !Convert.ToBoolean(registro._Prioridad))
1110 if (datos._TipoCom == 2 || (datos._TipoCom == 1 && (registro._IdGrupo == 3 || registro._IdGrupo == 4)))
1112 Gestionar_Tabla_DeleteNet(dtDelete, datos, registro._Nombre, dicDt, registro);
1118 private static void TratarTablasEnvioEspecial(DataRow item, OfflineDatosComunicaciones datos, RegistroTabRel registro,
string tcSucursal,
bool tlImagenes, Dictionary<string, bool> dicTablas, Dictionary<string, DataTable> dicDt,
ILog_comoffRepository logRepository)
1120 string lcTipoDato = clsOfflineUtils.ObtenerTipoDato(registro._Clave);
1122 string lcCampoEmpresa = item.Field<
string>(
"empresa").TrimEnd();
1123 string lcCampoEmpreSecun = item.Field<
string>(
"empresecun").TrimEnd();
1126 string lcBdReal = clsOfflineUtils.ObtenerNombreBdReal(registro._DBSecundaria);
1129 if (
string.IsNullOrEmpty(lcBdReal))
1134 logDto.
Detalle =
"No existe la base de datos " + registro._DBSecundaria +
".";
1135 logRepository.
Insert(logDto);
1139 if (_TextStepDetalle !=
"Revisando datos tabla " + registro._DBSecundaria +
"!" + registro._TablaSecundaria)
1141 _TextStepDetalle =
"Revisando datos tabla " + registro._DBSecundaria +
"!" + registro._TablaSecundaria;
1144 if (clsOfflineUtils.ExisteTablaOffline(
"[" + _cRaizDataBaseTemporal + registro._DBPrincipal +
"].dbo.[" + registro._TablaPrincipal + registro._Sufijo +
"]"))
1146 string lcSql =
string.Empty;
1147 string lcFiltrePrincipal =
string.Empty;
1149 lcSql =
" FROM [" + lcBdReal +
"].dbo." + registro._TablaSecundaria +
" b " +
1150 " INNER JOIN [" + _cRaizDataBaseTemporal + registro._DBPrincipal +
"].dbo." + registro._TablaPrincipal + registro._Sufijo +
" a " +
1151 " ON " + ObtenerInnerOn(registro._DBPrincipal, registro._DBSecundaria, registro._TablaPrincipal, registro._TablaSecundaria, registro._Relacion, registro._Clave, datos, logRepository) +
1155 if (datos._EnvioArticulos && ((registro._DBPrincipal +
"!" + registro._TablaPrincipal) ==
"GESTION!ARTICULO" || registro._Clave ==
"STOCKINI" || registro._Clave ==
"STOCKS"))
1157 lcSql += Envio_Articulos_Sucursal(datos, registro._TablaSecundaria);
1160 if (datos._IsCentral && registro._DBPrincipal +
"!" + registro._TablaPrincipal ==
"COMUNES!LETRAS")
1162 lcSql += Envio_Series_Sucursal(datos);
1165 if (datos._IsCentral && registro._DBPrincipal +
"!" + registro._TablaPrincipal ==
"TPV!CAJAS")
1167 lcSql += Envio_Cajas_Sucursal(datos);
1170 if (registro._DBPrincipal != registro._DBSecundaria || registro._TablaPrincipal != registro._TablaSecundaria)
1173 if (!
string.IsNullOrEmpty(registro._CondSecun))
1175 lcFiltrePrincipal = registro._CondSecun;
1176 lcFiltrePrincipal = lcFiltrePrincipal.Replace(
"{TABLA}",
"b.");
1178 lcSql = lcSql +
" AND " + lcFiltrePrincipal;
1182 if (!
string.IsNullOrWhiteSpace(registro._CondEnv))
1184 lcFiltrePrincipal = registro._CondEnv;
1185 lcFiltrePrincipal = _offlineConfig.ConstruirFiltroAlmacen(lcFiltrePrincipal, tcSucursal, datos._Almacenes, registro._TablaSecundaria);
1186 lcFiltrePrincipal = _offlineConfig.ConstruirFiltroLetra(lcFiltrePrincipal, tcSucursal, datos._Series);
1187 lcFiltrePrincipal = _offlineConfig.ConstruirFiltroCaja(lcFiltrePrincipal, tcSucursal, datos._Cajas);
1189 lcFiltrePrincipal = lcFiltrePrincipal.Replace(
"{TABLA}",
"a.");
1191 lcSql = lcSql +
" AND " + lcFiltrePrincipal;
1195 clsOfflineUtils.RevisarTablasCampoEmpresa(registro._TablaPrincipal, ref lcCampoEmpresa);
1196 if (!
string.IsNullOrWhiteSpace(lcCampoEmpresa))
1198 lcSql = lcSql +
" AND a." + lcCampoEmpresa +
" NOT IN (SELECT empresa FROM [" + datos._BdOffline +
"].dbo.empexclu) ";
1201 clsOfflineUtils.RevisarTablasCampoEmpresa(registro._TablaSecundaria, ref lcCampoEmpreSecun);
1202 if (!
string.IsNullOrWhiteSpace(lcCampoEmpreSecun))
1204 lcSql = lcSql +
" AND b." + lcCampoEmpreSecun +
" NOT IN (SELECT empresa FROM [" + datos._BdOffline +
"].dbo.empexclu) ";
1207 DataTable ldtImagenes =
new DataTable();
1208 ActualizarDatosEnvio(item, datos, registro, tcSucursal, tlImagenes, dicTablas, dicDt, ref ldtImagenes, lcSql, logRepository);
1212 DataTable dtDelete = dicDt.FirstOrDefault(x => x.Key ==
"DELETENET").Value;
1214 if (datos._IsCentral ? Convert.ToBoolean(registro._Prioridad) : !Convert.ToBoolean(registro._Prioridad))
1216 if (datos._TipoCom == 2 || (datos._TipoCom == 1 && (registro._IdGrupo == 3 || registro._IdGrupo == 4)))
1218 Gestionar_Tabla_DeleteNet(dtDelete, datos, registro._Nombre, dicDt, registro);
1224 private static RegistroTabRel ComprobarFicheros(DataRow item)
1226 RegistroTabRel registro =
new RegistroTabRel();
1228 registro._DBPrincipal =
string.Empty;
1229 registro._TablaPrincipal =
string.Empty;
1231 registro._DBSecundaria =
string.Empty;
1232 registro._TablaSecundaria =
string.Empty;
1234 registro._Empresa = item.Field<
string>(
"empresa").TrimEnd();
1237 registro._ID = item.Field<
int>(
"id");
1238 registro._IdGrupo = item.Field<
int>(
"idgrupo");
1239 registro._Clave = item.Field<
string>(
"clave").TrimEnd();
1240 registro._Nombre = item.Field<
string>(
"nombre").TrimEnd();
1241 registro._Prioridad = Convert.ToInt32(item.Field<
bool>(
"prioridad"));
1242 registro._Titulo = item.Field<
string>(
"titulo").TrimEnd().ToUpper();
1244 registro._CondEnv = item.Field<
string>(
"condenv").TrimEnd().ToUpper();
1245 registro._CondSecun = item.Field<
string>(
"condsecun").TrimEnd().ToUpper();
1246 registro._CondCtrl = item.Field<
string>(
"condctrl").TrimEnd().ToUpper();
1247 registro._NombreTablaCtrl = item.Field<
string>(
"tablactrl").TrimEnd().ToUpper();
1249 if (!
string.IsNullOrWhiteSpace(item.Field<
string>(
"principal")))
1251 string[] subPos = item.Field<
string>(
"principal").TrimEnd().Split(
'!');
1252 if (subPos.Length == 2)
1254 registro._DBPrincipal = subPos[0].TrimEnd();
1255 registro._TablaPrincipal = subPos[1].TrimEnd();
1260 if (!
string.IsNullOrWhiteSpace(item.Field<
string>(
"nombre")))
1262 string[] subPos = item.Field<
string>(
"nombre").TrimEnd().Split(
'!');
1263 if (subPos.Length == 2)
1265 registro._DBSecundaria = subPos[0].TrimEnd();
1266 registro._TablaSecundaria = subPos[1].TrimEnd();
1270 if (!
string.IsNullOrWhiteSpace(item.Field<
string>(
"tablactrl")))
1272 string[] subPos = item.Field<
string>(
"tablactrl").TrimEnd().Split(
'!');
1273 if (subPos.Length == 2)
1275 registro._DBCondCtrl = subPos[0].TrimEnd();
1276 registro._TablaCondCtrl = subPos[1].TrimEnd();
1280 registro._Sufijo =
"_CREATED";
1281 registro._TipoTabla = item.Field<
int>(
"tipotabla");
1283 registro._Asientos = item.Field<
string>(
"asientos").TrimEnd();
1284 registro._Otrasien = item.Field<
string>(
"otrasien").TrimEnd();
1285 registro._Eos = item.Field<
string>(
"eos").TrimEnd();
1286 registro._Iva_exen = item.Field<
string>(
"iva_exen").TrimEnd();
1287 registro._Ivasopor = item.Field<
string>(
"ivasopor").TrimEnd();
1288 registro._Ivareper = item.Field<
string>(
"ivareper").TrimEnd();
1289 registro._Retsopor = item.Field<
string>(
"retsopor").TrimEnd();
1290 registro._Retreper = item.Field<
string>(
"retreper").TrimEnd();
1291 registro._Compras = item.Field<
string>(
"compras").TrimEnd();
1292 registro._Relacion = item.Field<
string>(
"relacion").TrimEnd();
1293 registro._RelaCtrl = item.Field<
string>(
"relactrl").TrimEnd();
1298 private static void ActualizarDatosEnvio(DataRow item, OfflineDatosComunicaciones datos, RegistroTabRel registro,
string tcSucursal,
bool tlImagenes, Dictionary<string, bool> dicTablas, Dictionary<string, DataTable> dicDt, ref DataTable ldtImagenes,
string lcSql,
ILog_comoffRepository logRepository)
1300 bool llPrioridad = (datos._IsCentral && Convert.ToBoolean(registro._Prioridad) || !datos._IsCentral && !Convert.ToBoolean(registro._Prioridad));
1302 if (llPrioridad || (registro._Clave ==
"FACTURAS" || registro._Clave ==
"FACTURAC" || registro._TablaSecundaria ==
"ENTREGAS"))
1304 registro._Sufijo =
"_MODIFIED";
1306 ProcesoActualizarDatos(item, datos, registro, tcSucursal, tlImagenes, dicTablas, dicDt, ref ldtImagenes, lcSql, logRepository);
1309 registro._Sufijo =
"_CREATED";
1311 ProcesoActualizarDatos(item, datos, registro, tcSucursal, tlImagenes, dicTablas, dicDt, ref ldtImagenes, lcSql, logRepository);
1314 private static void ProcesoActualizarDatos(DataRow item, OfflineDatosComunicaciones datos, RegistroTabRel registro,
string tcSucursal,
bool tlImagenes, Dictionary<string, bool> dicTablas, Dictionary<string, DataTable> dicDt, ref DataTable ldtImagenes,
string tcSql,
ILog_comoffRepository logRepository)
1316 string lcSqlCondicion =
string.Empty;
1317 DataTable dtDatos =
new DataTable();
1319 Dictionary<string, object> tablaSucursales = DB.SQLREGValor(
"SUCURSALES",
"CODIGO", tcSucursal,
"OFFLINE");
1321 string lcBdReal = clsOfflineUtils.ObtenerNombreBdReal(registro._DBSecundaria);
1322 string lcTipoDato = clsOfflineUtils.ObtenerTipoDato(registro._Clave);
1323 string lcAlias = ProcesoActualizarDatos_Alias(datos, registro);
1325 if (registro._Sufijo ==
"_MODIFIED")
1327 string lcSufijo =
string.Empty;
1328 string[] subPos = registro._Sufijo.Split(
'_');
1330 if (subPos.Length == 2)
1332 lcSufijo = subPos[1].TrimEnd();
1335 lcSqlCondicion =
" AND " + lcAlias + lcSufijo +
" >= " + DB.SQLString(datos._FechaInicial) +
" AND " + lcAlias + lcSufijo +
" <= " + DB.SQLString(datos._FechaFinal);
1336 lcSqlCondicion +=
" AND (" + lcAlias +
"CREATED < " + DB.SQLString(datos._FechaInicial) +
" OR " + lcAlias +
"CREATED > " + DB.SQLString(datos._FechaFinal) +
")";
1340 lcSqlCondicion =
" AND " + lcAlias +
"CREATED >= " + DB.SQLString(datos._FechaInicial) +
" AND " + lcAlias +
"CREATED <= " + DB.SQLString(datos._FechaFinal);
1343 string lcSql =
" SELECT b.* " + tcSql + lcSqlCondicion;
1345 if (!DB.SQLExec(lcSql, ref dtDatos))
1350 logDto.
Detalle =
"No se ha podido ejecutar la instrucción " + lcSql +
".";
1351 logRepository.
Insert(logDto);
1355 if (dtDatos.Rows.Count > 0)
1357 RegistroDatos(datos, item, lcBdReal, registro._DBSecundaria, registro._TablaSecundaria, dtDatos, registro._Sufijo, logRepository);
1358 dicTablas[item[0].ToString()] =
true;
1360 if (clsOfflineUtils.ExisteTablaOffline(
"[" + _cRaizDataBaseTemporal + registro._DBSecundaria +
"].dbo.[" + registro._TablaSecundaria + registro._Sufijo +
"]"))
1362 InsertarDatosBulkMode(dtDatos,
"[" + _cRaizDataBaseTemporal + registro._DBSecundaria +
"].dbo.[" + registro._TablaSecundaria + registro._Sufijo +
"]");
1366 if (!clsOfflineUtils.ExisteDatabaseOffline(_cRaizDataBaseTemporal + registro._DBSecundaria))
1368 CrearDataTable(registro._DBSecundaria, _cRaizDataBaseTemporal);
1371 lcSql =
" SELECT b.* INTO [" + _cRaizDataBaseTemporal + registro._DBSecundaria +
"].dbo.[" + registro._TablaSecundaria + registro._Sufijo +
"]" +
1372 tcSql + lcSqlCondicion;
1376 ProcesoActualizarDatosEspecial(registro, datos, dicDt);
1379 if (Revisar_Imagenes_Datos(tlImagenes, tablaSucursales, registro._TablaSecundaria, datos, ref dtDatos))
1382 Actualizar_Ultima_Fecha_Envio(registro._ID);
1385 if (registro._Sufijo ==
"_CREATED")
1387 Gestionar_Tabla_Control(dtDatos, datos, registro, Convert.ToBoolean(registro._Prioridad), registro._ID, lcTipoDato, item, dicTablas, logRepository);
1391 Seleccionar_Imagenes_Envio(tlImagenes, tablaSucursales, registro._TablaSecundaria, datos, ref ldtImagenes);
1396 private static string ProcesoActualizarDatos_Alias(OfflineDatosComunicaciones datos, RegistroTabRel registro)
1398 string lcAlias =
"a.";
1400 if (datos._IsCentral && Convert.ToBoolean(registro._Prioridad) || !datos._IsCentral && !Convert.ToBoolean(registro._Prioridad))
1407 if (registro._TablaPrincipal ==
"C_ALBVEN" && registro._TablaSecundaria ==
"ENTRE_CL" && !registro._Sobreescribir)
1413 if (registro._TablaPrincipal ==
"C_PEDIVE" && registro._TablaSecundaria ==
"ENTRE_PV" && !registro._Sobreescribir)
1419 if (registro._TablaPrincipal ==
"C_PRESUV" && registro._TablaSecundaria ==
"ENTRE_PR" && !registro._Sobreescribir)
1428 private static void TratamientoEspecial_RiesgoCliente(RegistroTabRel registro, OfflineDatosComunicaciones datos, Dictionary<string, DataTable> dicDt)
1430 DataTable tablaDatos =
new DataTable();
1431 string lcSql =
string.Empty;
1433 DataTable dtActRiesgo = dicDt.FirstOrDefault(x => x.Key ==
"ACTRIESGO").Value;
1435 switch (registro._Clave)
1439 if (registro._TablaPrincipal ==
"C_PEDIVE")
1441 lcSql =
" SELECT DISTINCT EMPRESA, CLIENTE AS CODIGO FROM [" + _cRaizDataBaseTemporal + registro._DBPrincipal +
"].[dbo].[" + registro._TablaPrincipal + registro._Sufijo +
"]";
1442 DB.SQLExec(lcSql, ref tablaDatos);
1449 case "TPVCONARQUEO":
1450 case "TPVSINARQUEO":
1452 if (registro._TablaPrincipal ==
"C_ALBVEN")
1454 lcSql =
" SELECT DISTINCT EMPRESA, CLIENTE AS CODIGO FROM [" + _cRaizDataBaseTemporal + registro._DBPrincipal +
"].[dbo].[" + registro._TablaPrincipal + registro._Sufijo +
"]";
1455 DB.SQLExec(lcSql, ref tablaDatos);
1462 if (registro._TablaPrincipal ==
"CLIENTES")
1464 lcSql =
" SELECT DISTINCT B.EMPRESA, A.CODIGO " +
1465 " FROM [" + _cRaizDataBaseTemporal + registro._DBPrincipal +
"].[dbo].[" + registro._TablaPrincipal + registro._Sufijo +
"] A " +
1466 " INNER JOIN " + DB.SQLDatabase(
"OFFLINE",
"ACTRIESGO") +
" B ON A.CODIGO = B.CODIGO " +
1467 " WHERE B.EMPRESA NOT IN (SELECT EMPRESA FROM " + DB.SQLDatabase(
"OFFLINE",
"EMPEXCLU") +
")";
1469 DB.SQLExec(lcSql, ref tablaDatos);
1480 if (tablaDatos != null && tablaDatos.Rows.Count > 0)
1482 foreach (DataRow item
in tablaDatos.Rows)
1484 var dataRow = dtActRiesgo.AsEnumerable().Where(dr => dr.Field<
string>(
"empresa") == item.Field<
string>(
"empresa") &&
1485 dr.Field<
string>(
"codigo") == item.Field<
string>(
"codigo"));
1488 DataRow newRow = dtActRiesgo.NewRow();
1490 newRow[
"empresa"] = item[
"empresa"];
1491 newRow[
"codigo"] = item[
"codigo"];
1493 dtActRiesgo.Rows.Add(newRow);
1497 dicDt.Remove(
"ACTRIESGO");
1498 dicDt.Add(
"ACTRIESGO", dtActRiesgo);
1502 private static void ProcesoActualizarDatosEspecial(RegistroTabRel registro, OfflineDatosComunicaciones datos, Dictionary<string, DataTable> dicDt)
1504 string lcSql =
string.Empty;
1507 if (!
string.IsNullOrWhiteSpace(registro._Asientos))
1509 TratamientoEspecial_ASI(registro,
"ASIENTOS", registro._Asientos);
1510 TratamientoEspecial_Asientos(registro, datos,
true);
1514 if (!
string.IsNullOrWhiteSpace(registro._Compras))
1516 TratamientoEspecial_Compras(registro, datos);
1519 if (!datos._IsCentral)
1521 TratamientoEspecial_RiesgoCliente(registro, datos, dicDt);
1525 switch (registro._TablaSecundaria)
1529 TratamientoEspecial_Asientos(registro, datos);
1536 TratamientoEspecial_Previsiones(registro, datos);
1543 DataTable ldtDatosEOS =
new DataTable();
1545 lcSql =
" SELECT A.* " +
1546 " FROM " + DB.SQLDatabase(
"GESTION",
"EOS") +
" A " +
1547 " INNER JOIN [" + _cRaizDataBaseTemporal + registro._DBSecundaria +
"].dbo.[" + registro._TablaSecundaria + registro._Sufijo +
"] B ON A.EMPRESA = B.EMPRESA AND A.ASIIVA = B.ASI ";
1549 if (registro._TablaSecundaria ==
"IVAREPER")
1551 lcSql = lcSql +
" AND A.TIPO = 1 ";
1555 lcSql = lcSql +
" AND A.TIPO = 0 ";
1558 DB.SQLExec(lcSql, ref ldtDatosEOS);
1560 if (ldtDatosEOS != null && ldtDatosEOS.Rows.Count > 0)
1562 ComprobarTablaTemporalSQL(registro,
"GESTION",
"EOS");
1564 InsertarDatosBulkMode(ldtDatosEOS,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"EOS" + registro._Sufijo +
"]");
1572 TratamientoEspecial_CriterioCaja(registro, datos);
1579 TratamientoEspecial_EnvioFabricacion(registro, datos);
1587 TratamientoEspecial_PedidosVenta(registro, datos);
1592 TratamientoEspecial_PedidosCompra(registro, datos);
1597 TratamientoEspecial_DepositosVenta(registro, datos);
1602 TratamientoEspecial_DepositosCompra(registro, datos);
1607 TratamientoEspecial_AlbaranesVenta(registro, datos);
1612 TratamientoEspecial_AlbaranesCompra(registro, datos);
1617 TratamientoEspecial_FacturasVenta(registro, datos);
1622 TratamientoEspecial_FacturasCompra(registro, datos);
1627 TratamientoEspecial_AccesoGrup(registro, datos);
1636 private static void TratamientoEspecial_AccesoGrup(RegistroTabRel registro, OfflineDatosComunicaciones datos)
1638 string lcSql =
string.Empty;
1641 lcSql =
" Delete From [" + _cRaizDataBaseTemporal + registro._DBSecundaria +
"].dbo." + registro._TablaSecundaria + registro._Sufijo +
" " +
1642 " Where grupo != " + DB.SQLString(lcGrupo);
1648 private static void TratamientoEspecial_PedidosVenta(RegistroTabRel registro, OfflineDatosComunicaciones datos)
1652 if (!registro._Sobreescribir && registro._DBPrincipal ==
"GESTION")
1654 DataTable ldtDatosRelacionados =
new DataTable();
1655 string lcSql =
string.Empty;
1658 lcSql =
" SELECT DISTINCT empresa, doc_num, doc_lin " +
1659 " FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].[dbo].[D_PEDIVE" + registro._Sufijo +
"]" +
1661 DB.SQLExec(lcSql, ref ldtDatosRelacionados);
1663 foreach (DataRow item
in ldtDatosRelacionados.Rows)
1665 DataTable ldtDatos =
new DataTable();
1666 lcSql =
" SELECT * " +
1667 " FROM " + DB.SQLDatabase(
"GESTION",
"C_PRESUV") +
1668 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
1669 " AND NUMERO + LETRA = " + DB.SQLString(item.Field<
string>(
"doc_num"));
1670 DB.SQLExec(lcSql, ref ldtDatos);
1672 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
1674 ComprobarTablaTemporalSQL(registro,
"GESTION",
"C_PRESUV",
"_ESPECIAL");
1676 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_PRESUV" +
"_ESPECIAL" +
"]");
1679 lcSql =
" SELECT * " +
1680 " FROM " + DB.SQLDatabase(
"GESTION",
"D_PRESUV") +
1681 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
1682 " AND NUMERO + LETRA = " + DB.SQLString(item.Field<
string>(
"doc_num")) +
1683 " AND LINIA = " + DB.SQLString(item.Field<
int>(
"doc_lin"));
1685 DB.SQLExec(lcSql, ref ldtDatos);
1687 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
1689 ComprobarTablaTemporalSQL(registro,
"GESTION",
"D_PRESUV",
"_ESPECIAL");
1691 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_PRESUV" +
"_ESPECIAL" +
"]");
1697 private static void TratamientoEspecial_PedidosCompra(RegistroTabRel registro, OfflineDatosComunicaciones datos)
1701 if (!registro._Sobreescribir && registro._DBPrincipal ==
"GESTION")
1707 private static void TratamientoEspecial_DepositosVenta(RegistroTabRel registro, OfflineDatosComunicaciones datos)
1711 if (!registro._Sobreescribir && registro._DBPrincipal ==
"GESTION")
1713 DataTable ldtDatosRelacionados =
new DataTable();
1714 string lcSql =
string.Empty;
1717 lcSql =
" SELECT DISTINCT empresa, doc_num, doc_lin " +
1718 " FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].[dbo].[D_ALBDEP" + registro._Sufijo +
"]" +
1720 DB.SQLExec(lcSql, ref ldtDatosRelacionados);
1722 foreach (DataRow item
in ldtDatosRelacionados.Rows)
1724 DataTable ldtDatos =
new DataTable();
1725 lcSql =
" SELECT * " +
1726 " FROM " + DB.SQLDatabase(
"GESTION",
"C_PEDIVE") +
1727 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
1728 " AND NUMERO + LETRA = " + DB.SQLString(item.Field<
string>(
"doc_num"));
1729 DB.SQLExec(lcSql, ref ldtDatos);
1731 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
1733 ComprobarTablaTemporalSQL(registro,
"GESTION",
"C_PEDIVE",
"_ESPECIAL");
1735 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_PEDIVE" +
"_ESPECIAL" +
"]");
1738 lcSql =
" SELECT * " +
1739 " FROM " + DB.SQLDatabase(
"GESTION",
"D_PEDIVE") +
1740 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
1741 " AND NUMERO + LETRA = " + DB.SQLString(item.Field<
string>(
"doc_num")) +
1742 " AND LINIA = " + DB.SQLString(item.Field<
int>(
"doc_lin"));
1744 DB.SQLExec(lcSql, ref ldtDatos);
1746 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
1748 ComprobarTablaTemporalSQL(registro,
"GESTION",
"D_PEDIVE",
"_ESPECIAL");
1750 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_PEDIVE" +
"_ESPECIAL" +
"]");
1755 lcSql =
" SELECT DISTINCT empresa, doc_num, doc_lin " +
1756 " FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].[dbo].[D_ALBDEP" + registro._Sufijo +
"]" +
1758 DB.SQLExec(lcSql, ref ldtDatosRelacionados);
1760 foreach (DataRow item
in ldtDatosRelacionados.Rows)
1762 DataTable ldtDatos =
new DataTable();
1763 lcSql =
" SELECT * " +
1764 " FROM " + DB.SQLDatabase(
"GESTION",
"C_ALBDEP") +
1765 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
1766 " AND NUMERO + LETRA = " + DB.SQLString(item.Field<
string>(
"doc_num"));
1767 DB.SQLExec(lcSql, ref ldtDatos);
1769 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
1771 ComprobarTablaTemporalSQL(registro,
"GESTION",
"C_ALBDEP",
"_ESPECIAL");
1773 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_ALBDEP" +
"_ESPECIAL" +
"]");
1776 lcSql =
" SELECT * " +
1777 " FROM " + DB.SQLDatabase(
"GESTION",
"D_ALBDEP") +
1778 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
1779 " AND NUMERO + LETRA = " + DB.SQLString(item.Field<
string>(
"doc_num")) +
1780 " AND LINIA = " + DB.SQLString(item.Field<
int>(
"doc_lin"));
1782 DB.SQLExec(lcSql, ref ldtDatos);
1784 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
1786 ComprobarTablaTemporalSQL(registro,
"GESTION",
"D_ALBDEP",
"_ESPECIAL");
1788 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_ALBDEP" +
"_ESPECIAL" +
"]");
1794 private static void TratamientoEspecial_DepositosCompra(RegistroTabRel registro, OfflineDatosComunicaciones datos)
1798 if (!registro._Sobreescribir && registro._DBPrincipal ==
"GESTION")
1800 DataTable ldtDatosRelacionados =
new DataTable();
1801 string lcSql =
string.Empty;
1804 lcSql =
" SELECT DISTINCT empresa, doc_num, doc_lin " +
1805 " FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].[dbo].[D_DEPCOM" + registro._Sufijo +
"]" +
1807 DB.SQLExec(lcSql, ref ldtDatosRelacionados);
1809 foreach (DataRow item
in ldtDatosRelacionados.Rows)
1811 DataTable ldtDatos =
new DataTable();
1812 lcSql =
" SELECT * " +
1813 " FROM " + DB.SQLDatabase(
"GESTION",
"C_PEDICO") +
1814 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
1815 " AND NUMERO = " + DB.SQLString(item.Field<
string>(
"doc_num"));
1816 DB.SQLExec(lcSql, ref ldtDatos);
1818 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
1820 ComprobarTablaTemporalSQL(registro,
"GESTION",
"C_PEDICO",
"_ESPECIAL");
1822 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_PEDICO" +
"_ESPECIAL" +
"]");
1825 lcSql =
" SELECT * " +
1826 " FROM " + DB.SQLDatabase(
"GESTION",
"D_PEDICO") +
1827 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
1828 " AND NUMERO = " + DB.SQLString(item.Field<
string>(
"doc_num")) +
1829 " AND LINIA = " + DB.SQLString(item.Field<
int>(
"doc_lin"));
1831 DB.SQLExec(lcSql, ref ldtDatos);
1833 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
1835 ComprobarTablaTemporalSQL(registro,
"GESTION",
"D_PEDICO",
"_ESPECIAL");
1837 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_PEDICO" +
"_ESPECIAL" +
"]");
1842 lcSql =
" SELECT DISTINCT empresa, doc_num, doc_lin " +
1843 " FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].[dbo].[D_DEPCOM" + registro._Sufijo +
"]" +
1845 DB.SQLExec(lcSql, ref ldtDatosRelacionados);
1847 foreach (DataRow item
in ldtDatosRelacionados.Rows)
1849 DataTable ldtDatos =
new DataTable();
1850 lcSql =
" SELECT * " +
1851 " FROM " + DB.SQLDatabase(
"GESTION",
"C_DEPCOM") +
1852 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
1853 " AND NUMERO = " + DB.SQLString(item.Field<
string>(
"doc_num"));
1854 DB.SQLExec(lcSql, ref ldtDatos);
1856 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
1858 ComprobarTablaTemporalSQL(registro,
"GESTION",
"C_DEPCOM",
"_ESPECIAL");
1860 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_DEPCOM" +
"_ESPECIAL" +
"]");
1863 lcSql =
" SELECT * " +
1864 " FROM " + DB.SQLDatabase(
"GESTION",
"D_DEPCOM") +
1865 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
1866 " AND NUMERO = " + DB.SQLString(item.Field<
string>(
"doc_num")) +
1867 " AND LINIA = " + DB.SQLString(item.Field<
int>(
"doc_lin"));
1869 DB.SQLExec(lcSql, ref ldtDatos);
1871 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
1873 ComprobarTablaTemporalSQL(registro,
"GESTION",
"D_DEPCOM",
"_ESPECIAL");
1875 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_DEPCOM" +
"_ESPECIAL" +
"]");
1882 private static void TratamientoEspecial_AlbaranesVenta(RegistroTabRel registro, OfflineDatosComunicaciones datos)
1886 if (!registro._Sobreescribir && registro._DBSecundaria ==
"GESTION")
1888 DataTable ldtDatosRelacionados =
new DataTable();
1889 string lcSql =
string.Empty;
1892 lcSql =
" SELECT DISTINCT empresa, doc_num, doc_lin " +
1893 " FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].[dbo].[D_ALBVEN" + registro._Sufijo +
"]" +
1895 DB.SQLExec(lcSql, ref ldtDatosRelacionados);
1897 foreach (DataRow item
in ldtDatosRelacionados.Rows)
1899 DataTable ldtDatos =
new DataTable();
1900 lcSql =
" SELECT * " +
1901 " FROM " + DB.SQLDatabase(
"GESTION",
"C_PEDIVE") +
1902 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
1903 " AND NUMERO + LETRA = " + DB.SQLString(item.Field<
string>(
"doc_num"));
1904 DB.SQLExec(lcSql, ref ldtDatos);
1906 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
1908 ComprobarTablaTemporalSQL(registro,
"GESTION",
"C_PEDIVE",
"_ESPECIAL");
1910 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_PEDIVE" +
"_ESPECIAL" +
"]");
1913 lcSql =
" SELECT * " +
1914 " FROM " + DB.SQLDatabase(
"GESTION",
"D_PEDIVE") +
1915 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
1916 " AND NUMERO + LETRA = " + DB.SQLString(item.Field<
string>(
"doc_num")) +
1917 " AND LINIA = " + DB.SQLString(item.Field<
int>(
"doc_lin"));
1919 DB.SQLExec(lcSql, ref ldtDatos);
1921 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
1923 ComprobarTablaTemporalSQL(registro,
"GESTION",
"D_PEDIVE",
"_ESPECIAL");
1925 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_PEDIVE" +
"_ESPECIAL" +
"]");
1930 lcSql =
" SELECT DISTINCT empresa, doc_num, doc_lin " +
1931 " FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].[dbo].[D_ALBVEN" + registro._Sufijo +
"]" +
1933 DB.SQLExec(lcSql, ref ldtDatosRelacionados);
1935 foreach (DataRow item
in ldtDatosRelacionados.Rows)
1937 DataTable ldtDatos =
new DataTable();
1938 lcSql =
" SELECT * " +
1939 " FROM " + DB.SQLDatabase(
"GESTION",
"C_ALBDEP") +
1940 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
1941 " AND NUMERO + LETRA = " + DB.SQLString(item.Field<
string>(
"doc_num"));
1942 DB.SQLExec(lcSql, ref ldtDatos);
1944 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
1946 ComprobarTablaTemporalSQL(registro,
"GESTION",
"C_ALBDEP",
"_ESPECIAL");
1948 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_ALBDEP" +
"_ESPECIAL" +
"]");
1951 lcSql =
" SELECT * " +
1952 " FROM " + DB.SQLDatabase(
"GESTION",
"D_ALBDEP") +
1953 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
1954 " AND NUMERO + LETRA = " + DB.SQLString(item.Field<
string>(
"doc_num")) +
1955 " AND LINIA = " + DB.SQLString(item.Field<
int>(
"doc_lin"));
1957 DB.SQLExec(lcSql, ref ldtDatos);
1959 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
1961 ComprobarTablaTemporalSQL(registro,
"GESTION",
"D_ALBDEP",
"_ESPECIAL");
1963 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_ALBDEP" +
"_ESPECIAL" +
"]");
1968 lcSql =
" SELECT DISTINCT empresa, doc_num, doc_lin " +
1969 " FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].[dbo].[D_ALBVEN" + registro._Sufijo +
"]" +
1971 DB.SQLExec(lcSql, ref ldtDatosRelacionados);
1973 foreach (DataRow item
in ldtDatosRelacionados.Rows)
1975 DataTable ldtDatos =
new DataTable();
1976 lcSql =
" SELECT * " +
1977 " FROM " + DB.SQLDatabase(
"GESTION",
"C_PRESUV") +
1978 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
1979 " AND NUMERO + LETRA = " + DB.SQLString(item.Field<
string>(
"doc_num"));
1980 DB.SQLExec(lcSql, ref ldtDatos);
1982 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
1984 ComprobarTablaTemporalSQL(registro,
"GESTION",
"C_PRESUV",
"_ESPECIAL");
1986 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_PRESUV" +
"_ESPECIAL" +
"]");
1989 lcSql =
" SELECT * " +
1990 " FROM " + DB.SQLDatabase(
"GESTION",
"D_PRESUV") +
1991 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
1992 " AND NUMERO + LETRA = " + DB.SQLString(item.Field<
string>(
"doc_num")) +
1993 " AND LINIA = " + DB.SQLString(item.Field<
int>(
"doc_lin"));
1995 DB.SQLExec(lcSql, ref ldtDatos);
1997 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
1999 ComprobarTablaTemporalSQL(registro,
"GESTION",
"D_PRESUV",
"_ESPECIAL");
2001 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_PRESUV" +
"_ESPECIAL" +
"]");
2007 private static void TratamientoEspecial_AlbaranesCompra(RegistroTabRel registro, OfflineDatosComunicaciones datos)
2011 if (!registro._Sobreescribir && registro._DBSecundaria ==
"GESTION")
2013 DataTable ldtDatosRelacionados =
new DataTable();
2014 string lcSql =
string.Empty;
2017 lcSql =
" SELECT DISTINCT empresa, doc_num, doc_lin " +
2018 " FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].[dbo].[D_ALBCOM" + registro._Sufijo +
"]" +
2020 DB.SQLExec(lcSql, ref ldtDatosRelacionados);
2022 foreach (DataRow item
in ldtDatosRelacionados.Rows)
2024 DataTable ldtDatos =
new DataTable();
2025 lcSql =
" SELECT * " +
2026 " FROM " + DB.SQLDatabase(
"GESTION",
"C_PEDICO") +
2027 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
2028 " AND NUMERO = " + DB.SQLString(item.Field<
string>(
"doc_num"));
2029 DB.SQLExec(lcSql, ref ldtDatos);
2031 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
2033 ComprobarTablaTemporalSQL(registro,
"GESTION",
"C_PEDICO",
"_ESPECIAL");
2035 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_PEDICO" +
"_ESPECIAL" +
"]");
2038 lcSql =
" SELECT * " +
2039 " FROM " + DB.SQLDatabase(
"GESTION",
"D_PEDICO") +
2040 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
2041 " AND NUMERO = " + DB.SQLString(item.Field<
string>(
"doc_num")) +
2042 " AND LINIA = " + DB.SQLString(item.Field<
int>(
"doc_lin"));
2044 DB.SQLExec(lcSql, ref ldtDatos);
2046 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
2048 ComprobarTablaTemporalSQL(registro,
"GESTION",
"D_PEDICO",
"_ESPECIAL");
2050 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_PEDICO" +
"_ESPECIAL" +
"]");
2055 lcSql =
" SELECT DISTINCT empresa, doc_num, doc_lin " +
2056 " FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].[dbo].[D_ALBCOM" + registro._Sufijo +
"]" +
2058 DB.SQLExec(lcSql, ref ldtDatosRelacionados);
2060 foreach (DataRow item
in ldtDatosRelacionados.Rows)
2062 DataTable ldtDatos =
new DataTable();
2063 lcSql =
" SELECT * " +
2064 " FROM " + DB.SQLDatabase(
"GESTION",
"C_DEPCOM") +
2065 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
2066 " AND NUMERO = " + DB.SQLString(item.Field<
string>(
"doc_num"));
2067 DB.SQLExec(lcSql, ref ldtDatos);
2069 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
2071 ComprobarTablaTemporalSQL(registro,
"GESTION",
"C_DEPCOM",
"_ESPECIAL");
2073 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_DEPCOM" +
"_ESPECIAL" +
"]");
2076 lcSql =
" SELECT * " +
2077 " FROM " + DB.SQLDatabase(
"GESTION",
"D_DEPCOM") +
2078 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
2079 " AND NUMERO = " + DB.SQLString(item.Field<
string>(
"doc_num")) +
2080 " AND LINIA = " + DB.SQLString(item.Field<
int>(
"doc_lin"));
2082 DB.SQLExec(lcSql, ref ldtDatos);
2084 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
2086 ComprobarTablaTemporalSQL(registro,
"GESTION",
"D_DEPCOM",
"_ESPECIAL");
2088 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_DEPCOM" +
"_ESPECIAL" +
"]");
2094 private static void TratamientoEspecial_FacturasVenta(RegistroTabRel registro, OfflineDatosComunicaciones datos)
2098 if (!registro._Sobreescribir && registro._DBPrincipal ==
"GESTION")
2100 DataTable ldtDatosRelacionados =
new DataTable();
2101 string lcSql =
string.Empty;
2104 lcSql =
" SELECT DISTINCT empresa, numero " +
2105 " FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].[dbo].[C_FACTUVEN" + registro._Sufijo +
"]";
2106 DB.SQLExec(lcSql, ref ldtDatosRelacionados);
2108 foreach (DataRow item
in ldtDatosRelacionados.Rows)
2110 DataTable ldtDatos =
new DataTable();
2111 lcSql =
" SELECT * " +
2112 " FROM " + DB.SQLDatabase(
"GESTION",
"C_ALBVEN") +
2113 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
2114 " AND FACTURA = " + DB.SQLString(item.Field<
string>(
"numero"));
2115 DB.SQLExec(lcSql, ref ldtDatos);
2117 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
2119 ComprobarTablaTemporalSQL(registro,
"GESTION",
"C_ALBVEN",
"_ESPECIAL");
2121 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_ALBVEN" +
"_ESPECIAL" +
"]");
2127 private static void TratamientoEspecial_FacturasCompra(RegistroTabRel registro, OfflineDatosComunicaciones datos)
2131 if (!registro._Sobreescribir && registro._DBPrincipal ==
"GESTION")
2133 DataTable ldtDatosRelacionados =
new DataTable();
2134 string lcSql =
string.Empty;
2137 lcSql =
" SELECT DISTINCT empresa, proveedor, numero " +
2138 " FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].[dbo].[C_FACTUCOM" + registro._Sufijo +
"]";
2139 DB.SQLExec(lcSql, ref ldtDatosRelacionados);
2141 foreach (DataRow item
in ldtDatosRelacionados.Rows)
2143 DataTable ldtDatos =
new DataTable();
2144 lcSql =
" SELECT * " +
2145 " FROM " + DB.SQLDatabase(
"GESTION",
"C_ALBCOM") +
2146 " WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
2147 " AND PROVEEDOR = " + DB.SQLString(item.Field<
string>(
"proveedor")) +
2148 " AND FACTURA = " + DB.SQLString(item.Field<
string>(
"numero"));
2149 DB.SQLExec(lcSql, ref ldtDatos);
2151 if (ldtDatos != null && ldtDatos.Rows.Count > 0)
2153 ComprobarTablaTemporalSQL(registro,
"GESTION",
"C_ALBCOM",
"_ESPECIAL");
2155 InsertarDatosBulkMode(ldtDatos,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"C_ALBCOM" +
"_ESPECIAL" +
"]");
2161 private static void ComprobarTablaTemporalSQL(RegistroTabRel registro,
string tcDb,
string tcTable,
string tcSufijo =
"")
2163 if (!clsOfflineUtils.ExisteDatabaseOffline(_cRaizDataBaseTemporal + tcDb))
2165 CrearDataTable(tcDb, _cRaizDataBaseTemporal);
2168 string lcSufijo = (!
string.IsNullOrWhiteSpace(tcSufijo) ? tcSufijo : registro._Sufijo);
2170 if (!clsOfflineUtils.ExisteTablaOffline(
"[" + _cRaizDataBaseTemporal + tcDb +
"].dbo.[" + tcTable + lcSufijo +
"]"))
2172 string lcSql =
" Select * INTO [" + _cRaizDataBaseTemporal + tcDb +
"].dbo.[" + tcTable + lcSufijo +
"]" +
2173 " From " + DB.SQLDatabase(tcDb, tcTable) +
" as A Where 1 = 2 ";
2180 private static void TratamientoEspecial_Compras(RegistroTabRel registro, OfflineDatosComunicaciones datos)
2183 DataTable ldtDatosCompras =
new DataTable();
2185 if (clsOfflineUtils.ExisteTablaOffline(
"[" + _cRaizDataBaseTemporal + registro._DBSecundaria +
"].dbo.[" + registro._TablaSecundaria + registro._Sufijo +
"]"))
2187 ComprobarTablaTemporalSQL(registro,
"COMUNES",
"COMPRAS");
2190 lcSql =
" SELECT A.* " +
2191 " FROM " + DB.SQLDatabase(
"COMUNES",
"COMPRAS") +
" A " +
2192 " INNER JOIN [" + _cRaizDataBaseTemporal + registro._DBPrincipal +
"].dbo.[" + registro._TablaSecundaria + registro._Sufijo +
"] B " +
2193 " ON A.SERIE = B." + registro._Compras;
2196 DB.SQLExec(lcSql, ref ldtDatosCompras);
2198 if (ldtDatosCompras != null && ldtDatosCompras.Rows.Count > 0)
2200 InsertarDatosBulkMode(ldtDatosCompras,
"[" + _cRaizDataBaseTemporal +
"COMUNES].dbo.[COMPRAS" + registro._Sufijo +
"]");
2205 private static void TratamientoEspecial_Asientos(RegistroTabRel registro, OfflineDatosComunicaciones datos,
bool tlForzar =
false)
2208 DataTable ldtDatosAsientos =
new DataTable();
2210 ComprobarTablaTemporalSQL(registro,
"GESTION",
"ASIENTOS");
2213 lcSql =
" SELECT DISTINCT A.* " +
2214 " FROM " + DB.SQLDatabase(
"GESTION",
"ASIENTOS") +
" A " +
2215 " INNER JOIN [" + _cRaizDataBaseTemporal +
"GESTION].dbo.[ASIENTOS" + registro._Sufijo +
"] B " +
2216 " ON A.EMPRESA=B.EMPRESA And A.NUMERO=B.NUMERO ";
2219 DB.SQLExec(lcSql, ref ldtDatosAsientos);
2221 if (ldtDatosAsientos != null && ldtDatosAsientos.Rows.Count > 0)
2223 DB.SQLExec(
"DELETE FROM [" + _cRaizDataBaseTemporal +
"GESTION].dbo.[ASIENTOS" + registro._Sufijo +
"] WHERE 1 = 1 ");
2225 InsertarDatosBulkMode(ldtDatosAsientos,
"[" + _cRaizDataBaseTemporal +
"GESTION].dbo.[ASIENTOS" + registro._Sufijo +
"]");
2227 if (!clsOfflineUtils.ExisteTablaOffline(
"[" + _cRaizDataBaseTemporal +
"OFFLINE" +
"].dbo.[" +
"CTRL_ASIEN" + registro._Sufijo +
"]"))
2229 if (!clsOfflineUtils.ExisteDatabaseOffline(_cRaizDataBaseTemporal +
"OFFLINE"))
2231 CrearDataTable(
"OFFLINE", _cRaizDataBaseTemporal);
2234 lcSql =
" SELECT * INTO [" + _cRaizDataBaseTemporal +
"OFFLINE" +
"].dbo.[" +
"CTRL_ASIEN" + registro._Sufijo +
"]" +
2235 " FROM [" + datos._BdOffline +
"].dbo.[" +
"CTRL_ASIEN" +
"] WHERE 1 = 2";
2241 Actualizar_Tabla_Control(ldtDatosAsientos,
"GESTION!ASIENTOS",
"CTRL_ASIEN", registro._ID, datos);
2245 string lcAny = EW_GLOBAL._GetVariable(
"wc_any").ToString();
2246 string lcSet =
" Set ORIGEN = " + (datos._IsCentral ? DB.SQLString(
"CENTRAL") : DB.SQLString(datos._Sucursal)) +
", MODIFIED = " + DB.SQLString(DateTime.Now);
2247 string lcOrigen = (datos._IsCentral ?
"CENTRAL" : datos._Sucursal);
2249 foreach (DataRow item
in ldtDatosAsientos.Rows)
2251 string lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
2252 " AND NUMERO = " + DB.SQLString(item.Field<
int>(
"numero")) +
2253 " AND LINEA = " + DB.SQLString(item.Field<
int>(
"linea")) +
2254 " AND EJERCICIO = " + DB.SQLString(lcAny);
2256 string lcInsert =
"(EMPRESA, NUMERO, LINEA, EJERCICIO, ORIGEN, IDTABREL, GUID_ID, CREATED, MODIFIED, VISTA) " +
2258 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
int>(
"numero")) +
", " + DB.SQLString(item.Field<
int>(
"linea")) +
", " +
2259 DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
", " + DB.SQLString(registro._ID) +
", NEWID(), GETDATE(), GETDATE(), cast(1 as bit))";
2261 ComprobarTablaTemporalSQL(registro,
"OFFLINE",
"CTRL_ASIEN");
2263 lcSql =
" IF EXISTS " + Environment.NewLine +
2264 " ( SELECT NUMERO FROM [" + _cRaizDataBaseTemporal +
"OFFLINE].dbo.[CTRL_ASIEN" + registro._Sufijo +
"] " + lcWhere +
" ) " + Environment.NewLine +
2265 " BEGIN " + Environment.NewLine +
2266 " Update [" + _cRaizDataBaseTemporal +
"OFFLINE].dbo.[CTRL_ASIEN" + registro._Sufijo +
"] " + lcSet + lcWhere + Environment.NewLine +
2267 " END " + Environment.NewLine +
2268 " ELSE " + Environment.NewLine +
2269 " BEGIN" + Environment.NewLine +
2270 "Insert Into [" + _cRaizDataBaseTemporal +
"OFFLINE].dbo.[CTRL_ASIEN" + registro._Sufijo +
"] " + lcInsert +
2278 TratamientoEspecialTablas(registro);
2281 private static void TratamientoEspecialTablas(RegistroTabRel registro)
2284 if (!
string.IsNullOrWhiteSpace(registro._Otrasien))
2286 TratamientoEspecial_ASI(registro,
"OTRASIEN", registro._Otrasien);
2289 if (!
string.IsNullOrWhiteSpace(registro._Ivareper))
2291 TratamientoEspecial_ASI(registro,
"IVAREPER", registro._Ivareper);
2294 if (!
string.IsNullOrWhiteSpace(registro._Ivasopor))
2296 TratamientoEspecial_ASI(registro,
"IVASOPOR", registro._Ivasopor);
2299 if (!
string.IsNullOrWhiteSpace(registro._Iva_exen))
2301 TratamientoEspecial_ASI(registro,
"IVA_EXEN", registro._Iva_exen);
2304 if (!
string.IsNullOrWhiteSpace(registro._Retreper))
2306 TratamientoEspecial_ASI(registro,
"RETREPER", registro._Retreper);
2309 if (!
string.IsNullOrWhiteSpace(registro._Retsopor))
2311 TratamientoEspecial_ASI(registro,
"RETSOPOR", registro._Retsopor);
2314 if (!
string.IsNullOrWhiteSpace(registro._Eos))
2316 TratamientoEspecial_ASI(registro,
"EOS", registro._Eos);
2320 private static void ProcesoActualizarControlEspecial(RegistroTabRel registro,
string tcTablaControl, OfflineDatosComunicaciones datos)
2323 switch (tcTablaControl)
2327 DataTable ldtDatosAsientos =
new DataTable();
2328 string lcSql =
string.Empty;
2330 ComprobarTablaTemporalSQL(registro,
"OFFLINE", tcTablaControl);
2333 lcSql =
" SELECT DISTINCT A.* " +
2334 " FROM " + DB.SQLDatabase(
"OFFLINE", tcTablaControl) +
" A " +
2335 " INNER JOIN [" + _cRaizDataBaseTemporal +
"OFFLINE" +
"].dbo.[" + tcTablaControl + registro._Sufijo +
"] B " +
2336 " ON A.EMPRESA=B.EMPRESA And A.NUMERO=B.NUMERO ";
2339 DB.SQLExec(lcSql, ref ldtDatosAsientos);
2341 if (ldtDatosAsientos != null && ldtDatosAsientos.Rows.Count > 0)
2343 DB.SQLExec(
"DELETE FROM [" + _cRaizDataBaseTemporal +
"OFFLINE" +
"].dbo.[" + tcTablaControl + registro._Sufijo +
"] WHERE 1 = 1 ");
2345 InsertarDatosBulkMode(ldtDatosAsientos,
"[" + _cRaizDataBaseTemporal +
"OFFLINE" +
"].dbo.[" + tcTablaControl + registro._Sufijo +
"]");
2358 private static void TratamientoEspecial_ASI(RegistroTabRel registro,
string tcTabla,
string tcCampo)
2360 DataTable ldtDatosASI =
new DataTable();
2361 string lcSql =
string.Empty;
2363 lcSql =
" Select A.* " +
2364 " From " + DB.SQLDatabase(
"GESTION", tcTabla) +
" as a " +
2365 " Inner Join ( Select a.empresa, a.asi " +
2366 " From " + DB.SQLDatabase(
"GESTION",
"ASIENTOS") +
" as a " +
2367 " Inner Join ( Select b.empresa, b.numero " +
2368 " From [" + _cRaizDataBaseTemporal + registro._DBSecundaria +
"].dbo." + registro._TablaSecundaria + registro._Sufijo +
" as a " +
2369 " Inner Join " + DB.SQLDatabase(
"GESTION",
"ASIENTOS") +
" b ON a.EMPRESA = b.EMPRESA And a." + tcCampo +
" = b.ASI " +
2370 " ) b ON a.EMPRESA = b.EMPRESA And a.NUMERO = b.NUMERO " +
2371 " ) b ON a.EMPRESA = b.EMPRESA And a.ASI = b.ASI ";
2375 DB.SQLExec(lcSql, ref ldtDatosASI);
2377 if (ldtDatosASI != null && ldtDatosASI.Rows.Count > 0)
2379 ComprobarTablaTemporalSQL(registro,
"GESTION", tcTabla);
2381 InsertarDatosBulkMode(ldtDatosASI,
"[" + _cRaizDataBaseTemporal +
"GESTION].dbo.[" + tcTabla + registro._Sufijo +
"]");
2385 private static void TratamientoEspecial_Previsiones(RegistroTabRel registro, OfflineDatosComunicaciones datos)
2387 DataTable ldtDatosPrevisiones =
new DataTable();
2388 string lcSql =
string.Empty;
2391 lcSql =
" Select DISTINCT A.* " +
2392 " From " + DB.SQLDatabase(
"GESTION",
"ASIENTOS") +
" as A " +
2393 " Where Exists ( " +
2395 " From [" + _cRaizDataBaseTemporal + registro._DBSecundaria +
"].dbo." + registro._TablaSecundaria + registro._Sufijo +
" as B " +
2396 " Where A.EMPRESA=B.EMPRESA And A.ASI=B.ASI )";
2399 DB.SQLExec(lcSql, ref ldtDatosPrevisiones);
2401 if (ldtDatosPrevisiones != null && ldtDatosPrevisiones.Rows.Count > 0)
2403 ComprobarTablaTemporalSQL(registro,
"GESTION",
"ASIENTOS");
2405 InsertarDatosBulkMode(ldtDatosPrevisiones,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"ASIENTOS" + registro._Sufijo +
"]");
2407 TratamientoEspecial_Asientos(registro, datos,
true);
2411 DataTable ldtDatosIva =
new DataTable();
2412 string lcTabla = (registro._TablaSecundaria ==
"PREVIS" ?
"IVASOPOR" :
"IVAREPER");
2414 if (clsOfflineUtils.ExisteTablaOffline(
"[" + _cRaizDataBaseTemporal +
"GESTION].dbo.[" + lcTabla + registro._Sufijo +
"]"))
2416 lcSql =
" Select A.* " +
2417 " From " + DB.SQLDatabase(
"GESTION", lcTabla) +
" as A " +
2418 " Where Exists ( " +
2420 " From [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo." + lcTabla + registro._Sufijo +
" as B " +
2421 " Where A.EMPRESA=B.EMPRESA And A.ASI = B.ASI )";
2424 DB.SQLExec(lcSql, ref ldtDatosIva);
2426 if (ldtDatosIva != null && ldtDatosIva.Rows.Count > 0)
2428 ComprobarTablaTemporalSQL(registro,
"GESTION", lcTabla);
2430 InsertarDatosBulkMode(ldtDatosIva,
"[" + _cRaizDataBaseTemporal +
"GESTION].dbo.[" + lcTabla + registro._Sufijo +
"]");
2435 private static void TratamientoEspecial_CriterioCaja(RegistroTabRel registro, OfflineDatosComunicaciones datos)
2437 TratamientoEspecial_CriterioCaja(registro, datos,
"ASI");
2438 TratamientoEspecial_CriterioCaja(registro, datos,
"ASI_IVA");
2439 TratamientoEspecial_CriterioCaja(registro, datos,
"ASIRECC");
2442 private static void TratamientoEspecial_CriterioCaja(RegistroTabRel registro, OfflineDatosComunicaciones datos,
string lcCampo)
2444 DataTable ldtDatosPrevisiones =
new DataTable();
2445 string lcSql =
string.Empty;
2447 lcSql =
" Select DISTINCT A.* " +
2448 " From " + DB.SQLDatabase(
"GESTION",
"ASIENTOS") +
" as A " +
2449 " Where Exists ( " +
2451 " From [" + _cRaizDataBaseTemporal + registro._DBSecundaria +
"].dbo." + registro._TablaSecundaria + registro._Sufijo +
" as B " +
2452 " Where A.EMPRESA=B.EMPRESA And A.ASI=B." + lcCampo +
" )";
2455 DB.SQLExec(lcSql, ref ldtDatosPrevisiones);
2457 if (ldtDatosPrevisiones != null && ldtDatosPrevisiones.Rows.Count > 0)
2459 ComprobarTablaTemporalSQL(registro,
"GESTION",
"ASIENTOS");
2461 InsertarDatosBulkMode(ldtDatosPrevisiones,
"[" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"ASIENTOS" + registro._Sufijo +
"]");
2463 TratamientoEspecial_Asientos(registro, datos,
true);
2467 private static void CrearDataTable(
string tcDB,
string tcArrelDB)
2469 string lcDataBaseTemp = tcArrelDB + tcDB;
2471 DB._DBCreate(lcDataBaseTemp);
2474 private static void CrearDataTable(
string tcDB,
string tcArrelDB, RegistroTabRel registro)
2476 string lcDataBaseTemp = tcArrelDB + tcDB;
2477 string lcRutaTemp = Path.Combine(TempFolderName, tcDB);
2479 DB._DBCreate(lcDataBaseTemp);
2481 string lcBdReal = clsOfflineUtils.ObtenerNombreBdReal(registro._DBSecundaria);
2484 if (Directory.Exists(lcRutaTemp))
2486 DB._DBCreate(lcDataBaseTemp);
2488 DB.SQLExec(
"DROP TABLE IF EXISTS [" + lcDataBaseTemp +
"].dbo.[" + registro._TablaSecundaria + registro._Sufijo +
"]");
2491 DB.SQLExec(
"SELECT * INTO [" + lcDataBaseTemp +
"].dbo.[" + registro._TablaSecundaria + registro._Sufijo +
"]" +
2492 " FROM [" + lcBdReal +
"].dbo.[" + registro._TablaSecundaria +
"] WHERE 1 = 2");
2496 private static void InsertarTablaBaseDatosBulk(
string tcDB,
string tcArrelDB, RegistroTabRel registro, DataTable dtDatos)
2498 string lcDataBaseTemp = tcArrelDB + tcDB;
2499 string lcRutaTemp = Path.Combine(TempFolderName, tcDB);
2502 if (Directory.Exists(lcRutaTemp))
2505 using (
System.Data.SqlClient.SqlBulkCopy bulkCopy =
new System.Data.SqlClient.SqlBulkCopy(DB.Conexion))
2507 bulkCopy.DestinationTableName =
"[" + lcDataBaseTemp +
"].dbo.["+ registro._TablaSecundaria + registro._Sufijo +
"]";
2510 bulkCopy.WriteToServer(dtDatos);
2515 private static void GestionarXML_TablasTemporales(Dictionary<string, DataTable> dicTablas, OfflineDatosComunicaciones datos,
string lcBd,
ILog_comoffRepository logRepository)
2517 _TextStepDetalle =
"Generando ficheros XML adicionales";
2518 _TextStepProgreso = _TextStepDetalle;
2519 _PorcenProgreso = IncrementarBarraProgreso();
2521 foreach (KeyValuePair<string, DataTable> tabla
in dicTablas)
2523 if (tabla.Value != null && tabla.Value.Rows.Count > 0)
2526 ConvertIndividualFile(tabla.Value, Path.Combine(datos._PathFolderInicial), tabla.Key, FormatoExportacion.XML);
2530 logDto.Resultado = 1;
2532 if (tabla.Key.Contains(
"DELETENET"))
2534 tabla.Value.DefaultView.Sort =
"tabla ASC";
2535 DataTable ldtAux = tabla.Value.DefaultView.ToTable();
2538 if (ldtAux.Rows.Count > 0)
2540 List<string> lsTabla =
new List<string>();
2542 foreach (DataRow row
in ldtAux.Rows)
2544 if (!lsTabla.Contains(row[
"tabla"]))
2546 DataRow[] dtRow = ldtAux.Select(
"tabla =" + DB.SQLString(row[
"tabla"]));
2547 if (dtRow.Length > 0)
2549 logDto.Detalle =
"Se han eliminado " + dtRow.Length +
" registros en la tabla " + row[
"tabla"].ToString().Trim() +
". " + Environment.NewLine +
2550 "Dichas eliminaciones se corresponden con datos eliminados en el grupo de empresa origen de los datos.";
2551 logRepository.
Insert(logDto);
2553 lsTabla.Add(row[
"tabla"].ToString());
2561 logDto.Detalle =
"Se han incluido datos nuevos en el fichero de comunicaciones. (" + tabla.Key +
")";
2562 logRepository.
Insert(logDto);
2577 private static void TratamientoEspecial_EnvioAsientos(RegistroTabRel registro, DataRow itemRow, DataRow row, ref DataTable dtAsientos, ref DataTable dtOtrasien, ref DataTable dtEos)
2579 string lcValueAsientos =
string.Empty;
2580 string lcValueOtrasien =
string.Empty;
2581 string lcValueEos =
string.Empty;
2582 string lcSql =
string.Empty;
2583 Dictionary<string, string> dcValue =
new Dictionary<string, string>();
2585 switch (registro._Clave)
2597 if (registro._Asientos !=
"")
2599 if (!
string.IsNullOrEmpty(itemRow[
"asientos"].ToString().Trim()))
2601 dcValue.Add(
"Asientos", itemRow[
"asientos"].ToString().Trim());
2603 RegistroEspecial_Asientos_Envio(dcValue,
"ASIENTOS", row, ref dtAsientos,
"Asientos");
2606 if (registro._Otrasien !=
"")
2608 if (!
string.IsNullOrEmpty(itemRow[
"otrasien"].ToString().Trim()))
2610 dcValue.Add(
"Otrasien", itemRow[
"otrasien"].ToString().Trim());
2612 RegistroEspecial_Asientos_Envio(dcValue,
"ASIENTOS", row, ref dtOtrasien,
"Otrasien");
2615 if (registro._Eos !=
"")
2617 if (!
string.IsNullOrEmpty(itemRow[
"eos"].ToString().Trim()))
2619 dcValue.Add(
"Eos", itemRow[
"eos"].ToString().Trim());
2621 RegistroEspecial_Asientos_Envio(dcValue,
"ASIENTOS", row, ref dtEos,
"Eos");
2637 private static void RegistroEspecial_Asientos_Envio(Dictionary<string,string> dcValue,
string lcTabla, DataRow row, ref DataTable dtTabla,
string lcBusqueda)
2639 DataTable dtTemp =
new DataTable();
2640 DataTable dtDatos =
new DataTable();
2642 string Value = dcValue.FirstOrDefault(x => x.Key == lcBusqueda).Value;
2644 if (!
string.IsNullOrEmpty(Value))
2647 string lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"GESTION", lcTabla) +
" WHERE " + Value +
" = " + DB.SQLString(row[Value]);
2649 DB.SQLExec(lcSql, ref dtTemp);
2651 foreach (DataRow loRow
in dtTemp.Rows)
2653 lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"GESTION", lcTabla) +
" WHERE NUMERO = " + DB.SQLString(loRow[
"numero"]) +
" AND EMPRESA = " + DB.SQLString(loRow[
"empresa"]);
2655 DB.SQLExec(lcSql, ref dtDatos);
2657 string lcValue =
string.Empty;
2658 foreach (DataRow item
in dtDatos.Rows)
2660 dtTabla.ImportRow(item);
2674 private static void RegistroEspecial_OtrasienEos_Envio(
string value,
string lcTabla, DataRow row, ref DataTable dtTabla, DataRow loRow)
2676 DataTable dtDatos =
new DataTable();
2678 string lcSql =
"SELECT * FROM " + DB.SQLDatabase(
"GESTION", lcTabla) +
" WHERE ASI = " + DB.SQLString(loRow[
"asi"]) +
" AND EMPRESA = " + DB.SQLString(loRow[
"empresa"]);
2680 DB.SQLExec(lcSql, ref dtDatos);
2682 foreach (DataRow item
in dtDatos.Rows)
2684 dtTabla.ImportRow(item);
2688 private static void RegistroDatosEspecial(OfflineDatosComunicaciones datos,
string tcTabla, DataTable ldtDatos,
ILog_comoffRepository logRepository)
2690 string lcDetalle =
string.Empty;
2692 if (ldtDatos.TableName.Contains(
"_MODIFIED"))
2694 lcDetalle =
"Se han incluido los siguientes datos modificados en el fichero de comunicaciones. Dato: " + tcTabla + Environment.NewLine;
2698 lcDetalle =
"Se han incluido los siguientes datos nuevos en el fichero de comunicaciones. Dato: " + tcTabla + Environment.NewLine;
2702 lcDetalle += ConstruirTextoDetalle(ldtDatos,
"numero",
"ASIENTOS",
"GESTION");
2708 logRepository.
Insert(logDto);
2711 private static void TratamientoEspecial_EnvioFabricacion(RegistroTabRel registro, OfflineDatosComunicaciones datos)
2713 string lcSql =
string.Empty;
2716 string lcBdReal = clsOfflineUtils.ObtenerNombreBdReal(registro._DBSecundaria);
2719 if (registro._TablaSecundaria ==
"D_PARTES")
2721 lcSql =
" SELECT a.* INTO [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[_COSTES_C_PARTES" + registro._Sufijo +
"]" +
2722 " FROM [" + lcBdReal +
"].dbo.C_PARTES a " +
2724 " SELECT DISTINCT empresa, numero " +
2725 " FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_PARTES" + registro._Sufijo +
"] " +
2726 " WHERE albaran = 0 " +
2727 " ) b ON a.empresa = b.empresa AND a.numero = b.numero ";
2730 lcSql =
" SELECT * INTO [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[_COSTES_D_PARTES" + registro._Sufijo +
"]" +
2731 " FROM [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" +
"D_PARTES" + registro._Sufijo +
"] WHERE albaran = 0 ";
2736 string[] filesTablas =
new string[] {
"D_PARTES",
"C_PARTES" };
2737 DataTable table =
new DataTable();
2739 foreach (
string file
in filesTablas)
2741 ComprobarTablaTemporalSQL(registro,
"GESTION", file);
2743 int tipo_alb = (registro._TablaSecundaria ==
"D_PROD" ? 1 : 2);
2745 if (file ==
"D_PARTES")
2747 lcSql =
" FROM [" + lcBdReal +
"].dbo.[D_PARTES] as A " +
2748 " INNER JOIN [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" + registro._TablaSecundaria + registro._Sufijo +
"] as B " +
2749 " ON A.EMPRESA = B.EMPRESA AND A.ALBARAN = B.NUMERO AND A.LINEA = B.LINEA AND A.TIPO_ALB = " + tipo_alb;
2753 lcSql =
" FROM [" + lcBdReal +
"].dbo.C_PARTES a " +
2754 " INNER JOIN ( SELECT DISTINCT A.EMPRESA, A.NUMERO " +
2755 " FROM [" + lcBdReal +
"].dbo.[D_PARTES] as A " +
2756 " INNER JOIN [" + _cRaizDataBaseTemporal +
"GESTION" +
"].dbo.[" + registro._TablaSecundaria + registro._Sufijo +
"] as B " +
2757 " ON A.EMPRESA = B.EMPRESA AND A.ALBARAN = B.NUMERO AND A.LINEA = B.LINEA AND A.TIPO_ALB = " + tipo_alb +
2758 " ) b on A.EMPRESA = B.EMPRESA And A.NUMERO = B.NUMERO ";
2761 DB.SQLExec(
" SELECT a.* " + lcSql, ref table);
2763 if (table != null & table.Rows.Count > 0)
2765 DB.SQLExec(
" SELECT A.* INTO [" + _cRaizDataBaseTemporal + registro._DBSecundaria +
"].dbo.[_PARTES" + tipo_alb +
"_" + file + registro._Sufijo +
"] " + lcSql);
2768 if (file ==
"D_PARTES")
2770 Actualizar_Tabla_Control(table,
"GESTION!D_PARTES",
"CTRL_PARCO", registro._ID, datos);
2772 string lcAny = EW_GLOBAL._GetVariable(
"wc_any").ToString();
2773 string lcSet =
" Set ORIGEN = " + (datos._IsCentral ? DB.SQLString(
"CENTRAL") : DB.SQLString(datos._Sucursal)) +
", MODIFIED = " + DB.SQLString(DateTime.Now);
2774 string lcOrigen = (datos._IsCentral ?
"CENTRAL" : datos._Sucursal);
2776 foreach (DataRow item
in table.Rows)
2778 string lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
2779 " AND NUMERO = " + DB.SQLString(item.Field<
string>(
"numero")) +
2780 " AND LINIA = " + DB.SQLString(item.Field<
int>(
"linea")) +
2781 " AND EJERCICIO = " + DB.SQLString(lcAny);
2783 string lcInsert =
"(EMPRESA, NUMERO, LINIA, ORIGEN, EJERCICIO, GUID_ID, CREATED, MODIFIED, VISTA, IDTABREL) " +
2785 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
string>(
"numero")) +
", " + DB.SQLString(item.Field<
int>(
"linea")) +
", " +
2786 DB.SQLString(lcOrigen) +
", " + DB.SQLString(lcAny) +
", NEWID(), GETDATE(), GETDATE(), cast(1 as bit), 0)";
2788 ComprobarTablaTemporalSQL(registro,
"OFFLINE",
"CTRL_PARCO");
2790 lcSql =
" IF EXISTS " + Environment.NewLine +
2791 " ( SELECT NUMERO FROM [" + _cRaizDataBaseTemporal +
"OFFLINE].dbo.[CTRL_PARCO" + registro._Sufijo +
"] " + lcWhere +
" ) " + Environment.NewLine +
2792 " BEGIN " + Environment.NewLine +
2793 " Update [" + _cRaizDataBaseTemporal +
"OFFLINE].dbo.[CTRL_PARCO" + registro._Sufijo +
"] " + lcSet + lcWhere + Environment.NewLine +
2794 " END " + Environment.NewLine +
2795 " ELSE " + Environment.NewLine +
2796 " BEGIN" + Environment.NewLine +
2797 "Insert Into [" + _cRaizDataBaseTemporal +
"OFFLINE].dbo.[CTRL_PARCO" + registro._Sufijo +
"] " + lcInsert +
2808 private static void RegistroDatos(OfflineDatosComunicaciones datos, DataRow registro,
string tcBdReal,
string tbDB,
string tcTabla, DataTable tdtDatos,
string lcSufijo,
ILog_comoffRepository logRepository)
2810 string lcDetalle =
string.Empty;
2811 string lcCampo =
string.Empty;
2813 List<string> lista =
new List<string>();
2816 if (lcSufijo.Contains(
"_MODIFIED"))
2818 lcDetalle =
"Se han incluido los siguientes datos modificados en el fichero de comunicaciones. " + Environment.NewLine;
2822 lcDetalle =
"Se han incluido los siguientes datos nuevos en el fichero de comunicaciones. " + Environment.NewLine;
2825 lcDetalle +=
"Dato: " + (tcTabla.Contains(
"CTRL_") ?
"Información extendida de " :
"") + registro.Field<
string>(
"titulo").TrimEnd().ToUpper() + Environment.NewLine + Environment.NewLine;
2827 int nId = registro.Field<
int>(
"id");
2828 string cClave = registro.Field<
string>(
"clave");
2854 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"articulo",
"ARTICULO",
"GESTION");
2859 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"familia",
"ARTICULO",
"GESTION");
2864 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"codigo",
"MCAMPOS",
"GESTION");
2869 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"subfam",
"SUBFAM",
"GESTION");
2874 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"talla",
"TALLAS",
"COMUNES");
2879 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"color",
"COLORES",
"COMUNES");
2896 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"almacen",
"ALMACEN",
"GESTION");
2904 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"almacen",
"ALMACEN",
"GESTION");
2915 ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"numero",
"",
"numero");
2921 ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"letra",
"numero",
"numero");
2926 ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"documento",
"",
"documento");
2935 lcCampo = (tcTabla ==
"D_FORMUL" ?
"formula" :
"articulo");
2936 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"C_FORMUL",
"LOTES",
"ARTICULO");
2942 lcCampo = (tcTabla ==
"ART_CLASIF" ?
"clasif" :
"codigo");
2943 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"CLASIF",
"COMUNES");
2960 lcCampo = (tcTabla ==
"RIESGO" ?
"codigo" :
"cliente");
2961 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"CLIENTES",
"GESTION");
2966 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"tcp",
"TCP",
"COMUNES");
2973 lcCampo = (tcTabla ==
"OTRAS" ?
"codigo" :
"cuenta");
2974 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"CUENTAS",
"GESTION");
2987 lcCampo = (tcTabla ==
"DESC_PRO" ?
"proveed" :
"proveedor");
2988 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"PROVEED",
"GESTION");
2997 lcCampo = (tcTabla ==
"ENTRE_CL" || tcTabla ==
"PREVI_CL" ?
"cliente" :
"cuenta");
2998 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"CLIENTES",
"GESTION");
3003 lcCampo = (tcTabla ==
"ENTRE_CL" ?
"cliente" : (tcTabla ==
"PREVIS" ?
"proveedor" :
"cuenta"));
3004 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"PROVEED",
"GESTION");
3017 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"factura");
3022 lcCampo = (tcTabla ==
"ENTRE_CL" || tcTabla ==
"PREVI_CL" ?
"cliente" :
"cuenta");
3023 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"CLIENTES",
"GESTION");
3028 lcCampo = (tcTabla ==
"ENTRE_CL" ?
"cliente" : (tcTabla ==
"PREVIS" ?
"proveedor" :
"cuenta"));
3029 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"PROVEED",
"GESTION");
3034 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"cuenta",
"factura");
3048 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"numfra");
3053 lcCampo = (tcTabla ==
"ENTRE_CL" || tcTabla ==
"PREVI_CL" ?
"cliente" :
"cuenta");
3054 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"CLIENTES",
"GESTION");
3059 lcCampo = (tcTabla ==
"ENTRE_CL" ?
"cliente" : (tcTabla ==
"PREVIS" ?
"proveedor" :
"cuenta"));
3060 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"PROVEED",
"GESTION");
3065 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"cuenta",
"numfra");
3077 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"cuenta",
"PROVEED",
"GESTION");
3082 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"cuenta",
"numfra");
3096 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"factura");
3101 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"cuenta",
"CLIENTES",
"GESTION");
3106 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"cuenta",
"PROVEED",
"GESTION");
3111 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"cuenta",
"factura");
3120 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"numfra");
3132 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"numfra");
3146 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"factura");
3151 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"cliente",
"CLIENTES",
"GESTION");
3164 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"proveedor",
"PROVEED",
"GESTION");
3169 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"proveedor",
"factura");
3177 lcDetalle += tdtDatos.Rows.Count.ToString() +
" registros.";
3188 lcCampo = (tcTabla ==
"OTRASIEN" ?
"codcuen" :
"cuenta");
3189 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"CLIENTES",
"GESTION");
3194 lcCampo = (tcTabla ==
"OTRASIEN" ?
"codcuen" :
"cuenta");
3195 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"CLIENTES",
"GESTION");
3200 lcCampo = (tcTabla ==
"OTRASIEN" ?
"codcuen" :
"cuenta");
3201 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"CLIENTES",
"GESTION");
3209 lcCampo = (tcTabla ==
"OTRASIEN" ?
"codcuen" :
"cuenta");
3210 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"CLIENTES",
"GESTION");
3217 lcCampo = (tcTabla ==
"OTRASIEN" ?
"codcuen" :
"cuenta");
3218 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"PROVEED",
"GESTION");
3223 lcCampo = (tcTabla ==
"OTRASIEN" ?
"codcuen" :
"cuenta");
3224 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"CLIENTES",
"GESTION");
3229 lcCampo = (tcTabla ==
"OTRASIEN" ?
"codcuen" :
"cuenta");
3230 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo,
"PROVEED",
"GESTION");
3243 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"numero");
3255 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"proveedor",
"numero");
3269 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"numfra");
3284 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"borrador");
3299 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"borrador");
3307 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"fpag",
"FPAG",
"GESTION");
3312 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"codigo",
"LINEAS",
"GESTION");
3317 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"ruta",
"RUTAS",
"GESTION");
3322 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"vendedor",
"VENDEDOR",
"GESTION");
3327 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"conirpf",
"nombre");
3333 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"letra",
"LETRAS",
"COMUNES");
3338 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"caja",
"CAJAS",
"TPV");
3343 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"plancont",
"PLANS",
"GESTION");
3363 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"empresa",
"EMPRESA",
"GESTION");
3368 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"operario",
"OPERARIO",
"COMUNES");
3374 lcDetalle += ConstruirTextoDetalle(tdtDatos,
"usuario",
"USUARIOS",
"COMUNES");
3383 foreach (DataRow item
in tdtDatos.Rows)
3385 lcDetalle += item.Field<
int>(
"codigo").ToString().TrimEnd() +
" - " + item.Field<
string>(
"nombre").TrimEnd() + Environment.NewLine;
3394 lcCampo = (tcTabla ==
"D_ARQUEO" ?
"arqueo" :
"numero");
3396 foreach (DataRow item
in tdtDatos.Rows)
3398 if (!lista.Contains(item.Field<
string>(
"empresa").ToString().TrimEnd() +
" - " + item.Field<
int>(lcCampo).ToString().TrimEnd()))
3400 lcDetalle += item.Field<
string>(
"empresa").ToString().TrimEnd() +
" - " + item.Field<
int>(lcCampo).ToString().TrimEnd() + Environment.NewLine;
3401 lista.Add(item.Field<
string>(
"empresa").ToString().TrimEnd() +
" - " + item.Field<
int>(lcCampo).ToString().TrimEnd());
3427 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"numero");
3440 case "TPVCONARQUEO":
3441 case "TPVSINARQUEO":
3443 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"letra",
"numero");
3458 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"proveedor",
"numero");
3473 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"letra",
"numero");
3518 lcCampo = (tcTabla ==
"PORTES" || tcTabla ==
"ENTREGAS" ?
"albaran" : (tcTabla ==
"VALES" ?
"ticket" :
"numero"));
3519 if (cClave ==
"FACTURAS")
3521 lcCampo = (tcTabla ==
"C_ALBVEN" && tcBdReal ==
"GESTION" ?
"factura" : lcCampo);
3524 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"letra", lcCampo);
3560 lcCampo = (tcTabla ==
"PRODUSER" || tcTabla ==
"PRODUSERC" || tcTabla ==
"TRANSER" || tcTabla ==
"TRANSSER" ?
"albaran" :
"numero");
3562 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa", lcCampo);
3576 lcCampo = (tcTabla ==
"PORTESC" ?
"albaran" :
"numero");
3577 if (cClave ==
"FACTURAC")
3579 lcCampo = (tcTabla ==
"C_ALBCOM" ?
"factura" : lcCampo);
3582 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"empresa",
"proveedor", lcCampo);
3591 lcDetalle += tdtDatos.Rows.Count.ToString() +
" registros.";
3603 if (tcTabla.Contains(
"CTRL_"))
3605 string[] loDatos = _offlineConfig.ObtenerTablaOriginalRelacionada(tcTabla).Split(
'!');
3608 if (loDatos.Length == 2)
3614 lcCampo =
"ARTICULO";
3619 lcCampo =
"ALMACEN";
3624 lcCampo =
"CONIRPF";
3634 if (tcTabla ==
"CTRL_PRCLI")
3636 lcDetalle += ConstruirTextoDetalleEntero(tdtDatos, lcCampo.ToLower(), loDatos[1], loDatos[0], lcCampo);
3640 lcDetalle += ConstruirTextoDetalle(tdtDatos, lcCampo.ToLower(), loDatos[1], loDatos[0], lcCampo);
3646 if (tdtDatos.Columns.Contains(
"codigo") && tdtDatos.Columns.Contains(
"nombre"))
3648 lcDetalle += ConstruirTextoDetalleEspecial(tdtDatos,
"codigo",
"nombre");
3656 logDto.
TipoDato = clsOfflineUtils.ObtenerTipoDato(registro.Field<
string>(
"clave").TrimEnd().ToUpper());
3659 logRepository.
Insert(logDto);
3667 public static void EnvioEmailNotificacion(
string tcFicheroZip, OfflineDatosComunicaciones datos,
ILog_comoffRepository logRepository)
3669 if (datos._NotificacionEnvio && !
string.IsNullOrEmpty(datos._EmailNotificacionEnvio))
3672 DataTable table =
new DataTable();
3674 AsistenteOffEnvioDatosBizRule loAsist =
new AsistenteOffEnvioDatosBizRule();
3675 Dictionary<string, int> loDic = loAsist.Result_LogComunicaciones_IdLog(ref table, datos._Log_ComoffID);
3677 if (loDic.Count > 0)
3679 KeyValuePair<string, int> itemFirst = loDic.First();
3680 nResultado = itemFirst.Value;
3683 string lcAsunto =
string.Empty;
3684 string lcMensajeEnvio =
string.Empty;
3689 lcAsunto =
"Sage 50 – Errores en el envío de datos";
3690 lcMensajeEnvio =
" Se han producido errores en el proceso de envío de datos de fecha " + clsOfflineUtils.ObtenerFechaFicheroDatos(tcFicheroZip) +
", fichero " + tcFicheroZip +
"<br><br>" +
3691 " Revise el documento adjunto donde se incluye detalle del registro de comunicaciones, en el cual podrá ver los errores detectadas durante el proceso de envío de datos. ";
3694 lcAsunto =
"Sage 50 – Incidencias en el envío de datos";
3695 lcMensajeEnvio =
" Ha finalizado el envío de datos de fecha " + clsOfflineUtils.ObtenerFechaFicheroDatos(tcFicheroZip) +
", fichero " + tcFicheroZip +
" con incidencias." +
"<br><br>" +
" Revise el documento adjunto donde se incluye detalle del registro de comunicaciones, en el cual podrá ver las incidencias detectadas durante el proceso de envío de datos. ";
3698 lcAsunto =
"Sage 50 – Envío de datos";
3699 lcMensajeEnvio =
" Ha finalizado el envío de datos de fecha " + clsOfflineUtils.ObtenerFechaFicheroDatos(tcFicheroZip) +
", fichero " + tcFicheroZip +
" correctamente. " +
"<br><br>" +
" Revise documento adjunto donde se incluye detalle del registro de comunicaciones en el cual podrá ver los datos enviados. ";
3704 _TextStepDetalle =
"Enviando email de notificación";
3705 _TextStepProgreso = _TextStepDetalle;
3706 _PorcenProgreso = IncrementarBarraProgreso();
3710 loSendMail.
_Emails = datos._EmailNotificacionEnvio.Split(
';').ToList();
3717 (datos._IsCentral ?
"Sucursal destino: " + datos._Sucursal +
" - " + DB.SQLValor(
"SUCURSALES",
"CODIGO", datos._Sucursal,
"NOMBRE",
"OFFLINE").ToString() :
"Central") +
"<br><br>" +
3720 loSendMail.
_Body = lcBody;
3726 _ObtenerConfiguracionEmail(loSendMail);
3729 string cRuta = TempFolderName;
3740 loLogCom.
_Exportar(ew.listados.Clases.Listados.ExportType.pdf, cRuta,
false,
"REG_COMU");
3748 logDto.
Detalle =
"No se ha podido adjuntar el fichero PDF.";
3749 logRepository.
Insert(logDto);
3758 logDto.
Detalle =
"Fallo al realizar envío de mail de notificación de envío de datos. Revise en el mantenimiento de grupos de empresa, los datos de configuración en pestaña Configuración notificaciones del Add-on Comunicaciones offline.";
3763 logDto.
Detalle =
"Enviado email de notificación de envío correctamente.";
3765 logRepository.
Insert(logDto);
3767 if (loSendMail.
_EnvioDirecto && File.Exists(cRuta +
".pdf"))
3769 File.Delete(cRuta +
".pdf");
3774 private static string Envio_Articulos_Sucursal(OfflineDatosComunicaciones datos,
string lcTabla)
3776 string lcCampo =
string.Empty;
3790 lcCampo =
"ARTICULO";
3794 return " AND b." + lcCampo +
" IN (SELECT ARTICULO FROM [" + datos._BdOffline +
"].dbo.sucurart WHERE SUCURSAL = " + DB.SQLString(datos._Sucursal) +
") ";
3797 private static string Envio_Series_Sucursal(OfflineDatosComunicaciones datos)
3799 return " AND a.codigo IN (SELECT LETRA FROM [" + datos._BdOffline +
"].dbo.sucurlet WHERE SUCURSAL = " + DB.SQLString(datos._Sucursal) +
") ";
3802 private static string Envio_Cajas_Sucursal(OfflineDatosComunicaciones datos)
3804 return " AND a.codigo IN (SELECT CAJA FROM [" + datos._BdOffline +
"].dbo.sucurcaja WHERE SUCURSAL = " + DB.SQLString(datos._Sucursal) +
") ";
3807 private static void Actualizar_Fecha_Envio_Sucursales(OfflineDatosComunicaciones datos,
string cTipoEnvio,
ILog_comoffRepository logRepository)
3811 string lcCampo = (cTipoEnvio ==
"i" ?
"CARGAINI" :
"ULTFECENV");
3812 string lcTipoEnvio = (cTipoEnvio ==
"i" ?
"la carga inicial" :
"datos");
3814 _TextStepDetalle =
"Actualizando la fecha de envío de las sucursales";
3815 _TextStepProgreso = _TextStepDetalle;
3816 _PorcenProgreso = IncrementarBarraProgreso();
3818 DB.SQLExec(
"UPDATE " + DB.SQLDatabase(
"OFFLINE",
"SUCURSALES") +
3819 " SET " + lcCampo +
" = " + DB.SQLString(DateTime.Now) +
", MODIFIED = MODIFIED " +
3820 " WHERE CODIGO = " + DB.SQLString(datos._Sucursal));
3825 logDto.
Detalle =
"Envío de " + lcTipoEnvio +
" finalizado correctamente.";
3826 logRepository.
Insert(logDto);
3835 private static void Actualizar_Fecha_Envio_Multiconf(OfflineDatosComunicaciones datos)
3837 string lcCampo =
"ULTFECENV";
3839 DB.SQLExec(
"UPDATE " + DB.SQLDatabase(
"OFFLINE",
"MULTCONF") +
3840 " SET " + lcCampo +
" = " + DB.SQLString(DateTime.Now) +
", MODIFIED = MODIFIED " +
3841 " WHERE IDCONF = " + DB.SQLString(datos._IdConf));
3849 private static void Actualizar_Ultima_Fecha_Envio(
int tnId)
3851 DateTime dtUltFecEnv = DateTime.Now;
3852 string lcWhere =
" WHERE ID = " + DB.SQLString(tnId);
3854 string lcSql =
" IF EXISTS " + Environment.NewLine +
3855 " ( SELECT ID FROM " + DB.SQLDatabase(
"OFFLINE",
"TABNETFEC") + lcWhere +
" ) " + Environment.NewLine +
3856 " BEGIN " + Environment.NewLine +
3857 " UPDATE " + DB.SQLDatabase(
"OFFLINE",
"TABNETFEC") +
3858 " SET ULTFECENV = " + DB.SQLString(dtUltFecEnv) +
3859 lcWhere + Environment.NewLine +
3860 " AND ULTFECENV < " + DB.SQLString(dtUltFecEnv) + Environment.NewLine +
3861 " END " + Environment.NewLine +
3862 " ELSE " + Environment.NewLine +
3863 " BEGIN" + Environment.NewLine +
3864 "Insert Into " + DB.SQLDatabase(
"OFFLINE",
"TABNETFEC") +
3865 "(ID, ULTFECENV) " +
3867 DB.SQLString(tnId) +
", " + DB.SQLString(dtUltFecEnv) +
")" +
3874 private static void Gestionar_Tabla_Control(DataTable table, OfflineDatosComunicaciones datos, RegistroTabRel registro,
bool tlPrioridad,
int tnId,
string tcTipoDato, DataRow itemRow, Dictionary<string, bool> dicTablas,
ILog_comoffRepository logRepository)
3876 DataTable tablaDatosNuevos =
new DataTable();
3877 DataTable tablaDatosModi =
new DataTable();
3879 string lcTablaControl = _offlineConfig.ObtenerTablaControlRelacionada(registro._DBSecundaria +
"!" + registro._TablaSecundaria);
3881 if (!
string.IsNullOrWhiteSpace(lcTablaControl))
3884 string lcInnerJoin = Actualizar_Tabla_Control(table, registro._DBSecundaria +
"!" + registro._TablaSecundaria, lcTablaControl, tnId, datos);
3887 string lcSql =
" FROM [" + datos._BdOffline +
"].dbo." + lcTablaControl +
" a " + lcInnerJoin +
" WHERE 1=1 ";
3889 string lcCampoEmpresa = registro._Empresa;
3891 clsOfflineUtils.RevisarTablasCampoEmpresa(registro._TablaSecundaria, ref lcCampoEmpresa);
3894 if (datos._EnvioArticulos && ((registro._DBSecundaria +
"!" + registro._TablaSecundaria) ==
"GESTION!ARTICULO" || registro._Clave ==
"STOCKINI" || registro._Clave ==
"STOCKS"))
3896 lcSql += Envio_Articulos_Sucursal(datos, registro._TablaSecundaria);
3899 if (datos._IsCentral && registro._DBPrincipal +
"!" + registro._TablaPrincipal ==
"COMUNES!LETRAS")
3901 lcSql += Envio_Series_Sucursal(datos);
3904 string lcFiltrePrincipal =
string.Empty;
3905 if (!
string.IsNullOrWhiteSpace(registro._CondEnv))
3907 if (registro._TablaPrincipal == registro._TablaSecundaria)
3909 lcFiltrePrincipal = registro._CondEnv;
3910 lcFiltrePrincipal = _offlineConfig.ConstruirFiltroAlmacen(lcFiltrePrincipal, datos._Sucursal, datos._Almacenes, registro._TablaSecundaria);
3911 lcFiltrePrincipal = _offlineConfig.ConstruirFiltroLetra(lcFiltrePrincipal, datos._Sucursal, datos._Series);
3912 lcFiltrePrincipal = _offlineConfig.ConstruirFiltroCaja(lcFiltrePrincipal, datos._Sucursal, datos._Cajas);
3914 lcFiltrePrincipal = lcFiltrePrincipal.Replace(
"{TABLA}",
"b.");
3916 lcSql = lcSql +
" AND " + lcFiltrePrincipal;
3920 if (!
string.IsNullOrWhiteSpace(registro._CondSecun))
3922 if (registro._TablaPrincipal != registro._TablaSecundaria)
3924 lcFiltrePrincipal = registro._CondSecun;
3925 lcFiltrePrincipal = _offlineConfig.ConstruirFiltroAlmacen(lcFiltrePrincipal, datos._Sucursal, datos._Almacenes, registro._TablaSecundaria);
3926 lcFiltrePrincipal = _offlineConfig.ConstruirFiltroLetra(lcFiltrePrincipal, datos._Sucursal, datos._Series);
3927 lcFiltrePrincipal = _offlineConfig.ConstruirFiltroCaja(lcFiltrePrincipal, datos._Sucursal, datos._Cajas);
3929 lcFiltrePrincipal = lcFiltrePrincipal.Replace(
"{TABLA}",
"b.");
3931 lcSql = lcSql +
" AND " + lcFiltrePrincipal;
3936 if (!
string.IsNullOrWhiteSpace(lcCampoEmpresa))
3938 lcSql = lcSql +
" AND a." + lcCampoEmpresa +
" NOT IN (SELECT empresa FROM [" + datos._BdOffline +
"].dbo.empexclu) ";
3951 ProcesoActualizarCtrl(itemRow, datos, registro, dicTablas, lcSql, lcTablaControl, logRepository);
3955 private static void ProcesoActualizarCtrl(DataRow itemRow, OfflineDatosComunicaciones datos, RegistroTabRel registro, Dictionary<string, bool> dicTablas,
string tcSql,
string lcTablaControl,
ILog_comoffRepository logRepository)
3957 DataTable dtDatos =
new DataTable();
3958 string lcTipoDato = clsOfflineUtils.ObtenerTipoDato(registro._Clave);
3959 string lcSqlCondicion =
string.Empty;
3977 lcSqlCondicion =
" AND a.CREATED >= " + DB.SQLString(datos._FechaInicial) +
" AND a.CREATED <= " + DB.SQLString(datos._FechaFinal);
3979 string lcSql =
" SELECT a.* " + tcSql + lcSqlCondicion;
3981 if (!DB.SQLExec(lcSql, ref dtDatos))
3986 logDto.
Detalle =
"No se ha podido ejecutar la instrucción " + lcSql +
".";
3987 logRepository.
Insert(logDto);
3990 if (dtDatos.Rows.Count > 0)
3992 if (clsOfflineUtils.ExisteTablaOffline(
"[" + _cRaizDataBaseTemporal +
"OFFLINE" +
"].dbo.[" + lcTablaControl + registro._Sufijo +
"]"))
3994 using (SqlBulkCopy bulkCopy =
new SqlBulkCopy(DB.Conexion))
3996 bulkCopy.DestinationTableName =
"[" + _cRaizDataBaseTemporal +
"OFFLINE" +
"].dbo.[" + lcTablaControl + registro._Sufijo +
"]";
3998 foreach (DataColumn column
in dtDatos.Columns)
4000 bulkCopy.ColumnMappings.Add(column.ColumnName.ToUpper(), column.ColumnName.ToUpper());
4006 bulkCopy.WriteToServer(dtDatos);
4010 bulkCopy.ColumnMappings.Clear();
4011 bulkCopy.WriteToServer(dtDatos);
4017 if (!clsOfflineUtils.ExisteDatabaseOffline(_cRaizDataBaseTemporal +
"OFFLINE"))
4019 CrearDataTable(
"OFFLINE", _cRaizDataBaseTemporal);
4022 lcSql =
" SELECT a.* INTO [" + _cRaizDataBaseTemporal +
"OFFLINE" +
"].dbo.[" + lcTablaControl + registro._Sufijo +
"]" +
4023 tcSql + lcSqlCondicion;
4027 ProcesoActualizarControlEspecial(registro, lcTablaControl, datos);
4029 RegistroDatos(datos, itemRow, datos._BdOffline, registro._TablaSecundaria, lcTablaControl, dtDatos, registro._Sufijo, logRepository);
4030 dicTablas[itemRow[0].ToString()] =
true;
4042 private static void Gestionar_Tabla_DeleteNet(DataTable dtDeleteNet, OfflineDatosComunicaciones datos,
string tcBdTabla, Dictionary<string, DataTable> dicDt, RegistroTabRel registro)
4044 if (!datos._Delete_Mantes && registro._TipoTabla == 1)
4049 if (!datos._Delete_Documentos && registro._TipoTabla == 2)
4054 DataTable tablaDatos =
new DataTable();
4056 string lcAny = EW_GLOBAL._GetVariable(
"wc_any").ToString();
4058 string lcBd =
string.Empty;
4059 string lcTabla =
string.Empty;
4061 string[] subPos = tcBdTabla.Split(
'!');
4062 if (subPos.Length == 2)
4064 lcBd = subPos[0].TrimEnd();
4065 lcTabla = subPos[1].TrimEnd();
4068 string lcSql =
" SELECT * FROM [" + datos._BdOffline +
"].dbo." +
"DELETENET" +
4069 " WHERE DB = " + DB.SQLString(lcBd) +
" AND TABLA = " + DB.SQLString(lcTabla) +
" AND EJERCICIO = " + DB.SQLString(lcAny) +
4070 (!
string.IsNullOrWhiteSpace(registro._Clave) ?
" AND CLAVETAB = " + DB.SQLString(registro._Clave) :
" ") +
4071 " AND CREATED >= " + DB.SQLString(datos._FechaInicial) +
" AND CREATED <= " + DB.SQLString(datos._FechaFinal);
4073 if (DB.SQLExec(lcSql, ref tablaDatos))
4075 foreach (DataRow loRow
in tablaDatos.Rows)
4077 DataRow newRow = dtDeleteNet.NewRow();
4078 newRow[
"id"] = loRow[
"id"];
4079 newRow[
"clavetab"] = loRow[
"clavetab"];
4080 newRow[
"db"] = loRow[
"db"];
4081 newRow[
"tabla"] = loRow[
"tabla"];
4082 newRow[
"ejercicio"] = loRow[
"ejercicio"];
4083 newRow[
"orden"] = loRow[
"orden"];
4084 newRow[
"tipo"] = loRow[
"tipo"];
4085 newRow[
"sql"] = loRow[
"sql"];
4086 newRow[
"guid_id"] = loRow[
"guid_id"];
4087 newRow[
"created"] = loRow[
"created"];
4088 newRow[
"modified"] = loRow[
"modified"];
4089 newRow[
"vista"] = loRow[
"vista"];
4090 newRow[
"checksum"] = loRow[
"checksum"];
4091 dtDeleteNet.Rows.Add(newRow);
4093 if (!
string.IsNullOrWhiteSpace(registro._Compras))
4096 string lcSerie =
string.Empty;
4097 string lcQuery = loRow[
"sql"].ToString();
4098 int lnPos = lcQuery.ToUpper().IndexOf(registro._Compras);
4099 DataTable ldtDatosCompras =
new DataTable();
4104 lcQuery = lcQuery.Substring(lnPos);
4106 string[] stringSerie = lcQuery.Split(
'\'');
4107 if (stringSerie.Length >= 2)
4109 lcSerie = stringSerie[1];
4111 ComprobarTablaTemporalSQL(registro,
"COMUNES",
"COMPRAS");
4114 lcSql =
" SELECT A.* " +
4115 " FROM " + DB.SQLDatabase(
"COMUNES",
"COMPRAS") +
" A " +
4116 " WHERE A.SERIE = " + DB.SQLString(lcSerie);
4119 DB.SQLExec(lcSql, ref ldtDatosCompras);
4121 if (ldtDatosCompras != null && ldtDatosCompras.Rows.Count > 0)
4123 InsertarDatosBulkMode(ldtDatosCompras,
"[" + _cRaizDataBaseTemporal +
"COMUNES].dbo.[COMPRAS" + registro._Sufijo +
"]");
4131 if (tablaDatos != null && tablaDatos.Rows.Count > 0)
4133 dicDt.Remove(
"DELETENET");
4134 dicDt.Add(
"DELETENET", dtDeleteNet);
4139 private static void GenerarFicherosXML_Series(OfflineDatosComunicaciones datos,
ILog_comoffRepository logRepository)
4146 if (!datos._IsCentral)
4148 DataTable tablaDatos =
new DataTable();
4149 string lcSql =
string.Empty;
4151 _TextStepDetalle =
"Generando fichero Series.xml";
4152 _TextStepProgreso = _TextStepDetalle;
4153 _PorcenProgreso = IncrementarBarraProgreso();
4158 logDto.
Detalle =
"Actualizados contadores de series de documentos de la sucursal " + datos._Sucursal +
".";
4159 logRepository.
Insert(logDto);
4161 lcSql +=
" SELECT * FROM " + DB.SQLDatabase(
"GESTION",
"SERIES") +
4162 " WHERE SERIE IN ( SELECT LETRA FROM " + DB.SQLDatabase(
"OFFLINE",
"SUCURLET") +
" WHERE SUCURSAL = " + DB.SQLString(datos._Sucursal) +
" ) " +
4163 " AND MODIFIED >= " + DB.SQLString(datos._FechaInicial) +
" AND MODIFIED <= " + DB.SQLString(datos._FechaFinal) +
4164 " AND (CREATED < " + DB.SQLString(datos._FechaInicial) +
" OR CREATED > " + DB.SQLString(datos._FechaFinal) +
" ) ";
4166 lcSql +=
" UNION ALL ";
4168 lcSql +=
" SELECT * FROM " + DB.SQLDatabase(
"GESTION",
"SERIES") +
4169 " WHERE SERIE IN ( SELECT LETRA FROM " + DB.SQLDatabase(
"OFFLINE",
"SUCURLET") +
" WHERE SUCURSAL = " + DB.SQLString(datos._Sucursal) +
" ) " +
4170 " AND CREATED >= " + DB.SQLString(datos._FechaInicial) +
" AND CREATED <= " + DB.SQLString(datos._FechaFinal);
4172 DB.SQLExec(lcSql, ref tablaDatos);
4174 if (tablaDatos.Rows.Count > 0)
4176 ConvertIndividualFile(tablaDatos, TempFolderName,
"SERIES", FormatoExportacion.XML);
4181 private static string Actualizar_Tabla_Control(DataTable table,
string tcBdTabla,
string tcTablaControl,
int tnId, OfflineDatosComunicaciones datos)
4183 string lcSql =
string.Empty;
4184 string lcWhere =
string.Empty;
4185 string lcInsert =
string.Empty;
4186 string lcAux =
string.Empty;
4187 string lcAny = EW_GLOBAL._GetVariable(
"wc_any").ToString();
4188 string lcSet =
" Set ORIGEN = " + (datos._IsCentral ? DB.SQLString(
"CENTRAL") : DB.SQLString(datos._Sucursal)) +
", MODIFIED = " + DB.SQLString(DateTime.Now);
4189 string lcOrigen = (datos._IsCentral ?
"CENTRAL" : datos._Sucursal);
4191 string lcInnerJoin =
string.Empty;
4192 string lcBd =
string.Empty;
4193 string lcTabla =
string.Empty;
4195 string[] subPos = tcBdTabla.Split(
'!');
4196 if (subPos.Length == 2)
4198 lcBd = subPos[0].TrimEnd();
4199 lcTabla = subPos[1].TrimEnd();
4202 foreach (DataRow item
in table.Rows)
4223 lcWhere =
" WHERE CODIGO = " + DB.SQLString(item.Field<
string>(
"codigo"));
4225 lcInsert =
"(CODIGO, ORIGEN) " +
4227 DB.SQLString(item.Field<
string>(
"codigo")) +
", " + DB.SQLString(lcOrigen) +
")";
4229 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.CODIGO = B.CODIGO ";
4236 lcWhere =
" WHERE CODIGO = " + DB.SQLString(item.Field<
string>(
"codigo"));
4238 lcInsert =
"(CODIGO, EJERCICIO, ORIGEN) " +
4240 DB.SQLString(item.Field<
string>(
"codigo")) +
", " + DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
")";
4243 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.CODIGO = B.CODIGO ";
4248 lcWhere =
" WHERE CLIENTE = " + DB.SQLString(item.Field<
string>(
"cliente")) +
4249 " AND ARTICULO = " + DB.SQLString(item.Field<
string>(
"articulo")) +
4250 " AND FAMILIA = " + DB.SQLString(item.Field<
string>(
"familia")) +
4251 " AND SUBFAMILIA = " + DB.SQLString(item.Field<
string>(
"subfamilia")) +
4252 " AND MARCA = " + DB.SQLString(item.Field<
string>(
"marca")) +
4253 " AND ACTIVIDAD = " + DB.SQLString(item.Field<
string>(
"actividad")) +
4254 " AND TARIFA = " + DB.SQLString(item.Field<
string>(
"tarifa")) +
4255 " AND CATALOGO = " + item.Field<
int>(
"catalogo") +
4256 " AND LINEA = " + item.Field<
int>(
"linea");
4258 lcInsert =
"(CLIENTE, ARTICULO, FAMILIA, SUBFAMILIA, MARCA, ACTIVIDAD, TARIFA, CATALOGO, LINEA, ORIGEN, IDTABREL) " +
4260 DB.SQLString(item.Field<
string>(
"cliente")) +
", " + DB.SQLString(item.Field<
string>(
"articulo")) +
", " +
4261 DB.SQLString(item.Field<
string>(
"familia")) +
", " + DB.SQLString(item.Field<
string>(
"subfamilia")) +
", " +
4262 DB.SQLString(item.Field<
string>(
"marca")) +
", " + DB.SQLString(item.Field<
string>(
"actividad")) +
", " +
4263 DB.SQLString(item.Field<
string>(
"tarifa")) +
", " + item.Field<
int>(
"catalogo") +
", " +
4264 item.Field<
int>(
"linea") +
", " + DB.SQLString(lcOrigen) +
", " + DB.SQLString(tnId) +
")";
4270 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4271 " AND NUMERO = " + DB.SQLString(item.Field<
int>(
"numero")) +
4272 " AND LINEA = " + DB.SQLString(item.Field<
int>(
"linea")) +
4273 " AND EJERCICIO = " + DB.SQLString(lcAny);
4275 lcInsert =
"(EMPRESA, NUMERO, LINEA, EJERCICIO, ORIGEN, IDTABREL) " +
4277 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
int>(
"numero")) +
", " + DB.SQLString(item.Field<
int>(
"linea")) +
", " +
4278 DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
", " + DB.SQLString(tnId) +
")";
4280 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.NUMERO = B.NUMERO AND A.LINEA = B.LINEA ";
4287 lcInnerJoin +=
" INNER JOIN " + DB.SQLDatabase(
"TPV",
"TIKETS") +
" C ON B.EMPRESA = C.EMPRESA AND B.ASI = C.ASI ";
4293 lcInnerJoin +=
" INNER JOIN " + DB.SQLDatabase(
"TPV",
"REPOSI") +
" C ON B.EMPRESA = C.EMPRESA AND B.ASI = C.ASI ";
4300 lcInnerJoin +=
" INNER JOIN " + DB.SQLDatabase(
"GESTION",
"C_ALBVEN") +
" C ON B.EMPRESA = C.EMPRESA AND B.ASI = C.ASI ";
4306 lcInnerJoin +=
" INNER JOIN " + DB.SQLDatabase(
"TPV",
"COB_PAGO") +
" C ON B.EMPRESA = C.EMPRESA AND B.ASI = C.ASI ";
4312 lcInnerJoin +=
" INNER JOIN " + DB.SQLDatabase(
"GESTION",
"ENTRE_CL") +
" C ON B.EMPRESA = C.EMPRESA AND B.ASI = C.ASI ";
4317 lcInnerJoin +=
" INNER JOIN " + DB.SQLDatabase(
"GESTION",
"C_ALBCOM") +
" C ON B.EMPRESA = C.EMPRESA AND B.ASI = C.ASI ";
4322 lcInnerJoin +=
" INNER JOIN " + DB.SQLDatabase(
"GESTION",
"C_TRANSDUA") +
" C ON B.EMPRESA = C.EMPRESA AND B.ASI = C.ASI_TRANS ";
4327 lcInnerJoin +=
" INNER JOIN " + DB.SQLDatabase(
"GESTION",
"C_TRANSDUA") +
" C ON B.EMPRESA = C.EMPRESA AND B.ASI = C.ASI_DUA ";
4336 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4337 " AND ARTICULO = " + DB.SQLString(item.Field<
string>(
"articulo"));
4339 lcInsert =
"(EMPRESA, ARTICULO, ORIGEN) " +
4341 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
string>(
"articulo")) +
", " +
4342 DB.SQLString(lcOrigen) +
")";
4344 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.ARTICULO = B.ARTICULO ";
4350 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4351 " AND CODIGO = " + DB.SQLString(item.Field<
string>(
"codigo"));
4353 lcInsert =
"(EMPRESA, CODIGO, ORIGEN) " +
4355 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
string>(
"codigo")) +
", " +
4356 DB.SQLString(lcOrigen) +
")";
4358 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.CODIGO = B.CODIGO ";
4364 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4365 " AND CODIGO = " + DB.SQLString(item.Field<
string>(
"codigo"));
4367 lcInsert =
"(EMPRESA, CODIGO, EJERCICIO, ORIGEN) " +
4369 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
string>(
"codigo")) +
", " +
4370 DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
")";
4372 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.CODIGO = B.CODIGO ";
4378 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4379 " AND CODIGO = " + DB.SQLString(item.Field<
string>(
"codigo")) +
4380 " AND EJERCICIO = " + DB.SQLString(lcAny);
4382 lcInsert =
"(EMPRESA, CODIGO, EJERCICIO, ORIGEN) " +
4384 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
string>(
"codigo")) +
", " +
4385 DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
")";
4387 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.CODIGO = B.CODIGO ";
4393 lcWhere =
" WHERE CONIRPF = " + DB.SQLString(item.Field<
string>(
"conirpf")) +
4394 " AND CONGASING = " + DB.SQLString(item.Field<
string>(
"congasing")) +
4395 " AND EJERCICIO = " + DB.SQLString(lcAny);
4397 lcInsert =
"(CONIRPF, CONGASING, EJERCICIO, ORIGEN) " +
4399 DB.SQLString(item.Field<
string>(
"conirpf")) +
", " + DB.SQLString(item.Field<
string>(
"congasing")) +
", " +
4400 DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
")";
4402 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.CONIRPF = B.CONIRPF AND A.CONGASING = B.CONGASING ";
4408 lcWhere =
" WHERE ARTICULO = " + DB.SQLString(item.Field<
string>(
"articulo")) +
4409 " AND CLIENTE = " + DB.SQLString(item.Field<
string>(
"cliente")) +
4410 " AND LINEA = " + DB.SQLString(item.Field<
int>(
"linea")) +
4411 " AND EJERCICIO = " + DB.SQLString(lcAny);
4413 lcInsert =
"(ARTICULO, CLIENTE, LINEA, EJERCICIO, ORIGEN) " +
4415 DB.SQLString(item.Field<
string>(
"articulo")) +
", " + DB.SQLString(item.Field<
string>(
"cliente")) +
", " +
4416 DB.SQLString(item.Field<
int>(
"linea")) +
", " + DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
")";
4418 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.ARTICULO = B.ARTICULO AND A.CLIENTE = B.CLIENTE AND A.LINEA = B.LINEA ";
4424 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4425 " AND PERIODO = " + DB.SQLString(item.Field<
int>(
"periodo")) +
4426 " AND FACTURA = " + DB.SQLString(item.Field<
string>(
"factura")) +
4427 " AND ORDEN = " + DB.SQLString(item.Field<
int>(
"orden")) +
4428 " AND IMPAGADO = " + DB.SQLString(item.Field<
int>(
"impagado")) +
4429 " AND PENDIENTE = " + DB.SQLString(item.Field<decimal>(
"pendiente"));
4431 lcInsert =
"(EMPRESA, PERIODO, FACTURA, ORDEN, IMPAGADO, PENDIENTE, ORIGEN, IDTABREL) " +
4433 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
int>(
"periodo")) +
", " +
4434 DB.SQLString(item.Field<
string>(
"factura")) +
", " + DB.SQLString(item.Field<
int>(
"orden")) +
", " +
4435 DB.SQLString(item.Field<
int>(
"impagado")) +
", " + DB.SQLString(item.Field<decimal>(
"pendiente")) +
", " +
4436 DB.SQLString(lcOrigen) +
", " + DB.SQLString(tnId) +
")";
4438 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.PERIODO = B.PERIODO " +
4439 " AND A.FACTURA = B.FACTURA AND A.ORDEN = B.ORDEN AND A.IMPAGADO = B.IMPAGADO AND A.PENDIENTE = B.PENDIENTE ";
4445 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4446 " AND YEAR(EMISION) = " + DB.SQLString(item.Field<
int>(
"periodo")) +
4447 " AND PROVEEDOR = " + DB.SQLString(item.Field<
string>(
"proveedor")) +
4448 " AND FACTURA = " + DB.SQLString(item.Field<
string>(
"factura")) +
4449 " AND NUMEREB = " + DB.SQLString(item.Field<
int>(
"numereb")) +
4450 " AND PENDIENTE = " + DB.SQLString(item.Field<
int>(
"pendiente"));
4452 lcInsert =
"(EMPRESA, EMISION, PROVEEDOR, FACTURA, NUMEREB, PENDIENTE, ORIGEN, IDTABREL) " +
4454 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<DateTime>(
"emision")) +
", " +
4455 DB.SQLString(item.Field<
string>(
"proveedor")) +
", " + DB.SQLString(item.Field<
string>(
"factura")) +
", " +
4456 DB.SQLString(item.Field<
int>(
"numereb")) +
", " + DB.SQLString(item.Field<
int>(
"pendiente")) +
", " +
4457 DB.SQLString(lcOrigen) +
", " + DB.SQLString(tnId) +
")";
4459 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.EMISION = B.EMISION " +
4460 " AND A.PROVEEDOR = B.PROVEEDOR AND A.FACTURA = B.FACTURA AND A.NUMEREB = B.NUMEREB AND A.PENDIENTE = B.PENDIENTE ";
4466 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4467 " AND FECHA = " + DB.SQLString(item.Field<DateTime>(
"fecha")) +
4468 " AND ALMACEN = " + DB.SQLString(item.Field<
string>(
"almacen")) +
4469 " AND ARTICULO = " + DB.SQLString(item.Field<
string>(
"articulo")) +
4470 " AND LINIA = " + DB.SQLString(item.Field<
int>(
"linia")) +
4471 " AND EJERCICIO = " + DB.SQLString(lcAny);
4473 lcInsert =
"(EMPRESA, FECHA, ALMACEN, ARTICULO, LINIA, EJERCICIO, ORIGEN) " +
4475 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<DateTime>(
"fecha")) +
", " +
4476 DB.SQLString(item.Field<
string>(
"almacen")) +
", " + DB.SQLString(item.Field<
string>(
"articulo")) +
", " +
4477 DB.SQLString(item.Field<
int>(
"linia")) +
", " + DB.SQLString(lcAny) +
", " +
4478 DB.SQLString(lcOrigen) +
")";
4480 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.FECHA = B.FECHA " +
4481 " AND A.ALMACEN = B.ALMACEN AND A.ARTICULO = B.ARTICULO AND A.LINIA = B.LINIA ";
4488 lcWhere =
" WHERE CODIGO = " + DB.SQLString(item.Field<
string>(
"codigo")) +
" AND EJERCICIO = " + DB.SQLString(lcAny);
4490 lcInsert =
"(CODIGO, EJERCICIO, ORIGEN, IDTABREL) " +
4492 DB.SQLString(item.Field<
string>(
"codigo")) +
", " + DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
", " + DB.SQLString(tnId) +
")";
4495 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.CODIGO = B.CODIGO ";
4504 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4505 " AND NUMERO = " + DB.SQLString(item.Field<
string>(
"numero")) +
4506 " AND LETRA = " + DB.SQLString(item.Field<
string>(
"letra")) +
4507 " AND EJERCICIO = " + DB.SQLString(lcAny);
4509 if (lcTabla ==
"C_ALBVEN")
4511 lcInsert =
"(EMPRESA, NUMERO, LETRA, EJERCICIO, ORIGEN, IDTABREL) " +
4513 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
string>(
"numero")) +
", " +
4514 DB.SQLString(item.Field<
string>(
"letra")) +
", " + DB.SQLString(lcAny) +
", " +
4515 DB.SQLString(lcOrigen) +
", " + DB.SQLString(tnId) +
")";
4519 lcInsert =
"(EMPRESA, NUMERO, LETRA, EJERCICIO, ORIGEN) " +
4521 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
string>(
"numero")) +
", " +
4522 DB.SQLString(item.Field<
string>(
"letra")) +
", " + DB.SQLString(lcAny) +
", " +
4523 DB.SQLString(lcOrigen) +
")";
4526 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.NUMERO = B.NUMERO AND A.LETRA = B.LETRA ";
4539 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4540 " AND NUMERO = " + DB.SQLString(item.Field<
string>(
"numero")) +
4541 " AND EJERCICIO = " + DB.SQLString(lcAny);
4543 if (lcTabla ==
"C_FACTUVEN")
4545 lcInsert =
"(EMPRESA, NUMERO, EJERCICIO, ORIGEN, IDTABREL) " +
4547 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
string>(
"numero")) +
", " +
4548 DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
", " + DB.SQLString(tnId) +
")";
4552 lcInsert =
"(EMPRESA, NUMERO, EJERCICIO, ORIGEN) " +
4554 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
string>(
"numero")) +
", " +
4555 DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
")";
4558 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.NUMERO = B.NUMERO ";
4560 if (lcTabla ==
"C_FACTUVEN")
4562 lcInnerJoin +=
" INNER JOIN " + DB.SQLDatabase(
"GESTION",
"C_ALBVEN") +
" C ON B.EMPRESA = C.EMPRESA AND B.NUMERO = C.FACTURA ";
4571 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4572 " AND NUMERO = " + DB.SQLString(item.Field<
string>(
"numero")) +
4573 " AND PROVEEDOR = " + DB.SQLString(item.Field<
string>(
"proveedor")) +
4574 " AND EJERCICIO = " + DB.SQLString(lcAny);
4576 lcInsert =
"(EMPRESA, NUMERO, PROVEEDOR, EJERCICIO, ORIGEN) " +
4578 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
string>(
"numero")) +
", " +
4579 DB.SQLString(item.Field<
string>(
"proveedor")) +
", " + DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
")";
4581 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.NUMERO = B.NUMERO AND A.PROVEEDOR = B.PROVEEDOR ";
4583 if (lcTabla ==
"C_FACTUCOM")
4585 lcInnerJoin +=
" INNER JOIN " + DB.SQLDatabase(
"GESTION",
"C_ALBCOM") +
" C ON B.EMPRESA = C.EMPRESA AND B.NUMERO = C.FACTURA AND B.PROVEEDOR = C.PROVEEDOR ";
4592 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4593 " AND NUMERO = " + DB.SQLString(item.Field<
int>(
"numero"));
4595 lcInsert =
"(EMPRESA, NUMERO, EJERCICIO, ORIGEN) " +
4597 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
int>(
"numero")) +
", " +
4598 DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
")";
4600 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.NUMERO = B.NUMERO ";
4606 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4607 " AND NUMERO = " + DB.SQLString(item.Field<
string>(
"numero"));
4609 lcInsert =
"(EMPRESA, NUMERO, ORIGEN) " +
4611 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
string>(
"numero")) +
", " +
4612 DB.SQLString(lcOrigen) +
")";
4614 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.NUMERO = B.NUMERO ";
4620 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4621 " AND NUMERO = " + DB.SQLString(item.Field<
string>(
"numero")) +
4622 " AND LINIA = " + DB.SQLString(item.Field<
int>(
"linea")) +
4623 " AND EJERCICIO = " + DB.SQLString(lcAny);
4625 lcInsert =
"(EMPRESA, NUMERO, LINIA, EJERCICIO, ORIGEN) " +
4627 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
string>(
"numero")) +
", " +
4628 DB.SQLString(item.Field<
int>(
"linea")) +
", " + DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
")";
4630 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.NUMERO = B.NUMERO AND A.LINIA = B.LINEA ";
4636 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4637 " AND ALMACEN = " + DB.SQLString(item.Field<
string>(
"almacen")) +
4638 " AND FECHA = " + DB.SQLString(item.Field<DateTime>(
"fecha")) +
4639 " AND DOCUMENTO = " + DB.SQLString(item.Field<
string>(
"documento")) +
4640 " AND LINIA = " + DB.SQLString(item.Field<
int>(
"linia")) +
4641 " AND EJERCICIO = " + DB.SQLString(lcAny);
4643 lcInsert =
"(EMPRESA, ALMACEN, FECHA, LINIA, DOCUMENTO, EJERCICIO, ORIGEN) " +
4645 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
string>(
"almacen")) +
", " +
4646 DB.SQLString(item.Field<DateTime>(
"fecha")) +
", " + DB.SQLString(item.Field<
int>(
"linia")) +
", " + DB.SQLString(item.Field<
string>(
"documento")) +
", " +
4647 DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
")";
4649 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.ALMACEN = B.ALMACEN " +
4650 " AND A.FECHA = B.FECHA AND A.DOCUMENTO = B.DOCUMENTO AND A.LINIA = B.LINIA ";
4656 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4657 " AND LETRA = " + DB.SQLString(item.Field<
string>(
"letra")) +
4658 " AND TICKET = " + DB.SQLString(item.Field<
string>(
"ticket")) +
4659 " AND ORDEN = " + DB.SQLString(item.Field<
int>(
"orden"));
4661 lcInsert =
"(EMPRESA, LETRA, TICKET, ORDEN, EJERCICIO, ORIGEN) " +
4663 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
string>(
"letra")) +
", " +
4664 DB.SQLString(item.Field<
string>(
"ticket")) +
", " + DB.SQLString(item.Field<
int>(
"orden")) +
", " +
4665 DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
")";
4667 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.LETRA = B.LETRA AND A.TICKET = B.TICKET " +
4668 " AND A.ORDEN = B.ORDEN ";
4674 lcAux =
", ARQUEO = " + DB.SQLString(item.Field<
int>(
"arqueo"));
4676 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4677 " AND CAJA = " + DB.SQLString(item.Field<
string>(
"caja")) +
4678 " AND MONEDA = " + DB.SQLString(item.Field<
string>(
"moneda")) +
4679 " AND FECHA = " + DB.SQLString(item.Field<DateTime>(
"fecha")) +
4680 " AND OPERARIO = " + DB.SQLString(item.Field<
string>(
"operario")) +
4682 " AND LINEA = " + DB.SQLString(item.Field<
int>(
"linea"));
4684 lcInsert =
"(EMPRESA, CAJA, MONEDA, FECHA, OPERARIO, ARQUEO, LINEA, ORIGEN) " +
4686 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
string>(
"caja")) +
", " +
4687 DB.SQLString(item.Field<
string>(
"moneda")) +
", " + DB.SQLString(item.Field<DateTime>(
"fecha")) +
", " +
4688 DB.SQLString(item.Field<
string>(
"operario")) +
", " + DB.SQLString(item.Field<
int>(
"arqueo")) +
", " +
4689 DB.SQLString(item.Field<
int>(
"linea")) +
", " + DB.SQLString(lcOrigen) +
")";
4691 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.CAJA = B.CAJA AND A.MONEDA = B.MONEDA " +
4692 " AND A.FECHA = B.FECHA AND A.OPERARIO = B.OPERARIO AND A.LINEA = B.LINEA ";
4698 lcAux =
", ARQUEO = " + DB.SQLString(item.Field<
int>(
"arqueo"));
4700 lcWhere =
" WHERE EMPRESA = " + DB.SQLString(item.Field<
string>(
"empresa")) +
4701 " AND CAJA = " + DB.SQLString(item.Field<
string>(
"caja")) +
4702 " AND FECHA = " + DB.SQLString(item.Field<DateTime>(
"fecha")) +
4703 " AND OPERARIO = " + DB.SQLString(item.Field<
string>(
"operario")) +
4705 " AND LINEA = " + DB.SQLString(item.Field<
int>(
"linea"));
4707 lcInsert =
"(EMPRESA, CAJA, FECHA, OPERARIO, ARQUEO, LINEA, ORIGEN) " +
4709 DB.SQLString(item.Field<
string>(
"empresa")) +
", " + DB.SQLString(item.Field<
string>(
"caja")) +
", " +
4710 DB.SQLString(item.Field<DateTime>(
"fecha")) +
", " + DB.SQLString(item.Field<
string>(
"operario")) +
", " +
4711 DB.SQLString(item.Field<
int>(
"arqueo")) +
", " + DB.SQLString(item.Field<
int>(
"linea")) +
", " + DB.SQLString(lcOrigen) +
")";
4713 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.EMPRESA = B.EMPRESA AND A.CAJA = B.CAJA " +
4714 " AND A.FECHA = B.FECHA AND A.OPERARIO = B.OPERARIO AND A.LINEA = B.LINEA ";
4720 lcWhere =
" WHERE CODIGO = " + DB.SQLString(item.Field<
int>(
"codigo")) +
4721 " AND EJERCICIO = " + DB.SQLString(lcAny);
4723 lcInsert =
"(CODIGO, EJERCICIO, ORIGEN) " +
4725 DB.SQLString(item.Field<
int>(
"codigo")) +
", " +
4726 DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
")";
4728 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.CODIGO = B.CODIGO ";
4735 if (lcBd ==
"LOTES" && lcTabla ==
"MCAMPOS")
4737 lcWhere =
" WHERE CODIGO = " + DB.SQLString(item.Field<
string>(
"codigo"));
4741 lcWhere =
" WHERE CODIGO = " + DB.SQLString(item.Field<
string>(
"codigo")) +
" AND EJERCICIO = " + DB.SQLString(lcAny);
4744 lcInsert =
"(CODIGO, EJERCICIO, ORIGEN) " +
4746 DB.SQLString(item.Field<
string>(
"codigo")) +
", " + DB.SQLString(lcAny) +
", " + DB.SQLString(lcOrigen) +
")";
4749 lcInnerJoin =
" INNER JOIN " + DB.SQLDatabase(lcBd, lcTabla) +
" B ON A.CODIGO = B.CODIGO ";
4754 lcSql =
" IF EXISTS " + Environment.NewLine +
4755 " ( SELECT ORIGEN FROM " + DB.SQLDatabase(
"OFFLINE", tcTablaControl) + lcWhere +
" ) " + Environment.NewLine +
4756 " BEGIN " + Environment.NewLine +
4757 " Update " + DB.SQLDatabase(
"OFFLINE", tcTablaControl) + lcSet + lcAux + lcWhere + Environment.NewLine +
4758 " END " + Environment.NewLine +
4759 " ELSE " + Environment.NewLine +
4760 " BEGIN" + Environment.NewLine +
4761 "Insert Into " + DB.SQLDatabase(
"OFFLINE", tcTablaControl) + lcInsert +
4770 private static bool Subir_Fichero_DatosEnvio(OfflineDatosComunicaciones datos,
string cTipoEnvio,
ILog_comoffRepository logRepository)
4774 string lcTipoEnvio = (cTipoEnvio ==
"i" ?
"la carga inicial " :
"envío ");
4776 string lcBaseFicheroZip = _cTempFileName + cTipoEnvio;
4779 if (!
string.IsNullOrWhiteSpace(lcBaseFicheroZip) && Directory.Exists(datos._PathFolderInicial))
4781 _TextStepDetalle =
"Subiendo el fichero de " + lcTipoEnvio + lcBaseFicheroZip +
".zip ";
4782 _TextStepProgreso = _TextStepDetalle;
4783 _PorcenProgreso = IncrementarBarraProgreso();
4785 clsOffLine utilsOffline =
new clsOffLine();
4786 string pathArchivoComprimido = utilsOffline.Fichero_Comprimir(datos._PathFolderInicial, lcBaseFicheroZip);
4793 if (
string.IsNullOrWhiteSpace(pathArchivoComprimido))
4796 logDto.
Detalle =
"El fichero de " + lcTipoEnvio + lcBaseFicheroZip +
".zip no se ha podido generar.";
4797 logRepository.
Insert(logDto);
4802 logDto.
Detalle =
"El fichero de " + lcTipoEnvio + lcBaseFicheroZip +
".zip se ha generado con éxito.";
4803 logRepository.
Insert(logDto);
4805 string lcZipFile = Path.Combine(datos._PathFolderInicial, pathArchivoComprimido);
4806 lcZipFile = Path.Combine(lcZipFile, lcBaseFicheroZip);
4807 lcZipFile = lcZipFile +
".zip";
4809 long uploadedFileSize = 0;
4811 var carpetaserv =
"SUCURNET" + datos._Sucursal +
"/";
4814 llOk = UploadManager.Subir_Fichero(lcZipFile,
"", carpetaserv, datos._IdConf, ref uploadedFileSize);
4817 string lcDescrip = (conexion == 0 ?
"FTP" :
"OneDrive");
4822 logDto.
Detalle =
"El fichero de " + lcTipoEnvio + lcBaseFicheroZip +
".zip se ha subido a la carpeta " + carpetaserv +
" del " + lcDescrip +
".";
4827 logDto.
Detalle =
"No se ha podido subir fichero de " + lcTipoEnvio + lcBaseFicheroZip +
".zip a carpeta " + lcDescrip +
" , revise si el usuario " + lcDescrip +
" configurado tiene permisos en la carpeta indicada.";
4830 logRepository.
Insert(logDto);
4838 private static int TipoConexion(OfflineDatosComunicaciones datos)
4840 int tipoConexion = 0;
4842 DataTable ldtDatos =
new DataTable();
4843 DB.SQLExec(
"SELECT CONEXION FROM " + DB.SQLDatabase(
"OFFLINE",
"MULTCONF") +
" WHERE IDCONF = " + DB.SQLString(datos._IdConf), ref ldtDatos);
4845 if (ldtDatos != null || ldtDatos.Rows.Count > 0)
4847 return Convert.ToInt16(ldtDatos.Rows[0][
"conexion"]);
4850 return tipoConexion;
4853 private static bool Subir_Fichero_Configuracion(OfflineDatosComunicaciones datos,
ILog_comoffRepository logRepository)
4855 string lcBaseFicheroZip =
"configura_offline";
4858 if (!
string.IsNullOrWhiteSpace(lcBaseFicheroZip) && Directory.Exists(datos._PathFolderInicial))
4860 clsOffLine utilsOffline =
new clsOffLine();
4861 string pathArchivoComprimido = utilsOffline.Fichero_Comprimir(datos._PathFolderInicial, lcBaseFicheroZip);
4865 if (
string.IsNullOrWhiteSpace(pathArchivoComprimido))
4868 logDto.
Detalle =
"El fichero de configuración offline " + lcBaseFicheroZip +
".zip no se ha podido generar.";
4869 logRepository.
Insert(logDto);
4874 logDto.
Detalle =
"El fichero de configuración offline " + lcBaseFicheroZip +
".zip se ha generado con éxito.";
4875 logRepository.
Insert(logDto);
4877 string lcZipFile = Path.Combine(datos._PathFolderInicial, pathArchivoComprimido);
4878 lcZipFile = Path.Combine(lcZipFile, lcBaseFicheroZip);
4879 lcZipFile = lcZipFile +
".zip";
4881 long uploadedFileSize = 0;
4882 var carpetaserv =
"/";
4884 llOk = UploadManager.Subir_Fichero(lcZipFile,
"", carpetaserv, datos._IdConf, ref uploadedFileSize);
4887 string lcDescrip = (conexion == 0 ?
"FTP" :
"OneDrive");
4892 logDto.
Detalle =
"El fichero de configuración offline " + lcBaseFicheroZip +
".zip se ha subido a la carpeta " + carpetaserv +
" del " + lcDescrip +
".";
4897 logDto.
Detalle =
"No se ha podido subir fichero de configuración offline " + lcBaseFicheroZip +
".zip a carpeta FTP, revise si el usuario FTP configurado tiene permisos en la carpeta indicada.";
4900 logRepository.
Insert(logDto);
4908 private static void Procesar_Imagenes_Envio(
string tcNombre, OfflineDatosComunicaciones datos, DataTable tdtImagenes,
ILog_comoffRepository logRepository)
4910 if (tdtImagenes.Rows.Count > 0)
4912 _TextStepDetalle =
"Procesando imagenes a enviar";
4913 _TextStepProgreso = _TextStepDetalle;
4914 _PorcenProgreso = IncrementarBarraProgreso();
4916 DataTable _ldtImgOff =
new DataTable();
4919 DB.SQLExec(
"SELECT * FROM " + DB.SQLDatabase(
"OFFLINE",
"IMAGENES") +
" ORDER BY TIPO, NOMBRE ", ref _ldtImgOff);
4923 if (_ldtImgOff.Rows.Count > 0)
4925 lnId = Convert.ToInt32(_ldtImgOff.Compute(
"MAX(ID)",
""));
4928 DB.SQLExec(
"SELECT * FROM " + DB.SQLDatabase(
"OFFLINE",
"IMAGENES") +
" WHERE SUCURSAL = " + DB.SQLString(datos._Sucursal) +
" ORDER BY TIPO, NOMBRE ", ref _ldtImgOff);
4933 foreach (DataRow item
in tdtImagenes.Rows)
4935 int lnTipo = item.Field<
int>(
"Tipo");
4936 string lcRutaImagen = Path.GetDirectoryName(item.Field<
string>(
"Imagen"));
4937 string lcNombreImagen = Path.GetFileName(item.Field<
string>(
"Imagen"));
4939 string lcBuscar =
"tipo = " + lnTipo.ToString().TrimEnd() +
" and nombre = '" + lcNombreImagen +
"'";
4941 DateTime ldData = DateTime.Today;
4943 bool llAfegir =
false;
4947 if (!
string.IsNullOrWhiteSpace(lcRutaImagen) && lcRutaImagen.ToLower().IndexOf(datos._IniServidor.ToLower()) < 0)
4950 logDto.
Detalle =
"La imagen asociada al código '" + item.Field<
string>(
"codigo") +
"' de la tabla '" + Definicion_Tipo_Imagen(lnTipo) +
"' no está almacenada en una carpeta dentro del servidor de Sage50. (" + lcRutaImagen +
"\\" + lcNombreImagen +
")";
4951 logRepository.
Insert(logDto);
4956 string lcOrigen = (
string.IsNullOrWhiteSpace(lcRutaImagen) ? datos._IniServidor +
"COMUNES\\FOTOS\\" : lcRutaImagen +
"\\") + lcNombreImagen;
4958 if (!File.Exists(lcOrigen))
4961 logDto.
Detalle =
"La imagen " + lcNombreImagen +
" no está almacenada en la carpeta especificada del servidor de Sage50.";
4962 logRepository.
Insert(logDto);
4968 string lcNewControl =
"";
4970 var plainTextBytes = Encoding.UTF8.GetBytes(lcOrigen);
4971 string lcValor =
System.Convert.ToBase64String(plainTextBytes);
4975 DataRow[] ldrs = _ldtImgOff.Select(lcBuscar);
4977 DataTable _curMd5 =
new DataTable();
4978 DB.SQLExec(
"select master.dbo.md5('" + lcValor +
"') as control", ref _curMd5);
4980 if (_curMd5 != null && _curMd5.Rows.Count > 0)
4982 lcNewControl = _curMd5.Rows[0][
"control"].ToString();
4985 if (ldrs.Length == 0)
4992 string lcRutaDest = lcRutaImagen.Replace(datos._IniServidor,
"");
4994 DataRow newRow = _ldtImgOff.NewRow();
4995 newRow[
"id"] = lnId;
4996 newRow[
"nombre"] = lcNombreImagen;
4997 newRow[
"control"] = lcNewControl;
4998 newRow[
"ruta"] = lcRutaDest;
4999 newRow[
"tipo"] = lnTipo;
5000 newRow[
"fecha"] = ldData;
5001 newRow[
"sucursal"] = datos._Sucursal;
5002 _ldtImgOff.Rows.Add(newRow);
5005 DB.SQLExec(
"INSERT INTO " + DB.SQLDatabase(
"OFFLINE",
"IMAGENES") +
" (id,nombre,control,ruta,tipo,fecha,sucursal) " +
5006 " VALUES (" + DB.SQLString(lnId) +
", " + DB.SQLString(lcNombreImagen) +
", " + DB.SQLString(lcNewControl) +
", " +
5007 DB.SQLString(lcRutaDest) +
", " + DB.SQLString(lnTipo) +
", " + DB.SQLString(ldData) +
", " + DB.SQLString(datos._Sucursal) +
")");
5012 string lcControl = ldrs[0][
"Control"].ToString();
5014 if (lcControl != lcNewControl)
5018 ldrs[0][
"Control"] = lcNewControl;
5019 ldrs[0][
"Fecha"] = ldData;
5022 DB.SQLExec(
"UPDATE " + DB.SQLDatabase(
"OFFLINE",
"IMAGENES") +
" SET control = " + DB.SQLString(lcNewControl) +
", fecha = " + DB.SQLString(ldData) +
5023 " WHERE tipo = " + DB.SQLString(lnTipo) +
" AND nombre = " + DB.SQLString(lcNombreImagen) +
" AND sucursal = " + DB.SQLString(datos._Sucursal));
5036 string lcDestino = Path.Combine(datos._PathFolderInicial,
"IMAGENES");
5038 if (!Directory.Exists(lcDestino))
5039 Directory.CreateDirectory(lcDestino);
5041 lcDestino = Path.Combine(lcDestino, lcNombreImagen);
5045 File.Copy(lcOrigen, lcDestino,
true);
5047 string lcTipoDato = clsOfflineUtils.ObtenerTipoDatoImagen(lnTipo);
5050 logDto.
Detalle =
"Imagen en la carpeta especificada del servidor de Sage50. (" + lcNombreImagen +
")";
5051 logRepository.
Insert(logDto);
5056 logDto.
Detalle =
"No ha sido posible copiar la imagen " + lcNombreImagen +
".";
5057 logRepository.
Insert(logDto);
5063 ConvertIndividualFile(_ldtImgOff, Path.Combine(datos._PathFolderInicial,
"IMAGENES"),
"IMAGENES", FormatoExportacion.XML);
5067 private static void Seleccionar_Imagenes_Envio(
bool tlImagenes, Dictionary<string, object> tablaSucursales,
string lcTabla, OfflineDatosComunicaciones datos, ref DataTable ldtImagenes)
5069 if (tlImagenes && tablaSucursales.ContainsKey(
"env_foto") && Convert.ToBoolean(tablaSucursales[
"env_foto"]))
5071 DataTable temporal =
new DataTable();
5072 string lcSql =
string.Empty;
5078 lcSql =
"SELECT 1 as tipo, LTRIM(RTRIM(b.foto)) as imagen, b.codigo FROM " + DB.SQLDatabase(
"GESTION", lcTabla) +
" b WHERE LTRIM(RTRIM(b.foto)) != '' ";
5082 lcSql =
"SELECT 2 as tipo, LTRIM(RTRIM(b.foto)) as imagen, b.codigo FROM " + DB.SQLDatabase(
"GESTION", lcTabla) +
" b WHERE LTRIM(RTRIM(b.foto)) != '' ";
5086 lcSql =
"SELECT 3 as tipo, LTRIM(RTRIM(b.imagen)) as imagen, b.articulo as codigo FROM " + DB.SQLDatabase(
"GESTION", lcTabla) +
" b WHERE LTRIM(RTRIM(b.imagen)) != '' ";
5089 if (datos._EnvioArticulos)
5091 lcSql += Envio_Articulos_Sucursal(datos, lcTabla);
5097 lcSql =
"SELECT 4 as tipo, LTRIM(RTRIM(b.imagen)) as imagen, b.codigo FROM " + DB.SQLDatabase(
"COMUNES", lcTabla) +
" b WHERE LTRIM(RTRIM(b.imagen)) != '' ";
5101 lcSql =
"SELECT 5 as tipo, LTRIM(RTRIM(b.foto)) as imagen, b.codigo FROM " + DB.SQLDatabase(
"GESTION", lcTabla) +
" b WHERE LTRIM(RTRIM(b.foto)) != '' ";
5105 lcSql =
"SELECT 6 as tipo, LTRIM(RTRIM(b.foto)) as imagen, b.codigo FROM " + DB.SQLDatabase(
"COMUNES", lcTabla) +
" b WHERE LTRIM(RTRIM(b.foto)) != '' ";
5109 lcSql =
"SELECT 7 as tipo, LTRIM(RTRIM(b.foto)) as imagen, b.codigo FROM " + DB.SQLDatabase(
"GESTION", lcTabla) +
" b WHERE LTRIM(RTRIM(b.foto)) != '' ";
5113 lcSql =
"SELECT 8 as tipo, LTRIM(RTRIM(b.foto)) as imagen, b.codigo FROM " + DB.SQLDatabase(
"GESTION", lcTabla) +
" b WHERE LTRIM(RTRIM(b.foto)) != '' ";
5117 lcSql =
"SELECT 9 as tipo, LTRIM(RTRIM(b.foto)) as imagen, b.codigo FROM " + DB.SQLDatabase(
"COMUNES", lcTabla) +
" b WHERE LTRIM(RTRIM(b.foto)) != '' ";
5121 if (DB.SQLExec(lcSql, ref temporal))
5123 if (ldtImagenes.Rows.Count == 0)
5125 ldtImagenes = temporal;
5129 DBfunctions.SQLUnionDatatable(ref ldtImagenes, temporal);
5135 private static bool Revisar_Imagenes_Datos(
bool tlImagenes, Dictionary<string, object> tablaSucursales,
string lcTabla, OfflineDatosComunicaciones datos, ref DataTable ldtDatos)
5137 if (ldtDatos.Rows.Count == 0)
5142 if (!tlImagenes || (tablaSucursales.ContainsKey(
"env_foto") && !Convert.ToBoolean(tablaSucursales[
"env_foto"])))
5144 DataTable temporal =
new DataTable();
5145 string lcSql =
string.Empty;
5157 foreach (DataRow item
in ldtDatos.Rows)
5159 item[
"foto"] =
string.Empty;
5164 foreach (DataRow item
in ldtDatos.Rows)
5166 item[
"imagen"] =
string.Empty;
5172 ldtDatos.AcceptChanges();
5181 private static DataTable obtenerDatosEnvio(Dictionary<int, bool> prioridades,
string cTipoEnvio)
5183 string lcSql =
string.Empty;
5184 string lcWhereCentral =
string.Empty;
5185 string lcWhereSucur =
string.Empty;
5186 string lcOrCentral =
string.Empty;
5187 string lcOrSucur =
string.Empty;
5189 foreach (KeyValuePair<int, bool> item
in prioridades)
5193 lcWhereCentral += lcOrCentral +
" ID = " + DB.SQLString(item.Key);
5194 lcOrCentral =
" OR ";
5198 lcWhereSucur += lcOrSucur +
" ID = " + DB.SQLString(item.Key);
5204 if (cTipoEnvio ==
"e" && (prioridades.ContainsKey(159) && !prioridades.ContainsKey(292)))
5206 if (!
string.IsNullOrEmpty(lcWhereCentral))
5208 lcWhereCentral += lcOrCentral +
" ID = " + DB.SQLString(292);
5209 lcOrCentral =
" OR ";
5213 lcWhereSucur += lcOrSucur +
" ID = " + DB.SQLString(292);
5218 if (!
string.IsNullOrWhiteSpace(lcOrCentral))
5220 lcWhereCentral =
" AND (" + lcWhereCentral +
")";
5224 lcWhereCentral =
" AND ( 1=2 )";
5227 if (!
string.IsNullOrWhiteSpace(lcOrSucur))
5229 lcWhereSucur =
" AND (" + lcWhereSucur +
")";
5233 lcWhereSucur =
" AND ( 1=2 )";
5239 string lcCampoWhere = (cTipoEnvio ==
"i" ?
"visicarga" :
"visible");
5241 DataTable TabTmp =
new DataTable();
5244 lcSql +=
" SELECT clave, (CASE WHEN secundaria = '' THEN principal ELSE secundaria END) as nombre, " +
5245 " empresa, id, idgrupo, principal, cast(1 as bit) as prioridad, visicond, UPPER(nombre) as titulo, tipotabla, " +
5246 " cast(condenv as varchar(max)) as condenv, cast(condsecun as varchar(max)) as condsecun, " +
5247 " asientos, otrasien, eos, iva_exen, ivasopor, ivareper, retsopor, retreper, compras, relacion, empresecun, visible, condctrl, tablactrl, relactrl " + Environment.NewLine +
5248 " FROM " + DB.SQLDatabase(
"OFFLINE",
"TABRELNET") + Environment.NewLine +
5250 " AND clave IN (SELECT DISTINCT CLAVE FROM " + DB.SQLDatabase(
"OFFLINE",
"TABRELNET") +
" WHERE " + lcCampoWhere +
" = 1 " + lcWhereCentral +
") " + Environment.NewLine;
5252 lcSql +=
" UNION ALL " + Environment.NewLine;
5254 lcSql +=
" SELECT clave, (CASE WHEN secundaria = '' THEN principal ELSE secundaria END) as nombre, " +
5255 " empresa, id, idgrupo,principal, cast(0 as bit) as prioridad, visicond, UPPER(nombre) as titulo, tipotabla, " +
5256 " cast(condenv as varchar(max)) as condenv, cast(condsecun as varchar(max)) as condsecun, " +
5257 " asientos, otrasien, eos, iva_exen, ivasopor, ivareper, retsopor, retreper, compras, relacion, empresecun, visible, condctrl, tablactrl, relactrl " + Environment.NewLine +
5258 " FROM " + DB.SQLDatabase(
"OFFLINE",
"TABRELNET") + Environment.NewLine +
5260 " AND clave IN (SELECT DISTINCT CLAVE FROM " + DB.SQLDatabase(
"OFFLINE",
"TABRELNET") +
" WHERE " + lcCampoWhere +
" = 1 " + lcWhereSucur +
") " + Environment.NewLine;
5262 DB.SQLExec(lcSql, ref TabTmp);
5264 TabTmp.DefaultView.Sort =
" CLAVE ASC, VISIBLE DESC, PRINCIPAL ASC, PRIORIDAD DESC ";
5265 TabTmp = TabTmp.DefaultView.ToTable();
5268 if (TabTmp != null && TabTmp.Rows.Count > 0 && (cTipoEnvio ==
"e" && (prioridades.ContainsKey(159) && !prioridades.ContainsKey(292))))
5270 DataRow[] ldrDelete = TabTmp.Select(
"id = 292");
5271 if (ldrDelete != null && ldrDelete.Length == 1)
5273 ldrDelete[0].Delete();
5275 TabTmp.AcceptChanges();
5279 bool _lEsSucursal = Convert.ToBoolean(EW_GLOBAL._ModuloActivo(
"OFFLINE")) && !Convert.ToBoolean(EW_GLOBAL._GetVariable(
"wl_TipoOffline"));
5280 if (TabTmp != null && TabTmp.Rows.Count > 0 && prioridades.ContainsKey(47) && _lEsSucursal)
5282 DataRow[] ldrDelete = TabTmp.Select(
"id = 287");
5283 if (ldrDelete != null && ldrDelete.Length == 1)
5285 ldrDelete[0].Delete();
5287 TabTmp.AcceptChanges();
5290 DataTable dtTemp =
new DataTable();
5292 if (TabTmp != null && TabTmp.Rows.Count > 0)
5293 dtTemp = TabTmp.Clone();
5295 foreach (DataRow item
in TabTmp.Rows)
5297 if (item.Field<
string>(
"nombre").TrimEnd() != item.Field<
string>(
"principal").TrimEnd())
5300 if (item.Field<
string>(
"nombre").TrimEnd() ==
"COMUNES!HISSERIE")
5306 DataRow[] ldrs = TabTmp.Select(
"nombre = '" + item.Field<
string>(
"principal").TrimEnd() +
"' and principal = '" + item.Field<
string>(
"principal").TrimEnd() +
"' and clave ='" + item.Field<
string>(
"clave").TrimEnd() +
"' ");
5307 if (ldrs.Length == 0)
5310 DataRow[] ldrTemp = dtTemp.Select(
"nombre = '" + item.Field<
string>(
"principal").TrimEnd() +
"' and principal = '" + item.Field<
string>(
"principal").TrimEnd() +
"'and clave ='" + item.Field<
string>(
"clave").TrimEnd() +
"' ");
5311 if (ldrTemp.Length == 0)
5314 DataRow dataRow = dtTemp.NewRow();
5316 dataRow.ItemArray = item.ItemArray.Clone() as
object[];
5317 dataRow[
"nombre"] = dataRow[
"principal"];
5318 dataRow[
"asientos"] =
"";
5319 dataRow[
"otrasien"] =
"";
5320 dataRow[
"eos"] =
"";
5321 dataRow[
"relacion"] =
"";
5322 dataRow[
"iva_exen"] =
"";
5323 dataRow[
"ivasopor"] =
"";
5324 dataRow[
"ivareper"] =
"";
5325 dataRow[
"retreper"] =
"";
5326 dataRow[
"retsopor"] =
"";
5327 dataRow[
"compras"] =
"";
5329 dtTemp.Rows.Add(dataRow);
5335 if (dtTemp != null && dtTemp.Rows.Count > 0)
5336 TabTmp.Merge(dtTemp);
5338 TabTmp.DefaultView.Sort =
" CLAVE ASC, VISIBLE DESC, PRINCIPAL ASC, RELACION ASC ";
5339 TabTmp = TabTmp.DefaultView.ToTable();
5344 private static bool UploadIndividualFile(DataTable datos,
string path,
string nombreTabla,
int idConf, FormatoExportacion formatoExportacion, ref
long uploadedFileSize,
string carpeta)
5347 string uploadFile = Path.Combine(path, nombreTabla +
"." + formatoExportacion.ToString());
5349 ConvertIndividualFile(datos, path, nombreTabla, formatoExportacion);
5351 string zippedName = Path.GetFileName(uploadFile) +
".zip";
5353 if (!UploadManager.Subir_Fichero(uploadFile, zippedName, carpeta, idConf, ref uploadedFileSize))
5359 #endregion Métodos para el Asistente de Configuración bool _Send(string tcCliente="", string tcProveedor="", string tcResumen="")
Envia el correo
Clase para el envío de emails
INterfaz para log_comoff repository
Log_comoffDto GetDto(OfflineDatosComunicaciones datos)
Obtiene un dto a partir de DAtos de comunicaciones
bool _EnvioDirecto
Utilizar el correo predeterminado de Windows o el envío directo de Sage50 false : envio mediante clie...
object Retrieve(Type T)
Resuelve objeto de tipo T
void SaveChanges()
Guardar cambios
Es como el tipo de entrada asientos pero por negocio, sin formulario, pq quiero que me haga las propu...
override string _NombreFicheroExportar
Sobreescribir la propiedad de _NombreFicheroExportar para que tenga el valor del nombre de fichero se...
string TipoDato
Tipo de dato
EnumVariables
Enumerado de variables
Registro de comunicaciones
string _Error_Message
Mensaje de error
Clase EW_GLOBAL para gestionar las variables públicas de Eurowin, variables de empresa, variables de anchuras de campo, variables de mascaras, etc.
virtual string _Nombre
Campo nombre del mantenimiento. En este hay que basar los demás campos en las clases heredadas ...
void _AddAttachment(string tcFileName)
Añade un fichero adjunto
string _Subject
Asunto del correo
List< string > _Emails
Dirección de correo electrónico a la que se enviará el correo
ILog_comoffRepository Log_comoffRepository
Repositorio de log_comoff
static string _CodigoGrupoActual()
Obtención del código de grupo actual
static DependencyInjector Instance
Instancia
Clase para el control de grupos de empresa (nuevo enfoque en Sage50, desaparece el multiempresa...
void Insert(Log_comoffDto logDto)
Añade log
bool _CCOUsuarioActivo
India si tenemos que añadir CCO a los emails definidos en el usuario
Dto para inserciones en log log_comoff
string _Body
Cuerpo del mensaje
TipoConexion
Tipo de conexión
bool _ShowEmailForm
Para mostrar el formulario del correo en envío directo true : presenta el formulario false : envia si...
Interfaz UnitOfWor Offline
Clase Inyector de dependencias para resolver las dependencias
bool _Exportar(ExportType toTipoDocumento, string tcRutaFichero, bool tlAbrirFichero=false, string tcPantalla="")
Nos exportará el listado hacia una ruta especificada. Se podra abrir tras su exportación.