unit UserCtl;
interface
Uses Classes, Forms ,Windows ,SysUtils ,ADODB, IniFiles;
Type
TAppUser = Class(Tobject)
Private
UserID :String;
Public
UserName :String;
UserType :Integer;
Connection :TAdoConnection;
constructor Create();
destructor Destroy();override;
Function Login():Boolean;
Procedure SetPower();
Procedure RelasePower();
end;
Var AppUser:TAppUser;
implementation
uses Logon ,Main;
Const IniName ='AppInfo.ini';
U_SQL ='Select * From Operator Where ID=:UID and Pwd=:UPwd';
ErrTitle = '错误提示';
{ UserInfo }
constructor TAppUser.Create;
Var Ini:TIniFile;
begin
inherited;
Ini :=TIniFile.Create(ExtractFilePath(Application.ExeName)+IniName);
try
UserID:=Ini.ReadString('Init','DefaultUser','');
finally
Ini.Free;
end;
end;
destructor TAppUser.Destroy;
begin
inherited;
end;
//============================用户登录模块==============================
function TAppUser.Login(): Boolean;
Var Q_User:TAdoQuery;
Password :String;
LogTimes :Integer;
Loged :Boolean;
Ini:TIniFile;
begin
LogTimes :=0;
Loged :=False;
LoginForm :=TLoginForm.Create(Application);
LoginForm.Again :=False;
Q_User :=TAdoQuery.Create(nil);
Try
Q_User.Connection :=Connection;
Q_User.SQL.Text :=U_SQL;
LoginForm.Caption :='请登录系统';
Repeat
if LogTimes=3 then Break;
LoginForm.IdEdit.Text := UserID;
LoginForm.PwdEdit.Clear;
if LoginForm.ShowModal =2 then break;
LoginForm.Again :=True;
Inc(LogTimes);
UserID:=LoginForm.IdEdit.Text;
Password :=LoginForm.PwdEdit.Text;
Q_User.Close;
Q_User.Parameters.ParamByName('UID').Value :=UserID;
Q_User.Parameters.ParamByName('UPwd').Value :=Password;
Q_User.Open;
if Q_User.RecordCount<>0 then
Begin
UserName :=Q_User.FieldByName('Name').AsString;
UserType :=Q_User.FieldByName('Type').AsInteger;
Loged :=True;
Ini :=TIniFile.Create(ExtractFilePath(Application.ExeName)+IniName);
try
Ini.WriteString('Init','DefaultUser',UserID);
finally
Ini.Free;
end;
end
Else Application.MessageBox('用户名或密码错误',ErrTitle,MB_OK OR MB_ICONERROR);
Until Loged;
Result :=Loged;
finally
LoginForm.Free;
Q_User.Free;
end;
end;
procedure TAppUser.SetPower();
begin
With MainForm do
Begin
end;
end;
procedure TAppUser.RelasePower();
begin
//
end;
initialization
AppUser:=TAppUser.Create();
finalization
AppUser.Free;
end.
登陆界面参考代码