2 using System.Collections.Generic;
12 using System.Runtime.InteropServices;
13 using System.Windows.Forms;
17 using System.Threading.Tasks;
20 using System.Globalization;
33 public static class main_s50
36 private static string _cRutaServ =
"";
37 private static string _cComunes =
"";
38 private static string _cOdbc =
"";
39 private static string _cIp =
"";
40 private static string _cUser =
"";
41 private static string _cPassword =
"";
42 private static string lcNameProd = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_nameproducto"));
43 private static bool _lExternal_Entry =
false;
44 private static bool _lSemaforoConfigBak =
false;
48 public static event _OnReportProgressHandLer _OnReportProgress;
53 public static bool _lEjecucionDesdeProyecto =
false;
58 public static bool _lEsEjecutable =
false;
63 public static Dictionary<string, RegCfgCliSrv> _oCfgCliSrv =
new Dictionary<string, RegCfgCliSrv>();
68 public static string _cPathInicio =
"";
73 public static Forms.frmSplash _frmSplash;
78 public static string _ErrorString =
"";
83 public static bool _External_Entry
85 get {
return _lExternal_Entry; }
91 private const int CACHE_EXPIRATION = 2;
96 private static readonly
string SQL_MINIMUM_VERSION =
"12";
102 public static bool _main_Sage_50()
104 bool lbValidar =
true;
105 string lcMensajeErrorSO =
"";
107 EW_GLOBAL.ValorEnClave_VarGlob(
"wl_sage50",
true);
110 DB._SetTimeCacheTo(CACHE_EXPIRATION);
113 LoadingLog(5, tcText:
"Requisitos de sistema operativo");
114 if (!FUNCTIONS._RequisitosVersionSO(out lcMensajeErrorSO))
116 ew.functions.AutoClosingMessageBox._Show(lcMensajeErrorSO,
"Requisitos de sistema operativo", 120000);
120 LoadingLog(10, tcText:
"Validaciones de entorno");
122 if (!validacionesEntornoCorrectas(out
string lcMensajeError))
124 DB.Registrar_Traza(
"main_s50.cs,_Validacion_Entorno_Fallida");
125 _ErrorString = lcMensajeError;
129 LoadingLog(20,
"_Validar_ConfigINI",
"Validando config.ini");
130 lbValidar = _Validar_ConfigINI(Program._cGrupoParametro);
134 LoadingLog(30,
"_Validar_CfgCliSrv",
"Validando cfgclisrv.xml");
135 lbValidar = _Validar_CfgCliSrv();
138 if (lbValidar && !_lEjecucionDesdeProyecto)
140 LoadingLog(30,
"_Validar_Eurowin",
"Validando EW");
141 lbValidar = _Validar_Eurowin();
147 LoadingLog(40,
"_Cargar_Licencia",
"Comprobando licencia");
148 lbValidar = _Cargar_Licencia();
153 LoadingLog(50,
"_Registrar_Dependencias_Injector",
"Registrando dependencias");
155 Stopwatch sw = Stopwatch.StartNew();
157 RegisterTypesDependencyInjector();
159 Trace.WriteLine($
"Tiempo para carga de dependencias de addons; {sw.ElapsedMilliseconds}");
161 LoadingLog(50,
"_Cargar_Globales",
"Cargando diccionarios");
162 lbValidar = _Cargar_Globales();
168 LoadingLog(60,
"_Cargar_LibreriasReports",
"Cargando librerias SageReports");
169 _Cargar_LibreriasReports();
172 LoadingLog(70,
"_RegistrerSageReport",
"Registrando SageReports");
173 _RegistrerSageReport();
176 LoadingLog(80,
"_RegistrerSageReport",
"Registrando notificationes");
177 _RegisterNotifications();
180 LoadingLog(90, tcText:
"Evaluar y registrar versión de motor Sql");
182 FUNCTIONS.EvaluarRequisitosMotorBaseDeDatos(SQL_MINIMUM_VERSION, tnDiasEntreNotificaciones: 7, tlGuardarRegistroNotificacion:
true);
185 LoadingLog(100,
"_LiveUpdate",
"Revisando Live Update");
189 DB.Registrar_Traza(
"main_s50,ew_MessageFilters");
191 Application.AddMessageFilter(lst);
193 LoadingLog(100, tcTextCentral:
"Cargando entorno ... ");
199 private static void LoadingLog(
int tnProcess,
string tcName =
"",
string tcText =
"",
string tcTextCentral =
"")
201 if (!
string.IsNullOrEmpty(tcText) || !
string.IsNullOrEmpty(tcTextCentral)) _OnReportProgress?.Invoke(
new InfoProgresBar(tnProcess, 100, tcText, tcTextCentral));
202 if (!
string.IsNullOrEmpty(tcName)) DB.Registrar_Traza($
"main_s50,{tcName}");
205 private static bool validacionesEntornoCorrectas(out
string lcMensajeError)
208 bool entornoCorrecto =
true;
211 if (!FormatoFechasValido())
213 entornoCorrecto =
false;
214 lcMensajeError = lcMensajeError +=
"Para poder trabajar con "+ lcNameProd+
" debe tener configurado el formato de fecha de la forma día/mes/año" + Environment.NewLine;
217 return entornoCorrecto;
224 private static bool FormatoFechasValido()
226 bool formatoCorrecto =
false;
228 string formato = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.ToUpper();
231 if (formato.StartsWith(
"D") && formato.EndsWith(
"Y"))
233 formatoCorrecto =
true;
235 return formatoCorrecto;
245 public static bool _main_Sage_50_External_Entry(
string tcRutaPathInicio,
string tcComunes =
"",
string tcEmpresa =
"")
248 sage.
ew.
db.
DB.Escribir_En_Log_Error(
sage.
ew.
db.
DB.Modo_Registro.Registro_Consulta, null,
"Entrando en _main_Sage_50_External_Entry. Ruta path inicio -> " + tcRutaPathInicio);
250 bool lbValidar =
true;
251 EW_GLOBAL.ValorEnClave_VarGlob(
"wl_sage50",
true);
253 _lExternal_Entry =
true;
256 if (
string.IsNullOrWhiteSpace(tcRutaPathInicio))
259 if (!Directory.Exists(tcRutaPathInicio))
262 string lcEmpAnt = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_empresa"));
263 string lcComunesAnt = DB.DbComunes;
265 _cPathInicio = tcRutaPathInicio;
266 lbValidar = _Validar_ConfigINI(tcComunes);
268 lbValidar = lbValidar && _Validar_CfgCliSrv(tcComunes);
271 _frmSplash =
new Forms.frmSplash();
274 RegisterTypesDependencyInjector();
276 lbValidar = lbValidar && _Cargar_Globales(tcEmpresa);
282 if (lbValidar && (EW_GLOBAL._Empresa == null || lcComunesAnt != DB.DbComunes || lcEmpAnt != Convert.ToString(EW_GLOBAL._GetVariable(
"wc_empresa"))))
283 EW_GLOBAL._Empresa =
new Empresa(Convert.ToString(EW_GLOBAL._GetVariable(
"wc_empresa")));
291 private static void _RegistrerSageReport()
294 String lcFile = Path.Combine(_cPathInicio,
"config.ini");
295 String lcPathSageReports = FUNCTIONS.LeerConfigIni(
"[SAGEREPORTS]", _cPathInicio);
306 public static bool _Validar_ConfigINI(
string tcComunes=
"")
308 bool lbValidar =
true;
309 string lcFile, lcFileBak;
311 LoadingLog(21, tcTextCentral:
"Validando config.ini ... ");
313 lcFile = Path.Combine(_cPathInicio,
"config.ini");
314 lcFileBak = Path.Combine(_cPathInicio,
"config.bak");
316 _cPathInicio = FUNCTIONS._AddBS(_cPathInicio);
319 if (!File.Exists(lcFile))
321 _ErrorString =
"No se ha encontrado el fichero de configuración en el directorio actual.";
327 lbValidar = _Validar_ConfigINI_Configuracion_Minima(tcComunes, lcFile);
330 if (!lbValidar && File.Exists(lcFileBak) && !_lSemaforoConfigBak)
333 bool llOk = _Validar_ConfigINI_Gestion_BAK(lcFile, lcFileBak);
338 _lSemaforoConfigBak =
true;
339 llOk = _Validar_ConfigINI(tcComunes);
340 _lSemaforoConfigBak =
false;
341 if (llOk) _ErrorString =
"";
346 LoadingLog(25, tcTextCentral: $
"{(lbValidar ? "Ok
" : "Fail
")}{Environment.NewLine}");
357 private static bool _Validar_ConfigINI_Gestion_BAK(
string lcFile,
string lcFileBak)
362 string lcFileBak2 = Path.Combine(_cPathInicio, (
"config_" + Path.GetRandomFileName() +
".bak"));
367 if (File.Exists(lcFile))
368 File.Copy(lcFile, lcFileBak2,
true);
371 if ((DateTime.Now - File.GetLastWriteTime(lcFileBak)).TotalDays <= 2)
374 File.Copy(lcFileBak, lcFile,
true);
378 catch (Exception) { llOk =
false; }
389 private static bool _Validar_ConfigINI_Configuracion_Minima(
string tcComunes,
string tcFileIni)
392 sage.
ew.
db.
DB.Escribir_En_Log_Error(
sage.
ew.
db.
DB.Modo_Registro.Registro_Consulta, null,
"Entrando en _Validar_ConfigINI_Configuracion_Minima. tcFileIni -> " + tcFileIni +
" / _cPathInicio -> " + _cPathInicio);
394 bool lbValidar =
true;
397 string lcContent = FUNCTIONS._ReadFile(tcFileIni);
398 if (
string.IsNullOrWhiteSpace(lcContent))
400 _ErrorString =
"El fichero de configuración está vacío.";
406 _cRutaServ = FUNCTIONS._AddBS(FUNCTIONS.LeerConfigIni(
"[SERVIDOR]", _cPathInicio));
407 if (
string.IsNullOrWhiteSpace(_cRutaServ))
409 _ErrorString =
"El fichero de configuración no tiene la estructura esperada. No contiene el tag [SERVIDOR].";
415 if (!Directory.Exists(_cRutaServ))
417 _ErrorString =
"La ruta del servidor encontrada en el fichero de configuración no es válida." + Environment.NewLine + _cRutaServ;
425 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_iniservidor", _cRutaServ);
429 if (
string.IsNullOrEmpty(tcComunes.Trim()))
430 _cComunes = FUNCTIONS.LeerConfigIni(
"[COMUNES]", _cPathInicio);
432 _cComunes = tcComunes;
434 if (
string.IsNullOrWhiteSpace(_cComunes))
436 _ErrorString =
"El fichero de configuración no tiene la estructura esperada. No contiene el tag [COMUNES].";
449 public static bool _Validar_CfgCliSrv()
452 return _Validar_CfgCliSrv(
string.Empty);
460 public static bool _Validar_CfgCliSrv(
string tcComunes)
463 bool lbValidar =
true;
464 bool lbAutWin =
false;
465 string lcCfgCliSrvXml =
"", lcNotificaComunes =
"";
467 LoadingLog(30, tcTextCentral:
"Validando cfgclisrv.xml...");
473 if (_oCfgCliSrv.Count == 0)
476 lcCfgCliSrvXml = Path.Combine(_cRutaServ,
"cfgclisrv.xml");
477 if (!File.Exists(lcCfgCliSrvXml))
479 _ErrorString =
"No se ha encontrado el fichero de configuración del servidor (cfgclisrv.xml).";
483 cargarCfgCliSrv(lcCfgCliSrvXml);
487 _cComunes = FUNCTIONS.LeerConfigIni(
"[COMUNES]", _cPathInicio);
492 if (!Validar_Comunes(ref lbAutWin, ref lcNotificaComunes))
494 _ErrorString =
"No se ha encontrado el COMUNES en el fichero de configuración del servidor.";
503 if (
string.IsNullOrWhiteSpace(_cUser) && lbAutWin ==
false)
505 _ErrorString =
"No se ha encontrado el valor de COMUNES del fichero de configuración del terminal en el fichero de configuración del servidor.";
512 bool llTopMost =
false;
515 _cPassword = FUNCTIONS._Encripta(_cPassword).Trim().ToLower();
517 if (_frmSplash is Form)
519 llTopMost = !_lExternal_Entry && _frmSplash.TopMost;
522 _frmSplash.TopMost =
false;
528 string _comunesForConnect =
string.IsNullOrWhiteSpace(tcComunes) ? _cComunes : tcComunes;
529 if (!DB.SQLConnect(_cIp, _cUser, _cPassword, _comunesForConnect, tcAliasConexion:
"eurowin", tbAuthWin: lbAutWin))
531 _ErrorString =
"No ha sido posible realizar la conexión con el servidor de datos.";
538 if (lbValidar && !_lExternal_Entry && faltaModuloTPV())
540 ew.functions.AutoClosingMessageBox._Show(
"No se han encontrado AddOns necesarios para el correcto funcionamiento del programa." + Environment.NewLine
541 + Environment.NewLine +
"Póngase en contacto con su soporte técnico habitual.",
"Requisitos de AddOns instalados", 120000);
549 LoadingLog(35, tcTextCentral: $
"Ok{Environment.NewLine}");
550 if (!
string.IsNullOrWhiteSpace(lcNotificaComunes))
551 FUNCTIONS._Notificacion(
"Validación CONFIG.INI",
"Etiqueta [COMUNES] con valor incorrecto", lcNotificaComunes, tcIcono:
"warning");
555 LoadingLog(35, tcTextCentral: $
"Fail{Environment.NewLine}");
558 LoadingLog(35, tcTextCentral:
"Driver:" + (!
string.IsNullOrWhiteSpace(_cOdbc) ? _cOdbc :
"SQL Native Client 2005") + Environment.NewLine);
569 private static bool Validar_Comunes(ref
bool tbAutWin, ref
string tcNotifica)
572 string lcComunes = _cComunes;
574 llOk = obtenerDatosConexion(_cComunes, ref _cUser, ref _cPassword, ref _cIp, ref tbAutWin, ref _cOdbc);
578 foreach (KeyValuePair<string, RegCfgCliSrv> loComunes
in _oCfgCliSrv)
580 if (loComunes.Key != lcComunes)
582 _cComunes = loComunes.Key;
583 llOk = obtenerDatosConexion(_cComunes, ref _cUser, ref _cPassword, ref _cIp, ref tbAutWin, ref _cOdbc);
587 FUNCTIONS._GuardarConfigIni(
"[COMUNES]", _cComunes, _cPathInicio,
"config.ini");
590 tcNotifica =
"Se ha encontrado el valor incorrecto '"+lcComunes+
"' en la etiqueta [COMUNES] del fichero CONFIG.INI en "+
591 "la siguiente ruta: "+ _cPathInicio+
"." +Environment.NewLine+Environment.NewLine+
592 "Para poder iniciar la aplicación correctamente, se ha sustituido por el valor '" + _cComunes+
"'.";
608 private static void cargarCfgCliSrv(
string tcFicheroXml)
610 XmlDocument xmlCfgCliSrv =
new XmlDocument();
611 xmlCfgCliSrv.Load(tcFicheroXml);
614 XmlNode VFPDataNode = xmlCfgCliSrv[
"VFPData"];
618 foreach (XmlNode cfgclisrvNode
in VFPDataNode.ChildNodes)
620 if (cfgclisrvNode.Name.ToLower().Trim() ==
"cfgclisrv")
624 if (!
string.IsNullOrWhiteSpace(cfgclisrvNode[
"comunes"].InnerText.Trim()))
630 if (!_oCfgCliSrv.TryGetValue(cfgclisrvNode[
"comunes"].InnerText.Trim().ToUpper(), out loExisteReg))
634 _User = cfgclisrvNode[
"user"].InnerText.Trim(),
635 _Password = cfgclisrvNode[
"password"].InnerText.Trim(),
636 _Ip = cfgclisrvNode[
"ip"].InnerText.Trim(),
637 _Comunes = cfgclisrvNode[
"comunes"].InnerText.Trim().ToUpper()
640 if (cfgclisrvNode[
"server"] != null)
641 loRegCfgCliServ.
_Server = cfgclisrvNode[
"server"].InnerText.Trim();
645 if (cfgclisrvNode[
"port"] != null)
646 loRegCfgCliServ.
_Port = Convert.ToInt32(cfgclisrvNode[
"port"].InnerText.Trim());
648 loRegCfgCliServ.
_Port = 0;
650 if (cfgclisrvNode[
"autwin"] != null)
651 loRegCfgCliServ.
_AutWin = Convert.ToBoolean(cfgclisrvNode[
"autwin"].InnerText.Trim());
653 loRegCfgCliServ.
_AutWin =
false;
655 if (cfgclisrvNode[
"odbc"] != null)
656 loRegCfgCliServ.
_Odbc = cfgclisrvNode[
"odbc"].InnerText.Trim();
658 loRegCfgCliServ.
_Odbc =
"";
660 _oCfgCliSrv.Add(cfgclisrvNode[
"comunes"].InnerText.Trim(), loRegCfgCliServ);
680 private static bool obtenerDatosConexion(
string tcComunes, ref
string tcUser, ref
string tcPassword, ref
string tcIp, ref
bool tlAutWin, ref
string tcOdbc)
688 if (!_oCfgCliSrv.TryGetValue(tcComunes.ToUpper(), out loRegCfgCliSrv))
694 tcUser = loRegCfgCliSrv.
_User;
696 tcIp = loRegCfgCliSrv.
_Ip;
697 tlAutWin = loRegCfgCliSrv.
_AutWin;
698 tcOdbc = loRegCfgCliSrv.
_Odbc;
709 private static bool faltaModuloTPV()
711 bool llFaltaModulo = (0 == Convert.ToInt32(DB._ValorSQL(
"MODULOS",
new string[] {
"NOMBRE='TPV'" },
new string[] {
"COUNT(NOMBRE) AS CONTADOR" },
"COMUNES")));
712 bool llFaltaPrgs = (2 > Convert.ToInt32(DB._ValorSQL(
"PRGS",
new string[] {
"MODULO='TPV'" },
new string[] {
"COUNT(MODULO) AS CONTADOR" },
"COMUNES")));
713 return (llFaltaModulo || llFaltaPrgs);
720 public static bool _Validar_Eurowin()
723 bool lbValidar =
true;
726 string lcDbVistasServidor = Path.Combine(_cRutaServ,
"db_vistas_serv");
727 string lcDbVistasTerminal = Path.Combine(_cPathInicio,
"Db_Vistas");
728 string lcTriggersServidor = Path.Combine(_cRutaServ,
"triggers");
729 string lcTriggersTerminal = Path.Combine(_cPathInicio,
"Triggers");
731 LoadingLog(30, tcTextCentral:
"Validando ejecutable ... ");
736 if (!Directory.Exists(lcDbVistasServidor))
738 _ErrorString =
"No se ha encontrado el directorio Db_Vistas_Serv en el servidor de la aplicación.";
746 if (!Directory.Exists(lcTriggersServidor))
748 _ErrorString =
"No se ha encontrado el directorio Triggers en el servidor de la aplicación.";
756 if (!Directory.Exists(lcDbVistasTerminal))
757 Directory.CreateDirectory(lcDbVistasTerminal);
758 if (!Directory.Exists(lcDbVistasTerminal))
760 _ErrorString =
"No se ha podido crear el directorio Db_Vistas en el terminal de la aplicación.";
768 if (!Directory.Exists(lcTriggersTerminal))
769 Directory.CreateDirectory(lcTriggersTerminal);
770 if (!Directory.Exists(lcTriggersTerminal))
772 _ErrorString =
"No se ha podido crear el directorio Triggers en el terminal de la aplicación.";
783 foreach (
string file
in Directory.GetFiles(lcDbVistasServidor))
785 string lcNomFile =
new FileInfo(file).Name;
786 File.Copy(Path.Combine(lcDbVistasServidor, lcNomFile), Path.Combine(lcDbVistasTerminal, lcNomFile),
true);
789 catch (Exception loEx)
791 DB.Registrar_Error(loEx);
795 if (!File.Exists(Path.Combine(lcDbVistasTerminal,
"vistasbase.vcx"))
796 || !File.Exists(Path.Combine(lcDbVistasTerminal,
"vistasbase.vct"))
797 || !File.Exists(Path.Combine(lcDbVistasTerminal,
"vistas.vcx"))
798 || !File.Exists(Path.Combine(lcDbVistasTerminal,
"vistas.vct")))
800 _ErrorString =
"No se han podido copiar las vistas al terminal.";
811 foreach (
string file
in Directory.GetFiles(lcTriggersServidor))
813 string lcNomFile =
new FileInfo(file).Name;
814 File.Copy(Path.Combine(lcTriggersServidor, lcNomFile), Path.Combine(lcTriggersTerminal, lcNomFile),
true);
822 if (!File.Exists(Path.Combine(lcTriggersTerminal,
"trigbase.vcx"))
823 || !File.Exists(Path.Combine(lcTriggersTerminal,
"trigbase.vct"))
824 || !File.Exists(Path.Combine(lcTriggersTerminal,
"triggers.vcx"))
825 || !File.Exists(Path.Combine(lcTriggersTerminal,
"triggers.vct")))
827 _ErrorString =
"No se han podido copiar las triggers al terminal.";
832 LoadingLog(35, tcTextCentral: $
"{(lbValidar ? "Ok
" : "Fail
")}{Environment.NewLine}");
841 public static bool _Cargar_Licencia()
846 LoadingLog(45, tcTextCentral: $
"Comprobando licencia ... ");
848 lcLicencia = LICENCIAS._ObtenerLicenciaActual();
849 if (
string.IsNullOrWhiteSpace(lcLicencia))
851 _ErrorString = LICENCIAS._MensajeError;
855 LoadingLog(45, tcTextCentral: $
"{(llOk ? "Ok
" : "Fail
")}{Environment.NewLine}");
875 public static bool _Cargar_Globales(
bool tlVerificarLicencia,
string tcEmpresa =
"",
string tcCajaTpv =
"")
877 return cargarGlobales(tcEmpresa, tcCajaTpv, tlVerificarLicencia);
886 public static bool _Cargar_Globales(
string tcEmpresa =
"",
string tcCajaTpv=
"")
888 return cargarGlobales(tcEmpresa, tcCajaTpv,
true);
899 private static bool cargarGlobales(
string tcEmpresa,
string tcCajaTpv,
bool tlVerificarLicencia)
901 bool lbValidar =
true;
902 string lcEmpresa =
"";
903 string lcCajaTpv =
"";
907 EW_GLOBAL.ValorEnClave_VarGlob(
"wl_sage50",
true);
908 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_pathinicio", _cPathInicio);
909 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_iniservidor", _cRutaServ);
911 string lcLicencia = LICENCIAS._Licencia;
918 EW_GLOBAL.ValorEnClave_VarGlob(
"wn_AsesorContable", 0);
919 if (!
string.IsNullOrWhiteSpace(lcLicencia) && lcLicencia.Length >= 2 && lcLicencia.Substring(0, 2) ==
"SY")
926 EW_GLOBAL._SetVariable(
"wn_AsesorContable", 10);
931 lcEmpresa = ObtenerEmpresa(tcEmpresa);
934 if (EW_GLOBAL._ModuloActivo(
"TPV"))
936 if (
string.IsNullOrEmpty(tcCajaTpv))
937 lcCajaTpv = FUNCTIONS.LeerConfigIni(
"[CAJATPV]");
939 lcCajaTpv = tcCajaTpv;
942 if (lcCajaTpv.Trim().ToUpper() ==
"NO")
943 lcCajaTpv =
string.Empty;
946 LoadingLog(45, tcTextCentral:
"Cargando diccionarios ... ");
948 if (
string.IsNullOrWhiteSpace(lcCajaTpv))
956 LoadingLog(55, tcTextCentral: $
"Ok{Environment.NewLine}");
957 LoadingLog(55, tcTextCentral:
"Obteniendo parámetros globales ... ");
960 EW_GLOBAL._Sage50Actualizado = FUNCTIONS._Sage50Actualizado();
963 string lcUsuario =
"";
964 if (!
string.IsNullOrWhiteSpace(Program._cUserEurowin))
965 lcUsuario = Program._cUserEurowin;
967 lcUsuario = FUNCTIONS.LeerConfigIni(
"[USUARIO]");
970 string lcLetra = FUNCTIONS.LeerConfigIni(
"[LETRA]");
971 string lcAlmacen = FUNCTIONS.LeerConfigIni(
"[ALMACEN]");
974 string lcAny = DB.Ejercicio_EW.ToString().Trim();
977 string lcOperarioTpv =
string.Empty;
978 if (EW_GLOBAL._ModuloActivo(
"TPV"))
979 lcOperarioTpv = Convert.ToString(DB.SQLValor(
"CAJAS",
"CODIGO", lcCajaTpv,
"OPERARIO",
"TPV"));
982 string lcusergraf = Path.Combine(_cRutaServ,
@"usergraf\");
985 string lcSqlLog = Convert.ToString(FUNCTIONS.LeerConfigIni(
"[SQL_LOG]")).ToUpper().Trim();
988 string lcPrueva = Convert.ToString(FUNCTIONS.LeerConfigIni(
"[PRUEVAS]")).ToUpper();
989 bool llPrueva = (lcPrueva ==
"SI" || lcPrueva ==
"PERMANENTE");
992 if (!
string.IsNullOrWhiteSpace(lcAny))
996 string lcDataBase =
string.Empty;
997 lcAny = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_any"));
1000 if (!DB._oAliasDB.TryGetValue(lcAny, out lcDataBase))
1002 lcAny = DB.Ejercicio_EW.ToString().Trim();
1005 DB.SQLPredeterminarGestion(Convert.ToString(lcAny));
1009 DB.PreloadSchemas();
1012 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_usuario", lcUsuario);
1013 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_empresa", lcEmpresa);
1014 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_cajatpv", lcCajaTpv);
1015 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_concomunes", _cComunes);
1016 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_any", lcAny);
1017 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_operariotpv", lcOperarioTpv);
1018 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_usergraf", lcusergraf);
1019 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_sql_log", lcSqlLog);
1020 EW_GLOBAL.ValorEnClave_VarGlob(
"wl_prueva", llPrueva);
1021 EW_GLOBAL.ValorEnClave_VarGlob(
"formvfp",
"");
1022 EW_GLOBAL.ValorEnClave_VarGlob(
"wl_EsEjecutable", _lEsEjecutable);
1025 if (!
string.IsNullOrWhiteSpace(lcLetra))
1026 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_letra", lcLetra);
1029 if (!
string.IsNullOrWhiteSpace(lcAlmacen))
1030 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_almacen", lcAlmacen);
1032 LoadingLog(55, tcTextCentral: $
"Ok{Environment.NewLine}");
1036 LoadingLog(55, tcTextCentral: $
"Fail{Environment.NewLine}");
1037 _ErrorString =
"No se han podido cargar los diccionario de variables globales.";
1041 if (tlVerificarLicencia)
1044 LoadingLog(57, tcTextCentral:
"Validando licencia ... ");
1046 if (LICENCIAS._Validar_Licencia_Suscripcion())
1048 LoadingLog(57, tcTextCentral: $
"Ok{Environment.NewLine}");
1052 LoadingLog(57, tcTextCentral: $
"Fail{Environment.NewLine}");
1053 _ErrorString = LICENCIAS._MensajeError;
1059 if (!
string.IsNullOrWhiteSpace(LICENCIAS._MensajeError))
1061 _ErrorString = LICENCIAS._MensajeError;
1062 LICENCIAS._MensajeError =
"";
1069 GetSage50PathLibrerias = FUNCTIONS.GetSage50PathLibrerias,
1070 CodigoLicencia = LICENCIAS._CodigoLicencia,
1071 PluginActivo = FUNCTIONS._PluginActivo,
1072 CrearNotificacionWarning = FUNCTIONS.CrearNotificacionWarning
1077 if (_lExternal_Entry)
1083 if ((!_garantizandoAddons || (!
string.IsNullOrWhiteSpace(_cGrupo) && _cGrupo != _cGrupoEmpresaActual)) && !_lExternal_Entry)
1086 _garantizandoAddons =
true;
1091 SetupAddons setup =
new SetupAddons(
true,
false,
false,
true);
1094 _cGrupo = _cGrupoEmpresaActual;
1101 static bool _garantizandoAddons =
false;
1103 private static string _cGrupo =
string.Empty;
1108 private static string _cGrupoEmpresaActual
1112 return DB.DbComunes.Substring(4, 4);
1120 private static bool LoadServices()
1122 string lcError =
string.Empty;
1124 FUNCTIONS._StateServiceForm(ref lcError);
1133 public static bool _Cargar_LibreriasReports()
1136 string lcPatron =
"Sage.ES.S50c.Reports";
1137 string lcPathInicio = FUNCTIONS.GetSage50PathLibrerias();
1139 if (Directory.Exists(lcPathInicio))
1141 DirectoryInfo loDir =
new DirectoryInfo(lcPathInicio);
1143 List<FileInfo> loList = (from loFile in loDir.GetFiles(
"*.dll")
1144 where loFile.Name.ToLower().StartsWith(lcPatron.ToLower())
1145 select loFile).ToList();
1148 foreach (FileInfo loFileInfo
in loList)
1151 string lcFicheroDll = loFileInfo.FullName;
1153 Assembly addonAssembly = null;
1156 var appDomain = AppDomain.CreateDomain(lcFicheroDll);
1157 addonAssembly = appDomain.Load(
System.IO.File.ReadAllBytes(lcFicheroDll));
1161 addonAssembly = null;
1163 if (addonAssembly == null)
1167 addonAssembly = Assembly.LoadFrom(lcFicheroDll);
1171 addonAssembly = null;
1175 if (addonAssembly != null)
1186 public static void _RegisterNotifications()
1189 string lcComunesPripal = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_ComunesPripal"));
1190 string lcComunesActual = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_ComunesActual"));
1193 if (
string.IsNullOrWhiteSpace(lcComunesActual))
1195 if (DB._oAliasDB.TryGetValue(
"COMUNES", out lcComunesActual))
1196 lcComunesActual = lcComunesActual.Replace(
"].dbo.",
"").Replace(
"[",
"").Trim().ToUpper();
1202 if (!
String.IsNullOrEmpty(lcComunesPripal.Trim()) && lcComunesActual != lcComunesPripal)
1206 string lcRutaServidor = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_iniservidor")).Trim();
1214 string lcPath = FUNCTIONS._AddBS(lcRutaServidor) +
@"\LOGS\NOTIFICA";
1217 if (!Directory.Exists(lcPath))
1221 DirectoryInfo ldDir =
new DirectoryInfo(lcPath);
1222 foreach (var lcFile
in ldDir.GetFiles(
"notifica*.xml"))
1224 string lcFileXml = Path.Combine(lcPath, lcFile.Name);
1227 if (_RegisterNotificationXml(lcFileXml))
1229 string lcFileCopy = Path.Combine(lcPath,
"_" + lcFile.Name);
1234 if (File.Exists(lcFileCopy))
1235 File.Delete(lcFileCopy);
1238 File.Move(lcFileXml, lcFileCopy);
1240 catch (Exception loEx)
1242 DB.Registrar_Error(
new Exception(
"No se ha podido copiar fichero "+lcFileXml+
" ("+loEx.Message+
")."));
1253 private static bool _RegisterNotificationXml(
string tcFile)
1255 bool llOk =
false, llReturn =
false;
1256 DataTable ldtTabla =
new DataTable();
1259 if (
System.IO.File.Exists(tcFile))
1260 llOk = FUNCTIONS._Xml2Datatable(tcFile, ref ldtTabla);
1263 if (!llOk || ldtTabla == null)
1267 foreach (DataRow ldrRow
in ldtTabla.Rows)
1269 string lcCat =
"", lcNombre =
"", lcDesc =
"", lcLib =
"", lcClase =
"", lcPermanente =
"";
1270 bool tlPermanente =
false;
1272 if (ldtTabla.Columns.Contains(
"categoria"))
1273 lcCat = Convert.ToString(ldrRow[
"categoria"]);
1275 if (ldtTabla.Columns.Contains(
"nombre"))
1276 lcNombre = Convert.ToString(ldrRow[
"nombre"]);
1278 if (ldtTabla.Columns.Contains(
"descrip"))
1279 lcDesc = Convert.ToString(ldrRow[
"descrip"]);
1281 if (ldtTabla.Columns.Contains(
"libreria"))
1282 lcLib = Convert.ToString(ldrRow[
"libreria"]);
1284 if (ldtTabla.Columns.Contains(
"clase"))
1285 lcClase = Convert.ToString(ldrRow[
"clase"]);
1287 if (ldtTabla.Columns.Contains(
"permanente"))
1289 lcPermanente = Convert.ToString(ldrRow[
"permanente"]);
1290 if (!
String.IsNullOrEmpty(lcPermanente.Trim()) && lcPermanente.Trim()==
"true")
1291 tlPermanente =
true;
1295 if (!
String.IsNullOrEmpty(lcCat.Trim()) && !
String.IsNullOrEmpty(lcNombre.Trim()))
1309 private static void RevisarLiveUpdate()
1312 Task TaskLU =
new Task(() => loLiveUpdate._RevisarLiveUpdate());
1326 public static bool Connect(
string tcPathEuroTerm,
string tcUser,
string tcPassword,
string tcEmpresa =
"",
bool tlMuestraErrores =
true)
1329 if (!
string.IsNullOrWhiteSpace(
sage.
ew.
db.
DB.Conexion))
1332 if(tlMuestraErrores)
1334 "Conexión a "+ lcNameProd, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
1340 if (!
string.IsNullOrWhiteSpace(tcPathEuroTerm) && Directory.Exists(tcPathEuroTerm))
1347 DB._SetTimeCacheTo(0);
1352 if (!
string.IsNullOrWhiteSpace(tcEmpresa))
1355 if (loForm._Empresa != tcEmpresa)
1356 _ErrorString +=
"No se ha podido asignar la empresa \"" + tcEmpresa +
"\"." + Environment.NewLine +
"¿Puede ser que la empresa no exista?";
1359 if (
string.IsNullOrWhiteSpace(_ErrorString))
1362 DialogResult leResposta = DialogResult.Cancel;
1364 if (
string.IsNullOrWhiteSpace(tcUser) ||
string.IsNullOrWhiteSpace(tcPassword))
1365 leResposta = loForm.ShowDialog();
1367 leResposta = loForm._CheckLogin(tcUser, tcPassword);
1369 llOk = (leResposta == DialogResult.OK);
1379 if (tlMuestraErrores)
1381 string lcError = _ErrorString;
1382 if (
string.IsNullOrWhiteSpace(lcError))
1383 lcError =
"Usuario o contraseña incorrectos.";
1384 MessageBox.Show(lcError,
"Conexión a "+ lcNameProd, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
1390 EW_GLOBAL._CodiPerfilCarregat =
".predet";
1406 public static bool Connect(
string tcInstancia,
string tcUser,
string tcPassword,
string tcBDComunes,
string tcEmpresaGuid,
bool tlMuestraErrores =
true)
1410 string codeBase = Assembly.GetExecutingAssembly().CodeBase;
1411 UriBuilder uri =
new UriBuilder(codeBase);
1412 string pathInicio = Uri.UnescapeDataString(uri.Path);
1413 pathInicio = Path.GetDirectoryName(pathInicio);
1414 string iniServidor =
string.Empty;
1416 if (!
string.IsNullOrWhiteSpace(pathInicio))
1418 pathInicio =
System.IO.Directory.GetParent(pathInicio).FullName;
1419 if (!
string.IsNullOrWhiteSpace(pathInicio))
1421 pathInicio = FUNCTIONS._AddBS(pathInicio);
1424 iniServidor = FUNCTIONS._AddBS(FUNCTIONS.LeerConfigIni(
"[SERVIDOR]", pathInicio));
1428 if (!
string.IsNullOrWhiteSpace(pathInicio) && !
string.IsNullOrWhiteSpace(iniServidor))
1431 _cPathInicio = pathInicio;
1432 _cRutaServ = iniServidor;
1433 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_pathinicio", _cPathInicio);
1437 EW_GLOBAL.ValorEnClave_VarGlob(
"wl_sage50",
true);
1440 if (!
string.IsNullOrWhiteSpace(
sage.
ew.
db.
DB.Conexion))
1443 if (tlMuestraErrores)
1445 "Conexión a "+lcNameProd, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
1449 bool lbValidar =
true;
1451 if (!
string.IsNullOrWhiteSpace(tcInstancia) && !
string.IsNullOrWhiteSpace(tcUser)
1452 && !
string.IsNullOrWhiteSpace(tcPassword) && !
string.IsNullOrWhiteSpace(tcBDComunes))
1455 _cComunes = tcBDComunes;
1457 _cPassword = tcPassword;
1461 if (!DB.SQLConnect(_cIp, _cUser, _cPassword, _cComunes, tcAliasConexion:
"eurowin", tbAuthWin:
false))
1463 _ErrorString =
"No ha sido posible realizar la conexión con el servidor de datos.";
1469 RegisterTypesDependencyInjector();
1471 LICENCIAS._ObtenerLicenciaActual();
1472 LICENCIAS._Validar_Licencia_Suscripcion();
1475 string lcEmpresa =
"";
1476 DataTable ldtTemp =
new DataTable();
1477 string lcSql =
"SELECT codigo FROM " + DB.SQLDatabase(
"EMPRESA") +
" WHERE guid_id = " + DB.SQLString(tcEmpresaGuid);
1478 if (DB.SQLExec(lcSql, ref ldtTemp) && ldtTemp.Rows.Count > 0 && !
string.IsNullOrWhiteSpace(ldtTemp.Rows[0][
"codigo"].ToString()))
1480 lcEmpresa = ldtTemp.Rows[0][
"codigo"].ToString();
1484 _ErrorString =
"No se han podido cargar los diccionario de variables globales.";
1489 lcSql =
"SELECT [any] AS ano FROM " + DB.SQLDatabase(
"COMUNES",
"ejercici") +
" ORDER BY [any] DESC ";
1490 DataTable ldtEjercicis =
new DataTable();
1491 if (DB.SQLExec(lcSql, ref ldtEjercicis) && ldtEjercicis.Rows.Count > 0)
1493 foreach (DataRow ldr
in ldtEjercicis.Rows)
1495 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_any", Convert.ToString(ldr[
"ano"]).Trim());
1496 DB.SQLPredeterminarGestion(Convert.ToString(ldr[
"ano"]).Trim());
1499 lcSql =
"SELECT codigo FROM " + DB.SQLDatabase(
"EMPRESA") +
" WHERE guid_id = " + DB.SQLString(tcEmpresaGuid);
1500 if (DB.SQLExec(lcSql, ref ldtTemp) && ldtTemp.Rows.Count > 0 && !
string.IsNullOrWhiteSpace(ldtTemp.Rows[0][
"codigo"].ToString()))
1502 lcEmpresa = ldtTemp.Rows[0][
"codigo"].ToString();
1506 _ErrorString =
"No se han podido cargar los diccionario de variables globales.";
1514 _ErrorString =
"No se ha encontrado ninguna empresa con el GUID \"" + tcEmpresaGuid +
"\".";
1520 _ErrorString =
"No se ha encontrado ninguna empresa con el GUID \"" + tcEmpresaGuid +
"\".";
1528 string lcAny = DB.Ejercicio_EW.ToString().Trim();
1531 if (!
string.IsNullOrWhiteSpace(lcAny))
1535 string lcDataBase =
string.Empty;
1536 lcAny = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_any"));
1539 if (!DB._oAliasDB.TryGetValue(lcAny, out lcDataBase))
1541 lcAny = DB.Ejercicio_EW.ToString().Trim();
1544 DB.SQLPredeterminarGestion(Convert.ToString(lcAny));
1548 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_pathinicio", _cPathInicio);
1549 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_iniservidor", _cRutaServ);
1550 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_usuario",
"SUPERVISOR");
1551 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_empresa", lcEmpresa);
1552 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_cajatpv",
"");
1553 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_concomunes", _cComunes);
1554 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_any", lcAny);
1555 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_operariotpv",
"");
1556 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_ewlicencia",
"");
1557 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_usergraf",
"");
1558 EW_GLOBAL.ValorEnClave_VarGlob(
"wc_sql_log",
"");
1559 EW_GLOBAL.ValorEnClave_VarGlob(
"wl_prueva",
false);
1560 EW_GLOBAL.ValorEnClave_VarGlob(
"formvfp",
"");
1561 EW_GLOBAL.ValorEnClave_VarGlob(
"wl_EsEjecutable", _lEsEjecutable);
1562 EW_GLOBAL.ValorEnClave_VarGlob(
"wl_sage50",
true);
1568 if (!LICENCIAS._CargarDiccionarioModulos())
1570 _ErrorString =
"No se ha podido cargar el diccionario de módulos.";
1573 EW_GLOBAL._Empresa =
new Empresa(Convert.ToString(EW_GLOBAL._GetVariable(
"wc_empresa")));
1583 if (tlMuestraErrores)
1585 string lcError = _ErrorString;
1586 if (
string.IsNullOrWhiteSpace(lcError))
1587 lcError =
"Error realizando conexión a base de datos.";
1588 MessageBox.Show(lcError,
"Conexión a "+ lcNameProd, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
1594 EW_GLOBAL._CodiPerfilCarregat =
".predet";
1604 public static void _Show()
1606 Forms.frmPrincipal loForm =
new Forms.frmPrincipal(
true);
1607 loForm.WindowState = FormWindowState.Maximized;
1609 loForm.ShowDialog();
1616 public static void RegisterTypesDependencyInjector()
1628 private static string ObtenerEmpresa(
string tcEmpresa)
1630 string lcEmpresa =
"";
1632 if (
string.IsNullOrEmpty(tcEmpresa))
1633 lcEmpresa = FUNCTIONS.LeerConfigIni(
"[EMPRESA]");
1635 lcEmpresa = tcEmpresa;
1637 string lcEmpNew = FUNCTIONS._ExisteEmpresa(lcEmpresa);
1638 if (
string.IsNullOrWhiteSpace(lcEmpresa) || lcEmpresa != lcEmpNew)
1639 FUNCTIONS._GuardarConfigIni(
"[EMPRESA]", lcEmpNew, _cPathInicio,
"config.ini");
bool _AutWin
Conexión por autentificación de Windows si o no.
static string GenerarChecksumOpciones(string tcOpcion, string tcSalt)
PE-102978: Generar una función hash segura a partir de una opción y un salt
Classe empresa basada en sage.ew.ewmante
static AddonsController Instance
Instancia al objeto singleton Addons
string _Ip
Servidor de la base de datos
Argumentos para los eventos lanzados por el addons en caso de error
static bool ReCargarDiccionarios()
Método para volver a realizar la carga de diccionarios, por si hay que actualizar algun valor (PE-908...
virtual void RegisterTypes()
Registra los tipos
bool _CargarAddOns(FunctionsDependencies loFuntionsDependencies)
Carga addons
bool _Add(Notificacion toNotificacion)
Añade una notificacion al sistema
Clase que captura y filtra mensajes de Windows (Capturar eventos).
static System.Drawing.Icon Sage50code
Busca un recurso adaptado de tipo System.Drawing.Icon similar a (Icono).
Clase Singleton para la carga de los diccionarios
Clase de recurso fuertemente tipado, para buscar cadenas traducidas, etc.
Clase para la clase de negocio de la configuración del live update
string _Server
Tipo de servidor de la base de datos
PE-85105: Clase donde se implementaran aquellas funciones de encriptación y desencriptación utilizand...
NotificaIconos
Iconos predefinidos para notificaciones Mirar sage.ew.objects.widgets.Notificador._GetDataTableSeleccion()
static bool CargarDiccionarios(string tcempresa, string tcCajaTpv)
A partir de un código de empresa y un código de caja nos carga las variables de empresa, mascaras, anchuras de campos standar y de TPV
Clase para uso de funciones genéricas
IAddonsManager AddonsManager
Gestor de Addons
Clase para gestionar registros del CFGCLISRV.XML.
Clase para el inicio de Sage 50
Clase para gestión de notificaciones
static Notifica _This
Instancia estática del objeto usuario con los datos del usuario actual (wc_usuario) ...
int _Port
Puerto del servidor de la base de datos.
Dependencias con functions
static void _RegisterReportsDataSourceIni(String lcPathSageReports)
Registra el Data Provider en el SageReport
bool _CargarAddons_WaitAll()
Esperar a que se hayan cargado todos los addons
Registra los tipos de Sage50
Clase estática de acceso a Base de Datos