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

📄 rm_pdbgrid.pas

📁 进销存·完整的·有数据库的·非常完整·只得参考
💻 PAS
📖 第 1 页 / 共 2 页
字号:
      begin
        liNum := 0;
        liFlagFirstColumn := True;
        if rmgoDoubleFrame in aFormReport.ReportOptions then
          liView.RightFrame.Width := 2;

        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 THackFormReport(aFormReport).FormWidth.Count > 1 then
    THackFormReport(aFormReport).FormWidth[THackFormReport(aFormReport).FormWidth.Count - 1] := IntToStr(tmpx);

//  tmpx := tmpx0; liPage := Page; liNum := 0;
//  for i := 0 to liDBGrid.Columns.Count - 1 do // 页合计
//  begin
//{$IFDEF Delphi4}
//    if not liDBGrid.Columns[i].Visible then
//      Continue;
//{$ENDIF}
{    if (aFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not aFormReport.ScaleMode.FitPageWidth) then
    begin
      if (liNum > 0) and (THackFormReport(aFormReport).CalcWidth(tmpx + (liDBGrid.Columns[i].Width + 1)) > THackFormReport(aFormReport).PageWidth) then // 超宽
      begin
        liNum := 0;
        liFlagFirstColumn := True;
        if rmgoDoubleFrame in aFormReport.ReportOptions then
          liView.RightFrame.Width := 2;

        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;

    MakeOnePageFooter(i);
    Inc(liNum);
  end;
}end;


{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMFormPrintStringGrid}
type
  THackGrid = class(TCustomGrid)
  end;

constructor TRMFormPrintStringGrid.Create;
begin
  inherited Create;
  AutoFree := False;
end;

destructor TRMFormPrintStringGrid.Destroy;
begin
  if FUserDataset <> nil then
  begin
    FUserDataset.Free;
    FUserDataset := nil;
  end;
  if FList <> nil then
  begin
    FList.Free;
    FList := nil;
  end;
  inherited Destroy;
end;

procedure TRMFormPrintStringGrid.SetMemos;
var
  i: Integer;
  liView: TRMMemoView;
  s: string;
  liHeight: Integer;

  procedure AssignFont(aFont: TFont);
  var
    liSaveColor: TColor;
  begin
    liSaveColor := liView.Font.Color;
    liView.Font.Assign(aFont);
    if not (rmgoUseColor in FFormReport.ReportOptions) then
      liView.Font.Color := liSaveColor;
  end;

begin
  liHeight := THackGrid(FGrid).RowHeights[FCurrentRow];
//	RMReport.Pages[0].FindObject(FDetailBandName).dy := liHeight;
  for i := 0 to FList.Count - 1 do
  begin
    liView := TRMMemoView(FFormReport.Report.FindObject(FList[i]));
    if liView <> nil then
    begin
      liView.dy := liHeight;
      s := THackGrid(FGrid).GetEditText(i, FCurrentRow);
      if s = '[Error]' then
        s := '';
      liView.Memo.Text := s;
    end;

    if FCurrentRow < 0 then //Fixed Row
    begin
    end
    else
    begin
    end;
  end;
end;

procedure TRMFormPrintStringGrid.OnUserDatasetCheckEOF(Sender: TObject; var Eof: Boolean);
begin
  Eof := FCurrentRow > (THackGrid(FGrid).RowCount - 1);
end;

procedure TRMFormPrintStringGrid.OnUserDatasetFirst(Sender: TObject);
begin
  FCurrentRow := THackGrid(FGrid).FixedRows;
  SetMemos;
end;

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

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

procedure TRMFormPrintStringGrid.OnReportBeginBand(Band: TRMBand);
begin
  if Band.Typ = btMasterData then // .Name = FFormReport.DetailBandName then
    Band.dy := THackGrid(FGrid).RowHeights[FCurrentRow];
end;

procedure TRMFormPrintStringGrid.OnGenerate_Object(aFormReport: TRMFormReport;
  Page: TRMPage; Control: TControl; var t: TRMView);
var
  liView: TRMMemoView;
  i, j, liPageNo, Leftx, NextLeft, NextTop: Integer;
  liNum: Integer;
  liGrid: THackGrid;
  s: string;
  liPage: TRMPage;
  liGridTitleHeight: Integer;
  liFlagFirstColumn: Boolean;

  procedure DrawDoubleFrameBottom(aView: TRMView; aList: TList);
  var
    t: TRMMemoView;
  begin
    if rmgoDoubleFrame in aFormReport.ReportOptions 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 MakeOneHeader(aRow, aIndex: Integer);
  begin
    liView := TRMMemoView(RMCreateObject(gtMemo, ''));
    liView.CreateUniqueName;
    liView.PLayout := rmtlCenter;
    liView.PAlignment := rmtaCenterJustify;
    liView.PStretched := rmgoStretch in aFormReport.ReportOptions;
    liView.PWordWrap := rmgoWordWrap in aFormReport.ReportOptions;
    liView.x := NextLeft;
    liView.y := NextTop;
    liView.dx := liGrid.ColWidths[aIndex] + 1;
    liView.dy := liGrid.RowHeights[aRow] + 4;
    liView.Font.Assign(liGrid.Font);
    s := liGrid.GetEditText(aIndex, aRow);
    if s = '[Error]' then
      s := '';
    liView.Memo.Text := s;
    if rmgoGridLines in aFormReport.ReportOptions then
      liView.Prop['FrameTyp'] := $F
    else
      liView.Prop['FrameTyp'] := 0;

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

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

  procedure MakeOneDetail(aIndex: Integer);
  begin
    liView := TRMMemoView(RMCreateObject(gtMemo, ''));
    liView.CreateUniqueName;
    liView.PLayout := rmtlCenter;
    liView.PAlignment := rmtaCenterJustify;
    liView.PStretched := rmgoStretch in aFormReport.ReportOptions;
    liView.PWordWrap := rmgoWordWrap in aFormReport.ReportOptions;
    liView.Font.Assign(liGrid.Font);
    if rmgoGridLines in aFormReport.ReportOptions then
      liView.Prop['FrameTyp'] := $F
    else
      liView.Prop['FrameTyp'] := 0;
    liView.x := NextLeft;
    liView.dx := liGrid.ColWidths[aIndex] + 1;
    liView.y := 0;
    liView.dy := 4;

    liPage.Objects.Add(liView);
    aFormReport.PageDetailViews.Add(liView);
    FList.Add(liView.Name);
    NextLeft := NextLeft + liView.dx;

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

  procedure DrawFixedHeader(aRow: Integer);
  var
    j: Integer;
  begin
    for j := 0 to aFormReport.GridFixedCols - 1 do
    begin
      if j < liGrid.ColCount then
        MakeOneHeader(aRow, j);
    end;
  end;

  procedure DrawFixedDetail;
  var
    i: Integer;
  begin
    for i := 0 to aFormReport.GridFixedCols - 1 do
    begin
      if i < liGrid.ColCount then
        MakeOneDetail(i);
    end;
  end;

