以下足彩投注单打印程序哪里出错?(50分)

  • 主题发起人 主题发起人 TENTODBV
  • 开始时间 开始时间
T

TENTODBV

Unregistered / Unconfirmed
GUEST, unregistred user!
哥哥让我帮他写个足彩投注单打印程序。数据源是文本文件,每行一个单注
3101030300310
3333111100003
3333333333333
1111111111111
0000000000000
......
生成的投注单不是直接打印文本,而是根据文本打印图形。投注单是这样的:每单有5栏,每栏有13行3列共39个打印位置。投注单纵向送入打印机,打印机根据每注的13场的结果而涂黑相应位置,就像标准化答题卡那样。每页打印5注。
我的实现方法是这样的:在QReport报表加入39个QRShape控件,分布位置见下图。把投注文本导入ADOQuery1中,然后打印ADOQuery1中的数据。需要涂黑的位置用类似这样的代码实现涂黑:QRShape1.Pen.Color:=clBlack;
实际的投注单的涂黑位置是像标准化答题卡那样细长形的,所以只能用图形形式打印,而不能用我下面给出的示例那样用全角字符■□来表示。实际打印时只需要打印涂黑位置即可,我为了说明问题而加注的1-13,1-3得数字和第X栏的文字不用打印。
-----------------------------
13121110 9 8 7 6 5 4 3 2 1 QReport报表控件摆放位置示意图
□□■□□■□■□□□□■ 3 QRShape13 QRShape12 ... QRShape1
□■□□□□□□□■□■□ 1 第一栏 QRShape26 QRShape25 ... QRShape14
■□□■■□■□■□■□□ 0 QRShape39 QRShape38 ... QRShape27
-----------------------------
13121110 9 8 7 6 5 4 3 2 1
■□□□□□□□□■■■■ 3
□□□□□■■■■□□□□ 1 第二栏
□■■■■□□□□□□□□ 0
-----------------------------
13121110 9 8 7 6 5 4 3 2 1
■■■■■■■■■■■■■ 3
□□□□□□□□□□□□□ 1 第三栏
□□□□□□□□□□□□□ 0
-----------------------------
13121110 9 8 7 6 5 4 3 2 1
□□□□□□□□□□□□□ 3
■■■■■■■■■■■■■ 1 第四栏
□□□□□□□□□□□□□ 0
-----------------------------
13121110 9 8 7 6 5 4 3 2 1
□□□□□□□□□□□□□ 3
□□□□□□□□□□□□□ 1 第五栏
■■■■■■■■■■■■■ 0
-----------------------------
我的程序代码如下:
程序存在一个重大错误:打印出来的投注单每注都是数据集中的最后一注。请问代码错在哪?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, DB, ADODB;
type
TForm1 = class(TForm)
Button1: TButton;
RichEdit1: TRichEdit;
ADOQuery1: TADOQuery;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
SL1:TStringList;
i:integer;
txtline:string;
begin
SL1:=TStringList.Create;
SL1.Add('3101030300310');
SL1.Add('3333111100003');
SL1.Add('3333333333333');
SL1.Add('1111111111111');
SL1.Add('0000000000000');
with ADOQuery1do
begin
ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+ExtractFilePath(Application.ExeName)+'printset.mdb';
SQL.Clear;
SQL.Add('delete from touzhu');
ExecSQL;
close;
SQL.Clear;
SQL.Add('select line from touzhu');
open;
end;

for i:=0 to SL1.Count-1do
begin
ADOQuery1.Append;
ADOQuery1.Fields[0].Value:=SL1;
ADOQuery1.Post;
end;

