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;
      end;
    end
  else
     showmessage('姓名、密码不能为空。');
end;

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

end.
