自动编号

来源:互联网 发布:软件设计师考试教材 编辑:程序博客网 时间:2024/05/17 00:08

------------------------------------------------------------三位编号

var

  s,m:string;

  i:integer;

begin

  with query1 do

    begin

      close;

      sql.Clear;

      sql.Add('select max(记录编号) as ss from CZYB');

      open;

    end;

   if query1.ParamByName('ss').Value=null then

     s:=s+'001'

   else

     begin

       m:=trim(query1.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;

     label5.Caption:=s;

 

 

----------------------------------------------------------------四位编号

var

  s,m:string;

  i:integer;

begin

  with query1 do

    begin

      close;

      sql.Clear;

      sql.Add('select max(记录编号) as ss from CZYB');

      open;

    end;

   if query1.ParamByName('ss').Value=null then

     s:=s+'0001'

   else

     begin

       m:=trim(query1.fieldbyname('ss').Value);

       i:=strtoint(trim(copy(m,11,5)));

     if i<9 then

        s:=s +'000'+inttostr(i+1)

     else if i<99 then

       s:=s +'00'+inttostr(i+1)

         else if i<999 then

           s:=s+'0'+inttostr(i+1)

           else

             s:=s +inttostr(i+1);

     end;

     label5.Caption:=s;

 

-----------------------------------------------------------------------六位编号

var

  s,m:string;

  i:integer;

begin

  with query1 do

    begin

      close;

      sql.Clear;

      sql.Add('select max(记录编号) as ss from CZYB');

      open;

    end;

   if query1.ParamByName('ss').Value=null then

     s:=s+'000001'

   else

     begin

       m:=trim(query1.fieldbyname('ss').Value);

       i:=strtoint(trim(copy(m,11,5)));

     if i<9 then

        s:=s +'00000'+inttostr(i+1)

     else if i<99 then

       s:=s +'0000'+inttostr(i+1)

         else if i<999 then

           s:=s+'000'+inttostr(i+1)

           else if i<9999 then

            s:=s+'00'+inttostr(i+1)

             else if i<99999 then

               s:=s+'0'+inttostr(i+1)

                else

                 s:=s +inttostr(i+1);

     end;

     label5.Caption:=s;

 

---------------------------------------------------------------加编码和日期的三位编号

var

  s,m:string;

  i:integer;

begin

  s:= 'TK'+ FormatDateTime('yyyymmdd',Now());      //编码"TK",日期当天

  with adotj do

    begin

      close;

      sql.Clear;

      sql.Add('select max(申请单号) as ss from TKDJ');

      open;

    end;

   if adotj.FieldByName('ss').Value=null then

     s:=s+'001'

   else

     begin

       m:=trim(adotj.fieldbyname('ss').Value);

       i:=strtoint(trim(copy(m,9,3)));

     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;

      label15.Caption:=s;

原创粉丝点击