一段代码里面的数据操作太多。。我想写个事务把它包起来,我应该怎么作,下面事代码:
SBID:= DataSetBrokeryuan.DataSet.FieldByName('sbid').AsInteger;
DataSetBrokertan.DataSet.Close;
with TsqlDataSet(DataSetBrokertan.DataSet) do
begin
UserFilter := 'ACCENTANCE_NOTIFY_LIST.id = '+IntToStr(SBID);
end;
DataSetBrokertan.DataSet.Open;
DataSetBrokertan.DataSet.Edit;
i:=DataSetBrokeryuan.DataSet.FieldByName('cksl').AsInteger;
h:=DataSetBrokertan.DataSet.FieldByName('sssl').AsInteger;
j:=DataSetBrokertan.DataSet.FieldByName('kcsl').AsInteger;
if i+j=h then
begin
DataSetBrokertan.DataSet.FieldByName('rkbz').AsInteger:=2;
end;
DataSetBrokertan.DataSet.FieldByName('kcsl').AsInteger:=i+j;
DataSetBrokertan.DataSet.Post;
DataSetBrokertan.DataSet.ApplyUpdates;
DataSetBrokeryuan.DataSet.Delete;
if DataSetBrokeryuan.DataSet.UpdatesPending = true then
begin
DataSetBrokerYuan.DataSet.First;
while not DataSetBrokerYuan.DataSet.Eof do
begin
k:= DataSetBrokerYuan.DataSet.FieldByName('sbid').AsInteger;
n:= DataSetBrokerYuan.DataSet.FieldByName('cksl').AsInteger;
o:= DataSetBrokerYuan.DataSet.FieldByName('id').AsInteger;
Query.Close;
Query.Params.ParamByName('FAID').AsInteger:= o;
Query.Open;
m:= Query.FieldByName('cksl').AsInteger;
with TsqlDataSet(DataSetBrokertan.DataSet) do
begin
close;
UserFilter := 'ACCENTANCE_NOTIFY_LIST.id = '+IntToStr(k);
open;
end;
l:= DataSetBrokerTan.DataSet.FieldByName('kcsl').AsInteger;
if n > m+l then
begin
showmessage('出库数量多于库存数量');
DataSetBrokeryuan.DataSet.Edit;
DataSetBrokerYuan.DataSet.FieldByName('cksl').AsInteger:=m;
DataSetBrokeryuan.DataSet.Post;
end
else
begin
DataSetBrokertan.DataSet.Edit;
DataSetBrokerTan.DataSet.FieldByName('kcsl').AsInteger:= l-(n-m);
DataSetBrokertan.DataSet.Post;
DataSetBrokertan.DataSet.ApplyUpdates;
DataSetBrokeryuan.DataSet.Edit;
DataSetBrokeryuan.DataSet.Post;
end;
DataSetBrokeryuan.DataSet.next;
end;
DataSetBrokertan.DataSet.ApplyUpdates;
end;