datapersistentunit.pas
来自「随便说说最近项目中的三层架构吧。讲点实际的东西。我最讨厌空讲道理。网上讲道理的太」· PAS 代码 · 共 117 行
PAS
117 行
unit DataPersistentUnit;
interface
uses Windows, Messages, Classes, SysUtils, Forms, DB, ADODB, DBClient, MConnect,
IDataPersistentUnit, DataStructureUnit;
type
TLDMDataSet = class(TPersistent)
private
IDataPer: IDataPersistent;
published
function BeginTrans: Integer; safecall;
function CommitTrans: Integer; safecall;
function RollBackTrans: Integer; safecall;
function SelectLDMDS(const wsSQL: WideString; out wsPrv :WideString): TDataSet; Stdcall;
function InsertLDMDS(const wsSQL: WideString): Integer; safecall;
function UpdateLDMDS(const wsSQL: WideString): Integer; safecall;
function DeleteLDMDS(const wsSQL: WideString): Integer; safecall;
Procedure CloseLDMDS(const wsDSName: WideString); safecall;
public
constructor Create(pIDataPer: IDataPersistent);
end;
implementation
uses ServerFrm, ResourceStrUnit;
constructor TLDMDataSet.Create(pIDataPer: IDataPersistent);
begin
inherited Create;
IDataPer := pIDataPer;
end;
function TLDMDataSet.BeginTrans: Integer; safecall;
begin
try
Result := IDataPer.BeginTrans;
except
Result := -1;
MessageBox(Application.handle, PChar(GloRs_IDsBTranErr), PChar(GloRs_Title), MB_ICONINFORMATION);
end;
end;
function TLDMDataSet.CommitTrans: Integer; safecall;
begin
try
Result := IDataPer.CommitTrans;
except
Result := -1;
MessageBox(Application.handle, PChar(GloRs_IDsCTranErr), PChar(GloRs_Title), MB_ICONINFORMATION);
end;
end;
function TLDMDataSet.RollBackTrans: Integer; safecall;
begin
try
Result := IDataPer.RollBackTrans;
except
Result := -1;
MessageBox(Application.handle, PChar(GloRs_IDsRTranErr), PChar(GloRs_Title), MB_ICONINFORMATION);
end;
end;
function TLDMDataSet.SelectLDMDS(const wsSQL: WideString; out wsPrv :WideString): TDataSet; Stdcall;
begin
try
Result := IDataPer.SelectData(wsSQL, wsPrv);
except
Result := nil;
MessageBox(Application.handle, PChar(GloRs_IDsGetData), PChar(GloRs_Title), MB_ICONINFORMATION);
end;
end;
function TLDMDataSet.InsertLDMDS(const wsSQL: WideString): Integer; safecall;
begin
try
Result := IDataPer.InsertDataSet(wsSQL);
except
Result := -1;
MessageBox(Application.handle, PChar(GloRs_IDsExeData), PChar(GloRs_Title), MB_ICONINFORMATION);
end;
end;
function TLDMDataSet.UpdateLDMDS(const wsSQL: WideString): Integer; safecall;
begin
try
Result := IDataPer.UpdateDataSet(wsSQL);
except
Result := -1;
MessageBox(Application.handle, PChar(GloRs_IDsExeData), PChar(GloRs_Title), MB_ICONINFORMATION);
end;
end;
function TLDMDataSet.DeleteLDMDS(const wsSQL: WideString): Integer; safecall;
begin
try
Result := IDataPer.DeleteDataSet(wsSQL);
except
Result := -1;
MessageBox(Application.handle, PChar(GloRs_IDsExeData), PChar(GloRs_Title), MB_ICONINFORMATION);
end;
end;
Procedure TLDMDataSet.CloseLDMDS(const wsDSName: WideString); safecall;
begin
try
IDataPer.CloseDataSet(wsDSName);
except
end;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?