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

📄 rm_pwwgrid.pas

📁 进销存·完整的·有数据库的·非常完整·只得参考
💻 PAS
📖 第 1 页 / 共 2 页
字号:
    while Pos('~', str) <> 0 do
      str[Pos('~', str)] := #13;
    liView.Memo.Text := str;
    liView.x := tmpx;
    liView.dx := _GetColumnWidth(liColumn) + 1;
    if liColumn.GroupName <> '' then
    begin
      liView.y := NextTop + liGridTitleHeight div 2;
      liView.dy := liGridTitleHeight - liGridTitleHeight div 2;
    end
    else
    begin
      liView.dy := liGridTitleHeight;
      liView.y := NextTop;
    end;
    aFormReport.AssignFont(TRMMemoView(liView), liDBGrid.TitleFont);
    TRMMemoView(liView).PLayout := rmtlCenter;
    case liDBGrid.TitleAlignment of
      taLeftJustify: TRMMemoView(liView).PAlignment := rmtaLeftJustify;
      taRightJustify: TRMMemoView(liView).PAlignment := rmtaRightJustify;
      taCenter: TRMMemoView(liView).PAlignment := rmtaCenterJustify;
    end;
    if rmgoUseColor in aFormReport.ReportOptions then
      liView.FillColor := liDBGrid.TitleColor;
    if (rmgoGridLines in aFormReport.ReportOptions) and (dgColLines in liDBGrid.Options) then
      liView.Prop['FrameTyp'] := $F
    else
      liView.Prop['FrameTyp'] := 0;

    liPage.Objects.Add(liView);
    aFormReport.PageHeaderViews.Add(liView);
    tmpx := tmpx + liView.dx;

    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(liColumn) + 1);
          Exit;
        end;
      end;
    end;

    if liControlType = 'BITMAP' then
    begin
      liView := TRMPictureView(RMCreateObject(gtPicture, ''));
      liView.Memo.Text := Format('[%s.%s."%s"]', [DSet.Owner.Name, DSet.Name, liColumn.FieldName]);
      TRMPictureView(liView).PPictureCenter := True;
      TRMPictureView(liView).PPictureRatio := True;
      TRMPictureView(liView).PStretched := True;
      liView.BandAlign := rmbaHeight;
    end
    else if liControlType = 'RICHEDIT' then
    begin
      liView := TRMwwRichView(RMCreateObject(gtAddIn, 'TRMwwRichView'));
      liView.PStretched := rmgoStretch in aFormReport.ReportOptions;
      TRMwwRichView(liView).RichEdit.Text := Format('[%s.%s."%s"]', [DSet.Owner.Name, DSet.Name, liColumn.FieldName]);
    end;

    if liView = nil then
    begin
      liView := TRMMemoView(RMCreateObject(gtMemo, ''));
      liView.PStretched := rmgoStretch in aFormReport.ReportOptions;
      aFormReport.AssignFont(TRMMemoView(liView), liDBGrid.Font);
      liView.Memo.Text := Format('[%s.%s."%s"]', [DSet.Owner.Name, DSet.Name, liColumn.FieldName]);
      TRMMemoView(liView).PLayout := rmtlCenter;
      TRMMemoView(liView).PWordWrap := rmgoWordWrap in aFormReport.ReportOptions;
      case DSet.Fields[aIndex].Alignment of
        taLeftJustify: TRMMemoView(liView).PAlignment := rmtaLeftJustify;
        taRightJustify: TRMMemoView(liView).PAlignment := rmtaRightJustify;
        taCenter: TRMMemoView(liView).PAlignment := rmtaCenterJustify;
      end;
      THackFormReport(aFormReport).SetMemoViewFormat(TRMMemoView(liView), DSet.Fields[aIndex]);
    end;
    if (rmgoGridLines in aFormReport.ReportOptions) and (dgColLines in liDBGrid.Options) then
      liView.Prop['FrameTyp'] := $F
    else
      liView.Prop['FrameTyp'] := 0;

    liView.CreateUniqueName;
    liView.x := tmpx;
    liView.y := 0;
    liView.dx := _GetColumnWidth(liColumn) + 1;
    liView.dy := liDBGrid.DefaultRowHeight + 4;
    if rmgoUseColor in aFormReport.ReportOptions then
      liView.FillColor := liDBGrid.Color;

    liPage.Objects.Add(liView);
    aFormReport.PageDetailViews.Add(liView);
    tmpx := tmpx + liView.dx;
    if Assigned(aFormReport.OnAfterCreateGridObjectEvent) then
      aFormReport.OnAfterCreateGridObjectEvent(Control, 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;
  liDBGrid := THackwwDBGrid(Control);
  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 + Control.Top;
  aFormReport.GridHeight := Control.Height;
  liGridTitleHeight := 0;
  NextTop := Control.Top + THackFormReport(aFormReport).OffsY;
  aFormReport.ReportDataSet.DataSource := liDBGrid.DataSource;
  aFormReport.Report.DataSet := aFormReport.ReportDataSet;

  DSet := liDBGrid.Datasource.Dataset;
  tmpx := 0;
  for i := 0 to liDBGrid.Selected.Count - 1 do
  begin
    tmpx := tmpx + _GetColumnWidth(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 = Control) or (tmpx > StrToInt(THackFormReport(aFormReport).FormWidth[0])) then
    THackFormReport(aFormReport).FormWidth[0] := IntToStr(tmpx + (THackFormReport(aFormReport).OffsX + Control.Left) * 2);

  liLastGroupName := '';
  if dgTitles in liDBGrid.Options then //表头
  begin
    liFlagFirstColumn := True;
    liGridTitleHeight := liDBGrid.RowHeights[0] + 4;
    tmpx := Control.Left + THackFormReport(aFormReport).OffsX;
    if rmgoGridNumber in aFormReport.ReportOptions then
    begin
      liView := RMCreateObject(gtMemo, '');
      liView.CreateUniqueName;
      liView.x := tmpx;
      liView.y := NextTop;
      liView.dx := RMCanvasHeight('a', liDBGrid.Font) * aFormReport.GridNumOptions.Number;
      liView.dy := liGridTitleHeight;
      liView.Memo.Add(aFormReport.GridNumOptions.Text);
      TRMMemoView(liView).PLayout := rmtlCenter;
      TRMMemoView(liView).PAlignment := rmtaCenterJustify;
      if (rmgoGridLines in aFormReport.ReportOptions) and (dgColLines in liDBGrid.Options) then
        liView.Prop['FrameTyp'] := $F
      else
        liView.Prop['FrameTyp'] := 0;
      Page.Objects.Add(liView);
      aFormReport.PageHeaderViews.Add(liView);
      tmpx := tmpx + liView.dx;

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

    liPage := Page; 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(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 := 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 := Page; //表体
  tmpx := Control.Left + THackFormReport(aFormReport).OffsX;
  liFlagFirstColumn := True;
  if rmgoGridNumber in aFormReport.ReportOptions then
  begin
    liView := RMCreateObject(gtMemo, '');
    liView.CreateUniqueName;
    liView.x := tmpx;
    liView.y := 0;
    liView.dx := RMCanvasHeight('a', liDBGrid.Font) * aFormReport.GridNumOptions.Number;
    liView.dy := liDBGrid.DefaultRowHeight + 4;
    liView.Memo.Add('[Line#]');
    TRMMemoView(liView).PLayout := rmtlCenter;
    TRMMemoView(liView).PAlignment := rmtaCenterJustify;
    if (rmgoGridLines in aFormReport.ReportOptions) and (dgColLines in liDBGrid.Options) then
      liView.Prop['FrameTyp'] := $F
    else
      liView.Prop['FrameTyp'] := 0;
    Page.Objects.Add(liView);
    aFormReport.PageDetailViews.Add(liView);
    tmpx := tmpx + liView.dx;

    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(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 := 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 + -