?? unit4.pas
字號:
unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
Tfrmlogin = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
//************************************
//處理錯誤函數,寫入project1.err,全局
//************************************
procedure werror(ss:string);
var
frmlogin: Tfrmlogin;
implementation
uses Unit3, Unit1;
{$R *.dfm}
procedure Tfrmlogin.FormCreate(Sender: TObject);
var sys_path:string;
begin
sys_path:=ExtractFileName(application.ExeName);
sys_path:=copy(sys_path,1,pos('.',sys_path));
sys_path:=ExtractFilePath(application.ExeName)+sys_path;
if not fileexists(sys_path+'mdb') then
begin
application.MessageBox(pchar('找不到數據庫:'+sys_path+'mdb'),'',64);
exit;
end;
dm1.ADOCon1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='
+sys_path+'mdb;Persist Security Info=False;';
try
dm1.ADOCon1.Connected:=true;
except
application.MessageBox(pchar('找不到數據庫:'+sys_path+'.mdb'),'',64);
end;
BitBtn1.Enabled:=true;
end;
procedure Tfrmlogin.BitBtn1Click(Sender: TObject);
var pas:string;
begin
if trim(edit1.Text)='' then
begin
application.MessageBox('請輸入用戶名','',64);
modalresult:=mrnone;
exit;
end;
if uppercase(edit1.Text)='ADMIN' then //管理員
begin
dm1.ADOQuery1.Close;
dm1.ADOQuery1.SQL.Text:='select passwd from admin';
dm1.ADOQuery1.Open;
if dm1.ADOQuery1.eof then
application.MessageBox('注意,沒有設置管理員口令','',64)
else
begin
pas:=trim(dm1.ADOQuery1.FieldByName('passwd').AsString);
if pas<>trim(edit2.Text) then
begin
application.MessageBox('口令錯誤','',64);
modalresult:=mrnone;
exit;
end;
if pas='' then
application.MessageBox('注意,管理員口令為空白','',64);
end;
end
else
begin //普通用戶
dm1.ADOQuery1.SQL.Text:='select passwd from users where name='''
+trim(edit1.Text)+'''';
dm1.ADOQuery1.Open;
if dm1.ADOQuery1.eof then
begin
dm1.ADOQuery1.close;
application.MessageBox('用戶不存在','',64);
modalresult:=mrnone;
exit;
end
else
begin
pas:=trim(dm1.ADOQuery1.FieldByName('passwd').AsString);
dm1.ADOQuery1.close;
if pas<>trim(edit2.Text) then
begin
application.MessageBox('口令錯誤','',64);
modalresult:=mrnone;
exit;
end;
end;
end;
users:=trim(edit1.Text);
end;
procedure werror(ss:string);
var e_file:textfile;
s:string;
begin
s:=ExtractFileName(APPLICATION.exeName);
if pos('.',s)<>-1 then
s:=copy(s,1,pos('.',s)-1);
ss:=datetostr(date)+' '+timetostr(time)+' '+ss;
AssignFile(e_file,ExtractFilePath(Application.ExeName)+s+'.err');
{$I-}
append(e_file);
{$I+}
if IOResult <> 0 then
rewrite(e_file);
writeln(e_file,ss);
CloseFile(e_file);
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -