📄 prpreviewdbg.pas
字号:
unit prPreviewDBG;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, db,grids, DBGrids, Buttons, ExtCtrls,
Spin, PReport;
type
Tpreviewdbgridform = class(TForm)
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
FontDialog1: TFontDialog;
GroupBox2: TGroupBox;
SpeedButton4: TSpeedButton;
edit1: TLabel;
edit2: TLabel;
btnPreview: TBitBtn;
btnPrint: TBitBtn;
btnCancel: TBitBtn;
PrinterSetupDialog1: TPrinterSetupDialog;
edit3: TLabel;
PRClass1: TPRClass;
procedure CheckBox1Click(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FN1Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure btnPrintClick(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
procedure btnPreviewClick(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure SpeedButton2Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
private
btFont: TLogFont; //标题字体 及字号
CellFont: TLogFont; //
zz:boolean;
Cellcolor:integer;
procedure PrintOrPreview(PV:string);
{ Private declarations }
public
Pdbgrid:TDBGrid;
FEptNAme:string;
sTitle: String
{ Public declarations }
end;
var
previewdbgridform: Tpreviewdbgridform;
implementation
{$R *.dfm}
//未满页空表格补齐
procedure Tpreviewdbgridform.CheckBox1Click(Sender: TObject);
begin
if CheckBox1.Checked then
PRClass1.AddEmptyLine:=true
else
PRClass1.AddEmptyLine:=false;
end;
procedure Tpreviewdbgridform.FormPaint(Sender: TObject);
begin
CheckBox1.Checked:=PRClass1.AddEmptyLine;
end;
procedure Tpreviewdbgridform.FormActivate(Sender: TObject);
var strFileDir:string;
begin
strFileDir := ExtractFileDir(Application.ExeName);
if FileExists(strFileDir+'\'+FeptName) then //如果文件存在
begin
CheckBox2.Enabled:=true;
GroupBox2.Enabled:=false;
end
else
CheckBox2.visible:=false;
end;
procedure Tpreviewdbgridform.FN1Click(Sender: TObject);
begin
FontDialog1.Font.Name := edit1.Font.Name;
FontDialog1.Font.Size := edit1.Font.Size;
FontDialog1.Font.Color:= edit1.Font.Color;
FontDialog1.Font.Style := edit1.Font.Style;
if FontDialog1.Execute then
begin
Windows.GetObject(FontDialog1.Font.Handle, SizeOf(btFont), @btFont);
edit1.Font.Name:= FontDialog1.Font.Name;
edit1.Font.size:= FontDialog1.Font.Size;
edit1.Font.Color:=FontDialog1.Font.Color;
edit1.Font.style:=FontDialog1.Font.style;
end;
end;
procedure Tpreviewdbgridform.SpeedButton4Click(Sender: TObject);
begin
FontDialog1.Font.Name := edit3.Font.Name;
FontDialog1.Font.Size := edit3.Font.Size;
FontDialog1.Font.Color:= edit3.Font.Color;
FontDialog1.Font.style:= edit3.Font.style;
if FontDialog1.Execute then
begin
Windows.GetObject(FontDialog1.Font.Handle, SizeOf(CellFont), @CellFont);
edit3.Font.Name:= FontDialog1.Font.Name;
edit3.Font.size:= FontDialog1.Font.Size;
edit3.Font.color:= FontDialog1.Font.color;
edit3.Font.style:=FontDialog1.Font.style;
end;
end;
//打印或预览控制
procedure Tpreviewdbgridform.PrintOrPreview(PV: string);
var i,j,k,iSum:integer; //iSum合计开始列
strFileDir:string;
begin
iSum:=0;
k:=0; //栏目个数
for i:=0 to pdbgrid.Columns.Count-1 do
if pdbgrid.Columns[i].Visible=true then k:=k+1; //yangsai GridEh可见栏目个数
strFileDir := ExtractFileDir(Application.ExeName); //可执行文件目录
if (not FileExists(strFileDir+'\'+FeptName)) or (not CheckBox2.Checked) then
begin
if not zz then //如果没有设置纸张
begin
//SetWndSize(748,1090);// 设置纸张大小
cp_pgw:=0;
PRClass1.CalcWndSize;// 选择默认的纸来确定报表窗口的大小并对该窗口进行设置。
end;
// 创建一个5行k列的表
//Row 1:标题 Row 2:条件 Row 3:表头 Row 4: 表身 Row 5 合计 Row 6:页码
PRClass1.NewTable(k ,6);
//处理0行抬头
PRClass1.SetCellSFocus(0,0,0,k-1);//选取0行
PRClass1.CombineCell; //合并0行单元格 第一行:标题
PRClass1.setLineHegit(0,40); //设定0行的高度
PRClass1.SetCellLines(false,false,false,false,1,1,1,1); //去掉表格线
PRClass1.SetCellText(0,0,sTitle); //填0行的内容
PRClass1.SetCellAlign(1, 1);//将选中行的文字居中
FontDialog1.Font.Name := edit1.Font.Name;
FontDialog1.Font.Size := edit1.Font.Size;
FontDialog1.Font.style := edit1.Font.style;
Windows.GetObject(FontDialog1.Font.Handle, SizeOf(btFont), @btFont);
PRClass1.SetCellFont(btFont); //设定字体
PRClass1.SetCellColor(edit1.Font.Color, clwhite); //白底红字
//处理1行条件
PRClass1.RemoveAllSelectedCell;
PRClass1.SetCellSFocus(1,0,1,k-1);//选取1行
PRClass1.CombineCell; //合并单元格 第一行:标题
PRClass1.setLineHegit(1,20); //设定高度
PRClass1.SetCellLines(false,false,false,false,1,1,1,1); //去掉表格线
PRClass1.SetCellText(1,0,'`condition'); //填4行的内容
PRClass1.SetCellAlign(0, 1);//将选中行的文字居?
FontDialog1.Font.Name := edit2.Font.Name;
FontDialog1.Font.Size := edit2.Font.Size;
FontDialog1.Font.style := edit2.Font.style;
Windows.GetObject(FontDialog1.Font.Handle, SizeOf(btFont), @btFont);
PRClass1.SetCellFont(btFont); //设定字体
PRClass1.SetCellColor(edit2.Font.Color, clwhite); //白底红字
// 20040824
j:=0;
for i:=0 to pdbgrid.Columns.Count-1 do
if pdbgrid.Columns[i].Visible=true then
begin
PRClass1.RemoveAllSelectedCell;
PRClass1.SetCellFocus(2,j);//
PRClass1.SetCellsWidth(pdbgrid.Columns[i].Width);////设置当前选定所有单元格宽度2004-09-27
PRClass1.SetCellText(2,j,pdbgrid.Columns[i].Title.Caption);
//
PRClass1.RemoveAllSelectedCell;
PRClass1.SetCellFocus(4,j);//
PRClass1.SetCellsWidth(pdbgrid.Columns[i].Width);
//
PRClass1.SetCellText(3,j,'细表.'+pdbgrid.Columns[i].FieldName);
PRClass1.RemoveAllSelectedCell;
PRClass1.SetCellFocus(3,j);//
PRClass1.SetCellsWidth(pdbgrid.Columns[i].Width);////设置当前选定所有单元格宽度2004-09-27
if pdbgrid.DataSource.DataSet.FieldByName(pdbgrid.Columns[i].FieldName) is tnumericField then
begin
PRClass1.SetCellAlign(2, 1); //右对齐
//
end else PRClass1.SetCellAlign(1, 1); //is tnumericField
//
j:=j+1;
end ;
// 20040824
PRClass1.RemoveAllSelectedCell;
PRClass1.SetCellSFocus(2,0,2,k-1);//选取1行
PRClass1.SetCellAlign(1, 1);//将选中行的文字居中
FontDialog1.Font.Name := edit2.Font.Name;
FontDialog1.Font.Size := edit2.Font.Size;
FontDialog1.Font.style := edit2.Font.style;
Windows.GetObject(FontDialog1.Font.Handle, SizeOf(cellFont), @cellFont);
PRClass1.SetCellFont(CellFont); //设定字体
PRClass1.SetCellColor(edit2.Font.Color, clwhite); //
//页码设置
PRClass1.RemoveAllSelectedCell;
PRClass1.SetCellsFocus(4,0,5,k-1); //选择最后一行
PRClass1.SetCellLines(false,false,false,false,1,1,1,1); //去掉表格线
PRClass1.CombineCell; //合并单元格
PRClass1.SetCellText(5,0,'[第?/n页]'); //本行内容为"第?/?页"样式的页码
PRClass1.SetCellAlign(1, 1); //居中
PRClass1.SetCellSFocus(3,0,3,k-1); //选择行
FontDialog1.Font.Name := edit3.Font.Name;
FontDialog1.Font.Size := edit3.Font.Size;
FontDialog1.Font.style := edit3.Font.style;
Windows.GetObject(FontDialog1.Font.Handle, SizeOf(cellFont), @cellFont);
PRClass1.SetCellFont(CellFont); //设定字体
PRClass1.SetCellColor(edit3.Font.Color, clwhite); //
PRClass1.SaveToFile(strFileDir+'\'+FeptName); //保存到文件
PRClass1.ResetContent;
end; //如果文件不存在
TPRExcute(owner).ReportFile:=strFileDir+'\'+FeptName;
TPRExcute(owner).ReportFile:=strFileDir+'\'+FeptName;
//设置数据集
TPRExcute(owner).Define('细表',pdbgrid.DataSource.DataSet);
//
if PV='preview' then //打印预览
TPRExcute(owner).PrintPreview(true); //true参数表示预览不显示非打印表格线
if PV='print' then //直接打印
TPRExcute(owner).print(false);
end;
procedure Tpreviewdbgridform.btnPreviewClick(Sender: TObject);
begin
PrintOrPreview('preview'); //打印预览
end;
procedure Tpreviewdbgridform.btnPrintClick(Sender: TObject);
begin
PrintOrPreview('print'); //直接打印
end;
procedure Tpreviewdbgridform.btnCancelClick(Sender: TObject);
begin
close;
end;
procedure Tpreviewdbgridform.SpeedButton1Click(Sender: TObject);
begin
end;
procedure Tpreviewdbgridform.FormCreate(Sender: TObject);
begin
zz:=false;
end;
procedure Tpreviewdbgridform.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
zz:=false;
end;
procedure Tpreviewdbgridform.SpeedButton2Click(Sender: TObject);
begin
FontDialog1.Font.Name := edit2.Font.Name;
FontDialog1.Font.Size := edit2.Font.Size;
FontDialog1.Font.Color:= edit2.Font.Color;
FontDialog1.Font.Style := edit2.Font.Style;
if FontDialog1.Execute then
begin
Windows.GetObject(FontDialog1.Font.Handle, SizeOf(btFont), @btFont);
edit2.Font.Name:= FontDialog1.Font.Name;
edit2.Font.size:= FontDialog1.Font.Size;
edit2.Font.Color:=FontDialog1.Font.Color;
edit2.Font.style:=FontDialog1.Font.style;
end;
end;
procedure Tpreviewdbgridform.CheckBox2Click(Sender: TObject);
begin
if CheckBox2.Checked then GroupBox2.Enabled:=false
else GroupBox2.Enabled:=true;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -