rm_f1book6.pas

来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 564 行 · 第 1/2 页

PAS
564
字号
    THackFormReport(aFormReport).FormWidth[0] := IntToStr(Leftx + (THackFormReport(aFormReport).OffsX + Control.Left) * 2);

  Leftx := Control.Left + THackFormReport(aFormReport).OffsX;
  NextLeft := 0;
  if liGrid.FixedRows > 0 then //表头
  begin
    for i := 1 to liGrid.FixedRows do
    begin
      liGridTitleHeight := liGridTitleHeight + Round(RMConvertToPixels1(liGrid.RowHeight[i] / 1440 * FGrid.ViewScale / 100)) + 4;
      NextLeft := Leftx;
      liPageNo := 0; liNum := 0;
      liPage := TRMReportPage(aFormReport.Report.Pages[0]);
      for j := 1 to liGrid.LastCol do
      begin
        if (aFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not aFormReport.ScaleMode.FitPageWidth) then
        begin
          if (liNum > 0) and (THackFormReport(aFormReport).CalcWidth(NextLeft + (Round(RMConvertToPixels1(liGrid.ColWidthTwips[j] / 1440 * FGrid.ViewScale / 100)) + 1)) > THackFormReport(aFormReport).PageWidth) then // 超宽
          begin
            liNum := 0;
            THackFormReport(aFormReport).FormWidth[liPageNo] := IntToStr(NextLeft);
            Inc(liPageNo);
            if liPageNo >= aFormReport.Report.Pages.Count then
            begin
              THackFormReport(aFormReport).AddPage;
              THackFormReport(aFormReport).FormWidth.Add('0');
            end;
            liPage := TRMReportPage(aFormReport.Report.Pages[liPageNo]);
            NextLeft := Leftx;
            DrawFixedHeader(i);
          end;
        end;
        MakeOneHeader(i, j);
        Inc(liNum);
      end;
      NextTop := NextTop + Round(RMConvertToPixels1(liGrid.RowHeight[i] / 1440 * FGrid.ViewScale / 100)) + 4;
    end;
  end;


  if THackFormReport(aFormReport).FormWidth.Count > 1 then
    THackFormReport(aFormReport).FormWidth[THackFormReport(aFormReport).FormWidth.Count - 1] := IntToStr(NextLeft);

  liPage := Page;
  liPageNo := 0; liNum := 0;
  NextLeft := Control.Left + THackFormReport(aFormReport).OffsX;
  for i := 1 to liGrid.LastCol do //表体
  begin

    if (aFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not aFormReport.ScaleMode.FitPageWidth) then
    begin
      if (liNum > 0) and (THackFormReport(aFormReport).CalcWidth(NextLeft + (Round(RMConvertToPixels1(liGrid.ColWidthTwips[i] / 1440 * FGrid.ViewScale / 100)) + 1)) > THackFormReport(aFormReport).PageWidth) then // 超宽
      begin
        liNum := 0;
        {DONE -oArm:超过页宽时越界}
        THackFormReport(aFormReport).FormWidth[liPageNo] := IntToStr(NextLeft);
        Inc(liPageNo);
        if liPageNo >= aFormReport.Report.Pages.Count then
        begin
          THackFormReport(aFormReport).AddPage;
          THackFormReport(aFormReport).FormWidth.Add('0');
        end;
        liPage := TRMReportPage(aFormReport.Report.Pages[liPageNo]);
        NextLeft := Control.Left + THackFormReport(aFormReport).OffsX;
        {DONE -oArm:表前n列问题}
      end;
    end;
    MakeOneDetail(i);
    Inc(liNum);
  end;
  if THackFormReport(aFormReport).FormWidth.Count > 1 then
    THackFormReport(aFormReport).FormWidth[THackFormReport(aFormReport).FormWidth.Count - 1] := IntToStr(NextLeft);
end;

