我的前台是delphi,后台是 sql,这是我的一个连接:机读卡的接口程序,但是连的时候有问题,格式文件选择后,不能读出正确的信息。例如,我的答题卡没有填写学号,课程号的信息时,按照程序原来设定,该是机子不读卡,给出提示信息,但是运行时没法给用户提示,机子进入死循环。
procedure Tfrm_jqdk.BitBtn1Click(Sender: TObject);
var
cmd:array[0..254] of char;
buf:array[0..254] of char; //数组
Sp: array[0..199] of char;
I:integer;
lsStr:string;
temp:pchar;
ErrNum:integer;
Maxnum,start:integer;
begin
try
if cob_class.Text <> emptystr then
begin
str:= path + '\setup.ini';
fomfilename:=getinifile(str,'fomfile','filename');
start:= strtoint(getinifile(str,'fomfile','start'));
aid:=getinifile(str,'counter','aid'); //答题卡序号
if fomfilename<>emptystr then
begin
timer1.Enabled:=true;
temp:= pchar('S '+ fomfilename + '/'); // FOMFILE.FOM为发送格式文件名
OmrS(temp);
OmrG(buf);
I:=0;
if copy(buf,1,2)='08' then
begin
pbar.Position:=0;
timer1.Enabled:=false;
exit;
end;
while true do
begin
fillchar(sp,200,ord(' '));
cmd:='/ ';
omrs(cmd);
omrg(buf);
if copy(buf,1,2)='OK' then
begin
strpcopy(cmd,'001'+sp+'/');
omrs(cmd);
omrg(buf);
if (i<=22)then //检测学号和课程号有没有涂写。前 8位是学号,后面的课程号!
if buf[i]=emptystr then
begin
application.MessageBox('提示','该答题卡无效',0);
end
else
i:=i+1;
if buf[i]<>emptystr then
begin
sid:=buf[1]+buf[2]+buf[3]+ buf[4]+buf[5]+buf[6]+buf[7]+buf[8];
cid:=buf[1]+buf[2]+buf[3]+ buf[4]+buf[5]+buf[6]+buf[7]+buf[8]+buf[9]+buf[10]+buf[11]+ buf[12]+buf[13]+buf[14]+inttostr(8);
end;
end;
if (strtoint(aid)>0) and (strtoint(sid)>0) and (strtoint(tmid)>=0) then
begin
with datam.qry_answer do
begin
close;
sql.Clear ;
sql.Add ('select cid,sid,sk from answer order by sid asc');
prepare;
open;
first;
while not eof do
begin
with datam.qry_answer do
begin
close;
sql.Clear;
sql.Add('insert into answer (tmid,sid,cid,aid,sk)');
sql.add(' values (:tmid,:sid,:cid,:aid,:sk)');
parambyname('sid').asstring:=sid; //填入学号
parambyname('cid').asstring:=cid;//填入课程号
datam.qry_class.FieldValues['classid'];//插入班级号
parambyname('tmid').asstring:=tmid;//题目序号
parambyname('aid').asstring:=aid+inttostr(1);
parambyname('sk').AsString :=buf[start];//学生的答案
prepare;
execsql;
end;
start:=start+1;
next;
end;
if not (putinifile(str,'counter','sid',inttostr(strtoint(aid)+1))) then
begin
application.MessageBox('提示','写配置文件出错!',0);
end;
lb_num.Caption:=inttostr(strtoint(aid)+1);
end;
end;
end;
end
else begin
ErrNum:= strtoint(copy(buf,1,2));
case ErrNum of
5 : begin
application.MessageBox('提示','检测点线错,数据未读入。',0);
timer1.Enabled:=false;
end;
3 : begin
application.MessageBox('提示','双张错,数据未读入。',0);
timer1.Enabled:=false;
end;
7 : begin
application.MessageBox('提示','卡纸或同步信号错,数据未读入。',0);
timer1.Enabled:=false;
end;
4: begin
application.MessageBox('提示','类型标志错,数据未读入。',0);
timer1.Enabled:=false;
end;
else application.MessageBox('提示','缺卡,加评议卡后按开始按钮',0);
cmd:='-/';
omrs(cmd);
exit;
end;
end;
end
else
application.MessageBox('提示','请先指定格式文件!',0);
except
cmd:='-/';
omrs(cmd);
application.MessageBox('警告','故障',0);
end;
end;procedure Tfrm_jqdk.Timer1Timer(Sender: TObject);
begin
pbar.StepIt;
if pbar.Position =pbar.Max then
pbar.Position:=0
end;procedure Tfrm_jqdk.FormActivate(Sender: TObject);
begin
setcob;
str:= path + '\setup.ini';
lb_num.Caption:=getinifile(str,'counter','aid');
end;
end.
procedure Tfrm_jqdk.BitBtn1Click(Sender: TObject);
var
cmd:array[0..254] of char;
buf:array[0..254] of char; //数组
Sp: array[0..199] of char;
I:integer;
lsStr:string;
temp:pchar;
ErrNum:integer;
Maxnum,start:integer;
begin
try
if cob_class.Text <> emptystr then
begin
str:= path + '\setup.ini';
fomfilename:=getinifile(str,'fomfile','filename');
start:= strtoint(getinifile(str,'fomfile','start'));
aid:=getinifile(str,'counter','aid'); //答题卡序号
if fomfilename<>emptystr then
begin
timer1.Enabled:=true;
temp:= pchar('S '+ fomfilename + '/'); // FOMFILE.FOM为发送格式文件名
OmrS(temp);
OmrG(buf);
I:=0;
if copy(buf,1,2)='08' then
begin
pbar.Position:=0;
timer1.Enabled:=false;
exit;
end;
while true do
begin
fillchar(sp,200,ord(' '));
cmd:='/ ';
omrs(cmd);
omrg(buf);
if copy(buf,1,2)='OK' then
begin
strpcopy(cmd,'001'+sp+'/');
omrs(cmd);
omrg(buf);
if (i<=22)then //检测学号和课程号有没有涂写。前 8位是学号,后面的课程号!
if buf[i]=emptystr then
begin
application.MessageBox('提示','该答题卡无效',0);
end
else
i:=i+1;
if buf[i]<>emptystr then
begin
sid:=buf[1]+buf[2]+buf[3]+ buf[4]+buf[5]+buf[6]+buf[7]+buf[8];
cid:=buf[1]+buf[2]+buf[3]+ buf[4]+buf[5]+buf[6]+buf[7]+buf[8]+buf[9]+buf[10]+buf[11]+ buf[12]+buf[13]+buf[14]+inttostr(8);
end;
end;
if (strtoint(aid)>0) and (strtoint(sid)>0) and (strtoint(tmid)>=0) then
begin
with datam.qry_answer do
begin
close;
sql.Clear ;
sql.Add ('select cid,sid,sk from answer order by sid asc');
prepare;
open;
first;
while not eof do
begin
with datam.qry_answer do
begin
close;
sql.Clear;
sql.Add('insert into answer (tmid,sid,cid,aid,sk)');
sql.add(' values (:tmid,:sid,:cid,:aid,:sk)');
parambyname('sid').asstring:=sid; //填入学号
parambyname('cid').asstring:=cid;//填入课程号
datam.qry_class.FieldValues['classid'];//插入班级号
parambyname('tmid').asstring:=tmid;//题目序号
parambyname('aid').asstring:=aid+inttostr(1);
parambyname('sk').AsString :=buf[start];//学生的答案
prepare;
execsql;
end;
start:=start+1;
next;
end;
if not (putinifile(str,'counter','sid',inttostr(strtoint(aid)+1))) then
begin
application.MessageBox('提示','写配置文件出错!',0);
end;
lb_num.Caption:=inttostr(strtoint(aid)+1);
end;
end;
end;
end
else begin
ErrNum:= strtoint(copy(buf,1,2));
case ErrNum of
5 : begin
application.MessageBox('提示','检测点线错,数据未读入。',0);
timer1.Enabled:=false;
end;
3 : begin
application.MessageBox('提示','双张错,数据未读入。',0);
timer1.Enabled:=false;
end;
7 : begin
application.MessageBox('提示','卡纸或同步信号错,数据未读入。',0);
timer1.Enabled:=false;
end;
4: begin
application.MessageBox('提示','类型标志错,数据未读入。',0);
timer1.Enabled:=false;
end;
else application.MessageBox('提示','缺卡,加评议卡后按开始按钮',0);
cmd:='-/';
omrs(cmd);
exit;
end;
end;
end
else
application.MessageBox('提示','请先指定格式文件!',0);
except
cmd:='-/';
omrs(cmd);
application.MessageBox('警告','故障',0);
end;
end;procedure Tfrm_jqdk.Timer1Timer(Sender: TObject);
begin
pbar.StepIt;
if pbar.Position =pbar.Max then
pbar.Position:=0
end;procedure Tfrm_jqdk.FormActivate(Sender: TObject);
begin
setcob;
str:= path + '\setup.ini';
lb_num.Caption:=getinifile(str,'counter','aid');
end;
end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货