📄 sourcedm.pas
字号:
unit SourceDM;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, IniFiles;
type
TDM_Source = class(TDataModule)
DBTd: TDatabase;
DBTx: TDatabase;
DBLs: TDatabase;
DBDh: TDatabase;
Qr_TdTemp: TQuery;
Qr_TxTemp: TQuery;
Qr_LsTemp: TQuery;
Qr_DhTemp: TQuery;
procedure DataModuleCreate(Sender: TObject);
private
{ Private declarations }
function Td_GetDBAliasName :string;
function Td_GetDBName :string; //取得系统内部别名
function Td_GetDBDataBaseName :string;
function Td_GetDBServerName :string;
function Td_GetDBUserName :string;
function Td_GetDBPassWord :string;
function Tx_GetDBAliasName :string;
function Tx_GetDBName :string; //取得系统内部别名
function Tx_GetDBDataBaseName :string;
function Tx_GetDBServerName :string;
function Tx_GetDBUserName :string;
function Tx_GetDBPassWord :string;
function Ls_GetDBAliasName :string;
function Ls_GetDBName :string; //取得系统内部别名
function Ls_GetDBDataBaseName :string;
function Ls_GetDBServerName :string;
function Ls_GetDBUserName :string;
function Ls_GetDBPassWord :string;
function Dh_GetDBAliasName :string;
function Dh_GetDBName :string; //取得系统内部别名
function Dh_GetDBDataBaseName :string;
function Dh_GetDBServerName :string;
function Dh_GetDBUserName :string;
function Dh_GetDBPassWord :string;
public
{ Public declarations }
Td_ConnectFlag:Boolean;//数据库连接标志
Tx_ConnectFlag:Boolean;
Ls_ConnectFlag:Boolean;
Dh_ConnectFlag:Boolean;
property Td_DBAliasName :string read Td_GetDBAliasName;
property Td_DBName :string read Td_GetDBName; //系统内部别名
property Td_DBDataBaseName :string read Td_GetDBDataBaseName;
property Td_DBServerName :string read Td_GetDBServerName;
property Td_DBUserName :string read Td_GetDBUserName;
property Td_DBPassWord :string read Td_GetDBPassWord;
property Tx_DBAliasName :string read Tx_GetDBAliasName;
property Tx_DBName :string read Tx_GetDBName; //系统内部别名
property Tx_DBDataBaseName :string read Tx_GetDBDataBaseName;
property Tx_DBServerName :string read Tx_GetDBServerName;
property Tx_DBUserName :string read Tx_GetDBUserName;
property Tx_DBPassWord :string read Tx_GetDBPassWord;
property Ls_DBAliasName :string read Ls_GetDBAliasName;
property Ls_DBName :string read Ls_GetDBName; //系统内部别名
property Ls_DBDataBaseName :string read Ls_GetDBDataBaseName;
property Ls_DBServerName :string read Ls_GetDBServerName;
property Ls_DBUserName :string read Ls_GetDBUserName;
property Ls_DBPassWord :string read Ls_GetDBPassWord;
property Dh_DBAliasName :string read Dh_GetDBAliasName;
property Dh_DBName :string read Dh_GetDBName; //系统内部别名
property Dh_DBDataBaseName :string read Dh_GetDBDataBaseName;
property Dh_DBServerName :string read Dh_GetDBServerName;
property Dh_DBUserName :string read Dh_GetDBUserName;
property Dh_DBPassWord :string read Dh_GetDBPassWord;
function ReadIni(const Section, Ident, Default: string): string;
end;
var
DM_Source: TDM_Source;
implementation
uses SourcePH;
{$R *.DFM}
function TDM_Source.ReadIni(const Section, Ident, Default: string): string;
var
tempIni:TIniFile;
STemp:String;
begin
tempIni:=nil;
sTemp:=ExtractFileName(Application.ExeName);
if pos('.',sTemp)>0 then
sTemp:=copy(sTemp,1,pos('.',sTemp))+'ini';
sTemp:=ExtractFilePath(Application.ExeName)+sTemp;
try
tempIni:= TIniFile.Create(sTemp);
result:=tempIni.ReadString(Section,Ident,Default);
finally
tempIni.Free;
end;
end;
function TDM_Source.Td_GetDBAliasName :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Td_Const_AliasName
else
result:=ReadIni('DBOption','Td_AliasName',Td_Const_AliasName);
end;
function TDM_Source.Td_GetDBName :string;
begin
result:=Td_Const_DatabaseName;
end;
function TDM_Source.Td_GetDBDataBaseName :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Td_Const_BDEDataBaseName
else
result:=ReadIni('DBOption','Td_DataBaseName',Td_Const_BDEDataBaseName);
end;
function TDM_Source.Td_GetDBServerName :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Td_Const_ServerName
else
result:=ReadIni('DBOption','Td_ServerName',Td_Const_ServerName);
end;
function TDM_Source.Td_GetDBUserName :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Td_Const_UserName
else
result:=ReadIni('DBOption','Td_UserName',Td_Const_UserName);
end;
function TDM_Source.Td_GetDBPassWord :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Td_Const_PassWord
else
result:=ReadIni('DBOption','Td_PassWord',Td_Const_PassWord);
end;
function TDM_Source.Tx_GetDBAliasName :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Tx_Const_AliasName
else
result:=ReadIni('DBOption','Tx_AliasName',Tx_Const_AliasName);
end;
function TDM_Source.Tx_GetDBName :string;
begin
result:=Tx_Const_DatabaseName;
end;
function TDM_Source.Tx_GetDBDataBaseName :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Tx_Const_BDEDataBaseName
else
result:=ReadIni('DBOption','Tx_DataBaseName',Tx_Const_BDEDataBaseName);
end;
function TDM_Source.Tx_GetDBServerName :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Tx_Const_ServerName
else
result:=ReadIni('DBOption','Tx_ServerName',Tx_Const_ServerName);
end;
function TDM_Source.Tx_GetDBUserName :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Tx_Const_UserName
else
result:=ReadIni('DBOption','Tx_UserName',Tx_Const_UserName);
end;
function TDM_Source.Tx_GetDBPassWord :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Tx_Const_PassWord
else
result:=ReadIni('DBOption','Tx_PassWord',Tx_Const_PassWord);
end;
function TDM_Source.Ls_GetDBAliasName :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Ls_Const_AliasName
else
result:=ReadIni('DBOption','Ls_AliasName',Ls_Const_AliasName);
end;
function TDM_Source.Ls_GetDBName :string;
begin
result:=Ls_Const_DatabaseName;
end;
function TDM_Source.Ls_GetDBDataBaseName :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Ls_Const_BDEDataBaseName
else
result:=ReadIni('DBOption','Ls_DataBaseName',Ls_Const_BDEDataBaseName);
end;
function TDM_Source.Ls_GetDBServerName :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Ls_Const_ServerName
else
result:=ReadIni('DBOption','Ls_ServerName',Ls_Const_ServerName);
end;
function TDM_Source.Ls_GetDBUserName :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Ls_Const_UserName
else
result:=ReadIni('DBOption','Ls_UserName',Ls_Const_UserName);
end;
function TDM_Source.Ls_GetDBPassWord :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Ls_Const_PassWord
else
result:=ReadIni('DBOption','Ls_PassWord',Ls_Const_PassWord);
end;
function TDM_Source.Dh_GetDBAliasName :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Dh_Const_AliasName
else
result:=ReadIni('DBOption','Dh_AliasName',Dh_Const_AliasName);
end;
function TDM_Source.Dh_GetDBName :string;
begin
result:=Dh_Const_DatabaseName;
end;
function TDM_Source.Dh_GetDBDataBaseName :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Dh_Const_BDEDataBaseName
else
result:=ReadIni('DBOption','Dh_DataBaseName',Dh_Const_BDEDataBaseName);
end;
function TDM_Source.Dh_GetDBServerName :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Dh_Const_ServerName
else
result:=ReadIni('DBOption','Dh_ServerName',Dh_Const_ServerName);
end;
function TDM_Source.Dh_GetDBUserName :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Dh_Const_UserName
else
result:=ReadIni('DBOption','Dh_UserName',Dh_Const_UserName);
end;
function TDM_Source.Dh_GetDBPassWord :string;
begin
if ReadIni('system','AutoSetDBOption','true')<>'false' then
result:=Dh_Const_PassWord
else
result:=ReadIni('DBOption','Dh_PassWord',Dh_Const_PassWord);
end;
procedure TDM_Source.DataModuleCreate(Sender: TObject);
begin
{ with DBTd do
begin
AliasName:=Td_DBAliasName;
DatabaseName:=Td_DBName;
Params.Values['DATABASE NAME']:=Td_DBDataBaseName;
Params.Values['SERVER NAME']:=Td_DBServerName;
Params.Values['USER NAME']:=Td_DBUserName;
Params.Values['PASSWORD']:=Td_DBPassWord;
Params.Values['CONNECT TIMEOUT']:='30';
try
Open;
Td_ConnectFlag:=true;
except
Td_ConnectFlag:=false;
ShowMessage('铁东区数据库连接失败!');
end;
end;
//if not DBTd.Connected then exit;
with DBTx do
begin
AliasName:=Tx_DBAliasName;
DatabaseName:=Tx_DBName;
Params.Values['DATABASE NAME']:=Tx_DBDataBaseName;
Params.Values['SERVER NAME']:=Tx_DBServerName;
Params.Values['USER NAME']:=Tx_DBUserName;
Params.Values['PASSWORD']:=Tx_DBPassWord;
Params.Values['CONNECT TIMEOUT']:='30';
try
Open;
Tx_ConnectFlag:=true;
except
Tx_ConnectFlag:=false;
ShowMessage('铁西区数据库连接失败!');
end;
end;
//if not DBTx.Connected then exit;
with DBLs do
begin
AliasName:=Ls_DBAliasName;
DatabaseName:=Ls_DBName;
Params.Values['DATABASE NAME']:=Ls_DBDataBaseName;
Params.Values['SERVER NAME']:=Ls_DBServerName;
Params.Values['USER NAME']:=Ls_DBUserName;
Params.Values['PASSWORD']:=Ls_DBPassWord;
Params.Values['CONNECT TIMEOUT']:='30';
try
Open;
Ls_ConnectFlag:=true;
except
Ls_ConnectFlag:=false;
ShowMessage('立山区数据库连接失败!');
end;
end;
//if not DBLs.Connected then exit;
with DBDh do
begin
AliasName:=Dh_DBAliasName;
DatabaseName:=Dh_DBName;
Params.Values['DATABASE NAME']:=Dh_DBDataBaseName;
Params.Values['SERVER NAME']:=Dh_DBServerName;
Params.Values['USER NAME']:=Dh_DBUserName;
Params.Values['PASSWORD']:=Dh_DBPassWord;
try
Open;
Dh_ConnectFlag:=true;
except
Dh_ConnectFlag:=false;
ShowMessage('大户数据库连接失败!');
end;
end; }
//if not DBDh.Connected then exit;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -