C
c_jt
Unregistered / Unconfirmed
GUEST, unregistred user!
代码:
function Tfrmmove.getno1: string;
var
idno,id,idzero,lastidno:string;
lastidval:integer;
a:tdate;
year,FD,LD:string;
begin
idzero:='00000';
a:=strtodate(datesys);
year:=formatdatetime('yyyy',a);
FD:=year+'-01-01';
LD:=year+'-12-31';
qryunuseid1.Close;
qryunuseid1.ParamByName('year').asstring:=year;
qryunuseid1.Open;
//若找不到可用编号
if qryunuseid1.eof and qryunuseid1.bof then
begin
lastidno:='00000';
qrylastid1.Close;
qrylastid1.sql.Clear;
qrylastid1.sql.add('select max(swapid1) swapid1 from swap where ');
qrylastid1.sql.add('swapdate>='''+FD+''' and swapdate<='''+LD+'''');
//qrylastid1.sql.add('order by swapid1');
qrylastid1.Prepare;
qrylastid1.open;
if not (qrylastid1.Eof and qrylastid1.Bof) then
begin
//qrylastid1.Last;
lastidno:=qrylastid1.fieldbyname('swapid1').asstring;
end;
lastidval:=strtoint(lastidno); //出库单编号的流水值
inc(lastidval); //出库单编号+1
idno:=inttostr(lastidval); //出库单编号的数值字符串
idzero:=copy(idzero,1,(5-length(idno))); //得出零的字符串
id:=idzero+idno;//暂时得出此出库单编号
//打开不可用编号库
qryuseid1.close;
qryuseid1.ParamByName('year').asstring:=year;
qryuseid1.Open;
while not qryuseid1.Eof do
begin //若暂时出库单编号不可用
if id=qryuseid1.FieldByName('swapid1').asstring then
begin
//出库单编号+1
//lastidno:=copy(id,7,10);
lastidval:=strtoint(id); //出库单编号的流水值
inc(lastidval); //出库单编号+1
idno:=inttostr(lastidval); //出库单编号的数值字符串
idzero:=copy(idzero,1,(5-length(idno))); //得出零的字符串
id:=idzero+idno;//暂时得此出库单编号
//break;
end;
qryuseid1.Next;
end;
//将此编号写入不可用编号库
qryuseid1.Insert;
qryuseid1.FieldByName('swapid1').asstring:=id;
qryuseid1.FieldByName('used').asstring:='Y';
qryuseid1.FieldByName('year1').asstring:=year;
qryuseid1.FieldByName('userid').asinteger:=useno;
qryuseid1.Post;
try
dmmain.dbxin.ApplyUpdates([qryuseid1]);
except
//raise;
end;
end; //找不到可用编号的流程完成
//找到今天可用编号
if not (qryunuseid1.Bof and qryunuseid1.Eof) then
begin
id:=qryunuseid1.fieldbyname('swapid1').asstring;
qryunuseid1.Edit;
qryunuseid1.FieldByName('used').asstring:='Y';
qryunuseid1.FieldByName('userid').asinteger:=useno;
if qryunuseid1.State in dseditmodes then
qryunuseid1.Post;
try
dmmain.dbxin.ApplyUpdates([qryunuseid1]);
except
//raise;
end;
end;
qryunuseid1.Close;
qry.Close;
qryuseid1.Close;
qrylastid1.Close;
result:=id;
end;
select swapid1,used,id,userid,year1 from goswap1
where used='N' and year1=:year
order by swapid1
qryuseid1中的sql为
select swapid1,used,id,userid,year1 from goswap1
where year1=:year
and used='Y'
程序要求多人使用,但是得到的号自动加一,不能重复,不能缺号
但是,你们能看出这个函数为何会在使用中同时得到一个自动生成的号而不符合要求.
谢谢.欢迎留下电话,必要时我可以通过电话请教.谢谢.解决了就一定给分