| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- unit csCommon;
- interface
- uses
- SOAPHTTPClient, IdMultipartFormData,
- IdHttp, Forms, Windows, csConfigInfo,
- ShellAPI, csProj;
- procedure InitHttpRioWSDL(AHttpRio: THTTPRIO);
- procedure Upload(AIdHttp: TIdHTTP; const AZipFile, AURL: string);
- procedure CreateDirIfNotExists(const ADir: string);
- function DeleteFiles(const AFilePath: string): Boolean;
- implementation
- uses SysUtils;
- procedure InitHttpRioWSDL(AHttpRio: THTTPRIO);
- begin
- AHttpRio.WSDLLocation := IntfConfig.WSDL;
- AHttpRio.Service := 'CostService';
- AHttpRio.Port := 'CostServiceHttpSoap11Endpoint';
- end;
- procedure Upload(AIdHttp: TIdHTTP; const AZipFile, AURL: string);
- procedure HintSucessOrFailed(const AText: string);
- var
- iPos: Integer;
- begin
- iPos := Pos(';', AText);
- if iPos > 0 then
- begin
- if Copy(AText, 1, iPos - 1) = 'true' then
- begin
- Application.MessageBox('文件上传成功! ', '提示', MB_OK + MB_ICONINFORMATION);
- csCurProj.ProjBatID := Copy(AText, iPos + 1, Length(AText) - iPos);
- end
- else
- begin
- Application.MessageBox('文件上传失败! ', '提示', MB_OK + MB_ICONWARNING);
- csCurProj.ProjBatID := '';
- end;
- end
- else
- begin
- if AText = 'true' then
- Application.MessageBox('文件上传成功! ', '提示', MB_OK + MB_ICONINFORMATION)
- else
- Application.MessageBox('文件上传失败! ', '提示', MB_OK + MB_ICONWARNING);
- end;
- end;
- procedure AddFormFields(
- AIdDataStream: TIdMultiPartFormDataStream; AZipFile: string);
- begin
- AIdDataStream.AddFormField('files', AZipFile);
- AIdDataStream.AddFormField('Submit', 'Submit');
- //AIdDataStream.AddFile('files', AZipFile, 'multipart/form-data');
- AIdDataStream.AddFile('files', AZipFile, 'text/plain');
- end;
- procedure UpLoadZipFile(
- AIdDataStream: TIdMultiPartFormDataStream; AURL: string);
- begin
- try
- AIdDataStream.Position := 0;
- HintSucessOrFailed(AIdHTTP.Post(AURL, AIdDataStream));
- except
- Application.MessageBox('远程服务器连接失败!', '提示', MB_OK + MB_ICONWARNING);
- end;
- end;
- var
- IdDataStream: TIdMultiPartFormDataStream;
- begin
- IdDataStream := TIdMultiPartFormDataStream.Create;
- try
- AddFormFields(IdDataStream, AZipFile);
- UpLoadZipFile(IdDataStream, AURL);
- finally
- IdDataStream.Free;
- end;
- end;
- procedure CreateDirIfNotExists(const ADir: string);
- begin
- if not DirectoryExists(ADir) then
- ForceDirectories(ADir);
- end;
- function DeleteFiles(const AFilePath: string): Boolean;
- var
- Fo: TSHFileOpStruct;
- begin
- FillChar(Fo, SizeOf(fo), 0);
- with Fo do
- begin
- Wnd := 0;
- wFunc := FO_DELETE;
- pFrom := PChar(AFilePath + #0);
- pTo := #0#0;
- fFlags := FOF_NOCONFIRMATION + FOF_SILENT;
- end;
- Result := (SHFileOperation(Fo) = 0); // 成功返回0
- end;
- end.
-
|