unit login;

interface

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

type
  TfrmLogin = class(TForm)
    Label1: TLabel;
    edtName: TEdit;
    Label2: TLabel;
    edtPass: TEdit;
    Button1: TButton;
    Button2: TButton;
    Panel1: TPanel;
    ADODataSet1: TADODataSet;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmLogin: TfrmLogin;
implementation
//单元引
uses admin;

{$R *.dfm}

procedure TfrmLogin.Button2Click(Sender: TObject);
begin
  close;
end;

procedure TfrmLogin.Button1Click(Sender: TObject);
begin
  strName:=edtName.Text;        //取用户输入的用户名
  strPassword:=edtPass.Text;    //取用户输入的密码
  if (strName<>'')and(strPassword<>'') then
    begin
      with ADODataSet1 do  begin
        Close;
        CommandText:='select * from admins where name='''+strName+''' and password='''+strPassword+'''';
        open;
        if isempty then     //查询结果记录集为空
          showmessage('姓名或密码错。')
        else  begin
            frmAdmin.Enabled :=true;   //允许主界面
            self.Close;        //关闭登录界面
            edtName.Text:='';  //清空编辑框
            edtPass.Text:='';
          end;
        close;      //关闭数据集ADODataSet1
      end;
    end
  else
     showmessage('姓名、密码不能为空。');
end;

procedure TfrmLogin.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if strName='' then
     frmAdmin.Close;    //如果没有登录，则关闭主界面
end;

end.
