Option Explicit On Option Strict On Imports System.Data Imports Extensiones Partial Class Sistemas_PopUpPerfil Inherits ClsPaginas Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not Page.IsPostBack Then CType(Me.Master, BaseMasterPage).EsPopup = True CargaUsuario() CargaComandos() End If End Sub Private Sub CargaComandos() Dim ObjGPS As New ClsGPS If ObjGPS.GetUsuariosComandos(UsuarioActual.CveUsuario, UsuarioActual.CveUsuario, 1) Then GvPermisosComandos.DataSource = ObjGPS.DtResultados End If ObjGPS.Dispose() GvPermisosComandos.DataBind() UpPermisoComandos.Update() End Sub Public Sub CargaUsuario() Dim ObjUsuario As New ClsSisUsuarios If ObjUsuario.GetUsuarios(UsuarioActual.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 End If ObjUsuario.Dispose() UpUsuario.Update() 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 Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Dim Nombre As String = TxtNombre.Text.Trim Dim Correo As String = TxtEmail.Text.Trim 'VALIDA NO ALTERAR DATOS DE OTRO USUARIO Dim DtUsuarios As DataTable = GlobalDTUsuarios.FiltraParametros($"CveUsuario <> {UsuarioActual.CveUsuario}") Dim UsuariosExistentes As Integer = DtUsuarios.COUNT("CveUsuario", $"Usuario IN ('{TxtNombre.Text.Trim}','{TxtEmail.Text.Trim}') OR Correo = '{TxtEmail.Text.Trim}'") If UsuariosExistentes > 0 Then Alert("Los datos ingresados ya existen en el sistema.Favor de verificar si existe el usuario", TipoMensaje.MsgAdvertencia) Return End If Dim HuboError As Boolean = False Dim CambioContra As Boolean = False Dim ObjUsuarios As New ClsSisUsuarios 'MODIFICA DATOS DE USUARIO If Not ObjUsuarios.UpdateUsuario(UsuarioActual.Usuario, Nombre, -1, Correo, -1, -1, False, True, -1, UsuarioActual.CveUsuario, -1, -1) Then HuboError = True End If 'ASIGNA COMANDOS If Not HuboError Then For Each row As GridViewRow In GvPermisosComandos.Rows Dim Permitir As Boolean = True Dim EsFavorito As Boolean = row.FCCheckBox("ChkFavorito").Checked If Not ObjUsuarios.UpdateUsuariosComandos(UsuarioActual.CveUsuario, UsuarioActual.CveUsuario, row.DataKey("CveComando").ToEntero, Permitir, EsFavorito) Then HuboError = True Exit For End If Next End If If Not HuboError Then Dim ContraActual As String = TxtContraActual.Text 'CHECHA SI VA A CAMBIAR A LA CONTRASEÑA If Not String.IsNullOrEmpty(TxtContraActual.Text) Then If Decripta(UsuarioActual.Contraseña) = ContraActual Then Dim ContraNueva As String = TxtContraNueva.Text Dim ContraConfirm As String = TxtConfirmContra.Text If ContraNueva = ContraConfirm Then If Not ObjUsuarios.UpdateUsuarioContrasenia(Encripta(ContraNueva), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa) Then HuboError = True Else CambioContra = True End If Else Alert("La contraseña nueva no coincide.", TipoMensaje.MsgAdvertencia) End If Else Alert("La contraseña actual es incorrecta.", TipoMensaje.MsgAdvertencia) End If End If End If If Not HuboError Then ObjUsuarios.Commit() Alert("Los datos fueron guardados correctamente.") If CambioContra Then Alert("La contraseña fue modificada correctamente.") End If Else ObjUsuarios.RollBack() Alert("Ocurrió un error al guardar los cambios.") End If ObjUsuarios.Dispose() CargaGlobal() End Sub Private Sub CargaGlobal() Dim ObjUsuarios As New ClsSisUsuarios If ObjUsuarios.GetUsuariosEmpresas(-1) Then Application("GlobalDTUsuarios") = ObjUsuarios.DtResultados End If ObjUsuarios.Dispose() End Sub End Class