自动生成单号的方法....
//单号长度,起始字符,字段名,加入天数
function TDM.CreateNO(FieldLength: Integer; NO, TableName,
FieldName: string; IsDay: boolean): string;
var
bh,Len:integer;
y,m,d:word;
y1,m1,d1,str:string;
begin
Result:='';
try
DecodeDate(Date,y,m,d);
NO:=Trim(NO);
Len:=Length(NO);
m1:=IntToStr(m);
d1:=IntToStr(d);
y1:=Copy(IntToStr
,3,2);
if m<10 then m1:='0'+m1;
if d<10 then d1:='0'+d1;
with TmpData do
begin
Close;
CommandText:='select Top 1 '+FieldName+' from '+TableName
+' where SUBSTRING('+FieldName+',1,'+IntToStr(Len)+')=:str1 and '
+' SUBSTRING('+FieldName+','+IntToStr(Len+1)+',2)=:y and '
+' SUBSTRING('+FieldName+','+IntToStr(Len+3)+',2)=:m ';
if IsDay then
begin
CommandText:=CommandText+' and SUBSTRING('+FieldName+','+IntToStr(Len+5)+',2)=:d ';
Parameters.ParamByName('d').Value:=d1;
end;
CommandText:=CommandText+' order by '+FieldName+' DESC';
Parameters.ParamByName('str1').Value:=NO;
Parameters.ParamByName('y').Value:=y1;
Parameters.ParamByName('m').Value:=m1;
open;
if IsDay then
str:=NO+y1+m1+d1+StringOfChar('0',FieldLength-Len-7)+'1'
else
str:=NO+y1+m1+StringOfChar('0',FieldLength-Len-5)+'1';
if Not IsEmpty then
begin
if IsDay then
begin
bh:=strtoint(Copy(trim(Fields[0].AsString),Len+7,FieldLength-len-6))+1;
str:=StringOfChar('0',FieldLength-Len-6-Length(IntToStr(bh)))+IntToStr(bh);
Str:=NO+y1+m1+d1+str;
end
else
begin
bh:=strtoint(Copy(trim(Fields[0].AsString),Len+5,FieldLength-len-4))+1;
str:=StringOfChar('0',FieldLength-Len-4-Length(IntToStr(bh)))+IntToStr(bh);
Str:=NO+y1+m1+str;
end;
end;
Result:=str;
end;
except
Result:='';
end;
end;