Ver Mensaje Individual
  #1  
Antiguo 03-07-2016
jose001 jose001 is offline
Miembro
NULL
 
Registrado: jul 2016
Posts: 13
Reputación: 0
jose001 Va por buen camino
Prolema con guardar datos usando un tStringGrid

Hola buenas tardes estoy trabajando con una aplicacion de venta usando mysql y zeos para lo cual cargo en un TstringGrid los datos como (idproducto,nombre,cantidad,precio,subtotal) luego al apretar el boton aceptar se guarda el idventa,fecha,idcliente y el total que seria la suma de todos los sub totales. El tema es el siguiente cuando guardo los datos en la base se cargan 2 filas una con los valores de la venta realizada y otra fila vacia con todos los campos null
por ejemplo en la tabla venta
Código SQL [-]
idventa
total
idcliente
fecha

se carga lo siguiente para dejarlo mas claro
idventa:1
idcliente:null
total:null
fecha:null
y en otra fila se carga por fin los datos guardados
idventa:2
idcliente:2
total:20
fecha:2016-07-02





Dejo el codigo del boton aceptar


Código Delphi [-]
procedure TfVentas.bAceptarClick(Sender: TObject);
var
i:integer;
begin

 try
  fmodulo.conexion.StartTransaction;
    with fmodulo,self do
     fmodulo.qVentas.Active:=true;
     fmodulo.qVentas.Insert;
     fmodulo.qVentas['idcliente']  := idcliente;
     fmodulo.qFecha.Open;
     fmodulo.qVentas['fechavent']  := fmodulo.qFecha['fecha'];
     fmodulo.qVentas['horavent']:= fmodulo.qFecha['hora'];
     fmodulo.qVentas['totalventa']:= eTotal.text;
     fmodulo.qFecha.Close;
     fmodulo.qVentas.Post;
     with fmodulo,self,sgDetalle do
     begin
       fmodulo.qdetalle.Active:=true;
       fmodulo.qProductos.Active:=true;
       for i := 1 to rowcount - 2 do
         begin
           fmodulo.qdetalle.Insert;
           fmodulo.qdetalle['idventa']:= fmodulo.qVentas['idventa'];
           fmodulo.qdetalle['idproducto']:= strtoint(sgDetalle.Cells[0,i]);
           fmodulo.qdetalle['precio_venta']:=  strtofloat(sgDetalle.Cells[2,i]);
           fmodulo.qdetalle['cantidad_venta']:= strtofloat(sgDetalle.Cells[3,i]);
           fmodulo.qdetalle.Post;

          if fmodulo.qProductos.Locate('idproducto',strtoint(sgDetalle.Cells[3,i],[]))= True then
           begin
            fmodulo.qProductos.Edit;
             fmodulo.qProductos['cantidadpr']:= fmodulo.qproductos['cantidadpro']-StrToInt(cells[2,i]);
              fmodulo.qProductos.Post;
           end;
         end;
     end;
finally
  fmodulo.conexion.Commit;
end;


Del boton que utilizo para seleccionar los productos

Código Delphi [-]
procedure TfListadosProductos.bSeleccionarClick(Sender: TObject);
begin
with fventas,fventas.sgDetalle,fmodulo do
fventas.sgDetalle.Cells[0,fventas.sgDetalle.RowCount-1]:= fmodulo.qProductos['idproducto'];
fventas.sgDetalle.Cells[1,fventas.sgDetalle.RowCount-1]:= fmodulo.qProductos['nombrepr'];
fventas.sgDetalle.Cells[2,fventas.sgDetalle.RowCount-1]:= fmodulo.qProductos['precio_unit'];
fventas.sgDetalle.Cells[3,fventas.sgDetalle.RowCount-1]:= eCantidad.Text ;
subtotal:=  fmodulo.qProductos['precio_unit']*StrToInt(self.eCantidad.Text)  ;
fventas.sgDetalle.Cells[4,fventas.sgDetalle.RowCount-1]:= FloattoStr(subtotal);
total:=total+subtotal;
fventas.eTotal.Text:= floattostr(total);
fventas.sgDetalle.RowCount:= fventas.sgDetalle.RowCount+1;
end;

espero que puedan ayudarme con este problema muchas gracias
Responder Con Cita