var
LoginForm: TLoginForm;
i: integer;
username: string;
//password: integer;
implementation
uses unit1, Unit13;
{$R *.dfm}
procedure TLoginForm.FormActivate(Sender: TObject);
begin
i:=4;
Edit1.text:='';
Edit2.text:='';
Edit1.setFocus;
end;
procedure TLoginForm.BitBtn1Click(Sender: TObject);
begin
with Datamoduleunit do
begin
i := i - 1;
if i = 0 then
begin
Application.MessageBox('非法用户,系统将退出!', '提示', Mb_Ok or Mb_IconStop);
Application.Terminate;
end;
if userquery1.Locate('用户名称', Trim(edit1.text), []) then
begin
if Edit2.Text = Userquery1.FieldByName('用户密码').AsString then
begin
Close;
UserName := edit1.Text;
Mainform.StatusBar1.Panels.Items[2].Text := UserName;
end
else
begin
Application.MessageBox('密码错误!', '提示', Mb_Ok or Mb_IconStop);
Edit1.SetFocus;
Edit1.SelectAll;
end;
end;
end;
end;
procedure TLoginForm.BitBtn2Click(Sender: TObject);
begin
application.messagebox('您确定要退出吗?','提示信息',mb_ok);
close;
end;
以及主程序的调用
procedure TMainForm.FormActivate(Sender: TObject);
var
Path: string;
begin
Path := ExtractFilePath(Application.ExeName);
//i:= 3;
with DatamoduleUnit do
begin
adoconnection1.LoginPrompt :=false;
ADOConnection1.Connected := False;
ADOConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + Path + '\CRMDB.mdb;Persist Security Info=False';
ADOConnection1.Connected := True;
with userquery1 do
begin
Close;
SQL.Clear;
Sql.Add('select * from 用户信息表');
try
Open;
except
end;
if IsEmpty then
begin
Close;
SQL.Clear;
SQL.Add('Insert into 用户信息表 values (''001'',''系统管理员'',''001'',''网络部'','''','''','''','''','''')');
try
ExecSql;
except
end;
end;
end;
if not Assigned(LoginForm) then
begin
LoginForm := TLoginForm.Create(Self);
end;
LoginForm.ShowModal;
LoginForm.Free;
end;
end;