Midas公文包模式下的数据刷新问题(100分)

  • 主题发起人 主题发起人 Yuanqi
  • 开始时间 开始时间
Y

Yuanqi

Unregistered / Unconfirmed
GUEST, unregistred user!
我在一个项目中采用公文包模式开发数据库应用。思路是这样的,平时的大部分的输入和
修改操作放在客户端的Midas公文包里进行,之后连上服务器,把客户端的数据批量上传。
同时,连上服务器后顺便对客户端公文包数据进行刷新。由于客户端和服务器端之间的网
速很慢,而它们之间的数据大部分是相同的,因此我只想将一定范围之内(如一段时间内)
的数据进行刷新,而这个范围外的数据保存在客户端不变(不需要从Server上重新下载而且仍保留在Client
端的公文包里)。我原来想先把要刷新的数据从公文包里删除,再从Server上下载相应数据
Append到客户端的ClientDataSet里。但Server和Client间的网络不稳定,有时会下载一半
时出错。于是我尝试将原来的老数据保存在临时表里,如果出错就倒回去。但我觉得可能
会有更好的办法,不知各位大虾有没有什么好的思路,奉上银子100两,希望可以抛“银”
引玉:)
 
用临时的clientdataset下数据,然后把DATA传一下不就得了?
 
您的回答好象没有跟我的没什么两样,
 
可以在服务端给你要下载的数据设置一个版本号, 如 1.3.1, 1.3.2, 1.4.1, ...
客户端查询服务端, 发现数据版本不同时, 可以根据需要下载.
 
because your network condition is very poor, u may compress data in application
server and transfer to client. in client decompree the package, if successfully
then
load the flat file to clientdataset.
 
用李维的这个方法吧!
新的CLIENTDATASET。
unit FTClientDataSet;
{$R-}
interface
uses Windows, SysUtils, ActiveX, Graphics, Classes, Controls, Forms, Db,
BDE, DSIntf, DBCommon, StdVcl, DBClient;
type
TFTClientDataSet = class(TClientDataSet)
private
FSaveAllRecords : Boolean;
FOpeningFile: Boolean;
protected
procedure WriteDataPacket(Stream: TStream;
WriteSize: Boolean;
XMLFormat: Boolean = False);
procedure CheckProviderEOF;
procedure FetchMoreData(All: Boolean);
procedure SaveDataPacket(XMLFormat: Boolean = False);
procedure ClearSavedPacket;
procedure SaveToStream(Stream: TStream;
Format: TDataPacketFormat = dfBinary);
public
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
procedure SaveToFile(const FileName: string = 'TmpDataFile.dat';
Format: TDataPacketFormat = dfBinary);
procedure LoadFromFile(const FileName: string = 'TmpDataFile.dat');
published
property SaveAllRecords : Boolean read FSaveAllRecords write FSaveAllRecords default False;
end;

procedure Register;
implementation
uses DBConsts, MidConst, ComObj, Provider, TypInfo;

procedure Register;
begin
RegisterComponents('龟驹Delphi 5', [TFTClientDataSet]);
end;

constructor TFTClientDataSet.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FSaveAllRecords := False;
FOpeningFile := False;
end;

destructor TFTClientDataSet.Destroy;
begin
inherited Destroy;
end;

procedure TFTClientDataSet.FetchMoreData(All: Boolean);
var
Count: Integer;
RecsOut: Integer;
begin
if All then
Count := AllRecords else
Count := PacketRecords;
if Count = 0 then
Exit;
AddDataPacket(DoGetRecords(Count, RecsOut, 0, '', Unassigned), RecsOut <> Count);
ProviderEOF := RecsOut <> Count;
end;

procedure TFTClientDataSet.CheckProviderEOF;
begin
if HasAppServer and not ProviderEOF and FetchOnDemand and (PacketRecords <> 0) then
FetchMoreData(True);
end;

procedure TFTClientDataSet.SaveDataPacket(XMLFormat: Boolean = False);
const
StreamMode: array[Boolean] of DWord = (xmlOFF, xmlON);
var
DataPacket: TDataPacket;
begin
DataPacket := VarToDataPacket(Data);
if Assigned(DSBase) and (DataSetField = nil) then
begin
DSBase.SetProp(dspropXML_STREAMMODE, StreamMode[XMLFormat]);
ClearSavedPacket;
Check(DSBase.StreamDS(DataPacket));
end;
end;

procedure TFTClientDataSet.ClearSavedPacket;
var
DataPacket: TDataPacket;
begin
DataPacket := VarToDataPacket(Delta);
FreeDataPacket(DataPacket);
end;

procedure TFTClientDataSet.WriteDataPacket(Stream: TStream;
WriteSize: Boolean;
XMLFormat: Boolean = False);
var
Size: Integer;
DataPtr: Pointer;
begin
if Active then
begin
CheckBrowseMode;
if (FSaveAllRecords) then
CheckProviderEOF;
SaveDataPacket(XMLFormat);
end;
if Assigned(VarToDataPacket(Data)) then
begin
Size := DataPacketSize(VarToDataPacket(Data));
SafeArrayAccessData(VarToDataPacket(Data), DataPtr);
try
if WriteSize then
Stream.Write(Size, SizeOf(Size));
Stream.Write(DataPtr^, Size);
finally
SafeArrayUnAccessData(VarToDataPacket(Data));
end;
if Active then
ClearSavedPacket;
end;
end;

procedure TFTClientDataSet.SaveToStream(Stream: TStream;
Format: TDataPacketFormat = dfBinary);
begin
WriteDataPacket(Stream, False, (Format=dfXML));
end;

procedure TFTClientDataSet.SaveToFile(const FileName: string = 'TmpDataFile.dat';
Format: TDataPacketFormat = dfBinary);
var
Stream: TStream;
begin
if FileName = '' then
Stream := TFileStream.Create(Self.FileName, fmCreate) else
Stream := TFileStream.Create(FileName, fmCreate);
try
if LowerCase(ExtractFileExt(FileName)) = '.xml' then
Format := dfXML;
SaveToStream(Stream, Format);
finally
Stream.Free;
end;
end;

procedure TFTClientDataSet.LoadFromFile(const FileName: string);
var
Stream: TStream;
begin
Close;
if FileName = '' then
Stream := TFileStream.Create(Self.FileName, fmOpenRead) else
Stream := TFileStream.Create(FileName, fmOpenRead);
try
FOpeningFile := True;
try
LoadFromStream(Stream);
finally
FOpeningFile := False;
end;
finally
Stream.Free;
end;
end;

end.
 
主要问题是:
Server和Client间的网络不稳定,有时会下载一半时出错。于是我尝试将老数据保存在临时表里,如果出错就倒回去。
可能会有更好的办法,不知各位大虾有没有什么好的思路??
 
哎...我真是"皇帝不急太监急"
 
maming真是个好同志,而且打字飞快。
 
哦,哈哈,谢谢夸奖啦!
我也是COPY啊!不知那问题解决了没有。
 
后退
顶部