想同时更新2个表 必须利用 TDatasetProvider的BeforeUpdateRecord事件.
TDatasetProvider提交数据库会先调用BeforeUpdateRecord事件.
所以我们必须在这里写sql语句一个一个的提交
procedure TDM_LYCWGL.dsp_dytcBeforeUpdateRecord(Sender: TObject;
SourceDS: TDataSet;
DeltaDS: TCustomClientDataSet;
UpdateKind: TUpdateKind;
var Applied: Boolean);
var
sqlStr: String;
ID: Integer;
begin
inherited;
try
case UpdateKind of
ukInsert:
begin
ID := DeltaDS.FieldByName('dytcID').AsInteger;
sqlStr := Format('insert into s_dytcn(dytcID,dyID,xmID,lxsID,tpbz,sftp,tcdj,'+
'DefineMan,DefineDate,ChangeMan,changeDate,DeleteMan,DeleteDate,Signlevel,signSpecial,signDetail,signUsed,signModify,signDelete,zjm) '+
'values(%d,%d,%d,%d,%d,%s,%f,'+
'%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',
[ID,
StrToInt(DeltaDS.FieldByName('dyID').NewValue),
StrToInt(DeltaDS.FieldByName('xmID').NewValue),
StrToInt(DeltaDS.FieldByName('lxsID').NewValue),
StrToInt(DeltaDS.FieldByName('tpbz').NewValue),
QuotedStr(DeltaDS.FieldByName('sftp').NewValue),
StrToFloat(DeltaDS.FieldByName('tcdj').NewValue),
QuotedStr(DeltaDS.FieldByName('DefineMan').NewValue),
QuotedStr(DeltaDS.FieldByName('DefineDate').NewValue),
QuotedStr(DeltaDS.FieldByName('ChangeMan').NewValue),
QuotedStr(DeltaDS.FieldByName('changeDate').NewValue),
QuotedStr(DeltaDS.FieldByName('DeleteMan').NewValue),
QuotedStr(DeltaDS.FieldByName('DeleteDate').NewValue),
QuotedStr(DeltaDS.FieldByName('Signlevel').NewValue),
QuotedStr(DeltaDS.FieldByName('signSpecial').NewValue),
QuotedStr(DeltaDS.FieldByName('signDetail').NewValue),
QuotedStr(DeltaDS.FieldByName('signUsed').NewValue),
QuotedStr(DeltaDS.FieldByName('signModify').NewValue),
QuotedStr(DeltaDS.FieldByName('signDelete').NewValue),
QuotedStr(DeltaDS.FieldByName('zjm').NewValue)]);
SYS_CommonDBObject.DO_SQL(sqlStr);
end;
ukModify:
begin
sqlStr := '';
AddUpdateSql(sqlStr,'dyID',DeltaDS);
AddUpdateSql(sqlStr,'xmID',DeltaDS);
AddUpdateSql(sqlStr,'lxsID',DeltaDS);
AddUpdateSql(sqlStr,'tpbz',DeltaDS);
AddUpdateSql(sqlStr,'sftp',DeltaDS);
AddUpdateSql(sqlStr,'tcdj',DeltaDS);
AddCommonFieldUpdateSql(sqlStr,DeltaDS);
if sqlStr <> '' then
begin
ID := DeltaDS.FieldByName('dytcID').OldValue;
sqlStr := Format('update s_dytcn set %s where dytcID = %d ',[sqlStr,ID]);
SYS_CommonDBObject.DO_SQL(sqlStr);
end;
end;
ukDelete:
begin
ID := DeltaDS.FieldByName('dytcID').OldValue;
sqlStr := Format('delete from s_dytcn where dytcID = %d ',[ID]);
SYS_CommonDBObject.DO_SQL(sqlStr);
end;
end;
except On e: Exceptiondo
ShowMessage(e.Message);
end;
Applied := true;
end;