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

📄 simple2.~pas

📁 delphi renyuanguanlixinxioxitong
💻 ~PAS
字号:
unit Simple2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, DBCtrls, Mask, DB, Grids, DBGrids, ADODB;

type
  TfrmSimple2 = class(TForm)
    adoConnection: TADOConnection;
    atbDepartment: TADOTable;
    aqryEmployee: TADOQuery;
    Label1: TLabel;
    edtEmployeeNo: TEdit;
    dbgEmployee: TDBGrid;
    dsEmployee: TDataSource;
    DBEdit1: TDBEdit;
    DBNavigator1: TDBNavigator;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    DBEdit2: TDBEdit;
    DBEdit3: TDBEdit;
    dbgDepartment: TDBGrid;
    btnSearch: TButton;
    dsDepartment: TDataSource;
    procedure FormShow(Sender: TObject);
    procedure btnSearchClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmSimple2: TfrmSimple2;

implementation

{$R *.dfm}
//当表单显示时,建立数据库的连接,并打开相应的表
procedure TfrmSimple2.FormShow(Sender: TObject);
begin
  //当表单显示时,建立数据库的连接
  if adoConnection.Connected then adoConnection.Close ;
  try
    adoConnection.Open ;
  except
    application.MessageBox('连接数据库出错','错误');
    application.Terminate ;   //应用程序终止
  end;
  //打开部门表
  try
    atbDepartment.Open ;
  except
    application.MessageBox('打开部门表出错','错误');
    application.Terminate ;   //应用程序终止
  end;
  //给aqryEmployee组件设置查询员工的SQL语句
  aqryEmployee.SQL.Clear ;
  aqryEmployee.SQL.Add('select * from Employee')  ;
  //将员工表所有的内容显示出来
  try
    aqryEmployee.Open ;
  except
    application.MessageBox('打开员工表出错','错误');
    application.Terminate ;   //应用程序终止
  end;
end;
//按用户输入的条件检索员工信息
procedure TfrmSimple2.btnSearchClick(Sender: TObject);
var
  sEmployeeNo :string;
begin
   sEmployeeNo  := trim(edtEmployeeNo.Text)+'%';
   if aqryEmployee.Active then aqryEmployee.Close;
   aqryEmployee.SQL.Clear ;
   aqryEmployee.SQL.Add('select * from Employee');
   aqryEmployee.SQL.Add('where EmployeeNo like :sEmployeeNo1') ;
   aqryEmployee.Parameters.ParamByName('sEmployeeNo1').Value := sEmployeeNo;
   try
    aqryEmployee.Open ;
  except
    application.MessageBox('打开员工表出错','错误');
  end;
end;
//当退出程序时断开与数据库的连接,释放资源
procedure TfrmSimple2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if aqryEmployee.Active then aqryEmployee.Close;
  if atbDepartment.Active then atbDepartment.Close;
  if adoConnection.Connected then adoConnection.Close ;
end;

end.

⌨️ 快捷键说明

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