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

📄 rm_formreport.pas

📁 进销存·完整的·有数据库的·非常完整·只得参考
💻 PAS
📖 第 1 页 / 共 5 页
字号:

function TRMGroupItems.Add: TRMGroupItem;
begin
  Result := TRMGroupItem(inherited Add);
end;

function TRMGroupItems.GetItem(Index: Integer): TRMGroupItem;
begin
  Result := TRMGroupItem(inherited GetItem(Index));
end;

procedure TRMGroupItems.SetItem(Index: Integer; Value: TRMGroupItem);
begin
  inherited SetItem(Index, Value);
end;

function TRMGroupItems.GetOwner: TPersistent;
begin
  Result := FReport;
end;

procedure TRMGroupItems.Update(Item: TCollectionItem);
begin
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMMasterDatalBandOptions}

constructor TRMMasterDataBandOptions.Create;
begin
  inherited Create;
  FLinesPerPage := 0;
  FColumns := 1;
  FColumnWidth := 200;
  FColumnGap := 20;
  FNewPageAfter := False;
end;

procedure TRMMasterDataBandOptions.Assign(Source: TPersistent);
begin
  inherited Assign(Source);
  LinesPerPage := TRMMasterDataBandOptions(Source).LinesPerPage;
  Columns := TRMMasterDataBandOptions(Source).Columns;
  ColumnWidth := TRMMasterDataBandOptions(Source).ColumnWidth;
  ColumnGap := TRMMasterDataBandOptions(Source).ColumnGap;
  FNewPageAfter := TRMMasterDataBandOptions(Source).NewPageAfter;
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMMasterDatalBandOptions}

constructor TRMGridFontOptions.Create;
begin
  inherited Create;
  FUseMaualFont := False;
  FFont := TFont.Create;
end;

destructor TRMGridFontOptions.Destroy;
begin
  FFont.Free;
  inherited Destroy;
end;

procedure TRMGridFontOptions.Assign(Source: TPersistent);
begin
  inherited Assign(Source);
  UseMaualFont := TRMGridFontOptions(Source).UseMaualFont;
  Font.Assign(TRMGridFontOptions(Source).Font);
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{ TRMPageAggr }
procedure TRMPageAggr.Assign(Source: TPersistent);
begin
	Inherited Assign(Source);
  if Source is TRMPageAggr then
  begin
  	FAutoTotal := TRMPageAggr(Source).AutoTotal;
    FTotalFields := TRMPageAggr(Source).TotalFields;
  end;
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
constructor TRMGridPageAggrOptions.Create;
begin
	Inherited Create;
  FPageSum := TRMPageAggr.Create;
  FPageSumTotal := TRMPageAggr.Create;
end;

destructor TRMGridPageAggrOptions.Destroy;
begin
	FPageSum.Free;
  FPageSumTotal.Free;
  Inherited Destroy;
end;

procedure TRMGridPageAggrOptions.Assign(Source: TPersistent);
begin
	Inherited Assign(Source);
  if Source is TRMPageAggr then
  begin
  	FPageSum.Assign(TRMGridPageAggrOptions(Source).PageSum);
  	FPageSumTotal.Assign(TRMGridPageAggrOptions(Source).PageSumTotal);
  end;
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{ TRMCustomGridReport }

constructor TRMCustomGridReport.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FShowProgress := True;
  FInitialZoom := pzDefault;
  FPreviewButtons := [pbZoom, pbLoad, pbSave, pbPrint, pbFind, pbPageSetup, pbExit];
  FReportOptions := [rmgoStretch, rmgoWordWrap, rmgoGridLines];
  FShowPrintDialog := True;
  FModifyPrepared := False;
  FReport := nil;
  FReportDataSet := nil;
  FormWidth := TStringList.Create;

  FGroups := TRMGroupItems.Create(Self);
  FPageLayout := TRMPageLayout.Create;

  FPageHeader := TRMPageHeaderFooter.Create;
  FPageHeader.ParentFormReport := Self;
  FPageFooter := TRMPageHeaderFooter.Create;
  FPageFooter.ParentFormReport := Self;
  FColumnFooter := TRMPageHeaderFooter.Create;
  FColumnFooter.ParentFormReport := Self;

  FScaleMode := TRMScaleOptions.Create;
  FGridNumOptions := TRMGridNumOptions.Create;
  FMasterDataBandOptions := TRMMasterDataBandOptions.Create;
  FGridFontOptions := TRMGridFontOptions.Create;
  FGridPageAggrOptions := TRMGridPageAggrOptions.Create;
  FAutoBooleanString := '';
end;

destructor TRMCustomGridReport.Destroy;
begin
  FGroups.Free;
  FPageLayout.Free;
  FPageHeader.Free;
  FPageFooter.Free;
  FColumnFooter.Free;
  FScaleMode.Free;
  FGridNumOptions.Free;
  FGridPageAggrOptions.Free;
  if RMDialogForm <> nil then
    FReport.Free;
  FReportDataSet.Free;
  FormWidth.Free;
  FMasterDataBandOptions.Free;
  FGridFontOptions.Free;

  inherited Destroy;
end;

procedure TRMCustomGridReport.Notification(AComponent: TComponent; Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  if Operation = opRemove then
  begin
    if AComponent = FDataSet then
      DataSet := nil
    else if AComponent = FDataSource then
      DataSource := nil;
  end;
end;

procedure TRMCustomGridReport.AssignFont(aView: TRMMemoView; aFont: TFont);
var
  liSaveColor: TColor;
begin
  liSaveColor := aView.Font.Color;
  aView.Font.Assign(aFont);
  if rmgoUseColor in ReportOptions then
    aView.Font.Color := liSaveColor;
end;

procedure TRMCustomGridReport.SetMemoViewFormat(aView: TRMMemoView; aField: TField);

  procedure SetFormat(aType, aIndex: Integer; const aFormat: string);
  begin
    if aFormat = '' then Exit;
    aView.Format := aType * $01000000 + aIndex * $00010000;
    aView.Format := aView.Format + Ord('.');
    aView.FormatStr := aFormat;
  end;

begin
	if aField = nil then Exit;
  if aField.DataType in [ftSmallint, ftInteger, ftWord, ftFloat, ftCurrency,
    ftBCD, ftBytes, ftVarBytes, ftAutoInc{$IFDEF Delphi4}, ftLargeint{$ENDIF}] then
    SetFormat(1, RMFormatNumCount, TNumericField(aField).DisplayFormat)
  else if aField.DataType in [ftDate, ftDateTime] then
    SetFormat(2, RMFormatDateCount, TDateTimeField(aField).DisplayFormat)
  else if aField.DataType in [ftTime] then
    SetFormat(3, RMFormatTimeCount, TDateTimeField(aField).DisplayFormat)
  else if aField.DataType in [ftBoolean] then
    SetFormat(4, RMFormatBooleanCount, TBooleanField(aField).DisplayValues);
end;

function TRMCustomGridReport.CalcWidth(aWidth: Integer): Integer;
begin
  Result := aWidth;
  if FScaleMode.ScaleMode = rmsmAdjust then
  begin
    if FScaleMode.ScaleFactor <> 100 then
      Result := Round(aWidth * FScaleMode.ScaleFactor / 100);
  end
end;

procedure TRMCustomGridReport.CalcRect(t: TRMView; ParentBand: TRMBandView; aFormWidth: Integer);
var
  liScale: Double;

  procedure ScaleView;
  begin
    t.dx := Round((t.x + t.dx) * liScale) - Round(t.x * liScale);
    t.dy := Round((t.y + t.dy) * liScale) - Round(t.y * liScale);
    t.x := Round(t.x * liScale);
    t.y := ParentBand.y + Round(t.y * liScale) - Round(ParentBand.y * liScale);
    if t is TRMMemoView then
      TRMMemoView(t).Font.Height := -Trunc(TRMMemoView(t).Font.Size * 96 / 72 * liScale);
  end;

begin
  t.x := t.x + OffsX;
  t.y := t.y + OffsY;
  liScale := FScaleMode.ScaleFactor / 100;
  if FScaleMode.ScaleMode = rmsmAdjust then
  begin
    if FScaleMode.ScaleFactor <> 100 then
      ScaleView;
  end
  else
  begin
    if FScaleMode.FitPageWidth then //水平缩放
    begin
      liScale := PageWidth / aFormWidth;
      ScaleView;
    end
    else if (not HaveDetailBand) and FScaleMode.FitPageHeight then
    begin
      liScale := PageHeight / FormHeight;
      ScaleView;
    end;
  end;

  if FScaleMode.CenterOnPageH then //水平居中
  begin
    t.x := t.x + (PageWidth - Round(aFormWidth * liScale)) div 2;
  end;
  if FScaleMode.CenterOnPageV and (not HaveDetailBand) then //垂直居中
  begin
    t.y := t.y + (PageHeight - Round(FormHeight * liScale)) div 2;
  end;
end;

type
  THackReport = class(TRMReport)
  end;

procedure TRMCustomGridReport.AddPage;
var
  liPage: TRMPage;
begin
  FReport.Pages.Add;
  liPage := FReport.Pages[FReport.Pages.Count - 1];
  with PageLayout do
  begin
    liPage.pgMargins := Rect(LeftMargin, TopMargin, RightMargin, BottomMargin);
    liPage.ChangePaper(pgSize, Width, Height, pgBin, pgOr);
  end;
end;

procedure TRMCustomGridReport._InternalShowReport(aFlag: Integer);
begin
  Report.ModalPreview := True;
  ReportDataSet.DataSet := nil;
  ReportDataSet.DataSource := nil;
  FReport.ModalPreview := TRUE;
  RM_Class.CurReport := FReport;
  RMVersion := RMCurrentVersion;
  try
    FReport.ReportInfo.Title := PageLayout.Title;
    FReport.InitialZoom := FInitialZoom;
    FReport.PreviewButtons := FPreviewButtons;
    FReport.Preview := FPreview;
    FReport.ReportType := FReportType;
    FReport.ShowProgress := FShowProgress;
    FReport.ModifyPrepared := FModifyPrepared;
    FReport.ShowPrintDialog := FShowPrintDialog;
    FReport.ReportInfo.Title := FReportTitle;
    FReport.OnBeginBand := FOnBeginBand;
    FReport.OnEndBand := FOnEndBand;
    FReport.OnBeginDoc := FOnBeginDoc;
    FReport.OnEndDoc := FOnEndDoc;
    FReport.OnBeginPage := FOnBeginPage;
    FReport.OnEndPage := FOnEndPage;
    FReport.OnGetValue := FOnGetValue;
    FReport.OnBeforePrint := nil;
    FReport.OnProgress := FOnProgress;
    FReport.OnBeginColumn := FOnBeginColumn;
    FReport.OnPrintColumn := FOnPrintColumn;
    if rmgoRebuildAfterPageChanged in ReportOptions then
      THackReport(FReport).OnAfterPreviewPageSetup := OnAfterPreviewPageSetup
    else
      THackReport(FReport).OnAfterPreviewPageSetup := nil;

    FReport.Pages.Clear;
    with PageLayout do
    begin
      FReport.DoublePass := DoublePass;
      THackReport(FReport).SetPrinterTo(PrinterName);
    end;
    AddPage;

    if CreateReportFromGrid then
    begin
      try
        if (rmgoDisableControls in ReportOptions) and (ReportDataSet.DataSource <> nil) and (ReportDataSet.DataSource.DataSet <> nil) then
          ReportDataSet.DataSource.DataSet.DisableControls;
        case aFlag of
          1: FReport.ShowReport;
          2: FReport.PrintReport;
          3: FReport.DesignReport;
        end;
      finally
        if (rmgoDisableControls in ReportOptions) and (ReportDataSet.DataSource <> nil) and (ReportDataSet.DataSource.DataSet <> nil) then
          ReportDataSet.DataSource.DataSet.EnableControls;
      end;
    end;
  finally
  end;
end;

procedure TRMCustomGridReport.ShowReport;
begin
  _InternalShowReport(1);
end;

procedure TRMCustomGridReport.PrintReport;
begin
  _InternalShowReport(2);
end;

procedure TRMCustomGridReport.DesignReport;
begin
  _InternalShowReport(3);
end;

procedure TRMCustomGridReport.BuildReport;
begin
  _InternalShowReport(0);
end;

procedure TRMCustomGridReport.OnAfterPreviewPageSetup(Sender: TObject);
begin
  ChangePageLayout(TRMPageSetting(Sender));
  BuildReport;
end;

procedure TRMCustomGridReport.PageSetup;
var
  tmpForm: TRMPageSetupForm;
begin
  tmpForm := TRMPageSetupForm.Create(Application);
  try
		tmpForm.PageSetting.Title := PageLayout.Title;
    tmpForm.PageSetting.DoublePass := PageLayout.DoublePass;
    tmpForm.PageSetting.PageOr := PageLayout.pgOr;
    tmpForm.PageSetting.MarginLeft := RMRound(RMConvertFromPixels(PageLayout.LeftMargin, rmsuMM) / 10, 1);
    tmpForm.PageSetting.MarginTop := RMRound(RMConvertFromPixels(PageLayout.TopMargin, rmsuMM) / 10, 1);
    tmpForm.PageSetting.MarginRight := RMRound(RMConvertFromPixels(PageLayout.RightMargin, rmsuMM) / 10, 1);
    tmpForm.PageSetting.MarginBottom := RMRound(RMConvertFromPixels(PageLayout.BottomMargin, rmsuMM) / 10, 1);
    tmpForm.PageSetting.ColCount := PageLayout.Columns;
    tmpForm.PageSetting.ColGap := RMRound(RMConvertFromPixels(PageLayout.ColumnSpace, rmsuMM) / 10, 1);
    tmpForm.PageSetting.PageWidth := PageLayout.Width;
    tmpForm.PageSetting.PageHeight := PageLayout.Height;
    tmpForm.PageSetting.PageSize := PageLayout.pgSize;
    tmpForm.PageSetting.PageBin := PageLayout.pgBin;
    tmpForm.PageSetting.PrinterName := PageLayout.PrinterName;
    tmpForm.PageSetting.PrintBackColor := PageLayout.PrintBackColor;
    if tmpForm.ShowModal = mrOk then
    begin
      ChangePageLayout(tmpForm.PageSetting);
    end;

⌨️ 快捷键说明

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