Está en la página 1de 6

Imports System.Data.

SqlClient
Public Class FormCompraRapida
Public dbconex As New SqlConnection("uid=sa; server=(local);database=sistema
;pwd=02645208ab@")
Public tablap As DataTable
Public total As Double
Private Sub txtNombreArticulo_KeyPress(sender As Object, e As KeyPressEventA
rgs) Handles txtNombreArticulo.KeyPress
If e.KeyChar = Chr(Keys.Enter) And txtNombreArticulo.Text <> "" Then
NombreArticulo.Focus()
End If
End Sub
Private Sub txtNombreArticulo_TextChanged(sender As Object, e As EventArgs)
Handles txtNombreArticulo.TextChanged
Try
dbconex.Open()
NombreArticulo.Visible = True
NombreArticulo.Items.Clear()
Using cmd As New SqlCommand
cmd.Connection = dbconex
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "ListaRapidaArticulo"
cmd.Parameters.Add("@lista", SqlDbType.VarChar).Value = txtNombr
eArticulo.Text
Using rs As SqlDataReader = cmd.ExecuteReader
While rs.Read
NombreArticulo.Items.Add(rs.Item(1).ToString)
End While
End Using
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If dbconex.State Then
dbconex.Close()
End If
End Try
End Sub
Private Sub FormCompraRapida_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
NombreArticulo.Visible = False
tablap = New DataTable
tablap.Columns.Add("nombrearticulo", GetType(String))
tablap.Columns.Add("nombreunidad", GetType(String))
tablap.Columns.Add("cantidad", GetType(Double))
tablap.Columns.Add("precio", GetType(Double))
tablap.Columns.Add("importe", GetType(Double))
Articulo.DataSource = tablap
Venta.Enabled = False
Costo.Enabled = False
TxtTotal.Text = "0"
End Sub
Private Sub NombreArticulo_KeyPress(sender As Object, e As KeyPressEventArgs
) Handles NombreArticulo.KeyPress
If e.KeyChar = Chr(Keys.Enter) Then
Try
txtNombreArticulo.Text = NombreArticulo.Text
NombreArticulo.Visible = False
NombreArticulo.Items.Clear()
Unidad.Items.Clear()
dbconex.Open()
Using cmd As New SqlCommand
cmd.Connection = dbconex
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "LlenaComboUnidad"
cmd.Parameters.Add("@NombreArticulo", SqlDbType.VarChar).Val
ue = txtNombreArticulo.Text
Using rs As SqlDataReader = cmd.ExecuteReader
While rs.Read
Unidad.Items.Add(rs.Item(0).ToString)
End While
End Using
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If dbconex.State Then
dbconex.Close()
End If
End Try
End If
End Sub
Private Sub NombreArticulo_SelectedIndexChanged(sender As Object, e As Event
Args) Handles NombreArticulo.SelectedIndexChanged
End Sub
Private Sub Unidad_SelectedIndexChanged(sender As Object, e As EventArgs) Ha
ndles Unidad.SelectedIndexChanged
Try
dbconex.Open()
Using cmd As New SqlCommand
cmd.Connection = dbconex
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "VentaCostoUnidad"
cmd.Parameters.Add("@NombreArticulo", SqlDbType.VarChar).Value =
txtNombreArticulo.Text
cmd.Parameters.Add("@NombreUnidad", SqlDbType.VarChar).Value = U
nidad.Text
Using rs As SqlDataReader = cmd.ExecuteReader
While rs.Read
Venta.Text = rs.Item(0).ToString
Costo.Text = rs.Item(1).ToString
TxtStock.Text = rs.Item(2) / rs.Item(3)
End While
End Using
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If dbconex.State Then
dbconex.Close()
End If
End Try
End Sub
Private Sub CmdAgregar_Click(sender As Object, e As EventArgs) Handles CmdAg
regar.Click
Dim fila As DataRow
fila = tablap.NewRow
fila(0) = txtNombreArticulo.Text
fila(1) = Unidad.Text
fila(2) = Val(TxtCantidad.Text)
fila(3) = Val(Venta.Text)
fila(4) = fila(2) * fila(3)
total = total + fila(4)
TxtTotal.Text = Str(total)
tablap.Rows.Add(fila)
Articulo.DataSource = tablap
End Sub
Private Sub CmdEliminar_Click(sender As Object, e As EventArgs) Handles CmdE
liminar.Click

Dim total1 As Double
total1 = Convert.ToDouble(TxtTotal.Text)
Dim celda As Double
celda = Articulo.CurrentRow.Cells(4).Value
total1 = total1 - celda
TxtStock.Text = Str(total1)
Articulo.Rows.RemoveAt(0)


End Sub
End Class

También podría gustarte