Foros del Web » Programación para mayores de 30 ;) » .NET »

suma cantidad celda

Estas en el tema de suma cantidad celda en el foro de .NET en Foros del Web. hola amigos...tengo un problemilla...tengo una base de datos, de ella he generado una grilla en el formulario que conecta con una tabla, el cliente inserta ...
  #1 (permalink)  
Antiguo 28/07/2011, 17:56
 
Fecha de Ingreso: noviembre-2010
Ubicación: madrid
Mensajes: 478
Antigüedad: 13 años, 5 meses
Puntos: 5
Pregunta suma cantidad celda

hola amigos...tengo un problemilla...tengo una base de datos, de ella he generado una grilla en el formulario que conecta con una tabla, el cliente inserta una serie de líneas en la grilla ahora necesito que al pulsar un botón se sume a la última línea en una celda concreta...la número 6 exactamente la cifra que hay en un textbox...lo intengo así pero nada...

For i = 0 To DgGenerados.Rows.Count - 1
Dim tod As New Integer
tod = CInt(Val(DgGenerados.Rows(i).Cells(6).Value))
tod = CInt(Val(DgGenerados.Rows(i).Cells(6).Value) + CDbl(TextDif.Text))
Next
  #2 (permalink)  
Antiguo 28/07/2011, 18:16
Avatar de HaverRamirez  
Fecha de Ingreso: junio-2011
Ubicación: Guatemala
Mensajes: 273
Antigüedad: 12 años, 9 meses
Puntos: 33
Respuesta: suma cantidad celda

Si la variable esta declarada dentro del for esta siempre se limpia

Dim tod As Integer = 0
For i = 0 To DgGenerados.Rows.Count - 1
tod += CInt(Val(DgGenerados.Rows(i).Cells(6).Value)) + cdbl(textDif.text)
Next
  #3 (permalink)  
Antiguo 29/07/2011, 10:24
 
Fecha de Ingreso: noviembre-2010
Ubicación: madrid
Mensajes: 478
Antigüedad: 13 años, 5 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

Etiquetas: cantidad, celda, suma
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:19.