给你一段,自己看吧!
//用户登陆模块
unit pws_p;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, Db, BtChkBox,registry,ADODB, ExtCtrls, Label3D,
ComCtrls, Mask, DBCtrls;
type
Tf_pws = class(TForm)
Panel1: TPanel;
BitBtn2: TBitBtn;
Edit1: TEdit;
Edit2: TEdit;
BitBtn1: TBitBtn;
chk: TBitCheckBox;
Query1: TADOQuery;
Label2: TLabel;
Label3: TLabel;
Label3D1: TLabel3D;
Label3D2: TLabel3D;
Panel2: TPanel;
Label1: TLabel;
Label4: TLabel;
DBEdit1: TDBEdit;
Label5: TLabel;
DataSource1: TDataSource;
Query1dwbh: TStringField;
Query1yhbh: TStringField;
Query1yhxm: TStringField;
Query1dlmc: TStringField;
Query1mm: TStringField;
Query1qx: TStringField;
Query1sybz: TSmallintField;
procedure BitBtn2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormClose(Sender: TObject
var Action: TCloseAction);
procedure Edit1KeyDown(Sender: TObject
var Key: Word;
Shift: TShiftState);
procedure Edit2KeyDown(Sender: TObject
var Key: Word;
Shift: TShiftState);
procedure Edit1Exit(Sender: TObject);
procedure Edit1Change(Sender: TObject);
private
canceled:boolean
i:integer;
public
{ Public declarations }
end;
var
f_pws: Tf_pws;
implementation
uses main_p;
{$R *.DFM}
procedure Tf_pws.BitBtn2Click(Sender: TObject);
begin
application.Terminate;
end;
procedure Tf_pws.FormShow(Sender: TObject);
var r:tregistry;
begin
canceled:=true;
try
r:=tregistry.Create;
r.RootKey:=HKEY_CURRENT_USER;
r.OpenKey('/software/CfitSoftWare',true);
if r.ReadString('rem')='1' then
begin
edit1.Text:=r.ReadString('userid');
edit2.text:='';
end;
r.free;
except
r.free;
end;
end;
procedure Tf_pws.BitBtn1Click(Sender: TObject);
var r:tregistry;
begin
//密码检测
if (trim(edit1.text)='spusr') and (trim(edit2.text)='sdsczt') then
begin
f_main.usrid:='spusr';
f_main.qx:='00100111';
f_main.usrname:='超级用户';
canceled:=false;
f_main.logs('信息管理系统','登录系统');
close;
exit;
end;
inc(i);
try
if query1.IsEmpty then
begin
if i>3 then
begin
application.MessageBox('你无权使用本系统!','错误信息',48);
f_main.adodb.close;
application.Terminate;
exit;
end;
application.MessageBox('帐号错误,请重新输入!','错误信息',48);
edit1.SetFocus;
exit;
end
else
begin
if trim(edit2.Text)<>trim(query1.FieldByName('mm').asstring) then
begin
if i>3 then
begin
application.MessageBox('你无权使用本系统!','错误信息',48);
f_main.adodb.close;
application.Terminate;
exit;
end;
application.MessageBox('密码错误,请重新输入!','错误信息',48);
edit2.Text:='';
edit2.SetFocus;
exit;
end;
end;
f_main.usrid:=trim(query1.fields[3].value);//用户帐号
f_main.qx:=trim(query1.fields[5].value)
//用户权限
f_main.usrname:=trim(query1.fields[2].value);//用户姓名
f_main.gsdwbh:=trim(query1.fieldbyname('dwbh').Value);
f_main.gsdwmc:=f_main.get_dwmc(copy(f_main.gsdwbh,1,2));
try
r:=tregistry.Create;
r.RootKey:=HKEY_CURRENT_USER;
if not r.OpenKey('/software/CFitSoftWare',true) then;
if chk.Checked then //记住用户的帐号,写注册表
begin
r.WriteString('userid',trim(edit1.text));
r.WriteString('rem','1')
end
else //不记忆用户帐号
begin
r.WriteString('userid','');
r.WriteString('rem','0')
end;
except
on e:exception do
begin
application.MessageBox(pchar('写注册表失败!'+#13+#13+e.Message),'错误信息',48);
end;
end;
r.Free;
canceled:=false;
close;
except
on e:exception do
begin
application.MessageBox(pchar('无法读取数据!'+#13+#13+'请与系统管理员联系!'+
#13+#13+e.Message),'错误信息',16);
f_main.adodb.close;
application.Terminate;
end;
end;
end;
procedure Tf_pws.FormClose(Sender: TObject
var Action: TCloseAction);
begin
if canceled=true then
begin
f_main.adodb.close;
application.Terminate;
end
end;
procedure Tf_pws.Edit1KeyDown(Sender: TObject
var Key: Word;
Shift: TShiftState);
begin
if key=13 then edit2.SetFocus;
end;
procedure Tf_pws.Edit2KeyDown(Sender: TObject
var Key: Word;
Shift: TShiftState);
begin
if key=13 then bitbtn1.Click;
end;
procedure Tf_pws.Edit1Exit(Sender: TObject);
begin
if (trim(edit1.Text)='') then exit;
query1.close;
query1.SQL.Text:='select * from x_yhb where dlmc=:dlmc and sybz=''1''';
query1.Parameters.ParamByName('dlmc').value:=trim(edit1.text);//帐号
if not f_main.sqlexec(query1,'无法读取数据!',0) then application.Terminate;
end;
procedure Tf_pws.Edit1Change(Sender: TObject);
begin
edit2.Text:='';
query1.close;
end;
end.