📄 report.pas
字号:
//注释说明:前注释'-->'说明功能作用,后注释'<--'解释变量属性等
unit Report;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, QuickRpt, QRCtrls, ComCtrls,Common, Buttons,
IniFiles;
//-->表格控制参数类型
type
TTBPara = record
Top,Left,Width,LinesH,BandCount,LinesCount,FootCount,LeftWidth,RightWidth:Integer;
Parent:TWinControl;
FontStyle:TFont;
end;
//<--Top,Left,Width分别表示表格左边,上边的坐标和表格的宽度
//<--LinesH,BandCount,LinesCount,FootCount分别表示表格行高和表头、表体、表尾行数(表体:操作内容到预发时间之间)
//<--LeftWidth,RithtWidth分别表示左边第一列的列宽和表体右边列宽
//<--Parent父窗口
//<--字体格式
type
TFrm_Rpt = class(TForm)
PL_Head: TPanel;
PL_Rpt: TPanel;
QRPT: TQuickRep;
SCB_Rpt: TScrollBox;
DetailBand1: TQRBand;
QRLB_Title: TQRLabel;
Btn_Print: TBitBtn;
Btn_Preview: TBitBtn;
Btn_Setup: TBitBtn;
PrinterSetupDialog1: TPrinterSetupDialog;
PrintDialog1: TPrintDialog;
procedure Btn_PreviewClick(Sender: TObject);
procedure Btn_PrintClick(Sender: TObject);
procedure Btn_SetupClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure DrawTable(Para:TTBPara);
procedure AddEdit(Para:TTBPara);
public
{ Public declarations }
Procedure BindData(content:TKcontent);
end;
var
Frm_Rpt: TFrm_Rpt;
TBPara:TTBPara;
ED_Head:Array[0..7] of TQRRichText;
ED_Band:Array of Array of TQRRichText; //对应BandCount
ED_Body:Array of Array of TQRRichText; //对应LinesCount
ED_Foot:Array of Array of TQRRichText; //对应FootFount
implementation
uses
Main;
{$R *.dfm}
Procedure TFrm_Rpt.BindData(content:TKcontent);
begin
if TBPara.BandCount=2 then
ED_Band[0][0].Lines[0]:='注 意';
ED_Band[TBPara.BandCount-1][1].Lines[0]:=content.Title;//任务
ED_Body[1][0].Lines[0]:='1';
ED_Body[1][1].Lines[0]:=content.Body.Strings[0];
ED_Body[2][0].Lines[0]:='2';
ED_Body[2][1].Lines[0]:=content.Body.Strings[1];
if TBPara.FootCount=1 then
begin
ED_Foot[0][0].Lines[0]:='操 作';
ED_Foot[0][2].Lines[0]:='终了时间';
end
else
begin
ED_Foot[0][0].Lines[0]:='签 发';
ED_Foot[1][0].Lines[0]:='审 核';
ED_Foot[2][0].Lines[0]:='操 作';
ED_Foot[0][2].Lines[0]:='预令时间';
ED_Foot[1][2].Lines[0]:='发令时间';
ED_Foot[2][2].Lines[0]:='终了时间';
end;
end;
procedure TFrm_Rpt.AddEdit(Para:TTBPara);
var
i,j,TempLeft:Integer;
begin
//-->表头
ED_Head[0]:=TQRRichText.Create(self);
ED_Head[0].Parent:=Para.Parent;
ED_Head[0].Font:=Para.FontStyle;
ED_Head[0].Width:=Para.LeftWidth+1;
ED_Head[0].Height:=Para.LinesH+1;
//Ed_Head[0].MaxLength:=2;
Ed_Head[0].Left:=Para.Left;
ED_Head[0].Top:=Para.Top;
//-->使文字居中
ED_Head[0].Alignment:=taCenter;
ED_Head[0].Lines[0]:='发 令';
ED_Head[0].Enabled:=False;
TempLeft:=Para.Left+Para.LeftWidth;
for i := 1 to 7 do
begin
ED_Head[i]:=TQRRichText.Create(self);
ED_Head[i].Parent:=Para.Parent;
ED_Head[i].Font:=Para.FontStyle;
ED_Head[i].Height:=Para.LinesH+1;
//Ed_Head[i].MaxLength:=ED_Head[i].Width div ED_Head[i].Font.Size;
Ed_Head[i].Left:=TempLeft;
if i=7 then
ED_Head[i].Width:=Para.Width-(ED_Head[i].Left-Para.Left)+1
else
ED_Head[i].Width:=(Para.Width-Para.LeftWidth)div 7 +1;
ED_Head[i].Top:=Para.Top;
//ED_Head[i].Text:=' '+inttostr(i);
ED_Head[i].Enabled:=False;
TempLeft:=TempLeft+(Para.Width-Para.LeftWidth)div 7;
end;
//-->使文字居中
for i := 1 to 7 do
begin
ED_Head[i].Alignment:=taCenter;
end;
ED_Head[2].Lines[0]:='受令单';
ED_Head[4].Lines[0]:='受 令';
ED_Head[6].Lines[0]:='令';
ED_Head[7].Lines[0]:='综 一';
//-->表头下方 Band
SetLength(ED_Band,Para.BandCount,2);//<--设定数组长度
for i :=0 to Para.BandCount-1 do
for j:=0 to 1 do
begin
ED_Band[i][j]:=TQRRichText.Create(self);
ED_Band[i][j].Parent:=Para.Parent;
ED_Band[i][j].Font:=Para.FontStyle;
ED_Band[i][j].Height:=Para.LinesH+1;
case j of
0:
begin
ED_Band[i][j].Width:=Para.LeftWidth+1;
ED_Band[i][j].Left:=Para.Left;
end;
1:
begin
ED_Band[i][j].Width:=Para.Width-Para.LeftWidth+1;
ED_Band[i][j].Left:=Para.Left+Para.LeftWidth;
end;
//else ;
end;
ED_Band[i][j].Top:=Para.Top+Para.LinesH*(i+1);
//ED_Band[i][j].Text:=inttostr(i);
ED_Band[i][j].Enabled:=False;
end;
//-->使文本居中显示
for i := 0 to Para.BandCount-1 do
begin
ED_Band[i][0].Alignment:=taCenter;
end;
ED_Band[Para.BandCount-1][0].Lines[0]:='任 务';
ED_Band[Para.BandCount-1][1].Lines[0]:=' 6kv一、十九联络41174开关停电 ';
//-->表体
SetLength(ED_Body,Para.LinesCount+1,3);//<--设定数组长度
for i := 0 to Para.LinesCount do
for j:=0 to 2 do
begin
ED_Body[i][j]:=TQRRichText.Create(self);
ED_Body[i][j].Parent:=Para.Parent;
ED_Body[i][j].Font:=Para.FontStyle;
ED_Body[i][j].Height:=Para.LinesH+1;
case j of
0:
begin
ED_Body[i][j].Width:=Para.LeftWidth+1;
ED_Body[i][j].Left:=Para.Left;
end;
1:
begin
ED_Body[i][j].Width:=Para.Width-Para.LeftWidth-Para.RightWidth +1;
ED_Body[i][j].Left:=Para.Left+Para.LeftWidth;
end;
2:
begin
ED_Body[i][j].Width:=Para.RightWidth+1;
ED_Body[i][j].Left:=Para.Left+Para.Width-Para.RightWidth;
end;
//else ;
end;
ED_Body[i][j].Top:=Para.Top+Para.LinesH*(i+Para.BandCount+1);
//ED_Body[i][j].Text:=inttostr(i);
end;
//-->使文本居中显示
for i := 0 to Para.LinesCount do
begin
ED_Body[i][0].Alignment:=taCenter;
ED_Body[i][2].Alignment:=taCenter;
end;
ED_Body[0][1].Alignment:=taCenter;
ED_Body[0][0].Lines[0]:='序 号';
Ed_Body[0][1].Lines[0]:='操 作 内 容' ;
ED_Body[0][2].Lines[0]:='备 注';
//-->表尾
SetLength(ED_Foot,Para.FootCount,4); //<--设定数组长度
for i :=0 to Para.FootCount-1 do
for j:=0 to 3 do
begin
ED_Foot[i][j]:=TQRRichText.Create(self);
ED_Foot[i][j].Parent:=Para.Parent;
ED_Foot[i][j].Font:=Para.FontStyle;
ED_Foot[i][j].Height:=Para.LinesH+1;
case j of
0:
begin
ED_Foot[i][j].Width:=Para.LeftWidth+1;
Ed_Foot[i][j].Left:=Para.Left;
end;
1:
begin
ED_Foot[i][j].Width:=Para.Width div 2 -Para.LeftWidth-49;
Ed_Foot[i][j].Left:=Para.Left+Para.LeftWidth;
end;
2:
begin
ED_Foot[i][j].Width:=101;
Ed_Foot[i][j].Left:=Para.Left+Para.Width div 2 -50 ;
end;
3:
begin
ED_Foot[i][j].Width:=Para.Width div 2 -49;
Ed_Foot[i][j].Left:=Para.Left+Para.Width div 2 +50 ;
end;
//else ;
end;
ED_Foot[i][j].Top:=Para.Top+Para.LinesH*(i+2+Para.BandCount+Para.LinesCount);
//ED_Foot[i][j].Text:=inttostr(i);
end;
for i:=0 to Para.FootCount-1 do
begin
ED_Foot[i][3].Lines[0]:=' 年 月 日 时';
//-->使文本居中显示
ED_Foot[i][0].Alignment:=taCenter;
ED_Foot[i][2].Alignment:=taCenter;
end;
end;
procedure TFrm_Rpt.DrawTable(Para:TTBPara);
var
i,Temp_Top,TB_Height,Cells_Width:integer;
TBShape:TQRShape;
begin
Temp_Top:=Para.Top;
//-->划标题线
TBShape:=TQRShape.Create(self);
TBShape.Parent:=Para.Parent;
TBShape.Height:=2; //<--表格线粗细为1
TBShape.Width:=Para.Width-360;
TBShape.Left:=Para.Left+170;
TBShape.Top:=Temp_Top-30;
TBShape.Pen.Color:=clFuchsia;
//-->控制标题位置
QRLB_Title.Left:=(Self.QRPT.Width-QRLB_TiTle.Width) div 2;
QRLB_Title.Top:=TBShape.Top-QRLB_Title.Height-10;
//-->划横线
for i:=1 to 3+Para.BandCount+Para.LinesCount+Para.FootCount do
begin
TBShape:=TQRShape.Create(self);
TBShape.Parent:=Para.Parent;
TBShape.Height:=1; //<--表格线粗细为1
TBShape.Width:=Para.Width;
TBShape.Left:=Para.Left;
TBShape.Top:=Temp_Top;
Temp_Top:=Temp_Top+Para.LinesH;
end;
//-->划主竖线
TB_Height:=Para.LinesH*(Para.BandCount+Para.LinesCount+Para.FootCount+2);//<--表格高度
TBShape:=TQRShape.Create(self);
TBShape.Parent:=Para.Parent;
TBShape.Height:=TB_Height+1;
TBShape.Width:=1;//<--表格线粗细为1
TBShape.Left:=Para.Left;
TBShape.Top:=Para.Top;
TBShape:=TQRShape.Create(self);
TBShape.Parent:=Para.Parent;
TBShape.Height:=TB_Height+1;
TBShape.Width:=1;//<--表格线粗细为1
TBShape.Left:=Para.Left+Para.LeftWidth;
TBShape.Top:=Para.Top;
TBShape:=TQRShape.Create(self);
TBShape.Parent:=Para.Parent;
TBShape.Height:=TB_Height+1;
TBShape.Width:=1;//<--表格线粗细为1
TBShape.Left:=Para.Left+Para.Width;
TBShape.Top:=Para.Top;
//-->划表头竖线
Cells_Width:=(Para.Width-Para.LeftWidth) div 7;//<--计算表头单元格宽度
for i :=1 to 6 do
begin
TBShape:=TQRShape.Create(self);
TBShape.Parent:=Para.Parent;
TBShape.Height:=Para.LinesH+1;
TBShape.Width:=1;//<--表格线粗细为1
TBShape.Left:=Para.Left+Para.LeftWidth+Cells_Width*i;
TBShape.Top:=Para.Top;
end;
//-->划表体竖线
TBShape:=TQRShape.Create(self);
TBShape.Parent:=Para.Parent;
TBShape.Height:=Para.LinesH*(Para.LinesCount+1)+1;
TBShape.Width:=1;//<--表格线粗细为1
TBShape.Left:=Para.Left+Para.Width-Para.RightWidth;
TBShape.Top:=Para.Top+(1+Para.BandCount)*Para.LinesH;
//-->画表尾竖线
TBShape:=TQRShape.Create(self);
TBShape.Parent:=Para.Parent;
TBShape.Height:=Para.LinesH*Para.FootCount;
TBShape.Width:=1;//<--表格线粗细为1
TBShape.Left:=Para.Left+Para.Width div 2 +50;
TBShape.Top:=Para.Top+(2+Para.BandCount+Para.LinesCount)*Para.LinesH;
TBShape:=TQRShape.Create(self);
TBShape.Parent:=Para.Parent;
TBShape.Height:=Para.LinesH*Para.FootCount;
TBShape.Width:=1;//<--表格线粗细为1
TBShape.Left:=Para.Left+Para.Width div 2 -50;
TBShape.Top:=Para.Top+(2+Para.BandCount+Para.LinesCount)*Para.LinesH;
end;
procedure TFrm_Rpt.Btn_PreviewClick(Sender: TObject);
begin
Self.QRPT.Preview;
end;
procedure TFrm_Rpt.Btn_PrintClick(Sender: TObject);
begin
Self.QRPT.Print;
end;
procedure TFrm_Rpt.Btn_SetupClick(Sender: TObject);
begin
Self.PrinterSetupDialog1.Execute;
Self.PrintDialog1.Execute;
end;
procedure TFrm_Rpt.FormCreate(Sender: TObject);
var
IniFile:TIniFile;
FileName:string;
begin
//-->从ini文件中读取配置信息
FileName:=ExtractFilePath(Application.ExeName)+'Config\TBSetup.ini'; //获取INI文件路径
if FileExists(FileName) then
begin
IniFile:=TIniFile.Create(FileName);
try
TBPara.Top:=IniFile.ReadInteger('Form','Top',150);
TBPara.Left:=IniFile.ReadInteger('Form','Left',100);
TBPara.LinesH:=IniFile.ReadInteger('Form','LinesH',28);
TBPara.Width:=IniFile.ReadInteger('Form','Width',600);
TBPara.LeftWidth:=IniFile.ReadInteger('Form','LeftWidth',65);
TBpara.RightWidth:=IniFile.ReadInteger('Form','RightWidth',50);
TBPara.BandCount:=IniFile.ReadInteger('Form','BandCount',2);
TBPara.FootCount:=IniFile.ReadInteger('Form','FootCount',3);
TBPara.LinesCount:=IniFile.ReadInteger('Form','LinesCount',4);
//<--LinesCount+BandCount+FootCount要<=27,否则会出界
finally
IniFile.Free;
end;
end
else
begin
//-->INI文件不存在时初始化默认配置
TBPara.Top:=150;
TBPara.Left:=100;
TBPara.LinesH:=28;
TBPara.Width:=600;
TBPara.BandCount:=2;
TBPara.FootCount:=3;
TBPara.LinesCount:=4; //LinesCount+BandCount+FootCount要<=27,否则会出界
TBPara.LeftWidth:=65;
TBpara.RightWidth:=50;
end;
Self.Parent:=Frm_Main.PL_Body;
//-->初始化
Self.QRPT.Left:=100;
Self.QRPT.Top:=0;
Self.DetailBand1.Visible:=False;
TBPara.FontStyle:=Self.Font;
TBpara.Parent:=self.QRPT;
AddEdit(TBPara);
DrawTable(TBPara);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -