u_gzda_zhcx.pas
来自「人事管理程序源码」· PAS 代码 · 共 711 行 · 第 1/2 页
PAS
711 行
QuickRep1.Bands.HasDetail:=true;
QuickRep1.Bands.HasPageFooter:=true;
quickrep1.Bands.HasSummary:=true;
DetailBand1.AfterPrint:=DetailBand1AfterPrint;
DetailBand1.BeforePrint:=DetailBand1BeforePrint;
SummaryBand1.AfterPrint:=SummaryBand1AfterPrint;
PageFooterBand1.BeforePrint:=PageFooterBand1BeforePrint;
ColumnHeaderBand1.Height:=30; //表头的字体
ColumnHeaderBand1.Font.Size:=dbgrid1.Columns[0].Title.Font.Size;
ColumnHeaderBand1.font.Name:=dbgrid1.Columns[0].Title.Font.Name;
DetailBand1.Height:=26; //明细的字体
DetailBand1.Font.Size:=dbgrid1.Columns[0].Title.Font.Size;
DetailBand1.Font.Name:=dbgrid1.Columns[0].Title.Font.name;
QRSubDetail1.Height :=26; //页合计的字体
QRSubDetail1.Font.Size:=dbgrid1.Columns[0].Title.Font.Size;
QRSubDetail1.Font.Name :=dbgrid1.Columns[0].Title.Font.name;
SummaryBand1.Height :=26; //总合计的字体
SummaryBand1.Font.Size:=dbgrid1.Columns[0].Title.Font.Size;
SummaryBand1.Font.Name :=dbgrid1.Columns[0].Title.Font.name;
report_width:=0;
for j:=0 to dbgrid1.Columns.Count-1 do begin //以窗体上的表格为摸板创建标题栏
cheader:=Tqrlabel.Create(Form_zhcx);
with cheader do begin //创建标题栏中的标题
parent:=Form_zhcx.ColumnHeaderBand1;
caption:=dbgrid1.Columns[j].Title.Caption;
width:=dbgrid1.Columns[j].Width;
Alignment :=taCenter;
height:=Form_zhcx.ColumnHeaderBand1.Height;
left:=leftv+2;
top:=12;
end; //====================
shap:=Tqrshape.Create(Form_zhcx); //创建标题栏中的竖线
with shap do begin
parent:=Form_zhcx.ColumnHeaderBand1;
shape:=qrsvertline;
width:=1;
height:=Form_zhcx.ColumnHeaderBand1.Height;
left:=leftv+1;
top:=1;
end; //=====================
leftv:=dbgrid1.Columns[j].Width+leftv; //为变量leftv累加
end; //==
//==========================
report_width:=leftv; //表格的总宽度
QRLabel1.Left:=(report_width-strtoint(floattostr(QRLabel1.Width))) div 2; //标题的开始显示位置
DecodeDate(now,nian,yue,ri);
QRLabel2.Caption:='打印日期:'+inttostr(nian)+'年'+inttostr(yue)+'月';
QRLabel2.Left:=(report_width-strtoint(floattostr(QRLabel2.Width))) div 2; //日期标题的开始显示位置
QRSysData1.Left:=(report_width-strtoint(floattostr(QRSysData1.Width)))-30; //页号的位置
//===================
shap:=Tqrshape.Create(Form_zhcx); //为标题栏画上下两条横线
with shap do begin //上横线
parent:=Form_zhcx.ColumnHeaderBand1;
shape:=qrsHorLine;
width:=leftv-2;
height:=1;
left:=1;
top:=1;
end; //======
shap:=Tqrshape.Create(Form_zhcx); //下横线
with shap do begin
parent:=Form_zhcx.ColumnHeaderBand1;
shape:=qrsHorLine;
width:=leftv-2;
height:=1;
left:=1;
top:=Form_zhcx.ColumnHeaderBand1.Height-2;
end; //======
shap:=Tqrshape.Create(Form_zhcx); //创建标题中的最左边一条竖线
with shap do begin
parent:=Form_zhcx.ColumnHeaderBand1;
shape:=qrsvertline;
width:=1;
height:=Form_zhcx.ColumnHeaderBand1.Height;
left:=leftv-1;
top:=1;
end;
leftv:=0; //清变量为O
for j:=0 to dbgrid1.Columns.Count-1 do begin //==========创建明细栏
detailtext:=Tqrdbtext.Create(Form_zhcx); //创建明细值
with detailtext do begin
parent:=Form_zhcx.DetailBand1;
dataset:=gzda_dm.ADOdataset_zhcx; //设定数据集
datafield:=dbgrid1.Columns[j].FieldName;
width:=dbgrid1.Columns[j].Width;
Alignment :=taCenter;
height:=Form_zhcx.DetailBand1.Height;
left:=leftv+2;
top:=8;
end;
shap:=Tqrshape.Create(Form_zhcx); //创建竖线
with shap do begin
parent:=Form_zhcx.DetailBand1;
shape:=qrsvertline;
width:=1;
height:=Form_zhcx.DetailBand1.Height;
left:=leftv+1;
top:=-2;
end; //=========
leftv:=dbgrid1.Columns[j].Width+leftv;
end;
shap:=Tqrshape.Create(Form_zhcx); //为明细栏创建一条横线
with shap do begin
parent:=Form_zhcx.DetailBand1;
shape:=qrsHorLine;
width:=leftv-2;
height:=1;
left:=1;
top:=Form_zhcx.DetailBand1.Height-2;
end;
shap:=Tqrshape.Create(Form_zhcx); //创建明细栏最左边一条竖线
with shap do begin
parent:=Form_zhcx.DetailBand1;
shape:=qrsvertline;
width:=1;
height:=Form_zhcx.DetailBand1.Height;
left:=leftv-1;
top:=-1;
end;
leftv:=0; //清变量为O
for j:=0 to dbgrid1.Columns.Count-1 do begin //=创建本页合计(不打印)
if copy(dbgrid1.Columns[j].Title.Caption,1,1)=' ' then
begin
hjtext1[j]:=TQRExpr.Create(Form_zhcx); //创建明细值
with hjtext1[j] do begin
parent:=Form_zhcx.PageFooterBand1;
Expression:='sum('+dbgrid1.Columns[j].FieldName+')';
width:=dbgrid1.Columns[j].Width;
Alignment :=taCenter;
height:=Form_zhcx.PageFooterBand1.Height;
left:=leftv+2;
top:=8;
end;
end;
end;
leftv:=0; //清变量为O
for j:=0 to dbgrid1.Columns.Count-1 do begin //==创建本页合计(打印)
if copy(dbgrid1.Columns[j].Title.Caption,1,1)=' ' then begin
cheader1[j]:=Tqrlabel.Create(Form_zhcx);
with cheader1[j] do begin //创建值
parent:=Form_zhcx.QRSubDetail1;
caption:=' ';
width:=dbgrid1.Columns[j].Width;
Alignment :=taCenter;
height:=Form_zhcx.QRSubDetail1.Height;
left:=leftv+2;
top:=6;
end; //===
end;
shap1[byhj_xs]:=Tqrshape.Create(Form_zhcx); //页合计中的竖线
with shap1[byhj_xs] do begin
parent:=Form_zhcx.QRSubDetail1;
shape:=qrsvertline;
width:=1;
height:=Form_zhcx.QRSubDetail1.Height+2;
left:=leftv+1;
top:=-2; //qqq
end;
byhj_xs:=byhj_xs+1;
leftv:=dbgrid1.Columns[j].Width+leftv;
end; //=========================
cheader1[30]:=Tqrlabel.Create(Form_zhcx);
with cheader1[30] do begin //创建本页合计栏中的“本页合计'
parent:=Form_zhcx.QRSubDetail1;
caption:='本页合计';
Alignment:=taCenter;
width:=dbgrid1.Columns[0].Width;
height:=Form_zhcx.QRSubDetail1.Height;
left:=2;
top:=6;
end;
shap1[byhj_xs]:=Tqrshape.Create(Form_zhcx); //下横线
with shap1[byhj_xs] do begin
parent:=Form_zhcx.QRSubDetail1;
shape:=qrsHorLine;
width:=leftv-2;
height:=1;
left:=1;
top:=Form_zhcx.QRSubDetail1.Height-2;
end; //======
byhj_xs:=byhj_xs+1;
shap1[byhj_xs]:=Tqrshape.Create(Form_zhcx); //创建本页合计(打印)中的最左边一条竖线
with shap1[byhj_xs] do begin
parent:=Form_zhcx.QRSubDetail1;
shape:=qrsvertline;
width:=1;
height:=Form_zhcx.QRSubDetail1.Height+2 ;
left:=leftv-1;
top:=-1;
ComponentIndex:=501;
end; //=====================
byhj_xs:=byhj_xs+1;
leftv:=0; //清变量为O
for j:=0 to dbgrid1.Columns.Count-1 do begin //==========创建总合计
if copy(dbgrid1.Columns[j].Title.Caption,1,1)=' ' then begin
hjtext:=TQRExpr.Create(Form_zhcx); //创建明细值
with hjtext do begin
parent:=Form_zhcx.SummaryBand1;
Expression:='sum('+dbgrid1.Columns[j].FieldName+')';
width:=dbgrid1.Columns[j].Width;
Alignment :=taCenter;
height:=Form_zhcx.SummaryBand1.Height;
left:=leftv+2;
top:=8;
end;
end; //====================
shap:=Tqrshape.Create(Form_zhcx); //创建竖线
with shap do begin
parent:=Form_zhcx.SummaryBand1;
shape:=qrsvertline;
width:=1;
height:=Form_zhcx.SummaryBand1.Height;
left:=leftv+1;
top:=-1; ///qqq
end; //=========
leftv:=dbgrid1.Columns[j].Width+leftv;
end;
cheader:=Tqrlabel.Create(Form_zhcx);
with cheader do begin //创建总合计栏中的“总合计'
parent:=Form_zhcx.SummaryBand1;
caption:='总合计';
cheader.Alignment:=taCenter;
width:=dbgrid1.Columns[0].Width;
height:=Form_zhcx.SummaryBand1.Height;
left:=2;
top:=6;
end; //====================
shap:=Tqrshape.Create(Form_zhcx); //为总合计栏创建一条横线
with shap do begin
parent:=Form_zhcx.SummaryBand1;
shape:=qrsHorLine;
width:=leftv-2;
height:=1;
left:=1;
top:=Form_zhcx.SummaryBand1.Height-2;
end; //=======================
shap:=Tqrshape.Create(Form_zhcx); //创建明细栏最左边一条竖线
with shap do begin
parent:=Form_zhcx.SummaryBand1;
shape:=qrsvertline;
width:=1;
height:=Form_zhcx.SummaryBand1.Height;
left:=leftv-1;
top:=-1;
end; //=========================
first_bz:=false; //预览以后使第一次预览标志设为假,
end; //以便在开始预览前清除“本页合计“中的控件.
procedure TForm_zhcx.QRSubDetail1NeedData(Sender: TObject;
var MoreData: Boolean);
var
j:integer;
begin
For j:=0 to dbgrid1.Columns.Count-1 do begin
if copy(dbgrid1.Columns[j].Title.Caption,1,1)=' ' then
begin
cheader1[j].Caption:=floattostr(int(hjtext1[j].Value.dblResult*1000+0.5)/1000);
end;
end;
end; //用以把默认的本页合计的值送到打印本页合计边上的Qrlabel的Caption属性
procedure TForm_zhcx.DetailBand1BeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean);
begin
if dybz then begin //用以判断是否在预览时打印
gzda_dm.ADOdataset_zhcx.First; //因为dybz的初始值为假,只在总合
i:=0; //打印以后才使它为真,所以如果
bz:=false; //dybz为真则一定是在预览时打印了
dybz:=false;
end;
end;
procedure TForm_zhcx.DetailBand1AfterPrint(Sender: TQRCustomBand;
BandPrinted: Boolean);
begin
i:=i+1; //用以使当前每页的行数加1
end;
procedure TForm_zhcx.QRSubDetail1BeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean);
begin
gzda_dm.ADOdataset_zhcx.next; //为了判断是否到了数据表的未尾
if (i=myhs) then begin //如果当前每页的行数等于设定的每页的行数则使本页合计打印
PrintBand:=true;
end
else begin
if (gzda_dm.ADOdataset_zhcx.eof) and (bz=false) then begin//如果到了数据表的未尾也使
PrintBand:=true; //本页合计打印,这里加了一个全局的控制变量bz,是为了
bz:=true; //使本页合计只打印一次,如果没有这个控制,因为这个条
end //条件一直成立,所以会把本页合计边一直打印下去。
else
PrintBand:=false;
end;
if not gzda_dm.ADOdataset_zhcx.eof then gzda_dm.ADOdataset_zhcx.Prior;
//加这下行代码是因为在上边我们使数据表下移了一条记录。这们是为了判断是否到了数据表的未
//尾。这里有一个Delphi默认的控制机制:在每打印完一个明细项(一条记录)时会自动下移记录
end;
procedure TForm_zhcx.QRSubDetail1AfterPrint(Sender: TQRCustomBand;
BandPrinted: Boolean);
begin
if i=myhs then begin //如果当前每页的行数等于设定的每页的行数则开始一新页
QuickRep1.NewColumn; //同时使控制变量为0
i:=0;
end;
end;
procedure TForm_zhcx.PageFooterBand1BeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean);
var
j:integer;
begin
for j:=0 to dbgrid1.Columns.Count-1 do begin //==========创建本页合计(不打印)
if copy(dbgrid1.Columns[j].Title.Caption,1,1)=' ' then begin
hjtext1[j].Reset;
end; //因为无法设置QRexpr的AfterPrintReset属性,因为根本没有打印
end; //所有要在这里调用QRexpr的Reset过程以清空它的值。
printband:=false;
end;
procedure TForm_zhcx.SummaryBand1AfterPrint(Sender: TQRCustomBand;
BandPrinted: Boolean);
begin
dybz:=true; // 使控制变量为真。
end;
procedure TForm_zhcx.FormShow(Sender: TObject);
begin
xsbg; //显示表格内容
szcx_tj; //重新设定 ycx_tj的值
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?