Sei sulla pagina 1di 7

frmlistaEmpleado

Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btnNuevo.Click
Dim r As DialogResult
frmEmpleado.lblcodEmpleado.Text = oEmpleado.genCod
frmEmpleado.ShowDialog()
r = frmEmpleado.DialogResult
If r = Windows.Forms.DialogResult.OK Then
LlenarGrid()
End If
frmEmpleado.Dispose()
End Sub

Private Sub btnModificar_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnModificar.Click
frmEmpleado.bModificar = True
Dim r As DialogResult
Dim cod As String
Dim nombres As String
Dim apellidos As String
Dim Direccion As String
Dim Sesion As String
Dim pass As String
Dim nivel As String
Dim estado As String
Dim fila As Integer

If dgListaEmpleado.RowCount > 0 Then


fila = dgListaEmpleado.CurrentRow.Index
cod = dgListaEmpleado.Rows(fila).Cells(0).Value.ToString
nombres = dgListaEmpleado.Rows(fila).Cells(1).Value.ToString
apellidos = dgListaEmpleado.Rows(fila).Cells(2).Value.ToString
Direccion = dgListaEmpleado.Rows(fila).Cells(3).Value.ToString
Sesion = dgListaEmpleado.Rows(fila).Cells(4).Value.ToString
pass = dgListaEmpleado.Rows(fila).Cells(5).Value.ToString
nivel = dgListaEmpleado.Rows(fila).Cells(7).Value.ToString
estado = dgListaEmpleado.Rows(fila).Cells(6).Value.ToString
frmEmpleado.lblcodEmpleado.Text = cod
frmEmpleado.txtNombres.Text = nombres
frmEmpleado.txtApellidos.Text = apellidos
frmEmpleado.txtDireccion.Text = Direccion
frmEmpleado.txtSesion.Text = Sesion
frmEmpleado.txtRepetir.Text = pass
frmEmpleado.txtContraseña.Text = pass
frmEmpleado.cboNivel.Text = nivel

If estado = "1" Then


frmEmpleado.ChkEstado.Checked = True
Else
frmEmpleado.ChkEstado.Checked = False
End If

frmEmpleado.ChkEstado.Checked = True
frmEmpleado.ShowDialog()
r = frmEmpleado.DialogResult
If r = Wimdows.Forms.DialogResult.OK Then
LlenarGrid()
End If
frmEmpleado.Dispose()
End If
End Sub
End Class

fomulario Empleado

Public Class frmEmpleado


Public bModificar As Boolean
Dim oEmpleado As New clsEmpleado
Private Sub frmEmpleado_FromClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
bModificar = False
End Sub

Private Sub btnAceptar_Click(sender As Object, e As EventArgs) Handles btnAceptar.Click


If txtApellidos.Text = "" Then
MessageBox.Show("Debe Ingresar los Apellidos", "Aviso del Sistema")
txtApellidos.Focus()
Return
End If
If txtNombres.Text = "" Then
MessageBox.Show("Debe Ingresar los Nombres", "Aviso del Sistema")
txtNombres.Focus()
Return
End If
If txtDireccion.Text = "" Then
MessageBox.Show("Debe Ingresar su Dirección", "Aviso del Sistema")
txtDireccion.Focus()
Return
End If
If txtSesion.Text = "" Then
MessageBox.Show("Debe Ingresar el Nombre de Sesion", "Aviso del Sistema")
txtSesion.Focus()
Return
End If
If txtContraseña.Text = "" Then
MessageBox.Show("Debe Ingresar la Contraseña", "Aviso del Sistema")
txtContraseña.Focus()
Return
End If
If txtRepetir.Text <> txtContraseña.Text Then
MessageBox.Show("Las Contraseñas no Coinciden", "Aviso del Sistema")
txtRepetir.Focus()
Return
End If
If cboNivel.Text = "" Then
MessageBox.Show("Debe Elegir un Nivel de Acceso ", "Aviso del Sistema")
cboNivel.Focus()
Return
End If
oEmpleado.Codigo = lblcodEmpleado.Text
oEmpleado.Nombres = txtNombres.Text
oEmpleado.Apellidos = txtApellidos.Text
oEmpleado.Direccion = txtDireccion.Text
oEmpleado.Sesion = txtSesion.Text
oEmpleado.Pass = txtContraseña.Text
oEmpleado.Nivel = cboNivel.Text
oEmpleado.Estado = ChkEstado.Text
If bModificar = True Then
oEmpleado.Update()
Else
oEmpleado.Reg()
End If
Me.DialogResult = Windows.Forms.DialogResult.OK
End Sub

