function TRDMDataSet.SelectRDMDS(const obj: TDataTransferObject;
filtrateSQL: String;
var DataSet: TClientDataSet): Boolean;
safecall;
var
i, j: integer;
begin
Result := SelectRDMDS(Adapter.getSearchSQLString(obj)+filtrateSQL, DataSet);
CloseRDMDS(DataSet);
for i:=0 to DataSet.FieldCount-1do
DataSet.Fields.DisplayLabel := obj.GridInfo;
for i:=0 to obj.GridVisible.Count-1do
begin
for j:=0 to DataSet.FieldCount-1do
if UpperCase(Trim(DataSet.Fields[j].FieldName))= UpperCase(Trim(obj.GridVisible.Strings)) then
DataSet.Fields[j].Visible := false;
end;
end;
function TRDMDataSet.SelectRDMDS(const obj: TDataTransferObject;
var DataSet: TClientDataSet): Boolean;
safecall;
var
i, j: integer;
begin
Result := SelectRDMDS(Adapter.getSearchSQLString(obj), DataSet);
CloseRDMDS(DataSet);
for i:=0 to DataSet.FieldCount-1do
DataSet.Fields.DisplayLabel := obj.GridInfo;
for i:=0 to obj.GridVisible.Count-1do
begin
for j:=0 to DataSet.FieldCount-1do
if UpperCase(Trim(DataSet.Fields[j].FieldName))= UpperCase(Trim(obj.GridVisible.Strings)) then
DataSet.Fields[j].Visible := false;
end;
end;
function TRDMDataSet.SelectRDMDS(const SqlStr: WideString;
var DataSet: TClientDataSet): Boolean;
var
sPrvName: WideString;
begin
Result := False;
sPrvName := '';
DataSet.Close;
DataSet.RemoteServer := SocketConn;
try
if IDLLDataPer.SelectData(@SqlStr, sPrvName) then
begin
DataSet.ProviderName := sPrvName;
try
DataSet.Close;
DataSet.Open;
Result := true;
except
Result := false;
end;
end
else
begin
if IDLLDataPer.SelectData(@SqlStr, sPrvName) then
begin
DataSet.ProviderName := sPrvName;
try
DataSet.Close;
DataSet.Open;
Result := true;
except
Result := false;
end;
end;
end;
except
Raise;
end;
if Copy(Trim(sPrvName),1,3) = 'DSP' then
CloseRDMDS(DataSet);
end;
function TRDMDataSet.InsertRDMDS(const SqlStr: WideString;
out pMsg: WideString): Boolean;
begin
Result := IDLLDataPer.InsertDataSet(@SqlStr, pMsg);
end;
function TRDMDataSet.InsertRDMDS(const obj: TDataTransferObject;
out pMsg: WideString): Boolean;
begin
SelectRDMDS(Adapter.getKeySQLString(obj), tmpCDS);
//主键更新失败
if tmpCDS.Fields[0].Value>0 then
begin
pMsg := '主键冲突,插入操作失败!';
exit;
end;
Result := InsertRDMDS(Adapter.getInsertSQLString(obj), pMsg);
end;
function TRDMDataSet.InsertRDMDS(const obj: TDataTransferObject;
var DataSet: TClientDataSet;
out pMsg: WideString): Boolean;
var
i: integer;
tmpPropList: TMPropList;
begin
SelectRDMDS(Adapter.getKeySQLString(obj), tmpCDS);
//主键更新失败
if tmpCDS.Fields[0].Value>0 then
begin
pMsg := '主键冲突,插入操作失败!';
DataSet.Cancel;
exit;
end;
Result := InsertRDMDS(Adapter.getInsertSQLString(obj), pMsg);
if Result = false then
begin
pMsg := '异常数据,插入操作失败!';
DataSet.Cancel;
exit;
end;
tmpPropList := obj.FPropList;
DataSet.Cancel;
DataSet.Append;
for i:=0 to tmpPropList.PropCount-1do
begin
case tmpPropList.Props^.PropType^.Kind of
tkInteger:
if Adapter.GetFldName(tmpPropList.PropNames)<>'' then
DataSet.FieldByName(Adapter.GetFldName(tmpPropList.PropNames)).Value := GetOrdProp(obj, tmpPropList.Props);
tkInt64:
if Adapter.GetFldName(tmpPropList.PropNames)<>'' then
DataSet.FieldByName(Adapter.GetFldName(tmpPropList.PropNames)).Value := GetInt64Prop(obj, tmpPropList.Props);
tkChar, tkLString, tkString:
if Adapter.GetFldName(tmpPropList.PropNames)<>'' then
DataSet.FieldByName(Adapter.GetFldName(tmpPropList.PropNames)).Value := GetStrProp(obj, tmpPropList.Props);
tkSet:
if Adapter.GetFldName(tmpPropList.PropNames)<>'' then
DataSet.FieldByName(Adapter.GetFldName(tmpPropList.PropNames)).Value := GetSetProp(obj, tmpPropList.Props);
tkEnumeration:
if Adapter.GetFldName(tmpPropList.PropNames)<>'' then
DataSet.FieldByName(Adapter.GetFldName(tmpPropList.PropNames)).Value := GetEnumProp(obj, tmpPropList.Props) ;
tkFloat:
if Adapter.GetFldName(tmpPropList.PropNames)<>'' then
DataSet.FieldByName(Adapter.GetFldName(tmpPropList.PropNames)).Value := GetFloatProp(obj, tmpPropList.Props) ;
tkWChar, tkWString:
if Adapter.GetFldName(tmpPropList.PropNames)<>'' then
DataSet.FieldByName(Adapter.GetFldName(tmpPropList.PropNames)).Value := GetWideStrProp(obj, tmpPropList.Props) ;
end;
end;
DataSet.Post;
end;
function TRDMDataSet.UpdateRDMDS(const SqlStr: WideString;
out pMsg: WideString): Boolean;
begin
Result := IDLLDataPer.UpdateDataSet(@SqlStr, pMsg);
end;
function TRDMDataSet.UpdateRDMDS(const obj: TDataTransferObject;
out pMsg: WideString): Boolean;
var
i: integer;
tmpPropList: TMPropList;
begin
SelectRDMDS(Adapter.getKeySQLString(obj), tmpCDS);
//主键更新失败
if not tmpCDS.Fields[0].Value>0 then
begin
pMsg := '主键不能正确定位,更新操作失败!';
exit;
end;
Result := UpdateRDMDS(Adapter.getUpdateSQLString(obj), pMsg);
end;
function TRDMDataSet.UpdateRDMDS(const obj: TDataTransferObject;
var DataSet: TClientDataSet;
out pMsg: WideString): Boolean;
var
i: integer;
tmpPropList: TMPropList;
begin
SelectRDMDS(Adapter.getKeySQLString(obj), tmpCDS);
//主键更新失败
if not tmpCDS.Fields[0].Value>0 then
begin
pMsg := '主键不能正确定位,更新操作失败!';
DataSet.Cancel;
exit;
end;
Result := UpdateRDMDS(Adapter.getUpdateSQLString(obj), pMsg);
if Result = false then
exit;
tmpPropList := obj.FPropList;
if not (DataSet.State in [dsEdit]) then
DataSet.Edit;
for i:=0 to tmpPropList.PropCount-1do
begin
case tmpPropList.Props^.PropType^.Kind of
tkInteger:
if Adapter.GetFldName(tmpPropList.PropNames)<>'' then
DataSet.FieldByName(Adapter.GetFldName(tmpPropList.PropNames)).Value := GetOrdProp(obj, tmpPropList.Props);
tkInt64:
if Adapter.GetFldName(tmpPropList.PropNames)<>'' then
DataSet.FieldByName(Adapter.GetFldName(tmpPropList.PropNames)).Value := GetInt64Prop(obj, tmpPropList.Props);
tkChar, tkLString, tkString:
if Adapter.GetFldName(tmpPropList.PropNames)<>'' then
DataSet.FieldByName(Adapter.GetFldName(tmpPropList.PropNames)).Value := GetStrProp(obj, tmpPropList.Props);
tkSet:
if Adapter.GetFldName(tmpPropList.PropNames)<>'' then
DataSet.FieldByName(Adapter.GetFldName(tmpPropList.PropNames)).Value := GetSetProp(obj, tmpPropList.Props);
tkEnumeration:
if Adapter.GetFldName(tmpPropList.PropNames)<>'' then
DataSet.FieldByName(Adapter.GetFldName(tmpPropList.PropNames)).Value := GetEnumProp(obj, tmpPropList.Props) ;
tkFloat:
if Adapter.GetFldName(tmpPropList.PropNames)<>'' then
DataSet.FieldByName(Adapter.GetFldName(tmpPropList.PropNames)).Value := GetFloatProp(obj, tmpPropList.Props) ;
tkWChar, tkWString:
if Adapter.GetFldName(tmpPropList.PropNames)<>'' then
DataSet.FieldByName(Adapter.GetFldName(tmpPropList.PropNames)).Value := GetWideStrProp(obj, tmpPropList.Props) ;
end;
end;
DataSet.Post;
end;