⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rm_pehgrid.pas

📁 report machine 2.3 功能强大
💻 PAS
📖 第 1 页 / 共 2 页
字号:
        THackFormReport(FFormReport).FormWidth[FFormReport.Report.Pages.Count - 1] := IntToStr(liNextX);
        THackFormReport(FFormReport).AddPage;
        THackFormReport(FFormReport).FormWidth.Add('0');
        liPage := FFormReport.Report.Pages[FFormReport.Report.Pages.Count - 1];
        liNextX := tmpx0;
        liFlagFirstColumn := True;
        DrawFixedColHeader;
      end;
    end;

    MakeOneHeader(i);
    Inc(liNum);
  end;

  liFlagFirstColumn := True;
  if FPrintDoubleFrame then
    t.RightFrame.Width := 2;

  if FFormReport.Report.Pages.Count > 1 then
    THackFormReport(FFormReport).FormWidth[THackFormReport(FFormReport).FormWidth.Count - 1] := IntToStr(liNextX);
end;

procedure TRMPrintEHGrid.OnBeforePrintBandEvent(Band: TRMBand; var PrintBand: Boolean);
begin
  if not THackGrid(FDBGridEh).SelectedRows.CurrentRowSelected then
    PrintBand := FALSE;
end;

procedure TRMPrintEHGrid.OnGenerate_Object(aFormReport: TRMFormReport;
  Page: TRMPage; Control: TControl; var t: TRMView);
