Imports Extensiones Imports System.Data Partial Class Sistemas_PopUpAddUsuario Inherits ClsPaginas #Region "PROPIEDADES" Public Property CveCliente As Integer Get Return ViewState("CveCliente").ToString.ToEntero End Get Set(value As Integer) ViewState("CveCliente") = value End Set End Property Public Property CveProveedor As Integer Get Return ViewState("CveProveedor").ToString.ToEntero End Get Set(value As Integer) ViewState("CveProveedor") = value End Set End Property Public Property CveUsuario As Integer Get Return ViewState("CveUsuario").ToString.ToEntero End Get Set(value As Integer) ViewState("CveUsuario") = value End Set End Property Private Property DTModulos As DataTable Get Return CType(ViewState("DTModulos"), DataTable) End Get Set(value As DataTable) ViewState("DTModulos") = value End Set End Property Private Property DtNotificacionesUsuarios As DataTable Get Return CType(ViewState("DtNotificacionesUsuarios"), DataTable) End Get Set(value As DataTable) ViewState("DtNotificacionesUsuarios") = value End Set End Property Public Property CvePlataforma As Integer Get Return ViewState("CvePlataforma").ToString.ToEntero End Get Set(value As Integer) ViewState("CvePlataforma") = value End Set End Property #End Region Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not Page.IsPostBack Then CType(Me.Master, BaseMasterPage).EsPopup = True If Request("CveUsuario") IsNot Nothing AndAlso IsNumeric(Request("CveUsuario")) AndAlso Request("CveUsuario").ToEntero > 0 Then ViewState("CveUsuario") = Request("CveUsuario").ToEntero If CveUsuario > 0 Then TxtEmail.Enabled = False CargaUsuario() End If Else CveUsuario = -1 LtlUsuario.Text = "Nuevo Usuario" End If If Request("CveCliente") IsNot Nothing AndAlso IsNumeric(Request("CveCliente")) AndAlso Request("CveCliente").ToEntero > 0 Then ViewState("CveCliente") = Request("CveCliente").ToEntero 'CargaDispositivos() 'CargarNotificaciones() Else CveCliente = -1 End If If Request("CveProveedor") IsNot Nothing AndAlso IsNumeric(Request("CveProveedor")) AndAlso Request("CveProveedor").ToEntero > 0 Then ViewState("CveProveedor") = Request("CveProveedor").ToEntero 'CargaDispositivos() 'CargarNotificaciones() Else CveProveedor = -1 End If If UsuarioActual.Empresa.CvePlataforma = 3 AndAlso (ViewState("CveProveedor") > 0 Or ViewState("CveCliente") > 0) Then CargaDispositivos() CargarNotificaciones() TabApp.Visible = True CargaGridModulosAccesoApp() End If If UsuarioActual.Empresa.CvePlataforma = 1 AndAlso (ViewState("CveProveedor") > 0 OrElse ViewState("CveCliente") > 0) Then TabVehiculos.Visible = False TabPermisoVehiculos.Visible = False TabNotificaciones.Visible = False TabPermisoComandos.Visible = False If CveUsuario > 0 Then DivEstatus.Visible = True Else DivEstatus.Visible = False End If Else DivEstatus.Visible = False CargaComandos() End If 'INICIALIZA CVEPLATAFORMA If UsuarioActual.Empresa.CvePlataforma = 1 And ViewState("CveCliente") > 0 Then ViewState("CvePlataforma") = 6 ElseIf UsuarioActual.Empresa.CvePlataforma = 1 And ViewState("CveProveedor") > 0 Then ViewState("CvePlataforma") = 7 Else ViewState("CvePlataforma") = 3 End If CargaModulosAcceso() CargaModulosPermisos() End If End Sub Public Sub CargaUsuario() If CveUsuario > 0 Then Dim ObjUsuario As New ClsSisUsuarios() If ObjUsuario.GetUsuarios(CveUsuario) Then LtlUsuario.Text = ObjUsuario.DtResultados.Rows(0)("Usuario").ToString() TxtEmail.Text = ObjUsuario.DtResultados.Rows(0)("Correo").ToString() TxtNombre.Text = ObjUsuario.DtResultados.Rows(0)("Nombre").ToString() ChkEstatus.Checked = ObjUsuario.DtResultados.Rows(0)("Estatus") If ObjUsuario.DtResultados.Rows(0)("CveRol").ToString.ToEntero = 1200 OrElse ObjUsuario.DtResultados.Rows(0)("CveRol").ToString.ToEntero = 1198 Then BtnDefaultPWD.Visible = True End If Dim Dt As Data.DataTable = GlobalDTUsuarios(CveUsuario) Dim empresas As New StringBuilder() If Dt.FiltraParametros("CvePlataforma = 3").Rows.Count > 0 Then empresas.Append($"

Empresas

