Ver Mensaje Individual
  #3 (permalink)  
Antiguo 29/07/2011, 10:24
guillebomtrasmiti
 
Fecha de Ingreso: noviembre-2010
Ubicación: madrid
Mensajes: 478
Antigüedad: 13 años, 6 meses
Puntos: 5
Respuesta: suma cantidad celda

haver ramirez, te mando mi código...es que no entiendo muy bien como debo hacerlo, lo pue en un botón independiente pero me suma todas las líneas y no me agrega la cantidad necesaria en la última fila...gracias amigo


Public Sub multiplica()
Dim cantidad As New Integer
Dim porcentaje As New Integer
Dim total As New Integer
Dim pvp As New Integer
Dim totalpvp As New Integer


'hace el cálculo para el producto 1
porcentaje = CInt((DgGeneraTipo.CurrentRow.Cells(12).Value))
total = CInt(CDbl(TextImporte.Text) * porcentaje / 100)
pvp = CInt((DgGeneraTipo.CurrentRow.Cells(6).Value))
totalpvp = CInt(total / pvp)
TextLinea1.Text = CStr(totalpvp)


'hace el cálculo para el producto 2
porcentaje = CInt((DgGeneraTipo.CurrentRow.Cells(13).Value))
total = CInt(CDbl(TextImporte.Text) * porcentaje / 100)
pvp = CInt((DgGeneraTipo.CurrentRow.Cells(7).Value))
totalpvp = CInt(total / pvp)
TextLinea2.Text = CStr(totalpvp)


'hace el cálculo para el producto 3
porcentaje = CInt((DgGeneraTipo.CurrentRow.Cells(14).Value))
total = CInt(CDbl(TextImporte.Text) * porcentaje / 100)
pvp = CInt((DgGeneraTipo.CurrentRow.Cells(8).Value))
totalpvp = CInt(total / pvp)
TextLinea3.Text = CStr(totalpvp)



'hace el cálculo para el producto 4
porcentaje = CInt((DgGeneraTipo.CurrentRow.Cells(15).Value))
total = CInt(CDbl(TextImporte.Text) * porcentaje / 100)
pvp = CInt((DgGeneraTipo.CurrentRow.Cells(9).Value))
totalpvp = CInt(total / pvp)
TextLinea4.Text = CStr(totalpvp)


'hace el cálculo para el producto 5
porcentaje = CInt((DgGeneraTipo.CurrentRow.Cells(16).Value))
total = CInt(CDbl(TextImporte.Text) * porcentaje / 100)
pvp = CInt((DgGeneraTipo.CurrentRow.Cells(10).Value))
totalpvp = CInt(total / pvp)
TextLinea5.Text = CStr(totalpvp)


'hace el cálculo para el producto 6
porcentaje = CInt((DgGeneraTipo.CurrentRow.Cells(17).Value))
total = CInt(CDbl(TextImporte.Text) * porcentaje / 100)
pvp = CInt((DgGeneraTipo.CurrentRow.Cells(11).Value))
totalpvp = CInt(total / pvp)
TextLinea6.Text = CStr(totalpvp)


Dim adapta2 As New OleDbDataAdapter
Dim datavacio As New DataSet
Dim maximo As Integer = CInt(TextLinea1.Text)
Dim maximo2 As Integer = CInt(TextLinea2.Text)
Dim maximo3 As Integer = CInt(TextLinea3.Text)
Dim maximo4 As Integer = CInt(TextLinea4.Text)
Dim maximo5 As Integer = CInt(TextLinea5.Text)
Dim maximo6 As Integer = CInt(TextLinea6.Text)

For x As Integer = 1 To maximo
'creo los parametros que uso en el SELECT, para filtrar en el datagridview(dgtotales)
Dim comados = conexion.CreateCommand
comados.CommandType = CommandType.Text
comados.CommandText = "INSERT INTO HistoricoTickets (Producto,Euros,Fecha,Iva) SELECT Producto1,Pvp1,Fecha1,Iva1 FROM HistoricoGTickets"

