📄 unitlogin.~pas
字号:
unit Unitlogin;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
Tlogin = class(TForm)
StaticText1: TStaticText;
StaticText2: TStaticText;
StaticText3: TStaticText;
StaticText4: TStaticText;
DataBase: TEdit;
User_Name: TEdit;
Password: TEdit;
StaticText5: TStaticText;
DatabaseType: TComboBox;
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure PasswordKeyPress(Sender: TObject; var Key: Char);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
login: Tlogin;
count: Integer; {设置全程整型变量作为计数器使用}
implementation
uses Unitmain, DataModule;
{$R *.dfm}
procedure Tlogin.Button2Click(Sender: TObject);
begin
Unitmain.main.Close;
end;
procedure Tlogin.Button1Click(Sender: TObject);
begin
count:=count+1;{计数加1}
if (Database.Text = '') then
begin
if (count=3) then
begin
MessageDlg('对不起,三次登陆错误!请退出。', mtInformation,[mbOk], 0);
Unitmain.main.Close;{三次输入错误,退出}
end
else
begin
showmessage('数据库名不能为空');
Database.SetFocus;
end;
end
else if (User_name.Text = '') then
begin
if (count=3) then
begin
MessageDlg('对不起,三次登陆错误!请退出。', mtInformation,[mbOk], 0);
Unitmain.main.Close;{三次输入错误,退出}
end
else
begin
showmessage('用户名不能为空');
User_name.SetFocus;
end;
end
else if (Password.Text = '') then
begin
if (count=3) then
begin
MessageDlg('对不起,三次登陆错误!请退出。', mtInformation,[mbOk], 0);
Unitmain.main.Close;{三次输入错误,退出}
end
else
begin
showmessage('密码不能为空');
Password.SetFocus;
end;
end
else
begin
if ((DataBaseType.Text <> 'Oracle') and (DataBaseType.Text <> 'DB2')) then
begin
if (count=3) then
begin
MessageDlg('对不起,三次登陆错误!请退出。', mtInformation,[mbOk], 0);
Unitmain.main.Close;{三次输入错误,退出}
end
else
begin
showmessage('请在下拉框中选择合适的数据库类型!');
DataBaseType.SetFocus;
end;
end
else
begin
try
// unitmain.main.SQLConnection1.ConnectionName := ConnectionName;
// unitmain.main.SQLConnection1.DriverName := DriverName;
// unitmain.main.SQLConnection1.GetDriverFunc := GetDriverFunc;
// unitmain.main.SQLConnection1.LibraryName := LibraryName;
// unitmain.main.SQLConnection1.VendorLib := VendorLib;
DataModule.DataModule1.SQLConnection1.Params.Values['DataBase'] := DataBase.Text;
DataModule.DataModule1.SQLConnection1.Params.Values['User_Name'] := User_Name.Text;
DataModule.DataModule1.SQLConnection1.Params.Values['Password'] := Password.Text;
DataModule.DataModule1.SQLConnection1.LoginPrompt := false;
DataModule.DataModule1.SQLConnection1.Connected := true;
showmessage('用户名和密码验证通过,请登陆!');
unitmain.main.Show;
login.Close;
except
on e:Exception do
begin
if (count=3) then
begin
Unitmain.main.Close;{三次输入错误,退出}
MessageDlg('对不起,三次登陆错误!请退出。', mtInformation,[mbOk], 0);
end
else
begin
showmessage('登陆信息不正确!请重新登陆。');
login.DataBase.Focused;
end;
end;
end;
end;
end;
end;
procedure Tlogin.PasswordKeyPress(Sender: TObject; var Key: Char);
begin
if (key=#13) then //当在Edit2中输入密码后,按回车键,执行密码检查
Button1.Click;
end;
procedure Tlogin.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DataBase.Text := '';
User_Name.Text := '';
PassWord.Text := '';
DataBaseType.Text := 'Oracle';
end;
procedure Tlogin.FormActivate(Sender: TObject);
begin
DataBaseType.Items.Clear;
DataBase.SetFocus;
DatabaseType.Items.Add('Oracle');
DatabaseType.Items.Add('DB2');
count := 0;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -