delphi前台流水号如何实现,有表A,要求是日期+编号,请问如何实现?

解决方案 »

  1.   

    procedure TForm1.cleardatabianhao(Sender: TObject);  //自定义过程,清楚数据,重写编号
    var s1,s2,s3:string;  //收费编号 (编号由日期和代号组成) ,s2系统当前日期,s3数据库最后一条记录的日期编号,s1为最后一个收费编号
        m1:integer;
        q2:TADOQuery;
        wu1,wu2:TDateTime;  //时间型,判断结帐
        t1:string;
        laststr:string;  //判断数据库最后一条数据是否为第二天的数据
        d:TDate;
    begin  //初始化数据
      s2:=formatdatetime('yyyymmdd',date());  form1.adoquery1.SQL.Clear;
      form1.adoquery1.SQL.Add('select number from 收费表 order by number');
      form1.adoquery1.Open;
      form1.adoquery1.Last;
      s1:=form1.adoquery1.fieldbyname('number').AsString;  //最后一个收费编号
      s3:=copy(s1,1,8);
      laststr:=s3+'001';
    //测试,如果是系统截帐日期过后,则自动生成第二天的数据
       wu1:=time(); //返回系统当前时间
       q2:=TADOQuery.Create(nil);
       q2.Connection:=form1.adoconnection1;
       q2.SQL.Clear;
       q2.SQL.Add('select ttime from ttime');
       q2.Open;
       t1:=q2.fieldbyname('ttime').asstring;
       wu2:=strtotime(t1);
       if wu1<wu2 then  //结帐之前,则当天的编号不变
        begin
         if s2=s3 then      //当天的编号数字部分加1
          begin
           s1:=copy(s1,9,3);
           m1:=strtoint(s1);
           m1:=m1+1;
           s1:=inttostr(m1);
           m1:=length(s1);
           if m1=1 then s1:='0'+'0'+s1;
           if m1=2 then s1:='0'+s1;
           form1.edit2.Text:=s2+s1;
         end
        else if s2<>s3 then    //不是当天的,则编号从001开台累计
         begin
           s1:='001';
           form1.edit2.Text:=s2+s1;
         end;
      end;  if (wu1>wu2) or (wu1=wu2) then
       begin
         d:=date()+1;
         s2:=formatdatetime('yyyymmdd',d);
        // s2:=datetostr(d);
         if s2=s3 then      //当天的编号数字部分加1
          begin
           s1:=copy(s1,9,3);
           m1:=strtoint(s1);
           m1:=m1+1;
           s1:=inttostr(m1);
           m1:=length(s1);
           if m1=1 then s1:='0'+'0'+s1;
           if m1=2 then s1:='0'+s1;
           form1.edit2.Text:=s2+s1;
         end
        else if s2<>s3 then    //不是当天的,则编号从001开台累计
         begin
           s1:='001';
           form1.edit2.Text:=s2+s1;
         end;
         
       end;
      

  2.   

    说句心里话,楼主不要不爱听,
    就象这种问题,只要稍微有delphi和sql的能力,思路清晰就可以搞定,
    思路很清晰的,为什么不自己去尝试实现呢?
    原谅我的直接!
      

  3.   


    procedure TForm2.khdmcode;
    var
      temp:Tadoquery;
    begin
        temp:=TADOQuery.Create(nil);
        tempkh:='';
        with temp do begin
          Connection:=dm.ADOConnection1;
          Close;
          SQL.Clear;
          sql.Add('select * from khxxtb where left(khdm,12)=:tempvar order by khdm desc');
          temp.Parameters.ParamByName('tempvar').Value:='KHDM'+FormatDateTime('yyyymmdd',Form1.gettime);
          Open;
          First;
          if temp.Fields.Fields[0].IsNull then tempkh:='KHDM'+FormatDateTime('yyyymmdd',Form1.gettime)+FormatFloat('000',1)
          else tempkh:='KHDM'+FormatDateTime('yyyymmdd',Form1.gettime)+FormatFloat('000',(StrToInt(copy(temp.Fields.Fields[0].value,13,3))+1));
        end;//end with
        showmessage(tempkh);
    end;////KHDM20051013001