比如下面这样的代码:
procedure ThreadTracData.Execute;
var
strsql: string;
i: integer;
PostStr: string;
strMsg: string;
sParam: TStringStream;
begin
{ Place thread code here }
SuperviseInfaceService.Query.Connection :=SuperviseInfaceService.Conn ;
SuperviseInfaceService.idHttp.Request.ContentType :='application/x-www-form-urlencoded';
SuperviseInfaceService.IdHTTP.ReadTimeout:=5000;
try
while not Terminated do
begin
//受理项目
strsql:='select * from AcceptItem order by Serialno';
SuperviseInfaceService.Query.SQL.Clear ;
SuperviseInfaceService.Query.SQL.Text:=strsql;
SuperviseInfaceService.Query.Open ;
if not SuperviseInfaceService.Query.Eof then
begin
for i:=0 to SuperviseInfaceService.Query.RecordCount -1 do
begin
SuperviseInfaceService.Conn.BeginTrans;
PostStr:=SuperviseInfaceService.Query.fieldByName('SerialNO').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.FieldByName('CreateTime').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('RecordType').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.FieldByName('DepartmentID').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('ItemClassID').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('ItemObjectID').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('ItemType').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('IsUnitObject').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('UnitOrder').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('AcceptDate').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('AcceptTime').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('OperatorID').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('OperatorName').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('OperatorBus').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('ApplicantOrgName').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('ApplicantPassType').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('ApplicantPassID').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('Material').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('Telephone').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('MobileTelephone').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('Fax').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('EMail').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('PostCode').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('Address').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('TagReturn').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('WriteReturn').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('IsAccepted').AsString ;
PostStr:=PostStr + '|&' + SuperviseInfaceService.Query.fieldByName('Mark').AsString ;
//SuperviseInfaceService.LogMessage(PostStr);
Try
sParam:=TStringStream.Create('');
sParam.WriteString('message='+UrlEncode(PostStr,true));
SuperviseInfaceService.IdHTTP.Post(SuperviseInfaceService.sURL,sParam);
sParam.Free;
if SuperviseInfaceService.IdHTTP.ResponseCode=200 then
begin
try
SuperviseInfaceService.Conn.BeginTrans;
InsertStr:='insert into AcceptItem_History(SerialNO,CreateTime,RecordType,DepartmentID,ItemClassID,ItemObjectID,';
InsertStr:=InsertStr + 'ItemType,IsUnitObject,UnitOrder,AcceptDate,AcceptTime,OperatorID,OperatorName,';
InsertStr:=InsertStr + 'OperatorBus,ApplicantOrgName,ApplicantPassType,ApplicantPassID,Material,Telephone,';
InsertStr:=InsertStr + 'MobileTelephone,Fax,Email,PostCode,Address,TagReturn,WriteReturn,IsAccepted,Mark,TranDate) values (';
InsertStr:=InsertStr + '''' +SuperviseInfaceService.Query.fieldByName('SerialNo').AsString + '''';
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('CreateTime').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('RecordType').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('DepartmentID').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('ItemClassID').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('ItemObjectID').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('ItemType').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('IsUnitObject').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('UnitOrder').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('AcceptDate').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('AcceptTime').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('OperatorID').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('OperatorName').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('OperatorBus').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('ApplicantOrgName').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('ApplicantPassType').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('ApplicantPassID').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('Material').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('Telephone').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('MobileTelephone').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('Fax').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('Email').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('PostCode').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('Address').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('TagReturn').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('WriteReturn').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('IsAccepted').AsString + '''' ;
InsertStr:=InsertStr + ',''' +SuperviseInfaceService.Query.fieldByName('Mark').AsString + '''' ;
InsertStr:=InsertStr + ',getdate())';
//SuperviseInfaceService.LogMessage(InsertStr);
SuperviseInfaceService.Conn.Execute(InsertStr);
strsql:='delete AcceptItem where SerialNO=''' + SuperviseInfaceService.Query.fieldByName('SerialNO').AsString + '''';
SuperviseInfaceService.Conn.Execute(strsql);
SuperviseInfaceService.Conn.CommitTrans;
except
SuperviseInfaceService.Conn.RollbackTrans;
end;
end;
except
//SuperviseInfaceService.LogMessage ('受理发送异常');
end;
SuperviseInfaceService.Query.Next;
if SuperviseInfaceService.Query.Eof then Break;
end;
end;
SuperviseInfaceService.Query.Close ;
sleep(5000);
end
except on E: Exception do
begin
SuperviseInfaceService.Conn.RollbackTrans;
SuperviseInfaceService.LogMessage('数据库错误:' + e.message);
end;
end;
end;