⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit3.pas

📁 这个是我自主研发的图书管理系统的应用
💻 PAS
字号:
unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, Grids, DBGrids, DB, ADODB, ExtCtrls, Buttons,
  Menus;

type
  TForm3 = class(TForm)
    Panel1: TPanel;
    ADOConnection1: TADOConnection;
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    GroupBox1: TGroupBox;
    Panel2: TPanel;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    Label3: TLabel;
    RadioButton3: TRadioButton;
    RadioButton4: TRadioButton;
    Label4: TLabel;
    ComboBox1: TComboBox;
    Label5: TLabel;
    ComboBox2: TComboBox;
    Button1: TButton;
    Button2: TButton;
    StatusBar1: TStatusBar;
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ADOQuery2: TADOQuery;
    Label6: TLabel;
    DateTimePicker1: TDateTimePicker;
    procedure RadioButton1Click(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure DBGrid1DblClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    
  private
    { Private declarations }
  public
    { Public declarations }
  procedure ShowTeacherInfo();
  end;

var
  Form3:TForm3;
  
implementation
  uses unit1;

{$R *.dfm}
procedure Tform3.ShowTeacherInfo();
begin
 AdoQuery1.close;
 ADoQuery1.sql.clear;
 adoquery1.sql.text:='select * from Teacher,reader where '
 +'teacher.borrowbook_id=reader.borrowbook_id';
 Adoquery1.open;
 statusBar1.panels[0].text:='现有记录:'+intTostr(Adoquery1.recordcount)+'条';
end;
procedure TForm3.RadioButton1Click(Sender: TObject);
begin
 edit1.Clear;
 edit1.Enabled:=false;
end;
procedure TForm3.RadioButton2Click(Sender: TObject);
begin
edit1.Enabled:=true;
button1.Enabled:=true;
button2.Enabled:=False;
edit1.Clear;
edit2.Clear;
radiobutton3.Checked:=True;
combobox1.Text:='--请选择系别--';
combobox2.Text:='--请输入借书证号--';
end;
procedure TForm3.FormCreate(Sender: TObject);
begin
statusbar1.Panels[0].Text:='';
showteacherinfo();
RadioButton1Click(Sender);
button1.Enabled:=false;
button2.Enabled:=false;
AdoQuery1.close;
ADoQuery1.sql.clear;
adoquery1.sql.text:='select * from Teacher,reader where '
+'teacher.borrowbook_id=reader.borrowbook_id';
Adoquery1.open;
while not adoquery1.Eof do
  begin
    combobox1.Items.Add(adoquery1.fieldbyname('tdept').AsString);
    combobox2.Items.Add(adoquery1.fieldbyname('borrowbook_Id').AsString);
    adoquery1.Next;
  end;
end;
procedure TForm3.DBGrid1DblClick(Sender: TObject);
begin
 try
    edit1.Enabled:=False;
    button1.Enabled:=true;
    button2.Enabled:=true;
    radiobutton1.Checked:=true;
    edit1.Text:=adoquery1.fieldbyname('Tno').AsString;
    edit2.Text:=adoquery1.fieldbyname('Tn').AsString;
    if adoquery1.fieldbyname('Tsex').AsString='男' then
       radiobutton3.Checked:=true
    else radiobutton4.Checked:=true;
    combobox1.Text:=adoquery1.fieldbyname('Tdept').AsString;
    combobox2.Text:=adoquery1.fieldbyname('borrowbook_id').AsString;
    adoquery2.Close;
    ADoQuery2.sql.clear;
    adoquery2.sql.add('select * from reader where borrowbook_id=:id1');
    adoquery2.Parameters.ParamByName('id1').Value:=combobox2.Text;
    Adoquery2.open;
    datetimepicker1.Date:=adoquery2.fieldbyname('bzdate').AsDateTime;
    except
    application.MessageBox('请选择一条记录双击!','警告',MB_OK+MB_ICONWarning);
end;
end;
procedure TForm3.N1Click(Sender: TObject);
begin
 //animatewindow(handle,1000,aw_hide or aw_center);
  form3.Hide;
  //Application.CreateForm(Tform1,form1);
  animatewindow(form1.handle,1000,aw_Activate or aw_center);
  form1.Show;
end;
procedure TForm3.N2Click(Sender: TObject);
begin
 application.Terminate;
end;
procedure TForm3.Button1Click(Sender: TObject);
begin
 if (Trim(edit1.Text)='') or (Length(edit1.Text)<>5) then
    begin
       application.MessageBox('教师号必须五位长度!','警告',MB_OK+MB_ICONWarning);
       exit;
    end;
 if Trim(edit2.Text)='' then
    begin
       application.MessageBox('教师姓名不能为空!','警告',MB_OK+MB_ICONWarning);
       edit2.SetFocus;
       Exit;
    end;
 if combobox1.Text='--请选择系别--' then
  begin
     application.MessageBox('没有选择系别!','警告',MB_OK+MB_ICONWarning);
     combobox1.SetFocus;
     exit;
  end;
  if combobox2.Text='--请输入借书证号--' then
  begin
     application.MessageBox('借书证号为空!','警告',MB_OK+MB_ICONWarning);
     combobox1.SetFocus;
     exit;
  end;
  if radiobutton1.Checked then
    begin
       adoquery1.Close;
       adoquery1.SQL.clear;
       adoquery1.SQL.Add('select * from teacher,reader where tno=:t1 and '
       +'teacher.borrowbook_id=reader.borrowbook_id');
       adoquery1.Parameters.ParamByName('t1').Value:=edit1.Text;
       adoquery1.Open;
       adoquery1.Edit;
       adoquery1.FieldByName('tn').AsString:=edit2.Text;
       if radiobutton3.Checked then
          adoquery1.FieldByName('tsex').AsString:='男'
       else
          adoquery1.FieldByName('tsex').AsString:='女';
       adoquery1.FieldByName('tdept').AsString:=combobox1.Text;
       adoquery1.FieldByName('borrowbook_id').AsString:=combobox2.Text;
       adoquery1.Post;
       adoquery2.Close;
       ADoQuery2.sql.clear;
       adoquery2.sql.add('select * from reader where borrowbook_id=:id1');
       adoquery2.Parameters.ParamByName('id1').Value:=combobox2.Text;
       Adoquery2.open;
       adoquery2.Edit;
       adoquery2.fieldbyname('bzdate').AsDateTime:=datetimepicker1.Date;
       adoquery2.Post;
       application.MessageBox('记录修改成功!','成功',MB_OK+MB_ICONWarning);
     end
  else
   begin
     adoquery1.Close;
     adoquery1.SQL.Clear;
     adoquery1.SQL.Add('select * from teacher,reader where tno=:tno2 or '
     +'teacher.borrowbook_id=:bno and teacher.borrowbook_id=reader.borrowbook_id');
     adoquery1.Parameters.ParamByName('tno2').Value:=edit1.text;
     adoquery1.Parameters.ParamByName('bno').Value:=combobox2.text;
     adoquery1.Open;
     if adoquery1.RecordCount=0 then
       begin
          adoquery1.Append;
          adoquery1.FieldByName('tno').AsString:=edit1.Text;
          adoquery1.FieldByName('tn').AsString:=edit2.Text;
           if radiobutton3.Checked then
          adoquery1.FieldByName('tsex').AsString:='男'
       else
       adoquery1.FieldByName('tsex').AsString:='女';
       adoquery1.FieldByName('tdept').AsString:=combobox1.Text;
       adoquery1.FieldByName('borrowbook_id').AsString:=combobox2.Text;
       adoquery1.Post;
       ADoQuery2.sql.clear;
       adoquery2.sql.add('select * from reader where borrowbook_id=:id1');
       adoquery2.Parameters.ParamByName('id1').Value:=combobox2.Text;
       Adoquery2.open;
       adoquery2.Edit;
       adoquery2.fieldbyname('bzdate').AsDateTime:=datetimepicker1.Date;
       adoquery2.Post;
       application.MessageBox('记录增加成功!','成功',MB_OK+MB_ICONWarning);
       RadioButton2Click(Sender);
       end
     else
       begin
         application.MessageBox('教师号或借书证号重复,请检查!','出错',MB_OK+MB_ICONWarning);
         edit1.SetFocus;
         edit1.SelectAll;
       end;
   end;
   showTeacherinfo();
end;
procedure TForm3.Button2Click(Sender: TObject);
begin
 if Trim(edit1.Text)='' then
   begin
     application.MessageBox('没有选择欲删除的记录!  请在列表中双击欲删除的记录','出错',MB_OK+MB_ICONWarning);
     exit;
   end;
 case application.MessageBox('确实要欲删除记录吗?','删除确认',MB_OKcancel+MB_ICONinformation) of
 IDCancel:;
 IDOK:
      begin
        adoquery1.Close;
        adoquery1.SQL.Clear;
        adoquery1.SQL.Add('delete from teacher where tno='''+edit1.text+'''');
        adoquery1.ExecSQL;
        application.MessageBox('删除记录成功!','成功',MB_OK+MB_ICONinformation);
        edit1.Clear;
        edit2.Clear;
        radiobutton3.Checked:=true;
        combobox1.Text:='--请选择系别--';
        combobox2.Text:='--请输入借书证号--';
        button2.Enabled:=false;
        showteacherinfo();
      end;
 end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -