Sei sulla pagina 1di 3

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

Eve
ntArgs) Handles btnbuscar.Click
Dim conexion As New MySqlConnection("server=localhost;user id=root;passw
ord=root;database=sistemacobro")
Dim cmd As MySqlCommand
Dim dr As MySqlDataReader
'txtcomu.Text = ""
txtbuscar.Text = InputBox("Ingresa el ID o nombre del servicio a buscar"
)
Try
cmd = New MySqlCommand("Select*From servicio where idservicio='" & t
xtbuscar.Text & "' or nombre='" & Me.txtbuscar.Text & "'", conexion)
conexion.Open()
dr = cmd.ExecuteReader
If dr.Read Then
Me.txtbuscar.Text = dr("idservicio")
Me.txtidservicio.Text = dr("idservicio")
Me.txtservicio.Text = dr("nombre")
Me.cbotipo.Text = dr("tipocobro")
MessageBox.Show("Servicio encontrada", "Servicio existe en el si
stema", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("Servicio no encontrada", "Error de busqueda", M
essageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
conexion.Close()
txtbuscar.Enabled = False
'txtcomu.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
txtbuscar.Text = ""
End Sub
Dim mireporte As New crpServicios
If conexion.consultar_allserv(services) Then
tabla = conexion.tabla
mireporte.SetDataSource(tabla)
frmReporteServicio.crpServicio.ReportSource = mireporte
frmReporteServicio.crpServicio.RefreshReport()
frmReporteServicio.Show()
End If
End Sub
Private Sub btnagregar_Click(ByVal sender As System.Object, ByVal e As System.Ev
entArgs) Handles btnagregar.Click
'txtidservicio.ReadOnly = False
' txtservicio.ReadOnly = False
cbotipo.Enabled = True
txtidservicio.Text = ""
txtservicio.Text = ""
cbotipo.Text = ""

txtidservicio.ReadOnly = False
txtservicio.ReadOnly = False
btnagregar.Enabled = False
btneliminar.Enabled = False
btnactualiza.Enabled = False
accion = True
Me.txtidservicio.Text = Me.dgservicio.RowCount
End Sub
Private Sub btneliminar_Click(ByVal sender As System.Object, ByVal e As Syst
em.EventArgs) Handles btneliminar.Click
Dim conexion As New cconex
Dim services As New cServicios
services.idservicio = txtidservicio.Text
'services.nombre_servicio = txtservicio.Text
' services.tipocobro = cbotipo.Text
Dim eliminar As MsgBoxResult
eliminar = MsgBox("Realmente deseas eliminar el servicio", MsgBoxStyle.O
kCancel, "Confirmar")
If eliminar = MsgBoxResult.Ok Then
'If accion Then
If conexion.delete_serv(services) Then
If conexion.consultar_allserv(services) Then
dgservicio.DataSource = conexion.tabla
End If
MessageBox.Show("Se eliminaron correctamente los datos", "Elimac
in", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("No se pudieron eliminar los datos", "Error!!!",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
'End If
txtidservicio.ReadOnly = True
txtservicio.ReadOnly = True
cbotipo.Enabled = False
Else
If eliminar = MsgBoxResult.Cancel Then
End If
End If

Me.TextBox1.Text = Me.dgservicio.RowCount - 1
End Sub
Private Sub btnactualiza_Click(ByVal sender As System.Object, ByVal e As Sys
tem.EventArgs) Handles btnactualiza.Click
txtidservicio.ReadOnly = False

txtservicio.ReadOnly = False
cbotipo.Enabled = True
accion = False
End Sub
Private Sub btnguardar_Click(ByVal sender As System.Object, ByVal e As System.Ev
entArgs) Handles btnguardar.Click
Dim conexion As New cconex
Dim services As New cServicios
services.idservicio = txtidservicio.Text
services.nombre_servicio = txtservicio.Text
services.tipocobro = cbotipo.Text
If accion Then
If conexion.insertar_serv(services) Then
If conexion.consultar_allserv(services) Then
dgservicio.DataSource = conexion.tabla
End If
MessageBox.Show("Se insertaron los datos correctamente", "Insert
ar", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show(" No se pudieron insertar datos, ID de la clase!
!!", "Error , ID de clase ya existe!!!", MessageBoxButtons.OK, MessageBoxIcon.In
formation)
End If
Else
If conexion.actualizar_serv(services) Then
If conexion.consultar_allserv(services) Then
dgservicio.DataSource = conexion.tabla
End If
MessageBox.Show("Se actualizaron los datos correctamente", "Actu
alizacion", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("No se actualizaron los datos correctamente", "A
ctualizacion", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
txtidservicio.ReadOnly = True
txtservicio.ReadOnly = True
cbotipo.Enabled = False
btnagregar.Enabled = True
btneliminar.Enabled = True
btnactualiza.Enabled = True
Me.TextBox1.Text = Me.dgservicio.RowCount - 1
End Sub

Potrebbero piacerti anche