2 using System.Collections.Generic;
14 using System.Threading.Tasks;
20 public static int _nHandleVfp = 0;
21 public static string _cdirectoryPath =
"";
22 public static string _cLicenciaSage50 =
"";
23 private static string _cPathLibrerias =
"";
26 public static string _cUserEurowin =
"";
27 public static string _cPasswordEurowin =
"";
28 public static string _cFormEurowin =
"";
29 public static string _cParamsFormEurowin =
"";
30 public static string _cGrupoParametro =
"";
33 private static bool _lAutomatico =
false;
39 public static void Main(
string[] tcArgs)
42 bool llDebug =
false, llSplash =
true, llSplashInfo =
false;
44 string lcNameProducto =
"Sage 50";
47 _cPathLibrerias = Application.StartupPath;
48 if (EntryControl(tcArgs))
51 ObtenerParametros(tcArgs);
53 if (lbRetorn && !Directory.Exists(_cPathLibrerias))
55 lcError +=
"- No existe la ruta de librerías: " + _cPathLibrerias + Environment.NewLine;
60 _cdirectoryPath = Directory.GetParent(_cPathLibrerias).FullName;
61 if (
string.IsNullOrWhiteSpace(_cdirectoryPath) || !Directory.Exists(_cdirectoryPath))
63 lcError +=
"- No existe la ruta de inicio: " + _cdirectoryPath + Environment.NewLine;
70 _cPathLibrerias = VersionNumber.DirectoryFullNameVersion(_cdirectoryPath);
71 if (lbRetorn && !Directory.Exists(_cPathLibrerias))
73 lcError +=
"- No existe la ruta de librerías: " + _cPathLibrerias + Environment.NewLine;
80 Control.CheckForIllegalCrossThreadCalls =
true;
85 if (_cUserEurowin.ToUpper().Trim() ==
"SAGESYSTEM" && _cPasswordEurowin.Trim().Length >= 64)
88 EW_GLOBAL._lSageSystem64 =
true;
96 MessageBox.Show(lcError, lcNameProducto, MessageBoxButtons.OK, MessageBoxIcon.Warning);
98 catch (InvalidOperationException)
102 using (
System.Diagnostics.EventLog eventLog =
new System.Diagnostics.EventLog(
"Application"))
104 eventLog.Source =
"Application";
105 eventLog.WriteEntry(lcError,
System.Diagnostics.EventLogEntryType.Error, 50);
108 NETVFP._CerrarHandle(_nHandleVfp);
113 DB.Registrar_Traza(
"Program.cs,Main_EnableVisualStyles");
114 Application.EnableVisualStyles();
115 Application.SetCompatibleTextRenderingDefault(
false);
120 main_s50._cPathInicio = _cdirectoryPath;
121 main_s50._lEsEjecutable =
true;
124 MostrarSplashInfo(out llSplash, out llSplashInfo, out llDebug);
127 EW_GLOBAL._lDebugMode = llDebug;
130 main_s50._frmSplash =
new Forms.frmSplash();
132 if (!_lAutomatico && llSplash)
134 main_s50._frmSplash._bMostrarInfo = llSplashInfo;
135 main_s50._frmSplash.Show();
137 while (main_s50._frmSplash._IsBusy)
139 Application.DoEvents();
143 lbRetorn = main_s50._frmSplash._Result;
148 DB.Registrar_Traza(
"Program.cs,Main_main_Sage_50");
149 lbRetorn = main_s50._main_Sage_50();
154 main_s50._ErrorString = !
string.IsNullOrEmpty(main_s50._ErrorString) ? main_s50._ErrorString +
System.Environment.NewLine + ex.Message : ex.Message;
162 DB.Registrar_Traza(
"Program.cs,Main_Run");
169 MessageBox.Show(main_s50._ErrorString, lcNameProducto +
" - Error en la validación de inicio", MessageBoxButtons.OK, MessageBoxIcon.Error);
171 catch (InvalidOperationException)
175 using (
System.Diagnostics.EventLog eventLog =
new System.Diagnostics.EventLog(
"Application"))
177 eventLog.Source =
"Application";
178 eventLog.WriteEntry(
"Error en la validacion de inicio: " + main_s50._ErrorString,
System.Diagnostics.EventLogEntryType.Error, 50);
181 main_s50._frmSplash.Close();
182 NETVFP._CerrarHandle(_nHandleVfp);
187 private static bool EntryControl(
string[] tcArgs)
191 DirectoryInfo loDirLibrerias;
194 if (!ParamControl(tcArgs) && !
System.Diagnostics.Debugger.IsAttached)
196 loDirLibrerias =
new DirectoryInfo(_cPathLibrerias);
197 lcPath = Path.Combine(loDirLibrerias.Parent.FullName,
"Sage50.exe");
200 if (File.Exists(lcPath))
203 SaveEngagedVersion(loDirLibrerias.Name, loDirLibrerias.Parent.FullName);
205 proc =
new Process();
206 proc.EnableRaisingEvents =
false;
207 proc.StartInfo.UseShellExecute =
false;
208 proc.StartInfo.FileName = lcPath;
209 proc.StartInfo.CreateNoWindow =
true;
210 proc.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
211 proc.StartInfo.Arguments =
string.Join(
" ", tcArgs);
212 proc.StartInfo.WorkingDirectory = loDirLibrerias.Parent.FullName;
222 private static void SaveEngagedVersion(
string tcVersion,
string tcPathConfig)
227 loConfigIni.
_Load(tcPathConfig,
"");
229 lcVersions = loConfigIni.
_Propiedad(
"[ACCESCONTROL]").Trim();
231 if(!lcVersions.Contains(tcVersion))
233 lcVersions =
String.IsNullOrEmpty(lcVersions) ? tcVersion : $
"{lcVersions}|{tcVersion}";
234 loConfigIni.
_Save(
"[ACCESCONTROL]", lcVersions, tcPathConfig);
238 private static bool ParamControl(
string[] tcArgs)
247 private static void MostrarSplashInfo(out
bool tlMostrarSplash, out
bool tlMostrarInfo, out
bool tlDebug)
250 tlMostrarSplash =
true;
251 tlMostrarInfo =
false;
255 string lcValor = Convert.ToString(FUNCTIONS.LeerConfigIni(
"[SPLASH]", _cdirectoryPath)).Trim().ToUpper();
257 tlMostrarSplash =
false;
261 lcValor = Convert.ToString(FUNCTIONS.LeerConfigIni(
"[SPLASH_INFO]", _cdirectoryPath)).Trim().ToUpper();
263 tlMostrarInfo =
true;
267 lcValor = Convert.ToString(FUNCTIONS.LeerConfigIni(
"[SQL_LOG]", _cdirectoryPath)).Trim().ToUpper();
276 private static void ObtenerParametros(
string[] tcArgs)
278 if (tcArgs != null && tcArgs.Count() > 0)
281 string lcParams = tcArgs[0].Trim().Substring(1);
282 DB.Registrar_Traza(
"Program.cs,Main_Parameters", lcParams);
285 string[] lcArgs = lcParams.Split(
'|');
287 if (lcArgs.Count() > 2)
292 foreach (
string lcArg
in lcArgs)
298 _cUserEurowin = lcArgs[0];
302 _cPasswordEurowin = lcArgs[1];
306 _cFormEurowin = lcArgs[2];
313 if (!
string.IsNullOrWhiteSpace(_cParamsFormEurowin) && lcArg ==
"ACCESODIRECTO")
314 _cParamsFormEurowin +=
"*";
316 _cParamsFormEurowin += lcArg;
323 if (tcArgs.Count() > 1)
326 var result = Array.Find(tcArgs, param => param.Length == 11 && param.Substring(0, 6) ==
"/GRUPO");
329 _cGrupoParametro =
"COMU" + result.Substring(7);
337 private static void _Run()
340 Thread.CurrentThread.Name =
"MainThread";
343 EW_GLOBAL._CodiPerfilCarregat =
".predet";
346 DB.Registrar_Traza(
"Program.cs,Main_frmPrincipal");
347 Application.Run(
new Forms.frmPrincipal());
356 private static void CopiarConfigIni()
358 string lcFile = Path.Combine(main_s50._cPathInicio,
"config.ini");
359 string lcFileBak = Path.Combine(main_s50._cPathInicio,
"config.bak");
363 if (File.Exists(lcFile))
364 File.Copy(lcFile, lcFileBak,
true);
Clase para la actualización de librerias de Sage50
static string ParamControl
Parametro de control para saber si se lanza correctamente
Gestión de variables entorno del config.ini
bool _Save()
Salvar todas las etiquetas de memoria en disco en rutas por defecto
void _Load()
Cargar todas las etiquetas de memoria de disco de rutas por defecto
string _Propiedad(string key)
Devuelve el valor de la propiedad indicada