W
wangpop
Unregistered / Unconfirmed
GUEST, unregistred user!
login 代码:
unit login;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;
type
TLoginFm = class(TForm)
GroupBox1: TGroupBox;
EdName: TEdit;
EdPassword: TEdit;
ButOk: TButton;
ButCannel: TButton;
Label1: TLabel;
Label2: TLabel;
procedure EdNameKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure EdPasswordKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure ButCannelClick(Sender: TObject);
procedure ButOkClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
LoginFm: TLoginFm;
var
Maxtimes,Logintimes : integer ;
implementation
uses Dmdata, Poffice;
{$R *.dfm}
procedure TLoginFm.ButOkClick(Sender: TObject);
var Aname,Apass,Sqlstr:string;
begin
if (length(trim(EdName.text))>0) or (length(trim(EdPassword.text))>0) then
begin
Aname := trim(Edname.Text);
Apass := trim(Edpassword.Text);
Sqlstr := 'select * from loguser where (管理员='''+Aname+''') and (密码='''+Apass+''')';
with TADOQuery.Create(nil)do
begin
try
Close;
Connection:=Datamod.ADOConn;
Sql.Clear;
sql.Add(sqlstr);
open;
if recordcount > 0 then
begin
frmain.show; //显示主程序
end
else
begin
showmessage('密码是否正确');
EdPassword.SetFocus;
EdPassword.SelectAll;
end;
finally
Free;
end;
end;
end
else
begin
showmessage('请确定名称和密码是否正确');
Edname.SelectAll;
end;
end;
end.
===========================
工程
program office;
uses
Forms,
Dialogs,
Poffice in 'Poffice.pas' {FrMain},
Dmdata in 'Dmdata.pas' {DataMod: TDataModule},
login in 'login.pas' {LoginFm};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TFrMain, FrMain);
Application.CreateForm(TDataMod, DataMod);
if not DataMod.ADOConn.Connected then
begin
ShowMessage('连接后台数据库失败,请检查配置是否完好,数据库是否存在');
halt;
end;
Application.CreateForm(TLoginFm, LoginFm);
LOGINfm.ShowModal;
LOGINfm.close;
Application.Run;
end.
想在运行时先执行 Fmlogin 登录界面, 当密码正确的时,则运行主程序 frmain,并且这个登录关闭,但上面的代码一运行,主程序能运行,但登录窗口还是存在,并且,关掉登录窗口后,主程序也被关掉了,希望高手指点,谢谢!
unit login;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;
type
TLoginFm = class(TForm)
GroupBox1: TGroupBox;
EdName: TEdit;
EdPassword: TEdit;
ButOk: TButton;
ButCannel: TButton;
Label1: TLabel;
Label2: TLabel;
procedure EdNameKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure EdPasswordKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure ButCannelClick(Sender: TObject);
procedure ButOkClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
LoginFm: TLoginFm;
var
Maxtimes,Logintimes : integer ;
implementation
uses Dmdata, Poffice;
{$R *.dfm}
procedure TLoginFm.ButOkClick(Sender: TObject);
var Aname,Apass,Sqlstr:string;
begin
if (length(trim(EdName.text))>0) or (length(trim(EdPassword.text))>0) then
begin
Aname := trim(Edname.Text);
Apass := trim(Edpassword.Text);
Sqlstr := 'select * from loguser where (管理员='''+Aname+''') and (密码='''+Apass+''')';
with TADOQuery.Create(nil)do
begin
try
Close;
Connection:=Datamod.ADOConn;
Sql.Clear;
sql.Add(sqlstr);
open;
if recordcount > 0 then
begin
frmain.show; //显示主程序
end
else
begin
showmessage('密码是否正确');
EdPassword.SetFocus;
EdPassword.SelectAll;
end;
finally
Free;
end;
end;
end
else
begin
showmessage('请确定名称和密码是否正确');
Edname.SelectAll;
end;
end;
end.
===========================
工程
program office;
uses
Forms,
Dialogs,
Poffice in 'Poffice.pas' {FrMain},
Dmdata in 'Dmdata.pas' {DataMod: TDataModule},
login in 'login.pas' {LoginFm};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TFrMain, FrMain);
Application.CreateForm(TDataMod, DataMod);
if not DataMod.ADOConn.Connected then
begin
ShowMessage('连接后台数据库失败,请检查配置是否完好,数据库是否存在');
halt;
end;
Application.CreateForm(TLoginFm, LoginFm);
LOGINfm.ShowModal;
LOGINfm.close;
Application.Run;
end.
想在运行时先执行 Fmlogin 登录界面, 当密码正确的时,则运行主程序 frmain,并且这个登录关闭,但上面的代码一运行,主程序能运行,但登录窗口还是存在,并且,关掉登录窗口后,主程序也被关掉了,希望高手指点,谢谢!