begin
  if aFormReport.DrawOnPageFooter then
    exit;
  liGrid := THackGrid(Control);
  FGrid := TCustomGrid(Control);
  FFormReport := aFormReport;

  aFormReport.DrawOnPageFooter := TRUE;
  aFormReport.GridTop := THackFormReport(aFormReport).OffsY + Control.Top;
  aFormReport.GridHeight := Control.Height;
  liGridTitleHeight := 0;
  NextTop := Control.Top + THackFormReport(aFormReport).OffsY;

  if FUserDataset = nil then
    FUserDataset := TRMUserDataset.Create(nil);
  if FList = nil then
    FList := TStringList.Create;

  THackFormReport(aFormReport).CanSetDataSet := False;
  FList.Clear;
  FUserDataset.OnCheckEOF := OnUserDatasetCheckEOF;
  FUserDataset.OnFirst := OnUserDatasetFirst;
  FUserDataset.OnNext := OnUserDatasetNext;
  FUserDataset.OnPrior := OnUserDatasetPrior;
  aFormReport.Report.DataSet := FUserDataset;
  aFormReport.Report.OnBeginBand := OnReportBeginBand;

  Leftx := 0;
  for i := 0 to liGrid.ColCount - 1 do
    Leftx := Leftx + liGrid.ColWidths[i] + 1;

  if (aFormReport.PrintControl = Control) or (Leftx > StrToInt(THackFormReport(aFormReport).FormWidth[0])) then
    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
    liFlagFirstColumn := True;
    for i := 0 to liGrid.FixedRows - 1 do
    begin
      liGridTitleHeight := liGridTitleHeight + liGrid.RowHeights[i] + 4;
      NextLeft := Leftx;
      liPageNo := 0; liNum := 0;
      liPage := aFormReport.Report.Pages[0];
      for j := 0 to liGrid.ColCount - 1 do
      begin
        if (aFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not aFormReport.ScaleMode.FitPageWidth) then
        begin
          if (liNum > 0) and (THackFormReport(aFormReport).CalcWidth(NextLeft + (liGrid.ColWidths[j] + 1)) > THackFormReport(aFormReport).PageWidth) then // 超宽
          begin
            liFlagFirstColumn := True;
            if rmgoDoubleFrame in aFormReport.ReportOptions then
              liView.RightFrame.Width := 2;

            THackFormReport(aFormReport).FormWidth[liPageNo] := IntToStr(NextLeft);
            liNum := 0; Inc(liPageNo);
            if liPageNo >= aFormReport.Report.Pages.Count then
            begin
              THackFormReport(aFormReport).AddPage;
              THackFormReport(aFormReport).FormWidth.Add('0');
            end;
            liPage := aFormReport.Report.Pages[liPageNo];
            NextLeft := Leftx;
            liFlagFirstColumn := True;
            DrawFixedHeader(i);
          end;
        end;

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

      NextTop := NextTop + liGrid.RowHeights[i] + 4;
    end;

    liFlagFirstColumn := True;
    if rmgoDoubleFrame in aFormReport.ReportOptions then
      liView.RightFrame.Width := 2;
  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;
  liFlagFirstColumn := True;
  for i := 0 to liGrid.ColCount - 1 do //表体
  begin
    if (aFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not aFormReport.ScaleMode.FitPageWidth) then
    begin
      if (liNum > 0) and (THackFormReport(aFormReport).CalcWidth(NextLeft + (liGrid.ColWidths[i] + 1)) > THackFormReport(aFormReport).PageWidth) then // 超宽
      begin
        liFlagFirstColumn := True;
        if rmgoDoubleFrame in aFormReport.ReportOptions then
          liView.RightFrame.Width := 2;

        THackFormReport(aFormReport).FormWidth[liPageNo] := IntToStr(NextLeft);
        Inc(liPageNo); liNum := 0;
        if liPageNo >= aFormReport.Report.Pages.Count then
        begin
          THackFormReport(aFormReport).AddPage;
          THackFormReport(aFormReport).FormWidth.Add('0');
        end;
        liPage := aFormReport.Report.Pages[liPageNo];
        NextLeft := Control.Left + THackFormReport(aFormReport).OffsX;
        liFlagFirstColumn := True;
        DrawFixedDetail;
      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 THackFormReport(aFormReport).FormWidth.Count > 1 then
    THackFormReport(aFormReport).FormWidth[THackFormReport(aFormReport).FormWidth.Count - 1] := IntToStr(NextLeft);
end;

initialization
  RMRegisterFormReportControl(TStringGrid, TRMFormPrintStringGrid);
  RMRegisterFormReportControl(TCustomDBGrid, TRMFormPrintDBGrid);

end.

⌨️ 快捷键说明

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