在 OnDrawColumnCell 事件内,直接代码画流水号~

解决方案 »

  1.   

    通过一个函数就可以实现,再与DBGRID结合,效果会更加明显。
      

  2.   


    function CreateID(tablename:string):string;
    var
      strPer:string;
      strSql:string;
      len:integer;
      qryTmp:TADOQuery;
      intPerLength:integer;
      strID:string;
    begin
      strPer:=Comm2.strMachineNo;
      qryTmp:=TADOQuery.create(nil );
      qryTmp.connection:=dmDataModule.Conn;
      qryTmp.SQL.Clear ;
      len:=length(strPer)+1;
      intPerLength:=length(strper);
      strSql:='select max(substring(ID,'+inttostr(len)+',6)) as ID  from '+tablename + ' where left(ID,' + inttostr(intPerLength) + ')=''' + strper + '''';
      qryTmp.SQL.Text:=strSql;
      qryTmp.Open;
      if qryTmp.Fields[0].AsString='' then
      begin
        strID:=strPer + '000001';
      end
      else
      begin
        strID:=strPer + Format('%.6d',[StrToInt(qryTmp.Fields[0].asstring)+1]);
      end;
      CreateID:=strID;
      qryTmp.Close;
      qryTmp.Free;
    end;