rm_ptopgrid.pas

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

PAS
1,027
字号
  var
    i: Integer;
    liCol: TtsCol;
  begin
    for i := 1 to aFormReport.GridFixedCols do
    begin
      liCol := liGrid.Col[i];
      if not liCol.Visible then Continue;
      if i < liGrid.Cols then
        MakeOneDetail(i);
    end;
  end;

begin
  if aFormReport.DrawOnPageFooter then exit;
  liGrid := THackGrid(aControl);
  FFormReport := aFormReport;

  FGrid := liGrid;
  if (rmgoSelectedRecordsOnly in aFormReport.ReportOptions) and
    (liGrid.SelectedRows.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;

  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;

  tmpx := 0;
  for i := 1 to liGrid.Cols do
  begin
    liCol := liGrid.Col[i];
    if liCol.Visible then
      tmpx := tmpx + liCol.Width + 1;
  end;

  if liGrid.HeadingOn and (rmgoGridNumber in aFormReport.ReportOptions) then
    tmpx := tmpx + RMCanvasHeight('a', liGrid.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);

  if liGrid.HeadingOn then //表头
  begin
    liFlagFirstColumn := True;
    liGridTitleHeight := liGrid.RowHeights[0] + 4;
    tmpx := aControl.Left + THackFormReport(aFormReport).OffsX;
    if rmgoGridNumber in aFormReport.ReportOptions then
    begin
      liView := RMCreateObject(gtMemo, '');
      liView.ParentPage := aPage;
      liView.spLeft := tmpx;
      liView.spTop := NextTop;
      liView.spWidth := RMCanvasHeight('a', liGrid.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 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.spWidth := 2;
        liView.TopFrame.spWidth := 2;
      end;
      liFlagFirstColumn := False;
    end;

    liPage := aPage; liNum := 0;
    tmpx0 := tmpx;
    for i := 1 to liGrid.Cols do
    begin
      liCol := liGrid.Col[i];
      if not liCol.Visible then Continue;
      if (aFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not aFormReport.ScaleMode.FitPageWidth) then
      begin
        if (liNum > 0) and (THackFormReport(aFormReport).CalcWidth(tmpx + (liCol.Width + 1)) > THackFormReport(aFormReport).PageWidth) then // 超宽
        begin
          liNum := 0;
          liFlagFirstColumn := True;
          if rmgoDoubleFrame in aFormReport.ReportOptions then
            liView.RightFrame.spWidth := 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.spWidth := 2;
  end;

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

  liPage := aPage; //表体
  tmpx := aControl.Left + THackFormReport(aFormReport).OffsX;
  liFlagFirstColumn := True;
  if rmgoGridNumber in aFormReport.ReportOptions then
  begin
    liView := RMCreateObject(gtMemo, '');
    liView.ParentPage := aPage;
    liView.spLeft := tmpx;
    liView.spTop := 0;
    liView.spWidth := RMCanvasHeight('a', liGrid.Font) * aFormReport.GridNumOptions.Number;
    liView.spHeight := liGrid.DefaultRowHeight + 4;
    liView.Memo.Add('[Line#]');
    TRMMemoView(liView).VAlign := rmvCenter;
    TRMMemoView(liView).HAlign := rmhCenter;
    if (rmgoGridLines in aFormReport.ReportOptions) 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.spWidth := 2;
    end;
    DrawDoubleFrameBottom(liView, aFormReport.ColumnFooterViews);
    liFlagFirstColumn := False;
  end;

  tmpx0 := tmpx;
  liNum := 0; liPageNo := 0;
  for i := 1 to liGrid.Cols do
  begin
    liCol := liGrid.Col[i];
    if not liCol.Visible then Continue;
    if (aFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not aFormReport.ScaleMode.FitPageWidth) then
    begin
      if (liNum > 0) and (THackFormReport(aFormReport).CalcWidth(tmpx + (liCol.Width + 1)) > THackFormReport(aFormReport).PageWidth) then // 超宽
      begin
        liNum := 0;
        liFlagFirstColumn := True;
        if rmgoDoubleFrame in aFormReport.ReportOptions then
          liView.RightFrame.spWidth := 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.spWidth := 2;
  end;

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

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMPrintTopDBGrid}

//procedure TRMPrintTopDBGrid.OnBeforePrintBandEvent(Band: TRMBand; var PrintBand: Boolean);
//begin
//  PrintBand := THackDBGrid(FDBGrid).SelectedRows.Selected[THackDBGrid(FDBGrid).CurrentDataRow];
//end;

constructor TRMPrintTopDBGrid.Create;
begin
  inherited Create;
  FList := TStringList.Create;
end;

destructor TRMPrintTopDBGrid.Destroy;
begin
  FList.Free;
  inherited Destroy;
end;

procedure TRMPrintTopDBGrid._OnBeforePrint(Memo: TStrings; View: TRMReportView);
var
  i: Integer;
begin
  for i := 0 to FList.Count - 1 do
  begin
    if AnsiCompareText(View.Name, FList[i]) = 0 then
    begin
      if View is TRMMemoView then
      begin
        Memo.Text := THackDBGrid(FDBGrid).Cell[StrToInt(Memo[0]), THackDBGrid(FDBGrid).CurrentDataRow];
      end;
    end;
  end;
end;

procedure TRMPrintTopDBGrid.OnGenerate_Object(aFormReport: TRMFormReport; aPage: TRMReportPage;
  aControl: TControl; var t: TRMView);
var
  liView: TRMView;
  i, tmpx, tmpx0, NextTop: Integer;
  liGrid: THackDBGrid;
  DSet: TDataSet;
  liPage: TRMReportPage;
  liPageNo, liNum, liGridTitleHeight: Integer;
  liFlagFirstColumn: Boolean;
  liCol: TtsDBCol;
  liNeedBeforePrint: Boolean;

  procedure DrawDoubleFrameBottom(aView: TRMView; aList: TList);
  var
    t: TRMMemoView;
  begin
    if rmgoDoubleFrame in aFormReport.ReportOptions then
    begin
      t := TRMMemoView(RMCreateObject(gtMemo, ''));
      t.ParentPage := liPage;
      t.LeftFrame.Visible := False;
      t.TopFrame.Visible := True;
      t.RightFrame.Visible := False;
      t.BottomFrame.Visible := False;
      t.TopFrame.spWidth := 2;
      t.spGapLeft := 0; t.spGapTop := 0;
      t.SetspBounds(aView.spLeft, aFormReport.GridTop + aFormReport.GridHeight, aView.spWidth, 2);
      t.Stretched := rmgoStretch in aFormReport.ReportOptions;
      aList.Add(t);
    end;
  end;

  procedure MakeOneHeader(aIndex: Integer);
  var
    liCol: TtsDBCol;
  begin
    liCol := liGrid.Col[aIndex];
    liView := TRMMemoView(RMCreateObject(gtMemo, ''));
    liView.ParentPage := liPage;
    liView.Memo.Text := liCol.Heading;
    liView.spLeft := tmpx;
    liView.spTop := NextTop;
    liView.spWidth := liCol.Width + 1;
    liView.spHeight := liGridTitleHeight;
    TRMMemoView(liView).WordWrap := (liCol.HeadingWordWrap = wwOn) or ((liCol.HeadingWordWrap = wwDefault) and (liGrid.HeadingWordWrap = wwOn));
    if liCol.HeadingFont <> nil then
      aFormReport.AssignFont(TRMMemoView(liView), liCol.HeadingFont)
    else
      aFormReport.AssignFont(TRMMemoView(liView), liGrid.HeadingFont);

    case liCol.HeadingHorzAlignment of
      htaLeft: TRMMemoView(liView).HAlign := rmhLeft;
      htaRight: TRMMemoView(liView).HAlign := rmhRight;
    else
      TRMMemoView(liView).HAlign := rmhCenter;
    end;
    case liCol.HeadingVertAlignment of
      vtaCenter: TRMMemoView(liView).VAlign := rmvCenter;
      vtaBottom: TRMMemoView(liView).VAlign := rmvBottom;
    else
      TRMMemoView(liView).VAlign := rmvTop;
    end;

    if rmgoUseColor in aFormReport.ReportOptions then
      liView.FillColor := liCol.Color;
    if rmgoGridLines in aFormReport.ReportOptions 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;

⌨️ 快捷键说明

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