【delphi开源代码栏目提醒】:本文主要为网学会员提供dmXsgl.pas,希望对需要dmXsgl.pas网友有所帮助,学习一下!
unit dmXsgl;
interface
uses
SysUtils, Classes, DB, Dialogs, XSGLCommon, ADODB, IniFiles;
const
conConnectionStr = 'Provider=SQLOLEDB.1;Integrated Security=SSPI;' +
'Persist Security Info=False;Initial Catalog=%S;Data Source=%S';
type
TdmXsgl = class(TDataModule)
AdoXsgl: TADOConnection;
adotKhxx: TADOTable;
adoqDdxx: TADOQuery;
adoqDdmx: TADOQuery;
adotLocate: TADOTable;
adoqCommon: TADOQuery;
adotXsglFields: TADOTable;
adotCpxx: TADOTable;
adoqXscxByRQ: TADOQuery;
adoqXscxByCP: TADOQuery;
adoqXscxByKH: TADOQuery;
private
{ Private declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
function LocateValue(ATableName: string; const KeyFields: string;
const KeyValues: Variant): Boolean;
procedure InitComboBox(AList: TStrings; ATable: string; AFieldName: string);
end;
implementation
{$R *.dfm}
constructor TdmXsgl.Create(AOwner: TComponent);
var
l_IniFile: string;
l_ServerName, l_Database: string;
begin
inherited Create(AOwner);
l_IniFile := ExePath + conIniFile;
if not FileExists(l_IniFile) then
begin
ShowMessage('数据库连接信息文件不存在!');
Exit;
end;
with TIniFile.Create(l_IniFile) do
try
l_ServerName := ReadString('Server', 'ServerName', '127.0.0.1');
l_DataBase := ReadString('Server', 'DataBase', 'XSGL');
AdoXsgl.ConnectionString := Format(conConnectionStr, [l_DataBase, l_ServerName]);
AdoXsgl.Connected := True;
finally
free;
end;
adotXSGLFields.Open;
adotCpxx.Open;
adotKhxx.Open;
end;
procedure TdmXsgl.InitComboBox(AList: TStrings; ATable: string; AFieldName: string);
begin
with adoqCommon do
begin
Close;
SQL.Text := 'select * from ' + ATable;
Open;
AList.Clear;
while not Eof do
begin
Alist.Add(FieldByName(AFieldName).AsString);
Next;
end;
end;
end;
function TdmXsgl.LocateValue(ATableName: string; const KeyFields: string;
const KeyValues: Variant): Boolean;
begin
with adotLocate do
begin
if TableName <> ATableName then
begin
if Active then Close;
TableName := ATableName;
end;
if not Active then Open;
Result := Locate(KeyFields, KeyValues, []);
end;
end;
end.
上一篇:
DMUnit.pas
下一篇:
汝康皮肤护理液医治烧伤的可行性和效果分析