用了上面的方法还是解决不了,大家来看一下我的源代码,有借阅和预约两个功能:
procedure Tform2.BitBtn1Click(Sender: TObject);
var
BDatestr,RDatestr:string;
begin
if edit2.Text<>'' then
begin
if radiobutton1.Checked=True then
begin
with query1do
begin
close;
sql.Clear;
sql.Add('select * from student where 学号='+edit2.Text);
open;
if query1.RecordCount=0 then
begin
showmessage('学号错误!');
end
else
if query1.FieldByName('借阅许可').AsBoolean=False then
begin
showmessage('对不起,您的借书已达上限,请退出!');
form2.Close;
end
else
begin
with query1do
begin
close;
sql.Clear;
sql.Add('select * from record where 书号='+edit1.Text);
open;
end;
if query1.FieldByName('学号').AsInteger<>strtoint(edit2.Text) then
begin
with table1do
begin
close;
table1.IndexFieldNames:='书号';
table1.ReadOnly:=False;
open;
table1.FindKey([strtoint(edit1.Text)]);
edit;
table2.SetFields([nil,nil,nil,nil,nil,True,False]);
post;
end;
with table2do
begin
open;
insert;
BDatestr:=formatdatetime('yyyy''-''mm''-''dd',Date);
RDatestr:=copy(BDatestr,1,5)+inttostr(strtoint(copy(BDatestr,6,2))+1)+copy(BDatestr,8,3);
table2.SetFields([recordcount+1,strtoint(edit2.Text),strtoint(edit1.Text),BDatestr,RDatestr,False,False]);
post;
end;
showmessage('借阅成功!');
end;
end;
end;
end;
if radiobutton2.Checked=true then
begin
with query1do
begin
close;
sql.Clear;
sql.Add('select * from student where 学号='+edit2.Text);
open;
if query1.RecordCount=0 then
begin
edit2.Clear;
showmessage('学号错误!');
end
else
if query1.FieldByName('借阅许可').AsString='False' then
begin
showmessage('对不起,你的借书已达上限,请退出!');
form2.Close;
end
else
begin
with query1do
begin
close;
sql.Clear;
sql.Add('select * from record where 书号='+edit1.Text);
open;
end;
if query1.FieldByName('学号').AsInteger<>strtoint(edit2.Text) then
begin
with table1do
begin
close;
table1.IndexFieldNames:='书号';
table1.ReadOnly:=False;
open;
table1.FindKey([strtoint(edit1.Text)]);
edit;
table1.SetFields([nil,nil,nil,nil,nil,nil,True]);
post;
end;
with table2do
begin
open;
insert;
BDatestr:=formatdatetime('yyyy''-''mm''-''dd',Date);
RDatestr:=copy(BDatestr,1,5)+inttostr(strtoint(copy(BDatestr,6,2))+1)+copy(BDatestr,8,3);
table2.SetFields([recordcount+1,strtoint(edit2.Text),strtoint(edit1.Text),BDatestr,RDatestr,False,True]);
post;
end;
showmessage('预约成功!');
end
else
begin
showmessage('同一个人不能对同一本书进行借阅和预约!');
end;
end;
end;
end;
end;
with query1do
begin
close;
sql.Clear;
sql.Add('select * from record where 学号='+edit2.Text);
open;
if recordcount>=4 then
begin
with table3do
begin
table3.IndexFieldNames:='学号';
close;
readonly:=False;
open;
table3.FindKey([edit2.Text]);
edit;
setFields([nil,nil,nil,nil,nil,nil,nil,False]);
post;
end;
end;
end;
end;
end.
预约可以成功,但借阅就出现上面的异常了