📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, uDatabasePublic, uDBContext;
type
TForm1 = class(TForm)
btn1: TButton;
mmo1: TMemo;
edt1: TEdit;
procedure btn1Click(Sender: TObject);
private
//IconnDB: IDBContext;
pDbContext : TDBContext;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses
uMssqlDbContext, uMssqlFactory, uOralceFactory, ResourceStrUnit, uDBFactory,
uDaoFactory, uMemberDAO;
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
fDBconfig : TDBConfig;
fDbFactory : TDBFactory;
fConnFactory : TMssqlDbContext;
fConnDb : TADOConnection;
strFilePath : string;
fDaoFactory : TDaoFactory;
fMemberDao : IMemberDAO;
fMember : TMember;
fID : integer;
begin
strFilePath := ExtractFilePath(ParamStr(0))+'Config\dbConn.ini';
if(not FileExists(strFilePath)) then
begin
MessageBox(Application.handle, PChar(GloRs_ErrorDBConfig), PChar(GloRs_Title), MB_ICONINFORMATION);
exit;
end;
try
fDBconfig := TDBConfig.Create;
if not fDBconfig.setConnection(strFilePath) then
MessageBox(handle, PChar(GloRs_Title), PChar(GloRs_ErrorDBConfigErr),MB_ICONINFORMATION)
except
fDBconfig.Free;
exit;
end;
try
//创建数据库工厂
fDbFactory := TDBFactory.getDBFactory(fDBconfig.DBKind);
//创建数据库环境信息
pDbContext := fDbFactory.CreatDBContext;
pDbContext.DBConfig := fDBconfig;
pDbContext.Connection;
//if IConnDB.getDBKind = dbACCESS then
//EncryptDB(frmServer.pDBConfig.pDBName);
finally
fdbfactory.Free;
end;
if (pDbContext.getConnection is TADOConnection) then
begin
fconndb := pDbContext.getConnection as TADOConnection;
fconndb.GetTableNames(mmo1.Lines);
fconndb.Close;
end;
fDaoFactory := TDaoFactory.getDaoFactory(fDBconfig.DBKind);
fDaoFactory.Connection := fconndb;
fMemberDao := fDaoFactory.getMemberDAO;
fMember := TMember.Create;
fmember.MemberName := '徐静君';
fID := fMemberDao.insertMember(fmember);
edt1.Text := intTostr(fID);
fDaoFactory.Free;
fMember.Free;
//pDbContext.Free;
//fMemberDao.free;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -