422 lines
14 KiB
VB.net
422 lines
14 KiB
VB.net
|
Imports CLIENTE.clsComplejo 'permite conectarme a la base de datos y establer parametros
|
||
|
Imports System.Data.SqlClient 'para manejar objetos de datos SQL
|
||
|
Imports CLIENTE.Registro 'clase que me permite encriptar el password
|
||
|
Imports System.Data 'Para manejar objetos de estructuras de datos
|
||
|
Imports CLIENTE.clBusqueda 'para realizar busqueda en un registro
|
||
|
Imports CLIENTE.clOcultarColumna 'Permite ocultar columnas
|
||
|
Imports CLIENTE.ValidaTexto 'Permite validad las cajas de texto o combox
|
||
|
Public Class UsuarioM
|
||
|
Dim Guardar As Boolean
|
||
|
Dim Nuevo As Boolean
|
||
|
Dim clCmp As New clsComplejo()
|
||
|
Dim desh As New clsDeshabilita()
|
||
|
Dim dap As SqlDataAdapter = New SqlClient.SqlDataAdapter
|
||
|
Dim cmd As SqlCommand
|
||
|
Dim das As DataSet
|
||
|
Dim cnn As SqlConnection
|
||
|
Dim _Accion As String
|
||
|
Dim clcmj1 As New clsComplejo
|
||
|
Dim clsvariables As New clsVaribles
|
||
|
Dim blnuevo As Boolean = True
|
||
|
Dim blcarga As Boolean = True
|
||
|
Dim sql As String
|
||
|
Private Sub txtPassword_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPassword.DoubleClick
|
||
|
'MsgBox("pongo a true la bandera doble click")
|
||
|
txtPassword.ReadOnly = False
|
||
|
Nuevo = True
|
||
|
End Sub
|
||
|
|
||
|
|
||
|
Private Sub grdUsuario_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdUsuario.DoubleClick
|
||
|
Dim SQLBenef As String
|
||
|
Dim Fila As DataRow
|
||
|
Dim Classcom As New clsComplejo
|
||
|
|
||
|
|
||
|
Try
|
||
|
txtcomodin.Text = grdUsuario.Item(grdUsuario.CurrentRowIndex, 0).ToString()
|
||
|
SQLBenef = "SELECT * FROM USUARIO WHERE idUSUARIO = " & txtcomodin.Text '& " And Id_PropReal = " & ClsVariables.varidLigaCte"
|
||
|
Classcom.fdtDataSet(SQLBenef)
|
||
|
|
||
|
If Classcom.ds.Tables(0).Rows.Count <> 0 Then
|
||
|
'LLENA COMBOS
|
||
|
Fila = Classcom.ds.Tables(0).Rows(0)
|
||
|
|
||
|
|
||
|
'txtNombre.Text = Fila("Nombre")
|
||
|
'txtUsuario.Text = Fila("Usuario")
|
||
|
'txtAPaterno.Text = Fila("ApellidoPaterno")
|
||
|
'txtAMaterno.Text = Fila("ApellidoMaterno")
|
||
|
|
||
|
If Not IsDBNull(Fila("Nombre")) Then txtNombre.Text = Fila("Nombre")
|
||
|
If Not IsDBNull(Fila("Usuario")) Then txtUsuario.Text = Fila("Usuario")
|
||
|
If Not IsDBNull(Fila("ApellidoPaterno")) Then txtAPaterno.Text = Fila("ApellidoPaterno")
|
||
|
If Not IsDBNull(Fila("ApellidoMaterno")) Then txtAMaterno.Text = Fila("ApellidoMaterno")
|
||
|
If txtAMaterno.Text = "N/A" Then
|
||
|
txtAMaterno.Text = ""
|
||
|
End If
|
||
|
|
||
|
'txtPassword.Text = Registro.DesEncripta(Fila("PASSWORD"))
|
||
|
'txtPasswordConf.Text = Registro.DesEncripta(Fila("PASSWORD"))
|
||
|
|
||
|
|
||
|
cmbPerfil.SelectedValue = Fila("IdPerfil")
|
||
|
cmbPerfil.Tag = Fila("IdPerfil")
|
||
|
'cmbid_funcionario.SelectedValue = Fila("id_funcionario")
|
||
|
chkBloquear.Checked = Fila("ACTIVO")
|
||
|
chkBloquear.Tag = Fila("ACTIVO")
|
||
|
|
||
|
|
||
|
End If
|
||
|
Catch ex As System.ArgumentOutOfRangeException
|
||
|
MessageBox.Show("No existe Informacion", "MINDS Cliente", MessageBoxButtons.OK, MessageBoxIcon.Warning)
|
||
|
|
||
|
Catch ex As System.IndexOutOfRangeException
|
||
|
MessageBox.Show("No existe Informacion", "MINDS Cliente", MessageBoxButtons.OK, MessageBoxIcon.Warning)
|
||
|
|
||
|
|
||
|
Catch ex As Exception
|
||
|
MessageBox.Show("Error Busqueda; grdUsuario_DoubleClick: " & ex.Message, "MINDS Cliente", MessageBoxButtons.OK, MessageBoxIcon.Error)
|
||
|
Exit Sub
|
||
|
End Try
|
||
|
|
||
|
End Sub
|
||
|
|
||
|
Private Sub Exportar()
|
||
|
clcmj1 = New clsComplejo
|
||
|
Dim sqlgrid As String
|
||
|
Dim ClassAud As New ClassMyUtils
|
||
|
sqlgrid = "sp_ConsultarUsuarios"
|
||
|
clcmj1.fdtDataSetTabla(sqlgrid)
|
||
|
|
||
|
Try
|
||
|
If grdUsuario.VisibleRowCount = 0 Then
|
||
|
MessageBox.Show("Realiza una consulta ", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
|
||
|
Else
|
||
|
|
||
|
|
||
|
Dim clsExcel As aExcel = New aExcel
|
||
|
'Obtenemos el nombre o el titulo del form
|
||
|
clsExcel.Titulo = Me.Text
|
||
|
'Utilizo la funcion ExportDataset de la clase aExcel
|
||
|
clsExcel.ExportDataset(clcmj1.ds) 'Asigno el dataset a exportar
|
||
|
ClassAud.RT_Auditoria(clsVaribles.varUsuario, 44, 1, "EXPORTACION DE LISTADO DE USUARIOS")
|
||
|
|
||
|
'End If
|
||
|
End If
|
||
|
Catch ex As Exception
|
||
|
MessageBox.Show(ex.Message, "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Error)
|
||
|
End Try
|
||
|
End Sub
|
||
|
Private Sub UsuarioM_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
|
||
|
Dim SQLGrid As String
|
||
|
Dim ds1 As DataSet
|
||
|
|
||
|
Dim OcultarCol As clOcultarColumna = New clOcultarColumna()
|
||
|
|
||
|
Try
|
||
|
'txtPassword.ReadOnly = True
|
||
|
|
||
|
clcmj1 = New clsComplejo
|
||
|
llenagrid1()
|
||
|
'SQLGrid = " spConUsuario 2 "
|
||
|
|
||
|
|
||
|
'clcmj1.fdtDataSetTabla(SQLGrid)
|
||
|
'grdUsuario.SetDataBinding(clcmj1.ds, "Tabla") 'Llena el grid
|
||
|
' clcmj1 = New clsComplejo
|
||
|
|
||
|
clcmj1 = New clsComplejo
|
||
|
|
||
|
SQLGrid = "select IDPERFIL AS clave,PERFIL as nombre from cat_perfil"
|
||
|
clcmj1.cm.CommandText = SQLGrid
|
||
|
clcmj1.ad.SelectCommand = clcmj1.cm
|
||
|
|
||
|
clcmj1.sbLlenaCombo(SQLGrid, cmbPerfil)
|
||
|
cmbPerfil.SelectedIndex = -1
|
||
|
txtcomodin.Text = 0
|
||
|
Catch ex As Exception
|
||
|
MessageBox.Show("Error Busqueda; sbBuscas: " & ex.Message, "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Error)
|
||
|
|
||
|
End Try
|
||
|
End Sub
|
||
|
|
||
|
|
||
|
Private Sub Validar()
|
||
|
'Permite validar los cuadros de texto o combox
|
||
|
|
||
|
End Sub
|
||
|
|
||
|
Private Sub Limpiar()
|
||
|
'Limpia los controles del formulario, con la ayuda la instancia clCmp
|
||
|
clCmp.sbLimpiaControles(Me)
|
||
|
txtPassword.ReadOnly = False
|
||
|
cmbPerfil.SelectedIndex = -1
|
||
|
End Sub
|
||
|
|
||
|
Private Sub IniciaCargaForm()
|
||
|
|
||
|
'********************************************************
|
||
|
llenagrid1()
|
||
|
clCmp = New clsComplejo
|
||
|
|
||
|
sql = "spConTipoCon"
|
||
|
clCmp.sbLlenaCombo(sql, Me.cmbPerfil)
|
||
|
|
||
|
|
||
|
End Sub
|
||
|
|
||
|
|
||
|
Private Sub Llenocombo()
|
||
|
'limpio el combo
|
||
|
cmbPerfil.DataSource = Nothing
|
||
|
cmbPerfil.DataBindings.Clear()
|
||
|
'Lleno el combo de perfil a traves del procedimiento almacenado y la clase clCmp
|
||
|
Try
|
||
|
clCmp.sbLlenaCombo("spLlenaCombo", Me.cmbPerfil)
|
||
|
Catch er As Exception
|
||
|
MessageBox.Show(er.Message)
|
||
|
End Try
|
||
|
End Sub
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
Private Sub limpia()
|
||
|
txtNombre.Text = ""
|
||
|
txtUsuario.Text = ""
|
||
|
txtAPaterno.Text = ""
|
||
|
txtPassword.Text = ""
|
||
|
txtPasswordConf.Text = ""
|
||
|
txtAMaterno.Text = ""
|
||
|
'cmbPerfil.Text = ""
|
||
|
cmbPerfil.SelectedIndex = -1
|
||
|
'cmbid_funcionario.Text = ""
|
||
|
chkBloquear.Checked = False
|
||
|
End Sub
|
||
|
|
||
|
|
||
|
|
||
|
Private Sub txtPasswordConf_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPasswordConf.Validated
|
||
|
'If txtPasswordConf.Text <> txtPassword.Text Then
|
||
|
' MessageBox.Show("La Confirmacion del Password no coincide, Intentelo Nuevamente!", "Confirmacion Password", MessageBoxButtons.OK, MessageBoxIcon.Information)
|
||
|
' txtPassword.SelectAll()
|
||
|
' txtPassword.Focus()
|
||
|
'End If
|
||
|
End Sub
|
||
|
|
||
|
|
||
|
|
||
|
Private Sub BtnAlta_Click(sender As System.Object, e As System.EventArgs) Handles BtnAlta.Click
|
||
|
Dim classcom As New clsComplejo
|
||
|
Dim strSQLComodin As String
|
||
|
|
||
|
Dim ClassAud As New ClassMyUtils
|
||
|
Dim varUser As Long
|
||
|
Dim ClassComodin As New clsComplejo
|
||
|
|
||
|
Dim _Idfuncionario As Integer
|
||
|
Dim _IdUsuario As Integer
|
||
|
Dim _Nombre As String
|
||
|
Dim _Apaterno As String
|
||
|
Dim _Amaterno As String
|
||
|
Dim _usuario As String
|
||
|
Dim _password As String
|
||
|
Dim _IdPerfil As Integer
|
||
|
Dim _Activo As Integer
|
||
|
Dim _FAlta As String
|
||
|
Dim _FUltimoAcceso As String
|
||
|
Dim _FCambioPassword As String
|
||
|
Dim cadSQL As String
|
||
|
Dim fFunc As clsComplejo
|
||
|
Dim Fila As DataRow
|
||
|
|
||
|
Dim STRTABLA As String
|
||
|
|
||
|
If clsVaribles.lbDemo = True Then Exit Sub
|
||
|
|
||
|
|
||
|
'VALIDACION DE CAMPOS
|
||
|
Try
|
||
|
|
||
|
|
||
|
'NOTA: El orden de definir el query deben ser igual al orden en que
|
||
|
'fueron declarados los paramatros (variables) en el procedimiento almacenado
|
||
|
|
||
|
Try
|
||
|
|
||
|
Dim x As ValidaTexto = New ValidaTexto()
|
||
|
|
||
|
'If txtPasswordConf.Text <> txtPassword.Text Then
|
||
|
' MessageBox.Show("La Confirmacion del Password no coincide, Intentelo Nuevamente!", "Confirmacion Password", MessageBoxButtons.OK, MessageBoxIcon.Information)
|
||
|
' txtPassword.SelectAll()
|
||
|
' txtPassword.Focus()
|
||
|
' Exit Sub
|
||
|
|
||
|
'End If
|
||
|
If x.ValidaCadenas(txtNombre) = False Then
|
||
|
Exit Sub
|
||
|
End If
|
||
|
If x.ValidaCadenas(txtAPaterno) = False Then
|
||
|
Exit Sub
|
||
|
End If
|
||
|
'If x.ValidaCadenas(txtAMaterno) = False Then
|
||
|
' Exit Sub
|
||
|
' End If
|
||
|
If x.ValidaCadenas(txtNombre) = False Then
|
||
|
Exit Sub
|
||
|
End If
|
||
|
If x.ValidaCadenas(txtUsuario) = False Then
|
||
|
Exit Sub
|
||
|
End If
|
||
|
'If x.ValidaCadenas(txtPasswordConf) = False Then
|
||
|
' Exit Sub
|
||
|
'End If
|
||
|
'If x.ValidaCadenas(txtPassword) = False Then
|
||
|
' Exit Sub
|
||
|
'End If
|
||
|
'Asignacion de los valores a modificar o a insertar
|
||
|
_Nombre = txtNombre.Text
|
||
|
_Apaterno = txtAPaterno.Text
|
||
|
_Amaterno = txtAMaterno.Text
|
||
|
_usuario = txtUsuario.Text
|
||
|
|
||
|
'txtPassword.Text = CInt(Int((495 * Rnd()) + 1234)).ToString() & CInt(Int((321 * Rnd()) + 1234)).ToString()
|
||
|
|
||
|
'If txtPassword.Text <> "" Then
|
||
|
' txtPassword.Text = CInt(Int((495 * Rnd()) + 1234)).ToString() & CInt(Int((321 * Rnd()) + 1234)).ToString()
|
||
|
'End If
|
||
|
|
||
|
''Encripto el password con la ayuda de la clase registro, que recibe como parametro un string
|
||
|
'If Nuevo = True Then
|
||
|
' 'Encripto el password
|
||
|
' _password = Registro.Encripta(txtPassword.Text)
|
||
|
'Else
|
||
|
' 'si es una modificacion
|
||
|
' Dim CadDes As String
|
||
|
' ' CadDes = Registro.DesEncripta(txtPassword.Text)
|
||
|
' 'MsgBox("modificacion; " & CadDes)
|
||
|
' _password = Registro.Encripta(txtPassword.Text)
|
||
|
'End If
|
||
|
|
||
|
_password = ""
|
||
|
|
||
|
fFunc = New clsComplejo
|
||
|
|
||
|
|
||
|
|
||
|
_IdPerfil = cmbPerfil.SelectedValue
|
||
|
_Activo = chkBloquear.CheckState
|
||
|
' MsgBox(_Activo)
|
||
|
_FAlta = fFunc.ObtenFecha(Now.ToShortDateString, "yyyymmdd")
|
||
|
_FUltimoAcceso = fFunc.ObtenFecha(Now.ToShortDateString, "yyyymmdd")
|
||
|
_FCambioPassword = fFunc.ObtenFecha(Now.ToShortDateString, "yyyymmdd")
|
||
|
|
||
|
'Se declara un parametro
|
||
|
_IdUsuario = txtcomodin.Text
|
||
|
Catch er As Exception
|
||
|
' MessageBox.Show("Error al asignar valores. " & er.Message)
|
||
|
End Try
|
||
|
'End If
|
||
|
|
||
|
Dim SQL As String
|
||
|
Dim lsusu As String = ""
|
||
|
ClassComodin = New clsComplejo
|
||
|
Dim LIACCION As Integer
|
||
|
|
||
|
SQL = "SELECT idusuario FROM usuario WHERE idusuario = " & _IdUsuario
|
||
|
|
||
|
|
||
|
_Accion = "A"
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
lsusu = ""
|
||
|
Dim liAud As Integer
|
||
|
clsVaribles.lsValAnt = ClassAud.FnObtenValAnterior("SpConValoresAnteriores 6," & _IdUsuario)
|
||
|
If Len(Trim(clsVaribles.lsValAnt)) = 0 Then
|
||
|
liAud = 42
|
||
|
Else
|
||
|
liAud = 44
|
||
|
End If
|
||
|
|
||
|
|
||
|
'Se define el Query (cadena que lleva los datos a actualizar)
|
||
|
cadSQL = "" 'Estable la cadena nula o vacia
|
||
|
'"spGrabaUsuario" es el nombre del procecidimiento almacenado
|
||
|
cadSQL = cadSQL & "spGrabaUsuario "
|
||
|
cadSQL = cadSQL & "'" & _Nombre & "', "
|
||
|
cadSQL = cadSQL & "'" & _Apaterno & "', "
|
||
|
cadSQL = cadSQL & "'" & _Amaterno & "', "
|
||
|
cadSQL = cadSQL & "'" & _usuario & "', "
|
||
|
cadSQL = cadSQL & "'" & _password & "', "
|
||
|
cadSQL = cadSQL & _IdPerfil & ", "
|
||
|
cadSQL = cadSQL & _Activo & ", "
|
||
|
cadSQL = cadSQL & _IdUsuario & ", "
|
||
|
cadSQL = cadSQL & "'" & _FAlta & "', "
|
||
|
cadSQL = cadSQL & "'" & _FUltimoAcceso & "', "
|
||
|
cadSQL = cadSQL & "'" & _FCambioPassword & "', "
|
||
|
cadSQL = cadSQL & "'" & _Accion & "'" '_Idfuncionario
|
||
|
'MsgBox(cadSQL)
|
||
|
Try
|
||
|
' ClassComodin.BuscaDatos(cadSQL)
|
||
|
ClassComodin.sbInserta(cadSQL)
|
||
|
ClassAud.RT_Auditoria(clsVaribles.varUsuario, liAud, 13, clsVaribles.lsValAnt & " | Valores Nuevos: Usuario = " & _usuario & " Nombre = " & _Nombre & " " & _Apaterno & " " & _Amaterno & " Activo = " & _Activo & ", Perfil. " & cmbPerfil.Text)
|
||
|
|
||
|
If _Activo = 0 Then
|
||
|
ClassAud.RT_Auditoria(clsVaribles.varUsuario, 43, 13, clsVaribles.lsValAnt & " | Valores Nuevos: Usuario = " & _usuario & " Nombre = " & _Nombre & " " & _Apaterno & " " & _Amaterno & " Activo = " & _Activo & ", Perfil. " & cmbPerfil.Text)
|
||
|
End If
|
||
|
|
||
|
'MsgBox("0k")
|
||
|
Catch er As SqlException
|
||
|
MessageBox.Show("usuario; ModificaAgrega: " & er.Message, "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Error)
|
||
|
'Finally
|
||
|
' cnn.Close()
|
||
|
End Try
|
||
|
Limpiar()
|
||
|
'auditoria
|
||
|
''''''ClassAud.RT_Auditoria(clsVaribles.varUsuario, 98, My.Computer.Name, "Minds Cliente", "ALTA DE PARAMETROGRUPO CLAVE = " & txtClave.Text & " NOMBRE = " & cboParamRango.Text)
|
||
|
'FIN AUDITORIA
|
||
|
txtcomodin.Text = 0
|
||
|
llenagrid1()
|
||
|
MessageBox.Show("Operacion Satisfactoria ", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
|
||
|
Catch ex As Exception
|
||
|
MessageBox.Show("Error al grabar Datos" & ex.Message, "Minds", MessageBoxButtons.OK, MessageBoxIcon.Warning)
|
||
|
End Try
|
||
|
End Sub
|
||
|
Private Sub llenagrid1()
|
||
|
Dim SQLGRID As String = ""
|
||
|
Try
|
||
|
|
||
|
clcmj1 = New clsComplejo
|
||
|
SQLGRID = "sp_ConsultarUsuarios "
|
||
|
|
||
|
clcmj1.fdtDataSetTabla(SQLGRID)
|
||
|
grdUsuario.SetDataBinding(clcmj1.ds, "Tabla") 'Llena el grid
|
||
|
|
||
|
Catch ex As Exception
|
||
|
MessageBox.Show("Error al cargar usuarios " & ex.Message, "Minds", MessageBoxButtons.OK, MessageBoxIcon.Information)
|
||
|
'Finally
|
||
|
' cnn.Close()
|
||
|
End Try
|
||
|
|
||
|
End Sub
|
||
|
Private Sub BtnBuscar_Click(sender As System.Object, e As System.EventArgs)
|
||
|
llenagrid1()
|
||
|
End Sub
|
||
|
|
||
|
Private Sub BtnLimpiar_Click(sender As System.Object, e As System.EventArgs) Handles BtnLimpiar.Click
|
||
|
Limpiar()
|
||
|
End Sub
|
||
|
|
||
|
Private Sub BntSalie_Click(sender As System.Object, e As System.EventArgs) Handles BntSalie.Click
|
||
|
Me.Close()
|
||
|
End Sub
|
||
|
|
||
|
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
|
||
|
Exportar()
|
||
|
End Sub
|
||
|
|
||
|
End Class
|