uData单元代码如下:
unit uData;
interface
uses
SysUtils, Classes, DB, ADODB;
type
TdmPer = class(TDataModule)
acPer: TADOConnection;
private
{ Private declarations }
public
{ Public declarations }
end;
var
dmPer: TdmPer;
implementation
{$R *.dfm}
end.
uLogin单元代码如下:
unit uLogin;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB,uData;
type
TfrmLogin = class(TForm)
Label1: TLabel;
Label2: TLabel;
cmbUserName: TComboBox;
Label3: TLabel;
edtpassword: TEdit;
btnOK: TButton;
Button2: TButton;
procedure btnOKClick(Sender: TObject);
procedure edtpasswordKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmLogin: TfrmLogin;
implementation
{$R *.dfm}
procedure TfrmLogin.btnOKClick(Sender: TObject);
var
Query:TADOQuery;
begin
try
Query.Create(nil);
Query.Connection:=dmPer.acPer;
Query.SQL.Add('select * from Operator where UserName=:UserName and UserPwd=:UserPwd');
Query.Parameters.ParamByName('UserName').Value:=cmbUserName.Text;
Query.Parameters.ParamByName('UserPwd').Value:=edtpassword.Text;
Query.Open;
if(Query.RecordCount=0)then
begin
MessageDlg('请输入正确的用户名和密码',mtError,[mbOK],0);
Exit;
end;
if(Query.FieldByName('Class').AsInteger=0)then
begin
end;
if(Query.FieldByName('Class').AsInteger=1)then
begin
end;
edtpassword.Text:='';
Query.Close;
Query.Free;
except
MessageDlg('连接数据库出错',mtError,[mbOk],0);
end;
end;
procedure TfrmLogin.edtpasswordKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if(key=13)then
btnOKClick(Sender);
end;
procedure TfrmLogin.FormShow(Sender: TObject);
begin
edtpassword.SetFocus;
end;
procedure TfrmLogin.FormCreate(Sender: TObject);
Var
Query:TADOQuery;
begin
try
cmbUserName.Clear;
Query:=TADOQuery.Create(nil);
Query.Connection:=dmPer.acPer;
Query.SQL.Add('select UserName from Operator');
Query.Open;
if(Query.RecordCount=0)then
begin
MessageDlg('没有可以登录的用户名',mtError,[mbOk],0);
Exit;
end
else
Query.First;
while(Query.Eof=false)do
begin
cmbUserName.Items.Add(Query.FieldByName('UserName').AsString);
Query.Next;
end;
except
MessageDlg('连接数据库出错',mtError,[mbOk],0);
end;
end;
end.