只
只你
Unregistered / Unconfirmed
GUEST, unregistred user!
unit ULogin;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, DB,DBTables,ADODB;
type
TFrmLogin = class(TForm)
Label1: TLabel;
Label2: TLabel;
UserName: TComboBox;
UserPwd: TEdit;
BtnDm: TBitBtn;
BrmCancel: TBitBtn;
procedure BtnDmClick(Sender: TObject);
procedure BrmCancelClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure UserPwdKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FrmLogin: TFrmLogin;
implementation
uses UDM,UMain,UIn,uOut,UKcManager;
{$R *.dfm}
procedure TFrmLogin.BtnDmClick(Sender: TObject);
var
Query : TADOQuery;
begin
try
Query := TADOQuery.Create(nil);
Query.Connection := Dm.ADOConnection1;
Query.SQL.Add('select * from Operator where UserName =:UserName and UserPwd =: UserPwd');
Query.Parameters.ParamByName('UserName').Value:=UserName.Text;
Query.Parameters.ParamByName('UserPwd').Value:=UserPwd.Text;
Query.Open;
if Query.RecordCount = 0 then
MessageDlg('请输入正确的用户和密码!!!',mtERROR,[mbok],0);
exit;
if Query.FieldByName('Class').AsInteger = 0 then
begin
UserPwd.Text :='';
Query.Close;
Query.Free;
FrmMain.Show;
FrmLogin.Close;
end;
if Query.FieldByName('Class').AsInteger = 1 then
begin
UserPwd.Text :='';
Query.Close;
Query.Free;
Ypin.Show ;
FrmLogin.Close;
end;
if Query.FieldByName('Class').AsInteger = 2 then
begin
UserPwd.Text :='';
Query.Close;
Query.Free;
KcManager.Show;
FrmLogin.Close;
end;
if Query.FieldByName('Class').AsInteger = 3 then
begin
UserPwd.Text :='';
Query.Close;
Query.Free;
YpOut.Show;
FrmLogin.Close;
end;
except
MessageDlg('数据库连接出错!!!',mtERROR,[mbOK],0);
end;
end;
procedure TFrmLogin.BrmCancelClick(Sender: TObject);
begin
modalResult := mrCancel;
FrmLogin.Close;
Application.Terminate;
end;
procedure TFrmLogin.FormShow(Sender: TObject);
begin
UserPwd.SetFocus;
end;
procedure TFrmLogin.FormCreate(Sender: TObject);
var
Query : TADOQuery;
begin
UserName.Clear;
try
Query := TADOQuery.Create(nil);
Query.Connection := Dm.ADOConnection1;
Query.SQL.Add('select username from operator');
Query.Open;
if Query.RecordCount = 0 then
begin
MessageDlg('没有可连接的用户!!!',mtERROR,[mbOk],0);
exit;
end
else
begin
Query.First;
while Query.Eof = False do
begin
UserName.Items.Add(Query.FieldByName('UserName').asstring);
Query.Next;
end;
end;
Query.Close;
query.Free;
UserName.ItemIndex := 0;
except
MessageDlg('链接数据库出错!!!',mtERROR,[mbOK],0);
end;
end;
procedure TFrmLogin.UserPwdKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = 13 then
BtnDmClick(Sender);
end;
end.
但是运行的时候老是会跳出这个错误,再按运行后也不行,那位高手帮我看看
project yiyao.exe raised exception class EAccessViolaton with message'
Access violation at address 004ef2eb in module 'yiyao.exe'.Read of address 00000058' process stopped.use
Step or Run to continue
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, DB,DBTables,ADODB;
type
TFrmLogin = class(TForm)
Label1: TLabel;
Label2: TLabel;
UserName: TComboBox;
UserPwd: TEdit;
BtnDm: TBitBtn;
BrmCancel: TBitBtn;
procedure BtnDmClick(Sender: TObject);
procedure BrmCancelClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure UserPwdKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FrmLogin: TFrmLogin;
implementation
uses UDM,UMain,UIn,uOut,UKcManager;
{$R *.dfm}
procedure TFrmLogin.BtnDmClick(Sender: TObject);
var
Query : TADOQuery;
begin
try
Query := TADOQuery.Create(nil);
Query.Connection := Dm.ADOConnection1;
Query.SQL.Add('select * from Operator where UserName =:UserName and UserPwd =: UserPwd');
Query.Parameters.ParamByName('UserName').Value:=UserName.Text;
Query.Parameters.ParamByName('UserPwd').Value:=UserPwd.Text;
Query.Open;
if Query.RecordCount = 0 then
MessageDlg('请输入正确的用户和密码!!!',mtERROR,[mbok],0);
exit;
if Query.FieldByName('Class').AsInteger = 0 then
begin
UserPwd.Text :='';
Query.Close;
Query.Free;
FrmMain.Show;
FrmLogin.Close;
end;
if Query.FieldByName('Class').AsInteger = 1 then
begin
UserPwd.Text :='';
Query.Close;
Query.Free;
Ypin.Show ;
FrmLogin.Close;
end;
if Query.FieldByName('Class').AsInteger = 2 then
begin
UserPwd.Text :='';
Query.Close;
Query.Free;
KcManager.Show;
FrmLogin.Close;
end;
if Query.FieldByName('Class').AsInteger = 3 then
begin
UserPwd.Text :='';
Query.Close;
Query.Free;
YpOut.Show;
FrmLogin.Close;
end;
except
MessageDlg('数据库连接出错!!!',mtERROR,[mbOK],0);
end;
end;
procedure TFrmLogin.BrmCancelClick(Sender: TObject);
begin
modalResult := mrCancel;
FrmLogin.Close;
Application.Terminate;
end;
procedure TFrmLogin.FormShow(Sender: TObject);
begin
UserPwd.SetFocus;
end;
procedure TFrmLogin.FormCreate(Sender: TObject);
var
Query : TADOQuery;
begin
UserName.Clear;
try
Query := TADOQuery.Create(nil);
Query.Connection := Dm.ADOConnection1;
Query.SQL.Add('select username from operator');
Query.Open;
if Query.RecordCount = 0 then
begin
MessageDlg('没有可连接的用户!!!',mtERROR,[mbOk],0);
exit;
end
else
begin
Query.First;
while Query.Eof = False do
begin
UserName.Items.Add(Query.FieldByName('UserName').asstring);
Query.Next;
end;
end;
Query.Close;
query.Free;
UserName.ItemIndex := 0;
except
MessageDlg('链接数据库出错!!!',mtERROR,[mbOK],0);
end;
end;
procedure TFrmLogin.UserPwdKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = 13 then
BtnDmClick(Sender);
end;
end.
但是运行的时候老是会跳出这个错误,再按运行后也不行,那位高手帮我看看
project yiyao.exe raised exception class EAccessViolaton with message'
Access violation at address 004ef2eb in module 'yiyao.exe'.Read of address 00000058' process stopped.use
Step or Run to continue