conexion.Open()
frmProgressbar.Show()
Dim Lecto1 = comados.ExecuteNonQuery
frmProgressbar.Close()
conexion.Close()
Next
For x As Integer = 1 To maximo2
'creo los parametros que uso en el SELECT, para filtrar en el datagridview(dgtotales)
Dim comados2 = conexion.CreateCommand
comados2.CommandType = CommandType.Text
comados2.CommandText = "INSERT INTO HistoricoTickets (Producto,Euros,Fecha,Iva) SELECT Producto2,Pvp2,Fecha1,Iva2 FROM HistoricoGTickets"

conexion.Open()
frmProgressbar.Show()
Dim Lecto2 = comados2.ExecuteNonQuery
frmProgressbar.Close()
conexion.Close()
Next

For x As Integer = 1 To maximo3
'creo los parametros que uso en el SELECT, para filtrar en el datagridview(dgtotales)
Dim comados3 = conexion.CreateCommand
comados3.CommandType = CommandType.Text
comados3.CommandText = "INSERT INTO HistoricoTickets (Producto,Euros,Fecha,Iva) SELECT Producto3,Pvp3,Fecha1,Iva3 FROM HistoricoGTickets"

conexion.Open()
frmProgressbar.Show()
Dim Lecto3 = comados3.ExecuteNonQuery
frmProgressbar.Close()
conexion.Close()
Next

For x As Integer = 1 To maximo4
'creo los parametros que uso en el SELECT, para filtrar en el datagridview(dgtotales)
Dim comados4 = conexion.CreateCommand
comados4.CommandType = CommandType.Text
comados4.CommandText = "INSERT INTO HistoricoTickets (Producto,Euros,Fecha,Iva) SELECT Producto4,Pvp4,Fecha1,Iva4 FROM HistoricoGTickets"

conexion.Open()
frmProgressbar.Show()
Dim Lecto4 = comados4.ExecuteNonQuery
frmProgressbar.Close()
conexion.Close()
Next

For x As Integer = 1 To maximo5
'creo los parametros que uso en el SELECT, para filtrar en el datagridview(dgtotales)
Dim comados5 = conexion.CreateCommand
comados5.CommandType = CommandType.Text
comados5.CommandText = "INSERT INTO HistoricoTickets (Producto,Euros,Fecha,Iva) SELECT Producto5,Pvp5,Fecha1,Iva5 FROM HistoricoGTickets"

conexion.Open()
frmProgressbar.Show()
Dim Lecto5 = comados5.ExecuteNonQuery
frmProgressbar.Close()
conexion.Close()
Next

For x As Integer = 1 To maximo6
'creo los parametros que uso en el SELECT, para filtrar en el datagridview(dgtotales)
Dim comados6 = conexion.CreateCommand
comados6.CommandType = CommandType.Text
comados6.CommandText = "INSERT INTO HistoricoTickets (Producto,Euros,Fecha,Iva) SELECT Producto6,Pvp6,Fecha1,Iva6 FROM HistoricoGTickets"

conexion.Open()
frmProgressbar.Show()
Dim Lecto6 = comados6.ExecuteNonQuery
frmProgressbar.Close()
conexion.Close()
Next
remplazacantidad()
End Sub

'reemplaza la cantidad de 0 por 1
Public Sub remplazacantidad()
'Try
Dim adapt As New OleDbDataAdapter
Dim setda As New DataSet
Dim com = conexion.CreateCommand

com.CommandType = CommandType.Text
com.CommandText = "UPDATE HistoricoTickets SET Cantidad = (" & 1 & ") where Cantidad = (" & 0 & ")"

adapt.UpdateCommand = com
conexion.Open()
com.ExecuteNonQuery()
conexion.Close()
'Catch
'MessageBox.Show("Compruebe los datos introducidos")
' End Try
End Sub