planteo el problema.
resulta que tengo un StringGrid el cual hace la funcion de detalle de factura, bien pues resulta que cuando agrego un producto hago lo siguiente:
1. si el registro ya esta en el Tstringgrid tomo los valores y le sumo lo que el usuario introduce, en caso de no existeis busco ese registro en la base de datos y loa grego al TstringGrid.
el problema surge en que el ciclo for cuando busca el registro en el TstrigGrid no funciona alguien tiene una idea adjunto todo el codigo de cuando pierde el foco un Tedit.
Código Delphi
[-]
procedure TFfactura.txtcodigoExit(Sender: TObject);
var wcodigobarras: string;
wprecio_totalouble;
wprecio_ventaouble;
i:Integer;
wcodigomodificar,wdescripcionmodificar:string;
wcantidadmodificar,wventa_totalmodificada:Integer;
wdescuentomodificar,wpreciomodificarouble;
wtotalmodificarouble;
begin
wcodigobarras:=Trim(Ffactura.txtcodigo.Text);
if wcodigobarras<>'' then
begin
For i:=1 to Ffactura.SGFact.RowCount-1 do
begin
if Ffactura.SGFact.Cells[0,i]= Trim(wcodigobarras) then
begin
wcodigomodificar:=Ffactura.SGFact.Cells[0,i]; wdescripcionmodificar:=Ffactura.SGFact.Cells[1,i]; wcantidadmodificar:=StrToInt(Ffactura.SGFact.Cells[2,i]); wpreciomodificar:=wprecioventa;
wdescuentomodificar:=StrToFloat(Ffactura.SGFact.Cells[4,i]);
if wcantidad_venta<>0 then
begin
Ffactura.SGFact.Cells[0,i]:=wcodigobarras; Ffactura.SGFact.Cells[1,i]:=wdescripcionmodificar; wventa_totalmodificada:=wcantidadmodificar+wcantidad_venta; Ffactura.SGFact.Cells[2,i]:=IntToStr(wventa_totalmodificada); wprecio_total:=(wventa_totalmodificada*wprecioventa); Ffactura.SGFact.Cells[5,i] := Format('%8.2f',[wprecio_total]);
calcula_totales;
wcantidad_venta:=0;
Ffactura.txtcodigo.Text:='';
Ffactura.txtcodigo.SetFocus;
Exit;
end
else
begin
Ffactura.SGFact.Cells[0,i]:=wcodigobarras; Ffactura.SGFact.Cells[1,i]:=wdescripcionmodificar; wventa_totalmodificada:=wcantidadmodificar+1; Ffactura.SGFact.Cells[2,i]:=IntToStr(wventa_totalmodificada); wprecio_total:=(wventa_totalmodificada*wprecioventa); Ffactura.SGFact.Cells[5,i] := Format('%8.2f',[wprecio_total]);
calcula_totales;
wcantidad_venta:=0;
Ffactura.txtcodigo.Text:='';
Ffactura.txtcodigo.SetFocus;
Exit;
end;
end
else
begin
with fmodulo.Qry_Temp2 do
begin
Close;
sql.clear;
SQL.Add('select * from articulo');
SQL.Add('where codigobarras=:Pcodigobarras');
Parameters.ParamByName('pcodigobarras').Value:=Trim(wcodigobarras);
try
Open;
if not Fmodulo.Qry_Temp2.IsEmpty then
begin
while not Fmodulo.Qry_Temp2.Eof do
begin
If Cuenta > 1 then SGFact.RowCount := SGFact.RowCount + 1;
wprecioventa:=StrToFloat(FieldByname('precioventa').AsVariant);
Ffactura.SGFact.Cells[0,cuenta] := Ffactura.txtcodigo.Text;
Ffactura.SGFact.Cells[1,Cuenta]:=(FieldByname('nombre').AsString);
if wcantidad_venta<>0 then
begin
Ffactura.SGFact.Cells[2,Cuenta]:=IntToStr(wcantidad_venta);
wprecio_total:=(wcantidad_venta*wprecioventa);
end
else
begin
Ffactura.SGFact.Cells[2,Cuenta]:='1';
wcantidad_venta:=StrToInt(SGFact.Cells[2,cuenta]);
wprecio_total:=(wcantidad_venta*wprecioventa);
end;
wprecio_venta:=FieldByname('precioventa').AsFloat;
Ffactura.SGFact.Cells[3,Cuenta]:=Format('%8.2n',[wprecio_venta]);
wcantidad_venta:=StrToInt(SGFact.Cells[2,cuenta]);
SGFact.Cells[4,Cuenta]:='0.00';
Ffactura.SGFact.Cells[5,Cuenta] := Format('%8.2f',[wprecio_total]);
Cuenta:=cuenta+1;
calcula_totales;
Next;
Ffactura.txtcodigo.Text:='';
Ffactura.txtcodigo.SetFocus;
wcantidad_venta:=0;
Exit;
end;
end
else
begin
MessageDlg('Registro'+chr(13)+'No localizado', mtError, [MBOK], 0);
Ffactura.txtcodigo.Text:='';
Ffactura.txtcodigo.SetFocus;
Exit;
end;
except
on E:EOleException do
begin
MessageDlg(Format('Error: %s Codigo: %d', [E.Message, E.ErrorCode]), mtError, [mbOK], 0);
end;
end;
end;
end;
end;
end;
end;