📄 unit2.pas
字号:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Unit1, ExtCtrls, DB, ADODB, Registry;
type
Tlogin = class(TForm)
Panel1: TPanel;
Button1: TButton;
Button3: TButton;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
odbc: TComboBox;
User_name: TEdit;
Password: TEdit;
Edit3: TEdit;
ADOConnection1: TADOConnection;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure odbcDropDown(Sender: TObject);
procedure PasswordKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
login: Tlogin;
count: Integer; {设置全程整型变量作为计数器使用}
implementation
{$R *.dfm}
procedure Tlogin.Button1Click(Sender: TObject);
var
OdbcStr: String;
UNStr: String;
PWStr: String;
CnntStr: String;
begin
count := count + 1;
if (odbc.Text = '') then
begin
if (count = 3) then
begin
MessageDlg('对不起,三次登陆错误!请退出。', mtInformation,[mbOk], 0);
Unit1.main.Close;{三次输入错误,退出}
end
else
begin
showmessage('请在下拉框中选择ODBC数据源!');
odbc.SetFocus;
end;
end
else if (User_name.Text = '') then
begin
if (count = 3) then
begin
MessageDlg('对不起,三次登陆错误!请退出。', mtInformation,[mbOk], 0);
Unit1.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);
Unit1.main.Close;{三次输入错误,退出}
end
else
begin
showmessage('密码不能为空');
Password.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;
OdbcStr := odbc.Text;
UNStr := User_Name.Text;
PWStr := Password.Text;
CnntStr := 'Provider=MSDASQL.1;Password='+PWStr+';Persist Security Info=True;User ID='+UNStr+';Data Source='+OdbcStr+';Extended Properties="DSN='+OdbcStr+';UID='+UNStr+';PWD='+PWStr+'; "';
ADOConnection1.ConnectionString := CnntStr;
ADOConnection1.Connected := true;
showmessage('用户名和密码验证通过,请登陆!');
Unit1.firstLogin := false;
unit1.main.Show;
login.Close;
except
on e:Exception do
begin
if (count=3) then
begin
MessageDlg('对不起,三次登陆错误!请退出。', mtInformation,[mbOk], 0);
Unit1.main.Close;{三次输入错误,退出}
end
else
begin
showmessage('登陆信息不正确!请重新登陆。');
login.odbc.Focused;
end;
end;
end;
end;
end;
procedure Tlogin.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if Unit1.firstLogin then
begin
Unit1.main.Close;
end;
end;
procedure Tlogin.Button2Click(Sender: TObject);
begin
Unit1.main.Close;
end;
procedure Tlogin.Button3Click(Sender: TObject);
begin
odbc.Text := '';
User_name.Text := '';
Password.Text := '';
end;
procedure Tlogin.odbcDropDown(Sender: TObject);
var
Reg: TRegistry;
Val:TStrings;
I:Integer;
begin
odbc.Clear;
Reg:=TRegistry.Create;
try
Val:=TStringList.Create;
try
Reg.RootKey:=HKEY_LOCAL_MACHINE;
if not Reg.OpenKey('Software\ODBC\ODBC.INI\',False) then
ShowMessage('打开ODBC键错误!')
else
begin
Reg.GetKeyNames(Val);
for i:=0 to Val.Count-1 do
odbc.Items.Append(Val[i])
end;
finally
Val.Free;
end;
finally
Reg.Free;
end;
end;
procedure Tlogin.PasswordKeyPress(Sender: TObject; var Key: Char);
begin
if (key=#13) then //当在Edit2中输入密码后,按回车键,执行密码检查
Button1.Click;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -