Imports DevExpress.Web
Public Class ucControlUsuarios
    Inherits System.Web.UI.UserControl
    Private Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init

        'CREAMOS LOS USUARIOS POR DEFAULT PARA AUDITORIA
        SqlDataUsuario.InsertParameters("usuario").DefaultValue = Page.User.Identity.Name
        SqlDataUsuario.UpdateParameters("usuarioModificacion").DefaultValue = Page.User.Identity.Name

    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub gridUsuarios_CustomButtonCallback(sender As Object, e As ASPxGridViewCustomButtonCallbackEventArgs) Handles gridUsuarios.CustomButtonCallback
        'PROCESO PARA ACTIVAR / DESACTIVAR USUARIO
        If (e.ButtonID = "desactivar") Then
            Dim oUsuario As New UsuariosBusinessObject(CInt(gridUsuarios.GetRowValues(e.VisibleIndex, "idUsuario")))
            If oUsuario.Entity.estado = 1 Then
                oUsuario.Entity.estado = 0
            Else
                oUsuario.Entity.estado = 1
            End If

            Dim msg As MSG = oUsuario.SaveChanges()
            If msg.EventType = dGen.Library.Entity.MSG.MsgType.Success Then
                gridUsuarios.DataBind()
            End If
        End If
    End Sub

    Private Sub SqlDataUsuario_Inserting(sender As Object, e As SqlDataSourceCommandEventArgs) Handles SqlDataUsuario.Inserting
        'PONEMOS POR DEFAULT QUE EL LOGIN SEA LA CLAVE
        e.Command.Parameters("@clave").Value = dGen.Library.Security.Cryptography.EncrypterRSAManager.Encrypt(e.Command.Parameters("@login").Value)
        'e.Command.Parameters("@codigoTrans").Value = UsuariosBusinessObject.PropuestaIDInstitucional
    End Sub

    Protected Sub gridRoles_BeforePerformDataSelect(sender As Object, e As EventArgs)
        Session("idUsuario") = CType(sender, ASPxGridView).GetMasterRowKeyValue
    End Sub

    Protected Sub gridUsuarios_HtmlDataCellPrepared(sender As Object, e As ASPxGridViewTableDataCellEventArgs) Handles gridUsuarios.HtmlDataCellPrepared
        If e.DataColumn.FieldName = "roles" Then
            If Convert.ToInt32(e.CellValue) = 0 Then
                e.Cell.BackColor = Drawing.Color.Red
            End If
        End If
    End Sub
End Class