4 using System.Collections.Generic;
17 private DataTable _dtUsuarios =
new DataTable();
18 private string _GrupoDestino;
19 private bool multiplesGrupos =
false;
24 private string idSage50 = DB.SQLValor(
"GRUPOSEMP",
"CODIGO",
GrupoEmpresa.
_CodigoGrupoActual().ToString().Trim(),
"IDSAGE50",
"EUROWINSYS").ToString().Trim();
26 private DataTable _dtUniusers = null;
27 private DataTable _dtAccesoGrup = null;
28 private DataTable _dtOtrosGruposUsers = null;
29 internal string _RutaOrigenTempRestauracion =
"";
42 internal void _ObtenerDatosUnificacionUsuariosActual(
string tcGrupoDestino)
44 string lcSql =
"SELECT uni.idusuario AS idusuario_uniuser, usu.* " +
45 "FROM " + DB.SQLDatabaseReal(
"EUROWINSYS",
"UNIUSERS") +
" AS uni " +
46 "LEFT JOIN " + DB.SQLDatabase(
"COMUNES",
"USUARIOS") +
" AS usu on uni.idusuario = usu.idusuario " +
47 "WHERE uni.idsage50 = " + DB.SQLString(idSage50) +
" " +
49 "SELECT '' AS idusuario, usu.* " +
50 "FROM " + DB.SQLDatabase(
"COMUNES",
"USUARIOS") +
" AS usu " +
51 "WHERE idusuario = '' and cloudid = 0";
53 DB.SQLExec(lcSql, ref _dtUsuarios);
56 string lcGrupoPripal = GrupoempTools._Obtener_CodGrupoPripal(tcGrupoDestino);
57 DataTable ldtTempGrupos = GrupoempTools.ObtenerTodosLosGrupos(lcGrupoPripal);
58 if (ldtTempGrupos != null && ldtTempGrupos.Rows.Count > 1)
59 multiplesGrupos =
true;
61 multiplesGrupos =
false;
68 internal void RestaurarProcesosUnificacionUsuarios(
string tcGrupoDestino)
70 _GrupoDestino = tcGrupoDestino;
76 var usuariosUnificadosDestino = _dtUsuarios
78 .Where(r => !
string.IsNullOrWhiteSpace(r.Field<
string>(
"idusuario")));
80 if (usuariosUnificadosDestino.Count() > 0)
83 ProcesosRevisionUsuarios();
88 NingunUsuarioUnificadoDestino();
94 ProcesoRevisionUsuarioUnicoGrupo();
101 private void NingunUsuarioUnificadoDestino()
104 string lcSql =
"UPDATE " + DB.SQLDatabaseReal(
"COMU" + _GrupoDestino,
"USUARIOS") +
" SET idusuario = " + DB.SQLString(
"") +
", cloudid = 0 ";
111 private void ProcesosRevisionUsuarios()
113 DataTable ldtUsuarios =
new DataTable();
115 string lcSql =
"SELECT codigo, nombre, idusuario, cloudid FROM " + DB.SQLDatabaseReal(
"COMU" + _GrupoDestino,
"USUARIOS");
116 DB.SQLExec(lcSql, ref ldtUsuarios);
117 if (ldtUsuarios != null && ldtUsuarios.Rows.Count > 0)
120 foreach (DataRow ldr
in ldtUsuarios.Rows)
122 var usuarioExiste = _dtUsuarios
124 .Where(r => r.Field<
object>(
"codigo") != null && r.Field<
object>(
"codigo") != DBNull.Value && r.Field<
string>(
"codigo").Trim() == Convert.ToString(ldr[
"codigo"]).Trim());
125 if (usuarioExiste.Count() > 0)
128 UsuarioExisteDestino(ldr);
133 if (ComprobarUsuarioExisteOtrosGrupos(ldr))
135 UsuarioExisteOtrosGrupos(ldr);
140 UsuarioNOExisteDestino(ldr);
147 var usuariosUnificadosDestino = _dtUsuarios
149 .Where(r => !
string.IsNullOrWhiteSpace(r.Field<
string>(
"idusuario"))).ToList();
151 foreach (DataRow ldr
in usuariosUnificadosDestino)
153 DataRow[] usuario = ldtUsuarios.Select(
"codigo = '" + ldr[
"codigo"] +
"'");
154 if (usuario.Length == 0)
157 UsuarioExisteDestinoNOOrigen(ldr);
163 var usuariosUnificadosDestinoFaltaUsuario = _dtUsuarios
165 .Where(r => r.Field<
object>(
"codigo") == null || r.Field<
object>(
"codigo") == DBNull.Value).ToList();
166 foreach (DataRow ldr
in usuariosUnificadosDestinoFaltaUsuario)
169 List<DataRow> usuarioDestino;
170 if (ComprobarOtrosGruposIdUsuario(
"", Convert.ToString(ldr[
"idusuario_uniuser"]).Trim(), out usuarioDestino))
172 DataTable ldtTemp =
new DataTable();
173 lcSql =
"SELECT * FROM " + DB.SQLDatabaseReal(
"COMU" + _GrupoDestino,
"USUARIOS") +
" WHERE codigo = " + DB.SQLString(Convert.ToString(usuarioDestino[0][
"codigo"]).Trim());
174 DB.SQLExec(lcSql, ref ldtTemp);
178 if (ldtTemp != null && ldtTemp.Rows.Count == 0)
180 UnificarUsuario(Convert.ToString(usuarioDestino[0][
"codigo"]).Trim(), usuarioDestino,
false, 0);
190 private void UsuarioExisteDestino(DataRow ldr)
193 List<DataRow> usuarioDestino = _dtUsuarios
195 .Where(r => r.Field<
object>(
"codigo") != null && r.Field<
object>(
"codigo") != DBNull.Value && r.Field<
string>(
"codigo").Trim() == Convert.ToString(ldr[
"codigo"]).Trim()).ToList();
197 if (
string.IsNullOrWhiteSpace(Convert.ToString(usuarioDestino[0][
"idusuario"])))
202 LimpiarDatosUnificacionUsuario(Convert.ToString(ldr[
"codigo"]).Trim());
204 else if (!
string.IsNullOrWhiteSpace(Convert.ToString(usuarioDestino[0][
"idusuario"])))
210 UnificarUsuario(Convert.ToString(ldr[
"codigo"]).Trim(), usuarioDestino, !
string.IsNullOrWhiteSpace(Convert.ToString(ldr[
"idusuario"])));
218 private void UsuarioExisteOtrosGrupos(DataRow ldr)
224 List<DataRow> usuarioDestino;
225 if (ComprobarOtrosGruposIdUsuario(Convert.ToString(ldr[
"codigo"]).Trim(),
"", out usuarioDestino))
227 UnificarUsuario(Convert.ToString(ldr[
"codigo"]).Trim(), usuarioDestino, !
string.IsNullOrWhiteSpace(Convert.ToString(ldr[
"idusuario"])));
233 LimpiarDatosUnificacionUsuario(Convert.ToString(ldr[
"codigo"]).Trim());
241 private void LimpiarDatosUnificacionUsuario(
string tcUsuario)
244 string lcSql =
"UPDATE " + DB.SQLDatabaseReal(
"COMU" + _GrupoDestino,
"USUARIOS") +
" SET idusuario = " + DB.SQLString(
"") +
", cloudid = 0 " +
245 "WHERE codigo = " + DB.SQLString(tcUsuario);
256 private void UnificarUsuario(
string tcUsuario, List<DataRow> usuarioDestino,
bool tbUnificadoCopia,
int nivelAccesogrup = 10)
259 GuardarDatosUsuarioDestino(tcUsuario, usuarioDestino);
261 string lcSql =
"DELETE FROM " + DB.SQLDatabaseReal(
"EUROWINSYS",
"ACCESOGRUP") +
" WHERE idsage50 = " + DB.SQLString(idSage50) +
262 " AND grupo = " + DB.SQLString(_GrupoDestino) +
" AND usuario = " + DB.SQLString(tcUsuario);
265 string lcNivelAcceso;
266 if (tbUnificadoCopia)
268 List<DataRow> registroAccesogrup = _dtAccesoGrup
270 .Where(r => r.Field<
string>(
"usuario").Trim() == tcUsuario).ToList();
271 if (registroAccesogrup != null && registroAccesogrup.Count() > 0)
273 if (nivelAccesogrup == 10)
275 lcNivelAcceso = Convert.ToString(registroAccesogrup[0][
"nivel"]);
279 lcNivelAcceso = Convert.ToString(nivelAccesogrup);
282 lcSql =
"INSERT INTO " + DB.SQLDatabase(
"EUROWINSYS",
"ACCESOGRUP") +
" (idsage50, grupo, modulo, usuario, nivel) " +
283 "VALUES (" + DB.SQLString(idSage50) +
", " + DB.SQLString(_GrupoDestino) +
", " + DB.SQLString(
"SEL_GRUPO") +
284 ", " + DB.SQLString(tcUsuario) +
", " + lcNivelAcceso +
")";
290 if (nivelAccesogrup == 10)
296 lcNivelAcceso = Convert.ToString(nivelAccesogrup);
298 lcSql =
"INSERT INTO " + DB.SQLDatabaseReal(
"EUROWINSYS",
"ACCESOGRUP") +
" (idsage50, grupo, modulo, usuario, nivel) " +
299 " VALUES(" + DB.SQLString(idSage50) +
", " + DB.SQLString(_GrupoDestino) +
", " + DB.SQLString(
"SEL_GRUPO") +
", " + DB.SQLString(tcUsuario) +
", " + lcNivelAcceso +
")";
305 private void GuardarDatosUsuarioDestino(
string tcUsuario, List<DataRow> usuarioDestino,
string tcGrupo =
"")
307 string lcGrupoDestino;
308 if (!
string.IsNullOrWhiteSpace(tcGrupo))
310 lcGrupoDestino = tcGrupo;
314 lcGrupoDestino = _GrupoDestino;
317 DataTable ldtTemp =
new DataTable();
318 string lcSql =
"SELECT * FROM " + DB.SQLDatabaseReal(
"COMU" + lcGrupoDestino,
"USUARIOS") +
" WHERE codigo = " + DB.SQLString(tcUsuario);
319 DB.SQLExec(lcSql, ref ldtTemp);
321 if (ldtTemp == null || ldtTemp.Rows.Count == 0)
324 lcSql =
"INSERT INTO " + DB.SQLDatabaseReal(
"COMU" + lcGrupoDestino,
"USUARIOS") +
325 "(codigo, idusuario, cloudid, nombre, clave, r_pantalla, r_usuario, r_expulsar, entrada, mensaje, nombremail, mail, smtp, autenticado, usermail, clavemail, firma," +
326 " topinfo, leftinfo, maxinfo, verinfo, pag, propied, favoritos, pregunta, respuesta, ok, cifradossl, smtpport, ultopcion, fec_valida, dominio, usr_real," +
327 " pep, ult_fecha, terminal, dashboard, clientid, refreshtoken, resourceids, usercalendars, foto, guid_id, created, modified" +
328 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"VISIBLE") ?
", visible" :
"") +
329 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"NOVICAP") ?
", novicap" :
"") +
330 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"NOMBREPER") ?
", nombreper" :
"") +
331 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"APELLIDOS") ?
", apellidos" :
"") +
332 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"TELEFONO") ?
", telefono" :
"") +
333 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"FECHAPWD") ?
", fechapwd" :
"") +
334 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"VALIDEZPWD") ?
", validezpwd" :
"") +
335 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"OLDPWDS") ?
", oldpwds" :
"") +
336 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"CONFNOT") ?
", confnot" :
"") +
337 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"ETICOMU") ?
", eticomu" :
"") +
338 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"FBLOQNOCAR") ?
", fbloqnocar" :
"") +
339 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"FBLOQNOEMA") ?
", fbloqnoema" :
"") +
340 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"NOCOMUCAR") ?
", nocomucar" :
"") +
341 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"NOCOMUEMA") ?
", nocomuema" :
"") +
342 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"NOCOMUOBS") ?
", nocomuobs" :
"") +
343 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"CODPOST") ?
", codpost" :
"") +
344 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"DIRECCION") ?
", direccion" :
"") +
345 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"PAIS") ?
", pais" :
"") +
346 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"POBLACION") ?
", poblacion" :
"") +
347 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"PROVINCIA") ?
", provincia" :
"") +
348 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"SINCUENTA") ?
", sincuenta" :
"") +
350 DB.SQLString(tcUsuario) +
351 ", " + DB.SQLString(Convert.ToString(usuarioDestino[0][
"idusuario"]).Trim()) +
353 ", " + DB.SQLString(usuarioDestino[0][
"nombre"]) +
354 ", " + DB.SQLString(usuarioDestino[0][
"clave"]) +
355 ", " + DB.SQLString(usuarioDestino[0][
"r_pantalla"]) +
356 ", " + DB.SQLString(usuarioDestino[0][
"r_usuario"]) +
357 ", " + DB.SQLString(usuarioDestino[0][
"r_expulsar"]) +
358 ", " + DB.SQLString(usuarioDestino[0][
"entrada"]) +
359 ", " + DB.SQLString(usuarioDestino[0][
"mensaje"]) +
360 ", " + DB.SQLString(usuarioDestino[0][
"nombremail"]) +
361 ", " + DB.SQLString(usuarioDestino[0][
"mail"]) +
362 ", " + DB.SQLString(usuarioDestino[0][
"smtp"]) +
363 ", " + DB.SQLString(usuarioDestino[0][
"autenticado"]) +
364 ", " + DB.SQLString(usuarioDestino[0][
"usermail"]) +
365 ", " + DB.SQLString(usuarioDestino[0][
"clavemail"]) +
366 ", " + DB.SQLString(usuarioDestino[0][
"firma"]) +
367 ", " + DB.SQLString(usuarioDestino[0][
"topinfo"]) +
368 ", " + DB.SQLString(usuarioDestino[0][
"leftinfo"]) +
369 ", " + DB.SQLString(usuarioDestino[0][
"maxinfo"]) +
370 ", " + DB.SQLString(usuarioDestino[0][
"verinfo"]) +
371 ", " + DB.SQLString(usuarioDestino[0][
"pag"]) +
372 ", " + DB.SQLString(usuarioDestino[0][
"propied"]) +
373 ", " + DB.SQLString(usuarioDestino[0][
"favoritos"]) +
374 ", " + DB.SQLString(usuarioDestino[0][
"pregunta"]) +
375 ", " + DB.SQLString(usuarioDestino[0][
"respuesta"]) +
376 ", " + DB.SQLString(usuarioDestino[0][
"ok"]) +
377 ", " + DB.SQLString(usuarioDestino[0][
"cifradossl"]) +
378 ", " + DB.SQLString(usuarioDestino[0][
"smtpport"]) +
379 ", " + DB.SQLString(usuarioDestino[0][
"ultopcion"]) +
380 ", " + DB.SQLString(usuarioDestino[0][
"fec_valida"]) +
381 ", " + DB.SQLString(usuarioDestino[0][
"dominio"]) +
382 ", " + DB.SQLString(usuarioDestino[0][
"usr_real"]) +
383 ", " + DB.SQLString(usuarioDestino[0][
"pep"]) +
384 ", " + DB.SQLString(usuarioDestino[0][
"ult_fecha"]) +
385 ", " + DB.SQLString(usuarioDestino[0][
"terminal"]) +
386 ", " + DB.SQLString(usuarioDestino[0][
"dashboard"]) +
387 ", " + DB.SQLString(usuarioDestino[0][
"clientid"]) +
388 ", " + DB.SQLString(usuarioDestino[0][
"refreshtoken"]) +
389 ", " + DB.SQLString(usuarioDestino[0][
"resourceids"]) +
390 ", " + DB.SQLString(usuarioDestino[0][
"usercalendars"]) +
391 ", " + DB.SQLString(usuarioDestino[0][
"foto"]) +
392 ", " + DB.SQLString(usuarioDestino[0][
"guid_id"]) +
393 ", " + DB.SQLString(usuarioDestino[0][
"created"]) +
394 ", " + DB.SQLString(usuarioDestino[0][
"modified"]) +
395 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"VISIBLE") ?
", " + DB.SQLString(usuarioDestino[0][
"visible"]) :
"") +
396 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"NOVICAP") ?
", " + DB.SQLString(usuarioDestino[0][
"novicap"]) :
"") +
397 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"NOMBREPER") ?
", " + DB.SQLString(usuarioDestino[0][
"nombreper"]) :
"") +
398 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"APELLIDOS") ?
", " + DB.SQLString(usuarioDestino[0][
"apellidos"]) :
"") +
399 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"TELEFONO") ?
", " + DB.SQLString(usuarioDestino[0][
"telefono"]) :
"") +
400 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"FECHAPWD") ?
", " + DB.SQLString(usuarioDestino[0][
"fechapwd"]) :
"") +
401 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"VALIDEZPWD") ?
", " + DB.SQLString(usuarioDestino[0][
"validezpwd"]) :
"") +
402 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"OLDPWDS") ?
", " + DB.SQLString(usuarioDestino[0][
"oldpwds"]) :
"") +
403 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"CONFNOT") ?
", " + DB.SQLString(usuarioDestino[0][
"confnot"]) :
"") +
404 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"ETICOMU") ?
", " + DB.SQLString(usuarioDestino[0][
"eticomu"]) :
"") +
405 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"FBLOQNOCAR") ?
", " + DB.SQLString(usuarioDestino[0][
"fbloqnocar"]) :
"") +
406 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"FBLOQNOEMA") ?
", " + DB.SQLString(usuarioDestino[0][
"fbloqnoema"]) :
"") +
407 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"NOCOMUCAR") ?
", " + DB.SQLString(usuarioDestino[0][
"nocomucar"]) :
"") +
408 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"NOCOMUEMA") ?
", " + DB.SQLString(usuarioDestino[0][
"nocomuema"]) :
"") +
409 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"NOCOMUOBS") ?
", " + DB.SQLString(usuarioDestino[0][
"nocomuobs"]) :
"") +
410 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"CODPOST") ?
", " + DB.SQLString(usuarioDestino[0][
"codpost"]) :
"") +
411 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"DIRECCION") ?
", " + DB.SQLString(usuarioDestino[0][
"direccion"]) :
"") +
412 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"PAIS") ?
", " + DB.SQLString(usuarioDestino[0][
"pais"]) :
"") +
413 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"POBLACION") ?
", " + DB.SQLString(usuarioDestino[0][
"poblacion"]) :
"") +
414 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"PROVINCIA") ?
", " + DB.SQLString(usuarioDestino[0][
"provincia"]) :
"") +
415 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"SINCUENTA") ?
", " + DB.SQLString(usuarioDestino[0][
"sincuenta"]) :
"") +
422 lcSql =
"UPDATE " + DB.SQLDatabaseReal(
"COMU" + lcGrupoDestino,
"USUARIOS") +
" SET idusuario = " + DB.SQLString(Convert.ToString(usuarioDestino[0][
"idusuario"]).Trim()) +
424 ", nombre = " + DB.SQLString(usuarioDestino[0][
"nombre"]) +
425 ", clave = " + DB.SQLString(usuarioDestino[0][
"clave"]) +
426 ", r_pantalla = " + DB.SQLString(usuarioDestino[0][
"r_pantalla"]) +
427 ", r_usuario = " + DB.SQLString(usuarioDestino[0][
"r_usuario"]) +
428 ", r_expulsar = " + DB.SQLString(usuarioDestino[0][
"r_expulsar"]) +
429 ", entrada = " + DB.SQLString(usuarioDestino[0][
"entrada"]) +
430 ", mensaje = " + DB.SQLString(usuarioDestino[0][
"mensaje"]) +
431 ", nombremail = " + DB.SQLString(usuarioDestino[0][
"nombremail"]) +
432 ", mail = " + DB.SQLString(usuarioDestino[0][
"mail"]) +
433 ", smtp = " + DB.SQLString(usuarioDestino[0][
"smtp"]) +
434 ", autenticado = " + DB.SQLString(usuarioDestino[0][
"autenticado"]) +
435 ", usermail = " + DB.SQLString(usuarioDestino[0][
"usermail"]) +
436 ", clavemail = " + DB.SQLString(usuarioDestino[0][
"clavemail"]) +
437 ", firma = " + DB.SQLString(usuarioDestino[0][
"firma"]) +
438 ", topinfo = " + DB.SQLString(usuarioDestino[0][
"topinfo"]) +
439 ", leftinfo = " + DB.SQLString(usuarioDestino[0][
"leftinfo"]) +
440 ", maxinfo = " + DB.SQLString(usuarioDestino[0][
"maxinfo"]) +
441 ", verinfo = " + DB.SQLString(usuarioDestino[0][
"verinfo"]) +
442 ", pag = " + DB.SQLString(usuarioDestino[0][
"pag"]) +
443 ", propied = " + DB.SQLString(usuarioDestino[0][
"propied"]) +
444 ", favoritos = " + DB.SQLString(usuarioDestino[0][
"favoritos"]) +
445 ", pregunta = " + DB.SQLString(usuarioDestino[0][
"pregunta"]) +
446 ", respuesta = " + DB.SQLString(usuarioDestino[0][
"respuesta"]) +
447 ", ok = " + DB.SQLString(usuarioDestino[0][
"ok"]) +
448 ", cifradossl = " + DB.SQLString(usuarioDestino[0][
"cifradossl"]) +
449 ", smtpport = " + DB.SQLString(usuarioDestino[0][
"smtpport"]) +
450 ", ultopcion = " + DB.SQLString(usuarioDestino[0][
"ultopcion"]) +
451 ", fec_valida = " + DB.SQLString(usuarioDestino[0][
"fec_valida"]) +
452 ", dominio = " + DB.SQLString(usuarioDestino[0][
"dominio"]) +
453 ", usr_real = " + DB.SQLString(usuarioDestino[0][
"usr_real"]) +
454 ", pep = " + DB.SQLString(usuarioDestino[0][
"pep"]) +
455 ", ult_fecha = " + DB.SQLString(usuarioDestino[0][
"ult_fecha"]) +
456 ", terminal = " + DB.SQLString(usuarioDestino[0][
"terminal"]) +
457 ", dashboard = " + DB.SQLString(usuarioDestino[0][
"dashboard"]) +
458 ", clientid = " + DB.SQLString(usuarioDestino[0][
"clientid"]) +
459 ", refreshtoken = " + DB.SQLString(usuarioDestino[0][
"refreshtoken"]) +
460 ", resourceids = " + DB.SQLString(usuarioDestino[0][
"resourceids"]) +
461 ", usercalendars = " + DB.SQLString(usuarioDestino[0][
"usercalendars"]) +
462 ", foto = " + DB.SQLString(usuarioDestino[0][
"foto"]) +
463 ", guid_id = " + DB.SQLString(usuarioDestino[0][
"guid_id"]) +
464 ", created = " + DB.SQLString(usuarioDestino[0][
"created"]) +
465 ", modified = " + DB.SQLString(usuarioDestino[0][
"modified"]) +
466 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"VISIBLE") ?
", visible = " + DB.SQLString(usuarioDestino[0][
"visible"]) :
"") +
467 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"NOVICAP") ?
", novicap = " + DB.SQLString(usuarioDestino[0][
"novicap"]) :
"") +
468 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"NOMBREPER") ?
", nombreper = " + DB.SQLString(usuarioDestino[0][
"nombreper"]) :
"") +
469 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"APELLIDOS") ?
", apellidos = " + DB.SQLString(usuarioDestino[0][
"apellidos"]) :
"") +
470 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"TELEFONO") ?
", telefono = " + DB.SQLString(usuarioDestino[0][
"telefono"]) :
"") +
471 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"FECHAPWD") ?
", fechapwd = " + DB.SQLString(usuarioDestino[0][
"fechapwd"]) :
"") +
472 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"VALIDEZPWD") ?
", validezpwd = " + DB.SQLString(usuarioDestino[0][
"validezpwd"]) :
"") +
473 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"OLDPWDS") ?
", oldpwds = " + DB.SQLString(usuarioDestino[0][
"oldpwds"]) :
"") +
474 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"CONFNOT") ?
", confnot = " + DB.SQLString(usuarioDestino[0][
"confnot"]) :
"") +
475 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"ETICOMU") ?
", eticomu = " + DB.SQLString(usuarioDestino[0][
"eticomu"]) :
"") +
476 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"FBLOQNOCAR") ?
", fbloqnocar = " + DB.SQLString(usuarioDestino[0][
"fbloqnocar"]) :
"") +
477 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"FBLOQNOEMA") ?
", fbloqnoema = " + DB.SQLString(usuarioDestino[0][
"fbloqnoema"]) :
"") +
478 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"NOCOMUCAR") ?
", nocomucar = " + DB.SQLString(usuarioDestino[0][
"nocomucar"]) :
"") +
479 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"NOCOMUEMA") ?
", nocomuema = " + DB.SQLString(usuarioDestino[0][
"nocomuema"]) :
"") +
480 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"NOCOMUOBS") ?
", nocomuobs = " + DB.SQLString(usuarioDestino[0][
"nocomuobs"]) :
"") +
481 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"CODPOST") ?
", codpost = " + DB.SQLString(usuarioDestino[0][
"codpost"]) :
"") +
482 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"DIRECCION") ?
", direccion = " + DB.SQLString(usuarioDestino[0][
"direccion"]) :
"") +
483 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"PAIS") ?
", pais = " + DB.SQLString(usuarioDestino[0][
"pais"]) :
"") +
484 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"POBLACION") ?
", poblacion = " + DB.SQLString(usuarioDestino[0][
"poblacion"]) :
"") +
485 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"PROVINCIA") ?
", provincia = " + DB.SQLString(usuarioDestino[0][
"provincia"]) :
"") +
486 (DB.SQLExisteCampo(
"COMUNES",
"USUARIOS",
"SINCUENTA") ?
", sincuenta = " + DB.SQLString(usuarioDestino[0][
"sincuenta"]) :
"") +
487 " WHERE codigo = " + DB.SQLString(tcUsuario);
500 private bool ComprobarOtrosGruposIdUsuario(
string tcCodigoUsuario,
string tcIdUsuario, out List<DataRow> usuarioDestino)
502 DataTable ldtTemp =
new DataTable();
503 if (_dtOtrosGruposUsers == null)
505 ObtenerUsuariosOtrosGrupos();
508 if (_dtOtrosGruposUsers != null)
511 var usuariosNulos = _dtUsuarios
513 .Where(r => r.Field<
object>(
"codigo") == null || r.Field<
object>(
"codigo") == DBNull.Value);
514 foreach (DataRow ldr
in usuariosNulos)
516 EnumerableRowCollection<DataRow> usuarioExiste = null;
517 if (!
string.IsNullOrWhiteSpace(tcCodigoUsuario))
519 usuarioExiste = _dtOtrosGruposUsers
521 .Where(r => r.Field<
string>(
"usuario").Trim() == tcCodigoUsuario && r.Field<
string>(
"idusuario").Trim() == Convert.ToString(ldr[
"idusuario_uniuser"]).Trim());
523 else if (!
string.IsNullOrWhiteSpace(tcIdUsuario))
525 usuarioExiste = _dtOtrosGruposUsers
527 .Where(r => r.Field<
string>(
"idusuario").Trim() == tcIdUsuario);
529 if (usuarioExiste != null && usuarioExiste.Count() > 0)
531 string lcGrupo = Convert.ToString(usuarioExiste.First()[
"grupo"]).Trim();
532 string lcUsuario = Convert.ToString(usuarioExiste.First()[
"usuario"]).Trim();
533 string lcIdusuario = Convert.ToString(usuarioExiste.First()[
"idusuario"]).Trim();
535 string lcSql =
"SELECT * FROM " + DB.SQLDatabaseReal(
"COMU" + lcGrupo,
"USUARIOS") +
" WHERE codigo = " + DB.SQLString(lcUsuario);
536 DB.SQLExec(lcSql, ref ldtTemp);
537 if (ldtTemp != null && ldtTemp.Rows.Count > 0)
539 usuarioDestino =
new List<DataRow>() { ldtTemp.Rows[0] };
546 usuarioDestino = null;
553 private void DeserializarJSONs()
558 if (Directory.Exists(_RutaOrigenTempRestauracion +
"\\CLOUDID"))
560 if (File.Exists(_RutaOrigenTempRestauracion +
"\\CLOUDID\\uniusers.json"))
562 lcTempJson =
System.IO.File.ReadAllText(_RutaOrigenTempRestauracion +
"\\CLOUDID\\uniusers.json");
563 _dtUniusers = JsonConvert.DeserializeObject<DataTable>(lcTempJson);
565 if (File.Exists(_RutaOrigenTempRestauracion +
"\\CLOUDID\\accesogrup.json"))
567 lcTempJson =
System.IO.File.ReadAllText(_RutaOrigenTempRestauracion +
"\\CLOUDID\\accesogrup.json");
568 _dtAccesoGrup = JsonConvert.DeserializeObject<DataTable>(lcTempJson);
576 _dtAccesoGrup = null;
577 DB.Registrar_Error(e);
585 private void UsuarioNOExisteDestino(DataRow ldr)
590 if (
string.IsNullOrWhiteSpace(Convert.ToString(ldr[
"idusuario"])))
594 string lcIdUsuario = Convert.ToString(ldr[
"idusuario"]).Trim();
595 string lcCodigoUsuario = Convert.ToString(ldr[
"codigo"]).Trim();
596 string lcIdUsuarioNuevo = Guid.NewGuid().ToString().ToUpper();
599 List<DataRow> registroUniuser = _dtUniusers
601 .Where(r => r.Field<
string>(
"idusuario").Trim() == lcIdUsuario).ToList();
602 if (registroUniuser != null && registroUniuser.Count() > 0)
605 lcSql =
"INSERT INTO " + DB.SQLDatabaseReal(
"EUROWINSYS",
"UNIUSERS") +
" (idsage50, idusuario, idcloudid, email, rol) " +
606 "VALUES (" + DB.SQLString(idSage50) +
", " + DB.SQLString(lcIdUsuarioNuevo) +
", " + DB.SQLString(registroUniuser[0][
"idcloudid"])
607 +
", " + DB.SQLString(registroUniuser[0][
"email"]) +
", " + registroUniuser[0][
"rol"] +
")";
611 lcSql =
"UPDATE " + DB.SQLDatabaseReal(
"COMU" + _GrupoDestino,
"USUARIOS") +
" SET idusuario = " + DB.SQLString(lcIdUsuarioNuevo) +
", cloudid = 1 " +
612 "WHERE codigo = " + DB.SQLString(lcCodigoUsuario);
616 List<DataRow> registroAccesogrup = _dtAccesoGrup
618 .Where(r => r.Field<
string>(
"usuario").Trim() == lcCodigoUsuario).ToList();
619 if (registroAccesogrup != null && registroAccesogrup.Count() > 0)
622 lcSql =
"INSERT INTO " + DB.SQLDatabase(
"EUROWINSYS",
"ACCESOGRUP") +
" (idsage50, grupo, modulo, usuario, nivel) " +
623 "VALUES (" + DB.SQLString(idSage50) +
", " + DB.SQLString(_GrupoDestino) +
", " + DB.SQLString(
"SEL_GRUPO") +
624 ", " + DB.SQLString(lcCodigoUsuario) +
", " + registroAccesogrup[0][
"nivel"] +
")";
629 InsertarUsuarioOtrosGrupos(lcCodigoUsuario);
638 private void InsertarUsuarioOtrosGrupos(
string tcUsuario)
640 List<DataRow> usuarioDestino =
new List<DataRow>();
641 DataTable ldtUsuario =
new DataTable();
642 string lcSql =
"SELECT * FROM " + DB.SQLDatabaseReal(
"COMU" + _GrupoDestino,
"USUARIOS") +
" WHERE codigo = " + DB.SQLString(tcUsuario);
643 DB.SQLExec(lcSql, ref ldtUsuario);
644 if (ldtUsuario != null && ldtUsuario.Rows.Count > 0)
646 usuarioDestino =
new List<DataRow>() { ldtUsuario.Rows[0] };
649 DataTable ldtTemp =
new DataTable();
650 lcSql =
"SELECT codigo, nombre FROM " + DB.SQLDatabaseReal(
"EUROWINSYS",
"GRUPOSEMP") +
" WHERE idsage50 = " + DB.SQLString(idSage50);
651 DB.SQLExec(lcSql, ref ldtTemp);
653 if (ldtTemp != null && ldtTemp.Rows.Count > 0)
655 foreach (DataRow ldr
in ldtTemp.Rows)
657 if (DB._SQLExisteBBDD(
"COMU" + ldr[
"codigo"]) && Convert.ToString(ldr[
"codigo"]).Trim() != _GrupoDestino)
659 lcSql =
"INSERT INTO " + DB.SQLDatabaseReal(
"EUROWINSYS",
"ACCESOGRUP") +
" (idsage50, grupo, modulo, usuario, nivel) " +
660 "VALUES(" + DB.SQLString(idSage50) +
", " + DB.SQLString(ldr[
"codigo"]) +
", " + DB.SQLString(
"SEL_GRUPO") +
661 ", " + DB.SQLString(tcUsuario) +
", 0)";
664 GuardarDatosUsuarioDestino(tcUsuario, usuarioDestino, Convert.ToString(ldr[
"codigo"]).Trim());
674 private void UsuarioExisteDestinoNOOrigen(DataRow ldr)
676 string lcCodigoUsuario = Convert.ToString(ldr[
"codigo"]).Trim();
677 string lcGrupoDatosUsuario =
"";
679 string lcSql =
"DELETE FROM " + DB.SQLDatabaseReal(
"EUROWINSYS",
"ACCESOGRUP") +
680 " WHERE idsage50 = " + DB.SQLString(idSage50) +
" AND grupo = " + DB.SQLString(_GrupoDestino) +
" AND modulo = " + DB.SQLString(
"SEL_GRUPO") +
681 " AND usuario = " + DB.SQLString(lcCodigoUsuario);
684 lcSql =
"INSERT INTO " + DB.SQLDatabaseReal(
"EUROWINSYS",
"ACCESOGRUP") +
" (idsage50, grupo, modulo, usuario, nivel) " +
685 "VALUES(" + DB.SQLString(idSage50) +
", " + DB.SQLString(_GrupoDestino) +
", " + DB.SQLString(
"SEL_GRUPO") +
686 ", " + DB.SQLString(lcCodigoUsuario) +
", 0)";
689 if (_dtOtrosGruposUsers == null)
691 ObtenerUsuariosOtrosGrupos();
694 if (_dtOtrosGruposUsers != null)
696 DataRow[] ldrGrupoUser = _dtOtrosGruposUsers.Select(
"usuario = '" + lcCodigoUsuario +
"'");
697 if (ldrGrupoUser.Length > 0)
698 lcGrupoDatosUsuario = Convert.ToString(ldrGrupoUser[0][
"grupo"]);
701 if (!
string.IsNullOrWhiteSpace(lcGrupoDatosUsuario))
703 List<DataRow> usuarioDestino =
new List<DataRow>();
704 DataTable ldtUsuario =
new DataTable();
705 lcSql =
"SELECT * FROM " + DB.SQLDatabaseReal(
"COMU" + lcGrupoDatosUsuario,
"USUARIOS") +
" WHERE codigo = " + DB.SQLString(lcCodigoUsuario);
706 DB.SQLExec(lcSql, ref ldtUsuario);
707 if (ldtUsuario != null && ldtUsuario.Rows.Count > 0)
709 usuarioDestino =
new List<DataRow>() { ldtUsuario.Rows[0] };
710 GuardarDatosUsuarioDestino(lcCodigoUsuario, usuarioDestino);
720 private bool ComprobarUsuarioExisteOtrosGrupos(DataRow ldr)
722 if (_dtOtrosGruposUsers == null)
724 ObtenerUsuariosOtrosGrupos();
727 if (_dtOtrosGruposUsers != null)
729 var usuarioExiste = _dtOtrosGruposUsers
731 .Where(r => r.Field<
string>(
"usuario").Trim() == Convert.ToString(ldr[
"codigo"]).Trim());
732 return usuarioExiste.Count() > 0;
742 private void ObtenerUsuariosOtrosGrupos()
744 _dtOtrosGruposUsers =
new DataTable();
745 _dtOtrosGruposUsers.Columns.Add(
"grupo", typeof(
string));
746 _dtOtrosGruposUsers.Columns.Add(
"usuario", typeof(
string));
747 _dtOtrosGruposUsers.Columns.Add(
"idusuario", typeof(
string));
748 DataTable ldtTemp =
new DataTable();
750 string lcSql =
"SELECT codigo, nombre FROM " + DB.SQLDatabaseReal(
"EUROWINSYS",
"GRUPOSEMP") +
" WHERE idsage50 = " + DB.SQLString(idSage50) +
751 " AND codigo <> " + DB.SQLString(_GrupoDestino);
752 DB.SQLExec(lcSql, ref ldtTemp);
753 if (ldtTemp != null && ldtTemp.Rows.Count > 0)
755 foreach (DataRow ldr
in ldtTemp.Rows)
757 if (DB._SQLExisteBBDD(
"COMU" + Convert.ToString(ldr[
"codigo"]).Trim()))
759 ldtTemp2 =
new DataTable();
760 lcSql =
"SELECT codigo, idusuario FROM " + DB.SQLDatabaseReal(
"COMU" + Convert.ToString(ldr[
"codigo"]).Trim(),
"USUARIOS");
761 DB.SQLExec(lcSql, ref ldtTemp2);
762 if (ldtTemp != null && ldtTemp2.Rows.Count > 0)
764 foreach (DataRow ldr2
in ldtTemp2.Rows)
766 DataRow _fila = _dtOtrosGruposUsers.NewRow();
767 _fila[
"grupo"] = Convert.ToString(ldr[
"codigo"]).Trim();
768 _fila[
"usuario"] = Convert.ToString(ldr2[
"codigo"]).Trim();
769 _fila[
"idusuario"] = Convert.ToString(ldr2[
"idusuario"]).Trim();
770 _dtOtrosGruposUsers.Rows.Add(_fila);
781 private void ProcesoRevisionUsuarioUnicoGrupo()
783 DataTable ldtUsuarios =
new DataTable();
786 string lcSql =
"DELETE FROM " + DB.SQLDatabaseReal(
"EUROWINSYS",
"UNIUSERS") +
" WHERE idsage50 = " + DB.SQLString(idSage50);
788 lcSql =
"DELETE FROM " + DB.SQLDatabaseReal(
"EUROWINSYS",
"ACCESOGRUP") +
" WHERE idsage50 = " + DB.SQLString(idSage50);
791 lcSql =
"SELECT codigo, nombre, idusuario, cloudid FROM " + DB.SQLDatabaseReal(
"COMU" + _GrupoDestino,
"USUARIOS");
792 DB.SQLExec(lcSql, ref ldtUsuarios);
793 if (ldtUsuarios != null && ldtUsuarios.Rows.Count > 0)
797 foreach (DataRow ldr
in ldtUsuarios.Rows)
799 UsuarioNOExisteDestino(ldr);
CopiaSeguridadCloudId()
Constructor por defecto
Task 197705: Clase para gestionar los procesos específicos de copia de seguridad que tenemos con Clou...
static string _CodigoGrupoActual()
Obtención del código de grupo actual
Clase para el control de grupos de empresa (nuevo enfoque en Sage50, desaparece el multiempresa...