Imports System.Data.OleDb
Public Class FrmConsulta
Dim CN As New OleDbConnection("PROVIDER=MICROSOFT.ACE.OLEDB.12.0;DATA SOURCE=C:\Users\acer\Documents\CursoVisual.Net\EjerciciosMañana\Trabajo\Trabajo\Inventario.accdb")
Public VALOR As Integer = 0
Dim CONSULTA As String
Sub MOSTRAR()
Dim DA As New OleDbDataAdapter("SELECT COD_PRO,NOM_PRO,PRE_PRO,STK_PRO,DES_PRO,NOM_MAR,NOM_CATE " & _
"FROM (PRODUCTO INNER JOIN MARCA ON PRODUCTO.MAR_PRO=MARCA.COD_MAR) " & _
"INNER JOIN CATEGORIA ON PRODUCTO.CAT_PRO=CATEGORIA.COD_CATE", CN)
Dim DS As New DataSet
DA.Fill(DS, "PRODUCTO")
DataGridView1.DataSource = DS.Tables("PRODUCTO")
End Sub
Sub CARGAR()
Dim DA As New OleDbDataAdapter("SELECT * FROM MARCA", CN)
Dim DS As New DataSet
DA.Fill(DS, "MARCA")
CBOMARCA.DataSource = DS.Tables("MARCA")
CBOMARCA.DisplayMember = "NOM_MAR"
Dim DA_CAT As New OleDbDataAdapter("SELECT * FROM CATEGORIA", CN)
Dim DS_CAT As New DataSet
DA_CAT.Fill(DS_CAT, "CATEGORIA")
CBOCATEGORIA.DataSource = DS_CAT.Tables("CATEGORIA")
CBOCATEGORIA.DisplayMember = "NOM_CATE"
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call MOSTRAR()
Call CARGAR()
End Sub
Sub LIMPIAR()
TXTLETRAPRO.Clear()
CBOMARCA.Text = ""
CBOCATEGORIA.Text = ""
End Sub
Private Sub RBLETRA_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RBLETRA.CheckedChanged
LIMPIAR()
TXTLETRAPRO.Enabled = True
CBOMARCA.Enabled = False
CBOCATEGORIA.Enabled = False
VALOR = 1
End Sub
Private Sub RBMARCA_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RBMARCA.CheckedChanged
LIMPIAR()
TXTLETRAPRO.Enabled = False
CBOMARCA.Enabled = True
CBOCATEGORIA.Enabled = False
VALOR = 2
End Sub
Private Sub RBCATEGORIA_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RBCATEGORIA.CheckedChanged
LIMPIAR()
TXTLETRAPRO.Enabled = False
CBOMARCA.Enabled = False
CBOCATEGORIA.Enabled = True
VALOR = 3
End Sub
Private Sub BTNCONSULTAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNCONSULTAR.Click
If VALOR = 1 Then
CONSULTA = "SELECT COD_PRO,NOM_PRO,PRE_PRO,STK_PRO,DES_PRO,NOM_MAR,NOM_CATE " & _
"FROM (PRODUCTO INNER JOIN MARCA ON PRODUCTO.MAR_PRO=MARCA.COD_MAR) " & _
"INNER JOIN CATEGORIA ON PRODUCTO.CAT_PRO=CATEGORIA.COD_CATE " & _
"WHERE NOM_PRO LIKE '" & TXTLETRAPRO.Text & "%'"
'SELECT * FROM TABLA WHERE CAMPO LIKE 'LETRA%'
ElseIf VALOR = 2 Then
CONSULTA = "SELECT COD_PRO,NOM_PRO,PRE_PRO,STK_PRO,DES_PRO,NOM_MAR,NOM_CATE " & _
"FROM (PRODUCTO INNER JOIN MARCA ON PRODUCTO.MAR_PRO=MARCA.COD_MAR) " & _
"INNER JOIN CATEGORIA ON PRODUCTO.CAT_PRO=CATEGORIA.COD_CATE " & _
"WHERE NOM_MAR='" & CBOMARCA.Text & "'"
ElseIf VALOR = 3 Then
CONSULTA = "SELECT COD_PRO,NOM_PRO,PRE_PRO,STK_PRO,DES_PRO,NOM_MAR,NOM_CATE " & _
"FROM (PRODUCTO INNER JOIN MARCA ON PRODUCTO.MAR_PRO=MARCA.COD_MAR) " & _
"INNER JOIN CATEGORIA ON PRODUCTO.CAT_PRO=CATEGORIA.COD_CATE " & _
"WHERE NOM_CATE='" & CBOCATEGORIA.Text & "'"
End If
Dim DA As New OleDbDataAdapter(CONSULTA, CN)
Dim DS As New DataSet
DA.Fill(DS, "PRODUCTO")
DataGridView1.DataSource = DS.Tables("PRODUCTO")
End Sub
Private Sub BTNVER_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNVER.Click
MOSTRAR()
LIMPIAR()
RBLETRA.Checked = True
End Sub
Private Sub BTNGENERAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNGENERAR.Click
End Sub
End Class
No hay comentarios:
Publicar un comentario