一个简单的小票打印问题(50分)

  • 主题发起人 主题发起人 linlingwei
  • 开始时间 开始时间
L

linlingwei

Unregistered / Unconfirmed
GUEST, unregistred user!
sp_bianma sp_name sp_num sp_price

1001 衣服 2 1.5
1002 帽子 3 2.6

怎样在并口的小票打印机中打印出来,就是pos系统的前台打印。
按下面这种格式打印

---------------------------------------
某某超市 |
|
日期:2004-01-12 |
|
sp_bianma sp_name sp_num sp_price |
1001 衣服 2 1.5 |
1002 帽子 3 2.6 |
|
************************************** | 合计:4.1
欢迎光临 |

那位大虾帮我写一段代码,在下感激不尽,双手送出所有的分。
 
给一例子:
// 向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.Eof do
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
 
to wwwwb:
编译不能通过,我把 F设为string ,提示错误。
 
var
F:TEXTFILE;
 
to wwwwb:
不好意思,这种程序从没有弄过,我把源代码写在下面,你帮我修改一下,我把所有的分
都给你。谢谢!

procedure Tform1.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;


procedure TForm1.Button1Click(Sender: TObject);
var outfile:string;
F,CompanyTitle:TEXTFILE;
begin
// 打印小单
// 输出到文本,稍后再输出到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.Eof do
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); // 输出文件到打印口
end;
 
var outfile,CompanyTitle:string;
F:TEXTFILE;
有什么问题?
 
SysParms 提示出错
 
在哪里出错啊?
 
CompanyTitle:=SysParms.CompanyTitle+'购物清单'; 在此处出错
 
没有引用SysParms单元吧?
 
我加入
uses SysParms 却报错
 
这些代码是整个程序的一部分,只是给你参照一下,你根据自己的需要修改。
 
最好把你的错误信息贴出来
 
直接在File——>Use Unit 选中SysParms 就可以了!
如果你开始就没有引用那个unit就根本选不到!那就先
Project——>Add to Project
 
to 江南大米;
现在调试 通过,就是不输出,
procedure Tform1.PrintFile(AFileToPrint: string);
var
Port, FileToPrint: TextFile;
ALine: string;
begin
AssignFile(FileToPrint, AFileToPrint);
Reset(FileToprint); ######################在此处报错,提示输出 I/O端口错误
但是我的打印机已经接上了。
AssignFile(Port, 'LPT1');
Rewrite(Port);
while not Eof(FileToPrint) do
begin
Readln(FileToPrint, ALine);
Writeln(Port, ALine);
end;
CloseFile(Port);
CloseFile(FileToPrint);
end;


procedure TForm1.Button1Click(Sender: TObject);
var
MerName, outfile,CompanyTitle:string;
F:TEXTFILE;
len,CardPayment:integer;
begin
CardPayment:=1002;
EdCash.Text:=inttostr(22);
STOpID.Caption :='111';
STSaleID.Caption :='2222';
STSaleDate.Caption :='2003-01-01' ;
STHj.Caption :='321';
STRl.Caption :='33';
STSs.Caption :='4343';
STBack.Caption :='333';
// 打印小单
// 输出到文本,稍后再输出到LPT1端口;
OutFile:=ExtractFilePath(Application.ExeName)+'output.txt';
AssignFile(F, OutFile);
Rewrite(F);

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.Eof do
begin
MerName:=ADSSaleList.FieldValues['sp_name'];
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['sp_jj']:2);
Write(F, FormatFloat('0.0', ADSSaleList.FieldValues['sp_pfj']):6);
Writeln(F, FormatFloat('0.0', 5):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); // 输出文件到打印口
end;
 
给你参照一下,简单一点的
var
F:TEXTFILE;
BEGIN
ASSIGNFILE(F,'LPT1');
REWRITE(F);
WRITELN(F,chr(27) '@'); //initial the printer
WRITELN(F,'TEST1 FIRST LINE');
WRITELN(F,chr(12)); // move the paper to a new page
CLOSEFILE(F);
 
感谢 wwwwb 和 江南大米:
问题已经解决了,顺祝春节愉快。
 
后退
顶部