这是胜天里的,谁能写出类似的东西来:
unit PrintForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
dxDBGrid, RM_class, RM_Desgn, RM_dset, RM_dbset, dxEditor, StdCtrls,
dxCntner, dxEdLib, dxDBELib, dxTL, dxDBCtrl, ExtCtrls, dxExEdtr, RM_shape,
dxDBTL, KsControls, KsLabels, KsSkinLabels, RM_e_csv, RM_e_txt, RM_chart,
RM_PChart, RM_FormReport, Series;
const
SHOW_REPORT = 1;
PRINT_REPORT = 2;
DESIGN_REPORT = 3;
INITI_REPORT = 4;
type
TfrmPrintForm = class(TForm)
rmReport: TRMReport;
RMDesigner1: TRMDesigner;
RMDBDataSet1: TRMDBDataSet;
RMTextExport1: TRMTextExport;
RMCSVExport1: TRMCSVExport;
RMChartObject1: TRMChartObject;
private
{ Private declarations }
BandReportTitle: TRMBandView;
BandPageHeader: TRMBandView;
BandDetail: TRMBandView;
BandDetailChart: TRMBandView;
BandPageFooter: TRMBandView;
BandReportSummary: TRMBandView;
lTitleY, lGridY, lGridH: Integer;
frmForm1: TForm;
Page1: TRMPage;
sReportFile, sFile: string;
lTitle, lMode: Integer;
bPrintBar, bReturn, bNewReport: Boolean;
lPrintChartType: Integer;
sChart, sPrintChartX, sPrintChartY, sChartNameX, sChartNameY: string;
procedure PrintPrepare;
//准备打印
function Printbegin
: Boolean;
//开始打印
procedure LoadBand;
//读入页边条
procedure LoadControl(Control: TControl);
//读入Control
procedure LoadTopControl(Control: TControl);
//读入最上面Control
procedure LoadBottomControl(Control: TControl);
//读入最下面Control
procedure LoadOldControl(Control: TControl);
//读入已存在Control
procedure LoadDBGrid(Grid1: TdxDBGrid);
//读入DBGrid
procedure SetGridHeader(Grid1: TdxDBGrid);
//设置表头
procedure SetGridBody(Grid1: TdxDBGrid);
//设置表体
procedure SetGridSummary(Grid1: TdxDBGrid);
//设置表尾
procedure LoadDBTree(Tree1: TdxDBTreeList);
//读入DBTree
procedure SetTreeHeader(Tree1: TdxDBTreeList);
//设置表头
procedure SetTreeBody(Tree1: TdxDBTreeList);
//设置表体
procedure SetTreeSummary(Tree1: TdxDBTreeList);
//设置表尾
function LoadReportFile: Boolean;
//读报表文件
function SaveReportFile: boolean;
//写报表文件
procedure SetTitle;
//设置标题
function GetAlignment(Align: TAlignment): TRMAlignment;
function GetBandSub(Grid1: TCustomdxDBTreeListControl;
Index: Integer):
Integer;
function ViewAssign(m1: TRMMemoView;
Control: TControl): Boolean;
//为各种控件赋值
function ShapeViewAssign(s1: TRMShapeView;
Control: TControl): Boolean;
//为各种Shape控件赋值
function PicViewAssign(p1: TRMPictureView;
Control: TControl): Boolean;
//为各种图象控件赋值
function GetPoint(Control: TControl): TPoint;
procedure SetChart;
public
{ Public declarations }
end;
function WinPrint(Form1: TForm;
lTitle1, lMode1: Integer;
sFile1, sChart1:
string): Boolean;
{
参数( 要打印Form;标题类型(0=空,1=中间,2=左边);打印类型(显示,打印,编辑,初始化);文件ID )
打印类型(显示=SHOW_REPORT,打印=PRINT_REPORT,编辑=DESIGN_REPORT,初始化=INITI_REPORT)
}
implementation
uses SysPublic;
{$R *.DFM}
const
C_LEFT = 20;
C_HEIGHT = 20;
function WinPrint(Form1: TForm;
lTitle1, lMode1: Integer;
sFile1, sChart1:
string): Boolean;
var
frmPrintForm: TfrmPrintForm;
begin
frmPrintForm := TfrmPrintForm.Create(Application);
with frmPrintFormdo
begin
frmForm1 := Form1;
lMode := lMode1;
lTitle := lTitle1;
sFile := sFile1;
sChart := sChart1;
PrintPrepare;
Printbegin
;
Result := bReturn;
{Free;}
end;
end;
procedure TfrmPrintForm.PrintPrepare;
var
i: Integer;
begin
lPrintChartType := -1;
sPrintChartX := '';
sPrintChartY := '';
sChartNameX := '';
sChartNameY := '';
lPrintChartType := StrToInt2(GetCommaStr(sChart, 1));
sPrintChartX := GetCommaStr(sChart, 2);
sPrintChartY := GetCommaStr(sChart, 3);
if (sPrintChartX = '') or (sPrintChartY = '') then
lPrintChartType := -1;
//不是图形
if lPrintChartType >= 0 then
bNewReport := True;
LoadReportFile;
LoadBand;
SetTitle;
with frmForm1do
begin
for i := 0 to ComponentCount - 1do
begin
if (TControl(Components).Visible) and (Components is
TCustomdxTreeList) then
begin
lGridY := GetPoint(TControl(Components)).Y;
lGridH := TdxDBGrid(Components).RowHeight;
end;
end;
for i := 0 to ComponentCount - 1do
if (TControl(Components).Visible) and (Components is TControl) then
begin
if bNewReport then
LoadTopControl(TControl(Components))
else
LoadOldControl(TControl(Components));
end;
for i := 0 to ComponentCount - 1do
if (TControl(Components).Visible) and (Components is TdxDBGrid) then
LoadDBGrid(TdxDBGrid(Components));
for i := 0 to ComponentCount - 1do
if (TControl(Components).Visible) and (Components is TdxDBTreeList)
then
LoadDBTree(TdxDBTreeList(Components));
for i := 0 to ComponentCount - 1do
begin
if (TControl(Components).Visible) and (Components is TControl) then
begin
if bNewReport then
LoadBottomControl(TControl(Components))
else
LoadOldControl(TControl(Components));
end;
end;
if bNewReport then
for i := 0 to ComponentCount - 1do
begin
if (sChartNameX <> '') and (sChartNameY <> '') then
begin
SetChart;
Break;
end;
end;
end;
end;
procedure TfrmPrintForm.SetChart;
var
lBY, lBH: Integer;
cv: TRMChartView;
begin
//饼图
BandPageHeader.Visible := False;
BandDetail.dy := 0;
BandReportSummary.Visible := False;
lBY := BandReportSummary.y + BandReportSummary.dy + C_HEIGHT;
lBH := 300;
BandDetailChart := TRMBandView(RMCreateObject(gtBand, ''));
BandDetailChart.BandType := btMasterData;
BandDetailChart.Name := 'BandDetailChart';
Page1.Objects.Add(BandDetailChart);
BandDetailChart.SetBounds(0, lBY, 0, lBH);
cv := TRMChartView.Create;
cv.Name := 'ChartView';
cv.SetBounds(C_LEFT, lBy + C_HEIGHT, 600, lBH - C_HEIGHT);
cv.AddSeries;
cv.Series[0].ChartOptions.ShowMarks := True;
cv.Series[0].ChartOptions.Colored := True;
cv.Series[0].ChartOptions.ChartType := lPrintChartType;
cv.Series[0].ChartOptions.MarksStyle := 3;
cv.Series[0].LegendObj := sChartNameX;
cv.Series[0].ValueObj := sChartNameY;
Page1.Objects.Add(cv);
end;
function TfrmPrintForm.Printbegin
: Boolean;
begin
Result := True;
case lMode of
SHOW_REPORT: rmReport.ShowReport;
PRINT_REPORT: rmReport.PrintReport;
DESIGN_REPORT: rmReport.DesignReport;
INITI_REPORT: rmReport.DesignReport;
else
Result := False;
end;
if Result <> False then
SaveReportFile;
end;
procedure TfrmPrintForm.LoadBand;
begin
if bNewReport then
begin
rmReport.Pages.Clear;
rmReport.Pages.Add;
Page1 := rmReport.Pages[0];
BandReportTitle := TRMBandView(RMCreateObject(gtBand, ''));
BandReportTitle.BandType := btReportTitle;
BandReportTitle.Name := 'BandReportTitle';
BandReportTitle.SetBounds(0, C_HEIGHT, 0, 0);
Page1.Objects.Add(BandReportTitle);
BandPageHeader := TRMBandView(RMCreateObject(gtBand, ''));
BandPageHeader.BandType := btPageHeader;
BandPageHeader.Name := 'BandPageHeader';
Page1.Objects.Add(BandPageHeader);
BandPageHeader.SetBounds(0, C_HEIGHT * 2, 0, 0);
BandDetail := TRMBandView(RMCreateObject(gtBand, ''));
BandDetail.BandType := btMasterData;
BandDetail.Name := 'BandDetail';
Page1.Objects.Add(BandDetail);
BandDetail.SetBounds(0, C_HEIGHT * 3, 0, 0);
BandPageFooter := TRMBandView(RMCreateObject(gtBand, ''));
BandPageFooter.BandType := btPageFooter;
BandPageFooter.Name := 'BandPageFooter';
Page1.Objects.Add(BandPageFooter);
BandPageFooter.SetBounds(0, C_HEIGHT * 4, 0, 0);
BandReportSummary := TRMBandView(RMCreateObject(gtBand, ''));
BandReportSummary.BandType := btReportSummary;
BandReportSummary.Name := 'BandReportSummary';
Page1.Objects.Add(BandReportSummary);
BandReportSummary.SetBounds(0, C_HEIGHT * 5, 0, 0);
end
else
begin
Page1 := rmReport.Pages[0];
BandReportTitle := TRMBandView(page1.FindObject('BandReportTitle'));
BandPageHeader := TRMBandView(page1.FindObject('BandPageHeader'));
BandDetail := TRMBandView(page1.FindObject('BandDetail'));
BandPageFooter := TRMBandView(page1.FindObject('BandPageFooter'));
BandReportSummary := TRMBandView(page1.FindObject('BandReportSummary'));
end;
end;
function TfrmPrintForm.LoadReportFile: Boolean;
var
sDir: string;
begin
Result := True;
bNewReport := False;
sReportFile := '';
sDir := Trim(ExtractFilePath(Application.ExeName)) + 'Report';
if not DirectoryExists(sDir) then
begin
if not CreateDir(sDir) then
begin
raise Exception.Create('不能新建目录,请手工新建这目录。' + #13 + sDir);
Result := false;
end;
end;
if Result <> False then
begin
if lPrintChartType = -1 then
sReportFile := sDir + '/' + sFile + '.Rep'
else
sReportFile := sDir + '/' + sFile + '图形.Rep';
end;
if (not FileExists(sReportFile)) or (lMode = INITI_REPORT) then
bNewReport := True
else
if not rmReport.LoadFromFile(sReportFile) then
bNewReport := True;
rmReport.FileName := sReportFile;
end;
function TfrmPrintForm.SaveReportFile: Boolean;
begin
Result := True;
if lPrintChartType >= 0 then
Exit;
if (sReportFile <> '') and bNewReport then
rmReport.SaveToFile(sReportFile);
if not FileExists(sReportFile) then
Result := False;
end;
procedure TfrmPrintForm.SetTitle;
var
mt: TRMMemoView;
Font: TFont;
begin
if not bNewReport then
exit;
mt := TRMMemoView(RMCreateObject(gtMemo, ''));
mt.gapx := 0;
mt.gapy := 0;
mt.dx := 0;
lTitleY := C_HEIGHT;
lGridY := 0;
if lTitle > 0 then
begin
Font := TFont.Create;
Font.Name := '宋体';
Font.Size := 22;
Font.Charset := GB2312_CHARSET;
Font.Style := [fsBold];
mt.Font.Assign(Font);
if lTitle = 1 then
mt.PAlignment := rmtaCenterJustify
else
if lTitle = 2 then
mt.PAlignment := rmtaLeftJustify;
mt.Memo.Add(frmForm1.Caption);
mt.SetBounds(C_LEFT, C_HEIGHT, frmForm1.Width, 40);
mt.Name := 'TiTtle' + frmForm1.Name;
Page1.Objects.Add(mt);
BandReportTitle.y := C_HEIGHT;
BandReportTitle.dy := 40;
lTitleY := BandReportTitle.dy + C_HEIGHT;
end
end;
procedure TfrmPrintForm.LoadControl(Control: TControl);
var
m: TRMMemoView;
p: TRMPictureView;
s: TRMShapeView;
begin
if Control.Parent.Visible = False then
exit;
if (Control is TImage) or (Control is TdxGraphicEdit) or (Control is
TdxDBGraphicEdit) then
begin
p := TRMPictureView(RMCreateObject(gtPicture, ''));
p.gapx := 0;
p.gapy := 0;
p.dx := 0;
p.SetBounds(GetPoint(Control).x + C_LEFT, GetPoint(Control).y + lTitleY,
Control.Width, Control.Height);
if not PicViewAssign(p, Control) then
exit;
p.Name := Control.Name;
Page1.Objects.Add(p);
if (BandReportTitle.dy < (p.y + p.dy)) and (p.y < (lGridY + lTitleY)) then
BandReportTitle.dy := p.y + p.dy;
if p.y > (lGridY + lTitleY) then
begin
p.y := BandReportSummary.y + lGridH + 8;
if (BandReportSummary.dy < (p.y - BandReportSummary.y + p.dy)) then
BandReportSummary.dy := (p.y - BandReportSummary.y + p.dy);
end;
end
else
if (Control is TShape) then
begin
s := TRMShapeView(RMCreateObject(gtAddin, 'TRMShapeView'));
s.gapx := 0;
s.gapy := 0;
s.dx := 0;
s.SetBounds(GetPoint(Control).x + C_LEFT, GetPoint(Control).y + lTitleY,
Control.Width, Control.Height);
if not ShapeViewAssign(s, Control) then
exit;
s.Name := Control.Name;
Page1.Objects.Add(s);
if (BandReportTitle.dy < (s.y + s.dy)) and (s.y < (lGridY + lTitleY)) then
BandReportTitle.dy := s.y + s.dy;
if s.y > (lGridY + lTitleY) then
begin
s.y := BandReportSummary.y + lGridH + 8;
if (BandReportSummary.dy < (s.y - BandReportSummary.y + s.dy)) then
BandReportSummary.dy := (s.y - BandReportSummary.y + s.dy);
end;
end
else
begin
m := TRMMemoView(RMCreateObject(gtMemo, ''));
m.gapx := 0;
m.gapy := 0;
m.dx := 0;
m.SetBounds(GetPoint(Control).x + C_LEFT, GetPoint(Control).y + lTitleY,
Control.Width, Control.Height);
if not ViewAssign(m, Control) then
exit;
m.Name := Control.Name;
Page1.Objects.Add(m);
if (BandReportTitle.dy < (m.y + m.dy)) and (m.y < (lGridY + lTitleY)) then
BandReportTitle.dy := m.y + m.dy;
if m.y > (lGridY + lTitleY) then
begin
m.y := BandReportSummary.y + lGridH + 8;
if (BandReportSummary.dy < (m.y - BandReportSummary.y + m.dy)) then
BandReportSummary.dy := (m.y - BandReportSummary.y + m.dy);
end;
end;
end;
procedure TfrmPrintForm.LoadTopControl(Control: TControl);
//读入最上面Control
begin
BandReportSummary.y := BandReportTitle.y + BandReportTitle.dy + C_HEIGHT * 4;
if GetPoint(Control).y <= lGridY then
LoadControl(Control);
end;
procedure TfrmPrintForm.LoadBottomControl(Control: TControl);
//读入最下面Control
begin
if GetPoint(Control).y >= lGridY then
LoadControl(Control);
end;
procedure TfrmPrintForm.LoadOldControl(Control: TControl);
var
v: TRMView;
begin
v := Page1.FindObject(Control.Name);
if v = nil then
exit;
if (Control is TImage) or (Control is TdxGraphicEdit) or (Control is
TdxDBGraphicEdit) then
begin
if not PicViewAssign(TRMPictureView(v), Control) then
exit;
end
else
if (Control is TShape) then
begin
if not ShapeViewAssign(TRMShapeView(Page1.FindObject(Control.Name)), Control)
then
exit;
end
else
begin
if not ViewAssign(TRMMemoView(Page1.FindObject(Control.Name)), Control) then
exit;
end;
end;
function TfrmPrintForm.GetBandSub(Grid1: TCustomdxDBTreeListControl;
Index:
Integer): Integer;
var
i, j: Integer;
begin
j := 0;
for i := 0 to Grid1.ColumnCount - 1do
if Grid1.Columns.Visible and (Grid1.Columns.BandIndex = Index) then
inc(j);
Result := j;
end;
procedure TfrmPrintForm.LoadDBGrid(Grid1: TdxDBGrid);
begin
if (Grid1 = nil) or (Grid1.Datasource = nil) or (Grid1.Datasource.Dataset =
nil) then
Exit;
if not Grid1.Datasource.Dataset.Active then
Exit;
RMDBDataSet1.DataSource := Grid1.DataSource;
rmReport.DataSet := RMDBDataSet1;
if Grid1.Tag = 5 then
bPrintBar := True
else
bPrintBar := False;
SetGridHeader(Grid1);
//表头
SetGridBody(Grid1);
//表体
SetGridSummary(Grid1);
//表尾
end;
procedure TfrmPrintForm.SetGridHeader(Grid1: TdxDBGrid);
var
x, i: Integer;
m: TRMMemoView;
begin
if bNewReport then
BandPageHeader.y := BandReportTitle.y + BandReportTitle.dy + C_HEIGHT;
if Grid1.ShowBands then
//表头1
begin
x := C_LEFT;
if bNewReport then
BandPageHeader.dy := BandPageHeader.dy + Grid1.RowHeight + 4;
if bNewReport and bPrintBar then
BandPageHeader.dy := 0;
//打印成条行表
for i := 0 to Grid1.Bands.Count - 1do
begin
if not Grid1.Bands.Visible then
Continue;
m := TRMMemoView(RMCreateObject(gtMemo, ''));
m.SetBounds(x, BandPageHeader.y, Grid1.Bands.Width +
GetBandSub(Grid1, Grid1.Bands.Index), Grid1.RowHeight + 4);
m.Font.Assign(Grid1.BandFont);
m.Memo.Text := Grid1.Bands.Caption;
m.PLayout := rmtlCenter;
m.PAlignment := GetAlignment(Grid1.Bands.Alignment);
m.FillColor := Grid1.Color;
if Grid1.ShowGrid then
m.Prop['FrameTyp'] := $F;
m.Name := 'Grid_Band_' + IntToStr(i);
if Page1.FindObject(m.Name) <> nil then
Page1.FindObject(m.Name).Assign(m)
else
Page1.Objects.Add(m);
x := x + Grid1.Bands.Width + GetBandSub(Grid1, Grid1.Bands.Index);
end;
end;
if Grid1.ShowHeader then
//表头2
begin
x := C_LEFT;
if bNewReport then
BandPageHeader.dy := BandPageHeader.dy + Grid1.RowHeight + 4;
if bNewReport and bPrintBar then
BandPageHeader.dy := 0;
//打印成条行表
for i := 0 to Grid1.ColumnCount - 1do
begin
if not Grid1.Columns.Visible then
Continue;
if (Grid1.Columns.Field = nil) and (Grid1.Columns.Visible = false)
then
Continue;
m := TRMMemoView(RMCreateObject(gtMemo, ''));
if Grid1.ShowBands then
m.SetBounds(x, BandPageHeader.y + Grid1.RowHeight + 4,
Grid1.Columns.Width + 1, Grid1.RowHeight + 4)
else
m.SetBounds(x, BandPageHeader.y, Grid1.Columns.Width + 1,
Grid1.RowHeight + 4);
m.Font.Assign(Grid1.Columns.Font);
m.Memo.Text := Grid1.Columns.Caption;
m.PLayout := rmtlCenter;
m.PAlignment := GetAlignment(Grid1.Columns.Alignment);
m.FillColor := Grid1.Color;
if Grid1.ShowGrid then
m.Prop['FrameTyp'] := $F;
m.Name := 'Row0' + Grid1.Columns.Name;
if Page1.FindObject(m.Name) <> nil then
Page1.FindObject(m.Name).Assign(m)
else
Page1.Objects.Add(m);
x := x + Grid1.Columns.Width + 1;
end;
end;
end;
procedure TfrmPrintForm.SetGridBody(Grid1: TdxDBGrid);
var
x, i: Integer;
v: TRMView;
begin
//画出表体
if bNewReport then
BandDetail.y := BandPageHeader.y + BandPageHeader.dy + C_HEIGHT;
if bNewReport then
BandDetail.dy := Grid1.RowHeight + 4;
x := C_LEFT;
for i := 0 to Grid1.ColumnCount - 1do
begin
if not Grid1.Columns.Visible then
Continue;
if (Grid1.Columns.Field = nil) and (Grid1.Columns.Visible = false)
then
Continue;
v := RMCreateObject(gtMemo, '');
v.SetBounds(x, BandDetail.y, Grid1.Columns.Width + 1, BandDetail.Dy);
if not bNewReport and bPrintBar then
v.SetBounds(x, BandDetail.y + Grid1.RowHeight + 4, Grid1.Columns.Width + 1, Grid1.RowHeight + 4)
else
v.SetBounds(x, BandDetail.y, Grid1.Columns.Width + 1, BandDetail.Dy);
TRMMemoView(v).PAlignment := GetAlignment(Grid1.Columns.Alignment);
if Grid1.ShowGrid then
v.Prop['FrameTyp'] := $F;
TRMMemoView(v).Font.Assign(Grid1.Columns.Font);
//设置数据字段
v.Memo.Text := Format('[%s.%s."%s"]', [Grid1.DataSource.DataSet.Owner.Name,
Grid1.DataSource.DataSet.Name, Grid1.Columns.FieldName]);
v.FillColor := Grid1.Color;
v.Name := 'Row1' + Grid1.Columns.Name;
//画饼图
if Grid1.Columns.FieldName = sPrintChartX then
sChartNameX := v.Name
else
if Grid1.Columns.FieldName = sPrintChartY then
sChartNameY := v.Name;
if lPrintChartType >= 0 then
//如果是图形
begin
v.dy := 0;
v.Visible := False;
end;
if Page1.FindObject(v.Name) <> nil then
Page1.FindObject(v.Name).Assign(v)
else
Page1.Objects.Add(v);
x := x + Grid1.Columns.Width + 1;
end;
if bNewReport and bPrintBar then
BandDetail.y := BandPageHeader.y;
//打印成条行表
if bNewReport and bPrintBar then
BandDetail.dy := Grid1.RowHeight * 3 + 12;
//打印成条行表
end;
procedure TfrmPrintForm.SetGridSummary(Grid1: TdxDBGrid);
//表尾
var
x, i: Integer;
m: TRMMemoView;
begin
if bNewReport then
BandPageFooter.y := BandDetail.y + BandDetail.dy + C_HEIGHT;
if bNewReport then
BandPageFooter.dy := 0;
if bNewReport then
BandReportSummary.y := BandPageFooter.y + BandPageFooter.dy + C_HEIGHT;
if bNewReport then
BandReportSummary.dy := BandReportSummary.dy + Grid1.RowHeight + 4;
x := C_LEFT;
if Grid1.ShowSummaryFooter then
begin
for i := 0 to Grid1.ColumnCount - 1do
begin
if not Grid1.Columns.Visible then
Continue;
if (Grid1.Columns.Field = nil) and (Grid1.Columns.Visible = false)
then
Continue;
m := TRMMemoView(RMCreateObject(gtMemo, ''));
m.SetBounds(x, BandReportSummary.y, Grid1.Columns.Width + 1,
Grid1.RowHeight + 4);
m.PAlignment := GetAlignment(Grid1.Columns.Alignment);
if Grid1.ShowGrid then
m.Prop['FrameTyp'] := $F;
m.Font.Assign(Grid1.Columns.Font);
m.Memo.Text := Grid1.Columns.SummaryFooterText;
m.FillColor := Grid1.Color;
m.Name := 'Summary' + Grid1.Columns.Name;
if Page1.FindObject(m.Name) <> nil then
Page1.FindObject(m.Name).Assign(m)
else
Page1.Objects.Add(m);
x := x + Grid1.Columns.Width + 1;
end;
end;
end;
procedure TfrmPrintForm.LoadDBTree(Tree1: TdxDBTreeList);
begin
if (Tree1 = nil) or (Tree1.Datasource = nil) or (Tree1.Datasource.Dataset =
nil) then
Exit;
if not Tree1.Datasource.Dataset.Active then
Exit;
RMDBDataSet1.DataSource := Tree1.DataSource;
rmReport.DataSet := RMDBDataSet1;
if Tree1.Tag = 5 then
bPrintBar := True
else
bPrintBar := False;
SetTreeHeader(Tree1);
//表头
SetTreeBody(Tree1);
//表体
SetTreeSummary(Tree1);
//表尾
end;
procedure TfrmPrintForm.SetTreeHeader(Tree1: TdxDBTreeList);
var
x, i: Integer;
m: TRMMemoView;
begin
if bNewReport then
BandPageHeader.y := BandReportTitle.y + BandReportTitle.dy + C_HEIGHT;
if Tree1.ShowBands then
//表头1
begin
x := C_LEFT;
if bNewReport then
BandPageHeader.dy := BandPageHeader.dy + Tree1.RowHeight + 4;
if bNewReport and bPrintBar then
BandPageHeader.dy := 0;
//打印成条行表
for i := 0 to Tree1.Bands.Count - 1do
begin
if not Tree1.Bands.Visible then
Continue;
m := TRMMemoView(RMCreateObject(gtMemo, ''));
m.SetBounds(x, BandPageHeader.y, Tree1.Bands.Width +
GetBandSub(Tree1, Tree1.Bands.Index), Tree1.RowHeight + 4);
m.Font.Assign(Tree1.BandFont);
m.Memo.Text := Tree1.Bands.Caption;
m.PLayout := rmtlCenter;
m.PAlignment := GetAlignment(Tree1.Bands.Alignment);
m.FillColor := Tree1.Color;
// if Tree1.ShowGrid then
m.FrameTyp := $F;
m.Prop['FrameTyp'] := $F;
m.Name := 'Grid_Band_' + IntToStr(i);
if Page1.FindObject(m.Name) <> nil then
Page1.FindObject(m.Name).Assign(m)
else
Page1.Objects.Add(m);
x := x + Tree1.Bands.Width + GetBandSub(Tree1, Tree1.Bands.Index);
end;
end;
if Tree1.ShowHeader then
//表头2
begin
x := C_LEFT;
if bNewReport then
BandPageHeader.dy := BandPageHeader.dy + Tree1.RowHeight + 4;
if bNewReport and bPrintBar then
BandPageHeader.dy := 0;
//打印成条行表
for i := 0 to Tree1.ColumnCount - 1do
begin
if not Tree1.Columns.Visible then
Continue;
if (Tree1.Columns.Field = nil) and (Tree1.Columns.Visible = false)
then
Continue;
m := TRMMemoView(RMCreateObject(gtMemo, ''));
if Tree1.ShowBands then
m.SetBounds(x, BandPageHeader.y + Tree1.RowHeight + 4,
Tree1.Columns.Width + 1, Tree1.RowHeight + 4)
else
m.SetBounds(x, BandPageHeader.y, Tree1.Columns.Width + 1,
Tree1.RowHeight + 4);
m.Font.Assign(Tree1.Columns.Font);
m.Memo.Text := Tree1.Columns.Caption;
m.PLayout := rmtlCenter;
m.PAlignment := GetAlignment(Tree1.Columns.Alignment);
m.FillColor := Tree1.Color;
m.Prop['FrameTyp'] := $F;
m.Name := 'Row0' + Tree1.Columns.Name;
if Page1.FindObject(m.Name) <> nil then
Page1.FindObject(m.Name).Assign(m)
else
Page1.Objects.Add(m);
x := x + Tree1.Columns.Width + 1;
end;
end;
end;
procedure TfrmPrintForm.SetTreeBody(Tree1: TdxDBTreeList);
var
x, i: Integer;
v: TRMView;
begin
//画出表体
if bNewReport then
BandDetail.y := BandPageHeader.y + BandPageHeader.dy + C_HEIGHT;
if bNewReport then
BandDetail.dy := Tree1.RowHeight + 4;
x := C_LEFT;
for i := 0 to Tree1.ColumnCount - 1do
begin
if not Tree1.Columns.Visible then
Continue;
if (Tree1.Columns.Field = nil) and (Tree1.Columns.Visible = false)
then
Continue;
v := RMCreateObject(gtMemo, '');
if not bNewReport and bPrintBar then
v.SetBounds(x, BandDetail.y + Tree1.RowHeight + 4, Tree1.Columns.Width + 1, Tree1.RowHeight + 4)
else
v.SetBounds(x, BandDetail.y, Tree1.Columns.Width + 1, BandDetail.Dy);
TRMMemoView(v).PAlignment := GetAlignment(Tree1.Columns.Alignment);
if Tree1.ShowGrid then
v.Prop['FrameTyp'] := $F;
v.Prop['FrameTyp'] := $F;
TRMMemoView(v).Font.Assign(Tree1.Columns.Font);
//设置数据字段
v.Memo.Text := Format('[%s.%s."%s"]', [Tree1.DataSource.DataSet.Owner.Name,
Tree1.DataSource.DataSet.Name, Tree1.Columns.FieldName]);
v.FillColor := Tree1.Color;
v.Name := 'Row1' + Tree1.Columns.Name;
//画饼图
if Tree1.Columns.FieldName = sPrintChartX then
sChartNameX := v.Name
else
if Tree1.Columns.FieldName = sPrintChartY then
sChartNameY := v.Name;
if lPrintChartType >= 0 then
//如果是图形
begin
v.dy := 0;
v.Visible := False;
end;
if Page1.FindObject(v.Name) <> nil then
Page1.FindObject(v.Name).Assign(v)
else
Page1.Objects.Add(v);
x := x + Tree1.Columns.Width + 1;
end;
if bNewReport and bPrintBar then
BandDetail.y := BandPageHeader.y;
//打印成条行表
if bNewReport and bPrintBar then
BandDetail.dy := Tree1.RowHeight * 3 + 12;
//打印成条行表
end;
procedure TfrmPrintForm.SetTreeSummary(Tree1: TdxDBTreeList);
//表尾
var
x, i: Integer;
m: TRMMemoView;
begin
if bNewReport then
BandPageFooter.y := BandDetail.y + BandDetail.dy + C_HEIGHT;
if bNewReport then
BandPageFooter.dy := 0;
if bNewReport then
BandReportSummary.y := BandPageFooter.y + BandPageFooter.dy + C_HEIGHT;
if bNewReport then
BandReportSummary.dy := BandReportSummary.dy + Tree1.RowHeight + 4;
x := C_LEFT;
if Tree1.ShowFooter then
begin
for i := 0 to Tree1.ColumnCount - 1do
begin
if not Tree1.Columns.Visible then
Continue;
if (Tree1.Columns.Field = nil) and (Tree1.Columns.Visible = false)
then
Continue;
m := TRMMemoView(RMCreateObject(gtMemo, ''));
m.SetBounds(x, BandReportSummary.y, Tree1.Columns.Width + 1,
Tree1.RowHeight + 4);
m.PAlignment := GetAlignment(Tree1.Columns.Alignment);
if Tree1.ShowGrid then
m.Prop['FrameTyp'] := $F;
m.Prop['FrameTyp'] := $F;
m.Font.Assign(Tree1.Columns.Font);
m.Memo.Text := Tree1.Columns.SummaryFooterText;// .SummaryFooterFormat;
m.FillColor := Tree1.Color;
m.Name := 'Summary' + Tree1.Columns.Name;
if Page1.FindObject(m.Name) <> nil then
Page1.FindObject(m.Name).Assign(m)
else
Page1.Objects.Add(m);
x := x + Tree1.Columns.Width + 1;
end;
end;
end;
function TfrmPrintForm.GetPoint(Control: TControl): TPoint;
var
Point: TPoint;
begin
Point.x := 0;
Point.y := 0;
Point := Control.ClientToScreen(point);
Point := frmForm1.ScreenToClient(Point);
Result := Point;
end;
function TfrmPrintForm.GetAlignment(Align: TAlignment): TRMAlignment;
begin
case Align of
taLeftJustify: Result := rmtaLeftJustify;
taRightJustify: Result := rmtaRightJustify;
taCenter: Result := rmtaCenterJustify;
else
Result := rmtaLeftJustify;
end;
end;
function TfrmPrintForm.ViewAssign(m1: TRMMemoView;
Control: TControl): Boolean;
begin
Result := true;
if Control is TSeSkinLabel then
begin
//标准控件
m1.Font.Assign(TSeSkinLabel(Control).Font);
m1.Memo.Text := TSeSkinLabel(Control).Caption;
end
else
if Control is TCustomEdit then
begin
m1.Font.Assign(TEdit(Control).Font);
m1.Memo.Text := TEdit(Control).Text;
end
else
if Control is TCustomMemo then
begin
m1.Font.Assign(TMemo(Control).Font);
m1.Memo.Assign(TMemo(Control).Lines);
end
else
if Control is TCustomdxEdit then
begin
//Express No DB
m1.Font.Assign(TdxEdit(Control).Font);
m1.Memo.Text := TdxEdit(Control).Text;
end
else
if Control is TCustomdxDateEdit then
begin
m1.Font.Assign(TdxDateEdit(Control).Font);
m1.Memo.Text := TdxDateEdit(Control).Text;
end
else
if Control is TCustomdxPickEdit then
begin
m1.Font.Assign(TdxPickEdit(Control).Font);
m1.Memo.Text := TdxPickEdit(Control).Text;
end
else
if Control is TdxButtonEdit then
begin
m1.Font.Assign(TdxButtonEdit(Control).Font);
m1.Memo.Text := TCustomdxButtonEdit(Control).Text;
end
else
if Control is TCustomdxDBEdit then
begin
//Express is DB
m1.Font.Assign(TdxDBEdit(Control).Font);
m1.Memo.Text := TdxDBEdit(Control).Text;
end
else
if Control is TCustomdxDBDateEdit then
begin
m1.Font.Assign(TdxDBDateEdit(Control).Font);
m1.Memo.Text := TdxDBDateEdit(Control).Text;
end
else
if Control is TCustomdxDBPickEdit then
begin
m1.Font.Assign(TdxDBPickEdit(Control).Font);
m1.Memo.Text := TdxDBPickEdit(Control).Text;
end
else
if Control is TdxDBButtonEdit then
begin
m1.Font.Assign(TdxDBButtonEdit(Control).Font);
m1.Memo.Text := TCustomdxDBButtonEdit(Control).Text;
end
else
if Control is TdxInplaceTextEdit then
begin
m1.Font.Assign(frmForm1.Font);
m1.Memo.Text := TdxInplaceTextEdit(Control).Text;
end
else
Result := false;
end;
function TfrmPrintForm.ShapeViewAssign(s1: TRMShapeView;
Control: TControl):
Boolean;
begin
Result := True;
if Control is TShape then
begin
case TShape(Control).Shape of
stRectangle: s1.ShapeType := rmskRectangle;
stSquare: s1.ShapeType := rmskRectangle;
stRoundRect: s1.ShapeType := rmskRectangle;
stRoundSquare: s1.ShapeType := rmskRectangle;
stEllipse: s1.ShapeType := rmskRectangle;
stCircle: s1.ShapeType := rmskRectangle;
end;
s1.FillColor := TShape(Control).Brush.Color;
s1.dx := TShape(Control).Pen.Width;
s1.FillColor := TShape(Control).Pen.Color;
s1.PenMode := TShape(Control).Pen.Mode;
end
else
Result := false;
end;
function TfrmPrintForm.PicViewAssign(p1: TRMPictureView;
Control: TControl):
Boolean;
begin
Result := True;
if Control is TImage then
begin
if TImage(Control).Picture.Graphic <> nil then
p1.Picture.Assign(TImage(Control).Picture);
p1.Flags := (p1.Flags and not flPictCenter) + Word(TImage(Control).Center) *
flPictCenter;
p1.Flags := (p1.Flags and not flStretched) + Word(TImage(Control).Stretch) *
flStretched;
p1.Flags := (p1.Flags and not flPictRatio) + Word(0) * flPictRatio;
end
else
if Control is TdxGraphicEdit then
begin
if TdxGraphicEdit(Control).Picture.Graphic <> nil then
p1.Picture.Assign(TdxGraphicEdit(Control).Picture);
p1.Flags := (p1.Flags and not flPictCenter) +
Word(TdxGraphicEdit(Control).Center) * flPictCenter;
p1.Flags := (p1.Flags and not flStretched) +
Word(TdxGraphicEdit(Control).Stretch) * flStretched;
p1.Flags := (p1.Flags and not flPictRatio) + Word(0) * flPictRatio;
end
else
if Control is TdxDBGraphicEdit then
begin
if TdxDBGraphicEdit(Control).Picture.Graphic <> nil then
p1.Picture.Assign(TdxDBGraphicEdit(Control).Picture);
p1.Flags := (p1.Flags and not flPictCenter) +
Word(TdxDBGraphicEdit(Control).Center) * flPictCenter;
p1.Flags := (p1.Flags and not flStretched) +
Word(TdxDBGraphicEdit(Control).Stretch) * flStretched;
p1.Flags := (p1.Flags and not flPictRatio) + Word(0) * flPictRatio;
end
else
Result := false;
end;
end.