delphi7中登陆判断的代码

2025-03-20 15:18:09
推荐回答(1个)
回答1:

procedure TfrmLogin.btnLoginClick(Sender: TObject);
begin
with ADOQuery do
begin
Close;
SQL.Text:='Select 用户名,密码 From 用户表 Where 用户名='''+
Trim(edtUserName.Text)+''' and 密码='''+Trim(edtPassword.Text)+'''';
Open;
end;
if ADOQuery.RecordCount>0 then
begin
with ADOQuery do
begin
Close;
SQL.Text:='Select 用户名,等级 From 用户表 Where 用户名='''+
Trim(edtUserName.Text)+''' and 等级=''管理''';
Open;
end;
if ADOQuery.RecordCount>0 then //如果不是管理员就是普通用户
begin
Application.CreateForm(TForm2, Form2);
Form2.Show;
end
else
begin
Application.CreateForm(TForm1, Form1);
Form1.Show;
end;
Close;
end
else
begin
MessageBox(Handle,'用户名称或密码不正确,请重新输入。','错误',MB_ICONERROR);
edtPassword.Clear;
edtPassword.SetFocus;
end;
end;