unitlogin.pas

来自「delphi做的名片管理软件」· PAS 代码 · 共 86 行

PAS
86
字号
unit Unitlogin;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, DB, ADODB, StdCtrls;
type
  TLoginFrm = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  LoginFrm: TLoginFrm;

implementation

uses UnitDataModule,UnitMain;

var username,password:String;
{$R *.dfm}

procedure TLoginFrm.Button1Click(Sender: TObject);

begin

  if self.Edit1.Text='' then
      messagebox(LoginFrm.handle,'请输入用户名','警告',mb_ok+mb_iconwarning)
   else
      if self.Edit2.Text='' then
         messagebox(LoginFrm.handle,'请输入密码','警告',mb_ok+mb_iconwarning)
   else
   begin
      username:=edit1.text;
      password:=edit2.text;
      with DataModule1.ADOQuery1 do //查询数据库来判断用户合法性
      begin
        Close;
        SQL.Clear;
        SQL.add('select * from userinfo where username=');
        SQL.add(''''+username+''''+'and password='+''''+password+'''');
        open;
        first;
        if recordcount=1 then //如果用户名和密码正确
        begin
           MainFrm.Edit3.Text:= DataModule1.ADOQuery1.fieldByName('id').AsString;
           LoginFrm.Hide;//登录界面隐藏
           MainFrm.Show; //进入界面
        end else  //如果用户名和密码错误将弹出警告
          messagebox(LoginFrm.handle,'请输入正确的用户名或密码','警告',mb_ok+mb_iconwarning);
         
      end;
    end;
end;

procedure TLoginFrm.Button2Click(Sender: TObject);
begin
   if MainFrm.Showing=False then
   begin
      Application.terminate; //退出系统
   end else
   begin
      self.Close;
   end;
end;


procedure TLoginFrm.FormKeyPress(Sender: TObject; var Key: Char);
begin
    if key=#13 then
       SelectNext(Sender as TWinControl, True, True);
end;

end.

⌨️ 快捷键说明

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