lend.pas
上传用户:blmaxia
上传日期:2010-02-17
资源大小:657k
文件大小:8k
- unit lend;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, DBCtrls, Mask, DB, DBTables, data, ownbook;
- type
- Tlendform = class(TForm)
- GroupBox1: TGroupBox;
- StaticText9: TStaticText;
- ComboBox1: TComboBox;
- StaticText10: TStaticText;
- DBName: TDBEdit;
- StaticText11: TStaticText;
- DBAuthor: TDBEdit;
- StaticText12: TStaticText;
- DBPress: TDBEdit;
- StaticText13: TStaticText;
- DBOutDate: TDBEdit;
- StaticText14: TStaticText;
- DBCost: TDBEdit;
- StaticText15: TStaticText;
- DBMemo: TDBMemo;
- GroupBox2: TGroupBox;
- StaticText1: TStaticText;
- StaticText2: TStaticText;
- StaticText3: TStaticText;
- StaticText4: TStaticText;
- StaticText5: TStaticText;
- ReaderIDEdit: TEdit;
- TotalEdit: TEdit;
- OwnTimeEdit: TEdit;
- FineEdit: TEdit;
- Button1: TButton;
- Button2: TButton;
- Button3: TButton;
- tempADOQuery1: TQuery;
- TEMPADOQuery2: TQuery;
- DataSource1: TDataSource;
- procedure FormShow(Sender: TObject);
- procedure ComboBox1Change(Sender: TObject);
- procedure ComboBox1KeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure ReaderIDEditChange(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- type
- TOwnBook = record
- code:string;
- name:string;
- price:string;
- owndays:integer;
- end;
- var
- lendform: Tlendform;
- implementation
- {$R *.dfm}
- procedure Tlendform.FormShow(Sender: TObject);
- var
- i:integer;
- begin
- with datamoduleado.ADOQuery1 do
- begin
- sql.Clear ;
- sql.Add('select code from book');
- open;
- first;
- for i:=0 to recordcount-1 do
- begin
- combobox1.Items.Add(fieldbyname('code').AsString );
- next;
- end;
- close;
- end;
- end;
- procedure Tlendform.ComboBox1Change(Sender: TObject);
- var
- fdate:tdate;
- owntime:Tdate;
- begin
- readeridedit.Text :='';
- totaledit.Text :='';
- owntimeedit.Text :='';
- fineEdit.Text :='';
- if length(combobox1.Text )=10 then
- begin
- try
- with datamoduleado.ADOTable1 do
- begin
- tablename:='book';
- dbname.DataField :='name';
- dbauthor.DataField :='author';
- dbpress.DataField :='press';
- dboutdate.DataField :='outdate';
- dbcost.DataField :='cost';
- dbmemo.DataField :='memo0';
- active:=true;
- if not locate('code',combobox1.Text ,[]) then
- begin
- messagedlg('没有数据或数据库操作失败',mterror,[mbok],0);
- exit;
- end;
- end;
- except
- messagedlg('数据操作出错',mterror,[mbok],0);
- end;
- try
- with datamoduleado.ADOQuery1 do
- begin
- sql.Clear ;
- sql.Add('select * from lend where code=:code');
- parameters.ParamByName('code').Value :=combobox1.Text;
- open;
- if recordcount<>0 then
- begin
- fdate:=fieldbyname('outdate').AsDateTime ;
- owntime:=date-fdate;
- owntimeedit.Text :=floattostr(owntime);
- readerIDEdit.Text :=fieldbyname('readerid').AsString;
- statictext1.Visible :=true;
- owntimeedit.Visible :=true;
- if strtoint(owntimeedit.Text )>60 then
- begin
- statictext12.Visible :=true;
- fineedit.Visible :=true;
- fineedit.Text :=floattostr((strtoint(owntimeedit.Text )-60)*0.1);
- end;
- button1.Enabled :=false;
- button2.Enabled :=true;
- button2.SetFocus ;
- close;
- end
- else begin
- readeridedit.SetFocus ;
- button1.Enabled :=true;
- button2.Enabled :=false;
- end;
- end;
- except
- readeridedit.SetFocus ;
- end;
- end;
- end;
- procedure Tlendform.ComboBox1KeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- if key=13 then
- combobox1change(sender);
- end;
- procedure Tlendform.ReaderIDEditChange(Sender: TObject);
- begin
- if length(readerIDEdit.Text )=10 then
- begin
- with datamoduleADO.ADOQuery1 do
- begin
- sql.Clear ;
- sql.Add('select readerid from reader where readerid=:readerid');
- parameters.ParamByName('readerid').Value :=readeridedit.Text ;
- open;
- if recordcount=0 then
- begin
- button1.Enabled :=false;
- messagedlg('借书证号<'+readeridedit.Text +'>不存在',mterror,[mbok],0);
- close;
- exit;
- end;
- close;
- end;
- try
- with datamoduleado.ADOQuery1 do
- begin
- sql.Clear ;
- sql.Add('select count(readerid) from lend where readerid=:readerid');
- parameters.ParamByName('readerid').Value :=readeridedit.Text ;
- open;
- totaledit.Text :=inttostr(fields[0].Value );
- close;
- end;
- except
- totaledit.Text :='0';
- end;
- button2.Enabled :=false;
- button1.Enabled :=true;
- button1.SetFocus ;
- end;
- end;
- procedure Tlendform.Button1Click(Sender: TObject);
- var
- tempownbook:townbook;
- canlend:boolean;
- mmcode:string;
- begin
- if readeridedit.Text <>'' then
- begin
- try
- with datamoduleado.adoquery1 do
- begin
- sql.clear;
- sql.Add('select code from lend where readerid=:readerid');
- parameters.ParamByName('readerid').Value :=readeridedit.Text ;
- open;
- canlend:=true;
- ownbookform.ListView1.Items.Clear ;
- mmcode:=fieldbyname('code').AsString;
- while not eof do
- begin
- with tempadoquery1 do
- begin
- sql.Clear ;
- sql.Add('select * from book where code =:code') ;
- parameters.ParamByName('code').Value :=mmcode;
- open;
- tempownbook.code:=fieldbyname('code').asstring;
- tempownbook.name:=fieldbyname('name').asstring;
- tempownbook.price:=fieldbyname('cost').asstring;
- try
- with tempadoquery2 do
- begin
- sql.Clear ;
- sql.Add('select * from lend where code=:code and readerid=:readerid');
- parameters.ParamByName('code').Value :=datamoduleado.ADOQuery1.fieldbyname('code').AsString ;
- parameters.ParamByName('readerid').Value := readeridedit.Text ;
- open;
- tempownbook.owndays:=round(date-fieldbyname('outdate').AsDateTime );
- close;
- end;
- except
- tempownbook.owndays:=0;
- end;
- close;
- end;
- if tempownbook.owndays>60 then
- begin
- with ownbookform.listview1.Items.add do
- begin
- caption:=tempownbook.code;
- subitems.add(tempownbook.name);
- subitems.add(tempownbook.price);
- subitems.Add(inttostr(tempownbook.owndays));
- subitems.Add(floattostr((tempownbook.owndays-60)*0.1));
- end;
- canlend:=false;
- end;
- next;
- end;
- close;
- end;
- except
- canlend:=true;
- end;
- if canlend=false then
- begin
- ownbookform.Caption :=readeridedit.text+'有以下书籍没按时归还';
- ownbookform.showmodal;
- exit;
- end;
- try
- with DatamoduleADO.adoquery1 do
- begin
- sql.clear;
- sql.add('insert into lend(code,readerid,outdate)'+' values(:code,:readerid,:outdate)');
- parameters.parambyname('code').value:=combobox1.text;
- parameters.parambyname('readerid').value:=readeridedit.text;
- parameters.parambyname('outdate').value:=datetostr(now());
- execsql;
- end;
- except
- messagedlg('借书不成功',mterror,[mbok],0);
- end;
- end
- else begin
- showmessage('请输入借书证号!');
- readeridedit.setfocus;
- end;
- end;
- procedure Tlendform.Button2Click(Sender: TObject);
- begin
- try
- with datamoduleado.adoquery1 do
- begin
- sql.clear;
- sql.add('delete from lend where code=:code');
- parameters.parambyname('code').value:=combobox1.text;
- execsql;
- close;
- end;
- except
- messagedlg('还书不成功',mterror,[mbok],0);
- end;
- readeridedit.text:='';
- totaledit.text:='';
- owntimeedit.text:='';
- fineedit.text:='';
- end;
- procedure Tlendform.Button3Click(Sender: TObject);
- begin
- close;
- end;
- end.