") End If For Each row As DataRow In Dt.FiltraParametros("CvePlataforma = 3 ", "", {"CveEmpresa", "Empresa"}).Rows empresas.Append($"
{row("Empresa").ToString()}
") For Each wor As DataRow In Dt.Select($"CvePlataforma = 3 AND CveCliente>0 AND CveEmpresa={row("CveEmpresa").ToString().ToEntero()}") empresas.Append($"
{wor("Cliente").ToString()}
") Next Next LtlEmpresas.Text = empresas.ToString() Else LtlUsuario.Text = "" TxtEmail.Text = "" TxtNombre.Text = "" LtlEmpresas.Text = "" BtnDefaultPWD.Visible = False End If ObjUsuario.Dispose() UpUsuario.Update() End If End Sub Private Sub BtnDefaultPWD_Click(sender As Object, e As EventArgs) Handles BtnDefaultPWD.Click Dim ObjUsuario As New ClsSisUsuarios If ObjUsuario.UpdateUsuarioContrasenia(ContraseñaPredeterminadaEncriptada, CveUsuario, UsuarioActual.CveEmpresa) Then If ObjUsuario.UpdateUsuario(LtlUsuario.Text, TxtNombre.Text, -1, TxtEmail.Text, -1, -1, True, True, -1, CveUsuario, -1, -1) Then Alert("La contraseña se reestableció correctamente a la contraseña por default '-acceso-'.") Dim Liga As String = $"{Context.Request.Url.OriginalString.Substring(0, Context.Request.Url.OriginalString.Length - Context.Request.Url.PathAndQuery.Length)}/LogIn.aspx" Dim LigaActivar As String = Liga & "?p=" & Encripta("CveU=" & CveUsuario & "&Clave=" & "-acceso-" & "&Opcion=Activar&Hora=" & DateTime.Now.Ticks& & "&CveE=" & UsuarioActual.CveEmpresa) If UsuarioActual.Empresa.CvePlataforma = 3 Then EnviaCorreoGPS(Liga, LigaActivar) Else EnviaCorreo(Liga, LigaActivar) End If End If End If ObjUsuario.Dispose() End Sub Private Sub CargaComandos() Dim ObjGPS As New ClsGPS If ObjGPS.GetUsuariosComandos(CveUsuario, UsuarioActual.CveUsuario, -1) Then GvPermisosComandos.DataSource = ObjGPS.DtResultados End If ObjGPS.Dispose() GvPermisosComandos.DataBind() UppComandos.Update() End Sub Private Function ValidaDatos() As Boolean Dim Valido As Boolean = False If Not String.IsNullOrEmpty(TxtEmail.Text.Trim) Then Valido = True Else Alert("Debe asginar un correo al usuario", TipoMensaje.MsgAdvertencia) Valido = False Return Valido End If If Not String.IsNullOrEmpty(TxtNombre.Text.Trim) Then Valido = True Else Alert("Debe asignar un nombre al usuario", TipoMensaje.MsgAdvertencia) Valido = False Return Valido End If Dim NumModulos As Integer = 0 For Each Row As GridViewRow In GvModulosAcceso.Rows If Row.RowType = DataControlRowType.DataRow Then If Row.FCCheckBox("ChkPermitir").Checked Then NumModulos = NumModulos + 1 End If End If Next If NumModulos > 0 Then Valido = True Else Alert("Debe seleccionar al menos 1 modulo", TipoMensaje.MsgAdvertencia) Valido = False Return Valido End If Return Valido End Function Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) If Not ValidaDatos() Then Exit Sub End If Dim HuboError As Boolean Dim Editar As Boolean = False Dim Mensaje As String = "" Dim ObjUsuarios As New ClsSisUsuarios() ObjUsuarios.IniciaTransacSQL() Try If CveUsuario = -1 Then 'VALIDA NO ALTERAR DATOS DE OTRO USUARIO 'Dim UsuariosExistentes As Integer = GlobalDTUsuarios().COUNT("CveUsuario", $"Usuario IN ('{TxtNombre.Text.Trim}','{TxtEmail.Text.Trim}') OR Correo = '{TxtEmail.Text.Trim}'") 'If UsuariosExistentes > 0 Then ' ObjUsuarios.RollBack() ' ObjUsuarios.Dispose() ' Alert("Los datos ingresados ya existen en el sistema.Favor de verificar si existe el usuario", TipoMensaje.MsgAdvertencia) ' Return 'End If Editar = False 'AGREGA USUARIO If UsuarioActual.Empresa.CvePlataforma = 3 Then CveUsuario = ObjUsuarios.AddUsuarioPopUp(TxtEmail.Text.Trim, ContraseñaPredeterminadaEncriptada, TxtNombre.Text, TxtEmail.Text, True, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveCliente, CveProveedor) ElseIf UsuarioActual.Empresa.CvePlataforma = 1 Then CveUsuario = ObjUsuarios.AddUsuarioPortal(TxtEmail.Text.Trim, ContraseñaPredeterminadaEncriptada, TxtNombre.Text, TxtEmail.Text, CveCliente, CveProveedor, CvePlataforma, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) End If 'ENVIA CORREO If CveUsuario > 0 Then Dim Liga As String = $"{Context.Request.Url.OriginalString.Substring(0, Context.Request.Url.OriginalString.Length - Context.Request.Url.PathAndQuery.Length)}/LogIn.aspx" Dim LigaActivar As String = Liga & "?p=" & Encripta("CveU=" & CveUsuario & "&Clave=" & "-acceso-" & "&Opcion=Activar&Hora=" & DateTime.Now.Ticks& & "&CveE=" & UsuarioActual.CveEmpresa) If UsuarioActual.Empresa.CvePlataforma = 3 Then Mensaje = EnviaCorreoGPS(Liga, LigaActivar) Else Mensaje = EnviaCorreo(Liga, LigaActivar) End If Else HuboError = True End If 'AGREGA ACCESO A MODULOS If Not HuboError Then For Each Row As GridViewRow In GvModulosAcceso.Rows 'Nota, permitir, tiene 3 valores, ''(Vacio), no se ha estipulado, '0' que se denego, '1' permitido(aplicado solo cuando no viene del rol If Row.DataKey("CveModuloAcceso") <> "" Then If Row.DataKey("Permitir") = "" AndAlso Row.FCCheckBox("ChkDenegar").Checked OrElse Row.DataKey("Permitir") = "0" AndAlso Row.FCCheckBox("ChkDenegar").Checked = False Then If Not ObjUsuarios.UpdateUsuariosModulos(CveUsuario, Row.DataKey("CveModulo").ToEntero, Not Row.FCCheckBox("ChkDenegar").Checked, UsuarioActual.CveUsuario) Then HuboError = True Exit For End If End If Else If Row.DataKey("Permitir") = "" AndAlso Row.FCCheckBox("ChkPermitir").Checked OrElse Row.DataKey("Permitir") = "1" AndAlso Row.FCCheckBox("ChkPermitir").Checked = False Then If Not ObjUsuarios.UpdateUsuariosModulos(CveUsuario, Row.DataKey("CveModulo").ToEntero, Row.FCCheckBox("ChkPermitir").Checked, UsuarioActual.CveUsuario) Then HuboError = True Exit For End If End If End If Next End If 'EXCLUSIVO GPS -- DISPOSITIVOS, COMANDOS If UsuarioActual.Empresa.CvePlataforma = 3 Then If Not HuboError AndAlso CveCliente > 0 AndAlso UsuarioActual.Empresa.CvePlataforma = 3 Then For Each row As GridViewRow In GvDispositivos.Rows If Not ObjUsuarios.UpdateUsuariosDispositivos(CveUsuario, row.DataKey("CveDispositivo").ToEntero, row.FCCheckBox("chkDis").Checked) Then HuboError = True Exit For End If Next End If If Not HuboError AndAlso CveCliente > 0 AndAlso UsuarioActual.Empresa.CvePlataforma = 3 Then For Each row As GridViewRow In GvPermisosComandos.Rows Dim Permitir As Boolean = row.FCCheckBox("ChkP").Checked Dim EsFavorito As Boolean = row.FCCheckBox("ChkFavorito").Checked If Not ObjUsuarios.UpdateUsuariosComandos(CveUsuario, UsuarioActual.CveUsuario, row.DataKey("CveComando").ToEntero, Permitir, EsFavorito) Then HuboError = True Exit For End If Next End If 'If Not HuboError AndAlso CveCliente > 0 Then ' Using ObjNotificaciones As New ClsSisNotificaciones() ' For Each row As GridViewRow In GVNotificaciones.Rows ' If row.FCCheckBox("chkCorreo").Checked OrElse row.FCCheckBox("chkVentana").Checked OrElse row.FCCheckBox("chkSMS").Checked OrElse ' row.FCCheckBox("chkApp").Checked OrElse row.FCCheckBox("chkCampana").Checked Then ' If Not ObjNotificaciones.AddUsuariosNotificacion(CveUsuario, row.DataKey("CveNotificacion"), row.FCCheckBox("chkCorreo").Checked, row.FCCheckBox("chkVentana").Checked, row.FCCheckBox("chkSMS").Checked, ' row.FCCheckBox("chkApp").Checked, row.FCCheckBox("chkCampana").Checked) Then ' HuboError = True ' End If ' End If ' Next ' End Using 'End If End If 'AGREGA PERMISOS If Not HuboError Then For Each Row As GridViewRow In GvModulosPermiso.Rows If Row.DataKey("CveProcesoAcceso") <> "" Then 'checo si el permiso que tiene es del rol, de ser así, nada más actualizo los denegados If Row.DataKey("Permitir") = "" AndAlso Row.FCCheckBox("ChkD").Checked OrElse Row.DataKey("Permitir") = "0" AndAlso Row.FCCheckBox("ChkD").Checked = False Then If Not ObjUsuarios.UpdateUsuariosProcesos(CveUsuario, Row.DataKey("CveProceso").ToEntero, Not Row.FCCheckBox("ChkD").Checked, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then HuboError = True Exit For End If End If Else 'permisos que el rol, no le está otorgando, y serán únicos para el usuario If Row.DataKey("Permitir") = "" AndAlso Row.FCCheckBox("ChkP").Checked OrElse Row.DataKey("Permitir") = "1" AndAlso Row.FCCheckBox("ChkP").Checked = False Then If Not ObjUsuarios.UpdateUsuariosProcesos(CveUsuario, Row.DataKey("CveProceso").ToEntero, Row.FCCheckBox("ChkP").Checked, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then HuboError = True Exit For End If End If End If Next For Each Row As GridViewRow In GvModulosApp.Rows If Row.DataKey("CveProcesoAcceso") <> "" Then 'checo si el permiso que tiene es del rol, de ser así, nada más actualizo los denegados If Row.DataKey("Permitir") = "" AndAlso Row.FCCheckBox("ChkDenegar").Checked OrElse Row.DataKey("Permitir") = "0" AndAlso Row.FCCheckBox("ChkDenegar").Checked = False Then If Not ObjUsuarios.UpdateUsuariosProcesos(CveUsuario, Row.DataKey("CveProceso").ToEntero, Not Row.FCCheckBox("ChkDenegar").Checked, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then HuboError = True Exit For End If End If Else 'permisos que el rol, no le está otorgando, y serán únicos para el usuario If Row.DataKey("Permitir") = "" AndAlso Row.FCCheckBox("ChkPermitir").Checked OrElse Row.DataKey("Permitir") = "1" AndAlso Row.FCCheckBox("ChkPermitir").Checked = False Then If Not ObjUsuarios.UpdateUsuariosProcesos(CveUsuario, Row.DataKey("CveProceso").ToEntero, Row.FCCheckBox("ChkPermitir").Checked, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then HuboError = True Exit For End If End If End If Next End If ElseIf CveUsuario > 0 Then 'VALIDA NO ALTERAR DATOS DE OTRO USUARIO 'Dim DtUsuarios As DataTable = GlobalDTUsuarios.FiltraParametros($"CveUsuario <> {CveUsuario}") Editar = True 'Dim UsuariosExistentes As Integer = DtUsuarios.COUNT("CveUsuario", $"Usuario IN ('{TxtEmail.Text.Trim}') OR Correo = '{TxtEmail.Text.Trim}'") 'If UsuariosExistentes > 0 Then ' ObjUsuarios.RollBack() ' ObjUsuarios.Dispose() ' Alert("Los datos ingresados ya existen en el sistema.Favor de verificar si existe el usuario", TipoMensaje.MsgAdvertencia) ' Return 'End If 'SI ES UN USUARIO DEL ERP, DEBE DARLE ACCESO AL CLIENTE If UsuarioActual.Empresa.CvePlataforma = 1 AndAlso CveCliente > 0 Then Dim DtClientesAcceso As DataTable = Nothing If Not HuboError AndAlso ObjUsuarios.GetUsuarioCliente(CveUsuario, CveCliente) Then 'DEBE AGREGAR EL USUARIO AL CLIENTE If ObjUsuarios.DtResultados.Rows.Count = 0 Then If Not HuboError AndAlso Not ObjUsuarios.AddUsuarioCliente(CveUsuario, CveCliente) Then HuboError = True End If End If Else HuboError = True End If 'SI ES UN USUARIO DEL ERP, DEBE DARLE ACCESO AL PROVEEDOR ElseIf UsuarioActual.Empresa.CvePlataforma = 1 AndAlso CveProveedor > 0 Then Dim DtProveedoresAcceso As DataTable = Nothing If Not HuboError AndAlso ObjUsuarios.GetUsuarioProveedor(CveUsuario, CveProveedor) Then 'DEBE AGREGAR EL USUARIO AL PROVEEDOR If ObjUsuarios.DtResultados.Rows.Count = 0 Then If Not HuboError AndAlso Not ObjUsuarios.AddUsuarioProveedor(CveUsuario, CveProveedor) Then HuboError = True End If End If Else HuboError = True End If ElseIf UsuarioActual.Empresa.CvePlataforma = 3 Then If Not ObjUsuarios.UpdateUsuario(LtlUsuario.Text.Trim, TxtNombre.Text, -1, TxtEmail.Text, -1, -1, False, True, -1, CveUsuario, -1, -1) Then HuboError = True End If If Not HuboError AndAlso Not ObjUsuarios.AddUsuarioCliente(CveUsuario, CveCliente) Then HuboError = True End If ElseIf CvePlataforma = 6 OrElse CvePlataforma = 7 Then If Not ObjUsuarios.UpdateUsuarioPortal(LtlUsuario.Text.Trim, TxtNombre.Text, TxtEmail.Text, ChkEstatus.Checked, "-1", CveCliente, CveProveedor, CveUsuario, UsuarioActual.CveUsuario) Then HuboError = True End If End If If Not HuboError Then For Each Row As GridViewRow In GvModulosAcceso.Rows 'Nota, permitir, tiene 3 valores, ''(Vacio), no se ha estipulado, '0' que se denego, '1' permitido(aplicado solo cuando no viene del rol If Row.DataKey("CveModuloAcceso") <> "" Then If Row.DataKey("Permitir") = "" AndAlso Row.FCCheckBox("ChkDenegar").Checked OrElse Row.DataKey("Permitir") = "0" AndAlso Row.FCCheckBox("ChkDenegar").Checked = False Then If Not ObjUsuarios.UpdateUsuariosModulos(CveUsuario, Row.DataKey("CveModulo").ToEntero, Not Row.FCCheckBox("ChkDenegar").Checked, UsuarioActual.CveUsuario) Then HuboError = True Exit For End If End If Else If Row.DataKey("Permitir") = "" AndAlso Row.FCCheckBox("ChkPermitir").Checked OrElse Row.DataKey("Permitir") = "1" AndAlso Row.FCCheckBox("ChkPermitir").Checked = False Then If Not ObjUsuarios.UpdateUsuariosModulos(CveUsuario, Row.DataKey("CveModulo").ToEntero, Row.FCCheckBox("ChkPermitir").Checked, UsuarioActual.CveUsuario) Then HuboError = True Exit For End If End If End If Next For Each Row As GridViewRow In GvModulosApp.Rows 'Nota, permitir, tiene 3 valores, ''(Vacio), no se ha estipulado, '0' que se denego, '1' permitido(aplicado solo cuando no viene del rol If Row.DataKey("CveModuloAcceso") <> "" Then If Row.DataKey("Permitir") = "" AndAlso Row.FCCheckBox("ChkDenegar").Checked OrElse Row.DataKey("Permitir") = "0" AndAlso Row.FCCheckBox("ChkDenegar").Checked = False Then If Not ObjUsuarios.UpdateUsuariosModulos(CveUsuario, Row.DataKey("CveModulo").ToEntero, Not Row.FCCheckBox("ChkDenegar").Checked, UsuarioActual.CveUsuario) Then HuboError = True Exit For End If End If Else If Row.DataKey("Permitir") = "" AndAlso Row.FCCheckBox("ChkPermitir").Checked OrElse Row.DataKey("Permitir") = "1" AndAlso Row.FCCheckBox("ChkPermitir").Checked = False Then If Not ObjUsuarios.UpdateUsuariosModulos(CveUsuario, Row.DataKey("CveModulo").ToEntero, Row.FCCheckBox("ChkPermitir").Checked, UsuarioActual.CveUsuario) Then HuboError = True Exit For End If End If End If Next End If 'EXCLUSIVO GPS If Not HuboError AndAlso CveCliente > 0 AndAlso UsuarioActual.Empresa.CvePlataforma = 3 Then For Each row As GridViewRow In GvDispositivos.Rows If Not ObjUsuarios.UpdateUsuariosDispositivos(CveUsuario, row.DataKey("CveDispositivo").ToEntero, row.FCCheckBox("chkDis").Checked) Then HuboError = True Exit For End If Next End If If Not HuboError AndAlso CveCliente > 0 AndAlso UsuarioActual.Empresa.CvePlataforma = 3 Then For Each row As GridViewRow In GvPermisosComandos.Rows Dim Permitir As Boolean = row.FCCheckBox("ChkP").Checked Dim EsFavorito As Boolean = row.FCCheckBox("ChkFavorito").Checked If Not ObjUsuarios.UpdateUsuariosComandos(CveUsuario, UsuarioActual.CveUsuario, row.DataKey("CveComando").ToEntero, Permitir, EsFavorito) Then HuboError = True Exit For End If Next End If 'If Not HuboError AndAlso CveCliente > 0 Then ' Using ObjNotificaciones As New ClsSisNotificaciones() ' ObjNotificaciones.DeleteNotificacion(-1, CveUsuario) ' For Each row As GridViewRow In GVNotificaciones.Rows ' If row.FCCheckBox("chkCorreo").Checked OrElse row.FCCheckBox("chkVentana").Checked OrElse row.FCCheckBox("chkSMS").Checked OrElse ' row.FCCheckBox("chkApp").Checked OrElse row.FCCheckBox("chkCampana").Checked Then ' If Not ObjNotificaciones.AddUsuariosNotificacion(CveUsuario, row.DataKey("CveNotificacion"), row.FCCheckBox("chkCorreo").Checked, row.FCCheckBox("chkVentana").Checked, row.FCCheckBox("chkSMS").Checked, ' row.FCCheckBox("chkApp").Checked, row.FCCheckBox("chkCampana").Checked) Then ' HuboError = True ' End If ' End If ' Next ' End Using 'End If If Not HuboError Then For Each Row As GridViewRow In GvModulosPermiso.Rows If Row.DataKey("CveProcesoAcceso") <> "" Then 'checo si el permiso que tiene es del rol, de ser así, nada más actualizo los denegados If Row.DataKey("Permitir") = "" AndAlso Row.FCCheckBox("ChkD").Checked OrElse Row.DataKey("Permitir") = "0" AndAlso Row.FCCheckBox("ChkD").Checked = False Then If Not ObjUsuarios.UpdateUsuariosProcesos(CveUsuario, Row.DataKey("CveProceso").ToEntero, Not Row.FCCheckBox("ChkD").Checked, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then HuboError = True Exit For End If End If Else 'permisos que el rol, no le está otorgando, y serán únicos para el usuario If Row.DataKey("Permitir") = "" AndAlso Row.FCCheckBox("ChkP").Checked OrElse Row.DataKey("Permitir") = "1" AndAlso Row.FCCheckBox("ChkP").Checked = False Then If Not ObjUsuarios.UpdateUsuariosProcesos(CveUsuario, Row.DataKey("CveProceso").ToEntero, Row.FCCheckBox("ChkP").Checked, CveUsuarioModifico:=UsuarioActual.CveUsuario) Then HuboError = True Exit For End If End If End If Next End If Else Alert("Ocurrió un error al agregar el usuario.", TipoMensaje.MsgInformacion) End If Catch ex As Exception OnError("Ocurrió un error al agregar el usuario.", ex) End Try If Not HuboError Then ObjUsuarios.Commit() If UsuarioActual.Empresa.CvePlataforma = 3 Then Using ObjNotificaciones As New ClsSisNotificaciones() ObjNotificaciones.DeleteNotificacion(-1, CveUsuario) For Each row As GridViewRow In GVNotificaciones.Rows If row.FCCheckBox("chkCorreo").Checked OrElse row.FCCheckBox("chkVentana").Checked OrElse row.FCCheckBox("chkSMS").Checked OrElse row.FCCheckBox("chkApp").Checked OrElse row.FCCheckBox("chkCampana").Checked Then If Not ObjNotificaciones.AddUsuariosNotificacion(CveUsuario, row.DataKey("CveNotificacion"), row.FCCheckBox("chkCorreo").Checked, row.FCCheckBox("chkVentana").Checked, row.FCCheckBox("chkSMS").Checked, row.FCCheckBox("chkApp").Checked, row.FCCheckBox("chkCampana").Checked) Then HuboError = True End If End If Next End Using End If Dim JSBTN As String = "" If UsuarioActual.Empresa.CvePlataforma = 3 AndAlso UsuarioActual.CveCliente > 0 Then JSBTN = $"document.location.href=""javascript:Ir2({CveCliente})"";" ElseIf CveCliente > 0 Then JSBTN = $"document.location.href=""javascript:Ir({CveCliente})"";" ElseIf CveProveedor > 0 Then JSBTN = $"document.location.href=""javascript:IrProveedores({CveProveedor})"";" End If If Editar Then Alert($"El usuario se actualizó correctamente.

{Mensaje} ", TipoMensaje.MsgInformacion, JSBTN) Else Alert($"El usuario se guardó correctamente.

{Mensaje}", TipoMensaje.MsgInformacion, JSBTN) End If Else ObjUsuarios.RollBack() Alert("Ocurrió un error al agregar el usuario.", TipoMensaje.MsgInformacion) End If ObjUsuarios.Dispose() RecargarGlobalUsuarios() RecargarGlobal() End Sub Private Sub RecargarGlobal() Dim GPS As New ClsGPS If GPS.DispositivosUsuariosGet(-1, -1, -1, -1, -1) Then GlobalDTDispositivosUsuarios(-1, -1) = GPS.DtResultados End If GPS.Dispose() End Sub Private Sub RecargarGlobalUsuarios() Dim ObjUsuarios As New ClsSisUsuarios If ObjUsuarios.GetUsuariosEmpresas(-1) Then Application("GlobalDTUsuarios") = ObjUsuarios.DtResultados Application("GlobalDTUsuarioResponsable") = ObjUsuarios.DtResultados.FiltraParametros("ProveedoresResponsables > 0") End If ObjUsuarios.Dispose() End Sub #Region "MANDAR CORREOS" Private Function EnviaCorreo(Liga As String, LigaActivar As String) As String Dim Retorno As String = "" Try Dim URL As String = UrlSitio If UsuarioActual.Empresa.CvePlataforma = 3 Then URL = "https://gps.signalsgps.com/" End If Dim Para = TxtEmail.Text.Trim Dim Asunto = "" If CveCliente > 0 Then Asunto = "ACTIVACIÓN DEL PORTAL DE CLIENTE" ElseIf CveProveedor > 0 Then Asunto = "ACTIVACIÓN DEL PORTAL DE PROVEEDOR" End If Dim SBBody As New StringBuilder 'Linia de estilos SBBody.Append("") 'incio Cuerpo del correo SBBody.Append("
") SBBody.Append("
") SBBody.Append("
") SBBody.Append("ALTA DE CUENTA") SBBody.Append("
") SBBody.Append("
") SBBody.AppendFormat(" Estimado {0}:
", TxtNombre.Text.ToUpper) SBBody.AppendFormat("El presente correo es para informarle que se le han asignado los siguientes datos para el acceso a la Plataforma de: {0}

", UsuarioActual.Empresa.Empresa) SBBody.Append("
") SBBody.Append("
Datos de usuario
") SBBody.Append("
") SBBody.Append("
") SBBody.Append("
") SBBody.Append("
Usuario
") SBBody.AppendFormat("
{0}
", TxtEmail.Text) SBBody.Append("
") SBBody.Append("
") SBBody.Append("
Accesé al sistema dando click a la liga y estableciendo su contraseña
") SBBody.AppendFormat("", LigaActivar) SBBody.Append("
") SBBody.Append("
") SBBody.Append("
") SBBody.Append("
") SBBody.Append("Para Activar su cuenta debera cambiar su contraseña.

") SBBody.Append("
") SBBody.Append("Nota Favor de NO responder este correo. ") SBBody.Append("


") SBBody.AppendFormat("", URL) SBBody.Append("
") SBBody.Append("
") 'Termino Cuerpo del correo Dim Hilo As New System.Threading.Thread(Sub() MandaCorreo(Asunto, Para, SBBody.ToString)) Hilo.Start() 'Dim JSBTN As String = "" 'If UsuarioActual.CveCliente > 0 Then ' JSBTN = $"document.location.href=""javascript:Ir2({CveCliente})"";" 'ElseIf CveCliente > 0 Then ' JSBTN = $"document.location.href=""javascript:Ir({CveCliente})"";" 'End If 'If UsuarioActual.Empresa.CvePlataforma = 3 Then ' Alert("El correo se ha enviado correctamente a: " + TxtEmail.Text + ".", TipoMensaje.MsgInformacion, JSBTN) 'End If Retorno = $"El correo se ha enviado correctamente a: {TxtEmail.Text}." Catch ex As Exception OnError("Ocurrió error al mandar MAIL", ex) End Try Return Retorno End Function Private Function EnviaCorreoGPS(Liga As String, LigaActivar As String) As String Dim Retorno As String = "" Try 'Dim URL As String = "https://gps.signalsgps.com/" + LigaActivar Dim Para = TxtEmail.Text.Trim Dim Asunto = "ACCESO A SIGNALS GPS" 'Dim SBBody As New StringBuilder ''Linia de estilos 'SBBody.Append("") ''incio Cuerpo del correo 'SBBody.Append("
") 'SBBody.Append("
") 'SBBody.Append("
") 'SBBody.Append("ALTA DE CUENTA") 'SBBody.Append("
") 'SBBody.Append("
") 'SBBody.AppendFormat(" Estimado {0}:
", TxtNombre.Text.ToUpper) 'SBBody.AppendFormat("El presente correo es para informarle que se le han asignado los siguientes datos para el acceso a la Plataforma de: {0}

", UsuarioActual.Empresa.Empresa) 'SBBody.Append("
") 'SBBody.Append("
Datos de usuario
") 'SBBody.Append("
") 'SBBody.Append("
") 'SBBody.Append("
") 'SBBody.Append("
Usuario
") 'SBBody.AppendFormat("
{0}
", TxtEmail.Text) 'SBBody.Append("
") 'SBBody.Append("
") 'SBBody.Append("
Accesé al sistema dando click a la liga y estableciendo su contraseña
") 'SBBody.AppendFormat("", LigaActivar) 'SBBody.Append("
") 'SBBody.Append("
") 'SBBody.Append("
") 'SBBody.Append("
") 'SBBody.Append("Para Activar su cuenta debera cambiar su contraseña.

") 'SBBody.Append("
") 'SBBody.Append("Nota Favor de NO responder este correo. ") 'SBBody.Append("


") 'SBBody.AppendFormat("", URL) 'SBBody.Append("
") 'SBBody.Append("
") Dim SBBody As New StringBuilder() SBBody.Append("
") SBBody.Append("
") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append("
 ") SBBody.Append("

DATOS DE ACCESO

") SBBody.Append("

 

") SBBody.Append("
") SBBody.Append("
") SBBody.AppendFormat("


Estimado / a {0}:

", TxtNombre.Text) SBBody.Append("

El presente correo es para informarle que se le han asignado los siguentes datos para el acceso a la plataforma SIGNALS GPS

") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append(" ") SBBody.Append("") SBBody.Append("
") SBBody.Append("

USUARIO ASIGNADO

") SBBody.Append("
") SBBody.Append("

Usuario:

") SBBody.AppendFormat("

{0}

", TxtEmail.Text) SBBody.Append("
") SBBody.Append("

Contraseña:

") SBBody.Append("

-acceso-

") SBBody.Append("
") SBBody.AppendFormat("

👆INGRESAR A SIGNALS GPS👆

", LigaActivar) SBBody.Append("
") SBBody.Append("
") SBBody.Append("


Favor de NO responder este correo.

") SBBody.Append("
") SBBody.Append("

 

") SBBody.Append("
") 'Termino Cuerpo del correo Dim Hilo As New System.Threading.Thread(Sub() MandaCorreo(Asunto, Para, SBBody.ToString)) Hilo.Start() 'Dim JSBTN As String = "" 'If UsuarioActual.CveCliente > 0 Then ' JSBTN = $"document.location.href=""javascript: Ir2({CveCliente})"";" 'ElseIf CveCliente > 0 Then ' JSBTN = $"document.location.href=""javascript:Ir({CveCliente})"";" 'End If 'If UsuarioActual.Empresa.CvePlataforma = 3 Then ' Alert("El correo se ha enviado correctamente a: " + TxtEmail.Text + ".", TipoMensaje.MsgInformacion, JSBTN) 'End If Retorno = $"El correo se ha enviado correctamente a: {TxtEmail.Text}." Catch ex As Exception OnError("Ocurrió error al mandar MAIL", ex) End Try Return Retorno End Function Private Sub MandaCorreo(Asunto As String, Para As String, Body As String) Dim a As String = String.Format("{0} -- {1} ---- -->", Asunto, Para) a.GuardaLog() Dim Mail As New ClsSisMail() Dim EmpresaEnvio As Empresa = ClsPaginas.EmpresaNotificaciones If UsuarioActual.Empresa.CvePlataforma = 3 Then EmpresaEnvio = ClsPaginas.EmpresaNotificacionesGPS End If Mail.SendMail(EmpresaEnvio, Para, Asunto, Body) End Sub #End Region #Region "M O D U L O S" Public Sub CargaModulosAcceso() Dim ObjPermisos As New ClsSisUsuarios If ObjPermisos.GetUsuariosModulos(CveUsuario, UsuarioActual.CveEmpresa, If(False, UsuarioActual.CveUsuario, -1)) Then If UsuarioActual.Empresa.CvePlataforma = 1 AndAlso CveCliente > 0 Then DTModulos = ObjPermisos.DtResultados.FiltraParametros("Liga <> '' AND CvePlataforma = 6") ElseIf UsuarioActual.Empresa.CvePlataforma = 1 AndAlso CveProveedor > 0 Then DTModulos = ObjPermisos.DtResultados.FiltraParametros("Liga <> '' AND CvePlataforma = 7") Else DTModulos = ObjPermisos.DtResultados.FiltraParametros($"Liga <> '' AND CvePlataforma = {UsuarioActual.Empresa.CvePlataforma}") End If Else DTModulos = Nothing End If ObjPermisos.Dispose() CargaGridModulosAcceso() End Sub Private Sub CargaGridModulosAcceso() GvModulosAcceso.DataSource = DTModulos GvModulosAcceso.DataBind() If (GvModulosAcceso.Rows.Count > 0) Then GvModulosAcceso.UseAccessibleHeader = True GvModulosAcceso.HeaderRow.TableSection = TableRowSection.TableHeader End If UpDatos.Update() End Sub Private Sub CargaGridModulosAccesoApp() Dim ObjPermisos As New ClsSisUsuarios If ObjPermisos.GetUsuariosModulos(CveUsuario, UsuarioActual.CveEmpresa, If(False, UsuarioActual.CveUsuario, -1)) Then If UsuarioActual.CveRol = 1 Then GvModulosApp.DataSource = ObjPermisos.DtResultados.FiltraParametros($"CvePlataforma = 5") Else GvModulosApp.DataSource = ObjPermisos.DtResultados.FiltraParametros($"CvePlataforma = 5 AND CveModulo <> 5010") End If End If ObjPermisos.Dispose() GvModulosApp.DataBind() If (GvModulosApp.Rows.Count > 0) Then GvModulosApp.UseAccessibleHeader = True GvModulosApp.HeaderRow.TableSection = TableRowSection.TableHeader End If UpDatos.Update() End Sub Protected Sub GvModulosAcceso_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvModulosAcceso.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If (e.Row.DBCampo("Permitir")) = "0" Then e.Row.FCCheckBox("ChkDenegar").Checked = True End If If (e.Row.DBCampo("CveModuloAcceso")) <> "" Then e.Row.FCCheckBox("ChkDenegar").Enabled = True e.Row.Cells(3).CssClass = "bg-yellow" Else e.Row.FCCheckBox("ChkPermitir").Enabled = True If e.Row.DBCampo("Permitir") = "1" Then e.Row.FCCheckBox("ChkPermitir").Checked = True End If End If End Sub Protected Sub GvModulosApp_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvModulosApp.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If (e.Row.DBCampo("Permitir")) = "0" Then e.Row.FCCheckBox("ChkDenegar").Checked = True End If If (e.Row.DBCampo("CveModuloAcceso")) <> "" Then e.Row.FCCheckBox("ChkDenegar").Enabled = True e.Row.Cells(3).CssClass = "bg-yellow" Else e.Row.FCCheckBox("ChkPermitir").Enabled = True If e.Row.DBCampo("Permitir") = "1" Then e.Row.FCCheckBox("ChkPermitir").Checked = True End If End If End Sub Public Sub CargaModulosPermisos() Dim ObjProcesos As New ClsSisUsuarios If ObjProcesos.GetUsuariosProcesos(CveUsuario, If(False, UsuarioActual.CveUsuario, -1)) Then If UsuarioActual.Empresa.CvePlataforma = 1 And CveCliente > 0 Then GvModulosPermiso.DataSource = ObjProcesos.DtResultados.FiltraParametros($"CvePlataforma = 6") ElseIf UsuarioActual.Empresa.CvePlataforma = 1 And CveProveedor > 0 Then GvModulosPermiso.DataSource = ObjProcesos.DtResultados.FiltraParametros($"CvePlataforma = 7") If CveUsuario > 0 Then BtnDefaultPWD.Visible = True End If ElseIf UsuarioActual.Empresa.CvePlataforma = 3 Then GvModulosPermiso.DataSource = ObjProcesos.DtResultados.FiltraParametros("CveModulo = 433") End If Else GvModulosPermiso.DataSource = Nothing End If ObjProcesos.Dispose() GvModulosPermiso.DataBind() UpDatos.Update() End Sub Protected Sub GvModulosPermiso_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvModulosPermiso.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then 'cuando el Módulo es heredado del rol If (e.Row.DBCampo("CveModuloAcceso")) <> "" Then e.Row.Cells(0).CssClass = "bg-yellow" ' = "bg-font-yellow" '.BackColor = Color.Gold End If 'cuando el Módulo es heredado del Rol If (e.Row.DBCampo("CveModuloUsuarioAcceso")) <> "" Then e.Row.Cells(0).CssClass = "bg-purple-plum" End If 'cuando el Proceso es heredado del Rol If (e.Row.DBCampo("CveProcesoAcceso")) <> "" Then e.Row.FCCheckBox("ChkD").Enabled = True e.Row.Cells(3).CssClass = "bg-yellow" Else e.Row.FCCheckBox("ChkP").Enabled = True If e.Row.DBCampo("Permitir") = "1" Then e.Row.FCCheckBox("ChkP").Checked = True End If If (e.Row.DBCampo("Permitir")) = "0" Then e.Row.FCCheckBox("ChkD").Checked = True End If End If End Sub Protected Sub GvPermisosComandos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvPermisosComandos.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then Dim Permitir As Integer = e.Row.DBCampo("Permitir").ToEntero Dim EsFavorito As Boolean = CBool(e.Row.DBCampo("EsFavorito")) e.Row.FCCheckBox("ChkFavorito").Checked = EsFavorito If Permitir = 0 Then e.Row.FCCheckBox("ChkP").Checked = False End If If Permitir = 1 Then e.Row.FCCheckBox("ChkP").Checked = True End If End If End Sub #End Region #Region "V E H I C U L O S" Private Sub CargaDispositivos() GvDispositivos.DataSource = GlobalDTDispositivos(CveCliente).FiltraParametros("Estatus = 1 ") GvDispositivos.DataBind() End Sub Protected Sub GvDispositivos_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GvDispositivos.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If CveUsuario > 0 Then If GlobalDTDispositivosUsuarios(CveCliente).FiltroPrimeroValor("Permitir", $"CveUsuario = {CveUsuario} AND CveDispositivo = {e.Row.DBCampo("CveDispositivo")} ").ToString = "True" Then e.Row.FCCheckBox("chkDis").Checked = True End If End If End If End Sub #End Region #Region "N O T I F I C A C I O N E S" Private Sub CargarNotificaciones() Dim ObjNotificaciones As New ClsSisNotificaciones If ObjNotificaciones.GetNotificaciones(-1) Then DtNotificacionesUsuarios = ObjNotificaciones.DtResultados.FiltraParametros($"CveUsuario = {CveUsuario} ") GVNotificaciones.DataSource = ObjNotificaciones.DtResultados.FiltraParametros("1 = 1", "CveNotificacion", {"CveNotificacion", "Nombre"}) End If ObjNotificaciones.Dispose() GVNotificaciones.DataBind() End Sub Protected Sub GvNotificaciones_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GVNotificaciones.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then If DtNotificacionesUsuarios.Rows.Count > 0 Then e.Row.FCCheckBox("chkCampana").Checked = If(DtNotificacionesUsuarios.FiltroPrimeroValor("Alerta_Campana", $"CveNotificacion = {e.Row.DBCampo("CveNotificacion").ToString}").ToString = "True", True, False) e.Row.FCCheckBox("chkCorreo").Checked = If(DtNotificacionesUsuarios.FiltroPrimeroValor("Alerta_Correo", $"CveNotificacion = {e.Row.DBCampo("CveNotificacion")}").ToString = "True", True, False) e.Row.FCCheckBox("chkVentana").Checked = If(DtNotificacionesUsuarios.FiltroPrimeroValor("Alerta_Ventana", $"CveNotificacion = {e.Row.DBCampo("CveNotificacion")}").ToString = "True", True, False) e.Row.FCCheckBox("chkSMS").Checked = If(DtNotificacionesUsuarios.FiltroPrimeroValor("Alerta_SMS", $"CveNotificacion = {e.Row.DBCampo("CveNotificacion")}").ToString = "True", True, False) e.Row.FCCheckBox("chkApp").Checked = If(DtNotificacionesUsuarios.FiltroPrimeroValor("Alerta_App", $"CveNotificacion = {e.Row.DBCampo("CveNotificacion")}").ToString = "True", True, False) End If End If End Sub #End Region Protected Sub BtnCambiarUsuario_Click(sender As Object, e As EventArgs) CveUsuario = -1 Dim usuario As String = TxtEmail.Text Dim objs As New ClsSisUsuarios objs.GetWSusuarios(usuario) If objs.DtResultados.Rows.Count > 0 Then CveUsuario = objs.DtResultados.Rows(0)("CveUsuario").ToString().ToEntero() End If objs.Dispose() If CveUsuario > -1 Then CargaUsuario() Else LtlUsuario.Text = "" TxtEmail.Text = "" TxtNombre.Text = "" LtlEmpresas.Text = "" BtnDefaultPWD.Visible = False UpUsuario.Update() End If If CveCliente > 0 Then CargaDispositivos() CargarNotificaciones() End If CargaModulosAcceso() CargaModulosPermisos() CargaComandos() UpDatos.Update() RegistraScript(" $('.CustomSpinner').hide();") End Sub End Class