Q
QDseashore
Unregistered / Unconfirmed
GUEST, unregistred user!
const
BufSize=$F000;
var
strSQL:String;
qrySave:TADOQuery;
bExist:Boolean;
iSize,iBlock:Integer;
aFStream:TFileStream;
aStream:TStream;
BufferAnsiChar;
begin
inherited;
//初时化认为记录不存在
bExist:=False;
rlprgrsbrMain.Position:=0;
//检测文件路径
if Trim(edtFileName.Text)='' then
begin
gcf_MsgBox('请选择要更新的文件及程序!',0,Handle);
Exit;
end;
//检测文件MD5值是否存在
if Trim(lblMD5.Caption)='' then
begin
gcf_MsgBox('获取文件MD5值失败,请重新操作!',0,Handle);
Exit;
end;
//检测是否获取到应用程序明
if Trim(edtName.Text)='' then
begin
gcf_MsgBox('获取文件名失败,请重新操作!',0,Handle);
Exit;
end;
//将文件以文件流对象打开.
aFStream:=TFileStream.Create(Trim(edtFileName.Text),fmOpenRead or fmShareDenyNone);
qrySave:=TADOQuery.Create(nil);
try
//查询数据库
strSQL:='Select * from ' + DEF_UPDATETABLE + ' where FileName=' + quotedstr(edtName.Text);
if qrySave.Active then qrySave.Close;
qrySave.SQl.Clear;
qrySave.ConnectionString:=gConStr;
qrySave.SQL.Add(strSQL);
qrySave.Open;
//有此文件名
if Not qrySave.IsEmpty then
begin
bExist:=True;
qrySave.First;
qrySave.Edit;
end else begin
qrySave.Append;
end;
if bExist then
begin
//比较原文件MD5值,不同则更新
if not gcf_GetFileMD5Math(Trim(edtFileName.Text),qrySave.FieldByName('FileID').AsString) then
begin
//数据流字段
TBlobField(qrySave.FieldByName('FileData')).LoadFromStream(aFStream);
//将ADO写入的流赋给aStream流
aStream:=qrySave.CreateBlobStream(qrySave.FieldByName('FileData'),bmWrite);
//将文件大小放置到iSize中
iSize:=aFStream.Size;
//进度条初始化
rlprgrsbrMain.Min:=0;
rlprgrsbrMain.Max:=iSize div BufSize;
while iSize<>0 do
begin
//调整拷贝块的大小
if iSize>BufSize then
begin
iBlock:=BufSize;
end else begin
iBlock:=iSize;
end;
//文件流写入缓冲读取缓冲
aFStream.ReadBuffer(Buffer^,iBlock);
//从缓冲读取写入流
aStream.WriteBuffer(Buffer^,iBlock);
//依次递减
Dec(iSize,iBlock);
rlprgrsbrMain.Position:=rlprgrsbrMain.Position+1;
end;
end;
end else begin
//数据流字段
TBlobField(qrySave.FieldByName('FileData')).LoadFromStream(aFStream);
//将ADO写入的流赋给aStream流
aStream:=qrySave.CreateBlobStream(qrySave.FieldByName('FileData'),bmWrite);
//将文件大小放置到iSize中
iSize:=aFStream.Size;
//进度条初始化
rlprgrsbrMain.Min:=0;
rlprgrsbrMain.Max:=iSize div BufSize;
while iSize<>0 do
begin
//调整拷贝块的大小
if iSize>BufSize then
begin
iBlock:=BufSize;
end else begin
iBlock:=iSize;
end;
//文件流写入缓冲读取缓冲
aFStream.ReadBuffer(Buffer^,iBlock);
//从缓冲读取写入流
aStream.WriteBuffer(Buffer^,iBlock);
//依次递减
Dec(iSize,iBlock);
rlprgrsbrMain.Position:=rlprgrsbrMain.Position+1;
end;
end;
qrySave.FieldByName('FileName').AsString:=Trim(edtName.Text);
qrySave.FieldByName('FileID').AsString:=Trim(lblMD5.Caption);
qrySave.FieldByName('RegDate').AsString:=Trim(lblFileDate.Caption);
qrySave.FieldByName('FileSourcePath').AsString:=Trim(edtFileName.Text);
qrySave.FieldByName('FileSize').AsString:=Trim(lblFileSize.Caption);
qrySave.FieldByName('Remark').AsString:=Trim(mmoMain.Text);
if chkEnabled.Checked then qrySave.FieldByName('Status').AsInteger:=1 else qrySave.FieldByName('Status').AsInteger:=0;
//保存数据
if qrySave.State in [dsInsert,dsEdit] then qrySave.Post;
//刷新树
gcp_DrawfcTreeView(fctrvwMain,'','FileName',
VarArrayOf([DEF_BSEPCHAR,'','','','','',DEF_ESEPCHAR]),VarArrayOf(['FileName','FileID','FileSize','RegDate','Status','FileSourcePath','Remark']),'','',gConStr,
'Select * from ' + DEF_UPDATETABLE,tvctNone,0,1);
gcf_MsgBox('更新成功!',0,Handle);
finally
qrySave.Free;
end;
BufSize=$F000;
var
strSQL:String;
qrySave:TADOQuery;
bExist:Boolean;
iSize,iBlock:Integer;
aFStream:TFileStream;
aStream:TStream;
BufferAnsiChar;
begin
inherited;
//初时化认为记录不存在
bExist:=False;
rlprgrsbrMain.Position:=0;
//检测文件路径
if Trim(edtFileName.Text)='' then
begin
gcf_MsgBox('请选择要更新的文件及程序!',0,Handle);
Exit;
end;
//检测文件MD5值是否存在
if Trim(lblMD5.Caption)='' then
begin
gcf_MsgBox('获取文件MD5值失败,请重新操作!',0,Handle);
Exit;
end;
//检测是否获取到应用程序明
if Trim(edtName.Text)='' then
begin
gcf_MsgBox('获取文件名失败,请重新操作!',0,Handle);
Exit;
end;
//将文件以文件流对象打开.
aFStream:=TFileStream.Create(Trim(edtFileName.Text),fmOpenRead or fmShareDenyNone);
qrySave:=TADOQuery.Create(nil);
try
//查询数据库
strSQL:='Select * from ' + DEF_UPDATETABLE + ' where FileName=' + quotedstr(edtName.Text);
if qrySave.Active then qrySave.Close;
qrySave.SQl.Clear;
qrySave.ConnectionString:=gConStr;
qrySave.SQL.Add(strSQL);
qrySave.Open;
//有此文件名
if Not qrySave.IsEmpty then
begin
bExist:=True;
qrySave.First;
qrySave.Edit;
end else begin
qrySave.Append;
end;
if bExist then
begin
//比较原文件MD5值,不同则更新
if not gcf_GetFileMD5Math(Trim(edtFileName.Text),qrySave.FieldByName('FileID').AsString) then
begin
//数据流字段
TBlobField(qrySave.FieldByName('FileData')).LoadFromStream(aFStream);
//将ADO写入的流赋给aStream流
aStream:=qrySave.CreateBlobStream(qrySave.FieldByName('FileData'),bmWrite);
//将文件大小放置到iSize中
iSize:=aFStream.Size;
//进度条初始化
rlprgrsbrMain.Min:=0;
rlprgrsbrMain.Max:=iSize div BufSize;
while iSize<>0 do
begin
//调整拷贝块的大小
if iSize>BufSize then
begin
iBlock:=BufSize;
end else begin
iBlock:=iSize;
end;
//文件流写入缓冲读取缓冲
aFStream.ReadBuffer(Buffer^,iBlock);
//从缓冲读取写入流
aStream.WriteBuffer(Buffer^,iBlock);
//依次递减
Dec(iSize,iBlock);
rlprgrsbrMain.Position:=rlprgrsbrMain.Position+1;
end;
end;
end else begin
//数据流字段
TBlobField(qrySave.FieldByName('FileData')).LoadFromStream(aFStream);
//将ADO写入的流赋给aStream流
aStream:=qrySave.CreateBlobStream(qrySave.FieldByName('FileData'),bmWrite);
//将文件大小放置到iSize中
iSize:=aFStream.Size;
//进度条初始化
rlprgrsbrMain.Min:=0;
rlprgrsbrMain.Max:=iSize div BufSize;
while iSize<>0 do
begin
//调整拷贝块的大小
if iSize>BufSize then
begin
iBlock:=BufSize;
end else begin
iBlock:=iSize;
end;
//文件流写入缓冲读取缓冲
aFStream.ReadBuffer(Buffer^,iBlock);
//从缓冲读取写入流
aStream.WriteBuffer(Buffer^,iBlock);
//依次递减
Dec(iSize,iBlock);
rlprgrsbrMain.Position:=rlprgrsbrMain.Position+1;
end;
end;
qrySave.FieldByName('FileName').AsString:=Trim(edtName.Text);
qrySave.FieldByName('FileID').AsString:=Trim(lblMD5.Caption);
qrySave.FieldByName('RegDate').AsString:=Trim(lblFileDate.Caption);
qrySave.FieldByName('FileSourcePath').AsString:=Trim(edtFileName.Text);
qrySave.FieldByName('FileSize').AsString:=Trim(lblFileSize.Caption);
qrySave.FieldByName('Remark').AsString:=Trim(mmoMain.Text);
if chkEnabled.Checked then qrySave.FieldByName('Status').AsInteger:=1 else qrySave.FieldByName('Status').AsInteger:=0;
//保存数据
if qrySave.State in [dsInsert,dsEdit] then qrySave.Post;
//刷新树
gcp_DrawfcTreeView(fctrvwMain,'','FileName',
VarArrayOf([DEF_BSEPCHAR,'','','','','',DEF_ESEPCHAR]),VarArrayOf(['FileName','FileID','FileSize','RegDate','Status','FileSourcePath','Remark']),'','',gConStr,
'Select * from ' + DEF_UPDATETABLE,tvctNone,0,1);
gcf_MsgBox('更新成功!',0,Handle);
finally
qrySave.Free;
end;