2,495
社区成员
发帖
与我相关
我的任务
分享
function CreateID(tablename:string):string;
var
strPer:string;
strSql:string;
len:integer;
qryTmp:TADOQuery;
intPerLength:integer;
strID:string;
begin
strPer:=Comm2.strMachineNo;
qryTmp:=TADOQuery.create(nil );
qryTmp.connection:=dmDataModule.Conn;
qryTmp.SQL.Clear ;
len:=length(strPer)+1;
intPerLength:=length(strper);
strSql:='select max(substring(ID,'+inttostr(len)+',6)) as ID from '+tablename + ' where left(ID,' + inttostr(intPerLength) + ')=''' + strper + '''';
qryTmp.SQL.Text:=strSql;
qryTmp.Open;
if qryTmp.Fields[0].AsString='' then
begin
strID:=strPer + '000001';
end
else
begin
strID:=strPer + Format('%.6d',[StrToInt(qryTmp.Fields[0].asstring)+1]);
end;
CreateID:=strID;
qryTmp.Close;
qryTmp.Free;
end;