📄 unit7.pas
字号:
unit Unit7;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, DB, ADODB, ExtCtrls, ComCtrls, StdCtrls, Buttons;
type
TForm7 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
Label1: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Label2: TLabel;
Label3: TLabel;
Edit3: TEdit;
Label4: TLabel;
Edit4: TEdit;
Label5: TLabel;
Edit5: TEdit;
GroupBox1: TGroupBox;
StatusBar1: TStatusBar;
Timer1: TTimer;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
ADOQuery3: TADOQuery;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
ADOQuery4: TADOQuery;
BitBtn1: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit5KeyPress(Sender: TObject; var Key: Char);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure showReaderInformation();
procedure showGrid();
end;
var
Form7: TForm7;
ctid,Bdatestr:string; //ctid记录借书证编号
implementation
uses unit1;
{$R *.dfm}
procedure TForm7.FormCreate(Sender: TObject);
begin
edit1.Enabled:=true;
edit2.Color:=clwindow;
edit3.Color:=clwindow;
edit4.Color:=clwindow;
edit1.Clear;
edit5.Enabled:=true;
edit5.Clear;
edit2.Clear;
edit3.Clear;
edit4.Clear;
adoquery2.Close;
statusbar1.Panels[0].Text:='';
statusbar1.Panels[1].Text:='现在时间: ';
Timer1Timer(Sender);
speedbutton1.Down:=true;
end;
procedure TForm7.Timer1Timer(Sender: TObject);
begin
statusbar1.Panels[2].Text:=formatdatetime('YYYY-MM-DD',date());
statusbar1.Panels[3].Text:=formatdatetime('hh:mm:ss',time());
end;
procedure TForm7.SpeedButton1Click(Sender: TObject);
begin
edit1.Enabled:=true;
edit1.Color:=clwindow;
edit1.Clear;
edit1.SetFocus;
edit5.Enabled:=true;
edit5.Clear;
edit2.Clear;
edit3.Clear;
edit4.Clear;
adoquery2.Close;
statusbar1.Panels[0].Text:='';
end;
procedure TForm7.SpeedButton2Click(Sender: TObject);
begin
edit1.Enabled:=false;
edit1.Color:=clbtnface;
edit1.Clear;
edit5.enabled:=true;
edit5.Clear;
edit5.SetFocus;
edit2.Clear;
edit3.Clear;
edit4.Clear;
adoquery2.Close;
statusbar1.Panels[0].Text:='';
end;
procedure TForm7.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
begin
if trim(edit1.Text)='' then
begin
application.MessageBox('请输入借书证号!','出错',MB_OK+MB_ICONWarning);
exit;
end;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from reader where borrowbook_Id=:id1');
adoquery1.Parameters.ParamByName('id1').Value:=edit1.Text;
adoquery1.Open;
if adoquery1.RecordCount<>0 then
begin
ctid:=adoquery1.fieldbyname('borrowbook_Id').AsString;
showReaderInformation();
showGrid();
edit5.SetFocus;
end
else
begin
application.MessageBox(Pchar('借书证号:'+edit5.text+'不存在,无法借阅!'),'出错',MB_OK+MB_ICONWarning);
edit1.SetFocus;
edit1.SelectAll;
end;
end;
end;
procedure Tform7.showReaderInformation();
begin
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select * from student where borrowbook_Id=:id2');
adoquery3.Parameters.ParamByName('id2').Value:=ctid;
adoquery3.Open;
if adoquery3.Bof and adoquery3.Eof then
begin
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select * from teacher where borrowbook_Id=:id3');
adoquery3.Parameters.ParamByName('id3').Value:=ctid;
adoquery3.Open;
edit2.Text:=adoquery3.fieldbyname('Tn').AsString;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from reader,reader_category where borrowbook_Id=:id4 and reader.category_ID=reader_category.category_Id');
adoquery1.Parameters.ParamByName('id4').Value:=ctid;
adoquery1.Open;
edit3.Text:=adoquery1.fieldbyname('borrow_count').AsString;
end
else
begin
edit2.Text:=adoquery3.fieldbyname('sn').AsString;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from reader,reader_category where borrowbook_Id=:id4 and reader.category_ID=reader_category.category_Id');
adoquery1.Parameters.ParamByName('id4').Value:=ctid;
adoquery1.Open;
edit3.Text:=adoquery1.fieldbyname('borrow_count').AsString;
end;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from borrow where borrowbook_Id=:id5');
adoquery1.Parameters.ParamByName('id5').Value:=ctid;
adoquery1.Open;
edit4.Text:=adoquery1.fieldbyname('count').AsString;
end;
procedure Tform7.showGrid();
begin
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select book.bookno,bookname,author,publishment,borrowtime,returntime,count from borrow,book where borrowbook_Id=:id6 and book.bookno=borrow.bookno');
adoquery2.Parameters.ParamByName('id6').Value:=ctid;
adoquery2.Open;
statusbar1.Panels[0].Text:='->>'+edit2.Text+' 当前借阅'+inttostr(adoquery2.RecordCount)+' 册图书';
end;
procedure TForm7.Edit5KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
begin
if speedbutton2.Down then //return book
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from borrow where bookno=:id7');
adoquery1.Parameters.ParamByName('id7').Value:=edit5.Text;
adoquery1.Open;
if adoquery1.Bof and adoquery1.Eof then
begin
application.MessageBox('无法完成还书, 该书未被借出或图书条形码不正确!','出错',MB_OK+MB_ICONWarning);
edit5.SelectAll;
exit;
end
else
begin
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select * from borrow where bookno=:id8');
adoquery3.Parameters.ParamByName('id8').Value:=edit5.Text;
adoquery3.Open;
ctid:=adoquery3.fieldbyname('borrowbook_id').AsString;
edit1.Text:=ctid;
showReaderInformation();
end;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('delete from borrow where bookno=:id9');
adoquery1.Parameters.ParamByName('id9').Value:=edit5.Text;
adoquery1.execsql;
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select * from book where bookno=:id10');
adoquery3.Parameters.ParamByName('id10').Value:=edit5.Text;
adoquery3.Open;
adoquery3.Edit;
adoquery3.fieldbyname('borrowed').AsBoolean:=true;
adoquery3.Post;
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('update borrow set count=count-1 where borrowbook_Id=:id14');
adoquery3.Parameters.ParamByName('id14').Value:=ctid;
adoquery3.execsql;
adoquery4.Close;
adoquery4.SQL.Clear;
adoquery4.SQL.Add('select * from borrow where borrowbook_Id=:id20');
adoquery4.Parameters.ParamByName('id20').Value:=ctid;
adoquery4.Open;
edit4.Text:=adoquery4.fieldbyname('count').AsString;
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Text:='select * from return1';
adoquery3.Open;
adoquery3.Append;
adoquery3.FieldByName('borrowbook_id').AsString:=ctid;
adoquery3.FieldByName('bookno').AsString:=edit5.Text;
adoquery3.FieldByName('borrowtime').AsDateTime:=adoquery4.fieldbyname('borrowtime').AsDateTime;
adoquery3.FieldByName('factreturntime').AsDateTime:=date();
adoquery3.post;
application.MessageBox('还书操作成功!','成功',MB_OK+MB_ICONinformation);
showGrid();
edit5.Clear;
edit5.SetFocus;
end
else //借书
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from borrow where bookno=:id11');
adoquery1.Parameters.ParamByName('id11').Value:=edit5.Text;
adoquery1.Open;
if adoquery1.RecordCount<>0 then
begin
application.MessageBox('无法完成借书, 该书已经被借出!','出错',MB_OK+MB_ICONWarning);
edit5.SelectAll;
exit;
end;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from book where bookno=:id12');
adoquery1.Parameters.ParamByName('id12').Value:=edit5.Text;
adoquery1.Open;
if adoquery1.RecordCount<>0 then
begin
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select * from borrow where borrowbook_id='''+ctid+'''');
adoquery3.Open;
if adoquery3.RecordCount<>0 then
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from reader,reader_category,borrow '
+'where reader.borrowbook_Id=:id4 and reader.category_ID=reader_category.category_Id and borrow.borrowbook_id =reader.borrowbook_id');
adoquery1.Parameters.ParamByName('id4').Value:=ctid;
adoquery1.Open;
if adoquery1.fieldbyname('count').AsInteger>=adoquery1.fieldbyname('borrow_count').AsInteger then
begin
application.MessageBox(Pchar('你已经借了'+adoquery1.fieldbyname('borrow_count').asstring+'!'),'警告',MB_OK+MB_ICONWarning);
exit;
end;
end;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from borrow');
adoquery1.Open;
adoquery1.Append;
adoquery1.fieldbyname('borrowbook_id').AsString:=ctid;
adoquery1.fieldbyname('bookno').AsString:=edit5.Text;
adoquery1.fieldbyname('borrowtime').AsCurrency:=date();
adoquery4.Close;
adoquery4.SQL.Clear;
adoquery4.SQl.add('select * from student where borrowbook_id=:b1');
adoquery4.Parameters.ParamByName('b1').Value:=ctid;
adoquery4.Open;
Bdatestr:=formatdatetime('yyyy''-''mm''-''dd',date());
if adoquery4.RecordCount<>0 then
adoquery1.fieldbyname('returntime').AsDateTime:=strtodate(copy(bdatestr,1,5)+inttostr(strtoint(copy(bdatestr,6,2))+1)+copy(bdatestr,8,3))
else
adoquery1.fieldbyname('returntime').AsDateTime:=strtodate(copy(bdatestr,1,5)+inttostr(strtoint(copy(bdatestr,6,2))+2)+copy(bdatestr,8,3));
adoquery1.Post;
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('update borrow set count=count+1 where borrowbook_Id=:id14');
adoquery3.Parameters.ParamByName('id14').Value:=ctid;
adoquery3.execsql;
adoquery4.Close;
adoquery4.SQL.Clear;
adoquery4.SQL.Add('select max(count) count_ from borrow where borrowbook_Id=:id16');
adoquery4.Parameters.ParamByName('id16').Value:=ctid;
adoquery4.Open;
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select * from borrow where borrowbook_Id=:id17 and bookno=:id18');
adoquery3.Parameters.ParamByName('id17').Value:=ctid;
adoquery3.Parameters.ParamByName('id18').Value:=edit5.Text;
adoquery3.open;
adoquery3.Edit;
adoquery3.FieldByName('count').AsInteger:=adoquery4.fieldbyname('count_').AsInteger;
adoquery3.post;
edit4.Text:=adoquery4.fieldbyname('count_').AsString;
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select * from book where bookno=:id10');
adoquery3.Parameters.ParamByName('id10').Value:=edit5.Text;
adoquery3.Open;
adoquery3.Edit;
adoquery3.fieldbyname('borrowed').AsBoolean:=false;
adoquery3.Post;
application.MessageBox('借书操作成功!','成功',MB_OK+MB_ICONinformation);
showGrid();
edit5.Clear;
edit1.SetFocus;
edit1.SelectAll;
end
else
begin
application.MessageBox('无法完成借书, 请确认图书条形码是否正确!','出错',MB_OK+MB_ICONWarning);
edit5.selectall;
end;
end;
end;
end;
procedure TForm7.BitBtn1Click(Sender: TObject);
begin
form7.Hide;
animatewindow(form1.handle,1000,aw_Activate or aw_center);
form1.Show;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -