Computer Room, Wuxi Traditional Chinese Medicine Hospital, Jiangsu Province
Yuan Bo
----The information management system of our hospital uses Delphi programming. Since the requirements of each subject are different and the report forms are also diverse, it is a headache to write. Delphi runs under the WINDOWS platform, and printing is completely different from that under DOS. Quick Report is difficult to control and takes up resources. For a slightly complex report with special requirements, Quick Report cannot be realized. Here are some implementation methods for typical reports encountered in programming.
---- 1. The finance department of any unit has several thick ledgers. The finance department of our hospital proposed to print the ledger of the medicine warehouse so as to get rid of the manual ledger. It can be regarded as a modernization of the office. The request is reasonable, dean It is also said that it should be so. Looking at the small red and green cards provided by the Finance Department, uniformly printed, and with a line spacing of 3 mm, I couldn't help but think of the virtue of frugality of the Chinese people. Considering that each drug must be printed at least once, and not a single table line is missing. In addition, there are more than 2,000 kinds of drugs in the traditional Chinese medicine hospital, so this report must be printed with a laser printer (as for how to get the dean to agree to purchase a laser printer, then It’s another thing. How can office automation be without cost?) The idea of implementing the program is basically to use the printing paper as a canvas to draw small rectangles on it, which is specifically implemented by the following processes: (Let the Form be named Ttzview).
First define two classes in the program:
titlerecord=record
Currect:Trect;
Atitle:string;
end;
detailrecord=record
Arect:Trect;
alignment:Word;
end;
---- Establish the following four processes;
---- RectDraw(Acanvas:Tcanvas;s:string;R:Trect;frame:boolean;position:word);
---- This process is used to draw a rectangle, and the frame determines whether to draw a line (of course it must be drawn here!);
----PRintinitit(firsttop,firstleft:integer);
---- This process is used for initialization, which is to define the position of each small rectangle on the paper;
---- printtitle(acanvas:Tcanvas);
----This process is to print the header, because the characters in the header are always larger;
---- printdetail(acanvas:Tcanvas;Qtz:Tdataset;acount:integer;firstpage:integer);
----This process is to print the specific content. One page prints 40 lines. If it is not enough, change the page. In short, one page can only be one medicine;
---- printhj(acanvas:Tcanvas);
---- You can tell at a glance that this process is to print the total!
---- Just create a Botton and call the four processes of printinitit, printtitle, printdetail, and printhj in sequence.
---- (Calling format: printtitle(printer.canvas);)
---- By the way, Qtz is the ledger data queried. How to generate it will not be discussed here.
----The specific procedures are as follows
---- This program runs under delphi1, delphi3 versions WIN3.2, WIN95, WIN97, and WIN98 platforms. By the way, it provides the library structure of the ledger database.
---- 2. Very complex and incomprehensible reports
---- The Oncology Department of our hospital needs to print patient medical records. This is part of the modernization of specialty specialties. The Health Bureau will come to inspect, so the task must be completed. Each medical record has more than 100 items. If you use Qreport, if you need to add or subtract an item in the middle (this happens often), the adjustment and arrangement of dozens of items will make people faint. I created more than 100 temporary variables at once and drew on the virtual canvas. It ran smoothly on my PII233 machine with 64M memory, but when I switched to the oncology department's machine with 486.8M memory (Don’t laugh, everyone), the system stack will overflow immediately, so I have to resort to the pointer method (my programming level seems to have improved again, secretly happy), the method is as follows:
First create the titleprint class:
titleprint=^Titlerecord;
titlerecord=record
Currect:Trect;
Atitle:string[50];
end;
Then create the process printnow (the name of the Form is
zlk, printdot are the dots of the printer, generally 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));
{The following four lines will be repeated more than 100 times, which is basically the same.
I don’t write them all to earn royalties}
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));
.......
{Print}
printtitle(acanvas);
{This function will not be provided, it doesn’t matter if you don’t need the header}
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]);
{Don’t forget to release the memory occupied by the pointer}
end;
---- Finally, create a Botton, add a judgment whether it is really printed, and then call these functions.
---- (Calling format: printtitle(printer.canvas);)
---- After reading the above two examples, do you think that printing under WINDOWS is actually very simple, just like drawing a table by hand, and whether the position of the table content is centered, left, or right depends entirely on the Alignment of the printed content. The printing format is determined by the Display Format of the content. You don’t have to calculate it yourself, which is very convenient.