book.pas
上传用户:blmaxia
上传日期:2010-02-17
资源大小:657k
文件大小:5k
- unit book;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ExtCtrls, StdCtrls, ComCtrls, Data, DB, DBCtrls, Mask;
- type
- Tbookform = class(TForm)
- PageControl1: TPageControl;
- TabSheet1: TTabSheet;
- TabSheet2: TTabSheet;
- GroupBox1: TGroupBox;
- StaticText1: TStaticText;
- codeedit: TEdit;
- StaticText2: TStaticText;
- NameEdit: TEdit;
- StaticText3: TStaticText;
- StaticText4: TStaticText;
- StaticText5: TStaticText;
- StaticText6: TStaticText;
- StaticText7: TStaticText;
- StaticText8: TStaticText;
- AuthorEdit: TEdit;
- PressEdit: TEdit;
- OuttimeEdit: TEdit;
- CostEdit: TEdit;
- Memo1: TMemo;
- Button1: TButton;
- Button2: TButton;
- GroupBox2: TGroupBox;
- StaticText9: TStaticText;
- StaticText10: TStaticText;
- StaticText11: TStaticText;
- StaticText12: TStaticText;
- StaticText13: TStaticText;
- StaticText14: TStaticText;
- StaticText15: TStaticText;
- StaticText16: TStaticText;
- ComboBox1: TComboBox;
- DBName: TDBEdit;
- DBAuthor: TDBEdit;
- DBPress: TDBEdit;
- DBOutDate: TDBEdit;
- DBCost: TDBEdit;
- DBMemo: TDBMemo;
- DataSource1: TDataSource;
- Button4: TButton;
- procedure TabSheet1Show(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure TabSheet2Show(Sender: TObject);
- procedure ComboBox1Change(Sender: TObject);
- procedure ComboBox1KeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- bookform: Tbookform;
- implementation
- {$R *.dfm}
- procedure Tbookform.TabSheet1Show(Sender: TObject);
- begin
- codeedit.SetFocus ;
- CodeEdit.SelectAll ;
- NameEdit.Text :='';
- AuthorEdit.Text :='';
- OutTimeEdit.Text :='';
- CostEdit.Text :='';
- PressEdit.Text :='';
- Memo1.Lines.Clear ;
- end;
- procedure Tbookform.Button1Click(Sender: TObject);
- begin
- //检查新入库图书的书号是否长度是否为10
- if Length(CodeEdit.Text )<>10 then
- begin
- messagedlg('书号不正确',mtError,[mbok],0);
- CodeEdit.SetFocus ;
- exit;
- end;
- //检查书号是否已经存在
- with dataModuleAdo.adoquery1 do
- begin
- sql.clear;
- sql.Add('select code from book where code=:code');
- parameters.ParamByName('code').Value :=codeedit.Text ;
- open;
- if recordcount<>0 then
- begin
- messagedlg('书号<'+codeedit.Text+'>已经存在',mtError,[mbok],0);
- codeedit.SetFocus ;
- exit;
- end;
- close;
- end;
-
- try
- with datamoduleado.ADOQuery1 do
- begin
- sql.Clear;
- sql.Add('insert into book(code,name,author,press,outdate,cost,memo0)'+
- 'values(:code,:name,:author,:press,:outdate,:cost,:MMEMO)');
- parameters.ParamByName('code').Value :=codeedit.Text ;
- parameters.ParamByName('name').Value :=nameedit.Text ;
- parameters.ParamByName('author').Value :=authoredit.Text ;
- parameters.ParamByName('press').Value :=pressedit.Text ;
- try
- parameters.ParamByName('outdate').Value :=strtodate(outtimeedit.Text) ;
- except
- messagedlg('参数<出版时间>设置错误',mtError,[mbok],0);
- exit;
- end;
- try
- parameters.ParamByName('cost').Value :=strtofloat(costedit.Text) ;
- except
- messagedlg('参数<价格>设置错误',mtError,[mbok],0);
- exit;
- end;
- try
- parameters.ParamByName('MMEMO').Value :=memo1.Text ;
- except
- messagedlg('memo erro',mterror,[mbok],0);
- exit;
- end;
- execSQL;
- end;
- Tabsheet1show(sender);
- except
- messagedlg('入库错误',mtError,[mbok],0);
- end;
- end;
- procedure Tbookform.Button2Click(Sender: TObject);
- begin
- close;
- end;
- procedure Tbookform.TabSheet2Show(Sender: TObject);
- var
- i:integer;
- begin
- combobox1.Items.Clear ;
- 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 Tbookform.ComboBox1Change(Sender: TObject);
- begin
- 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 locate('code',combobox1.Text ,[]) then
- edit
- else
- showmessage('not found ' );
- end;
- except
- messagedlg('数据操作出错',mtError,[mbok],0);
- end;
- end;
- end;
- procedure Tbookform.ComboBox1KeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- if key=13 then
- combobox1change(sender);
-
- end;
- end.