📄 u_loginform.pas
字号:
unit U_LoginForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBTables, ExtCtrls, OleCtrls,
Buttons;
type
TFrmLogin = class(TForm)
Panel1: TPanel;
UserCB: TComboBox;
PasswordEdit: TEdit;
CancelSB: TSpeedButton;
OkSB: TSpeedButton;
Label2: TLabel;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure OkSBClick(Sender: TObject);
procedure CancelSBClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure StopAltF4(var message:TWMCLOSE);message WM_CLOSE;
end;
var
FrmLogin: TFrmLogin;
LigonUser,LoginPass,GuestKind:string;
implementation
uses U_DataModule;
var
TryCount:word;
{$R *.dfm}
{ TForm1 }
procedure TFrmLogin.StopAltF4(var message: TWMCLOSE);
begin
exit;
end;
procedure TFrmLogin.FormCreate(Sender: TObject);
begin
TryCount:=0 ;
with DataModule1.Table1 do
begin
Open;
if RecordCount=0 then
begin
AppendRecord(['sa','123','操作']);
Application.Terminate;
end else
begin
First;
while not Eof do
begin
UserCB.Items.Add(Fields[0].AsString);
Next;
end;
end;
end;
end;
procedure TFrmLogin.OkSBClick(Sender: TObject);
var
Count:word;
begin
Count:=0;
LigonUser:=UserCB.Text;
if LigonUser='' then Showmessage('请确定用户名!');
with DataModule1.Table1 do
begin
if Locate('UserName',UserCB.Text,[loCaseInsensitive]) then
begin
LoginPass:=Trim(Fields[1].AsString); //用户密码
Inc(Count); //用户存在Count 加1
if LoginPass=Trim(PasswordEdit.Text) then
Inc(Count) //密码又正确 Count 再加1
else
ShowMessage('密码不对!');
end else
ShowMessage('用户不存在!');
if Count=2 then //Count=2 说明是合法用户,取出其类别
GuestKind:=Fields[2].AsString //用户类别
else
begin
if TryCount<3 then
begin
Inc(TryCount);
exit;
end else
Application.Terminate;
end;
end;
Close;
end;
procedure TFrmLogin.CancelSBClick(Sender: TObject);
begin
Application.Terminate;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -