下面是我自己写的,你自己去研究吧,刚好是十一位: var nian,yue,fen,ss:string; begin nian:=copy(datetostr(now),3,2); yue:=copy(datetostr(now),6,2); with query2 do begin close; sql.Clear; sql.Add('select dddh from dhhtb order by dddh'); open; if Recordcount<>0 then begin last; ss:=copy(trim(fieldbyname('dddh').asstring),6,2); fen:=copy(trim(fieldbyname('dddh').AsString),9,length(trim(fieldbyname('dddh').AsString))-8); if strtoint(ss)<>strtoint(yue) then fen:='1' else fen:=inttostr(strtoint(fen)+1); fcb3.Text:=Format('PO'+nian+'/'+yue+'/%.3d',[strtoint(fen)]); end else fcb3.Text:='PO'+nian+'/'+yue+'/001'; end;
function SqNoPut(SqId: string; wDate: TDateTime; EmpSw: Integer): string; begin Result:=''; if wDate=0 then exit; if EmpSw = 0 then begin Result := SqNoEmpPut(SqId, wDate); if Result > ' ' then exit; end; Result := SqNoAdd(SqId, wDate); end;
把时间分解成年、月、日等,之后再组合成11位编号
如果不是Oracle,但又要求连续编号的话,可以自己建个编号表来实现序列器的功能,不过,自己做的序列器通常的事务相关的,使用时应小心一点.
var nian,yue,fen,ss:string;
begin
nian:=copy(datetostr(now),3,2);
yue:=copy(datetostr(now),6,2);
with query2 do
begin
close; sql.Clear;
sql.Add('select dddh from dhhtb order by dddh');
open;
if Recordcount<>0 then
begin
last;
ss:=copy(trim(fieldbyname('dddh').asstring),6,2);
fen:=copy(trim(fieldbyname('dddh').AsString),9,length(trim(fieldbyname('dddh').AsString))-8);
if strtoint(ss)<>strtoint(yue) then
fen:='1'
else
fen:=inttostr(strtoint(fen)+1);
fcb3.Text:=Format('PO'+nian+'/'+yue+'/%.3d',[strtoint(fen)]);
end
else
fcb3.Text:='PO'+nian+'/'+yue+'/001';
end;
wDate: TDateTime;
EmpSw: Integer): string;
begin
Result:='';
if wDate=0 then exit;
if EmpSw = 0 then
begin
Result := SqNoEmpPut(SqId, wDate);
if Result > ' ' then exit;
end;
Result := SqNoAdd(SqId, wDate);
end;