var
  liView: TRMView;
  i, j, liLeftx: Integer;
  liNextX, liNextY: Integer;
  liDataSet: TDataSet;
  liFooter: TColumnFooterEh;
  liNum, liPageNo, tmpx0: Integer;
  liPage: TRMPage;
  liFlagFirstColumn: Boolean;

  procedure DrawDoubleFrameBottom(aView: TRMView; aList: TList);
  var
    t: TRMMemoView;
  begin
    if FPrintDoubleFrame then
    begin
      t := TRMMemoView(RMCreateObject(gtMemo, ''));
      t.CreateUniqueName;
      t.LeftFrame.Visible := False;
      t.TopFrame.Visible := True;
      t.RightFrame.Visible := False;
      t.BottomFrame.Visible := False;
      t.TopFrame.Width := 2;
      t.Gapx := 0; t.GapY := 0;
      t.SetBounds(aView.x, aFormReport.GridTop + aFormReport.GridHeight, aView.dx, 2);
      t.PStretched := rmgoStretch in aFormReport.ReportOptions;
      liPage.Objects.Add(t);
      aList.Add(t);
    end;
  end;

  procedure MakeOneDetail(aIndex: Integer);
  begin
    if THackGrid(FDBGridEh).Columns[aIndex].Checkboxes then
    begin
      liView := RMCreateObject(gtAddIn, 'TRMCheckBoxView');
      TRMCheckBoxView(liView).CheckStyle := csCheck;
    end
    else
    begin
      liView := RMCreateObject(gtMemo, '');
      liView.PStretched := rmgoStretch in FFormReport.ReportOptions;
      TRMMemoView(liView).PWordWrap := rmgoWordWrap in aFormReport.ReportOptions;
      TRMMemoView(liView).PLayout := rmtlCenter;
      aFormReport.AssignFont(TRMMemoView(liView), THackGrid(FDBGridEh).Columns[aIndex].Font);
      case THackGrid(FDBGridEh).Columns[aIndex].Alignment of
        taLeftJustify: TRMMemoView(liView).PAlignment := rmtaLeftJustify;
        taRightJustify: TRMMemoView(liView).PAlignment := rmtaRightJustify;
        taCenter: TRMMemoView(liView).PAlignment := rmtaCenterJustify;
      end;
      THackFormReport(aFormReport).SetMemoViewFormat(TRMMemoView(liView), liDataSet.FieldByName(THackGrid(FDBGridEh).Columns[aIndex].FieldName));
    end;
    liView.CreateUniqueName;
    liView.x := liNextX;
    liView.y := 0;
    liView.dx := THackGrid(FDBGridEh).Columns[aIndex].Width + 1;
    liView.dy := THackGrid(FDBGridEh).DefaultRowHeight + 4;
    if (rmgoGridLines in aFormReport.ReportOptions) and (dgColLines in THackGrid(FDBGridEh).Options) then
      liView.Prop['FrameTyp'] := $F
    else
      liView.Prop['FrameTyp'] := 0;
    if THackGrid(FDBGridEh).Columns[aIndex].FieldName <> '' then
      liView.Memo.Text := Format('[%s.%s."%s"]', [liDataSet.Owner.Name, liDataSet.Name, THackGrid(FDBGridEh).Columns[aIndex].FieldName]);
    liPage.Objects.Add(liView);
    aFormReport.PageDetailViews.Add(liView);
    liNextX := liNextX + THackGrid(FDBGridEh).Columns[aIndex].Width + 1;
    if Assigned(aFormReport.OnAfterCreateGridObjectEvent) then
      aFormReport.OnAfterCreateGridObjectEvent(Control, THackGrid(FDBGridEh).Columns[aIndex].FieldName, liView);

    if FPrintDoubleFrame then
    begin
      if liFlagFirstColumn then
        liView.LeftFrame.Width := 2;
    end;
    DrawDoubleFrameBottom(liView, aFormReport.ColumnFooterViews);
    liFlagFirstColumn := False;
  end;

  procedure MakeOneFooter(aRow, aIndex: Integer);
  begin
    liFooter := nil;
    if THackGrid(FDBGridEh).Columns[aIndex].Footers.Count > aRow then
      liFooter := THackGrid(FDBGridEh).Columns[aIndex].Footers[aRow]
    else if THackGrid(FDBGridEh).Columns[aIndex].Footers.Count = aRow then
      liFooter := THackGrid(FDBGridEh).Columns[aIndex].Footer;
    if liFooter <> nil then
    begin
      case liFooter.ValueType of
        fvtSum:
          begin
            liView := RMCreateObject(gtCalcMemo, '');
            TRMCalcMemoView(liView).ResetAfterPrint := True;
            TRMCalcMemoView(liView).CalcType := rmdcSum;
            if liFooter.FieldName <> '' then
            begin
              liView.Memo.Text := Format('[%s.%s."%s"]', [liDataSet.Owner.Name, liDataSet.Name, liFooter.FieldName]);
              THackFormReport(aFormReport).SetMemoViewFormat(TRMMemoView(liView), liDataSet.FieldByName(liFooter.FieldName));
            end;
          end;
        fvtCount:
          begin
            liView := RMCreateObject(gtCalcMemo, '');
            TRMCalcMemoView(liView).ResetAfterPrint := True;
            TRMCalcMemoView(liView).CalcType := rmdcCount;
          end;
      else
        liView := RMCreateObject(gtMemo, '');
        liView.Memo.Text := liFooter.Value;
      end;
    end
    else
      liView := RMCreateObject(gtMemo, '');

    liView.CreateUniqueName;
    liView.x := liNextX;
    liView.y := liNexty;
    liView.dx := THackGrid(FDBGridEh).Columns[aIndex].Width + 1;
    liView.dy := THackGrid(FDBGridEh).DefaultRowHeight + 4;
    TRMMemoView(liView).PLayout := rmtlCenter;
    if liFooter <> nil then
    begin
      aFormReport.AssignFont(TRMMemoView(liView), liFooter.Font);
      case liFooter.Alignment of
        taLeftJustify: TRMMemoView(liView).PAlignment := rmtaLeftJustify;
        taRightJustify: TRMMemoView(liView).PAlignment := rmtaRightJustify;
        taCenter: TRMMemoView(liView).PAlignment := rmtaCenterJustify;
      end;
    end
    else
    begin
      aFormReport.AssignFont(TRMMemoView(liView), THackGrid(FDBGridEh).Columns[aIndex].Font);
      case THackGrid(FDBGridEh).Columns[aIndex].Alignment of
        taLeftJustify: TRMMemoView(liView).PAlignment := rmtaLeftJustify;
        taRightJustify: TRMMemoView(liView).PAlignment := rmtaRightJustify;
        taCenter: TRMMemoView(liView).PAlignment := rmtaCenterJustify;
      end;
    end;

    if (rmgoGridLines in aFormReport.ReportOptions) and (dgColLines in THackGrid(FDBGridEh).Options) then
      liView.Prop['FrameTyp'] := $F
    else
      liView.Prop['FrameTyp'] := 0;
    liPage.Objects.Add(liView);
    aFormReport.GroupFooterViews.Add(liView);
    liNextX := liNextX + THackGrid(FDBGridEh).Columns[aIndex].Width + 1;
  end;

  procedure DrawFixedColDetail;
  var
    i: Integer;
  begin
    for i := 0 to FFormReport.GridFixedCols - 1 do
    begin
      if not THackGrid(FDBGridEh).Columns[i].Visible then Continue;
      if i < THackGrid(FDBGridEh).Columns.Count then MakeOneDetail(i);
    end;
  end;

  procedure DrawFixedColFooter(aRow: Integer);
  var
    j: Integer;
  begin
    for j := 0 to FFormReport.GridFixedCols - 1 do
    begin
      if not THackGrid(FDBGridEh).Columns[j].Visible then Continue;

      if j < THackGrid(FDBGridEh).Columns.Count then
        MakeOneFooter(aRow, j);
    end;
  end;

begin
  FFormReport := aFormReport;
  FDBGridEh := TCustomDBGridEh(Control);
  if not Assigned(FDBGridEh) or not Assigned(THackGrid(FDBGridEh).DataSource) or
    not Assigned(THackGrid(FDBGridEh).DataSource.DataSet) then Exit;
