我的编者是
TG20040828000
结构是TG+年月日+三位数有一很奇怪的是
从TG20040828001自动加到TG20040828009都没有问题,但是想加到10时就变为
TG200408280010,而我要的是TG20040828010
代码如下:
s:='TG'+formatdatetime('yyyymmdd',now());
with adoquery1 do
begin
close;
SQL.Clear;
sql.add('select max(订单id) as ss from 订单');
open;
end;
//自动生成编号
if adoquery1.FieldByName('ss').Value=null then
s:=s+'001'
else
begin
m:=trim(adoquery1.fieldbyname('ss').value);
i:=strtoint(trim(copy(m,11,5)));
if i<10 then
s:=s+'00'+inttostr(i+1)
else if i<100 then
s:=s+'0'+inttostr(i+1)
else
s:=s+inttostr(i+1);
end;
TG20040828000
结构是TG+年月日+三位数有一很奇怪的是
从TG20040828001自动加到TG20040828009都没有问题,但是想加到10时就变为
TG200408280010,而我要的是TG20040828010
代码如下:
s:='TG'+formatdatetime('yyyymmdd',now());
with adoquery1 do
begin
close;
SQL.Clear;
sql.add('select max(订单id) as ss from 订单');
open;
end;
//自动生成编号
if adoquery1.FieldByName('ss').Value=null then
s:=s+'001'
else
begin
m:=trim(adoquery1.fieldbyname('ss').value);
i:=strtoint(trim(copy(m,11,5)));
if i<10 then
s:=s+'00'+inttostr(i+1)
else if i<100 then
s:=s+'0'+inttostr(i+1)
else
s:=s+inttostr(i+1);
end;
当然就变成了0010
这样改应该就没问题了
s:=s+'001'
else
begin
m:=trim(adoquery1.fieldbyname('ss').value);
i:=strtoint(trim(copy(m,11,5)));
if i<9 then
s:=s+'00'+inttostr(i+1)
else if i<99 then
s:=s+'0'+inttostr(i+1)
else
s:=s+inttostr(i+1);
end;
改成
i:=strtoint(trim(copy(m,11,5)))+1;
也行
if adoquery1.FieldByName('ss').Value=null then
s:=s+'001'
else
begin
m:=trim(adoquery1.fieldbyname('ss').value);
i:=strtoint(trim(copy(m,11,5)));
s:=s+FormatFloat('0###',i+1);
end;
//自动生成编号
if adoquery1.FieldByName('ss').Value=null then
s:=s+'001'
else
begin
m:=trim(adoquery1.fieldbyname('ss').value);
i:=strtoint(trim(copy(m,11,5)));
s:=s+RightStr(FormatFloat('0###',i+1),3);
end;
前几位不说就当已经生成了只说最后三位:
m:=copy(m,1,length(m)-lengtth(inttostr(inc(strtoint(copy(m,length(m)-3,3))))))+
inttostr(inc(strtoint(copy(m,length(m)-3,3))))
直接写的,你自己看着用吧~
m:=copy(m,1,length(m)-lengtth(inttostr(inc(strtoint(copy(m,length(m)-3+1,3))))))+
inttostr(inc(strtoint(copy(m,length(m)-3+1,3))))自动增加