問題 ( 积分: 50 )

  • 主题发起人 urlabelsoft
  • 开始时间
U

urlabelsoft

Unregistered / Unconfirmed
GUEST, unregistred user!
function getsqldata(CDS:Tclientdataset;TableName,keyField:wideString;ssql:wideString;
const Maxrec:integer=20):boolean;
var
TempCDS:TclientDataset;
FkeyValue:String;
Fsql:String;
function SetSql():String;
const SqlFmt='select * from %s%s%s order by %s';
begin
if FkeyValue='' then
begin
Result:=Format(SqlFmt,[Tablename,' where ',ssql,keyField]);
end
else
begin
Result:=Format(sqlFmt,[Tablename,' where ',
keyfield+'>'+#39+FkeyValue+#39+' and '+ssql,keyField]);
end;
end;

begin
ClearCDSData(CDS);
try
TempCDS:=Tclientdataset.Create(nil);
TempCDS.FetchOnDemand:=False;
tempCDS.PacketRecords:=Maxrec;
FkeyValue:='';
while True do
begin
Fsql:=SetSql;
GetDataFormServer(TempCDS,Fsql,MaxRec);
InsertCDSData(TempCDS,CDS);
if TempCDS.RecordCount<MaxRec then
Break;
TempCDS.Last;
FkeyValue:=TempCDS.fieldbyname(keyField).AsString;
ClearCDSdata(TempCDS);
Fsql:='';
Application.ProcessMessages;
end;
finally
TempCDS.Close;
TempCDS.Free();
end;
Result:=True;
end;

function getDataFormServer(ACDS:TclientDataSet;ssql:wideString;const reccount:integer=20):wordbool;
begin
try
ACDS.Data:=dmClient.SocketConnection1.AppServer.GetlargeData(ssql,reccount);
Result:=True;
except
Result:=False;
end;
end;

function insertCDSDATA(s,d:TclientDataset):boolean;
var
V:TbookMark;
begin
Result:=True;
try
V:=D.GetBookmark;
if d.Active then
d.AppendData(S.Data,False)
else
D.Data:=S.Data;
finally
D.GotoBookmark(V);
D.FreeBookmark(V);
end;
end;

function ClearCDSDATA(s:Tclientdataset):boolean;
begin
S.Close;
s.Data:=null;
Result:=True;
end;

function TDataprocess.GetLargeData(const cmdStr: WideString;
Rcount: Integer): OleVariant;
var
CL:TRTLCriticalSection;
begin
try
InitializeCriticalSection(CL);
EnterCriticalSection(CL);
try
dmServer.Qgetdata.Close;
dmServer.Qgetdata.SQL.Clear;
dmServer.Qgetdata.SQL.Text:=cmdStr;
dmServer.Qgetdata.MaxRecords:=rcount;
dmServer.CDSgetdata.Active:=false;
dmServer.CDSgetdata.FetchOnDemand:=false;
dmServer.CDSgetdata.PacketRecords:=rcount;
dmServer.CDSgetdata.Active:=True;
Result:=dmServer.CDSgetdata.Data;
finally
dmServer.Qgetdata.Close;
dmServer.Qgetdata.SQL.Clear;
dmServer.Qgetdata.MaxRecords:=0;
dmServer.CDSgetdata.Active:=false;
dmServer.CDSgetdata.PacketRecords:=-1;
end;
finally
LeaveCriticalSection(CL);
end;
end;
保存
function TDataprocess.BsApplyupdate(Delta: OleVariant;
const TableName,
KeyField,UserCode, PCname: WideString): WordBool;
var
i:integer;
s1,s2:String;
Cmdstr:string;
FieldList:TstringList;
Cdsupdate:Tclientdataset;
begin
if VarisNull(delta) then
begin
Result:=null;
Exit;
end;
try
with dmServer.adoConErp do
begin
FieldList:=Tstringlist.Create;
GetFieldNames(Tablename,FieldList);
end;
Cdsupdate:=Tclientdataset.Create(nil);
Cdsupdate.Close;
Cdsupdate.Data:=delta;
if not Cdsupdate.Active then
Cdsupdate.Open;
for i:=1 to fieldList.Count do
if Cdsupdate.FindField(FieldList[i-1])<>nil then
cdsupdate.FindField(FieldList[i-1]).tag:=1;
FieldList.Free;
if CDSupdate.RecordCount>0 then
begin
CDSupdate.First;
s1:='';
s2:='';
while not CDSupdate.Eof do
begin
CmdStr:='';
case Cdsupdate.UpdateStatus of
usUnmodified:
begin
S2:=VartoSql(cdsupdate[keyField]);
end;
usModified:
begin
s1:='';
for i:=1 to CDSupdate.FieldCount do
if (not cdsupdate.Fields[i-1].isNull) and (Cdsupdate.Fields[i-1].tag=1) then
begin
if s1='' then
s1:=Trim(CDSupdate.Fields[i-1].FieldName)+' = '+vartosql(Cdsupdate.Fields[i-1].value)
else
s1:=s1+','+Trim(CDSupdate.Fields[i-1].FieldName)+' = '+vartosql(Cdsupdate.Fields[i-1].value);
end;
if s1<>'' then
begin
CmdStr:=' update '+tablename+' set '+s1+' where '+keyField+' = '+s2;
end;
end;
usInserted:
begin
s1:='';
s2:='';
for i:=1 to Cdsupdate.FieldCount do
if (not Cdsupdate.Fields[i-1].isnull) and (cdsupdate.Fields[i-1].tag=1) then
begin
if s1='' then
begin
s1:=Trim(Cdsupdate.Fields[i-1].FieldName);
s2:=Vartosql(Cdsupdate.Fields[i-1].value);
end
else
begin
s1:=s1+','+Trim(Cdsupdate.Fields[i-1].FieldName);
s2:=s2+','+Vartosql(Cdsupdate.Fields[i-1].value);
end;
end;
if s1<>'' then
begin
CmdStr:=' Insert into '+Tablename+'('+s1+') values('+s2+')';
end;
end;
usDeleted:
begin
s2:=Vartosql(Cdsupdate[keyField]);
CmdStr:='Delete '+tablename+' where '+keyField+'='+s2;
end;
end;
if CmdStr<>'' then
if Execsql(Cmdstr) then
begin
Syslog(TableName,cmdStr,UserCode,PCname);
Result:=True
end
else
begin
Syslog(TableName,cmdStr,UserCode,PCname);
Result:=False;
end;
Cdsupdate.Next;
end;
end;
finally
Cdsupdate.Close;
Cdsupdate.Free;
end;
end;
 
function getsqldata(CDS:Tclientdataset;TableName,keyField:wideString;ssql:wideString;
const Maxrec:integer=20):boolean;
var
TempCDS:TclientDataset;
FkeyValue:String;
Fsql:String;
function SetSql():String;
const SqlFmt='select * from %s%s%s order by %s';
begin
if FkeyValue='' then
begin
Result:=Format(SqlFmt,[Tablename,' where ',ssql,keyField]);
end
else
begin
Result:=Format(sqlFmt,[Tablename,' where ',
keyfield+'>'+#39+FkeyValue+#39+' and '+ssql,keyField]);
end;
end;

begin
ClearCDSData(CDS);
try
TempCDS:=Tclientdataset.Create(nil);
TempCDS.FetchOnDemand:=False;
tempCDS.PacketRecords:=Maxrec;
FkeyValue:='';
while True do
begin
Fsql:=SetSql;
GetDataFormServer(TempCDS,Fsql,MaxRec);
InsertCDSData(TempCDS,CDS);
if TempCDS.RecordCount<MaxRec then
Break;
TempCDS.Last;
FkeyValue:=TempCDS.fieldbyname(keyField).AsString;
ClearCDSdata(TempCDS);
Fsql:='';
Application.ProcessMessages;
end;
finally
TempCDS.Close;
TempCDS.Free();
end;
Result:=True;
end;

function getDataFormServer(ACDS:TclientDataSet;ssql:wideString;const reccount:integer=20):wordbool;
begin
try
ACDS.Data:=dmClient.SocketConnection1.AppServer.GetlargeData(ssql,reccount);
Result:=True;
except
Result:=False;
end;
end;

function insertCDSDATA(s,d:TclientDataset):boolean;
var
V:TbookMark;
begin
Result:=True;
try
V:=D.GetBookmark;
if d.Active then
d.AppendData(S.Data,False)
else
D.Data:=S.Data;
finally
D.GotoBookmark(V);
D.FreeBookmark(V);
end;
end;

function ClearCDSDATA(s:Tclientdataset):boolean;
begin
S.Close;
s.Data:=null;
Result:=True;
end;

function TDataprocess.GetLargeData(const cmdStr: WideString;
Rcount: Integer): OleVariant;
var
CL:TRTLCriticalSection;
begin
try
InitializeCriticalSection(CL);
EnterCriticalSection(CL);
try
dmServer.Qgetdata.Close;
dmServer.Qgetdata.SQL.Clear;
dmServer.Qgetdata.SQL.Text:=cmdStr;
dmServer.Qgetdata.MaxRecords:=rcount;
dmServer.CDSgetdata.Active:=false;
dmServer.CDSgetdata.FetchOnDemand:=false;
dmServer.CDSgetdata.PacketRecords:=rcount;
dmServer.CDSgetdata.Active:=True;
Result:=dmServer.CDSgetdata.Data;
finally
dmServer.Qgetdata.Close;
dmServer.Qgetdata.SQL.Clear;
dmServer.Qgetdata.MaxRecords:=0;
dmServer.CDSgetdata.Active:=false;
dmServer.CDSgetdata.PacketRecords:=-1;
end;
finally
LeaveCriticalSection(CL);
end;
end;
保存
function TDataprocess.BsApplyupdate(Delta: OleVariant;
const TableName,
KeyField,UserCode, PCname: WideString): WordBool;
var
i:integer;
s1,s2:String;
Cmdstr:string;
FieldList:TstringList;
Cdsupdate:Tclientdataset;
begin
if VarisNull(delta) then
begin
Result:=null;
Exit;
end;
try
with dmServer.adoConErp do
begin
FieldList:=Tstringlist.Create;
GetFieldNames(Tablename,FieldList);
end;
Cdsupdate:=Tclientdataset.Create(nil);
Cdsupdate.Close;
Cdsupdate.Data:=delta;
if not Cdsupdate.Active then
Cdsupdate.Open;
for i:=1 to fieldList.Count do
if Cdsupdate.FindField(FieldList[i-1])<>nil then
cdsupdate.FindField(FieldList[i-1]).tag:=1;
FieldList.Free;
if CDSupdate.RecordCount>0 then
begin
CDSupdate.First;
s1:='';
s2:='';
while not CDSupdate.Eof do
begin
CmdStr:='';
case Cdsupdate.UpdateStatus of
usUnmodified:
begin
S2:=VartoSql(cdsupdate[keyField]);
end;
usModified:
begin
s1:='';
for i:=1 to CDSupdate.FieldCount do
if (not cdsupdate.Fields[i-1].isNull) and (Cdsupdate.Fields[i-1].tag=1) then
begin
if s1='' then
s1:=Trim(CDSupdate.Fields[i-1].FieldName)+' = '+vartosql(Cdsupdate.Fields[i-1].value)
else
s1:=s1+','+Trim(CDSupdate.Fields[i-1].FieldName)+' = '+vartosql(Cdsupdate.Fields[i-1].value);
end;
if s1<>'' then
begin
CmdStr:=' update '+tablename+' set '+s1+' where '+keyField+' = '+s2;
end;
end;
usInserted:
begin
s1:='';
s2:='';
for i:=1 to Cdsupdate.FieldCount do
if (not Cdsupdate.Fields[i-1].isnull) and (cdsupdate.Fields[i-1].tag=1) then
begin
if s1='' then
begin
s1:=Trim(Cdsupdate.Fields[i-1].FieldName);
s2:=Vartosql(Cdsupdate.Fields[i-1].value);
end
else
begin
s1:=s1+','+Trim(Cdsupdate.Fields[i-1].FieldName);
s2:=s2+','+Vartosql(Cdsupdate.Fields[i-1].value);
end;
end;
if s1<>'' then
begin
CmdStr:=' Insert into '+Tablename+'('+s1+') values('+s2+')';
end;
end;
usDeleted:
begin
s2:=Vartosql(Cdsupdate[keyField]);
CmdStr:='Delete '+tablename+' where '+keyField+'='+s2;
end;
end;
if CmdStr<>'' then
if Execsql(Cmdstr) then
begin
Syslog(TableName,cmdStr,UserCode,PCname);
Result:=True
end
else
begin
Syslog(TableName,cmdStr,UserCode,PCname);
Result:=False;
end;
Cdsupdate.Next;
end;
end;
finally
Cdsupdate.Close;
Cdsupdate.Free;
end;
end;
 
顶部