D
dreamblue
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db, DBTables;
type
TForm2 = class(TForm)
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Query1: TQuery;
ComboBox1: TComboBox;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.DFM}
procedure TForm2.Button1Click(Sender: TObject);
begin
with query1 do
begin
close;
sql.clear;
sql.add('select yonghu,mima,qx from pasw.db where yonghu=:yonghu and mima=:mima and qx=:qx');
params[0].asstring:=combobox1.text;
params[1].asstring:=edit2.text;
open;
if query1.recordcount>0 then
begin
if params[2].asstring:='1' then
begin
form2.hide;
form1.show;
form1.n1.Enabled:=fasle;
end
else
begin
form2.hide;
form1.show;
end;
end
else
showmessage('您输入的用户名或密码错误');
combobox1.text:='';
edit2.text:='';
end;
注:以上代码的目地是根据权限判断登陆后的界面菜单是否显示。
数据库pas.db中
yonghu代表用户
mima代表密码
qx代表权限
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db, DBTables;
type
TForm2 = class(TForm)
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Query1: TQuery;
ComboBox1: TComboBox;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.DFM}
procedure TForm2.Button1Click(Sender: TObject);
begin
with query1 do
begin
close;
sql.clear;
sql.add('select yonghu,mima,qx from pasw.db where yonghu=:yonghu and mima=:mima and qx=:qx');
params[0].asstring:=combobox1.text;
params[1].asstring:=edit2.text;
open;
if query1.recordcount>0 then
begin
if params[2].asstring:='1' then
begin
form2.hide;
form1.show;
form1.n1.Enabled:=fasle;
end
else
begin
form2.hide;
form1.show;
end;
end
else
showmessage('您输入的用户名或密码错误');
combobox1.text:='';
edit2.text:='';
end;
注:以上代码的目地是根据权限判断登陆后的界面菜单是否显示。
数据库pas.db中
yonghu代表用户
mima代表密码
qx代表权限