📄 unit1.pas
字号:
unit Unit1;
//login
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, jpeg, ExtCtrls, Buttons;
type
Tfrm_login = class(TForm)
Image1: TImage;
Edit1: TEdit;
Edit2: TEdit;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure plogin;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Edit2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frm_login: Tfrm_login;
m:integer = 0;
s:boolean = False;
yonghu: string;
implementation
uses Unit2, Unit13, Unit5;
{$R *.dfm}
//-------------------------退出-----------------------------//
procedure Tfrm_login.SpeedButton2Click(Sender: TObject);
begin
if s=false then
application.Terminate
else
close;
end;
//-------------------------登陆---------------------------//
procedure Tfrm_login.SpeedButton1Click(Sender: TObject);
begin
m := m+1; //记录输入字数,如果大于3次。则失败
if edit1.Text='' then
application.MessageBox('请输入用户名','提示',64)
else
if edit2.Text='' then
application.MessageBox('请输入密码','提示',64)
else
plogin;
end;
//-----------------------登陆涵数-------------------//
procedure Tfrm_login.plogin;
begin
with Data1.ADOlogin do
begin
close;
sql.Clear;
sql.Add('select * from admin where admin = :a and pass = :b');
parameters.ParamByName('a').Value:=trim(edit1.Text);
parameters.ParamByName('b').Value:=trim(edit2.Text);
open;
end;
if Data1.ADOlogin.RecordCount>0 then
begin
yonghu := data1.ADOlogin.fieldByName('admin').Value;
s := True;
frm_main.StatusBar1.Panels[1].Text := yonghu; //MAIN窗口中状态条设置显示用户名
frm_main.StatusBar1.Panels[3].Text := datetostr(date()); //日期
close;
end
else
if m<3 then //输入错误次数小于3
begin
application.MessageBox('用户名或密码错误,请重新输入','提示',64);
edit1.Clear;
edit2.Clear;
edit1.SetFocus; //设焦点
end
else
begin
application.MessageBox('你无权使用本系统','提示',64);
application.Terminate;
end;
end;
//----------------------关闭--------------------------------//
procedure Tfrm_login.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if s=false then
application.Terminate;
end;
//--------------------密码DEYDOWN事件------------------//
procedure Tfrm_login.Edit2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if((Key = vk_Return) or (Key = vk_Down)) then
SpeedButton1Click(sender) //当按下回车或向下键时,执行登陆
else
Edit2.SetFocus;
if Key = vk_Up then
Edit1.SetFocus; //使EDIT1焦点
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -