⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmlogin.pas

📁 物流供应链管理系统
💻 PAS
字号:
unit frmLogin;
{******************************************************
作者:杨中科
描述:登录对话框
*******************************************************}
interface

uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, 
  Buttons, ExtCtrls, DB, ADODB;


type
  TFormLogin = class(TForm)
    BtnLogin: TButton;
    BtnExit: TButton;
    LEdtUserId: TLabeledEdit;
    LEdtPassword: TLabeledEdit;
    BtnAdv: TButton;
    LEdtConnectString: TLabeledEdit;
    BtnSel: TButton;
    BtnRestore: TButton;
    ADOTSysOperator: TADOTable;
    ADOTSysLog: TADOTable;
    ADOCon: TADOConnection;
    ADOTPermission: TADOTable;
    Button1: TButton;
    procedure BtnAdvClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BtnSelClick(Sender: TObject);
    procedure BtnRestoreClick(Sender: TObject);
    procedure BtnLoginClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    FConnectionString: String;
    FIsLegal: Boolean;
    FPermissionList: TStringList;
    FTryTimes: Integer;
  public
    { Public declarations }
    function IsLegal: Boolean;//判断是否登录成功
    function GetUserId: string;//取得用户输入的用户名
    function GetPassword: string;//取得密码
    function GetUserRightList: string;//取得用户权限列表
    function GetConnectionString: string;//取得连接字符串
  end;

var
  FormLogin: TFormLogin;

implementation
uses untConfig,AdoConEd, CommonFunc, untGlobal;
{$R *.dfm}

procedure TFormLogin.BtnAdvClick(Sender: TObject);
begin
  if '高级(&A)>>' = (Sender as TButton).Caption then
  begin
    (Sender as TButton).Caption := '高级(&A)<<';
    self.Height := 260;
  end
  else
  begin
    (Sender as TButton).Caption := '高级(&A)>>';
    self.Height := 170;
  end;
end;

function TFormLogin.IsLegal: Boolean;
begin
  result := FIsLegal;
end;

function TFormLogin.GetUserId: String;
begin
  result := Trim(LEdtUserId.Text);
end;

function TFormLogin.GetPassword: string;
begin
  result := Trim(LEdtPassword.Text);
end;

function TFormLogin.GetUserRightList: String;
begin
  result := FPermissionList.Text;
end;

function TFormLogin.GetConnectionString: String;
begin
  result := FConnectionString;
end;



procedure TFormLogin.FormCreate(Sender: TObject);
begin
  FConnectionString := untConfig.GetConnectionString;
  LEdtConnectString.Text := FConnectionString;
  FIsLegal := false;
  ADOCon.Close;
  ADOCon.ConnectionString := FConnectionString;
  FPermissionList := TStringList.Create;
  FPermissionList.Text := '';
  FTryTimes := 0;
end;

procedure TFormLogin.BtnSelClick(Sender: TObject);
begin
  if EditConnectionString(ADOCon) then
  begin
    FConnectionString := ADOCon.ConnectionString;
    LEdtConnectString.Text := FConnectionString;
    SetConnectionString(FConnectionString);
  end;

end;

procedure TFormLogin.BtnRestoreClick(Sender: TObject);
begin
  FConnectionString := GetDefaultConnectionString;
  LEdtConnectString.Text := FConnectionString;
  SetConnectionString(FConnectionString);
end;

procedure TFormLogin.BtnLoginClick(Sender: TObject);
var
  LUserId, LPws: string;
  LPerId: Integer;
begin
  if (not CheckInput(LEdtUserId)) or (not CheckInput(LEdtPassword)) then
    exit;
  if FTryTimes >= 3 then
  begin
    LCShowMessage('尝试次数多于3次,禁止尝试,退出系统!');
    Application.Terminate;
  end;
  LUserId := Trim(LEdtUserId.Text);
  LPws := Trim(LEdtPassword.Text);
  try
    ADOCon.Open;
    ADOTSysOperator.Open;
    if ADOTSysOperator.Locate('UserId', LUserId, []) then
    begin
      if LPws = ADOTSysOperator.FieldByName('Password').AsString then //合法验证
      begin
        LPerId := ADOTSysOperator.FieldByName('PermissionId').AsInteger;
        ADOTSysOperator.Close;
        ADOTPermission.Open;
        if ADOTPermission.Locate('MasterId', LPerId, []) then
        begin
          FPermissionList.Clear;     //填充权限表
          while not ADOTPermission.Eof do
          begin
            FPermissionList.Add(ADOTPermission.FieldByName('Func').AsString);
            ADOTPermission.Next;
          end;
        end;
        ADOTPermission.Close;
        ADOTSysLog.Open;
        ADOTSysLog.Append;       //记录登录日志
        ADOTSysLog.FieldByName('UserId').AsString := LUserId;
        ADOTSysLog.FieldByName('LogInDateTime').AsDateTime := Now();
        try
          ADOTSysLog.Post;
        except
          ADOTSysLog.Cancel;
          ADOCon.Close;
          raise Exception.Create(ERRORPOSTDB);
        end;
        self.ModalResult := mrOK;
      end
      else
      begin
        LCShowMessage(ERRORPASSWORD);
        Inc(FTryTimes);
      end;
    end
      else
      begin
        LCShowMessage(ERRORUSERID);
        Inc(FTryTimes);
      end;
  except
    ADOCon.Close;
    raise Exception.Create(ERRORPOSTDB);
  end;
end;

procedure TFormLogin.Button1Click(Sender: TObject);
begin
  FIsLegal := true;
  FPermissionList.Add('SysAdmin');
end;

procedure TFormLogin.FormDestroy(Sender: TObject);
begin
  FPermissionList.Free;
end;

end.

⌨️ 快捷键说明

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