procedure TRMPrintF1book6.OnReportBeginBand(Band: TRMBand);
begin
  if Band.BandType = rmbtMasterData then
    Band.spHeight := Round(RMConvertToPixels1(FGrid.RowHeight[FCurrentRow] / 1440 * FGrid.ViewScale / 100));
end;

procedure TRMPrintF1book6.OnUserDatasetCheckEOF(Sender: TObject;
  var Eof: Boolean);
begin
  Eof := FCurrentRow > (THackbook(FGrid).LastRow);
end;

procedure TRMPrintF1book6.OnUserDatasetFirst(Sender: TObject);
begin
  FCurrentRow := 1 + THackbook(FGrid).FixedRows;
  SetMemos;
end;

procedure TRMPrintF1book6.OnUserDatasetNext(Sender: TObject);
begin
  Inc(FCurrentRow);
  SetMemos;
end;

procedure TRMPrintF1book6.OnUserDatasetPrior(Sender: TObject);
begin
  Dec(FCurrentRow);
  SetMemos;
end;

procedure TRMPrintF1book6.SetMemos;
var
  i, FixCount: Integer;
  liView: TRMMemoView;
  s, S1: string;
  liHeight, Temp: Integer;
  cellformat: F1CellFormat;
  pRow1, pCol1, pRow2, pCol2: integer;
  procedure FindandSetMemo(RowNo, ColNo: integer; MemoName: string);
  var
    j: integer;
  begin
    liHeight := Round(RMConvertToPixels1(FGrid.RowHeight[RowNo] / 1440 * FGrid.ViewScale / 100));
    liView := TRMMemoView(FFormReport.Report.FindObject(MemoName));
    if liView <> nil then
    begin
      S := FGrid.FormattedTextRC[RowNo, ColNo + 1];
      if Abs(FGrid.TypeRC[RowNo, ColNo + 1]) = 1 then //number
      begin
        if FGrid.NumberRC[RowNo, ColNo + 1] = 0 then
          liView.Memo.Text := ''
        else
          liView.Memo.Text := s;
      end
      else
        liView.Memo.Text := s;
      //合并单元格的对齐方式
      if (ColNo div 26) = 0 then
        FGrid.Selection := Chr(65 + ColNo) + inttostr(RowNo)
      else
        FGrid.Selection := Chr(65 + (ColNo div 26)) + Chr(65 + (ColNo mod 26)) + inttostr(FCurrentRow);

      FGrid.GetSelection(0, pRow1, pCol1, pRow2, pCol2);
      if (pRow1 < pRow2) and (pRow1 = RowNo) then
      begin
        Temp := 0;
        for J := pRow1 to pRow2 do
          Temp := Temp + Round(RMConvertToPixels1(FGrid.RowHeight[J] / 1440 * FGrid.ViewScale / 100));
        liView.spHeight := temp;
      end
      else
        liView.spHeight := liHeight;
      if (pCol1 < pCol2) and (pCol1 = ColNo + 1) then
      begin
        Temp := 0;
        for J := pCol1 to pCol2 do
          Temp := Temp + Round(RMConvertToPixels1(FGrid.ColWidthtwips[J] / 1440 * FGrid.ViewScale / 100)) + 1;
        liView.spWidth := Temp;
      end
      else
        liView.spWidth := Round(RMConvertToPixels1(FGrid.ColWidthtwips[ColNo + 1] / 1440 * FGrid.ViewScale / 100)) + 1;

      //对齐方式
      FGrid.SetActiveCell(RowNo, ColNo + 1);
      Cellformat := FGrid.GetCellFormat;
      if CellFormat.AlignHorizontal = F1HAlignCenter then
        LiView.HAlign := rmhCenter;
      if CellFormat.AlignHorizontal = F1HalignRight then
        LiView.HAlign := rmhRight;
      if CellFormat.AlignHorizontal = F1HAlignLeft then
        LiView.HAlign := rmhLeft;
      {//垂直排列}
      if CellFormat.AlignVertical = F1VAlignTop then
        LiView.VAlign := rmvTop;
      if CellFormat.AlignVertical = F1VAlignCenter then
        LiView.VAlign := rmvCenter;
      if CellFormat.AlignVertical = F1VAlignBottom then
        LiView.VAlign := rmvBottom;
      //
      if CellFormat.AlignHorizontal = F1HAlignGeneral then
        if IsNumber(s) then
          LiView.HAlign := rmhRight
        else
          LiView.HAlign := rmhLeft;

     //字体
      LiView.Font.Name := CellFormat.FontName;
      LiView.Font.Size := CellFormat.FontSize;
      LiView.Font.Color := CellFormat.FontColor;
      Liview.Font.Style := [];
      if CellFormat.FontBold then
        Liview.Font.Style := LiView.Font.style + [fsBold];
      if CellFormat.FontItalic then
        Liview.Font.Style := LiView.Font.style + [fsItalic];
      if CellFormat.FontUnderline then
        Liview.Font.Style := LiView.Font.style + [fsUnderline];
      if CellFormat.FontStrikeout then
        Liview.Font.Style := LiView.Font.style + [fsStrikeOut];

 //画表格线
      FGrid.GetSelection(0, pRow1, pCol1, pRow2, pCol2);
      liView.LeftFrame.Visible := False;
      liView.TopFrame.Visible := False;
      liView.RightFrame.Visible := False;
      liView.BottomFrame.Visible := False;
      if RowNo = PRow1 then
        if cellformat.BorderStyle[F1TopBorder] > 0 then
          liView.TopFrame.Visible := True;
      if ColNo + 1 = PCol1 then
        if cellformat.BorderStyle[F1LeftBorder] > 0 then
          liView.LeftFrame.Visible := True;
      if RowNo = PRow2 then
        if cellformat.BorderStyle[F1BottomBorder] > 0 then
          liView.BottomFrame.Visible := True;
      if ColNo + 1 = PCol2 then
        if cellformat.BorderStyle[F1RightBorder] > 0 then
          liView.RightFrame.Visible := True;
    end;
  end;
begin
  FixCount := 0;
  for i := 0 to FList.Count - 1 do
  begin
    //处理固定列
    S1 := Copy(FList[i], Pos('$', Flist[i]), Length(Flist[i]) - Pos('$', Flist[i]) + 1);
    if S1[1] = '$' then
    begin
      Inc(FixCount);
      FindandSetMemo(FCurrentRow, StrToInt(Copy(S1, 2, Length(S1) - 1)) - 1, Copy(FList[i], 1, Length(Flist[i]) - 2));
    end
    else
    begin
      if FixCount <= FFormReport.GridFixedCols then
        FindandSetMemo(FCurrentRow, I, FList[i])
      else
        FindandSetMemo(FCurrentRow, I - FixCount + FFormReport.GridFixedCols, FList[i]);
    end;
  end;
end;

function IsNumber(S: string): boolean;
const
  Number = ['0'..'9', '.'];
var
  I, j: integer;
begin
  Result := True;
  if s = '' then
    Result := False;
  if Pos('-', s) = 1 then
  begin
    Result := True;
    system.Delete(s, 1, 1);
  end;
  j := 0;
  for i := 1 to Length(S) do
  begin
    if not (S[i] in Number) then
    begin
      Result := False;
      break;
    end
    else
    begin
      if S[i] = '.' then
        j := j + 1;
      if j > 1 then
      begin
        Result := False;
        break;
      end;
    end;
  end;
end;

function RMConvertToPixels1(Avalue: extended): extended;
begin
  Result := Avalue * RMPixPerInchX;
end;

procedure Register;
begin
  RegisterComponents('Report Machine', [TRMPrintF1Book]);
end;
initialization
  RMRegisterFormReportControl(TF1book6, TRMPrintF1book6);
end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?