You are on page 1of 2

FORMULARIO BOTONES

Public Class Form1 Private Sub btnMostrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMostrar.Click Try Dim func As New funciones Dim dt As DataTable = func.mostrar DataGridView1.DataSource = dt Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub btnInsertar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsertar.Click Try Dim dts As New datos Dim func As New funciones dts.gdocumento = txtDocumento.Text dts.gnombre_apellidos = txtNombre.Text dts.gtelefono = txtTelefono.Text If func.insertar(dts) Then MsgBox("El usuario se ha insertado") txtDocumento.Clear() : txtNombre.Clear() : txtTelefono.Clear() Else MsgBox("Error al insertar") txtDocumento.Clear() : txtNombre.Clear() : txtTelefono.Clear() End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click Try Dim func As New funciones Dim dt As DataTable = func.buscar(documento:=txtBuscar.Text) txtDocumento.Text = dt.Rows(0).Item(0) txtNombre.Text = dt.Rows(0).Item(1) txtTelefono.Text = dt.Rows(0).Item(2) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub btnEditar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditar.Click Try Dim dts As New datos Dim func As New funciones dts.gdocumento = txtDocumento.Text dts.gnombre_apellidos = txtNombre.Text dts.gtelefono = txtTelefono.Text If func.editar(dts) Then

MsgBox("El usuario se ha editado") txtDocumento.Clear() : txtNombre.Clear() : txtTelefono.Clear() Else MsgBox("Error al editar") txtDocumento.Clear() : txtNombre.Clear() : txtTelefono.Clear() End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick txtDocumento.Text = DataGridView1.SelectedCells.Item(0).Value txtNombre.Text = DataGridView1.SelectedCells.Item(1).Value txtTelefono.Text = DataGridView1.SelectedCells.Item(2).Value End Sub Private Sub btnEliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEliminar.Click Try Dim dts As New datos Dim func As New funciones dts.gdocumento = txtDocumento.Text If func.eliminar(dts) Then MsgBox("El usuario se ha eliminado") txtDocumento.Clear() : txtNombre.Clear() : txtTelefono.Clear() Else MsgBox("Error al eliminar") txtDocumento.Clear() : txtNombre.Clear() : txtTelefono.Clear() End If Catch ex As Exception MsgBox(ex.Message) End Try End Sub End Class

You might also like