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

📄 rm_pwwgrid.pas

📁 这是一个功能强大
💻 PAS
📖 第 1 页 / 共 2 页
字号:
    liView.ParentPage := liPage;
    str := liColumn.DisplayLabel;
    while Pos('~', str) <> 0 do
      str[Pos('~', str)] := #13;
    liView.Memo.Text := str;
    liView.spLeft := tmpx;
    liView.spWidth := _GetColumnWidth(aIndex, liColumn) + 1;
    if liColumn.GroupName <> '' then
    begin
      liView.spTop := NextTop + liGridTitleHeight div 2;
      liView.spHeight := liGridTitleHeight - liGridTitleHeight div 2;
    end
    else
    begin
      liView.spHeight := liGridTitleHeight;
      liView.spTop := NextTop;
    end;
    aFormReport.AssignFont(TRMMemoView(liView), liDBGrid.TitleFont);
    TRMMemoView(liView).VAlign := rmvCenter;
    case liDBGrid.TitleAlignment of
      taLeftJustify: TRMMemoView(liView).HAlign := rmhLeft;
      taRightJustify: TRMMemoView(liView).HAlign := rmhRight;
      taCenter: TRMMemoView(liView).HAlign := rmhCenter;
    end;
    if rmgoUseColor in aFormReport.ReportOptions then
      liView.FillColor := liDBGrid.TitleColor;
    if (rmgoGridLines in aFormReport.ReportOptions) and (dgColLines in liDBGrid.Options) then
    begin
      liView.LeftFrame.Visible := True;
      liView.TopFrame.Visible := True;
      liView.RightFrame.Visible := True;
      liView.BottomFrame.Visible := True;
    end
    else
    begin
      liView.LeftFrame.Visible := False;
      liView.TopFrame.Visible := False;
      liView.RightFrame.Visible := False;
      liView.BottomFrame.Visible := False;
    end;

    aFormReport.ColumnHeaderViews.Add(liView);
    tmpx := tmpx + liView.spWidth;

    if rmgoDoubleFrame in aFormReport.ReportOptions then
    begin
      if liFlagFirstColumn then
        liView.LeftFrame.Width := 2;
      liView.TopFrame.Width := 2;
    end;
    liFlagFirstColumn := False;
    liLastGroupName := liColumn.GroupName;
  end;

  procedure MakeOneDetail(aIndex: Integer);
  var
    liColumn: TwwColumn;
    liControlType, liParameters: string;
    liComponent: TComponent;
  begin
    liColumn := liDBGrid.Columns[aIndex];
    liDBGrid.GetControlInfo(liColumn.FieldName, liControlType, liParameters);
    liControlType := Uppercase(liControlType);
    liView := nil;
    if liControlType = 'CUSTOMEDIT' then
    begin
      liComponent := _GetCustomEditControl(liParameters);
      if liComponent <> nil then
      begin
        if liComponent is TwwCustomRichEdit then
          liControlType := 'RICHEDIT'
        else if AnsiCompareText(liComponent.ClassName, 'TDBImage') = 0 then
          liControlType := 'BITMAP'
        else if AnsiCompareText(liComponent.ClassName, 'TwwDataInspector') = 0 then
        begin
          _MakeDataInspectorObject(TwwDataInspector(liComponent), _GetColumnWidth(aIndex, liColumn) + 1);
          Exit;
        end;
      end;
    end;

    if liControlType = 'BITMAP' then
    begin
      liView := TRMPictureView(RMCreateObject(rmgtPicture, ''));
      liView.ParentPage := liPage;
      liView.Memo.Text := Format('[%s."%s"]', [THackFormReport(aFormReport).AddRMDataSet(DSet).Name, liColumn.FieldName]);
      TRMPictureView(liView).PictureCenter := True;
      TRMPictureView(liView).PictureRatio := True;
      TRMPictureView(liView).PictureStretched := True;
