Lenguaje de Programación Visual Diseñar el siguiente formulario Crear el siguiente Modulo Module Variables 'Para los productos Public Codigo As String Public Descripcion As String Public Precio As Double Public Stock As Integer Public Saldo As Integer Public Fecha As Date End Module Codificar Imports System.Data.OleDb Public Class FrmProductos Dim cn As OleDbConnection Dim ds As DataSet Dim daProducto As OleDbDataAdapter Private Sub FrmProductos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cn = New OleDbConnection("PROVIDER=Microsoft.jet.oledb.4.0;DATA Source=ALMACEN_KIMAM.mdb") cn.Open() ds = New DataSet() daProducto = New OleDbDataAdapter("Select * From Articulos", cn) daProducto.Fill(ds, "Articulos") cn.Close() Ing. Henry Marcial Arévalo Flores Página 1 ' mostramos los registros en las cajas de texto Me.TxtCodigo.DataBindings.Add("Text", ds, "Articulos.IdArticulo") Me.TxtDescripcion.DataBindings.Add("Text", ds, "Articulos.DescripcionArt") Me.TxtPrecio.DataBindings.Add("Text", ds, "Articulos.PrecioArt") Me.TxtStock.DataBindings.Add("Text", ds, "Articulos.Stock") Me.TxtSaldo.DataBindings.Add("Text", ds, "Articulos.Saldo") Me.DTPFecha.DataBindings.Add("Text", ds, "Articulos.FechaArt") End Sub Private Sub BtnSiguiente_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSiguiente.Click If Me.BindingContext(ds, "Articulos").Position < Me.ds.Tables("Articulos").Rows.Count - 1 Then Me.BindingContext(ds, "Articulos").Position = (Me.BindingContext(ds, "Articulos").Position + 1) Else '' End If End Sub Private Sub BtnAnterior_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAnterior.Click If Me.BindingContext(ds, "Articulos").Position > 0 Then Me.BindingContext(ds, "Articulos").Position = (Me.BindingContext(ds, "Articulos").Position - 1) Else '' End If End Sub Private Sub BtnPrimero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPrimero.Click Me.BindingContext(ds, "Articulos").Position = 0 End Sub Private Sub BtnUltimo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUltimo.Click Me.BindingContext(ds, "Articulos").Position = (ds.Tables("Articulos").Rows.Count - 1) End Sub Private Sub BtnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNuevo.Click Me.TxtCodigo.Text = String.Empty Me.TxtDescripcion.Text = String.Empty Me.TxtPrecio.Text = String.Empty Me.TxtStock.Text = String.Empty Me.TxtSaldo.Text = String.Empty Me.TxtCodigo.Focus() End Sub Private Sub BtnModificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnModificar.Click cn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=ALMACEN_KIMAM.mdb") cn.Open() Dim cmd As OleDbCommand Codigo = TxtCodigo.Text.Trim() Descripcion = TxtDescripcion.Text.Trim() Precio = Double.Parse(TxtPrecio.Text.Trim()) Stock = Integer.Parse(TxtStock.Text.Trim()) Saldo = Integer.Parse(TxtSaldo.Text.Trim()) Fecha = Date.Parse(DTPFecha.Text.Trim()) cmd = New OleDbCommand("UPDATE articulos SET idarticulo=@idarticulo,descripcionart=@descripcion,precioart=@precio,stock=@stock,saldo=@saldo,fechaart=@fecha WHERE idarticulo=@idarticulo") cmd.Parameters.Add("@idarticulo", OleDbType.VarChar) cmd.Parameters("@idarticulo").Value = Codigo Lenguaje de Programación Visual cmd.Parameters.Add("@descripcion", OleDbType.VarChar) cmd.Parameters("@descripcion").Value = Descripcion cmd.Parameters.Add("@precio", OleDbType.Double) cmd.Parameters("@precio").Value = Precio cmd.Parameters.Add("@stock", OleDbType.Integer) cmd.Parameters("@stock").Value = Stock cmd.Parameters.Add("@saldo", OleDbType.Integer) cmd.Parameters("@saldo").Value = Saldo cmd.Parameters.Add("@fecha", OleDbType.Date) cmd.Parameters("@fecha").Value = Fecha cmd.Connection = cn If (MessageBox.Show("Está seguro que desea modificar?", "Mensaje", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then cmd.ExecuteNonQuery() End If cn.Close() End Sub Private Sub BtnGrabar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGrabar.Click cn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=ALMACEN_KIMAM.mdb") cn.Open() Dim cmd As OleDbCommand Codigo = TxtCodigo.Text.Trim() Descripcion = TxtDescripcion.Text.Trim() Precio = Double.Parse(TxtPrecio.Text.Trim()) Stock = Integer.Parse(TxtStock.Text.Trim()) Saldo = Integer.Parse(TxtSaldo.Text.Trim()) Fecha = Date.Parse(Me.DTPFecha.Text.Trim()) cmd = New OleDbCommand("INSERT INTO articulos VALUES (@idarticulo,@descripcion,@precio,@stock,@saldo,@fecha)") cmd.Parameters.Add("@idarticulo", OleDbType.VarChar) cmd.Parameters("@idarticulo").Value = Codigo cmd.Parameters.Add("@descripcion", OleDbType.VarChar) cmd.Parameters("@descripcion").Value = Descripcion cmd.Parameters.Add("@precio", OleDbType.Double) cmd.Parameters("@precio").Value = Precio cmd.Parameters.Add("@stock", OleDbType.Integer) cmd.Parameters("@stock").Value = Stock cmd.Parameters.Add("@saldo", OleDbType.Integer) cmd.Parameters("@saldo").Value = Saldo cmd.Parameters.Add("@Fecha", OleDbType.Date) cmd.Parameters("@fecha").Value = Fecha cmd.Connection = cn If (MessageBox.Show("Está seguro que desea grabar?", "Mensaje", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then cmd.ExecuteNonQuery() End If cn.Close() End Sub Private Sub BtnEliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEliminar.Click 'Dim cn As OleDbConnection cn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=ALMACEN_KIMAM.mdb") cn.Open() Dim cmd As OleDbCommand Dim Idarticulo As String = TxtCodigo.Text.Trim() cmd = New OleDbCommand("DELETE FROM articulos WHERE idarticulo=@idarticulo") Ing. Henry Marcial Arévalo Flores Página 3 cmd.Parameters.Add("@idarticulo", OleDbType.VarChar) cmd.Parameters("@idarticulo").Value = Idarticulo cmd.Connection = cn If (MessageBox.Show("Está seguro que desea eliminar?", "Mensaje", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then cmd.ExecuteNonQuery() End If If Me.BindingContext(ds, "Articulos").Position < Me.ds.Tables("Articulos").Rows.Count - 1 Then Me.BindingContext(ds, "Articulos").Position = (Me.BindingContext(ds, "Articulos").Position + 1) Else '' End If cn.Close() End Sub Private Sub BtnSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSalir.Click End End Sub Private Sub BtnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBuscar.Click Dim cn As OleDbConnection cn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=ALMACEN_KIMAM.mdb") cn.Open() dtA.Clear() Dim Codigo As String = InputBox("Ingrese el código del producto a buscar: ") ds = New DataSet() daProducto = New OleDbDataAdapter("Select * From Articulos WHERE idarticulo='" & Codigo & "'", cn) daProducto.Fill(dtA) If (dtA.Rows.Count <> 0) Then MessageBox.Show("Registro encontrado", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information) Me.TxtCodigo.Text = dtA.Rows(0)(0).ToString Me.TxtDescripcion.Text = dtA.Rows(0)(1).ToString Me.TxtPrecio.Text = dtA.Rows(0)(2).ToString Me.TxtStock.Text = dtA.Rows(0)(3).ToString Me.TxtSaldo.Text = dtA.Rows(0)(4).ToString Me.DTPFecha.Value = dtA.Rows(0)(5).ToString Else MessageBox.Show("Registro no encontrado", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information) Me.BtnBuscar.Focus() End If cn.Close() End Sub End Class