with ADOQuery1.Recordsetdo
begin
while not Eofdo
begin
txtline:=Fields[0].Value;
//第1场
if txtline[1]='3' then
begin
Form2.QRShape1.Pen.Color:=clBlack;
Form2.QRShape14.Pen.Color:=clWhite;
Form2.QRShape27.Pen.Color:=clWhite;
end
else
if txtline[1]='1' then
begin
Form2.QRShape14.Pen.Color:=clBlack;
Form2.QRShape1.Pen.Color:=clWhite;
Form2.QRShape27.Pen.Color:=clWhite;
end
else
if txtline[1]='0' then
begin
Form2.QRShape27.Pen.Color:=clBlack;
Form2.QRShape1.Pen.Color:=clWhite;
Form2.QRShape14.Pen.Color:=clWhite;
end;

//第2场
if txtline[2]='3' then
begin
Form2.QRShape2.Pen.Color:=clBlack;
Form2.QRShape15.Pen.Color:=clWhite;
Form2.QRShape28.Pen.Color:=clWhite;
end
else
if txtline[2]='1' then
begin
Form2.QRShape15.Pen.Color:=clBlack;
Form2.QRShape2.Pen.Color:=clWhite;
Form2.QRShape28.Pen.Color:=clWhite;
end
else
if txtline[2]='0' then
begin
Form2.QRShape28.Pen.Color:=clBlack;
Form2.QRShape2.Pen.Color:=clWhite;
Form2.QRShape15.Pen.Color:=clWhite;
end;

//第3场
if txtline[3]='3' then
begin
Form2.QRShape3.Pen.Color:=clBlack;
Form2.QRShape16.Pen.Color:=clWhite;
Form2.QRShape29.Pen.Color:=clWhite;
end
else
if txtline[3]='1' then
begin
Form2.QRShape16.Pen.Color:=clBlack;
Form2.QRShape3.Pen.Color:=clWhite;
Form2.QRShape29.Pen.Color:=clWhite;
end
else
if txtline[3]='0' then
begin
Form2.QRShape29.Pen.Color:=clBlack;
Form2.QRShape3.Pen.Color:=clWhite;
Form2.QRShape16.Pen.Color:=clWhite;
end;

//第4场
if txtline[4]='3' then
begin
Form2.QRShape4.Pen.Color:=clBlack;
Form2.QRShape17.Pen.Color:=clWhite;
Form2.QRShape30.Pen.Color:=clWhite;
end
else
if txtline[4]='1' then
begin
Form2.QRShape17.Pen.Color:=clBlack;
Form2.QRShape4.Pen.Color:=clWhite;
Form2.QRShape30.Pen.Color:=clWhite;
end
else
if txtline[4]='0' then
begin
Form2.QRShape30.Pen.Color:=clBlack;
Form2.QRShape4.Pen.Color:=clWhite;
Form2.QRShape17.Pen.Color:=clWhite;
end;

//第5场
if txtline[5]='3' then
begin
Form2.QRShape5.Pen.Color:=clBlack;
Form2.QRShape18.Pen.Color:=clWhite;
Form2.QRShape31.Pen.Color:=clWhite;
end
else
if txtline[5]='1' then
begin
Form2.QRShape18.Pen.Color:=clBlack;
Form2.QRShape5.Pen.Color:=clWhite;
Form2.QRShape31.Pen.Color:=clWhite;
end
else
if txtline[5]='0' then
begin
Form2.QRShape31.Pen.Color:=clBlack;
Form2.QRShape5.Pen.Color:=clWhite;
Form2.QRShape18.Pen.Color:=clWhite;
end;

//第6场
if txtline[6]='3' then
begin
Form2.QRShape6.Pen.Color:=clBlack;
Form2.QRShape19.Pen.Color:=clWhite;
Form2.QRShape32.Pen.Color:=clWhite;
end
else
if txtline[6]='1' then
begin
Form2.QRShape19.Pen.Color:=clBlack;
Form2.QRShape6.Pen.Color:=clWhite;
Form2.QRShape32.Pen.Color:=clWhite;
end
else
if txtline[6]='0' then
begin
Form2.QRShape32.Pen.Color:=clBlack;
Form2.QRShape6.Pen.Color:=clWhite;
Form2.QRShape19.Pen.Color:=clWhite;
end;

