bookborrowform.~pas
来自「图书管理系统,使用Delphi开发,数据库为Microsoft SQL Serv」· ~PAS 代码 · 共 293 行
~PAS
293 行
unit BookBorrowForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask, DBCtrls, ComCtrls, ToolWin, ImgList, Grids,
ADODB, DB;
type
TBookBorrow = class(TForm)
DataSource1: TDataSource;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
ADOCommand1: TADOCommand;
StringGrid1: TStringGrid;
ImageList1: TImageList;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
RadioButton4: TRadioButton;
Edit1: TEdit;
Edit2: TEdit;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid1Click(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure FormShow(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
procedure ToolButton3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
//
booknum,thisbook,keeptime:integer;
//
usernum:string;
procedure cleargrid();
end;
var
BookBorrow: TBookBorrow;
implementation
{$R *.dfm}
uses
DataMod;
procedure TBookBorrow.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
end;
procedure TBookBorrow.Edit1KeyPress(Sender: TObject; var Key: Char);
var
name:string;
num:string;
i:integer;
begin
//
if radiobutton1.Checked then
name:='ReaderInfo_No';
if radiobutton2.Checked then
name:='ReaderInfo_BarCode';
//
booknum:=0;
thisbook:=0;
label6.Caption:='已借书'+inttostr(booknum)+'本';
label7.Caption:='本次借书'+inttostr(thisbook)+'本';
if key=#13 then
begin
//
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select a.*, b.ReaderType_MaxBookNo from ReaderInfo a,ReaderType b where (a.'+name+'='''+edit1.Text+''')and(a.ReaderInfo_Type=b.ReaderType_Type)');
adoquery1.Open;
//
usernum:=adoquery1.FieldByName('ReaderInfo_No').AsString;
//
num:=adoquery1.FieldByName('ReaderInfo_No').AsString;
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select a.*, b.BookInfo_BookName, b.BookInfo_PublishingCompany,b.BookInfo_Price from BookLend a,BookInfo b where(ReaderInfo_No='''+num+''')and(a.BookInfo_No=b.BookInfo_No)and(a.BookLend_State=''未还'')');
adoquery2.Open;
i:=1;
//
cleargrid();
while not adoquery2.Eof do
begin
stringgrid1.Cells[0,i]:=adoquery2.fieldbyname('BookLend_State').AsString;
stringgrid1.Cells[1,i]:=adoquery2.fieldbyname('BookInfo_No').AsString;
stringgrid1.Cells[2,i]:=adoquery2.fieldbyname('BookInfo_BookName').AsString;
stringgrid1.Cells[3,i]:=adoquery2.fieldbyname('BookLend_BorrowDate').AsString;
stringgrid1.Cells[4,i]:=adoquery2.fieldbyname('BookLend_RestoreDate').AsString;
stringgrid1.Cells[5,i]:=adoquery2.fieldbyname('BookInfo_PublishingCompany').AsString;
stringgrid1.Cells[6,i]:=adoquery2.fieldbyname('BookInfo_Price').AsString;
i:=i+1;
adoquery2.Next;
end;
//
booknum:=i-1;
label6.Caption:='已借书'+inttostr(booknum)+'本';
//
if dbedit3.Text<>'' then
groupbox2.Enabled:=true
else groupbox2.Enabled:=false;
//
edit2.SetFocus;
end;
end;
procedure TBookBorrow.StringGrid1Click(Sender: TObject);
begin
end;
//
procedure TBookBorrow.cleargrid;
var
i,j:integer;
begin
for i:=1 to 11 do
for j:=0 to 6 do
stringgrid1.Cells[j,i]:='';
end;
procedure TBookBorrow.Edit2KeyPress(Sender: TObject; var Key: Char);
var
name:string;
booktype:string;
i:integer;
begin
//
if radiobutton3.Checked then
name:='BookInfo_No';
if radiobutton4.Checked then
name:='BookInfo_BarCode';
//
if key=#13 then
begin
//
if booknum-strtoint(dbedit3.Text)>=0 then
begin
showmessage('达到借书数量上限,请先归还图书再借书');
exit;
end;
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select * from BookInfo where '+name+'='''+edit2.Text+'''');
adoquery2.Open;
if adoquery2.FieldByName('BookInfo_No').AsString<>'' then
begin
//
for i:=1 to 12 do
if stringgrid1.Cells[1,i]=adoquery2.FieldByName('BookInfo_No').AsString then
begin
showmessage('读者已借有该书,不允许再借');
edit2.Clear;
exit;
end;
//
stringgrid1.Cells[0,booknum+1]:='新借';
stringgrid1.Cells[1,booknum+1]:=adoquery2.fieldByName('BookInfo_No').AsString;
stringgrid1.Cells[2,booknum+1]:=adoquery2.fieldByName('BookInfo_BookName').AsString;
stringgrid1.Cells[5,booknum+1]:=adoquery2.fieldByName('BookInfo_PublishingCompany').AsString;
stringgrid1.Cells[6,booknum+1]:=adoquery2.fieldByName('BookInfo_Price').AsString;
booktype:=adoquery2.fieldByName('BookInfo_Type').AsString;
//
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select * from BookType where BookType_TypeName='''+booktype+'''');
adoquery2.Open;
keeptime:=adoquery2.fieldByName('BookType_Lenddays').AsInteger;
stringgrid1.Cells[3,booknum+1]:=datetostr(date);
stringgrid1.Cells[4,booknum+1]:=datetostr(date+keeptime);
//
booknum:=booknum+1;
thisbook:=thisbook+1;
label6.Caption:='已借书'+inttostr(booknum)+'本';
label7.Caption:='本次借书'+inttostr(thisbook)+'本';
//
edit2.Clear;
//
toolbutton1.Enabled:=true;
toolbutton2.Enabled:=true;
end;
end;
end;
procedure TBookBorrow.FormShow(Sender: TObject);
var
i,j:integer;
begin
stringgrid1.Cells[0,0]:='状态';
stringgrid1.ColWidths[0]:=64;
stringgrid1.Cells[1,0]:='编号';
stringgrid1.ColWidths[1]:=128;
stringgrid1.Cells[2,0]:='书号';
stringgrid1.ColWidths[2]:=128;
stringgrid1.Cells[3,0]:='借出时间';
stringgrid1.ColWidths[3]:=64;
stringgrid1.Cells[4,0]:='应还时间';
stringgrid1.ColWidths[4]:=64;
stringgrid1.Cells[5,0]:='出版社';
stringgrid1.ColWidths[5]:=128;
stringgrid1.Cells[6,0]:='书架';
stringgrid1.ColWidths[6]:=64;
//
booknum:=0;
thisbook:=0;
label6.Caption:='已借书'+inttostr(booknum)+'本';
label7.Caption:='本次借书'+inttostr(thisbook)+'本';
end;
procedure TBookBorrow.ToolButton1Click(Sender: TObject);
var
i:integer;
maxnum:integer;
begin
//
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select max(BookLend_No) 最大编号 from BookLend');
adoquery2.Open;
maxnum:=adoquery2.FieldByName('最大编号').AsInteger;
maxnum:=maxnum+1;
//
adocommand1.CommandText:='SET IDENTITY_INSERT BookLend on';
adocommand1.Execute;
//
for i:=1 to 12 do
if stringgrid1.Cells[0,i]='新借' then
begin
adocommand1.CommandText:='insert into BookLend([BookLend_No],[BookInfo_No],[ReaderInfo_No],[BookLend_BorrowDate],[BookLend_RestoreDate],[BookLend_RenewalDegree],[BookLend_State]) values('''+inttostr(maxnum)+''','''+stringgrid1.Cells[1,i]+''','''+usernum+''','''+stringgrid1.Cells[3,i]+''','''+stringgrid1.Cells[4,i]+''',''0'',''未还'')';
adocommand1.Execute;
maxnum:=maxnum+1;
end;
//
adocommand1.CommandText:='SET IDENTITY_INSERT BookLend off';
adocommand1.Execute;
toolbutton1.Enabled:=false;
toolbutton2.Enabled:=false;
groupbox2.Enabled:=false;
cleargrid();
edit2.Clear;
edit1.Clear;
end;
procedure TBookBorrow.ToolButton2Click(Sender: TObject);
begin
toolbutton1.Enabled:=false;
toolbutton2.Enabled:=false;
groupbox2.Enabled:=false;
cleargrid();
edit2.Clear;
edit1.Clear;
end;
procedure TBookBorrow.ToolButton3Click(Sender: TObject);
begin
if toolbutton1.Enabled=true then
if application.MessageBox('尚未保存借书记录,是否直接退出?','确认退出',MB_OKCANCEL)=IDOK then
close;
if toolbutton1.Enabled=false then
close;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?