// 向LPT口打印一个文本文件
procedure TPosFrm.PrintFile(AFileToPrint: string);
var
Port, FileToPrint: TextFile;
ALine: string;
begin
AssignFile(FileToPrint, AFileToPrint);
Reset(FileToprint);
AssignFile(Port, 'LPT1');
Rewrite(Port);
while not Eof(FileToPrint)do
begin
Readln(FileToPrint, ALine);
Writeln(Port, ALine);
end;
CloseFile(Port);
CloseFile(FileToPrint);
end;
// 打印小单
// 输出到文本,稍后再输出到LPT1端口;
OutFile:=ExtractFilePath(Application.ExeName)+'output.txt';
AssignFile(F, OutFile);
Rewrite(F);
CompanyTitle:=SysParms.CompanyTitle+'购物清单';
CompanyTitle:=StringOfChar(' ', (32-Length(CompanyTitle)) div 2)+CompanyTitle;
Writeln(F, CompanyTitle);
Writeln(F,'--------------------------------');
// Writeln(F,'收银机:'+EdPosID.Text+' 单号:'+EdSaleID.Text);
// Writeln(F,'收银员:'+EdOpID.Text+ ' 日期:'+EdSaleDate.Text);
Write(F,'收银员:', Format('%-10s', [STOpID.Caption]));
Writeln(F, '单号:'+STSaleID.Caption);
Writeln(F,'日期:'+STSaleDate.Caption+ ' 时间:'+FormatDateTime('hh:mm:ss', Now));
Writeln(F,'--------------------------------');
// 12345678901234567890123456789012
Writeln(F,'商品名称 数量 单价 金额');
ADSSaleList.DisableControls;
ADSSaleList.First;
while not ADSSaleList.Eofdo
begin
MerName:=ADSSaleList.FieldValues['MerName'];
len:=Length(MerName);
if len < 18 then
MerName:=MerName+StringOfChar(' ', 18-len);
if (len mod 2) = 0 then
Write(F, Copy(MerName, 1, 18))
else
Write(F, (Copy(MerName, 1, 17)+' '):18);
Write(F, ADSSaleList.FieldValues['Qty']:2);
Write(F, FormatFloat('0.0', ADSSaleList.FieldValues['Price']):6);
Writeln(F, FormatFloat('0.0', ADSSaleList.FieldValues['Amount']):6);
ADSSaleList.Next;
end;
ADSSaleList.EnableControls;
Writeln(F,'--------------------------------');
Writeln(F,'合计:',STHj.Caption:8, ' 让利:', STRl.Caption:8);
Writeln(F,'实收:',STSs.Caption:8, ' 金卡:',
FormatCurr('0.00', CardPayment):8
);
Writeln(F,'现金:',
FormatCurr('0.00', StrToCurr(EdCash.Text)-CardPayment):8,
' 找补:', STBack.Caption:8
);
Writeln(F,' ');
//空行,添加或减少空行即可控制出纸多少。
...
PrintFile(Outfile);
// 输出文件到打印口
输出如下例:
XX化妆品世界购物清单
--------------------------------
收银员:01 单号:000000329
日期:2003-07-16 时间:17:53:28
--------------------------------
商品名称 数量 单价 金额
8g华美健强力消痘乳 4 16.0 64.0
小口红 1 5.0 5.0
180g隆力奇蛇胆不紧 3 20.8 62.4
速效脱毛露 2 7.5 15.0
美容海藻面膜 3 18.0 54.0
蕾琪唇彩 1 12.0 12.0
.....
--------------------------------
合计: 2058.40 让利: 0.00
实收: 2058.40 金卡: 0.00
现金: 2100.00 找补: 41.60
因宽度只有58mm,故商品名切去部分。