关于代码优化问题
//数据清零
with sjcx do
begin
close;
sql.Clear;
sql.Add('delete from sc_xsrb');
ExecSQL;
end;
sc_cjrb.Close;
sc_cjrb.Open;
//提取细纱工序开台及累计数据
with sjcx do
begin
close;
sql.Clear;
sql.Add('select pzmc,bb,sum(hjzl) hj from xscl where scrq>='''+datetostr(rq1.DateTime)+''' and scrq<='''+datetostr(rq2.DateTime)+''' and bmmc='''+trim(bmmc.Text)+''' group by pzmc,bb');
open;
end;
//插入累计产量
sjcx.First;
while not sjcx.Eof do
begin
with cx do
begin
close;
sql.Clear;
sql.Add('insert into sc_xsrb (rb_bb,rb_gx,rb_pzmc,rb_ljcl) values (:bb1,:gx,:pzmc1,:ljcl1)');
Parameters.ParamByName('bb1').Value:=sjcx.fieldbyname('bb').AsString;
Parameters.ParamByName('pzmc1').Value:=sjcx.fieldbyname('pzmc').AsString;
Parameters.ParamByName('ljcl1').Value:=sjcx.fieldbyname('hj').Value;
Parameters.ParamByName('gx').Value:='细纱';
ExecSQL;
end;
sjcx.Next;
end;
sc_cjrb.Close;
sc_cjrb.Open;
//提取细纱工序开台及当日数据
with sjcx do
begin
close;
sql.Clear;
sql.Add('select pzmc,bb,count(*) kt,sum(hjzl) hj from xscl where scrq='''+datetostr(rq2.DateTime)+''' and bmmc='''+trim(bmmc.Text)+''' group by pzmc,bb');
open;
end;
//更新车间日报中的细纱产量
sc_cjrb.First;
while not sc_cjrb.Eof do
begin
sjcx.First;
while not sjcx.Eof do
begin
with cx do
begin
close;
sql.Clear;
sql.Add('update sc_xsrb set rb_drcl=:drcl1,rb_drkt=:drkt1 where rb_bb=:bb1 and rb_pzmc=:pzmc1 and rb_gx=''细纱''');
Parameters.ParamByName('bb1').Value:=sjcx.fieldbyname('bb').AsString;
Parameters.ParamByName('pzmc1').Value:=sjcx.fieldbyname('pzmc').AsString;
Parameters.ParamByName('drkt1').Value:=sjcx.fieldbyname('kt').Value;
Parameters.ParamByName('drcl1').Value:=sjcx.fieldbyname('hj').Value;
ExecSQL;
end;
sjcx.Next;
end;
sc_cjrb.Next;
end;
以上代码执行速度较慢,请帮忙优化一下