Private Sub txtNombres_KeyPress(ByVal sender As Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles txtNombres.KeyPress
If Char.IsLetter(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsSeparator(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub Limpiar()
lblcodEmpleado.Text = ""
txtNombres.Text = ""
txtApellidos.Text = ""
txtDireccion.Text = ""
txtSesion.Text = ""
txtContraseña.Text = ""
txtRepetir.Text = ""
End Sub
Private Sub Habilitar(ByVal opcion As Boolean)
btnAceptar.Enabled = Not opcion
btnCancelar.Enabled = Not opcion
cboNivel.Enabled = opcion
ChkEstado.Enabled = opcion
End Sub
Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCancelar.Click
Habilitar(False)
Limpiar()
Me.Close()
End Sub
End Class

clsEmpleado

Public Function genCod() As String


Dim oDatos As New clsEmpleado
Dim cod As String
cod = oDatos.genCod
oDatos = Nothing
Return cod
End Function
Public Function Reg() As Boolean
Dim oDatos As New clsDataEmpleado
Dim r As Integer
r = oDatos.Reg(Me)
If r = 0 Then
MessageBox.Show("No se Grabaron los Datos ", "Error")
Return False
Else
MessageBox.Show("Se Grabaron los Datos", "Exito")
Return True
End If
oDatos = Nothing
End Function
Public Function Update() As Boolean
Dim oDatos As New clsDataEmpleado
Dim r As Integer
r = oDatos.Actualizar(Me)
If r = False Then
MessageBox.Show("No se Grabaron los Datos ", "Error")
Return False
Else
MessageBox.Show("Se Grabaron los Datos", "Exito")
Return True
End If
oDatos = Nothing
End Function
End Class

Public Class frmListaEmpleado


Dim oEmpleado As New clsEmpleado
Private WithEvents bs As New BindingSource
Private Sub clsListaEmpleado_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
oEmpleado = Nothing
End Sub
Private Sub clsListaEmpleado_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
LlenarGrid()

With dgListaEmpleado
.MultiSelect = False
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
End With
End Sub
Private Sub LlenarGrid()
bs.DataSource = oEmpleado.llenarGrid()
dgListaEmpleado.DataSource = bs
End Sub
Private Sub btnCerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnCerrar.Click
Me.Close()
End Sub

Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btnNuevo.Click
Dim r As DialogResult
frmEmpleado.lblcodEmpleado.Text = oEmpleado.genCod
frmEmpleado.ShowDialog()
r = frmEmpleado.DialogResult
If r = Windows.Forms.DialogResult.OK Then
LlenarGrid()
End If
frmEmpleado.Dispose()
End Sub

Private Sub btnModificar_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnModificar.Click
frmEmpleado.bModificar = True
Dim r As DialogResult
Dim cod As String
Dim nombres As String
Dim apellidos As String
Dim Direccion As String
Dim Sesion As String
Dim pass As String
Dim nivel As String
Dim estado As String
Dim fila As Integer

If dgListaEmpleado.RowCount > 0 Then


fila = dgListaEmpleado.CurrentRow.Index
cod = dgListaEmpleado.Rows(fila).Cells(0).Value.ToString
nombres = dgListaEmpleado.Rows(fila).Cells(1).Value.ToString
apellidos = dgListaEmpleado.Rows(fila).Cells(2).Value.ToString
Direccion = dgListaEmpleado.Rows(fila).Cells(3).Value.ToString
Sesion = dgListaEmpleado.Rows(fila).Cells(4).Value.ToString
pass = dgListaEmpleado.Rows(fila).Cells(5).Value.ToString
nivel = dgListaEmpleado.Rows(fila).Cells(7).Value.ToString
estado = dgListaEmpleado.Rows(fila).Cells(6).Value.ToString
frmEmpleado.lblcodEmpleado.Text = cod
frmEmpleado.txtNombres.Text = nombres
frmEmpleado.txtApellidos.Text = apellidos
frmEmpleado.txtDireccion.Text = Direccion
frmEmpleado.txtSesion.Text = Sesion
frmEmpleado.txtRepetir.Text = pass
frmEmpleado.txtContraseña.Text = pass
frmEmpleado.cboNivel.Text = nivel

If estado = "1" Then


frmEmpleado.ChkEstado.Checked = True
Else
frmEmpleado.ChkEstado.Checked = False
End If

frmEmpleado.ChkEstado.Checked = True
frmEmpleado.ShowDialog()
r = frmEmpleado.DialogResult
If r = Wimdows.Forms.DialogResult.OK Then
LlenarGrid()
End If
frmEmpleado.Dispose()
End If
End Sub
End Class

Potrebbero piacerti anche