📄 uadbconnsetting.pas
字号:
{******************************************************************************************}
{ }
{ Universal Agent on demond SDK }
{ }
{ }
{ COPYRIGHT }
{ ========= }
{ The UA SDK (software) is Copyright (C) 2001-2003, by vinson zeng(曾胡龙). }
{ All rights reserved. }
{ The authors - vinson zeng (曾胡龙), }
{ exclusively own all copyrights to the Advanced Application }
{ Controls (AppControls) and all other products distributed by Utilmind Solutions(R). }
{ }
{ LIABILITY DISCLAIMER }
{ ==================== }
{ THIS SOFTWARE IS DISTRIBUTED "AS IS" AND WITHOUT WARRANTIES AS TO PERFORMANCE }
{ OF MERCHANTABILITY OR ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
{ YOU USE IT AT YOUR OWN RISK. THE AUTHOR WILL NOT BE LIABLE FOR DATA LOSS, }
{ DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS SOFTWARE.}
{ }
{ RESTRICTIONS }
{ ============ }
{ You may not attempt to reverse compile, modify, }
{ translate or disassemble the software in whole or in part. }
{ You may not remove or modify any copyright notice or the method by which }
{ it may be invoked. }
{******************************************************************************************}
unit uaDbConnSetting;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls, DB, ADODB,IniFiles;
type
TDbConnSettingForm = class(TForm)
Label1: TLabel;
edt_server: TEdit;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
edt_Db: TEdit;
edt_User: TEdit;
edt_Password: TEdit;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
adoConn_: TADOConnection;
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
FPassedDbConn:Boolean;
procedure Init;
end;
var
DbConnSettingForm: TDbConnSettingForm;
implementation
{$R *.dfm}
procedure TDbConnSettingForm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
If (Key=VK_DOWN) or (Key=VK_RETURN) then Begin
Key:=0;
GetParentForm(Self).Perform(wm_NextDlgCtl, 0, 0);
end Else if Key=VK_UP then Begin
Key:=0;
GetParentForm(Self).Perform(wm_NextDlgCtl, 1, 0);
End;
end;
procedure TDbConnSettingForm.Init;
begin
end;
procedure TDbConnSettingForm.SpeedButton3Click(Sender: TObject);
begin
ModalResult := mrCancel;
end;
procedure TDbConnSettingForm.SpeedButton2Click(Sender: TObject);
var
sServer:string;
sDb:string;
sUser:string;
sPassword:string;
DbConn_Ini: TIniFile;
begin
sServer := trim(edt_Server.Text);
sDb := trim(edt_Db.Text);
sUser := trim(edt_User.Text);
sPassword := trim(edt_Password.Text);
try
DbConn_Ini := TIniFile.Create(ExtractFilePath(Paramstr(0))+'\DbConn.ini');
DbConn_Ini.WriteString('Db_PARAMS', 'SERVER NAME', sServer);
DbConn_Ini.WriteString('Db_PARAMS', 'DATABASE NAME', sDB);
DbConn_Ini.WriteString('Db_PARAMS', 'User NAME', sUser);
DbConn_Ini.WriteString('Db_PARAMS', 'PASSWORD', sPassWord);
except
on E:Exception do
begin
end;
end;
ModalResult := mrOk;
end;
procedure TDbConnSettingForm.SpeedButton1Click(Sender: TObject);
var
sServer:string;
sDb:string;
sUser:string;
sPassword:string;
sConn:string;
begin
if trim(edt_server.Text) = '' then
begin
MessageDlg('数据库服务器名称不能为空!', mtInformation,[mbOk], 0);
Exit;
end;
if trim(edt_Db.Text) = '' then
begin
MessageDlg('数据库名称不能为空!', mtInformation,[mbOk], 0);
Exit;
end;
if trim(edt_User.Text) = '' then
begin
MessageDlg('用户名称不能为空!', mtInformation,[mbOk], 0);
Exit;
end;
sServer := trim(edt_Server.Text);
sDb := trim(edt_Db.Text);
sUser := trim(edt_User.Text);
sPassword := trim(edt_Password.Text);
sConn := 'Provider=SQLOLEDB.1;Persist Security Info=True;Password='''+sPassWord+''''+';User ID='+sUser+';Initial Catalog='+sDB+'; Data Source='+sServer;
try
try
adoConn_.ConnectionString := sConn;
if not adoConn_.Connected then
adoConn_.Connected := true;
FPassedDbConn := true;
except
on E:Exception do
begin
FPassedDbConn := false;
Showmessage('进行数据库连接测试失败!'+#13+'Information:'+E.Message);
end;
end;
finally
if FPassedDbConn then
Showmessage('进行数据库连接测试成功,请确认退出!');
if adoConn_.Connected then
adoConn_.Connected := false;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -