📄 publicfuncion.~pas
字号:
unit PublicFuncion;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, ExtCtrls,
StdCtrls, FR_View, ComCtrls, FR_DSet, FR_DBSet,Printers,
FR_Class,fr_shape,db;
procedure RefrestReport(app:Tapplication;frReport: TfrReport;frDs:TfrDBDataSet;sCaption,sPrintPeaple:pchar;sFlagTableName:pchar);
implementation
uses CommUseFunctionExport, messageRegister;
procedure RefrestReport(app:Tapplication;frReport: TfrReport;frDs:TfrDBDataSet;sCaption,sPrintPeaple:pchar;sFlagTableName:pchar);
var
v: TfrView;
b,MasterDate1: TfrBandView;
Page: TfrPage;
sShape:TFrShapeView;
i,iLeft,iTop,iWidth,iHeight,iRight,iFitColumn,iFontSize:integer;
sFieldName,iniFileName:string;
sPageOrient,sHide,
sWidth,sAlign,sSumType:string;
sLeftSize,sRightSize,sPageFontName:string;
iPageWidth,iPageHeight,iFootCount,iFootWidth:integer;
sFootName,sTemp:string;
begin
application:=app;
frmmessageRegister:=TfrmmessageRegister.Create(application);
frmmessageRegister.Show;
application.ProcessMessages;
iniFileName:=ExtractFilePath(application.ExeName)+'ReportSetup.ini';
spageOrient:=readini(inifilename,sFlagTableName,'PageOrient','纵向'); // 页方向
sLeftSize:=readini(inifilename,sFlagTableName,'LeftSize','10'); // 右边距
sRightSize:=readini(inifilename,sFlagTableName,'RightSize','10'); // 左边距
iFontSize:=strtoint(readini(inifilename,sFlagTableName,'PageFontSize','8'));
sPageFontName:=readini(inifilename,sFlagTableName,'PageFontName','Arial');
frReport.DataSet:=frDs;
frReport.StoreInDFM:=false;
frReport.ShowProgress:=false;
frReport.ShowPrintDialog:=false;
frReport.Pages.Clear;
frReport.Pages.Add;// create page
// frReport.Pages[0].pgOr:=poLandscape;
Page := frReport.Pages[0];
if spageOrient='纵向' then
Page.pgOr:=poPortrait//纵向 720
else
Page.pgOr:=poLandscape;//横向 1032 poLandscape
page.pgSize:=strtoint(trim(ReadIni(iniFileName,sFlagTableName,'PageSize','9')));
if page.pgSize<>256 then
Page.ChangePaper(page.pgSize,0,0,0,page.pgOr) //刷新
else
begin
iPageWidth:=strtoint(ReadIni(iniFileName,sFlagTableName,'PageWidth','1000'));
iPageHeight:=strtoint(ReadIni(iniFileName,sFlagTableName,'PageHeight','1000'));
Page.ChangePaper(page.pgSize,iPageWidth,iPageHeight,0,page.pgOr); //刷新
end;
b := TfrBandView.Create; // create Title band
b.SetBounds(0, 20, 0, 80); // position and size in pixels
b.BandType := btReportTitle; // (only Top and Height are significant
Page.Objects.Add(b);
// for the band)
iHeight:=iFontSize*2+2;
iLeft:=strtoint(sLeftSize);
v:=TfrMemoView.Create;
v.SetBounds(iLeft, 100-iHeight, 200, iHeight);
v.Prop['Font.Size']:=iFontSize;
v.Prop['Font.Name']:=sPageFontName;
v.Memo.Add('打印日期:[Date]');
Page.Objects.Add(v);
if spageOrient='纵向' then
iRight:=500-strtoint(sRightSize)
else
iRight:=920-strtoint(sRightSize);
v := TfrMemoView.Create; // create memo
v.SetBounds(20, 20, 200, 30);
v.BandAlign := baWidth;
v.Prop['Alignment'] := frtaCenter; // another way to access properties
v.Prop['Font.Style'] := 2;
v.Prop['Font.Size']:=20;
v.Memo.Add(readini(iniFileName,sFlagTableName,'PageCaption',sCaption));
Page.Objects.Add(v);
b := TfrBandView.Create; // create Title band
// position and size in pixels
b.BandType := btPageHeader;
iTop:=120;
b.SetBounds(0, iTop, 0, iHeight); // 页头
Page.Objects.Add(b);
iLeft:=strtoint(sLeftSize);
//iLeft:=5;
for i:=0 to frDs.DataSet.FieldCount-1 do
begin
sFieldName:=frDs.DataSet.Fields[i].FieldName;
sWidth:=readini(iniFileName,sFieldName,
'width','50'); //宽度
sHide:=readini(iniFileName,sFieldName,
'hide','0');//隐藏
sAlign:=readini(iniFileName,sFieldName,
'align','向左');//排列
if sHide='1' then continue;
sShape:=TfrShapeView.Create;
sShape.SetBounds(iLeft,iTop,strtoint(sWidth),iHeight);
Page.Objects.Add(sShape);
v:=TFrMemoView.Create;
v.SetBounds(iLeft, iTop, strtoint(sWidth)-2, iHeight);
if sAlign='向左' then
v.Prop['Alignment'] := frtaLeft
else
if sAlign='居中' then
v.Prop['Alignment'] := frtaCenter
else
v.Prop['Alignment'] := frtaRight;//向右
v.Prop['Font.Name']:=sPageFontName;
v.Prop['Font.Size']:=iFontSize;
v.Memo.Add(frDs.DataSet.Fields[i].FieldName);
Page.Objects.Add(v);
iLeft:=iLeft+strtoint(sWidth);
if spageOrient='纵向' then
begin
if iLeft>=720-strtoint(sRightSize) then
break;
end
else
begin
if iLeft>=1030-strtoint(sRightSize) then
break;
end;
//Inc(iLeft,80);
end;
v:=TfrMemoView.Create;
v.SetBounds(iLeft-200, 100-iHeight, 200, iHeight);
v.Prop['Alignment']:=frtaRight;
v.Prop['Font.Name']:=sPageFontName;
v.Prop['Font.Size']:=iFontSize;
v.Memo.Add('打印人:'+sPrintPeaple);
Page.Objects.Add(v);
itop:=180;
MasterDate1 := TfrBandView.Create; // create MasterData band
MasterDate1.SetBounds(0, itop, 0, iHeight);
MasterDate1.BandType := btMasterData;
MasterDate1.Name:='MyDate1';
MasterDate1.Dataset := 'frDs'; // band's dataset
Page.Objects.Add(MasterDate1);
iLeft:=strtoint(sLeftSize);
for i:=0 to frDs.DataSet.FieldCount-1 do
begin
sFieldName:=frDs.DataSet.Fields[i].FieldName;
sWidth:=readini(iniFileName,sFieldName,
'width','50'); //宽度
sHide:=readini(iniFileName,sFieldName,
'hide','0');//隐藏
sAlign:=readini(iniFileName,sFieldName,
'align','向左');//排列
if sHide='1' then continue;
sShape:=TfrShapeView.Create;
sShape.SetBounds(iLeft,itop,strtoint(sWidth),iHeight);
Page.Objects.Add(sShape);
v:=TFrMemoView.Create;
v.SetBounds(iLeft, itop, strtoint(sWidth)-2, iHeight);
if sAlign='向左' then
v.Prop['Alignment'] := frtaLeft
else
if sAlign='居中' then
v.Prop['Alignment'] := frtaCenter
else
v.Prop['Alignment'] := frtaRight;//向右
v.Prop['Font.Name']:=sPageFontName;
v.Prop['Font.Size']:=iFontSize;
v.Memo.Add('["'+frDs.DataSet.Fields[i].FieldName+'"]');
Page.Objects.Add(v);
iLeft:=iLeft+strtoint(sWidth);
if spageOrient='纵向' then
begin
if iLeft>=720-strtoint(sRightSize) then
break;
end
else
begin
if iLeft>=1030-strtoint(sRightSize) then
break;
end;
// Inc(iLeft,80);
end;
itop:=240;
b := TfrBandView.Create; // create 报表合计
b.SetBounds(0, itop, 0, iHeight);
b.BandType := btReportSummary;
b.Dataset := 'frDs'; // band's dataset
Page.Objects.Add(b);
iLeft:=strtoint(sLeftSize);
iFitColumn:=0;
for i:=0 to frDs.DataSet.FieldCount-1 do
begin
sFieldName:=frDs.DataSet.Fields[i].FieldName;
sWidth:=readini(iniFileName,sFieldName,
'width','50'); //宽度
sHide:=readini(iniFileName,sFieldName,
'hide','0');//隐藏
sAlign:=readini(iniFileName,sFieldName,
'align','向左');//排列
sSumType:=readini(iniFileName,sFieldName,
'sumType','文本');//汇总类型
if i=iFitColumn then
begin
if sHide='1' then
begin
iFitColumn:=iFitColumn+1;
continue;
end;
sShape:=TfrShapeView.Create;
sShape.SetBounds(iLeft,itop,strtoint(sWidth),iHeight);
Page.Objects.Add(sShape);
v:=TFrMemoView.Create;
v.SetBounds(iLeft, itop, strtoint(sWidth)-2, iHeight);
v.Prop['Font.Size']:=iFontSize;
v.Prop['Alignment'] := frtaCenter;
v.Prop['Font.Name']:=sPageFontName;
v.Memo.Add('合计');
Page.Objects.Add(v);
iLeft:=iLeft+strtoint(sWidth);
continue;
end;
if sHide='1' then continue;
sShape:=TfrShapeView.Create;
sShape.SetBounds(iLeft,itop,strtoint(sWidth),iHeight);
Page.Objects.Add(sShape);
v:=TFrMemoView.Create;
v.SetBounds(iLeft, itop, strtoint(sWidth)-2, iHeight);
if sAlign='向左' then
v.Prop['Alignment'] := frtaLeft
else
if sAlign='居中' then
v.Prop['Alignment'] := frtaCenter
else
v.Prop['Alignment'] := frtaRight;//向右
v.Prop['Font.Name']:=sPageFontName;
v.Prop['Font.Size']:=iFontSize;
if (frDs.DataSet.Fields[i].DataType=ftInteger) or (frDs.DataSet.Fields[i].DataType=ftFloat)
or (frDs.DataSet.Fields[i].DataType=ftCurrency) or (frDs.DataSet.Fields[i].DataType=ftBCD) then
begin
if sSumType='文本' then
v.Memo.Add(' ')
else
if sSumType='平均' then
v.Memo.Add('[AVG(["'+sFieldName+'"])]')
else
if sSumType='汇总' then
v.Memo.Add('[SUM(["'+sFieldName+'"])]')
else
v.Memo.Add('[COUNT(MyDate1)]');//计数
end
else
if sSumType='计数' then
v.Memo.Add('[COUNT(MyDate1)]')//计数
else
v.Memo.Add(' ');
Page.Objects.Add(v);
iLeft:=iLeft+strtoint(sWidth);
if spageOrient='纵向' then
begin
if iLeft>=720-strtoint(sRightSize) then
break;
end
else
begin
if iLeft>=1030-strtoint(sRightSize) then
break;
end;
// Inc(iLeft,80);
end;
//页脚
sFootName:=ReadIni(iniFileName,sFlagTableName,'PageFoot','');//读文件存页脚项
iLeft:=strtoint(sLeftSize);
if sFootname<>'' then
begin
itop:=300;
b := TfrBandView.Create; // create 页脚
b.SetBounds(0, itop, 0, iHeight);
b.BandType := btPageFooter;
Page.Objects.Add(b);
iFootCount:=0;
i:=0;
sTemp:=sFootName;
while pos(',',sTemp)<>0 do //计算有多少个页脚项
begin
inc(iFootCount);
sTemp:=copy(sTemp,pos(',',sTemp)+1,length(sTemp));
end;
if spageOrient='纵向' then
begin
iFootWidth:=(720-iLeft-strtoint(sRightSize)-100) div (iFootcount-1);//计算每个页脚有多宽
while pos(',',sFootName)<>0 do
begin
sTemp:=copy(sFootName,1,pos(',',sFootName)-1);
v:=TFrMemoView.Create;
inc(i);
if iFootcount=i then
v.SetBounds(iLeft, 300, 720 div iFootcount-8, iHeight)
else
v.SetBounds(iLeft, 300, 720 div iFootcount-8, iHeight);
v.Prop['Font.Name']:=sPageFontName;
v.Prop['Font.Size']:=iFontSize;
v.Memo.Add(sTemp);
Page.Objects.Add(v);
ileft:=ileft+iFootWidth;
sFootName:=copy(sFootName,pos(',',sFootName)+1,length(sFootname));
end;
end
else
begin
iFootWidth:=(1030-iLeft-strtoint(sRightSize)-100) div (iFootcount-1);//计算每个页脚有多宽
while pos(',',sFootName)<>0 do
begin
sTemp:=copy(sFootName,1,pos(',',sFootName)-1);
v:=TFrMemoView.Create;
inc(i);
if iFootcount=i then
v.SetBounds(iLeft, 300, 1030 div iFootcount-8, iHeight)
else
v.SetBounds(iLeft, 300, 1030 div iFootcount-8, iHeight);
v.Prop['Font.Name']:=sPageFontName;
v.Prop['Font.Size']:=iFontSize;
v.Memo.Add(sTemp);
Page.Objects.Add(v);
ileft:=ileft+iFootWidth;
sFootName:=copy(sFootName,pos(',',sFootName)+1,length(sFootname));
end;
end;
end;
// frReport.Preview:=FormPreview.frPreview1;
frReport.ShowPreparedReport;
frReport.ShowReport;
frmmessageRegister.Close;
frmmessageRegister.Free;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -