📄 gzlr_unit.pas
字号:
dbc_xl.Text := '';
end;
procedure Tgzlr.dbc_byxxChange(Sender: TObject);
begin
if dbc_byxx.Text = '无' then
dbc_byxx.Text := '';
end;
procedure Tgzlr.dbc_zyChange(Sender: TObject);
begin
if dbc_zy.Text = '无' then
dbc_zy.Text := '';
end;
procedure Tgzlr.Button5Click(Sender: TObject);
const
LeftBlank = 0;
RightBlank = 0;
TopBlank = 1;
ButtomBlank = 1;
//定义四周的页边距,单位厘米
var
PointX, PointY: integer;
PointScale, PrintStep, printwidth: integer;
s: string;
x, y, x1, y1, yyy, y_top: integer;
i, j, z: integer;
zdm: array[0..150] of string;
zdm_str: array[0..1500] of string;
lm: array[0..100] of string;
fenge_bz: array[0..150] of integer;
gao_bo: array[0..150] of integer;
str_top_str: string;
line_w, str_ls, str_all, str_top, str_down, fenge, str_top_width, aaa: integer;
col_width, prt_all, printsetup, prt_cen, prt_fir: integer;
ii, ij, LineNum, iTemp, HanziNum, WordSpace, gs: integer;
szTemp, text: string;
// )))))))))))))))))))
begin
if not table2.Active then
begin
Application.MessageBox('请查找数据', '提示', 32);
exit;
end;
if table2.RecordCount = 0 then
begin
Application.MessageBox(' 无可打印数据', '提示', 32);
exit;
end;
///////////////////////////////////////////////////////////////////////////////////
printer.Canvas.Font.Name := '宋体';
printer.canvas.Font.Size := 10;
//根据字体的大小确定每行的高度
s := 's';
Printwidth := printer.canvas.TextWidth(s);
line_w := 0;
str_ls := 0;
str_all := 0;
STR_TOP := 0;
STR_DOWN := 0;
fenge := 0;
j := 0;
for i := 0 to dbgrideh1.Columns.Count - 1 do
begin
if dbgrideh1.Columns[i].Visible then
begin
// zdm[j] := dbgrideh1.Columns[i].FieldName;
// zdm_str[j] := dbgrideh1.Columns[i].Title.Caption;
// lm[j] := inttostr(i);
line_w := line_w + dbgrideh1.Columns.Items[i].width;
str_ls := pos('|', dbgrideh1.Columns[i].Title.Caption);
if str_ls > 0 then
begin
fenge := fenge + 1;
if fenge = 1 then
begin
fenge_bz[j] := 1;
if str_top < str_ls - 1 then
str_top := str_ls - 1;
str_top_str := copy(dbgrideh1.Columns[i].Title.Caption, 1, str_ls - 1);
str_top_width := dbgrideh1.Columns.Items[i].width;
gao_bo[j] := trunc((strlen(pchar(dbgrideh1.Columns[i].Title.Caption)) - str_ls) * printwidth / dbgrideh1.Columns.Items[i].width) + 1;
end
else
begin
if str_top_str = copy(dbgrideh1.Columns[i].Title.Caption, 1, str_ls - 1) then
begin
fenge_bz[j] := 1;
str_top_width := str_top_width + dbgrideh1.Columns.Items[i].width;
if gao_bo[j - 1] < trunc((strlen(pchar(dbgrideh1.Columns[i].Title.Caption)) - str_ls) * printwidth / dbgrideh1.Columns.Items[i].width) + 1 then
begin
aaa := trunc((strlen(pchar(dbgrideh1.Columns[i].Title.Caption)) - str_ls) * printwidth / dbgrideh1.Columns.Items[i].width) + 1;
// application.MessageBox(pchar(inttostr(gao_bo[j - 1])),'111111111111111');
// application.MessageBox(pchar(inttostr(aaa)),'aaaaaaaaaaaaaaaaaaaaaaaa');
gao_bo[j] := aaa;
gao_bo[j - 1] := aaa;
for z := 0 to fenge - 1 do
gao_bo[j - z] := trunc((strlen(pchar(dbgrideh1.Columns[i].Title.Caption)) - str_ls) * printwidth / dbgrideh1.Columns.Items[i].width) + 1;
// application.MessageBox(pchar(dbgrideh1.Columns[i].Title.Caption),'aa');
end
else
gao_bo[j] := gao_bo[j - 1];
end
else
begin
str_top_str := copy(dbgrideh1.Columns[i].Title.Caption, 1, str_ls - 1);
gao_bo[j] := trunc((strlen(pchar(dbgrideh1.Columns[i].Title.Caption)) - str_ls) * printwidth / dbgrideh1.Columns.Items[i].width) + 1;
str_top := trunc(strlen(pchar(str_top_str)) * printwidth / str_top_width) + 1;
fenge := 1;
fenge_bz[j] := 1;
fenge_bz[j - 1] := 1;
end;
end;
if str_down < trunc((strlen(pchar(dbgrideh1.Columns[i].Title.Caption)) - str_ls) * printwidth / dbgrideh1.Columns.Items[i].width) + 1 then
str_down := trunc((strlen(pchar(dbgrideh1.Columns[i].Title.Caption)) - str_ls) * printwidth / dbgrideh1.Columns.Items[i].width) + 1;
end
else
begin
if str_all < strlen(pchar(dbgrideh1.Columns[i].Title.Caption)) then
str_all := strlen(pchar(dbgrideh1.Columns[i].Title.Caption));
if fenge > 0 then
begin
fenge_bz[j - 1] := 1;
str_top := trunc(strlen(pchar(str_top_str)) * printwidth / str_top_width) + 1;
fenge := 0;
end;
end;
j := j + 1;
end;
end;
// for z := 0 to j - 1 do
// memo1.Lines.Add(inttostr(gao_bo[z]));
// button4.Caption := inttostr(printwidth) + ' ' + inttostr(str_top) + ' ' + inttostr(str_down) + ' ' + inttostr(str_all);
//
p.Execute;
//////////////////////////////////////////////////////////////////////////////////
//获取当前打印机的分辨率
PointX := Trunc(GetDeviceCaps(Printer.Handle, LOGPIXELSX) / 2.54);
PointY := Trunc(GetDeviceCaps(Printer.Handle, LOGPIXELSY) / 2.54);
//根据打印机和屏幕的分辨率计算出从屏幕转换到打印机的比例
PointScale := Trunc(GetDeviceCaps(Printer.Handle, LOGPIXELSX) / Screen.PixelsPerInch + 0.5);
//设置打印机横向打印
// printer.Orientation := poLandscape;
printer.Orientation := poportrait; //poLandscape; //poportrait为纵向;
//设置打印机打印的 字体和大小
printer.Canvas.Font.Name := '宋体';
printer.canvas.Font.Size := 10;
//根据字体的大小确定每行的高度
s := 'Some Famous Corp.';
PrintStep := printer.canvas.TextHeight(s) + 0;
//设置打印的起点位置
x := PointX * LeftBlank;
y := PointY * topblank;
////////////
yyy := 0;
y1 := y;
x1 := x;
printer.BeginDoc;
table2.First;
with table2 do
while not eof do
begin
yyy := yyy + 1;
prt_all := str_all * printsetup; //表头总高度
prt_cen := trunc(prt_all / 2);
j := -1;
y_top := y1 + printer.canvas.TextHeight(s) * str_all;
for i := 0 to dbgrideh1.Columns.Count - 1 do
begin
if dbgrideh1.Columns[i].Visible then
begin
y := y1;
//x := PointX * LeftBlank;
// y := PointY * topblank;
j := j + 1;
str_ls := pos('|', dbgrideh1.Columns[i].Title.Caption);
if str_ls = 0 then
text := dbgrideh1.Columns[i].Title.Caption;
if str_ls > 0 then
begin
text := copy(dbgrideh1.Columns[i].Title.Caption, 1, str_ls - 1) + copy(dbgrideh1.Columns[i].Title.Caption, str_ls + 1, strlen(pchar(dbgrideh1.Columns[i].Title.Caption)) - str_ls);
end;
col_width := dbgrideh1.Columns[i].Width;
y := y1;
if gao_bo[j] >= 0 then //为不折行情况
begin
y := y1;
//画格
// showmessage('ajhsd');
Printer.Canvas.Rectangle(x, y, x + col_Width * PointScale, y + printer.canvas.TextHeight(s) * str_all);
//下面开始分析字符排版格式及打印
// showmessage(dbgrideh1.Columns[i].Title.Caption + ' ' +inttostr(strlen(pchar(text)) * Printwidth)+' '+ inttostr(col_width));
if printer.Canvas.TextWidth(pchar(text)) <= col_width * PointScale - 16 then //不折行
begin
// showmessage(dbgrideh1.Columns[i].Title.Caption + ' 55555555 ' + inttostr(col_width * PointScale) + ' ' + inttostr(printer.Canvas.TextWidth(pchar(text))));
// Printer.Canvas.TextOut(x, y , text);
Printer.Canvas.TextOut(x, y + trunc((printer.canvas.TextHeight(s) * (str_all - 1)) / 2), text);
x := x + col_Width * PointScale;
// memo1.Lines.Add(text + 'bb ' + inttostr(y + trunc((printer.canvas.TextHeight(s) * (str_all - 1)) / 2)));
end
else //折行情况
begin
if col_width >= 0 then
begin
//分析折行组数
WordSpace := trunc((col_width * PointScale - 10) / printer.Canvas.TextWidth('ss'));
/// showmessage(dbgrideh1.Columns[i].Title.Caption + ' 55555555 ' + inttostr(wordspace) + ' ' + inttostr(printer.Canvas.TextWidth(pchar(text))));
if wordspace = 0 then
begin
wordspace := 2;
gs := 1;
end
else
begin
gs := wordspace;
wordspace := wordspace * 2;
end;
prt_fir := trunc((printer.canvas.TextHeight('s') * (str_all - (strlen(pchar(text)) / 2) / gs) / 2));
ii := 0; LineNum := 0; ij := 1;
HanziNum := 0;
repeat
ii := ii + 2;
szTemp := copy(text, ij, ii - ij + 1);
itemp := itemp + 2;
if (ii >= wordspace) and (itemp mod wordspace = 0) and (ii <= length(Text)) then
begin
if ii = wordspace then
y := y; //+ prt_fir;
szTemp := Copy(Text, ij, ii - ij + 1);
ij := ii + 1;
LineNum := LineNum + 1;
if LineNum > 1 then y := Y + printstep;
Printer.Canvas.TextOut(x + 2, y + prt_fir, sztemp);
itemp := 0; HanziNum := 0;
// memo1.Lines.Add(sztemp + ' ' + inttostr(y + prt_fir));
end;
if (ii > strlen(pchar(text))) and (ij < strlen(pchar(text))) then
begin
szTemp := Copy(Text, ij, strlen(pchar(text)) - ij + 1);
Printer.Canvas.TextOut(x + 2, y + prt_fir, sztemp);
// memo1.Lines.Add(sztemp + 'aaa' + inttostr(y + prt_fir));
end;
until ii > length(Text);
x := x + col_Width * PointScale;
end;
end;
end;
end;
end;
x1 := PointX * LeftBlank;
y1 := y_top;
for i := 0 to dbgrideh1.Columns.Count - 1 do
begin
if dbgrideh1.Columns[i].Visible then
begin
Printer.Canvas.MoveTo(x1, y1 + 2 * PrintStep);
Printer.Canvas.LineTo(x1 + DBGrideh1.columns.Items[i].Width * PointScale, y1 + 2 * PrintStep);
Printer.Canvas.Rectangle(x1, y1, x1 + DBGrideh1.columns.Items[i].Width * PointScale, y1 + 2 * PrintStep);
Printer.Canvas.TextOut(x1 + 16, y1 + printsetup + 10, DBGrideh1.Fields[i].asString);
x1 := x1 + DBGrideh1.Columns.Items[i].Width * PointScale;
end;
end;
y1 := y_top + 80;
if (y1 + printer.canvas.TextHeight(s) * str_all + 2 * printsetup) > (Printer.PageHeight - PointY * ButtomBlank) then
begin
Printer.NewPage;
y1 := PointY * topblank;
end;
x := PointX * LeftBlank;
// y1 := y1 +printsetup;
table2.next;
end;
printer.EndDoc;
Application.MessageBox('打印完成', '打印', 32);
end;
procedure Tgzlr.DateEdit2Change(Sender: TObject);
begin
table2.edit;
table2['a13'] := copy(dateedit2.Text, 1, 7)
end;
procedure Tgzlr.rdte_rq1Change(Sender: TObject);
begin
table2.edit;
table2['a12'] := copy(dateedit1.Text, 1, 7)
end;
procedure Tgzlr.dateedit3Change(Sender: TObject);
begin
table2.edit;
table2['a14'] := copy(dateedit3.Text, 1, 7)
end;
procedure Tgzlr.dbc_jszwExit(Sender: TObject);
var
xsmc: string;
i, fx: integer;
begin
fx := 0;
xsmc := dbc_jszw.Text;
if xsmc <> '无' then
begin
for i := 0 to dbc_jszw.Items.Count do
if xsmc = dbc_jszw.Items[i] then
fx := 1;
end;
if fx = 0 then
begin
tb_jszw.Open;
tb_jszw.Append;
tb_jszw.Edit;
tb_jszw['jszwmc'] := xsmc;
tb_jszw.post;
tb_jszw.Close;
dbc_jszw.Items.Add(xsmc);
end;
end;
procedure Tgzlr.dbc_zwExit(Sender: TObject);
var
xsmc: string;
i, fx: integer;
begin
fx := 0;
xsmc := dbc_zw.Text;
if xsmc <> '无' then
begin
for i := 0 to dbc_zw.Items.Count do
if xsmc = dbc_zw.Items[i] then
fx := 1;
end;
if fx = 0 then
begin
tb_zw.Open;
tb_zw.Append;
tb_zw.Edit;
tb_zw['zwmc'] := xsmc;
tb_zw.post;
tb_zw.Close;
dbc_zw.Items.Add(xsmc);
end;
end;
procedure Tgzlr.dbc_whcdChange(Sender: TObject);
begin
if dbc_whcd.Text = '无' then
dbc_whcd.Text := '';
end;
procedure Tgzlr.dbc_whcdExit(Sender: TObject);
var
xsmc: string;
i, fx: integer;
begin
fx := 0;
xsmc := dbc_whcd.Text;
if xsmc <> '无' then
begin
for i := 0 to dbc_whcd.Items.Count do
if xsmc = dbc_whcd.Items[i] then
fx := 1;
end;
if fx = 0 then
begin
tb_whcd.Open;
tb_whcd.Append;
tb_whcd.Edit;
tb_whcd['whcdmc'] := xsmc;
tb_whcd.post;
tb_whcd.Close;
dbc_whcd.Items.Add(xsmc);
end;
end;
procedure Tgzlr.dbc_byxxExit(Sender: TObject);
var
xsmc: string;
i, fx: integer;
begin
fx := 0;
xsmc := dbc_byxx.Text;
if xsmc <> '无' then
begin
for i := 0 to dbc_byxx.Items.Count do
if xsmc = dbc_byxx.Items[i] then
fx := 1;
end;
if fx = 0 then
begin
tb_byxx.Open;
tb_byxx.Append;
tb_byxx.Edit;
tb_byxx['byxxmc'] := xsmc;
tb_byxx.post;
tb_byxx.Close;
dbc_byxx.Items.Add(xsmc);
end;
end;
procedure Tgzlr.dbc_zyExit(Sender: TObject);
var
xsmc: string;
i, fx: integer;
begin
fx := 0;
xsmc := dbc_zy.Text;
if xsmc <> '无' then
begin
for i := 0 to dbc_zy.Items.Count do
if xsmc = dbc_zy.Items[i] then
fx := 1;
end;
if fx = 0 then
begin
tb_zy.Open;
tb_zy.Append;
tb_zy.Edit;
tb_zy['zymc'] := xsmc;
tb_zy.post;
tb_zy.Close;
dbc_zy.Items.Add(xsmc);
end;
end;
procedure Tgzlr.dbc_gwChange(Sender: TObject);
begin
if dbc_gw.Text = '无' then
dbc_gw.Text := '';
end;
procedure Tgzlr.dbc_gwExit(Sender: TObject);
var
xsmc: string;
i, fx: integer;
begin
fx := 0;
xsmc := dbc_gw.Text;
if xsmc <> '无' then
begin
for i := 0 to dbc_gw.Items.Count do
if xsmc = dbc_gw.Items[i] then
fx := 1;
end;
if fx = 0 then
begin
tb_gw.Open;
tb_gw.Append;
tb_gw.Edit;
tb_gw['gwmc'] := xsmc;
tb_gw.post;
tb_gw.Close;
dbc_gw.Items.Add(xsmc);
end;
end;
procedure Tgzlr.dbc_xlExit(Sender: TObject);
begin
if dbc_xl.Text = '无' then
dbc_xl.Text := '';
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -