用delphi编写医院的复杂报表

类别:Delphi 点击:0 评论:0 推荐:

用delphi编写医院的复杂报表


江苏省无锡市中医医院电脑房
袁波
---- 我院的信息管理系统采用delphi编程,由于各科要求不同,报表形式也多种多样,编写起来让人头痛。delphi运行在WINDOWS平台下,打印同DOS下完全不同,而Quick Report即难以控制又占用资源,对于一个稍复杂的、有特殊要求的报表,Quick Report无法实现。这里介绍几个在编程中遇到的比较典型的报表的实现方法。

---- 1、哪个单位的财务科都有几本厚厚的台帐,我院财务科提出打印药库的台帐,好脱掉手工帐,也算是办公现代化了,要求合情合理,院长也说应当如此。看着财务科提供的红绿相间的、统一印制的、行间距3毫米的台帐专用小卡片,我不由想到中国人节俭的美德。考虑到每个药品至少打印一张,而且表格线一个都不能少,加上中医院药品有二千多种,所以这个报表必须用激光打印机来打印(至于如何让院长同意购买激光打印机,则是另一回事,办公自动化哪能没有代价呢)。程序实现的思路基本上是把打印纸当做画布在上面画一个个小矩形,具体由以下几个过程实现:(设Form名为Ttzview)。

先在程序中定义二个类:
titlerecord=record
Currect:Trect;
Atitle:string;
end;
detailrecord=record
Arect:Trect;
alignment:word;
end;

---- 再建立以下四个过程;
---- RectDraw(Acanvas:Tcanvas;s:string;R:Trect;frame:boolean;position:word);

---- 这个过程就是画矩形用的,frame决定是否画线(这里当然要画啦!);

---- printinitit(firsttop,firstleft:integer);

---- 这个过程是初始化用的,就是定义各个小矩形在纸上的位置;

---- printtitle(acanvas:Tcanvas);

---- 这个过程是打印表头的,因为表头的字总是要大一些;

---- printdetail(acanvas:Tcanvas;Qtz:Tdataset;acount:integer;firstpage:integer);

---- 这个过程才是打印具体内容的,一页打印40行,不够就换页,总之一页只能是一个药品;

---- printhj(acanvas:Tcanvas);

---- 一看就知道,这个过程就是打印合计的啦!

---- 只要建个Botton,顺序调用printinitit,printtitle,printdetail,printhj这四个过程就行了,

---- (调用格式:printtitle(printer.canvas);)

---- 对了,Qtz就是查询出来的台帐数据,如何生成的这里就不谈了。

---- 具体程序如下

---- 此程序在delphi1,delphi3版本WIN3.2,WIN95,WIN97,WIN98平台下运行通过,顺便提供台帐数据库的库结构

---- 2、非常复杂,无法取巧的报表

---- 我院肿瘤科需要打印病人的病案,这可是特色专科现代化建设的一部分,卫生局要来检查的,所以必须完成任务。每一个病案有100多个项目,若用Qreport,中间如果要加减一个项目(这事常有),几十个项目的调整排列会使人昏倒。我一下子建立100多个临时变量,在虚拟的画布上画啊画,运行在我的PII233,64M内存的机子上倒是顺顺当当的,不过换到肿瘤科的486,8M内存的机子上时(大家别笑),系统堆栈马上溢出,所以只好祭出指针大法(我的编程水平好象又有长进,窃喜),方法如下:

先建立titleprint类:
titleprint=^Titlerecord;
titlerecord=record
Currect:Trect;
Atitle:string[50];
end;
再建立过程printnow(Form的名称叫
zlk,printdot就是打印机的点数,一般针打是180);
procedure Tzlk.printnow(acanvas:Tcanvas);
var i,x,y,pc_count:integer;
myprint:array[0..200] of titleprint;
begin
firsttop:=round(int(0.5/2.54*printdot));
firstleft:=round(int(0.1/2.54*printdot));
rowheight:=round(int(0.7/2.54*printdot));
x:=0+firstleft;y:=round(int
(1.3/2.54*printdot))+firsttop;
pc_count:=0;
inc(pc_count); new(myprint[pc_count]);
myprint[pc_count]^.currect:=rect
(x+round(int(0.1/2.54*printdot))+firstleft,y,
x+round(int(3.0/2.54*printdot))+firstleft,
y+firsttop+round(int(0.5/2.54*printdot)));
myprint[pc_count]^.atitle:=Lname.
caption+DBname.text;
ACanvas.MoveTo(myprint[pc_count]^.
currect.left,
myprint[pc_count]^.currect.top-round
(rowheight/5));
{下面的四行还要重复100多次,基本差不多,
就不都写出来赚稿费了}
inc(pc_count); new(myprint[pc_count]);
myprint[pc_count]^.currect:=scalerect(
myprint[pc_count-1]^.currect,round(int
(2.5/2.54*printdot)),0);
myprint[pc_count]^.atitle:=Lxb.caption+Cxb.text;
ACanvas.LineTo(myprint[i]^.currect.right,
myprint[i]^.currect.top-round(rowheight/5));
.......

{打印}
printtitle(acanvas);
{这个函数就不提供了,表头不要也没关系}
for i:=1 to pc_count do
begin
RectDraw(Acanvas,myprint[i]^.atitle,
myprint[i]^.currect,false,
dt_left or dt_singleline or dt_vcenter);
end;
dispose(myprint[pc_count]);
{别忘了把指针占用的内存释放}
end;

---- 最后建个Botton,加个是否真的打印的判断,再调用这几个函数就行了。
---- (调用格式:printtitle(printer.canvas);)

---- 看了以上两个例子,是不是觉得WINDOWS下的打印其实很简单,就跟你手工画表一样,而且表格内容的位置是居中、居左、还是居右,全由打印内容的Alignment决定,打印格式由内容的Display Format决定,用不着自己去算,方便极了。


本文地址:http://com.8s8s.com/it/it6189.htm