有可能你看不明白,我也说不明白,我这是用多层做的,下面是中间层的两层
第一层
procedure TTollStateTrxDM.dspTollOperationAfterApplyUpdates(
Sender: TObject;
var OwnerData: OleVariant);
begin
if not TollOperation.Active then
TollOperation.Open;
TollOperation.Last;
OwnerData:=TollOperation.FieldByname('OperateiD').AsInteger;
end;
第二层
function TTollOperationTrxUpdObj.SetTollDetail(SID: OleVariant;
var Data,
Data_Detail: OleVariant;
MaxErrors: Integer;
var ErrorCount: Integer): OleVariant;
var
TrxDM: ITollStateTrxDM;
OwnerData: OleVariant;
Server: string;
TmpClt:TClientDataSet;
OperateID:integer;
begin
if not CheckSID(SID) then
Exit;
Server := reg.GetProviderServer;
TmpClt:=TClientDataSet.Create(nil);
TmpClt.Close;
try
if Server = '' then
TrxDM := CoTollStateTrxDM.Create
else
TrxDM := CoTollStateTrxDM.CreateRemote(Server);
Result := TrxDM.AS_ApplyUpdates('dspTollOperation', Data, MaxErrors, ErrorCount, OwnerData);
OperateID:=OwnerData;
TmpClt.Data:=Data_Detail;
TmpClt.First;
while not TmpClt.Eofdo
begin
if Tmpclt.FieldByName('OperateID').AsInteger=0 then
begin
TmpClt.Edit;
TmpClt.FieldByName('OperateID').AsInteger:=OperateID;
TmpClt.Post;
end;
TmpClt.Next;
end;
Result := TrxDM.AS_ApplyUpdates('dspTollDetail', TmpClt.Data , MaxErrors, ErrorCount, OwnerData);
TmpClt.Free;
SetComplete;
except
SetAbort;
TmpClt.Free;
raise;
end;
end;
客户端
procedure TTollIN_OutFrm.btnApplyClick(Sender: TObject);
var
ErrorCount: Integer;
OperationData,DetailData:OleVariant;
begin
if (ParentFrm.rmtTollOperation.State in [dsEdit,dsInsert]) then
ParentFrm.rmtTollOperation.Post;
OperationData:=ParentFrm.rmtTollOperation.Delta ;
DetailData := ParentFrm.rmtTollDetail.Delta;
try
if ParentFrm.rmtTollOperation.ChangeCount>0 then
ParentFrm.TollOperationUpdObj.SetTollDetail(gCurUser.SecurityID,OperationData,DetailData,
ParentFrm.rmtTollDetail.ChangeCount,ErrorCount );
//ParentFrm.TollOperationUpdObj.SetTollOperation(gCurUser.SecurityID,OperationData,1,ErrorCount);
Close;
except
on E: Exceptiondo
begin
if E.Message = 'Invalid data packet' then
begin
//?????????????????????????????????????????????????????????????????
end;
end;
end;
end;
在做两层时一般采用 存储过程来解决
CREATE PROCEDURE TollOperation_add
(
@fvtype_id varchar(6),
@operation smallint,
@fvid_b varchar(20),
@fvid_e varchar(20),
@taker varchar(10),
@operateid int output
)
as
begin
tran
insert into tolloperation (fvtypeid,operation,fvid_begin
,fvid_end,taker)values(@fvtype_id,@operation,@fvid_b,@fvid_e,@taker)
select @operateid= @@IDENTITY
commit tran
GO