cformlogin.pas
来自「Delphi深度探索,Delphi深度探索(第二版)」· PAS 代码 · 共 92 行
PAS
92 行
{-----------------------------------------------------------------------------
Unit Name: CFormLogin
Author: hubdog(陈省)
Purpose: 登陆界面
BeginDate 2002-7-8
History:
-----------------------------------------------------------------------------}
unit CFormLogin;
{PUBDIST}
interface
uses
IWAppForm, IWApplication, IWTypes, IWCompLabel, Classes, Controls,
IWControl, IWCompEdit, IWCompButton, SysUtils, Variants, IWBaseControl,
IWCompCheckbox;
type
TformLogin = class(TIWAppForm)
iweUser: TIWEdit;
IWLabel1: TIWLabel;
IWLabel2: TIWLabel;
iwePass: TIWEdit;
iwbConfirm: TIWButton;
iwbClear: TIWButton;
iwcbSaveLogin: TIWCheckBox;
iwbtnNew: TIWButton;
procedure iwbConfirmClick(Sender: TObject);
procedure iwbtnNewClick(Sender: TObject);
public
end;
var
formLogin: TFormLogin;
implementation
{$R *.dfm}
uses
ServerController, DatamoduleUnit, CWebUtils, CHR, CFormNewUser;
procedure TformLogin.iwbConfirmClick(Sender: TObject);
var
Cookies: TStrings;
begin
if (trim(iweUser.Text) = '') or (trim(iwePass.Text) = '') then
begin
WebApplication.ShowMessage('必须输入用户名和密码');
Exit;
end;
//
with dmHR do
begin
badoOperator.Active := True;
if not badoOperator.Locate('OperName;OperPass',
VarArrayOf([trim(iweUser.Text), trim(iwePass.Text)]), []) then
begin
WebApplication.ShowMessage('无效的用户名或口令,请重新输入');
Exit;
end
else
begin
//在Session中记录用户ID
UserSession.Id := badoOperator.FieldByName('OperID').AsInteger;
//写Cookie
if iwcbSaveLogin.Checked then
begin
Cookies := TStringList.create;
try
Cookies.Add(format('UserId=%d', [UserSession.Id]));
Webapplication.Response.SetCookieField(
Cookies, '', '', Now + 30 {保存登陆状态一个月}, False);
finally
Cookies.Free;
end;
end;
end;
Move(Tformmain);
end;
end;
procedure TformLogin.iwbtnNewClick(Sender: TObject);
begin
Move(TformNewUser);
end;
initialization
TformLogin.SetAsMainForm;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?