//第7场
if txtline[7]='3' then
begin
Form2.QRShape7.Pen.Color:=clBlack;
Form2.QRShape20.Pen.Color:=clWhite;
Form2.QRShape33.Pen.Color:=clWhite;
end
else
if txtline[7]='1' then
begin
Form2.QRShape20.Pen.Color:=clBlack;
Form2.QRShape7.Pen.Color:=clWhite;
Form2.QRShape33.Pen.Color:=clWhite;
end
else
if txtline[7]='0' then
begin
Form2.QRShape33.Pen.Color:=clBlack;
Form2.QRShape7.Pen.Color:=clWhite;
Form2.QRShape20.Pen.Color:=clWhite;
end;

//第8场
if txtline[8]='3' then
begin
Form2.QRShape8.Pen.Color:=clBlack;
Form2.QRShape21.Pen.Color:=clWhite;
Form2.QRShape34.Pen.Color:=clWhite;
end
else
if txtline[8]='1' then
begin
Form2.QRShape21.Pen.Color:=clBlack;
Form2.QRShape8.Pen.Color:=clWhite;
Form2.QRShape34.Pen.Color:=clWhite;
end
else
if txtline[8]='0' then
begin
Form2.QRShape34.Pen.Color:=clBlack;
Form2.QRShape8.Pen.Color:=clWhite;
Form2.QRShape21.Pen.Color:=clWhite;
end;

//第9场
if txtline[9]='3' then
begin
Form2.QRShape9.Pen.Color:=clBlack;
Form2.QRShape22.Pen.Color:=clWhite;
Form2.QRShape35.Pen.Color:=clWhite;
end
else
if txtline[9]='1' then
begin
Form2.QRShape22.Pen.Color:=clBlack;
Form2.QRShape9.Pen.Color:=clWhite;
Form2.QRShape35.Pen.Color:=clWhite;
end
else
if txtline[9]='0' then
begin
Form2.QRShape35.Pen.Color:=clBlack;
Form2.QRShape9.Pen.Color:=clWhite;
Form2.QRShape22.Pen.Color:=clWhite;
end;

//第10场
if txtline[10]='3' then
begin
Form2.QRShape10.Pen.Color:=clBlack;
Form2.QRShape23.Pen.Color:=clWhite;
Form2.QRShape36.Pen.Color:=clWhite;
end
else
if txtline[10]='1' then
begin
Form2.QRShape23.Pen.Color:=clBlack;
Form2.QRShape10.Pen.Color:=clWhite;
Form2.QRShape36.Pen.Color:=clWhite;
end
else
if txtline[10]='0' then
begin
Form2.QRShape36.Pen.Color:=clBlack;
Form2.QRShape10.Pen.Color:=clWhite;
Form2.QRShape23.Pen.Color:=clWhite;
end;

//第11场
if txtline[11]='3' then
begin
Form2.QRShape11.Pen.Color:=clBlack;
Form2.QRShape24.Pen.Color:=clWhite;
Form2.QRShape37.Pen.Color:=clWhite;
end
else
if txtline[11]='1' then
begin
Form2.QRShape24.Pen.Color:=clBlack;
Form2.QRShape11.Pen.Color:=clWhite;
Form2.QRShape37.Pen.Color:=clWhite;
end
else
if txtline[11]='0' then
begin
Form2.QRShape37.Pen.Color:=clBlack;
Form2.QRShape11.Pen.Color:=clWhite;
Form2.QRShape24.Pen.Color:=clWhite;
end;

//第12场
if txtline[12]='3' then
begin
Form2.QRShape12.Pen.Color:=clBlack;
Form2.QRShape25.Pen.Color:=clWhite;
Form2.QRShape38.Pen.Color:=clWhite;
end
else
if txtline[12]='1' then
begin
Form2.QRShape25.Pen.Color:=clBlack;
Form2.QRShape12.Pen.Color:=clWhite;
Form2.QRShape38.Pen.Color:=clWhite;
end
else
if txtline[12]='0' then
begin
Form2.QRShape38.Pen.Color:=clBlack;
Form2.QRShape12.Pen.Color:=clWhite;
Form2.QRShape25.Pen.Color:=clWhite;
end;

//第13场
if txtline[13]='3' then
begin
Form2.QRShape13.Pen.Color:=clBlack;
Form2.QRShape26.Pen.Color:=clWhite;
Form2.QRShape39.Pen.Color:=clWhite;
end
else
if txtline[13]='1' then
begin
Form2.QRShape26.Pen.Color:=clBlack;
Form2.QRShape13.Pen.Color:=clWhite;
Form2.QRShape39.Pen.Color:=clWhite;
end
else
if txtline[13]='0' then
begin
Form2.QRShape39.Pen.Color:=clBlack;
Form2.QRShape13.Pen.Color:=clWhite;
Form2.QRShape26.Pen.Color:=clWhite;
end;
MoveNext;
end;
end;

RichEdit1.Text:=SL1.Text;
Form2.QuickRep1.Preview;
with ADOQuery1do
begin
ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+ExtractFilePath(Application.ExeName)+'printset.mdb';
SQL.Clear;
SQL.Add('delete from touzhu');
ExecSQL;
end;
end;

end.

//============================================================
//窗体2
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, QuickRpt, QRCtrls, ExtCtrls, jpeg;
type
TForm2 = class(TForm)
QuickRep1: TQuickRep;
QRShape1: TQRShape;
QRShape2: TQRShape;
QRShape3: TQRShape;
QRShape4: TQRShape;
QRShape5: TQRShape;
QRShape6: TQRShape;
QRShape7: TQRShape;
QRShape8: TQRShape;
QRShape9: TQRShape;
DetailBand1: TQRBand;
QRShape10: TQRShape;
QRShape11: TQRShape;
QRShape12: TQRShape;
QRShape13: TQRShape;
QRShape14: TQRShape;
QRShape15: TQRShape;
QRShape16: TQRShape;
QRShape17: TQRShape;
QRShape18: TQRShape;
QRShape19: TQRShape;
QRShape20: TQRShape;
QRShape21: TQRShape;
QRShape22: TQRShape;
QRShape23: TQRShape;
QRShape24: TQRShape;
QRShape25: TQRShape;
QRShape26: TQRShape;
QRShape27: TQRShape;
QRShape28: TQRShape;
QRShape29: TQRShape;
QRShape30: TQRShape;
QRShape31: TQRShape;
QRShape32: TQRShape;
QRShape33: TQRShape;
QRShape34: TQRShape;
QRShape35: TQRShape;
QRShape36: TQRShape;
QRShape37: TQRShape;
QRShape38: TQRShape;
QRShape39: TQRShape;
PageHeaderBand1: TQRBand;
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;
implementation
uses Unit1;
{$R *.dfm}
end.
 
有现成免费的足彩打印程序,何苦要自己写
 
quickrep.dateset没有设置????
 
我之所以要写这个程序主要是出于学习目的。
 
为什么要用qrreport ,直接往printer 的canvas 画就行啦
 
我的问题有点类似这样的问题:数据库中用1表示男,0表示女,打印时不是打印1或0,而是打印'男'或'女'。即数据库存储的内容与打印的内容之间数据类型是不一样的,打印前需要经过一个转换。请问对于这类问题,一般是怎样解决的。
回答realLearning,我已经设置quickrep.dateset为Form1.ADOQuery1
 
做个函数来返回你要打印的东西不就行了
function Covert310(N:integer):string;
var
S:string;
begin
case N of
1: S:='男';
0: S:='女';
else
S:='';
end;
Covert310:=S:
end;
 
我的程序中也用了类似的转换,可为什么不行呢?
 
>>with ADOQuery1.Recordsetdo
这个前面将记录.first 不知道有没有用,
程序大概看了一下,没仔细看, 乱说的
你可以调试啊, 加几句话,打印出循环的结果,知道现在循环中的数据是什么样的了
或者单步调试就知道了 啊 应该很简单的
 
如果只有一注,则打印正确。若有两注。则所有打印出来的都是第二注,若有5注则全部打印第五注。总之打印出来的全都与最后一注相同。感觉好像对当前注的打印设置对在此之前的注也生效了。
 
前面有一个循环设置shape的颜色,循环结束时shape的颜色正好是最后一条记录
这个设置颜色的过程需要放到别的地方,比如adoquery.AfterScroll,记录滚动后
设置颜色,这样才能打印出需要的内容。
 
to realLearning
我把循环移到adoquery.AfterScroll中,结果只打印最后一条记录.
 
我把问题简化一下,方便大家发现问题所在。
Form1的数据集ADOQuery1有一个字符串型字段color,里面有多条记录,但总共只有三种取值:red,green,yellow代表交通灯的三种颜色。
在Form2添加QuickRep1,添加Detailand1,在Detailand1里面放三个QRShape控件:QRShape1(对应红灯),QRShape2(对应绿灯),QRShape3(对应黄灯),并把shape属性设为圆形qrsCircle,分别代表红绿黄三色灯。
现在我想实现的功能是按ADOQuery1中每条记录的颜色值打印交通灯颜色状态记录。例如,当前颜色为红色,则把QRShape1置为红色,QRShape2和QRShape3设成白色。
我的程序代码如下:(存在的问题是:打印出来的全都是对应记录集中的最后一条记录的值)
procedure TForm1.Button1Click(Sender: TObject);
var
SL1:TStringList;
i:integer;
txtline:string;
begin
SL1:=TStringList.Create;
SL1.Add('red');
SL1.Add('gleen');
SL1.Add('yellow');
SL1.Add('yellow');
SL1.Add('red');
SL1.Add('green');
with ADOQuery1do
begin
ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+ExtractFilePath(Application.ExeName)+'红绿灯.mdb';
SQL.Clear;
SQL.Add('delete from data');
ExecSQL;
close;
SQL.Clear;
SQL.Add('select color from data');
open;
end;

for i:=0 to SL1.Count-1do
begin
ADOQuery1.Append;
ADOQuery1.Fields[0].Value:=SL1;
ADOQuery1.Post;
end;
RichEdit1.Text:=SL1.Text;
ADOQuery1.Recordset.MoveFirst;
with ADOQuery1.Recordsetdo
begin
while not Eofdo
begin
txtline:=Fields['color'].Value;
if txtline='red' then
begin
Form2.QRShape1.Brush.Color:=clRed;
Form2.QRShape2.Brush.Color:=clWhite;
Form2.QRShape3.Brush.Color:=clWhite;
end
else
if txtline='green' then
begin
Form2.QRShape1.Brush.Color:=clWhite;
Form2.QRShape2.Brush.Color:=clgreen;
Form2.QRShape3.Brush.Color:=clWhite;
end
else
if txtline='yellow' then
begin
Form2.QRShape1.Brush.Color:=clWhite;
Form2.QRShape2.Brush.Color:=clWhite;
Form2.QRShape3.Brush.Color:=clyellow;
end;
MoveNext;
end;
end;
Form2.QuickRep1.Preview;
with ADOQuery1do
begin
SQL.Clear;
SQL.Add('delete from data');
ExecSQL;
end;
end;
 
我的意思是不要那个循环
quickrep print的时候会循环数据集
只要在afterscroll中根据记录的值设置shape的颜色就可以了。
自己不需要循环记录。
 
按照realLearning的提示,问题解决了。
 
后退
顶部