得了,真个贴给你:
unit DynamicReport;
interface
uses DB, FR_DSet, FR_DBSet, FR_Class,Graphics,Classes,StrUtils,
StdCtrls,SysUtils,Dialogs,FR_Prntr,printers;
Type
TPaperSizeInfo = Record
PaperName:String;
PaperSize:Integer;
end;
TAPaperSizeInfo = Array of TPaperSizeInfo;
TPrinterPapersInfo = class
public
class function PaperSizeNum:Integer;
class function PaperSizeInfo:TAPaperSizeInfo;
end;
THeaderCategory = Record
PageIndex :Integer;
Top :Integer;
Left :Integer;
Height :Integer;
Width :Integer;
DisplayLabel:String;
end;
TAHeaderCategory = Array of THeaderCategory;
TDynamicReport = class(TComponent)
private
WIDTHADJUST :Extended;
FfrReport :TfrReport;
FDataFont :TFont;
FHeaderFont :TFont;
FAutoSize :Boolean;
FAutoWrap :Boolean;
FMargin :Integer;
FLeftMargin :Integer;
FRightMargin :Integer;
FTopMargin :Integer;
FBottomMargin :Integer;
FRowBreaker :Boolean;
FNewPage :Boolean;
FWrapColumnIndex :Integer;
FRowSpace :Integer;
FDataRowHeight :Integer;
FHeaderRowHeight :Integer;
FFirstRowGroup :Boolean;
FDisplayProp :TAHeaderCategory;
FPaperSize :Integer;
FPaperOrientation :TPrinterOrientation;
procedure SetRowBreaker(const Value: Boolean);
function GetMasterBand(PageIndex: Integer;AutoCreate:Boolean = True):TfrBandView;
function GetGroupHeaderBand(PageIndex: Integer;AutoCreate:Boolean = True):TfrBandView;
function GetGroupFooterBand(PageIndex: Integer;AutoCreate:Boolean = True):TfrBandView;
function GetMasterFooterBand(PageIndex: Integer;AutoCreate:Boolean = True):TfrBandView;
function GetHeaderBand(PageIndex: Integer;
AutoCreate: Boolean=True): TfrBandView;
protected
procedure SetAutoSize(Value:Boolean);
procedure SetAutoWrap(Value:Boolean);
procedure SetfrReport(Value:TfrReport);
procedure SetDataFont(Value:TFont);
procedure SetHeaderFont(Value:TFont);
procedure SetDisplayProp(Value:TAHeaderCategory);
procedure SetMargin(Value:Integer);
procedure SetLeftMargin(Value:Integer);
function GetLeftMargin:Integer;
procedure SetRightMargin(Value:Integer);
procedure SetTopMargin(Value:Integer);
procedure SetBottomMargin(Value:Integer);
function GetRightMargin:Integer;
function GetTopMargin:Integer;
function GetBottomMargin:Integer;
procedure SetRowBraker(Value:Boolean);
procedure SetNewPage(Value:Boolean);
procedure SetWrapColumnIndex(Value:Integer);
procedure SetPaperOrientation(Value:TPrinterOrientation);
procedure SetPaperSize(Value:Integer);
procedure SetPagesProp(PropName:String;Value:Variant);
procedure PreparePage(ForDataAndHeader:Boolean=False);
public
procedure ClearOldCreatedObject;
procedure CreateMasterData;
procedure CreateMasterDataAndHeader(ItemCategory: TStringList);
procedure CreatePageHeader;
procedure ShowReport;overload;
procedure ShowReport(ColumnIndex, PageIndex: Integer);overload;
procedure CopyColumn(ColumnIndex, PageIndex: Integer);
constructor Create(AOwner: TComponent);override;
destructor Destroy;override;
published
property DataFont :TFont read FDataFont write SetDataFont;
property HeaderFont :TFont read FHeaderFont write SetHeaderFont;
property frReport :TfrReport read FfrReport write SetfrReport;
property AutoSize :Boolean read FAutoSize write SetAutoSize;
property AutoWrap :Boolean read FAutoWrap write SetAutoWrap;
property Margin :Integer read FMargin write SetMargin;
property LeftMargin :Integer read GetLeftMargin write SetLeftMargin;
property RightMargin :Integer read GetRightMargin write SetRightMargin;
property TopMargin :Integer read GetTopMargin write SetTopMargin;
property BottomMargin :Integer read GetRightMargin write SetBottomMargin;
property WrapColumnIndex :Integer read FWrapColumnIndex write SetWrapColumnIndex;
property RowBreaker :Boolean read FRowBreaker write SetRowBreaker;
property NewPage :Boolean read FNewPage write SetNewPage;
property RowSpace :Integer read FRowSpace write FRowSpace;
property DataRowHeight :Integer read FDataRowHeight write FDataRowHeight;
property HeaderRowHeight :Integer read FHeaderRowHeight write FHeaderRowHeight;
property FirstRowGroup :Boolean read FFirstRowGroup write FFirstRowGroup;
property DisplayProp :TAHeaderCategory read FDisplayProp write SetDisplayProp;
property PaperSize :Integer read FPaperSize write SetPaperSize;
property PaperOrientation :TPrinterOrientation read FPaperOrientation write SetPaperOrientation;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('GiSun', [TDynamicReport]);
end;
procedure TDynamicReport.ClearOldCreatedObject;
var
i,n:integer;
fPage:TfrPage;
fName:String;
begin
if FfrReport = nil then
exit;
for i := 0 to frReport.Pages.Count - 1do
begin
fPage := frReport.Pages
;
for n:= fPage.Objects.Count -1do
wnto 0do
begin
fName:=TfrView(fPage.Objects[n]).Prop['Name'];
if fName = '' then
Exit;
if LeftStr(fName,3) = '@@@' then
begin
fPage.Objects.Delete;
end else
end;
end;
end;
procedure TDynamicReport.CopyColumn(ColumnIndex,PageIndex:Integer);
var v:TfrMemoView;
n:integer;
fView:tFrView;
fPage:TfrPage;
aqCrossSalaryReport:TDataSet;
begin
if FfrReport = nil then
exit;
if not Assigned(FDataFont) then
exit;
if not Assigned(frReport.Dataset) then
exit;
if not ((frReport.Dataset) is TfrDBDataset) then
exit;
if not Assigned(TfrDBDataset(frReport.Dataset).Dataset) then
exit;
aqCrossSalaryReport := TfrDBDataset(frReport.Dataset).Dataset;
do
cMode := dmDesigning;
if ColumnIndex > aqCrossSalaryReport.FieldCount - 1 then
exit;
if PageIndex > frReport.Pages.Count - 1 then
exit;
n := ColumnIndex;
// for n:=0 to aqCrossSalaryReport.FieldCount - 1do
begin
fView := GetMasterBand(PageIndex);
fPage := frReport.Pages[PageIndex];
v := TfrMemoView(fpage.FindObject('@@@DAT-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr));
if v = nil then
begin
v :=TfrMemoView(frCreateObject(gtMemo,''));
v.Name := '@@@DAT-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr;
fPage.Objects.Add(v);
end;
v.SetBounds(FDisplayProp[n].Left,fView.Prop['top'] + FDisplayProp[n].Top,FDisplayProp[n].Width,FDisplayProp[n].Height);
v.Font.assign(DataFont);
v.FrameTyp :=15;
v.Prop['Wordwrap']:=True;
v.Alignment := Ord(aqCrossSalaryReport.Fields[n].Alignment)+frtaMiddle;
v.Memo.Text := ('['+aqCrossSalaryReport.Fields[n].FieldName+']');
fView := GetHeaderBand(PageIndex);
fPage := frReport.Pages[PageIndex];
v := TfrMemoView(fpage.FindObject('@@@HDR-'+aqCrossSalaryReport.Fields[n].DisplayLabel + IntToStr));
if v = nil then
begin
v :=TfrMemoView(frCreateObject(gtMemo,''));
v.Name := '@@@HDR-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr;
fPage.Objects.Add(v);
end;
v.SetBounds(FDisplayProp[n].Left,fView.Prop['top'] + FDisplayProp[n].Top,FDisplayProp[n].Width,FDisplayProp[n].Height);
v.Font.assign(DataFont);
v.FrameTyp :=15;
v.Prop['Wordwrap']:=True;
v.Alignment := Ord(aqCrossSalaryReport.Fields[n].Alignment)+frtaMiddle;
v.Memo.Text := (aqCrossSalaryReport.Fields[n].DisplayLabel);
// end;
end;
procedure TDynamicReport.CreateMasterData;
var v,tmpv:TfrMemoView;
n,GroupTop:integer;
fView,ftmpView:tFrView;
fPage:TfrPage;
aqCrossSalaryReport:TDataSet;
begin
if FfrReport = nil then
exit;
if not Assigned(FDataFont) then
exit;
if not Assigned(frReport.Dataset) then
exit;
if not ((frReport.Dataset) is TfrDBDataset) then
exit;
if not Assigned(TfrDBDataset(frReport.Dataset).Dataset) then
exit;
aqCrossSalaryReport := TfrDBDataset(frReport.Dataset).Dataset;
PreparePage;
do
cMode := dmDesigning;
for n:=0 to aqCrossSalaryReport.FieldCount - 1do
begin
fView := GetMasterBand(FDisplayProp[n].PageIndex);
fPage := frReport.Pages[FDisplayProp[n].PageIndex];
v := TfrMemoView(fpage.FindObject('@@@DAT-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr));
if v = nil then
begin
v :=TfrMemoView(frCreateObject(gtMemo,''));
v.Name := '@@@DAT-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr;
fPage.Objects.Add(v);
end;
if FFirstRowGroup and (n = 0) then
begin
//建立分组头
ftmpView := GetGroupHeaderBand(FDisplayProp[n].PageIndex);
ftmpView.Prop['CONDITION'] := '['+aqCrossSalaryReport.Fields[n].FieldName+']';
ftmpView.Prop['Height'] := FDisplayProp[n].Height;
GroupTop := ftmpView.Prop['Top'];
//如果第一列分组,则重新设置第一列的位置
v.SetBounds(FDisplayProp[n].Left,GroupTop + FDisplayProp[n].Top,FDisplayProp[n].Width,FDisplayProp[n].Height);
//建立一个只有左边有边框的空Memo
v.FrameTyp :=13;
tmpv :=TfrMemoView(frCreateObject(gtMemo,''));
tmpv.Name := '@@@Line-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr;
fPage.Objects.Add(tmpv);
tmpv.SetBounds(FDisplayProp[n].Left,fView.Prop['top'] + FDisplayProp[n].Top,FDisplayProp[n].Width,FDisplayProp[n].Height);
tmpv.FrameTyp := 4;
//建立分组尾及底线
ftmpView := GetGroupFooterBand(FDisplayProp[n].PageIndex);
ftmpView.Prop['Height'] := 0;
tmpv :=TfrMemoView(frCreateObject(gtLine,''));
tmpv.Name := '@@@BLine-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr;
fPage.Objects.Add(tmpv);
tmpv.SetBounds(FDisplayProp[n].Left,ftmpView.Prop['top'],FDisplayProp[n].Width,0);
tmpv.FrameTyp := 8;
tmpv.FrameWidth := 1;
end else
begin
v.FrameTyp :=15;
v.SetBounds(FDisplayProp[n].Left,fView.Prop['top'] + FDisplayProp[n].Top,FDisplayProp[n].Width,FDisplayProp[n].Height);
end;
//建立分组最后一列线
if FFirstRowGroup and (n < aqCrossSalaryReport.FieldCount - 1 ) and (n > 0) then
begin
ftmpView := GetGroupHeaderBand(FDisplayProp[n].PageIndex);
tmpv :=TfrMemoView(frCreateObject(gtMemo,''));
tmpv.Name := '@@@Line-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr;
fPage.Objects.Add(tmpv);
tmpv.SetBounds(FDisplayProp[n].Left,ftmpView.Prop['top'] + FDisplayProp[n].Top,FDisplayProp[n].Width,FDisplayProp[n].Height);
tmpv.FrameTyp := 8;
end;
if FFirstRowGroup and (n = aqCrossSalaryReport.FieldCount - 1 ) then
begin
ftmpView := GetGroupHeaderBand(FDisplayProp[n].PageIndex);
tmpv :=TfrMemoView(frCreateObject(gtMemo,''));
tmpv.Name := '@@@Line-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr;
fPage.Objects.Add(tmpv);
tmpv.SetBounds(FDisplayProp[n].Left,ftmpView.Prop['top'] + FDisplayProp[n].Top,FDisplayProp[n].Width,FDisplayProp[n].Height);
tmpv.FrameTyp := 11;
end;
if not FFirstRowGroup then
v.BandAlign := baLeft;
v.Font.assign(DataFont);
v.Prop['Wordwrap']:=True;
v.Alignment := Ord(aqCrossSalaryReport.Fields[n].Alignment) + 8;
v.Memo.Text := ('['+aqCrossSalaryReport.Fields[n].FieldName+']');
end;
end;
procedure TDynamicReport.CreatePageHeader;
var v:TfrMemoView;
n:integer;
fView:tFrView;
fPage:TfrPage;
aqCrossSalaryReport:TDataSet;
begin
if FfrReport = nil then
exit;
if not Assigned(FHeaderFont) then
exit;
if not Assigned(frReport.Dataset) then
exit;
if not ((frReport.Dataset) is TfrDBDataset) then
exit;
if not Assigned(TfrDBDataset(frReport.Dataset).Dataset) then
exit;
aqCrossSalaryReport := TfrDBDataset(frReport.Dataset).Dataset;
PreparePage;
do
cMode := dmDesigning;
for n:=0 to aqCrossSalaryReport.FieldCount - 1do
begin
fView := GetHeaderBand(FDisplayProp[n].PageIndex);
fPage := frReport.Pages[FDisplayProp[n].PageIndex];
v := TfrMemoView(fpage.FindObject('@@@HDR-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr));
if v = nil then
begin
v :=TfrMemoView(frCreateObject(gtMemo,''));
v.Name := '@@@HDR-'+aqCrossSalaryReport.Fields[n].FieldName + IntToStr;
fPage.Objects.Add(v);
end;
if FHeaderRowHeight = 0 then
begin
v.SetBounds(FDisplayProp[n].Left,fView.Prop['top'] + FDisplayProp[n].Top,FDisplayProp[n].Width,FDisplayProp[n].Height);
end else
begin
v.SetBounds(FDisplayProp[n].Left,fView.Prop['top'] + FDisplayProp[n].Top,FDisplayProp[n].Width,FHeaderRowHeight);
end;
if not FFirstRowGroup then
v.BandAlign := baLeft;
v.Font.assign(HeaderFont);
v.FrameTyp :=15;
v.Prop['Wordwrap']:=True;
v.Alignment := 10;
v.Memo.Text := (aqCrossSalaryReport.Fields[n].DisplayLabel);
end;
end;
procedure TDynamicReport.CreateMasterDataAndHeader(ItemCategory:TStringList);
var v:TfrMemoView;
n,fActTop,fTop,fActHeight,fHeight:integer;
fView:tFrView;
fPage:TfrPage;
CateCount:Integer;
AHeaderCate:array of THeaderCategory;
PreCate:String;
fName:String;
aqCrossSalaryReport:TDataSet;
begin
if FfrReport = nil then
exit;
if not Assigned(FDataFont) then
exit;
if not Assigned(FHeaderFont) then
exit;
if not Assigned(frReport.Dataset) then
exit;
if not (frReport.Dataset is TfrDBDataset) then
exit;
if not Assigned(TfrDBDataset(frReport.Dataset).DataSet) then
exit;
aqCrossSalaryReport := TfrDBDataset(frReport.Dataset).DataSet;
PreparePage(True);
fPage := frReport.Pages[0];
fView := nil;
for n:=0 to fPage.Objects.Count -1do
begin
if TfrView(fPage.Objects[n]).Prop['Name']='' then
TfrView(fPage.Objects[n]).Prop['Name']:='@@@SandBoy'+IntToStr;
fName:=TfrView(fPage.Objects[n]).Prop['Name'];
fView := fPage.FindObject(fName);
if (fView is TfrBandView) and (TfrBandView(fView).BandType = btMasterData) then
Break;
end;
if (fView = nil) then
begin
exit;
end;
do
cMode := dmDesigning;
fTop:=fView.Prop['top'] + FRowSpace;
fHeight:=fView.Prop['height'];
CateCount := 0;
PreCate := 'None';
for n:=0 to aqCrossSalaryReport.FieldCount - 1do
begin
if ItemCategory[n] = 'None' then
begin
fActTop := fTop;
fActHeight := Round(fHeight*2/3);
end else
begin
fActTop := fTop + Round(fHeight/3);
fActHeight := Round(fHeight/3);
end;
v := TfrMemoView(fpage.FindObject('@@@HDR'+ aqCrossSalaryReport.Fields[n].FieldName + IntToStr));
if v = nil then
begin
v :=TfrMemoView(frCreateObject(gtMemo,''));
v.Name := '@@@HDR'+ aqCrossSalaryReport.Fields[n].FieldName + IntToStr;
fPage.Objects.Add(v);
end;
v.SetBounds(FDisplayProp[n].Left,fActTop,FDisplayProp[n].Width,fActHeight);
//设置列显示长宽高,DisplayWidth是列长度
v.Font.assign(HeaderFont);
v.FrameTyp :=15;
v.Prop['Wordwrap']:=True;
v.Alignment := 10;
v.Memo.Text :=(aqCrossSalaryReport.Fields[n].DisplayLabel);
v := TfrMemoView(fpage.FindObject('@@@DAT'+ aqCrossSalaryReport.Fields[n].FieldName + IntToStr));
if v = nil then
begin
v :=TfrMemoView(frCreateObject(gtMemo,''));
v.Name := '@@@DAT'+ aqCrossSalaryReport.Fields[n].FieldName + IntToStr;
fPage.Objects.Add(v);
end;
v.SetBounds(FDisplayProp[n].Left,fTop + Round(fHeight*2/3),FDisplayProp[n].Width,Round(fHeight/3));
//设置列显示长宽高,DisplayWidth是列长度
v.Font.assign(DataFont);
v.FrameTyp :=15;
v.Prop['Wordwrap']:=True;
v.Alignment := Ord(aqCrossSalaryReport.Fields[n].Alignment)+frtaMiddle;
v.Memo.Text :=('['+aqCrossSalaryReport.Fields[n].FieldName+']');
if (PreCate <> ItemCategory[n]) then
begin
if PreCate <> 'None' then
begin
AHeaderCate[CateCount - 1].Width := FDisplayProp[n].Left - AHeaderCate[CateCount - 1].Left;
end;
if ItemCategory[n] <> 'None' then
begin
CateCount := CateCount + 1;
SetLength(AHeaderCate,CateCount);
AHeaderCate[CateCount - 1].Left := FDisplayProp[n].Left;
AHeaderCate[CateCount - 1].Top := fTop;
AHeaderCate[CateCount - 1].Height := Round(fHeight/3);
AHeaderCate[CateCount - 1].DisplayLabel := ItemCategory[n];
end;
end;
PreCate := ItemCategory[n];
end;
n := aqCrossSalaryReport.FieldCount - 1;
if PreCate <> 'None' then
AHeaderCate[CateCount - 1].Width := FDisplayProp[n].Left+FDisplayProp[n].Width - AHeaderCate[CateCount - 1].Left;
for n:=0 to CateCount - 1do
begin
if AHeaderCate[n].DisplayLabel <> 'None' then
begin
v := TfrMemoView(fpage.FindObject('@@@CAT'+ aqCrossSalaryReport.Fields[n].FieldName + IntToStr));
if v = nil then
begin
v :=TfrMemoView(frCreateObject(gtMemo,''));
v.Name := '@@@CAT'+ aqCrossSalaryReport.Fields[n].FieldName + IntToStr;
fPage.Objects.Add(v);
end;
v.SetBounds(AHeaderCate[n].Left,AHeaderCate[n].Top,AHeaderCate[n].Width,AHeaderCate[n].Height);
v.Font.assign(HeaderFont);
v.FrameTyp :=15;
v.Prop['Wordwrap']:=True;
v.Alignment := 10;
v.Memo.Text :=(AHeaderCate[n].DisplayLabel);
end;
end;
if FRowBreaker then
fView.Prop['Height'] := fView.Prop['Height'] + 5;
end;
constructor TDynamicReport.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FAutoSize := False;
FAutoWrap := True;
FDataFont := TFont.Create;
FNewPage := False;
FHeaderFont := TFont.Create;
FDataFont.Name := '宋体';
FDataFont.Size := 9;
HeaderFont.Name := '宋体';
HeaderFont.Size := 9;
WIDTHADJUST := 3.5;
Margin := 4;
FWrapColumnIndex := 0;
FRowBreaker := False;
FFirstRowGroup := False;
// FDataFontMMSize:= (-DataFont.Height * 25.4) / DataFont.PixelsPerInch;
// FHeaderFontMMSize:= (-HeaderFont.Height * 25.4) / HeaderFont.PixelsPerInch;
end;
{
constructor TDynamicReport.Create(ExistedReport: TfrReport);
begin
Create(nil);
FfrReport := ExistedReport;
end;
}
procedure TDynamicReport.SetAutoSize(Value :Boolean);
begin
if Value = FAutoSize then
exit;
FAutoSize := Value;
// FDataFontMMSize:= (-DataFont.Height * 25.4) / DataFont.PixelsPerInch;
// FHeaderFontMMSize:= (-HeaderFont.Height * 25.4) / HeaderFont.PixelsPerInch;
end;
destructor TDynamicReport.Destroy;
begin
FDataFont.Free;
FHeaderFont.Free;
inherited;
end;
procedure TDynamicReport.SetDataFont(Value: TFont);
begin
//字体毫米数-DataFont.Height * 25.4) / DataFont.PixelsPerInch)
FDataFont.Assign(Value);
// FDataFontMMSize:= (-DataFont.Height * 25.4) / DataFont.PixelsPerInch;
end;
procedure TDynamicReport.SetfrReport(Value: TfrReport);
begin
if FfrReport = Value then
exit;
FfrReport := Value;
if Value = nil then
exit;
if FfrReport.Pages.Count > 0 then
begin
FLeftMargin := frReport.Pages[0].Prop['LeftMargin'];
FTopMargin := frReport.Pages[0].Prop['LeftMargin'];
FRightMargin := frReport.Pages[0].Prop['LeftMargin'];
FBottomMargin := frReport.Pages[0].Prop['LeftMargin'];
end;
end;
procedure TDynamicReport.SetHeaderFont(Value: TFont);
begin
HeaderFont.Assign(Value);
// FHeaderFontMMSize:= (-HeaderFont.Height * 25.4) / HeaderFont.PixelsPerInch;
end;
procedure TDynamicReport.ShowReport;
begin
ClearOldCreatedObject;
CreatePageHeader;
CreateMasterData;
frReport.ShowReport;
end;
procedure TDynamicReport.PreparePage(ForDataAndHeader:Boolean);
var
aqCrossSalaryReport:TDataSet;
n,Offset:Integer;
tmpLabel:TLabel;
RowsOfOneLine:Integer;
fDataView,fHdrView:TfrView;
begin
{ 1Inch = 25.4mm}
if FfrReport = nil then
exit;
if not Assigned(FDataFont) then
exit;
if not Assigned(frReport.Dataset) then
exit;
if not ((frReport.Dataset) is TfrDBDataset) then
exit;
if not Assigned(TfrDBDataset(frReport.Dataset).Dataset) then
exit;
aqCrossSalaryReport := TfrDBDataset(frReport.Dataset).Dataset;
if aqCrossSalaryReport.FieldCount = 0 then
exit;
fHdrView := nil;
do
cMode := dmDesigning;
if not ForDataAndHeader then
fHdrView := GetHeaderBand(0);
fDataView := GetMasterBand(0);
SetLength(FDisplayProp,aqCrossSalaryReport.FieldCount);
tmpLabel:=TLabel.Create(nil);
tmpLabel.AutoSize := True;
aqCrossSalaryReport.First;
RowsOfOneLine := 1;
//设置宽高
for n:=0 to aqCrossSalaryReport.FieldCount - 1do
begin
tmpLabel.Caption := aqCrossSalaryReport.Fields[n].DisplayLabel;
if not FAutoSize then
FDisplayProp[n].Width := Round(aqCrossSalaryReport.Fields[n].DisplayWidth * 18/5)
else
begin
tmpLabel.Font := FDataFont;
FDisplayProp[n].Width :=tmpLabel.Width + 10;
tmpLabel.Font := FHeaderFont;
if FDisplayProp[n].Width < (tmpLabel.Width + 10) then
FDisplayProp[n].Width :=tmpLabel.Width + 10;
end;
FDisplayProp[n].DisplayLabel := tmpLabel.Caption;
tmpLabel.Font := FDataFont;
if FDataRowHeight = 0 then
begin
FDisplayProp[n].Height := tmpLabel.Height + FRowSpace;
tmpLabel.Font := FHeaderFont;
if FDisplayProp[n].Height < tmpLabel.Height + 4 then
FDisplayProp[n].Height := tmpLabel.Height + 4;
end else
begin
FDisplayProp[n].Height := FDataRowHeight;
end;
end;
//调整宽度
while not aqCrossSalaryReport.Eofdo
begin
for n:=0 to aqCrossSalaryReport.FieldCount - 1do
begin
tmpLabel.Caption := aqCrossSalaryReport.Fields[n].AsString;
tmpLabel.Font := FDataFont;
if tmpLabel.Width + 10 > FDisplayProp[n].Width then
FDisplayProp[n].Width :=tmpLabel.Width + 10;
tmpLabel.Font := FHeaderFont;
if tmpLabel.Width + 10 > FDisplayProp[n].Width then
FDisplayProp[n].Width :=tmpLabel.Width + 10;
end;
aqCrossSalaryReport.Next;
end;
tmpLabel.Free;
Offset := FLeftMargin;
if ForDataAndHeader then
fDataView.Prop['Height'] := FDisplayProp[0].Height*3
else
fDataView.Prop['Height'] := FDisplayProp[0].Height;
if not ForDataAndHeader then
if FRowBreaker then
fDataView.Prop['Height'] := fDataView.Prop['Height'] + FMargin;
if fHdrView <> nil then
fHDRView.Prop['Height'] := FDisplayProp[0].Height;
//设置左、上、页索引
for n := 0 to aqCrossSalaryReport.FieldCount - 1 do
begin
if FAutoWrap then
begin
if (Offset + FDisplayProp[n].Width)> (frReport.Pages[0].Prop['Width'] - (FLeftMargin + FRightMargin)) then
begin
Offset := FDisplayProp[FWrapColumnIndex].Left;
RowsOfOneLine := RowsOfOneLine + 1;
if not FNewPage then
begin
fDataView.Prop['Height'] := FDisplayProp[0].Height * RowsOfOneLine;
if not ForDataAndHeader then
if FRowBreaker then
fDataView.Prop['Height'] := fDataView.Prop['Height'] + FMargin;
if fHdrView <> nil then
fHDRView.Prop['Height'] := FDisplayProp[0].Height * RowsOfOneLine+FMargin;
end;
end;
end;
if FNewPage then
begin
FDisplayProp[n].Top := 0;
FDisplayProp[n].PageIndex := RowsOfOneLine - 1;
end else
begin
FDisplayProp[n].Top := FDisplayProp[n].Height * (RowsOfOneLine - 1);
FDisplayProp[n].PageIndex := 0;
end;
FDisplayProp[n].Left := Offset;
Offset := Offset + FDisplayProp[n].Width;
end;
if (RowsofOneLine > 1) and FNewPage then
begin
for n:= 1 to RowsofOneLine - 1do
begin
GetMasterBand.Prop['Top'] := fDataView.Prop['Top'];
GetMasterBand.Prop['Height'] := fDataView.Prop['Height'];
GetMasterBand.Prop['Left'] := fDataView.Prop['Left'];
GetMasterBand.Prop['Width'] := fDataView.Prop['Width'];
if fHDRView <> nil then
begin
GetHeaderBand.Prop['Top'] := fHDRView.Prop['Top'];
GetHeaderBand.Prop['Height'] := fHDRView.Prop['Height'];
GetHeaderBand.Prop['Left'] := fHDRView.Prop['Left'];
GetHeaderBand.Prop['Width'] := fHDRView.Prop['Width'];
end;
end;
end;
end;
procedure TDynamicReport.SetMargin(Value: Integer);
begin
FMargin := Value;
LeftMargin := Value;
RightMargin := Value;
TopMargin := Value;
BottomMargin := Value;
end;
procedure TDynamicReport.SetWrapColumnIndex(Value: Integer);
begin
FWrapColumnIndex := Value;
end;
procedure TDynamicReport.SetAutoWrap(Value: Boolean);
begin
FAutoWrap := Value;
end;
procedure TDynamicReport.SetRowBraker(Value: Boolean);
begin
FRowBreaker := Value;
end;
procedure TDynamicReport.SetRowBreaker(const Value: Boolean);
begin
FRowBreaker := Value;
end;
procedure TDynamicReport.SetNewPage(Value: Boolean);
begin
FNewPage := Value;
end;
function TDynamicReport.GetMasterBand(PageIndex:Integer;AutoCreate:Boolean):TfrBandView;
var
fDataView:TfrView;
fPage:TfrPage;
fName:String;
bv:TfrBandView;
n:Integer;
begin
Result := nil;
do
cMode := dmDesigning;
if (frReport.Pages.Count - 1) < PageIndex then
if not AutoCreate then
exit
else
begin
while (frReport.Pages.Count - 1) < PageIndexdo
begin
frReport.Pages.Add;
frReport.Pages[frReport.Pages.Count - 1].PrintToPrevPage := True;
end;
end;
fPage := frReport.Pages[PageIndex];
SetPaperSize(FPaperSize);
SetPaperOrientation(FPaperOrientation);
fDataView := nil;
for n:=0 to fPage.Objects.Count -1do
begin
if TfrView(fPage.Objects[n]).Prop['Name']='' then
TfrView(fPage.Objects[n]).Prop['Name']:='@@@SandBoy'+IntToStr;
fName:=TfrView(fPage.Objects[n]).Prop['Name'];
fDataView := fPage.FindObject(fName);
if (fDataView is TfrBandView) and
(TfrBandView(fDataView).BandType = btMasterData) then
Break;
end;
if (fDataView = nil) or not(fDataView is TfrBandView) or
(TfrBandView(fDataView).BandType <> btMasterData)then
begin
if not AutoCreate then
exit
else
begin
bv := TfrBandView(frCreateObject(gtBand,''));
bv.BandType := btMasterData;
bv.SetBounds(300,0,758,18);
bv.Prop['Top'] := 300;
bv.Prop['datasource'] := frReport.Dataset.Name;
fPage.Objects.Add(bv);
fDataView := TfrBandView(bv);
end
end;
Result := TfrBandView(fDataView);
end;
function TDynamicReport.GetHeaderBand(PageIndex:Integer;AutoCreate:Boolean):TfrBandView;
var
fHDRView:TfrView;
fPage:TfrPage;
fName:String;
bv:TfrBandView;
n:Integer;
begin
Result := nil;
do
cMode := dmDesigning;
if (frReport.Pages.Count - 1) < PageIndex then
if not AutoCreate then
exit
else
begin
while (frReport.Pages.Count - 1) < PageIndexdo
begin
frReport.Pages.Add;
frReport.Pages[frReport.Pages.Count - 1].PrintToPrevPage := True;
SetPaperSize(FPaperSize);
SetPaperOrientation(FPaperOrientation);
end;
end;
fPage := frReport.Pages[PageIndex];
fHDRView := nil;
for n:=0 to fPage.Objects.Count -1do
begin
if TfrView(fPage.Objects[n]).Prop['Name']='' then
TfrView(fPage.Objects[n]).Prop['Name']:='@@@SandBoy'+IntToStr;
fName:=TfrView(fPage.Objects[n]).Prop['Name'];
fHDRView := fPage.FindObject(fName);
if (fHDRView is TfrBandView) and
(TfrBandView(fHDRView).BandType = btPageHeader) then
Break;
end;
if (fHDRView = nil) or not(fHDRView is TfrBandView) or
(TfrBandView(fHDRView).BandType <> btPageHeader)then
begin
if not AutoCreate then
exit
else
begin
bv := TfrBandView(frCreateObject(gtBand,''));
bv.BandType := btPageHeader;
bv.SetBounds(100,0,758,18);
bv.Prop['Top'] := 100;
fPage.Objects.Add(bv);
fHDRView := TfrBandView(bv);
end
end;
if FHeaderRowHeight <> 0 then
fHDRView.Prop['Height'] := FHeaderRowHeight;
Result := TfrBandView(fHDRView);
end;
procedure TDynamicReport.ShowReport(ColumnIndex, PageIndex: Integer);
var
i,num:integer;
begin
if frReport = nil then
exit;
ClearOldCreatedObject;
CreatePageHeader;
CreateMasterData;
if PageIndex = -1 then
begin
num := frReport.Pages.Count;
for i := 0 to num - 1do
begin
if FDisplayProp[ColumnIndex].PageIndex <> i then
begin
CopyColumn(ColumnIndex,i);
end;
end;
end else
begin
if FDisplayProp[ColumnIndex].PageIndex <> PageIndex then
CopyColumn(ColumnIndex,PageIndex);
end;
frReport.ShowReport;
end;
procedure TDynamicReport.SetBottomMargin(Value: Integer);
var
i:Integer;
begin
FBottomMargin := Value;
if Assigned(frReport) then
for i := 0 to frReport.Pages.Count - 1do
begin
frReport.Pages.Prop['BottomMargin'] := Value;
end;
end;
procedure TDynamicReport.SetLeftMargin(Value: Integer);
var
i:Integer;
begin
FLeftMargin := Value;
if FrReport <> nil then
for i := 0 to frReport.Pages.Count - 1do
begin
frReport.Pages.Prop['LeftMargin'] := Value;
end;
end;
procedure TDynamicReport.SetRightMargin(Value: Integer);
var
i:Integer;
begin
FRightMargin := Value;
if FrReport <> nil then
for i := 0 to frReport.Pages.Count - 1do
begin
frReport.Pages.Prop['RightMargin'] := Value;
end;
end;
procedure TDynamicReport.SetTopMargin(Value: Integer);
var
i:Integer;
begin
FTopMargin := Value;
if FrReport <> nil then
for i := 0 to frReport.Pages.Count - 1do
begin
frReport.Pages.Prop['TopMargin'] := Value;
end;
end;
function TDynamicReport.GetBottomMargin: Integer;
begin
Result := FBottomMargin;
if FrReport <> nil then
if frReport.Pages.Count > 0 then
Result := frReport.Pages[0].Prop['BottomMargin']
end;
function TDynamicReport.GetLeftMargin: Integer;
begin
Result := FLeftMargin;
if FrReport <> nil then
if frReport.Pages.Count > 0 then
Result := frReport.Pages[0].Prop['LeftMargin'];
end;
function TDynamicReport.GetRightMargin: Integer;
begin
Result := FRightMargin;
if FrReport <> nil then
if frReport.Pages.Count > 0 then
Result := frReport.Pages[0].Prop['RightMargin']
end;
function TDynamicReport.GetTopMargin: Integer;
begin
Result := FTopMargin;
if FrReport <> nil then
if frReport.Pages.Count > 0 then
Result := frReport.Pages[0].Prop['TopMargin']
end;
procedure TDynamicReport.SetDisplayProp(Value: TAHeaderCategory);
var
i:Integer;
begin
for i := Low(FDisplayProp) to High(FDisplayProp)do
begin
FDisplayProp.PageIndex := Value.PageIndex;
FDisplayProp.Top := Value.Top;
FDisplayProp.Left := Value.Left;
FDisplayProp.Height := Value.Height;
FDisplayProp.Width := Value.Width;
FDisplayProp.DisplayLabel := Value.DisplayLabel;
end;
end;
function TDynamicReport.GetGroupHeaderBand(PageIndex: Integer;
AutoCreate: Boolean): TfrBandView;
var
fDataView:TfrView;
fPage:TfrPage;
fName:String;
bv:TfrBandView;
n:Integer;
begin
Result := nil;
do
cMode := dmDesigning;
if (frReport.Pages.Count - 1) < PageIndex then
if not AutoCreate then
exit
else
begin
while (frReport.Pages.Count - 1) < PageIndexdo
begin
frReport.Pages.Add;
end;
end;
fPage := frReport.Pages[PageIndex];
fDataView := nil;
for n:=0 to fPage.Objects.Count -1do
begin
if TfrView(fPage.Objects[n]).Prop['Name']='' then
TfrView(fPage.Objects[n]).Prop['Name']:='@@@SandBoy'+IntToStr;
fName:=TfrView(fPage.Objects[n]).Prop['Name'];
fDataView := fPage.FindObject(fName);
if (fDataView is TfrBandView) and
(TfrBandView(fDataView).BandType = btGroupHeader) then
Break;
end;
if (fDataView = nil) or not(fDataView is TfrBandView) or
(TfrBandView(fDataView).BandType <> btGroupHeader)then
begin
if not AutoCreate then
exit
else
begin
bv := TfrBandView(frCreateObject(gtBand,''));
bv.BandType := btGroupHeader;
bv.SetBounds(200,0,758,18);
bv.Prop['Top'] := 200;
fPage.Objects.Add(bv);
fDataView := TfrBandView(bv);
end
end;
Result := TfrBandView(fDataView);
end;
function TDynamicReport.GetGroupFooterBand(PageIndex: Integer;
AutoCreate: Boolean): TfrBandView;
var
fDataView:TfrView;
fPage:TfrPage;
fName:String;
bv:TfrBandView;
n:Integer;
begin
Result := nil;
do
cMode := dmDesigning;
if (frReport.Pages.Count - 1) < PageIndex then
if not AutoCreate then
exit
else
begin
while (frReport.Pages.Count - 1) < PageIndexdo
begin
frReport.Pages.Add;
end;
end;
fPage := frReport.Pages[PageIndex];
fDataView := nil;
for n:=0 to fPage.Objects.Count -1do
begin
if TfrView(fPage.Objects[n]).Prop['Name']='' then
TfrView(fPage.Objects[n]).Prop['Name']:='@@@SandBoy'+IntToStr;
fName:=TfrView(fPage.Objects[n]).Prop['Name'];
fDataView := fPage.FindObject(fName);
if (fDataView is TfrBandView) and
(TfrBandView(fDataView).BandType = btGroupFooter) then
Break;
end;
if (fDataView = nil) or not(fDataView is TfrBandView) or
(TfrBandView(fDataView).BandType <> btGroupFooter)then
begin
if not AutoCreate then
exit
else
begin
bv := TfrBandView(frCreateObject(gtBand,''));
bv.BandType := btGroupFooter;
bv.SetBounds(400,0,758,18);
bv.Prop['Top'] := 2400;
fPage.Objects.Add(bv);
fDataView := TfrBandView(bv);
end
end;
Result := TfrBandView(fDataView);
end;
function TDynamicReport.GetMasterFooterBand(PageIndex: Integer;
AutoCreate: Boolean): TfrBandView;
var
fDataView:TfrView;
fPage:TfrPage;
fName:String;
bv:TfrBandView;
n:Integer;
begin
Result := nil;
do
cMode := dmDesigning;
if (frReport.Pages.Count - 1) < PageIndex then
if not AutoCreate then
exit
else
begin
while (frReport.Pages.Count - 1) < PageIndexdo
begin
frReport.Pages.Add;
end;
end;
fPage := frReport.Pages[PageIndex];
fDataView := nil;
for n:=0 to fPage.Objects.Count -1do
begin
if TfrView(fPage.Objects[n]).Prop['Name']='' then
TfrView(fPage.Objects[n]).Prop['Name']:='@@@SandBoy'+IntToStr;
fName:=TfrView(fPage.Objects[n]).Prop['Name'];
fDataView := fPage.FindObject(fName);
if (fDataView is TfrBandView) and
(TfrBandView(fDataView).BandType = btMasterFooter) then
Break;
end;
if (fDataView = nil) or not(fDataView is TfrBandView) or
(TfrBandView(fDataView).BandType <> btMasterFooter)then
begin
if not AutoCreate then
exit
else
begin
bv := TfrBandView(frCreateObject(gtBand,''));
bv.BandType := btMasterFooter;
bv.SetBounds(450,0,758,18);
bv.Prop['Top'] := 2400;
fPage.Objects.Add(bv);
fDataView := TfrBandView(bv);
end
end;
Result := TfrBandView(fDataView);
end;
procedure TDynamicReport.SetPaperOrientation(Value: TPrinterOrientation);
begin
// if FPaperOrientation = Value then
exit;
FPaperOrientation := Value;
SetPagesProp('ORIENTATION',FPaperOrientation);
end;
procedure TDynamicReport.SetPagesProp(PropName:String;Value: Variant);
var
i:Integer;
begin
if FfrReport = nil then
exit;
for i := 0 to FfrReport.Pages.Count - 1do
begin
FfrReport.Pages.Prop[PropName] := Value;
end;
end;
procedure TDynamicReport.SetPaperSize(Value: Integer);
begin
// if FPaperSize = Value then
exit;
FPaperSize := Value;
SetPagesProp('SIZE',FPaperSize);
end;
{ TPrinterPapersInfo }
class function TPrinterPapersInfo.PaperSizeInfo: TAPaperSizeInfo;
var
i:Integer;
PaperSizeInfo:TAPaperSizeInfo;
begin
SetLength(PaperSizeInfo,prn.PaperSizesNum);
for i := 0 to prn.PaperSizesNum - 1do
begin
PaperSizeInfo.PaperName := prn.PaperNames;
PaperSizeInfo.PaperSize := prn.PaperSizes;
end;
Result := PaperSizeInfo;
end;
class function TPrinterPapersInfo.PaperSizeNum: Integer;
begin
Result := prn.PaperSizesNum;
end;
end.