2 using System.Collections.Generic;
20 public static class PEP
24 const string COMILLAS =
"\"";
29 private static string _cMainEXEFileName =
"";
32 private static string _cUserId =
"";
35 private static string _cCustomerId =
"";
38 private static string _cDivision =
"";
41 private static string _cLicensePlate =
"";
44 private static DateTime _dFechaSincro = DateTime.MinValue;
47 private static string _cApplicationNameAndVersion =
"";
50 private static int _nValue = 2;
68 private static bool _lSage50 =
false;
71 private static string _cAppName =
"sagetpv";
74 private static DataTable _dtControles = null;
76 #endregion PROPIEDADES 89 #endregion CONSTRUCTORES 92 #region METODOS PRIVADOS 98 private static DataTable Obtener_Controles()
100 DataTable ldtControles =
new DataTable();
102 string lcSql =
"SELECT clase, MAX(libreria) as libreria, MAX(nombre) as nombre FROM "+DB.SQLDatabase(
"COMUNES",
"OBJETOS");
105 lcSql +=
" WHERE s50 = " + DB.SQLString(_lSage50);
107 lcSql +=
" GROUP BY clase";
109 DB.SQLExec(lcSql, ref ldtControles);
112 foreach (DataRow loFila
in ldtControles.Rows)
114 loFila[
"clase"] = loFila[
"clase"].ToString().ToLower().Trim();
116 ldtControles.PrimaryKey =
new DataColumn[] { ldtControles.Columns[
"clase"] };
128 private static bool Execute_pep(
string tcParams,
bool tlSincron=
false)
131 string lcParams =
"", lcRutaExe=
"";
157 if (!Convert.ToBoolean(EW_GLOBAL._GetVariable(
"wl_EsEjecutable")))
161 if (LICENCIAS._EsLicenciaParaPruebas)
169 lcParams =
"-EXE=" + COMILLAS + _cMainEXEFileName.Trim() + COMILLAS +
" -USER=" + _cUserId +
" -LICENSEPLATE=" + COMILLAS + _cLicensePlate + COMILLAS +
" " + tcParams;
172 lcRutaExe = Path.Combine(EW_GLOBAL._GetVariable(
"wc_PathInicio").ToString(),
@"librerias\Sage.PEP.exe");
175 Process loProcess =
new Process();
176 ProcessStartInfo loExePep =
new ProcessStartInfo(lcRutaExe);
177 loExePep.Arguments = lcParams;
178 loProcess.StartInfo = loExePep;
182 llOk = loProcess.Start();
184 loProcess.WaitForExit();
186 catch (Exception loEx)
188 DB.Registrar_Error(loEx);
190 MessageBox.Show(
"Se ha detectado alguna incidencia en la ejecución del PEP Service."+Environment.NewLine+loEx.Message,
"Pep Service",MessageBoxButtons.OK,MessageBoxIcon.Error);
202 private static bool Enviar_Opcion(
string tcNombreOpcion,
bool tlEdicion)
205 string lcParams =
"",lcModulo=
"";
208 if (LICENCIAS._EsLicenciaParaPruebas)
220 if (EW_GLOBAL._EdicionPerfiles && !tlEdicion)
224 tcNombreOpcion = LimpiarDatosBasura(tcNombreOpcion);
228 lcModulo = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_modulo")).ToLower().Trim();
231 tcNombreOpcion = _cAppName +
"_"+tcNombreOpcion;
238 lcParams =
" -CUSTOMERID=" + COMILLAS + _cCustomerId + COMILLAS +
239 " -DIVISION=" + COMILLAS + _cDivision + COMILLAS +
240 " -FORM=" + COMILLAS + tcNombreOpcion + COMILLAS +
241 " -UISOURCE=" + COMILLAS + lcModulo + COMILLAS +
242 " -VERSION=" + COMILLAS + _cApplicationNameAndVersion + COMILLAS;
244 llOk = Execute_pep(lcParams);
254 private static string LimpiarDatosBasura(
string tcNombreOpcion)
256 tcNombreOpcion = QuitarLiteral(tcNombreOpcion,
"(sólolectura)");
257 tcNombreOpcion = QuitarLiteral(tcNombreOpcion,
"(bajasuscripción)");
258 tcNombreOpcion = QuitarLiteral(tcNombreOpcion,
"(sql_log)");
260 tcNombreOpcion = RecortarHastaLiteral(tcNombreOpcion,
"browser_listadodeplanesanalíticosdelacuentacontable");
261 tcNombreOpcion = RecortarHastaLiteral(tcNombreOpcion,
"frmobserv_observacionesdelcliente");
263 if (tcNombreOpcion.Contains(
"frmdoccompra"))
265 tcNombreOpcion = RecortarHastaLiteral(tcNombreOpcion,
"frmdoccompraalbaran");
266 tcNombreOpcion = RecortarHastaLiteral(tcNombreOpcion,
"frmdoccompradeposito");
267 tcNombreOpcion = RecortarHastaLiteral(tcNombreOpcion,
"frmdoccomprafactura");
268 tcNombreOpcion = RecortarHastaLiteral(tcNombreOpcion,
"frmdoccomprapedido");
269 tcNombreOpcion = RecortarHastaLiteral(tcNombreOpcion,
"frmdoccomprapropuesta");
272 if (tcNombreOpcion.Contains(
"frmdocventa"))
274 tcNombreOpcion = RecortarHastaLiteral(tcNombreOpcion,
"frmdocventaalbaran");
275 tcNombreOpcion = RecortarHastaLiteral(tcNombreOpcion,
"frmdocventadeposito");
276 tcNombreOpcion = RecortarHastaLiteral(tcNombreOpcion,
"frmdocventafra");
277 tcNombreOpcion = RecortarHastaLiteral(tcNombreOpcion,
"frmdocventaped");
278 tcNombreOpcion = RecortarHastaLiteral(tcNombreOpcion,
"frmdocventapresupuesto");
279 tcNombreOpcion = RecortarHastaLiteral(tcNombreOpcion,
"frmdocventatpv");
282 return tcNombreOpcion;
291 private static string QuitarLiteral(
string tcNombreOpcion,
string tcLiteral)
293 if (tcNombreOpcion.Contains(tcLiteral))
294 tcNombreOpcion = tcNombreOpcion.Replace(tcLiteral,
"");
296 return tcNombreOpcion;
305 private static string RecortarHastaLiteral(
string tcNombreOpcion,
string tcLiteral)
307 if (tcNombreOpcion.Contains(tcLiteral))
309 int lnPos = tcNombreOpcion.IndexOf(tcLiteral);
312 lnPos = lnPos + tcLiteral.Length;
313 tcNombreOpcion = tcNombreOpcion.Substring(0, lnPos);
317 return tcNombreOpcion;
320 #endregion METODOS PRIVADOS 323 #region METODOS PUBLICOS 328 public static void _Inicializar()
331 if (!Convert.ToBoolean(EW_GLOBAL._GetVariable(
"wl_EsEjecutable")))
335 if (LICENCIAS._EsLicenciaParaPruebas)
343 _lSage50 = Convert.ToBoolean(EW_GLOBAL._GetVariable(
"wl_Sage50"));
344 _cAppName = (_lSage50 ?
"sage50" :
"sagetpv");
349 object loInternal = LICENCIAS._ObtenerAtributoSagelic(
"internal.user");
350 if (loInternal != null && Convert.ToString(loInternal).ToLower().Trim() ==
"yes")
356 Dictionary<string, object> loDicCodCom = DB.SQLREGValor(
"codcom",
"1",
"1",
"comunes");
357 if (loDicCodCom.Count <= 0)
361 _cMainEXEFileName = Path.Combine(EW_GLOBAL._GetVariable(
"wc_PathInicio").ToString(), (_lSage50 ?
"Sage50.exe" :
"Eurowin.exe"));
364 _cLicensePlate = EW_GLOBAL._GetVariable(
"wc_ewlicencia").ToString();
367 if (loDicCodCom.TryGetValue(
"sageid", out loObj))
368 _cCustomerId = loObj.ToString().Trim();
376 if (loDicCodCom.TryGetValue(
"productname", out loObj))
377 _cApplicationNameAndVersion = loObj.ToString().Trim();
380 if (loDicCodCom.TryGetValue(
"version", out loObj))
381 _cApplicationNameAndVersion +=
" " + loDicCodCom[
"version"].ToString().Trim();
384 if (loDicCodCom.TryGetValue(
"pepvalue", out loObj))
385 _nValue = Convert.ToInt32(loObj);
390 _dtControles = Obtener_Controles();
399 public static bool _Login()
407 string lcParams =
" -VERSION=" + COMILLAS + _cApplicationNameAndVersion + COMILLAS +
" "+
410 llOk = Execute_pep(lcParams);
422 public static bool _Control(Control toControl,
bool tlEdicion=
false)
425 string lcExcluir =
"messageboxtactil,frmprincipal,frmlogin,btdocsalir";
427 if (toControl == null)
431 string lcNombreControl = toControl.Name.ToLower().Trim();
432 if (
string.IsNullOrWhiteSpace(lcNombreControl))
436 if (lcExcluir.Contains(lcNombreControl))
440 if ((toControl is CheckBox) && toControl.FindForm() != null && (toControl.FindForm().Name.ToLower().Trim() ==
"frmempresa"))
442 lcNombreControl =
"opcemp_" + (((CheckBox)toControl).Checked ?
"marked" :
"unmarked") +
"_" + toControl.Text.ToLower().Replace(
" ",
"").Trim();
443 return Enviar_Opcion(lcNombreControl,
false);
447 if ((toControl is CheckBox) && toControl.FindForm() != null && (toControl.FindForm().Name.ToLower().Trim() ==
"frmgruposemp") && lcNombreControl ==
"chkbackup")
449 lcNombreControl =
"chkbackup_" + (((CheckBox)toControl).Checked ?
"marked" :
"unmarked") +
"_" + toControl.Text.ToLower().Replace(
" ",
"").Trim();
450 return Enviar_Opcion(lcNombreControl,
false);
454 if (toControl is Form)
458 lcText = (toControl is
IFormBase) ? ((
IFormBase)toControl)._ObtenerText(
false) : toControl.Text;
459 lcText = lcText.ToLower().Trim().Replace(
" ",
"");
461 return Enviar_Opcion(lcNombreControl +
"_" + lcText, tlEdicion);
465 if (toControl is Button && toControl.GetType().GetProperty(
"_GoogleAnalytics") != null && ((
IGoogleAnalitics)toControl)._GoogleAnalytics)
467 return Enviar_Opcion(lcNombreControl +
"_" + toControl.Text.ToLower().Trim().Replace(
" ",
""), tlEdicion);
471 if (_dtControles != null && _dtControles.Rows.Count > 0)
473 llOk = (_dtControles.Rows.Find(lcNombreControl) != null);
478 return Enviar_Opcion(lcNombreControl,tlEdicion);
490 public static bool _Opcion(
string tcOpcion,
bool tlEdicion=
false)
492 if (
string.IsNullOrWhiteSpace(tcOpcion))
495 return Enviar_Opcion(tcOpcion,tlEdicion);
498 #endregion METODOS PUBLICOS
Interfaz para Google Analitics