编号:040727001
解释:04为年份,07为月份,27为日期,001表示当天的第一个顾客.
040727033 意思为04年7月27号的第33个顾客!
040728012 意思为04年7月28号的第12个顾客!这样的编号要让access自动生成应该怎么做啊?
解释:04为年份,07为月份,27为日期,001表示当天的第一个顾客.
040727033 意思为04年7月27号的第33个顾客!
040728012 意思为04年7月28号的第12个顾客!这样的编号要让access自动生成应该怎么做啊?
procedure Tpurin03.po01AfterInsert(DataSet: TDataSet);
var now:SYSTEMTIME;
s,sm:string;
i,j,q:integer;
begin
getLocalTime(now);
ADOQuery1.Close ;
ADOQuery1.SQL.Clear ;
ADOQuery1.SQL.Add('select max(poID) from po01 ');
ADOQuery1.open;
sm:=inttostr(now.wMonth);
if length(sm)=1 then sm:='0'+sm;
if ADOQuery1.fields[0].AsString<>'' then
begin
if sm=copy(ADOQuery1.fields[0].AsString,6,2) then
begin
s:=copy(ADOQuery1.fields[0].AsString,8,3);
q:=strtoint(s)+1;
i:=3-length(inttostr(q));
s:=inttostr(q);
for j:=1 to i do
begin
s:='0'+s;
end;
po01.Fields.FieldByName('poID').Asstring :='PO-'+copy(inttostr(now.wYear),3,2)+sm+s;
end else
po01.Fields.FieldByName('poID').Asstring :='PO-'+copy(inttostr(now.wYear),3,2)+sm+'001';
end else
begin
po01.Fields.FieldByName('poID').Asstring :='PO-'+copy(inttostr(now.wYear),3,2)+sm+'001';
end;
end;
var
y,m,d:WORD;
AutoStr:String;
begin
DecodeDate(Now,y,m,d);
y:=y mod 100;
if y<10 then AutoStr:=AutoStr+'0';
AutoStr:=AutoStr+IntToStr(y);
if d<10 then AutoStr:=AutoStr+'0';
AutoStr:=AutoStr+IntToStr(d);
ADOQuery1.Close;
ADOQuery1.SQL.Text:='SELECT MAX(编号) FROM CUSTOMER WHERE 编号 LIKE '''+AutoStr+'%''';
ADOQuery1.Open;
AutoStr:=AutoStr+Copy(ADOQuery1.Fields[0].Value,Length(ADOQuery1.Fields[0].Value)-2,3);
DataSet.Edit;
DataSet.Fields[1].Value:=AutoStr;
end;
procedure TForm1.ADOTable1AfterInsert(DataSet: TDataSet);
var
y,m,d:WORD;
AutoStr,CountStr:String;
begin
DecodeDate(Now,y,m,d);
y:=y mod 100;
if y<10 then AutoStr:=AutoStr+'0';
AutoStr:=AutoStr+IntToStr(y);
if m<10 then AutoStr:=AutoStr+'0';
AutoStr:=AutoStr+IntToStr(m);
if d<10 then AutoStr:=AutoStr+'0';
AutoStr:=AutoStr+IntToStr(d);
ADOQuery1.Close;
ADOQuery1.SQL.Text:='SELECT MAX(编号) FROM CUSTOMER WHERE 编号 LIKE '''+AutoStr+'%''';
ADOQuery1.Open;
if ADOQuery1.RecordCount>0 then
d:=StrToInt(Copy(ADOQuery1.Fields[0].Value,Length(ADOQuery1.Fields[0].Value)-2,3)) else d:=0;
Inc(d);
if d<100 then CountStr:='0';
if d<10 then CountStr:='00';
CountStr:=CountStr+IntToStr(d);
DataSet.Edit;
DataSet.Fields[1].Value:=AutoStr+CountStr;
end;