📄 login.pas
字号:
unit login;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, ExtCtrls, Buttons;
type
Tlog = class(TForm)
Label2: TLabel;
Label3: TLabel;
Edit2: TEdit;
Edit3: TEdit;
ADOQuery1: TADOQuery;
RadioGroup1: TRadioGroup;
Label1: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Image1: TImage;
Image2: TImage;
ADOCommand1: TADOCommand;
ADOConnection1: TADOConnection;
// procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var key: Char);
// procedure Button2Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
log: Tlog;
implementation
uses browse,browse_users,{ browse_AdAdmin,browse_GenAdmin,} account_information;
{$R *.dfm}
procedure Tlog.FormShow(Sender: TObject);
begin
Edit2.Clear;
Edit3.Clear;
RadioGroup1.ItemIndex:=-1;
end;
procedure Tlog.FormCreate(Sender: TObject);
var
Connect:TADOConnection;
//DLYH_Q:TADOQuery;
ADOCommand:TADOCommand;
s,DataPath : string;
begin
Connect:=TADOConnection.Create(nil);
Connect.ConnectionString:='Provider=SQLOLEDB;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=library';
Connect.LoginPrompt:=false;
try
Connect.Connected:=true
except
ADOCommand:=TADOCommand.Create(nil);
ADOCommand.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False';
DataPath:=ExtractFilePath(Application.ExeName) ;
s:='EXEC sp_attach_db @dbname = N'+char(39)+'library'+char(39)+','+
'@filename1 = N'+char(39)+DataPath+'library_Data.MDF'+char(39)+
','+'@filename2 = N'+char(39)+DataPath+'library_Log.LDF'+char(39);
ADOCommand.CommandText := s;
ADOCommand.Execute();
end;
Edit2.Clear;
Edit3.Clear;
RadioGroup1.ItemIndex:=-1;
end;
procedure Tlog.Edit2KeyPress(Sender: TObject;var key:char);
begin
if key=#13 then
BitBtn1.Click;
end;
procedure Tlog.BitBtn1Click(Sender: TObject);
var
user,pass,temp:string;
begin
user:=edit2.text;
pass:=edit3.text;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='select UserID from login_User where UserID='''+user+''' and Password='''+pass+'''';
ADOQuery1.Open;
temp:=ADOQuery1.FieldByName('UserID').AsString;
if (temp<>'') and (RadioGroup1.ItemIndex<>-1) then
begin
if RadioGroup1.ItemIndex=2 then
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='select UserID from login_User where UserID='''+user+''' and User_right=1';
ADOQuery1.Open;
if adoquery1.FieldByName('UserID').AsString<>'' then
begin
account_inf.Visible:=true;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Text:='select Name from AdAdmin where AdAdminID='''+user+'''';
adoquery1.Open;
account_inf.Edit1.text:=user;
account_inf.Edit2.text:=adoquery1.fieldbyname('Name').AsString;
account_inf.Edit3.Text:='高级管理员';
account_inf.Edit4.Text:='';
log.Hide;
end
else
begin
ShowMessage('请选择正确的用户类型');
end;
end;
if RadioGroup1.ItemIndex=1 then
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='select UserID from login_User where UserID='''+user+''' and User_right=2';
ADOQuery1.Open;
if ADOQuery1.FieldByName('UserID').AsString<>'' then
begin
account_inf.Visible:=true;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Text:='select Name from GenAdmin where GenAdminID='''+user+'''';
adoquery1.Open;
account_inf.Edit1.Text:=user;
account_inf.Edit2.Text:=trim(adoquery1.fieldbyname('Name').asstring);
account_inf.Edit3.Text:='普通管理员';
account_inf.Edit4.Text:='';
log.Hide;
end
else
begin
ShowMessage('请选择正确的用户类型');
end;
end;
if RadioGroup1.ItemIndex=0 then
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='select UserID from login_User where UserID='''+user+''' and User_right=3';
ADOQuery1.Open;
if ADOQuery1.FieldByName('UserID').AsString<>'' then
begin
adoquery1.Close;
adoquery1.SQL.Clear ;
adoquery1.SQL.Text:='select Symbol from [User] where StuID='''+user+'''';
adoquery1.Open;
if ADOQuery1.FieldByName('Symbol').asinteger=0 then
begin
showMessage('此证已挂失!');
account_inf.Visible:=true;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Text:='select Name from [User] where StuID='''+user+'''';
adoquery1.Open;
account_inf.Edit1.Text:=user;
account_inf.Edit2.Text:=adoquery1.fieldbyname('Name').asstring;
account_inf.Edit3.Text:='用户';
adoquery1.SQL.Clear ;
adoquery1.SQL.Text:='select StuGroup from [User] where StuID='''+user+'''';
adoquery1.Open;
account_inf.Edit4.Text:=adoquery1.fieldbyname('StuGroup').asstring;
log.Hide;
end
else
begin
account_inf.Visible:=true;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Text:='select Name from [User] where StuID='''+user+'''';
adoquery1.Open;
account_inf.Edit1.Text:=user;
account_inf.Edit2.Text:=adoquery1.fieldbyname('Name').asstring;
account_inf.Edit3.Text:='用户';
adoquery1.SQL.Clear ;
adoquery1.SQL.Text:='select StuGroup from [User] where StuID='''+user+'''';
adoquery1.Open;
account_inf.Edit4.Text:=adoquery1.fieldbyname('StuGroup').asstring;
log.Hide;
end
end
else
begin
ShowMessage('请选择正确的用户类型');
end;
end;
end
else
begin
if RadioGroup1.ItemIndex=-1 then
begin
showmessage('请选择用户类型');
end
else
begin
ShowMessage('用户名或密码错误,请检查正确后重新登陆');
end;
end;
end;
procedure Tlog.BitBtn2Click(Sender: TObject);
begin
ShowMessage('您是否确定要关闭吗?');
Close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -