|
@@ -20,7 +20,6 @@ type
|
|
|
TLoginType = (ltCon, ltDisCon, ltLoginFail, ltUpdate, ltIncomplete);
|
|
|
|
|
|
TPHPWeb = class(TDataModule)
|
|
|
- IdHTTP: TIdHTTP;
|
|
|
procedure DataModuleCreate(Sender: TObject);
|
|
|
private
|
|
|
// 远程服务器上时间
|
|
@@ -91,7 +90,7 @@ type
|
|
|
function UpDataFile(AUserID, ATenderID, APhaseNo: Integer; AFile, AMD5_JL: string;
|
|
|
AIsSubmit: Boolean; var AResultStr: string; ACheckPassed: Boolean; ACheckerMemo: string): Boolean;
|
|
|
|
|
|
- function UpAttachment(AUperID, AWebID, ABillID, APhase: Integer; AFile, ACategory, AMemo: string; var ANewFileName: string): Boolean;
|
|
|
+ function UpAttachment(AUperID, AWebID, ABillID, APhase: Integer; AFile, ACategory, AMemo: string; var ANewFileName, AFileID: string): Boolean;
|
|
|
function UpAttachmentOnLine(AWebID, ABillID, APhase: Integer; AIDAry: array of string): Boolean;
|
|
|
function DeleteAttachment(AFileID: Integer): Integer;
|
|
|
function GetAttachmentList(AWebID: Integer; var vArr: TOVArr): Boolean;
|
|
@@ -143,7 +142,7 @@ implementation
|
|
|
|
|
|
uses
|
|
|
MD5Unit, IdMultipartFormData, VCLUnZip, VCLZip,
|
|
|
- IniFiles, Forms, UtilMethods, Variants, ConstUnit{, Controls, Windows};
|
|
|
+ IniFiles, Forms, UtilMethods, Variants, ConstUnit, ScUtils;{, Controls, Windows}
|
|
|
|
|
|
var g_PHPWeb: TPHPWeb;
|
|
|
|
|
@@ -292,6 +291,7 @@ var
|
|
|
sResult, sURL: string;
|
|
|
J: TCslJson;
|
|
|
sZipMD5: string;
|
|
|
+ vIdHttp: TIdHTTP;
|
|
|
begin
|
|
|
Result := False;
|
|
|
|
|
@@ -328,12 +328,13 @@ begin
|
|
|
|
|
|
IdDataStream.Position := 0;
|
|
|
try
|
|
|
- sResult := IdHTTP.Post(sURL, IdDataStream);
|
|
|
+ sResult := vIdHTTP.Post(sURL, IdDataStream);
|
|
|
except
|
|
|
Abort;
|
|
|
end;
|
|
|
finally
|
|
|
IdDataStream.Free;
|
|
|
+ vIdHttp.Free;
|
|
|
DeleteFile(AFile);
|
|
|
end;
|
|
|
|
|
@@ -406,13 +407,14 @@ var
|
|
|
vStream: TMemoryStream;
|
|
|
iFlag: Integer;
|
|
|
bOK: Boolean;
|
|
|
+ vIdHTTP: TIdHTTP;
|
|
|
|
|
|
procedure SafeDownFile(ASourceURL: string; var ALocalFile: string);
|
|
|
begin
|
|
|
Inc(iFlag);
|
|
|
bOK := False;
|
|
|
try
|
|
|
- IdHTTP.Get(ASourceURL, vStream);
|
|
|
+ vIdHTTP.Get(ASourceURL, vStream);
|
|
|
vStream.SaveToFile(ALocalFile);
|
|
|
bOK := True;
|
|
|
except
|
|
@@ -431,6 +433,7 @@ begin
|
|
|
DeleteFile(ALocalFile);
|
|
|
|
|
|
vStream := TMemoryStream.Create;
|
|
|
+ vIdHTTP := TIdHTTP.Create(nil);
|
|
|
try
|
|
|
while (not bOK) and (iFlag < 3) do // 尝试3次
|
|
|
SafeDownFile(ASourceURL, ALocalFile);
|
|
@@ -438,6 +441,7 @@ begin
|
|
|
Result := bOK;
|
|
|
finally
|
|
|
vStream.Free;
|
|
|
+ vIdHTTP.Free;
|
|
|
end;
|
|
|
end;
|
|
|
|
|
@@ -450,22 +454,23 @@ var
|
|
|
ssResponse: TStringStream;
|
|
|
bDone: Boolean;
|
|
|
vJson: TCslJson;
|
|
|
+ vIdHTTP: TIdHTTP;
|
|
|
begin
|
|
|
Result := -1;
|
|
|
postList := TStringList.Create;
|
|
|
ssResponse := TStringStream.Create('');
|
|
|
+ vIdHTTP := TIdHTTP.Create(nil);
|
|
|
try
|
|
|
try
|
|
|
for i := Low(AInFields) to High(AInFields) do
|
|
|
postList.Add(Format('%s=%s', [AInFields[i], AInValues[i]]));
|
|
|
-
|
|
|
- IdHTTP.Post(AURL, postList, ssResponse);
|
|
|
+ vIdHTTP.Post(AURL, postList, ssResponse);
|
|
|
bDone := True;
|
|
|
except
|
|
|
bDone := False;
|
|
|
end;
|
|
|
|
|
|
- if (bDone) and (Pos('200 OK', IdHTTP.ResponseText) <> 0) then // 网络已通
|
|
|
+ if (bDone) and (Pos('200 OK', vIdHTTP.ResponseText) <> 0) then // 网络已通
|
|
|
begin
|
|
|
vJson := TCslJson.Create;
|
|
|
try
|
|
@@ -527,6 +532,7 @@ begin
|
|
|
finally
|
|
|
postList.Free;
|
|
|
ssResponse.Free;
|
|
|
+ vIdHTTP.Free;
|
|
|
end;
|
|
|
end;
|
|
|
|
|
@@ -606,12 +612,13 @@ begin
|
|
|
end;
|
|
|
|
|
|
function TPHPWeb.UpAttachment(AUperID, AWebID, ABillID, APhase: Integer; AFile,
|
|
|
- ACategory, AMemo: string; var ANewFileName: string): Boolean;
|
|
|
+ ACategory, AMemo: string; var ANewFileName, AFileID: string): Boolean;
|
|
|
var
|
|
|
vMPFDS: TIdMultiPartFormDataStream;
|
|
|
sResult, sURL: string;
|
|
|
J: TCslJson;
|
|
|
vArr: array of string;
|
|
|
+ vIdHTTP: TIdHTTP;
|
|
|
begin
|
|
|
Result := False;
|
|
|
|
|
@@ -622,9 +629,18 @@ begin
|
|
|
end;
|
|
|
|
|
|
vMPFDS := TIdMultiPartFormDataStream.Create;
|
|
|
+ vIdHTTP := TIdHTTP.Create(nil);
|
|
|
try
|
|
|
sURL := Format('%stender/attachment/%d/%d/upload', [FMeasureURL, AWebID, AUperID]);
|
|
|
- vMPFDS.AddFile('upitem', AFile, 'text/plain');
|
|
|
+
|
|
|
+ // 如果文件已被打开,这里会报错。
|
|
|
+ try
|
|
|
+ vMPFDS.AddFile('upitem', AFile, 'text/plain');
|
|
|
+ except
|
|
|
+ MessageHint(0, '当前文件处于打开状态,请关闭文件,重新上传。');
|
|
|
+ Exit;
|
|
|
+ end;
|
|
|
+
|
|
|
vMPFDS.AddFormField('itemid', IntToStr(ABillID));
|
|
|
vMPFDS.AddFormField('category', ACategory);
|
|
|
vMPFDS.AddFormField('memo', ReplaceCharsForJson(AMemo));
|
|
@@ -632,12 +648,13 @@ begin
|
|
|
|
|
|
vMPFDS.Position := 0;
|
|
|
try
|
|
|
- sResult := IdHTTP.Post(sURL, vMPFDS);
|
|
|
+ sResult := vIdHTTP.Post(sURL, vMPFDS);
|
|
|
except
|
|
|
Abort;
|
|
|
end;
|
|
|
finally
|
|
|
vMPFDS.Free;
|
|
|
+ vIdHTTP.Free;
|
|
|
end;
|
|
|
|
|
|
J := TCslJson.Create;
|
|
@@ -646,9 +663,10 @@ begin
|
|
|
if SameText(J.Value['status'], 'true') then
|
|
|
begin
|
|
|
Result := True;
|
|
|
- vArr := VarArrayOf(['onlinefilename']);
|
|
|
+ vArr := VarArrayOf(['onlinefilename', 'imnid']);
|
|
|
J.ChildValues('iteminfo', vArr);
|
|
|
ANewFileName := vArr[0];
|
|
|
+ AFileID := vArr[1];
|
|
|
end
|
|
|
else
|
|
|
begin
|