有表SaleProductMX,字段DocumentCode
要自动生成诸如041215A001,041215A002,041215P001,041215P002,0411216A001,041216A002,041216P001,A代表上午。P代表下午,041215代表日期如何生成啊?
function TfrmSaleProduct.ConvertDateToStr(Value: TDateTime): String;
var
  Y,M,D :Word;
  StrY,StrM,StrD:string;
begin
  Decodedate(value,Y,M,D);
  StrY:=copy(IntToStr(Y),3,2);
  if M<10 then
    StrM:='0'+IntToStr(M)
  else
    STrM:=IntToStr(M);
  if D<10 then
    StrD:='0'+IntToStr(D)
  else
    StrD:=IntToStr(D);
  Result:=StrY+StrM+StrD;
end;function TfrmSaleProduct.GetDocumentCode: string;
var
  s:String[3];
  I:integer;
begin
  With quTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select isnull(max(SubString(DocumentCode,len(DocumentCode)-2,3)),'''')from SaleProductMX ' );
    open;
     if Length(Trim(Fields[0].AsString))>0 then
    begin
      S:=IntToStr(StrToInt(Fields[0].AsString)+1);
      for i:= Length(S) to 2 do
        S:='0'+ S;
      Result :=ConvertDateToStr(now)+'A'+S;
    end
    else
      Result := ConvertDateToStr(now)+'A'+'001';
  end;
end;