//    or not FDBGridEh.DataSource.DataSet.Active then Exit;

  liDataSet := THackGrid(FDBGridEh).DataSource.DataSet;
  if (rmgoSelectedRecordsOnly in aFormReport.ReportOptions) and
    (THackGrid(FDBGridEh).SelectedRows.Count > 0) then //只打印选择的记录
  begin
    AutoFree := False;
    aFormReport.Report.OnBeforePrintBand := OnBeforePrintBandEvent;
  end;

  FPage := aFormReport.Report.Pages[0];
  aFormReport.DrawOnPageFooter := TRUE;
  aFormReport.GridTop := THackFormReport(aFormReport).OffsY + Control.Top;
  aFormReport.GridHeight := Control.Height;
//  liNextY := Control.Top + THackFormReport(aFormReport).OffsY;
  aFormReport.ReportDataSet.DataSource := THackGrid(FDBGridEh).DataSource;
  FPrintDoubleFrame := (rmgoDoubleFrame in aFormReport.ReportOptions) and
    (THackGrid(FDBGridEh).FooterRowCount = 0);

  liLeftx := 0;
  for i := 0 to THackGrid(FDBGridEh).Columns.Count - 1 do
  begin
    if THackGrid(FDBGridEh).Columns[i].Visible then
      liLeftx := liLeftX + THackGrid(FDBGridEh).Columns[i].Width + 1;
  end;

  if (aFormReport.PrintControl = Control) or (liLeftx > StrToInt(THackFormReport(aFormReport).FormWidth[0])) then
    THackFormReport(aFormReport).FormWidth[0] := IntToStr(liLeftx + (THackFormReport(aFormReport).OffsX + Control.Left) * 2);

//表头
  liNextX := Control.Left + THackFormReport(aFormReport).OffsX;
  if dgTitles in THackGrid(FDBGridEh).Options then
  begin
    if FDBGridEh.UseMultiTitle then
      PrintMultiTitle
    else
      PrintSimpleTitle;
  end;

// 表体
  liNum := 0; liPageNo := 0;
  liPage := Page; tmpx0 := lINextX;
  liFlagFirstColumn := True;
  for i := 0 to THackGrid(FDBGridEh).Columns.Count - 1 do
  begin
    if not THackGrid(FDBGridEh).Columns[i].Visible then Continue;

    if (FFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not FFormReport.ScaleMode.FitPageWidth) then
    begin
      if (liNum > 0) and (THackFormReport(FFormReport).CalcWidth(liNextX + (THackGrid(FDBGridEh).Columns[i].Width + 1)) > THackFormReport(FFormReport).PageWidth) then // 超宽
      begin
        liNum := 0;
        liFlagFirstColumn := True;
        if FPrintDoubleFrame then
          liView.RightFrame.Width := 2;

        THackFormReport(FFormReport).FormWidth[liPageNo] := IntToStr(liNextX);
        Inc(liPageNo);
        if liPageNo >= FFormReport.Report.Pages.Count then
        begin
          THackFormReport(FFormReport).AddPage;
          THackFormReport(FFormReport).FormWidth.Add('0');
        end;
        liPage := FFormReport.Report.Pages[liPageNo];
        liNextX := tmpx0;
        liFlagFirstColumn := True;
        DrawFixedColDetail;
      end;
    end;

    MakeOneDetail(i);
    Inc(liNum);
  end;

  if liNum > 0 then
  begin
    liFlagFirstColumn := True;
    if FPrintDoubleFrame then
      liView.RightFrame.Width := 2;
  end;

  if FFormReport.Report.Pages.Count > 1 then
    THackFormReport(FFormReport).FormWidth[liPageNo] := IntToStr(liNextX);

  // 统计
  if THackGrid(FDBGridEh).FooterRowCount > 0 then // Footer Row
  begin
    liNextY := 0;
    for i := 0 to THackGrid(FDBGridEh).FooterRowCount - 1 do
    begin
      liPage := Page; liNum := 0; liPageNo := 0;
      liNextX := Control.Left + THackFormReport(aFormReport).OffsX;
      for j := 0 to THackGrid(FDBGridEh).Columns.Count - 1 do // 表体
      begin
        if not THackGrid(FDBGridEh).Columns[j].Visible then Continue;

        if (FFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not FFormReport.ScaleMode.FitPageWidth) then
        begin
          if (liNum > 0) and (THackFormReport(FFormReport).CalcWidth(liNextX + (THackGrid(FDBGridEh).Columns[j].Width + 1)) > THackFormReport(FFormReport).PageWidth) then // 超宽
          begin
            liNum := 0;
            Inc(liPageNo);
            liPage := FFormReport.Report.Pages[liPageNo];
            liNextX := tmpx0;
            DrawFixedColFooter(i);
          end;
        end;

        MakeOneFooter(i, j);
        Inc(liNum);
      end; // end for
      liNextY := liNextY + THackGrid(FDBGridEh).DefaultRowHeight + 4;
    end;
  end;
end;

initialization
  RMRegisterFormReportControl(TCustomDBGridEh, TRMPrintEHGrid);
  RMRegisterFormReportControl(TDBGridEh, TRMPrintEHGrid);
{$ENDIF}
end.

⌨️ 快捷键说明

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