分享
 
 
 

delphi中实现黑标单据的打印(原创)

王朝delphi·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

对于很小的票据,打印起来很难套格式,连续打印时错位会很严重,这样我们可以用黑标检测来解决这个问题,当打印机打印完一张票据时就检测黑标,这样打印机将会停在检测到的黑标后面,打印一下张时将不会跑位。

黑标打印需要的条件:

1、打印机要支持黑标发票。打印说明书中可以查到。

2、行矩要跟据打印机来定,一般打印字体一样时,不同的打印机行矩会一样的。

下面是一个示例:

unit PrintHBUnit;

interface

uses SysUtils, IniFiles, windows, Forms, Dialogs, Classes;

//定义打印的记录类型

type

TPrintObj = record

Hbsbh: string;

Dffsny: string;

Khmc: string;

Khdz: string;

Dbcbh1: string;

Jsbl1: string;

Scbm1: string;

Bcbm1: string;

Dbcbh2: string;

Jsbl2: string;

Scbm2: string;

Bcbm2: string;

Dbcbh3: string;

Jsbl3: string;

Scbm3: string;

Bcbm3: string;

YDFLBH1: string;

YDFLBH2: string;

YDFLBH3: string;

Fldl1: string;

Fldl2: string;

Fldl3: string;

Fldj1: string;

Fldj2: string;

Fldj3: string;

Shdl1: string;

Shdl2: string;

Shdl3: string;

FlDF1: string;

FlDF2: string;

FlDF3: string;

DDDF1: string;

DDDF2: string;

DDDF3: string;

HjDL: string;

HjDF: string;

Scjy: string;

Bcss: string;

Bcxz: string;

Bcjy: string;

Ssdx: string;

Cby: string;

Sky: string;

Fphm: string;

Rq: string;

sswyj: string;

dyqdf : string;

BlackMark: string;

tbdf :string;

dddf:String;//电度电费

fldf:String;

end;

var

PrintObj: TPrintObj;

MyFile: TIniFile;

I:integer;//为1时代表已取电价,否则取电价

mldjList:Tstrings;

ydflbhList:Tstrings;

procedure SetPrintObj;

procedure pdrPrintObj(zs_bz:String='0');

procedure GetBlackMark;

function JeToDx(v_je: real): String;// 报表用的金额大写转换函数

implementation

uses DB;

function JeToDx(v_je: real): String;// 报表用的金额大写转换函数

var

l,i: integer;

je_zs, je_xs, dx, dw, s, s1, dx_je: string;

bFs:boolean;

begin

If v_je=0 Then

Begin

Result:='零元整';

Exit;

End;

if v_je<0 then

begin

bFs:=True;

v_je:=(-1)*v_je;

end

else bFs:=False;

je_zs:='';

je_xs:='';

if round(v_je)*100=v_je*100 then je_zs:=FloatToStr(v_je)

else

begin

s:=FloatToStr(v_je*100);

je_zs:=Copy(s,1,length(s)-2);

je_xs:=Copy(s,length(je_zs)+1,2);

if je_zs='' then je_zs:='00';

if je_xs='' then je_xs:='00';

end;

dx:='零壹贰叁肆伍陆柒捌玖';

dw:='元拾佰仟万拾佰仟亿';

dx_je:='';

if je_zs<>'' then

begin

l:=length(je_zs);

s1:='';

for i:=1 to l do

begin

s:=Copy(dx,StrToInt(Copy(je_zs,i,1))*2+1,2);

if s<>'零' then

begin

dx_je:=dx_je+s;

dx_je:=dx_je+Copy(dw,(l-i)*2+1,2);

end

else if s1<>'零' then dx_je:=dx_je+'零';

if i=(l-4) then

begin

s:=Copy(dx_je,length(dx_je)-1,2);

if s='零' then dx_je:=Copy(dx_je,1,length(dx_je)-2);

if s<>'万' then dx_je:=dx_je+'万';

end;

s1:=s;

end;

s:=Copy(dx_je,length(dx_je)-1,2);

if s='零' then dx_je:=Copy(dx_je,1,length(dx_je)-2);

if s<>'元' then dx_je:=dx_je+'元';

end;

if je_xs='' then dx_je:=dx_je+'整'

else

begin

if Copy(je_xs,1,1)<>'0' then

begin

if Copy(je_xs,2,1)<>'0' then

begin

if length(je_xs)=1 then je_xs:='0'+je_xs;

dx_je:=dx_je+Copy(dx,StrToInt(Copy(je_xs,1,1))*2+1,2)+'角';

dx_je:=dx_je+Copy(dx,StrToInt(Copy(je_xs,2,1))*2+1,2)+'分';

end

else dx_je:=dx_je+Copy(dx,StrToInt(Copy(je_xs,1,1))*2+1,2)+'角整';

end

else

begin

dx_je:=dx_je+'零'+Copy(dx,StrToInt(Copy(je_xs,2,1))*2+1,2)+'分';

end;

end;

if copy(dx_je,1,2)='元' then dx_je:='零'+dx_je;

if bFs then dx_je:='负'+dx_je;

