Formulario Ventas Simple con Datagridview y BDAccess
En esta entrada se va a ejemplificar un formulario de ventas donde se expresan algunas destrezas que anteriormente se han explicado en temas anteriores. es así que haciendo uso de las mismas se considera la siguiente captura de diseño
Explicando un poco: el formulario es sencillo y consiste en buscar el producto (registro) de acuerdo al codigo ingresado y devuelve el nombre(descripcion) del producto y el valor unitario del mismo para luego éste ser multiplicado por la cantidad de unidades pedidas.
Estos valores devueltos tanto la descripcion del producto como el valor unitario son recogidos por textboxs y por último son presentados en la grid y ser calculados el total de la factura.
Ademas si no se esta conforme con el pedido se puede eliminar de la grid seleccionado la fila y haciendo clic derecho-menu-Eliminar y automaticamente se realiza la resta y actualizacion correspondiente.
(citar control. ContextMenuStrip para el menú Eliminar y anexarlo al datagridview mediante las propiedades de este Objeto en la secuencia: Propiedades-ContextMenuStrip-ContextMenuStrip1).
Imports System.Data.OleDb
Public Class Form1
Dim andiario As New ConectarBDA
Dim filas As New DataView
Dim gridfic As New DataGridView
Dim ruta As String
Dim ds As New DataSet
Sub Buscar()
Try
Dim quebuscar As String = txtCod.Text
Dim tab As String = "SELECT * FROM Inventario ORDER BY CODIGO"
ruta = System.AppDomain.CurrentDomain.BaseDirectory
ruta &= "\datac.mdb"
andiario.Conectar(ruta, tab)
andiario.da.Fill(ds)
filas.Table = ds.Tables(0)
Dim str As String = FormatNumber(0)
filas.RowFilter = String.Format("Codigo Like '%{0}%'", quebuscar)
txtinfoprod.DataBindings.Add("Text", filas, "Descripcion")
txtinfovalor.DataBindings.Clear()
txtinfovalor.DataBindings.Add("Text", filas, "ValorUnit")
txtinfoprod.DataBindings.Clear()
Catch ex As Exception
Try
MsgBox("Producto no en contrado", vbCritical)
Catch ex2 As Exception
End Try
MessageBox.Show("ERROR al conectar o recuperar los datos:" & vbCrLf & _
ex.Message, "Conectar con la base", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub txtCod_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles txtCod.KeyPress, txtCant.KeyPress
If e.KeyChar = ChrW(Keys.Enter) Then
e.Handled = True
SendKeys.Send("{TAB}")
End If
txtCant.SelectAll()
End Sub
Private Sub txtCod_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles txtCod.LostFocus
Buscar()
End Sub
Private Sub txtCant_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles txtCant.LostFocus
llenar()
End Sub
Sub llenar()
Try
If txtinfovalor.Text And txtinfoprod.Text = "" Then
MsgBox("Producto no en contrado", vbCritical)
Else
gridV.Rows.Add(1)
Dim f As Integer = gridV.Rows.Count - 1
gridV.Item(0, f).Value = f + 1
gridV.Item(1, f).Value = txtinfoprod.Text
gridV.Item(2, f).Value = txtinfovalor.Text
gridV.Item(3, f).Value = txtCant.Text
gridV.Item(4, f).Value = gridV.Item(3, f).Value * gridV.Item(2, f).Value
TextBox1.Text = suma()
txtCod.Focus()
txtCod.SelectAll()
End If
Catch ex As Exception
MsgBox("Producto no en contrado", vbCritical)
txtCod.Focus()
txtCod.SelectAll()
End Try
End Sub
Function suma()
Dim sumar As Double
Dim f As Integer = gridV.Rows.Count - 1
For i As Integer = 0 To f
sumar = sumar + CDbl(gridV.Item(4, i).Value)
Next
Return sumar
End Function
Private Sub EliminarToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) _
Handles EliminarToolStripMenuItem.Click
gridV.Rows.Remove(gridV.CurrentRow)
suma()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
En la parte de abajo les dejo mi ejemplo:

Comentarios
Publicar un comentario