A
aleyn
Unregistered / Unconfirmed
GUEST, unregistred user!
部分原碼(三)
unit dmBaseModuleImp;
interface
uses
Classes, SysUtils, Variants, dmBaseModule,
hmSqlStoreProc, hmOleVariant, hmStrTools, hmSqlTools,
hmOleDataSet;
type
TSqlLoadType = (slSql, slProc);
type
THMSqlEx = class(THMSQL)
private
FModule: integer;
Service: IBaseService;
function GetSqlLanguage: WideString;
public
procedure LoadFromStore(index: integer);
procedure LoadParamV(index: string);
procedure LoadParamF(index: string);
property Module: integer read FModule write FModule;
property BaseService: IBaseService read Service write Service;
property SqlLanguage: WideString read GetSqlLanguage;
end;
THMSqlStoreProcEx = class(THMSqlStoreProc)
private
FModule: integer;
Service: IBaseService;
function GetSqlLanguage: WideString;
public
procedure LoadFromStore(index: integer);
procedure LoadOleParam(index: string);
procedure LoadOleFunc(index: string);
property Module: integer read FModule write FModule;
property BaseService: IBaseService read Service write Service;
property SqlLanguage: WideString read GetSqlLanguage;
end;
type
TBaseDataModule = class(TInterfacedObject, IBaseDataModule)
private
FModule: integer;
function GetOle: IHMOleVariant;
protected
Sql: THMSqlEx;
StoreProc: THMSqlStoreProcEx;
MsgList: TStringList;
Service: IBaseService;
protected
function ActionList(CmdIndex: integer;
var Data, Msg: OleVariant): WordBool;
virtual;
procedure ShowDebug(Msg: string);
procedure ApplyUpdates(Delta: OleVariant;
TableName, KeyField: string);
function GetInnerModuleInfo: WideString;
virtual;
procedure CheckTranstion;
procedure CallServiceReceiveDataV;
procedure CallServiceReceiveDataT;
procedure LoadFromStore(Index: integer;
LoadType: TSqlLoadType);
property Ole: IHMOleVariant read GetOle;
public
constructor Create(const BaseService: IBaseService);
destructor Destroy;
override;
function GetModuleInfo: WideString;
stdcall;
function GetBaseService: IBaseService;
stdcall;
procedure SetBaseService(const Value: IBaseService);
stdcall;
function GetModule(): integer;
stdcall;
procedure SetModule(const value: integer);
stdcall;
function Operation(var Data, Msg: OleVariant): WordBool;
stdcall;
procedure LoadOleParam(const Param: OleVariant);
stdcall;
end;
TBaseDataModuleInfo = class(TInterfacedObject, IDataModuleInfo)
public
function GetModuleName: WideString;
virtual;
stdcall;
function GetVersion: Widestring;
virtual;
stdcall;
function GetDesignner: Widestring;
virtual;
stdcall;
function GetMemo: Widestring;
virtual;
stdcall;
function GetLastUpdate: WideString;
virtual;
stdcall;
function GetModuleIndex: Integer;
virtual;
stdcall;
end;
type
ErrSystemBusy = class(Exception)
public
constructor Create;
end;
implementation
uses swModuleIndex;
{ TBaseDataModule }
constructor TBaseDataModule.Create(const BaseService: IBaseService);
begin
inherited Create;
Service := BaseService;
Sql := THMSqlEx.Create;
StoreProc := THMSqlStoreProcEx.Create;
MsgList := TStringList.Create;
Sql.BaseService := BaseService;
StoreProc.BaseService := BaseService;
end;
destructor TBaseDataModule.Destroy;
begin
Sql.Free;
StoreProc.Free;
MsgList.Free;
inherited Destroy;
end;
(* Operation : 通用執行函數,DataServer將通過它來執行 *)
(* ActionList: 內部重載執行函數,通它重載分析Action來執行 *)
(* Param : 執行參數,須通過Ole.LoadfromOle來讀取參數 *)
(* Data : 返回表格數據 *)
(* Msg : 返回執行信息,或是錯誤信息,或是執行完畢信息*)
function TBaseDataModule.Operation(var Data, Msg: OleVariant): WordBool;
var
CmdIndex: integer;
begin
try
CmdIndex := Service.Params.Action;
Result := ActionList(CmdIndex, Data, Msg);
StoreProc.Clear;
SQL.Params.Clear;
except
on E: Exceptiondo
begin
Msg := E.Message;
Result := False;
end;
end;
end;
function TBaseDataModule.ActionList(CmdIndex: integer;
var Data, Msg: OleVariant): WordBool;
begin
Msg := format('沒有可以執行的命令(%d)', [CmdIndex]);
Result := False;
end;
procedure TBaseDataModule.ShowDebug(Msg: string);
begin
Service.ShowMessage(Msg);
end;
procedure TBaseDataModule.ApplyUpdates(Delta: OleVariant;
TableName, KeyField: string);
begin
Service.ApplyUpdates(Delta, TableName, KeyField);
end;
procedure TBaseDataModule.SetModule(const Value: integer);
begin
FModule := Value;
Sql.Module := Value;
StoreProc.Module := Value;
end;
function TBaseDataModule.GetModule: integer;
begin
Result := FModule;
end;
function TBaseDataModule.GetModuleInfo: WideString;
begin
Result := GetInnerModuleInfo;
end;
function TBaseDataModule.GetInnerModuleInfo: WideString;
begin
Result := 'This is System Default Module(' + ClassName + ')';
end;
function TBaseDataModule.GetBaseService: IBaseService;
begin
Result := Service;
end;
procedure TBaseDataModule.SetBaseService(const Value: IBaseService);
begin
Service := Value;
end;
procedure TBaseDataModule.LoadOleParam(const Param: OleVariant);
begin
//FOle.LoadFromOle(Param);
end;
procedure TBaseDataModule.CallServiceReceiveDataT;
begin
Service.OpenQuery(StoreProc.StoreProc.Text);
Service.ReceiveDataWithDefault;
end;
procedure TBaseDataModule.CallServiceReceiveDataV;
begin
Service.OpenQuery(Sql.OutLines.Text);
Service.ReceiveDataWithDefault;
end;
procedure TBaseDataModule.CheckTranstion;
begin
if Service.InTranstion then
raise ErrSystemBusy.Create;
end;
procedure TBaseDataModule.LoadFromStore(Index: integer;
LoadType: TSqlLoadType);
var
i: integer;
Params, Body: WideString;
begin
if index < 1000 then
i := index + FModule * 1000 + 1
else
i := index;
if Service.GetSqlLanguage(i, Params, Body) then
begin
case LoadType of //
slSql:
begin
Sql.InLines.Text := Body;
end;
slProc:
begin
StoreProc.LoadStoreProc(Body);
StoreProc.LoadParams(Params);
end;
end;
// case
end
else
raise Exception.Create('Stored Sql not found(index:' + inttostr(index));
end;
function TBaseDataModule.GetOle: IHMOleVariant;
begin
Result := Service.Params;
end;
{ THMSqlEx }
function THMSqlEx.GetSqlLanguage: WideString;
begin
Result := OutLines.Text;
end;
procedure THMSqlEx.LoadFromStore(index: integer);
var
i: integer;
Params, Body: WideString;
begin
if index < 1000 then
i := index + FModule * 1000 + 1
else
i := index;
if Service.GetSqlLanguage(i, Params, Body) then
begin
InLines.Text := Body;
end
else
raise Exception.Create('Stored Sql not found(index:' + inttostr(index));
end;
procedure THMSqlEx.LoadParamF(index: string);
begin
Params.ParamValue[index] := '@F ' + Service.Params[index];
end;
procedure THMSqlEx.LoadParamV(index: string);
begin
Params.ParamValue[index] := Service.Params[index];
end;
{ THMSqlStoreProcEx }
procedure THMSqlStoreProcEx.LoadFromStore(index: integer);
var
i: integer;
Params, Body: WideString;
begin
if index < 1000 then
i := index + FModule * 1000 + 1
else
i := index;
if Service.GetSqlLanguage(i, Params, Body) then
begin
LoadStoreProc(Body);
LoadParams(Params);
end
else
raise Exception.Create('Stored Sql not found(index:' + inttostr(index));
end;
procedure THMSqlStoreProcEx.LoadOleParam(index: string);
begin
Self.Value[index] := Service.Params[index];
end;
procedure THMSqlStoreProcEx.LoadOleFunc(index: string);
begin
Self.Value[index] := Service.Params[index];
end;
function THMSqlStoreProcEx.GetSqlLanguage: WideString;
begin
Result := Self.StoreProc.Text;
end;
{ ErrSystemBusy }
constructor ErrSystemBusy.Create;
begin
inherited Create('系統忙:ADO IS Busy');
end;
{ TBaseDataModuleInfo }
function TBaseDataModuleInfo.GetDesignner: Widestring;
begin
Result := 'Aleyn.wu';
end;
function TBaseDataModuleInfo.GetLastUpdate: WideString;
begin
Result := '2003-09-25';
end;
function TBaseDataModuleInfo.GetMemo: Widestring;
begin
Result := 'This is BaseDataModule';
end;
function TBaseDataModuleInfo.GetModuleIndex: Integer;
begin
Result := -1;
end;
function TBaseDataModuleInfo.GetModuleName: WideString;
begin
Result := 'BaseDataModule';
end;
function TBaseDataModuleInfo.GetVersion: Widestring;
begin
Result := '0.0.0.0';
end;
end.
unit dmBaseModuleImp;
interface
uses
Classes, SysUtils, Variants, dmBaseModule,
hmSqlStoreProc, hmOleVariant, hmStrTools, hmSqlTools,
hmOleDataSet;
type
TSqlLoadType = (slSql, slProc);
type
THMSqlEx = class(THMSQL)
private
FModule: integer;
Service: IBaseService;
function GetSqlLanguage: WideString;
public
procedure LoadFromStore(index: integer);
procedure LoadParamV(index: string);
procedure LoadParamF(index: string);
property Module: integer read FModule write FModule;
property BaseService: IBaseService read Service write Service;
property SqlLanguage: WideString read GetSqlLanguage;
end;
THMSqlStoreProcEx = class(THMSqlStoreProc)
private
FModule: integer;
Service: IBaseService;
function GetSqlLanguage: WideString;
public
procedure LoadFromStore(index: integer);
procedure LoadOleParam(index: string);
procedure LoadOleFunc(index: string);
property Module: integer read FModule write FModule;
property BaseService: IBaseService read Service write Service;
property SqlLanguage: WideString read GetSqlLanguage;
end;
type
TBaseDataModule = class(TInterfacedObject, IBaseDataModule)
private
FModule: integer;
function GetOle: IHMOleVariant;
protected
Sql: THMSqlEx;
StoreProc: THMSqlStoreProcEx;
MsgList: TStringList;
Service: IBaseService;
protected
function ActionList(CmdIndex: integer;
var Data, Msg: OleVariant): WordBool;
virtual;
procedure ShowDebug(Msg: string);
procedure ApplyUpdates(Delta: OleVariant;
TableName, KeyField: string);
function GetInnerModuleInfo: WideString;
virtual;
procedure CheckTranstion;
procedure CallServiceReceiveDataV;
procedure CallServiceReceiveDataT;
procedure LoadFromStore(Index: integer;
LoadType: TSqlLoadType);
property Ole: IHMOleVariant read GetOle;
public
constructor Create(const BaseService: IBaseService);
destructor Destroy;
override;
function GetModuleInfo: WideString;
stdcall;
function GetBaseService: IBaseService;
stdcall;
procedure SetBaseService(const Value: IBaseService);
stdcall;
function GetModule(): integer;
stdcall;
procedure SetModule(const value: integer);
stdcall;
function Operation(var Data, Msg: OleVariant): WordBool;
stdcall;
procedure LoadOleParam(const Param: OleVariant);
stdcall;
end;
TBaseDataModuleInfo = class(TInterfacedObject, IDataModuleInfo)
public
function GetModuleName: WideString;
virtual;
stdcall;
function GetVersion: Widestring;
virtual;
stdcall;
function GetDesignner: Widestring;
virtual;
stdcall;
function GetMemo: Widestring;
virtual;
stdcall;
function GetLastUpdate: WideString;
virtual;
stdcall;
function GetModuleIndex: Integer;
virtual;
stdcall;
end;
type
ErrSystemBusy = class(Exception)
public
constructor Create;
end;
implementation
uses swModuleIndex;
{ TBaseDataModule }
constructor TBaseDataModule.Create(const BaseService: IBaseService);
begin
inherited Create;
Service := BaseService;
Sql := THMSqlEx.Create;
StoreProc := THMSqlStoreProcEx.Create;
MsgList := TStringList.Create;
Sql.BaseService := BaseService;
StoreProc.BaseService := BaseService;
end;
destructor TBaseDataModule.Destroy;
begin
Sql.Free;
StoreProc.Free;
MsgList.Free;
inherited Destroy;
end;
(* Operation : 通用執行函數,DataServer將通過它來執行 *)
(* ActionList: 內部重載執行函數,通它重載分析Action來執行 *)
(* Param : 執行參數,須通過Ole.LoadfromOle來讀取參數 *)
(* Data : 返回表格數據 *)
(* Msg : 返回執行信息,或是錯誤信息,或是執行完畢信息*)
function TBaseDataModule.Operation(var Data, Msg: OleVariant): WordBool;
var
CmdIndex: integer;
begin
try
CmdIndex := Service.Params.Action;
Result := ActionList(CmdIndex, Data, Msg);
StoreProc.Clear;
SQL.Params.Clear;
except
on E: Exceptiondo
begin
Msg := E.Message;
Result := False;
end;
end;
end;
function TBaseDataModule.ActionList(CmdIndex: integer;
var Data, Msg: OleVariant): WordBool;
begin
Msg := format('沒有可以執行的命令(%d)', [CmdIndex]);
Result := False;
end;
procedure TBaseDataModule.ShowDebug(Msg: string);
begin
Service.ShowMessage(Msg);
end;
procedure TBaseDataModule.ApplyUpdates(Delta: OleVariant;
TableName, KeyField: string);
begin
Service.ApplyUpdates(Delta, TableName, KeyField);
end;
procedure TBaseDataModule.SetModule(const Value: integer);
begin
FModule := Value;
Sql.Module := Value;
StoreProc.Module := Value;
end;
function TBaseDataModule.GetModule: integer;
begin
Result := FModule;
end;
function TBaseDataModule.GetModuleInfo: WideString;
begin
Result := GetInnerModuleInfo;
end;
function TBaseDataModule.GetInnerModuleInfo: WideString;
begin
Result := 'This is System Default Module(' + ClassName + ')';
end;
function TBaseDataModule.GetBaseService: IBaseService;
begin
Result := Service;
end;
procedure TBaseDataModule.SetBaseService(const Value: IBaseService);
begin
Service := Value;
end;
procedure TBaseDataModule.LoadOleParam(const Param: OleVariant);
begin
//FOle.LoadFromOle(Param);
end;
procedure TBaseDataModule.CallServiceReceiveDataT;
begin
Service.OpenQuery(StoreProc.StoreProc.Text);
Service.ReceiveDataWithDefault;
end;
procedure TBaseDataModule.CallServiceReceiveDataV;
begin
Service.OpenQuery(Sql.OutLines.Text);
Service.ReceiveDataWithDefault;
end;
procedure TBaseDataModule.CheckTranstion;
begin
if Service.InTranstion then
raise ErrSystemBusy.Create;
end;
procedure TBaseDataModule.LoadFromStore(Index: integer;
LoadType: TSqlLoadType);
var
i: integer;
Params, Body: WideString;
begin
if index < 1000 then
i := index + FModule * 1000 + 1
else
i := index;
if Service.GetSqlLanguage(i, Params, Body) then
begin
case LoadType of //
slSql:
begin
Sql.InLines.Text := Body;
end;
slProc:
begin
StoreProc.LoadStoreProc(Body);
StoreProc.LoadParams(Params);
end;
end;
// case
end
else
raise Exception.Create('Stored Sql not found(index:' + inttostr(index));
end;
function TBaseDataModule.GetOle: IHMOleVariant;
begin
Result := Service.Params;
end;
{ THMSqlEx }
function THMSqlEx.GetSqlLanguage: WideString;
begin
Result := OutLines.Text;
end;
procedure THMSqlEx.LoadFromStore(index: integer);
var
i: integer;
Params, Body: WideString;
begin
if index < 1000 then
i := index + FModule * 1000 + 1
else
i := index;
if Service.GetSqlLanguage(i, Params, Body) then
begin
InLines.Text := Body;
end
else
raise Exception.Create('Stored Sql not found(index:' + inttostr(index));
end;
procedure THMSqlEx.LoadParamF(index: string);
begin
Params.ParamValue[index] := '@F ' + Service.Params[index];
end;
procedure THMSqlEx.LoadParamV(index: string);
begin
Params.ParamValue[index] := Service.Params[index];
end;
{ THMSqlStoreProcEx }
procedure THMSqlStoreProcEx.LoadFromStore(index: integer);
var
i: integer;
Params, Body: WideString;
begin
if index < 1000 then
i := index + FModule * 1000 + 1
else
i := index;
if Service.GetSqlLanguage(i, Params, Body) then
begin
LoadStoreProc(Body);
LoadParams(Params);
end
else
raise Exception.Create('Stored Sql not found(index:' + inttostr(index));
end;
procedure THMSqlStoreProcEx.LoadOleParam(index: string);
begin
Self.Value[index] := Service.Params[index];
end;
procedure THMSqlStoreProcEx.LoadOleFunc(index: string);
begin
Self.Value[index] := Service.Params[index];
end;
function THMSqlStoreProcEx.GetSqlLanguage: WideString;
begin
Result := Self.StoreProc.Text;
end;
{ ErrSystemBusy }
constructor ErrSystemBusy.Create;
begin
inherited Create('系統忙:ADO IS Busy');
end;
{ TBaseDataModuleInfo }
function TBaseDataModuleInfo.GetDesignner: Widestring;
begin
Result := 'Aleyn.wu';
end;
function TBaseDataModuleInfo.GetLastUpdate: WideString;
begin
Result := '2003-09-25';
end;
function TBaseDataModuleInfo.GetMemo: Widestring;
begin
Result := 'This is BaseDataModule';
end;
function TBaseDataModuleInfo.GetModuleIndex: Integer;
begin
Result := -1;
end;
function TBaseDataModuleInfo.GetModuleName: WideString;
begin
Result := 'BaseDataModule';
end;
function TBaseDataModuleInfo.GetVersion: Widestring;
begin
Result := '0.0.0.0';
end;
end.