Result:=dx_je;

end;

procedure GetBlackMark;

var

BlackMark: string;

begin

//从INI文件中读取黑票类型

MyFile := Tinifile.create(ExtractFilePath(Application.ExeName)+'ydgl.ini');

try

BlackMark := MyFile.ReadString('Print', 'PrintType', '');

if Length(BlackMark) <> 0 then

PrintObj.BlackMark := BlackMark

else

begin

Application.MessageBox('已自动配置ydgl.ini文件,默认打印机类型为:BS-310K,请检查!', '提示', MB_OK);

MyFile.WriteString('Print', 'PrintType', 'BS-310K');

end;

finally

MyFile.Free;

end;

end;

procedure SetPrintObj;

begin

with PrintObj do

begin

Hbsbh := '0123456789';

Dffsny := '200401';

Khmc := '测试用户';

Khdz := '南昌市';

Dbcbh1 := 'A0001';

Jsbl1 := '1';

Scbm1 := '100';

Bcbm1 := '150';

Dbcbh2 := 'A0002';

Jsbl2 := '1';

Scbm2 := '10';

Bcbm2 := '110';

Dbcbh3 := '';

Jsbl3 := '';

Scbm3 := '';

Bcbm3 := '';

Fldl1 := '150';

Fldl2 := '';

Fldl3 := '';

Fldj1 := '0.50';

Fldj2 := '';

Fldj3 := '';

Shdl1 := '';

Shdl2 := '';

Shdl3 := '';

FlDF1 := '75.00';

FlDF2 := '';

FlDF3 := '';

DDDF1 := '75.00';

DDDF2 := '';

DDDF3 := '';

HjDL := '150';

HjDF := '75.00';

Scjy := '0';

Bcss := '100.00';

Bcxz := '75.00';

Bcjy := '25.00';

Ssdx := '壹佰元整';

Cby := '小王';

Sky := '小李';

Fphm := '001';

Rq := '2004-01-30';

sswyj:='0';

dyqdf:='';

dddf:='';

fldf:='';

end;

end;

procedure pdrPrintObj(zs_bz:String='0');

var

lpt: TextFile;

str,Other:String;

begin

AssignFile(lpt, 'LPT1');

try

ReWrite(lpt);

with PrintObj do

begin

BlackMark:='SP512MC';

if UpperCase(BlackMark)=UpperCase('SP512MC') then

begin

Writeln(lpt, '');

Writeln(lpt, Format(' %S', [sswyj]));

Writeln(lpt, Format(' %S %S', [Hbsbh, dffsny]));

Writeln(lpt, Format(' %S', [Khmc]));

Writeln(lpt, Format(' %S', [Khdz]));

Writeln(lpt, Format(' %-11S%-11S%-11S', [Dbcbh1,Dbcbh2,Dbcbh3]));

Writeln(lpt, Format(' %-11S%-11S%-11S', [Jsbl1,Jsbl2,Jsbl3]));

Writeln(lpt, Format(' %-11S%-11S%-11S', [Scbm1,Scbm2,Scbm3]));

Writeln(lpt, Format(' %-11S%-11S%-11S', [Bcbm1,Bcbm2,Bcbm3]));

Writeln(lpt, '');

Writeln(lpt, Format('%-11S%-11S%-11S%S', [Fldl1, Shdl1, Fldj1,

Fldf1]));

Writeln(lpt, Format('%-11S%-11S%-11S%S', [Fldl2, Shdl2, Fldj2,

Fldf2]));

Writeln(lpt, Format('%-11S%-11S%-11S%S', [Fldl3, Shdl3, Fldj3,

Fldf3]));

Writeln(lpt, Format(' %-20S%S', [Hjdl, Hjdf]));

//zs_bz:走收标致"1"为走收,"0"非走收

if zs_bz='0' then

begin

Writeln(lpt, Format(' %-20S%S', [Scjy, Bcss]));

Writeln(lpt, Format(' %-20S%S', [Bcxz, Bcjy]));

Writeln(lpt, Format(' %S', [Ssdx]));

end

else

begin

Writeln(lpt, Format(' %-20S%S', ['', Hjdf]));

Writeln(lpt, Format(' %-20S%S', [Hjdf, '']));

Writeln(lpt, Format(' %S', [JeToDx(StrToFloatDef(Hjdf,0))]));

end;

Writeln(lpt, Format(' %-15S%-15S%S', [Cby, Sky, Rq]));

Writeln(lpt, '');

Writeln(lpt, Format(' %S', [Fphm]));

Writeln(lpt, Format(' %-24S%S', [Hbsbh, dffsny]));

if zs_bz='0' then

begin

Writeln(lpt, Format(' %-24S%S', [Bcss, Bcjy]));

end

else

begin

Writeln(lpt, Format(' %-24S%S', [Hjdf+JeToDx(StrToFloatDef(Hjdf,0)), '']));

end;

Writeln(lpt, Format(' %-23S%S', [Sky, Rq]));

//发送黑标指令

Write(lpt, #12);

end

end;

finally

CloseFile(lpt);

end;

end;

end.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有