Usuario
Descontar stock

Pregunta
-
Hola a todos los amigos del foro necesito su ayuda tengo un proyecto en visual estudio 2010 ultimate necesito descontar el stock cuando realizo una venta ejmplo tengo 50 caramelos vendo 10 y se actualice al stock a 40 tengo mi proyecto en un archivo rar si alguien lo necesita mi tablas son :
clientes proveedores y stock tengo otro form que ahi esta el facturador donde se realiza la venta para descontar el stock de la columna unidades necesito su ayuda por favor no soy un programador experimentado soy nuevo muchas gracias .
Leandro
Leandro ALves
Todas las respuestas
-
se realizo varias veces esta pregunta en el foro
http://social.msdn.microsoft.com/Forums/es/vbes/thread/e8c79ec7-b162-4b9e-9a33-2343f5d38095
http://social.msdn.microsoft.com/Forums/es/vbes/thread/f7bfca97-e36f-4dc9-8bdd-15d9b4d99b39
http://social.msdn.microsoft.com/Forums/es-AR/vsgenerales/thread/375813b0-8e92-4361-9f07-e726e00c2c94
como veras realzias un UPDATE sobre stock pero debes definir que articulo vas a realizar la operacion, eso lo defines en el WHERE
saludos
Leandro Tuttini
Blog
Buenos Aires
Argentina -
Hola Leandro yo tngo el siguiente codigo y no me funciona
Public Sub Actualizar()
Dim Dl As New DChanged()
Try
Dim dinQuery As String = "UPDATE Stock SET unidades = unidades - " & CInt(TextBox4.Text) & " WHERE ID = 1;"
Dl.setConnectionString(setPath())
Dl.setClose()
Dl = Nothing
Catch ex As Exception
Dim ms As String = ex.Message
MsgBox(ms, MsgBoxStyle.Critical, "ERROR")
End Try
End Suby luego en el boton pongo Actualizar()
pero no me funciona
Leandro ALves
-
te pongo el codigo en c# que es similar a vb, de igual forma de anexo un convertidor para pasar de c# a vb
public void actualiza(int cantidad,int id) { try { string script = "update stock set unidades = unidades - "+cantidad+" where id = "+id+""; sqlCommand cmd = new SqlCommand(script, tucadenadeconexion); abrirConexion(); cmd.ExecuteNonQuery(); cerrarConexion(); MessageBox.Show("registro modificado","sistema"); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); cerrarConexion(); } }
ya con eso debe quedar, saludos
*NOTA: usa parametros para tus querys ;)
si mi respuesta te ayudo votala como util, si resolvio tu duda marcala como respuesta, de esta manera ayudas a otros compañeros que tengan dudas similares.
-
pero ese WHERE id=1 es al producto que queires descontar stock ? o sea hay un producto con id uno
se supone que en el where debes poner el producto que representa el stock, proque el stock de por si no es nada, el stock es de un producto, por eso el where debe ir el id de ese producto
ademas deberias usar parametros
no se que hacen ese Dl, pero asi como esta lo veo muy mal, el codigo deberia ser algo como esto
Dim connstring As String = "connection string" Using cn As New SqlConnection(connstring) cn.Open() Dim sql As String = "UPDATE Stock SET unidades = unidades - @unideades WHERE IDproducto = @id" Dim cmd As New SqlCommand(query, cn) cmd.Parameters.AddwithValue("@unideades", CInt(TextBox4.Text)) cmd.Parameters.AddwithValue("@id", txtIdproducto.Text) cmd.ExecuteNonQuery() End Using
saludos
Leandro Tuttini
Blog
Buenos Aires
Argentina -
Hola Leandro me lo podrias explicar pero en access porque la coneccion la tengo con ese proveedor de base de datos en este caso no utilizo sql, lo que quiero es que me actualice cualquier producto de del stock osea cuando cargo un producto para vender me descuente ese producto porque si pongo un where con un id 1 e : me actuaiza solo ese producto con ese id verdad?
Leandro ALves
- Editado Leandro2012 domingo, 20 de enero de 2013 6:46
-
si, dependiendo de que le mandes en el where ese producto va a hacer la modificacion, ahora depende como lo quieras aplicar por que igual podrias poner
where id in ('1','2','3') -- etc
aqui como son varios se tiene que tratar como cadena (poner las comillas), pero depende como quieras aplicar tu update de stock, saludossi mi respuesta te ayudo votala como util, si resolvio tu duda marcala como respuesta, de esta manera ayudas a otros compañeros que tengan dudas similares.
-
-
postea tus avancez y tambien que es lo que te sale mal y que es lo que te deberia salir, saludos
si mi respuesta te ayudo votala como util, si resolvio tu duda marcala como respuesta, de esta manera ayudas a otros compañeros que tengan dudas similares.
-
Hola Amigos del foro voy a postear parte de mi codigo aun sin resolver :
Imports System.Collections.Stack
Imports System.Drawing
Imports System.Printing
Imports System.Drawing.Image
Imports System.Drawing.Rectangle
Imports System.Drawing.Graphics
Imports System.Drawing.Brush
Public Class Facturador
Private PathAgenda As String
Private estadoGrillaCargada As Integer
Private basededatos As New Stack()
Dim i As Integer = 0
Private Sub cargarGrilla()
'Verificar si el stack está vacío
Dim emCo As New ArrayList()
emCo.Clear()
emCo.Add(New Factura())
DGV.DataBindings.Clear()
DGV.DataSource = emCo
End Sub
Private Sub push(ByVal objCol As Object)
basededatos.Push(objCol)
Dim tempStack As New Stack()
Dim daCo As New ArrayList()
Dim faCo As New Factura()
'Pase temporal de datos
daCo.Clear()
Dim i As Integer
For i = 0 To basededatos.Count - 1
Dim poping As Object = basededatos.Pop
tempStack.Push(poping)
daCo.Add(poping)
Next
i = 0
For i = 0 To tempStack.Count - 1
Dim poping As Object = tempStack.Pop
basededatos.Push(poping)
Next
'daCo.Add(faCo)
DGV.DataBindings.Clear()
DGV.DataSource = daCo
End Sub
Private Sub pop()
Try
Dim tempStack As New Stack()
Dim daCo As New ArrayList()
Dim faCo As New Factura()
basededatos.Pop()
'Pase temporal de datos
daCo.Clear()
Dim i As Integer
For i = 0 To basededatos.Count - 1
Dim poping As Object = basededatos.Pop
tempStack.Push(poping)
daCo.Add(poping)
Next
i = 0
For i = 0 To tempStack.Count - 1
Dim poping As Object = tempStack.Pop
basededatos.Push(poping)
Next
If basededatos.Count < 1 Then
cargarGrilla()
Exit Sub
End If
DGV.DataBindings.Clear()
DGV.DataSource = daCo
Catch ex As Exception
MsgBox("La grilla está vacía.", vbCritical, "ERROR EN LA GRILLA")
End Try
End Sub
Private Sub CargarFecha()
Dim Fecha As Date = Now()
DateTimePicker1.Text = Now() ' FormatDateTime(Fecha, DateFormat.ShortDate)
End Sub
#Region "Combos"
Public Sub cargarCombo()
Dim cl As New DBAccess
ComboBox1.Items.Clear()
ComboBox1.Items.Add("...")
With cl
.ConnectionString = setPath()
.Source = "Select Codigo From Stock Order By Codigo Asc;" 'Carga codigo mediante el combobox....
For Each fd In .loadCombos().Tables(0).Rows
ComboBox1.Items.Add(fd("Codigo"))
Next
End With
ComboBox1.SelectedItem = 0
cl = Nothing
End Sub
Private Sub cargarstockfactura(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged
Dim strcodigo As String = ComboBox1.Text.Trim
If strcodigo = "..." Then
TextBox2.Text = ""
TextBox3.Text = ""
Exit Sub
End If
Dim cl As New DBAccess
With cl
.ConnectionString = setPath()
.Source = "Select * From Stock Where Codigo = '" & strcodigo & "'" 'Cargar de base de datos mediante combobox...
For Each fd In .loadCombos().Tables(0).Rows
TextBox2.Text = fd("descripcion").ToString
TextBox3.Text = fd("precio").ToString
Next
End With
cl = Nothing
End Sub
#End Region
Private Sub Facturador_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cargarGrilla()
Me.Fill_DataGrid()
Call CargarFecha()
End Sub
Private Sub Fill_DataGrid()
End Sub
Private Sub controlBotones(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click
' Agregar datos a la grilla del facturador
If sender.Equals(Button1) Then
Try
Dim fctotal As Decimal = TextBox4.Text * TextBox3.Text
push(New Factura(DateTimePicker1.Text, ComboBox1.Text, TextBox2.Text, TextBox4.Text, TextBox3.Text, fctotal))
'fc = Nothing
Catch ex As Exception
MsgBox(ex.Message, vbCritical, "ERROR DE CARGA")
End Try
End If
' Extraer datos de la grilla del facturador
If sender.Equals(Button2) Then
pop()
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox10.Text = ""
TextBox11.Text = ""
TextBox12.Text = ""
End If
' Abrir datos desde archivo para Facturador...
If sender.Equals(Button3) Then
Dim dr As DerSerSOAP = New DerSerSOAP()
Dim co As Dialogs = New Dialogs()
Dim root As String = co.openFileXML()
If root.Trim() = "" Then
Exit Sub
Else
Try
Dim gr As New ArrayList()
Dim ob As Object() = CType(dr.deserialization(root), Object())
Dim fc As Object
Dim f As Factura = New Factura()
For Each fc In ob
If Not fc Is Nothing Then
gr.Add(New Factura( _
fc.Fecha, _
fc.Codigo, _
fc.Descripcion, _
fc.Cantidad, _
fc.Precio, _
fc.Total))
End If
Next
DGV.DataBindings.Clear()
DGV.DataSource = gr
Catch ex As Exception
'Sin mensajes
End Try
End If
co = Nothing
End If
' Guardar Factura
If sender.Equals(Button4) Then
Dim dr As DerSerSOAP = New DerSerSOAP()
Dim so As Dialogs = New Dialogs()
Dim fc As Factura = New Factura()
Dim objGrilla(DGV.RowCount) As Object
Dim gr As New ArrayList()
For r As Integer = 0 To DGV.RowCount - 1
objGrilla(r) = New Factura(DGV.Item(0, r).Value, _
DGV.Item(1, r).Value,
DGV.Item(2, r).Value, _
DGV.Item(3, r).Value, _
DGV.Item(4, r).Value, _
DGV.Item(5, r).Value)
Next
Dim root As String = so.saveFileXML()
If root.Trim() = "" Then
dr = Nothing
so = Nothing
fc = Nothing
Exit Sub
Else
dr.serialization(root, objGrilla)
End If
dr = Nothing
so = Nothing
fc = Nothing
End If
End Sub
Private Sub contador()
End Sub
#Region "Validaciones de textbox"
Private Sub validatingTexts(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles TextBox4.Validating
Try
e.Cancel = Not IsNumeric(TextBox4.Text.Trim())
errorColorBackground(Not IsNumeric(TextBox4.Text.Trim()))
Catch ex As Exception
e.Cancel = True
errorColorBackground(True)
End Try
End Sub
Private Sub errorColorBackground(ByVal values As Boolean)
With TextBox4
If Not values Then
.ForeColor = Color.Black
.BackColor = Color.White
Else
.ForeColor = Color.White
.BackColor = Color.Red
MsgBox("::Cantidad No puede estar Vacio::")
MsgBox("::Complete el campo solo con numeros::")
End If
End With
End Sub
Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
If Char.IsDigit(e.KeyChar) Then
e.Handled = False
ElseIf Char.IsControl(e.KeyChar) Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
#End Region
Private Sub VistaGrilla_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VistaGrilla.Click
Dim i As Integer = Me.DGV.CurrentRow.Index
Me.ComboBox1.Text = Me.DGV.Item(1, i).Value
Me.TextBox2.Text = Me.DGV.Item(2, i).Value
Me.TextBox3.Text = Me.DGV.Item(4, i).Value
Me.TextBox4.Text = Me.DGV.Item(3, i).Value
Me.TextBox5.Text = Me.DGV.Item(5, i).Value
End Sub
Public Sub Actualizar()
Dim Dl As New DChanged()
Try
Dim dinQuery As String = "UPDATE Stock SET unidades = unidades - " & CInt(TextBox4.Text) & " WHERE ID = 1;"
Dl.setConnectionString(setPath())
Dl.setClose()
Dl = Nothing
Catch ex As Exception
Dim ms As String = ex.Message
MsgBox(ms, MsgBoxStyle.Critical, "ERROR")
End Try
End Sub
Private Sub Total_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Total.Click
Dim i As Integer = Me.DGV.CurrentRow.Index
'hacemos la suma de la columna Total
Dim resul As Double = DGV.Rows.Cast(Of DataGridViewRow)().Sum(Function(x) Convert.ToDouble(x.Cells("Total").Value)) 'codigo para total general
TextBox5.Text = Convert.ToString(resul)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim Hora As Date = Now()
DateTimePicker1.Text = Now() ' FormatDateTime(Hora, DateFormat.LongTime)
End Sub
Private Sub Imprimir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Imprimir.Click
Me.PrintPreviewDialog1.Document = PrintDocument1
Me.PrintPreviewDialog1.ShowDialog()
End Sub
#Region "Impresion"
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Static pageNum As Integer
Dim i As Integer = 0
Dim rec As New Rectangle
Dim renglon As Integer = 5
Dim p As New Pen(Color.Black)
Dim p1 As New Pen(Color.Black, 2)
Dim prFont As New Font("Verdana", 10, GraphicsUnit.Point)
Dim pr2Font As New Font("Verdana", 14, GraphicsUnit.Point)
Dim pr3Font As New Font("Verdana", 18, GraphicsUnit.Point)
Dim pr1Font As New Font("Edwardian Script ITC", 24, GraphicsUnit.Point)
Dim myPincel As SolidBrush = New SolidBrush(Color.FromName("Silver"))
e.Graphics.FillRectangle(myPincel, New Rectangle(New Point(8, 250), New Size(810, 650)))
e.Graphics.FillRectangle(myPincel, New Rectangle(New Point(8, 10), New Size(809, 236)))
e.Graphics.FillRectangle(myPincel, New Rectangle(New Point(508, 900), New Size(311, 55)))
'Dim myPincel2 As SolidBrush = New SolidBrush(Color.FromName("DarkBlue")´dibujando elipse
'e.Graphics.FillEllipse(myPincel2, New Rectangle(New Point(530, 10), New Size(140, 50)))
e.Graphics.DrawRectangle(p1, 316, 35, 35, 30)
e.Graphics.DrawRectangle(p1, 8, 250, 810, 650)
e.Graphics.DrawRectangle(p1, 8, 250, 100, 650)
e.Graphics.DrawRectangle(p1, 8, 250, 200, 650)
e.Graphics.DrawRectangle(p1, 8, 250, 500, 650)
e.Graphics.DrawRectangle(p1, 8, 250, 600, 650)
e.Graphics.DrawRectangle(p1, 8, 250, 700, 650)
e.Graphics.DrawRectangle(p1, 8, 10, 809, 236)
e.Graphics.DrawRectangle(p1, 508, 900, 311, 55)
p1.Dispose()
e.Graphics.DrawString("Página " & pageNum + 1, prFont, Brushes.Black, 650, 1100)
e.Graphics.DrawString("Repuestos California", pr2Font, Brushes.Black, 10, 10)
e.Graphics.DrawString("FACTURA-", pr2Font, Brushes.Black, 200, 45)
e.Graphics.DrawString("FACTURA N°:", pr2Font, Brushes.Black, 580, 30)
e.Graphics.DrawString("B", pr3Font, Brushes.Black, 320, 38)
e.Graphics.DrawString("Consumidor Final", prFont, Brushes.Black, 250, 70)
e.Graphics.DrawString("Fecha", prFont, Brushes.DarkRed, 10, 253)
e.Graphics.DrawString("Código", prFont, Brushes.DarkRed, 110, 253)
e.Graphics.DrawString("Descripción", prFont, Brushes.DarkRed, 210, 253)
e.Graphics.DrawString("Cantidad", prFont, Brushes.DarkRed, 508, 253)
e.Graphics.DrawString("Precio", prFont, Brushes.DarkRed, 650, 253)
e.Graphics.DrawString("Total", prFont, Brushes.DarkRed, 760, 253)
e.Graphics.DrawString("Total General:", prFont, Brushes.DarkRed, 510, 920)
e.Graphics.DrawString("$", prFont, Brushes.Black, 610, 920)
e.Graphics.DrawString("Nombre:", prFont, Brushes.DarkRed, 10, 100)
e.Graphics.DrawString("Apellido:", prFont, Brushes.DarkRed, 10, 148)
e.Graphics.DrawString("Domicilio:", prFont, Brushes.DarkRed, 10, 195)
e.Graphics.DrawString("DNI:", prFont, Brushes.DarkRed, 400, 100)
e.Graphics.DrawString("C.U.I.T:", prFont, Brushes.DarkRed, 400, 148)
e.Graphics.DrawString("Localidad:", prFont, Brushes.DarkRed, 400, 195)
e.Graphics.DrawString("C.P:", prFont, Brushes.DarkRed, 600, 100)
e.Graphics.DrawString("I.V.A: 21%", prFont, Brushes.DarkRed, 600, 148)
e.Graphics.DrawLine(Pens.Black, 10, renglon + 270, 818, renglon + 270) 'Renglon de los item de la factura
e.Graphics.DrawLine(Pens.Black, 8, renglon + 85, 818, renglon + 85) 'Renglon Divisor de titulos
While i < Me.DGV.RowCount
e.Graphics.DrawString(Me.DGV.Item(0, i).Value, prFont, Brushes.Black, 10, i * 20 + 276)
e.Graphics.DrawString(Me.DGV.Item(1, i).Value, prFont, Brushes.Black, 116, i * 20 + 276)
e.Graphics.DrawString(Me.DGV.Item(2, i).Value, prFont, Brushes.Black, 210, i * 20 + 276)
e.Graphics.DrawString(Me.DGV.Item(3, i).Value, prFont, Brushes.Black, 515, i * 20 + 276)
e.Graphics.DrawString(Me.DGV.Item(4, i).Value, prFont, Brushes.Black, 658, i * 20 + 276)
e.Graphics.DrawString(Me.DGV.Item(5, i).Value, prFont, Brushes.Black, 760, i * 20 + 276)
e.Graphics.DrawString(Me.TextBox1.Text, pr2Font, Brushes.Black, 718, i * 0 + 30)
e.Graphics.DrawString(Me.TextBox5.Text, prFont, Brushes.Black, 620, i * 0 + 920)
e.Graphics.DrawString(Me.TextBox6.Text, prFont, Brushes.Black, 75, i * 0 + 100)
e.Graphics.DrawString(Me.TextBox7.Text, prFont, Brushes.Black, 75, i * 0 + 148)
e.Graphics.DrawString(Me.TextBox8.Text, prFont, Brushes.Black, 77, i * 0 + 195)
e.Graphics.DrawString(Me.TextBox9.Text, prFont, Brushes.Black, 438, i * 0 + 100)
e.Graphics.DrawString(Me.TextBox10.Text, prFont, Brushes.Black, 460, i * 0 + 148)
e.Graphics.DrawString(Me.TextBox11.Text, prFont, Brushes.Black, 475, i * 0 + 195)
e.Graphics.DrawString(Me.TextBox12.Text, prFont, Brushes.Black, 630, i * 0 + 100)
i += 1
If i > 50 Then
e.HasMorePages = True
End If
End While
'Dim myPaintArgs As New PaintEventArgs(e.Graphics, New Rectangle(New Point(20, 20), Me.Size))
'Me.InvokePaint(DGV, myPaintArgs)
End Sub
#End Region
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Actualizar()
End Sub
End Class
Esa parte del codigo es donde esta el form de facturador uso persistencia xml para guardar la factura pero lo que necesito hacer funcionar e el descuento en el stock cuando pongo vender
Leandro ALves
- Editado Leandro2012 lunes, 11 de febrero de 2013 0:53