//      TRMPictureView(liView).BandAlign := rmbaHeight;
    end
    else if liControlType = 'RICHEDIT' then
    begin
      liView := TRMwwRichView(RMCreateObject(rmgtAddin, 'TRMwwRichView'));
      liView.ParentPage := liPage;
      TRMwwRichView(liView).Stretched := rmgoStretch in aFormReport.ReportOptions;
      TRMwwRichView(liView).RichEdit.Text := Format('[%s."%s"]', [THackFormReport(aFormReport).AddRMDataSet(DSet).Name, liColumn.FieldName]);
    end;

    if liView = nil then
    begin
      liView := TRMMemoView(RMCreateObject(rmgtMemo, ''));
      liView.ParentPage := liPage;
      TRMMemoView(liView).Stretched := rmgoStretch in aFormReport.ReportOptions;
      aFormReport.AssignFont(TRMMemoView(liView), liDBGrid.Font);
      if aFormReport.GridFontOptions.UseCustomFontSize then
        TRMMemoView(liView).Font.Size := aFormReport.GridFontOptions.Font.Size;
      liView.Memo.Text := Format('[%s."%s"]', [THackFormReport(aFormReport).AddRMDataSet(DSet).Name, liColumn.FieldName]);
      TRMMemoView(liView).VAlign := rmvCenter;
      TRMMemoView(liView).WordWrap := rmgoWordWrap in aFormReport.ReportOptions;
      case DSet.Fields[aIndex].Alignment of
        taLeftJustify: TRMMemoView(liView).HAlign := rmhLeft;
        taRightJustify: TRMMemoView(liView).HAlign := rmhRight;
        taCenter: TRMMemoView(liView).HAlign := rmhCenter;
      end;
      THackFormReport(aFormReport).SetMemoViewFormat(TRMMemoView(liView), DSet.Fields[aIndex]);
    end;
    if (rmgoGridLines in aFormReport.ReportOptions) and (dgColLines in liDBGrid.Options) then
    begin
      liView.LeftFrame.Visible := True;
      liView.TopFrame.Visible := True;
      liView.RightFrame.Visible := True;
      liView.BottomFrame.Visible := True;
    end
    else
    begin
      liView.LeftFrame.Visible := False;
      liView.TopFrame.Visible := False;
      liView.RightFrame.Visible := False;
      liView.BottomFrame.Visible := False;
    end;

    liView.spLeft := tmpx;
    liView.spTop := 0;
    liView.spWidth := _GetColumnWidth(aIndex, liColumn) + 1;
    liView.spHeight := liRowHeight;
    if rmgoUseColor in aFormReport.ReportOptions then
      liView.FillColor := liDBGrid.Color;

    aFormReport.PageDetailViews.Add(liView);
    tmpx := tmpx + liView.spWidth;
    if Assigned(aFormReport.OnAfterCreateGridObjectEvent) then
      aFormReport.OnAfterCreateGridObjectEvent(aControl, DSet.Fields[aIndex].FieldName, liView);

    if rmgoDoubleFrame in aFormReport.ReportOptions then
    begin
      if liFlagFirstColumn then
        liView.LeftFrame.Width := 2;
    end;
    _DrawDoubleFrameBottom(liView, aFormReport.ColumnFooterViews);
    liFlagFirstColumn := False;
  end;

  procedure _DrawFixedColHeader;
  var
    i: Integer;
    SaveGroupName: string;
  begin
    SaveGroupName := liLastGroupName; liLastGroupName := '';
    for i := 0 to aFormReport.GridFixedCols - 1 do
    begin
      if i < liDBGrid.Selected.Count - 1 then
        MakeOneHeader(i);
    end;
    liLastGroupName := SaveGroupName;
  end;

  procedure DrawFixedColDetail;
  var
    i: Integer;
  begin
    for i := 0 to aFormReport.GridFixedCols - 1 do
    begin
      if i < liDBGrid.Selected.Count - 1 then
        MakeOneDetail(i);
    end;
  end;

