我在AfterFlowOut事件写如下代码
procedure TYMJFSYWLC.ProcUnitYMJCWQRYWGNAfterFlowOut(Sender: TObject; Command: TFlowOutCommand);
var
Connection: TConnection;
lTransHandle: TTransactionHandle;
lQuery:TQuery;
NewGuid,s,id,SQDW,WLBM:string;
RKSL:double;
begin
//处理库存
try
id := Command.FlowControl.Flow.ID ;
except
Business.Forms.Dialogs.ShowMessage( '流程数据错误!');
exit;
end;
Connection:=TConnection.Create(nil);
Connection.ConnectionString:='DATABASEURL=Biz:\GYLGLXT\YWSJK.Database';
Connection.Open;
try
lQuery:=TQuery.Create(nil);
lQuery.Connection:=Connection;
lQuery.CommandText:='select CKMXB.*,A.SQDW from CKMXB inner join YMJB A on CKMXB.GLID=A.ID where CKMXB.TKS>0 and A.id='''+id+'''';
lQuery.Open;
lTransHandle := Connection.Transaction.Start(False);
while not lQuery.Eof do
begin
SQDW:=lQuery.FieldByName('SQDW').AsString;
WLBM:=lQuery.FieldByName('WLBM').AsString;
RKSL:=lQuery.FieldByName('TKS').AsFloat*lQuery.FieldByName('HSBL').AsFloat;
NewGUID:=Business.System.JSCommon.CreateGUIDStr;
s:='if((select count(id) from WLKCB where CFCK='''+SQDW+''' and WLBM='''+WLBM+''')>0)';
s:=s+'update WLKCB set KCL=KCL+'+SysUtils.FloatToStr(RKSL)+' where CFCK='''+SQDW+''' and WLBM='''+WLBM+'''';
s:=s+' else insert into WLKCB(ID,WLBM,DJ,CFCK,WLZT,CGFS,KCL,RKSJ,MEMO) select '''+NewGUID+''' as ID,WLBM,DJ,'''+SQDW+''' as CFCK,WLZT,CGFS,'+SysUtils.FloatToStr(RKSL)+' as KCL,getdate() as RKSJ,MEMO from WLKCB,YMJB where WLKCB.CFCK=YMJB.CKCK and YMJB.ID='''+ID+''' and WLKCB.WLBM='''+WLBM+'''';
Connection.ExecuteSQL(s);
lQuery.Next;
end;
Connection.Transaction.Commit(lTransHandle);
except
Connection.Transaction.RollBack(lTransHandle);
Command.Accept:=False;
Raise;
end;
lQuery.Free;
Connection.Free;
end;
进行库存处理,现在问题是如果数据库操作中出现异常,而流程已经流转下去了,这种情况怎么处理?
我的意思是应该在哪个事件中处理库存,可以保证出错时流程不能流转,或者有什么可以变通的方案。 |