Boton Agregar,Buscar,Eliminar

Embed Size (px)

DESCRIPTION

comandos para programar botones

Citation preview

Private Sub btnbuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbuscar.Click Dim conexion As New MySqlConnection("server=localhost;user id=root;password=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='" & txtbuscar.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 sistema", MessageBoxButtons.OK, MessageBoxIcon.Information) Else MessageBox.Show("Servicio no encontrada", "Error de busqueda", MessageBoxButtons.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 SubPrivate Sub btnagregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 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 System.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.OkCancel, "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", "Elimacin", 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 System.EventArgs) Handles btnactualiza.Click txtidservicio.ReadOnly = False txtservicio.ReadOnly = False cbotipo.Enabled = True accion = False End SubPrivate Sub btnguardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 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", "Insertar", 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.Information) 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", "Actualizacion", MessageBoxButtons.OK, MessageBoxIcon.Information) Else MessageBox.Show("No se actualizaron los datos correctamente", "Actualizacion", 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