begin
  if aFormReport.DrawOnPageFooter then Exit;

  FParentReport := aFormReport.Report;
  liDBGrid := THackwwDBGrid(aControl);
  if (liDBGrid.Datasource = nil) or (liDBGrid.Datasource.Dataset = nil) then Exit;
  if not liDBGrid.Datasource.Dataset.Active then Exit;

  FDBGrid := liDBGrid;
  if (rmgoSelectedRecordsOnly in aFormReport.ReportOptions) and
    (liDBGrid.SelectedList.Count > 0) then //只打印选择的记录
  begin
    AutoFree := False;
    aFormReport.Report.OnBeforePrintBand := OnBeforePrintBandEvent;
  end;

  aFormReport.DrawOnPageFooter := TRUE;
  aFormReport.GridTop := THackFormReport(aFormReport).OffsY + aControl.Top;
  aFormReport.GridHeight := aControl.Height;
  liGridTitleHeight := 0;
  NextTop := aControl.Top + THackFormReport(aFormReport).OffsY;
  aFormReport.MainDataSet := THackFormReport(aFormReport).AddRMDataSet(liDBGrid.DataSource.DataSet);
//  aFormReport.ReportDataSet.DataSet := liDBGrid.DataSource.DataSet;

  liRowHeight := liDBGrid.DefaultRowHeight + 4;
  if aFormReport.MasterDataBandOptions.Height > 0 then
    liRowHeight := aFormReport.MasterDataBandOptions.Height;

  DSet := liDBGrid.Datasource.Dataset;
  tmpx := 0;
  for i := 0 to liDBGrid.Selected.Count - 1 do
  begin
    tmpx := tmpx + _GetColumnWidth(i, liDBGrid.Columns[i]) + 1;
  end;

  if (dgTitles in liDBGrid.Options) and (rmgoGridNumber in aFormReport.ReportOptions) then
    tmpx := tmpx + RMCanvasHeight('a', liDBGrid.Font) * aFormReport.GridNumOptions.Number;

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

  liLastGroupName := '';
  if dgTitles in liDBGrid.Options then //表头
  begin
    liFlagFirstColumn := True;
    liGridTitleHeight := liDBGrid.RowHeights[0] + 4;
    tmpx := aControl.Left + THackFormReport(aFormReport).OffsX;
    if rmgoGridNumber in aFormReport.ReportOptions then
    begin
      liView := RMCreateObject(rmgtMemo, '');
      liView.ParentPage := aPage;
      liView.spLeft := tmpx;
      liView.spTop := NextTop;
      liView.spWidth := RMCanvasHeight('a', liDBGrid.Font) * aFormReport.GridNumOptions.Number;
      liView.spHeight := liGridTitleHeight;
      liView.Memo.Add(aFormReport.GridNumOptions.Text);
      TRMMemoView(liView).VAlign := rmvCenter;
      TRMMemoView(liView).HAlign := rmhCenter;
      if (rmgoGridLines in aFormReport.ReportOptions) and (dgColLines in liDBGrid.Options) then
      begin
        liView.LeftFrame.Visible := True;
        liView.TopFrame.Visible := True;
        liView.RightFrame.Visible := True;
        liView.BottomFrame.Visible := True;
      end
      else
      begin
        liView.LeftFrame.Visible := False;
        liView.TopFrame.Visible := False;
        liView.RightFrame.Visible := False;
        liView.BottomFrame.Visible := False;
      end;

      aFormReport.ColumnHeaderViews.Add(liView);
      tmpx := tmpx + liView.spWidth;

      if rmgoDoubleFrame in aFormReport.ReportOptions then
      begin
        if liFlagFirstColumn then
          liView.LeftFrame.Width := 2;
        liView.TopFrame.Width := 2;
      end;
      liFlagFirstColumn := False;
    end;

    liPage := aPage; liNum := 0;
    tmpx0 := tmpx;
    for i := 0 to liDBGrid.GetColCount - 2 do
    begin
      if (aFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not aFormReport.ScaleMode.FitPageWidth) then
      begin
        if (liNum > 0) and (THackFormReport(aFormReport).CalcWidth(tmpx + (_GetColumnWidth(i, liDBGrid.Columns[i]) + 1)) > THackFormReport(aFormReport).PageWidth) then // 超宽
        begin
          liLastGroupName := '';
          liNum := 0;
          liFlagFirstColumn := True;
          if rmgoDoubleFrame in aFormReport.ReportOptions then
            liView.RightFrame.Width := 2;

          THackFormReport(aFormReport).FormWidth[THackFormReport(aFormReport).FormWidth.Count - 1] := IntToStr(tmpx);
          THackFormReport(aFormReport).AddPage;
          THackFormReport(aFormReport).FormWidth.Add('0');
          liPage := TRMReportPage(aFormReport.Report.Pages[aFormReport.Report.Pages.Count - 1]);
          tmpx := tmpx0;
          liFlagFirstColumn := True;
          _DrawFixedColHeader;
        end;
      end;

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

    liFlagFirstColumn := True;
    if rmgoDoubleFrame in aFormReport.ReportOptions then
      liView.RightFrame.Width := 2;
  end;

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

  liLastGroupName := '';
  liPage := aPage; //表体
  tmpx := aControl.Left + THackFormReport(aFormReport).OffsX;
  liFlagFirstColumn := True;
  if rmgoGridNumber in aFormReport.ReportOptions then
  begin
    liView := RMCreateObject(rmgtMemo, '');
    liView.ParentPage := aPage;
    liView.spLeft := tmpx;
    liView.spTop := 0;
    liView.spWidth := RMCanvasHeight('a', liDBGrid.Font) * aFormReport.GridNumOptions.Number;
    liView.spHeight := liRowHeight;
    liView.Memo.Add('[_RM_Line]');
    TRMMemoView(liView).VAlign := rmvCenter;
    TRMMemoView(liView).HAlign := rmhCenter;
    TRMMemoView(liView).Stretched := rmgoStretch in aFormReport.ReportOptions;
    if (rmgoGridLines in aFormReport.ReportOptions) and (dgColLines in liDBGrid.Options) then
    begin
      liView.LeftFrame.Visible := True;
      liView.TopFrame.Visible := True;
      liView.RightFrame.Visible := True;
      liView.BottomFrame.Visible := True;
    end
    else
    begin
      liView.LeftFrame.Visible := False;
      liView.TopFrame.Visible := False;
      liView.RightFrame.Visible := False;
      liView.BottomFrame.Visible := False;
    end;

    aFormReport.PageDetailViews.Add(liView);
    tmpx := tmpx + liView.spWidth;

    if rmgoDoubleFrame in aFormReport.ReportOptions then
    begin
      if liFlagFirstColumn then
        liView.LeftFrame.Width := 2;
    end;
    _DrawDoubleFrameBottom(liView, aFormReport.ColumnFooterViews);
    liFlagFirstColumn := False;
  end;

  tmpx0 := tmpx;
  liNum := 0; liPageNo := 0;
  for i := 0 to liDBGrid.GetColCount - 2 do
  begin
    if (aFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not aFormReport.ScaleMode.FitPageWidth) then
    begin
      if (liNum > 0) and (THackFormReport(aFormReport).CalcWidth(tmpx + (_GetColumnWidth(i, liDBGrid.Columns[i]) + 1)) > THackFormReport(aFormReport).PageWidth) then // 超宽
      begin
        liNum := 0;
        liFlagFirstColumn := True;
        if rmgoDoubleFrame in aFormReport.ReportOptions then
          liView.RightFrame.Width := 2;

        liFlagFirstColumn := True;
        THackFormReport(aFormReport).FormWidth[liPageNo] := IntToStr(tmpx);
        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]);
        tmpx := tmpx0;
        liFlagFirstColumn := True;
        DrawFixedColDetail;
      end;
    end;

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

  if liNum > 0 then
  begin
    liFlagFirstColumn := True;
    if rmgoDoubleFrame in aFormReport.ReportOptions then
      liView.RightFrame.Width := 2;
  end;

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

initialization
  RMRegisterFormReportControl(TwwCustomRichEdit, TRMPrintwwRichEdit);
  RMRegisterFormReportControl(TwwCustomDBGrid, TRMPrintwwDBGrid);
  RMRegisterFormReportControl(TwwDBCustomEdit, TRMPrintwwSpinEdit);
  RMRegisterFormReportControl(TwwDBCustomCheckBox, TRMPrintwwDBCheckBox);

{$ENDIF}
end.

⌨️ 快捷键说明

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