主题:[讨论]为什么用户权限的设定不好使呢?高手帮忙看看是哪里出错了吧~很急~~
是代码出了问题吗???
这是用户检测窗体的代码:
unit checkusr;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, jpeg, ExtCtrls, DB, ADODB;
type
TCheckUserForm = class(TForm)
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
ADOConnection1: TADOConnection;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
CheckUserForm: TCheckUserForm;
i:integer;
username:string; //用户名
qx:array[1..4] of boolean; //权限
implementation
uses main;
{$R *.dfm}
procedure TCheckUserForm.Button1Click(Sender: TObject);
var
Adodataset1:TAdoDataset;
begin
AdoDataSet1:=TAdoDataset.Create(self);
adoDataset1.Connection:=adoconnection1;
adodataset1.CommandType:=cmdtext;
Adodataset1.CommandText:='select * from 操作员信息表 where 用户名=:username and 密码=:password';
adodataset1.close;
Adodataset1.Parameters.Clear;
Adodataset1.Parameters.AddParameter;
adodataset1.Parameters[0].name:='username';
adodataset1.Parameters[0].DataType:=ftstring;
Adodataset1.Parameters[0].Direction:=pdinput;
adodataset1.Parameters[0].Value:=edit1.text;
Adodataset1.Parameters.AddParameter;
adodataset1.Parameters[1].name:='password';
adodataset1.Parameters[1].DataType:=ftstring;
Adodataset1.Parameters[1].Direction:=pdinput;
adodataset1.Parameters[1].Value:=edit2.text;
adodataset1.active:=true;
if adodataset1.Recordset.RecordCount=1 then
begin
username:=edit1.Text;
qx[1]:=adodataset1.FieldByName('权限一').asboolean;
qx[2]:=adodataset1.FieldByName('权限二').asboolean;
close;
end
else
begin
Application.MessageBox('您输入的用户名或密码错误,请检查!','提示信息',mb_ok);
i:=i-1;
edit1.text:='';
edit2.text:='';
edit1.SetFocus;
end;
if i=0 then
begin
username:='';
close;
end;
adodataset1.Active:=false;
end;
procedure TCheckUserForm.Button2Click(Sender: TObject);
begin
CheckUserForm.close;
MainForm.Close;
end;
procedure TCheckUserForm.FormActivate(Sender: TObject);
begin
i:=3;
edit1.text:='';
edit2.Text:='';
edit1.SetFocus;
end;
end.
这是主窗体关于用户权限设定的代码:
var
MainForm: TMainForm;
username: string; //用户名
qx: array[1..4] of boolean; //四个权限
procedure TMainForm.FormActivate(Sender: TObject);
begin
CheckUserForm.ShowModal();
if username <> '' then
begin
if qx[1] then
begin
N5.Enabled := true;
N6.Enabled := true;
N7.Enabled := true;
N10.Enabled := true;
N12.Enabled := true;
N11.Enabled := true;
N13.Enabled := true;
N14.Enabled := true;
N15.Enabled := true;
N16.Enabled := true;
Button1.Enabled := true;
Button2.Enabled := true;
Button3.Enabled := true;
Button4.Enabled := true;
Button5.Enabled := true;
Button6.Enabled := true;
Button7.Enabled := true;
Button8.Enabled := true;
Button9.Enabled := true;
Button10.Enabled := true;
end
else
begin
N5.Enabled := false;
N6.Enabled := false;
N7.Enabled := false;
N10.Enabled := false;
N12.Enabled := false;
N11.Enabled := false;
N13.Enabled := false;
N14.Enabled := false;
N15.Enabled := false;
Button1.Enabled := false;
Button2.Enabled := false;
Button3.Enabled := false;
Button4.Enabled := false;
Button5.Enabled := false;
Button6.Enabled := false;
Button7.Enabled := false;
Button8.Enabled := false;
end;
if qx[2] then
begin
N6.Enabled := true;
N17.Enabled := true;
N1.Enabled := true;
Button9.Enabled := true;
Button10.Enabled := true;
end
else
begin
N6.Enabled := false;
N17.Enabled := false;
N1.Enabled := false;
Button9.Enabled := false;
Button10.Enabled := false;
end;
end;
end;
这是用户检测窗体的代码:
unit checkusr;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, jpeg, ExtCtrls, DB, ADODB;
type
TCheckUserForm = class(TForm)
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
ADOConnection1: TADOConnection;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
CheckUserForm: TCheckUserForm;
i:integer;
username:string; //用户名
qx:array[1..4] of boolean; //权限
implementation
uses main;
{$R *.dfm}
procedure TCheckUserForm.Button1Click(Sender: TObject);
var
Adodataset1:TAdoDataset;
begin
AdoDataSet1:=TAdoDataset.Create(self);
adoDataset1.Connection:=adoconnection1;
adodataset1.CommandType:=cmdtext;
Adodataset1.CommandText:='select * from 操作员信息表 where 用户名=:username and 密码=:password';
adodataset1.close;
Adodataset1.Parameters.Clear;
Adodataset1.Parameters.AddParameter;
adodataset1.Parameters[0].name:='username';
adodataset1.Parameters[0].DataType:=ftstring;
Adodataset1.Parameters[0].Direction:=pdinput;
adodataset1.Parameters[0].Value:=edit1.text;
Adodataset1.Parameters.AddParameter;
adodataset1.Parameters[1].name:='password';
adodataset1.Parameters[1].DataType:=ftstring;
Adodataset1.Parameters[1].Direction:=pdinput;
adodataset1.Parameters[1].Value:=edit2.text;
adodataset1.active:=true;
if adodataset1.Recordset.RecordCount=1 then
begin
username:=edit1.Text;
qx[1]:=adodataset1.FieldByName('权限一').asboolean;
qx[2]:=adodataset1.FieldByName('权限二').asboolean;
close;
end
else
begin
Application.MessageBox('您输入的用户名或密码错误,请检查!','提示信息',mb_ok);
i:=i-1;
edit1.text:='';
edit2.text:='';
edit1.SetFocus;
end;
if i=0 then
begin
username:='';
close;
end;
adodataset1.Active:=false;
end;
procedure TCheckUserForm.Button2Click(Sender: TObject);
begin
CheckUserForm.close;
MainForm.Close;
end;
procedure TCheckUserForm.FormActivate(Sender: TObject);
begin
i:=3;
edit1.text:='';
edit2.Text:='';
edit1.SetFocus;
end;
end.
这是主窗体关于用户权限设定的代码:
var
MainForm: TMainForm;
username: string; //用户名
qx: array[1..4] of boolean; //四个权限
procedure TMainForm.FormActivate(Sender: TObject);
begin
CheckUserForm.ShowModal();
if username <> '' then
begin
if qx[1] then
begin
N5.Enabled := true;
N6.Enabled := true;
N7.Enabled := true;
N10.Enabled := true;
N12.Enabled := true;
N11.Enabled := true;
N13.Enabled := true;
N14.Enabled := true;
N15.Enabled := true;
N16.Enabled := true;
Button1.Enabled := true;
Button2.Enabled := true;
Button3.Enabled := true;
Button4.Enabled := true;
Button5.Enabled := true;
Button6.Enabled := true;
Button7.Enabled := true;
Button8.Enabled := true;
Button9.Enabled := true;
Button10.Enabled := true;
end
else
begin
N5.Enabled := false;
N6.Enabled := false;
N7.Enabled := false;
N10.Enabled := false;
N12.Enabled := false;
N11.Enabled := false;
N13.Enabled := false;
N14.Enabled := false;
N15.Enabled := false;
Button1.Enabled := false;
Button2.Enabled := false;
Button3.Enabled := false;
Button4.Enabled := false;
Button5.Enabled := false;
Button6.Enabled := false;
Button7.Enabled := false;
Button8.Enabled := false;
end;
if qx[2] then
begin
N6.Enabled := true;
N17.Enabled := true;
N1.Enabled := true;
Button9.Enabled := true;
Button10.Enabled := true;
end
else
begin
N6.Enabled := false;
N17.Enabled := false;
N1.Enabled := false;
Button9.Enabled := false;
Button10.Enabled := false;
end;
end;
end;