我要做的是一个仓库管理系统,当毕业设计用的,遇到让我头疼的问题就是登录窗口,
首先运行系统需要弹出登录窗口确认身份,可是我花了好几天时间看了好多例子,结果是---别人的系统用到我
的系统就不行了!
我详细说下我的登录窗口:
放了两个Labe,一个写用户名一个写密码;一个ComboBox,Edit分别是登录时要输入的用户名和密码,两个BitBtn一个确定一个取消.
我的数据库是ACESS的,ADOConnection1,ADOQuery1,ADOTable1,DateSouce1各一个,我确定数据库连接完好.
ACESS里面 denglu表
username password
zxz 123
一个主窗体,还有其他功能窗体.
---------------------------------------------------------------
代码写这样:
确定按钮代码:
procedure TyhdlForm.BitBtn1Click(Sender: TObject);
var
username:string;
password:Boolean;
i:integer;
a,b:string;
begin
try
with adoquery1 do
begin
close;
sql.clear;
sql.add('select * from denglu where username and password');
parameters.ParamByName('username').Value:=trim(Edit1.Text);
parameters.ParamByName('password').Value:=trim(Edit2.Text);
if Edit1.Text ='' then
begin
application.MessageBox('请输入用户名','提示信息',64);
Edit1.SetFocus;
exit;
end;
if edit2.Text ='' then
begin
application.MessageBox('请输入密码','提示信息',64);
edit1.SetFocus;
exit;
end; end;
if adoquery1.RecordCount<>0 then
begin
Edit1.Text:='username';
Edit2.Text:='password';
application.MessageBox('登陆成功','提示信息',64);
mainForm.Show;
yhdlForm.Hide;
end
else
application.MessageBox('输入的用户名或密码错误','提示信息',64);
except
application.MessageBox('登陆失败','提示信息',64);
end;
end;end.
取消按钮代码:
procedure TyhdlForm.BitBtn2Click(Sender: TObject);
begin
close;
end;
---------------------------------------------------------------
我看很多书上都在工程文件上写上调用,可是不管我怎么弄登录窗口就是没弹出来,我想问你们到底该怎么写调用才是对的呢?
{$R *.res}
var
yhdlForm:TyhdlForm;begin
Application.Initialize;
Application.CreateForm(TmainForm, mainForm);
Application.CreateForm(TyhdlForm, yhdlForm);
yhdlForm:=TyhdlForm.Create(nil);
Try
yhdlForm.ShowModal; //显示登录窗口 , 这句系统提示出错
Finally
yhdlForm.Free;
end;
Application.Run;
end.
-------------------------------------
运行后是登录窗口一闪而过,提示错误是:'Cannot make a visible window modal'跪求高手指点迷津.....................
首先运行系统需要弹出登录窗口确认身份,可是我花了好几天时间看了好多例子,结果是---别人的系统用到我
的系统就不行了!
我详细说下我的登录窗口:
放了两个Labe,一个写用户名一个写密码;一个ComboBox,Edit分别是登录时要输入的用户名和密码,两个BitBtn一个确定一个取消.
我的数据库是ACESS的,ADOConnection1,ADOQuery1,ADOTable1,DateSouce1各一个,我确定数据库连接完好.
ACESS里面 denglu表
username password
zxz 123
一个主窗体,还有其他功能窗体.
---------------------------------------------------------------
代码写这样:
确定按钮代码:
procedure TyhdlForm.BitBtn1Click(Sender: TObject);
var
username:string;
password:Boolean;
i:integer;
a,b:string;
begin
try
with adoquery1 do
begin
close;
sql.clear;
sql.add('select * from denglu where username and password');
parameters.ParamByName('username').Value:=trim(Edit1.Text);
parameters.ParamByName('password').Value:=trim(Edit2.Text);
if Edit1.Text ='' then
begin
application.MessageBox('请输入用户名','提示信息',64);
Edit1.SetFocus;
exit;
end;
if edit2.Text ='' then
begin
application.MessageBox('请输入密码','提示信息',64);
edit1.SetFocus;
exit;
end; end;
if adoquery1.RecordCount<>0 then
begin
Edit1.Text:='username';
Edit2.Text:='password';
application.MessageBox('登陆成功','提示信息',64);
mainForm.Show;
yhdlForm.Hide;
end
else
application.MessageBox('输入的用户名或密码错误','提示信息',64);
except
application.MessageBox('登陆失败','提示信息',64);
end;
end;end.
取消按钮代码:
procedure TyhdlForm.BitBtn2Click(Sender: TObject);
begin
close;
end;
---------------------------------------------------------------
我看很多书上都在工程文件上写上调用,可是不管我怎么弄登录窗口就是没弹出来,我想问你们到底该怎么写调用才是对的呢?
{$R *.res}
var
yhdlForm:TyhdlForm;begin
Application.Initialize;
Application.CreateForm(TmainForm, mainForm);
Application.CreateForm(TyhdlForm, yhdlForm);
yhdlForm:=TyhdlForm.Create(nil);
Try
yhdlForm.ShowModal; //显示登录窗口 , 这句系统提示出错
Finally
yhdlForm.Free;
end;
Application.Run;
end.
-------------------------------------
运行后是登录窗口一闪而过,提示错误是:'Cannot make a visible window modal'跪求高手指点迷津.....................
然后在yhdlForm关闭的时候在叫主Form.Show
……,
Controls;var
yhdlForm:TyhdlForm;begin
Application.Initialize;
Application.CreateForm(TmainForm, mainForm);
Application.CreateForm(TyhdlForm, yhdlForm); //在工程文件里把这句给注释掉
yhdlForm:=TyhdlForm.Create(nil);
Try
if (yhdlForm.ShowModal = mrOK) and (判断登录成功) then
Application.Run;
Finally
yhdlForm.Free;
end;
end.
var
loginSql:string;
tempPwd:string; //密码临时变量
tempLevel:string; //用户权限临时变量
begin loginSql:='select * from user_table where user_name =' +''''+trim(edtuser.Text )+''' ';
with dm.jomDm1.ADOQuery1 do
begin
close;
sql.Clear;
sql.Add(loginSql);
open;
end;
{如果存在该用户,则保存其密码变量,
并且与密码框比较,看其密码输入是否相符;
否则提示用户不存在信息}
if dm.ADOQuery1.FieldValues['user_name'] <> null then
begin
tempPwd:=dm.ADOQuery1.FieldValues['passward'];
if edtpassword.Text = tempPwd then //密码存在
begin
{权限控制}
tempLevel:=dm.ADOQuery1.FieldValues['level'];
if tempLevel = '0' then tempLevel :='管理员'
else if tempLevel = '1' then tempLevel :='采购'
else if tempLevel = '2' then tempLevel :='仓库'
else if tempLevel ='3' then tempLevel :='财务';
if cmbdepartment.Text = tempLevel then //验证用户权限
begin //****** 071113 ******//
if tempLevel = '采购' then //对应的用户是采购
begin
{以下三行代码是方便今后要做用户修改时用,
以下相同}
level_tmp := '1';
user_tmp:=edtuser.Text ;
pwd_tmp:=edtpassword.Text ;
mainFrm1.Show;
caigou;
end //对应的用户是采购 ... end
else if tempLevel = '仓库' then //仓库
begin
level_tmp := '2';
user_tmp:=edtuser.Text ;
pwd_tmp:=edtpassword.Text ;
mainfrm1.Show;
cangku;
end
else if tempLevel = '财务' then //财务
begin
level_tmp := '3';
user_tmp :=edtuser.Text ;
pwd_tmp :=edtpassword.Text ;
mainfrm1.Show;
caiwu;
end
else if tempLevel = '管理员' then //管理员
begin
level_tmp :='0';
user_tmp :=edtuser.Text ;
pwd_tmp :=edtpassword.Text ;
mainfrm1.Show;
manager;
end
else
begin
messagebox(handle,'对不起你登录无效!','信息提示',mb_ok);
dm.ADOQuery1.Close;
loginFrm1.Close;
end;
end//****** 071113 ******//
else
begin // *** *** //
messagebox(handle,'对不起你无权登录操作系统!','信息提示',mb_ok);
edtuser.SetFocus;
edtuser.SelectAll;
exit;
end; // *** *** // end //密码存在... end
else //密码错误
begin
messagebox(handle,'你输入的密码错误!','信息提示',mb_ok);
edtpassword.SetFocus;
edtpassword.SelectAll;
end; end
else
begin
messagebox(handle,'你录入的用户名称不存在!','信息提示',mb_ok);
edtpassword.Text :='';
cmbdepartment.Text :='';
edtuser.SetFocus;
edtuser.SelectAll;
end;
end;