ProjectCommands.pas 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. unit ProjectCommands;
  2. interface
  3. uses
  4. ProjectData, XMLDoc, XMLIntf, ProjectManagerDm, sdIDTree, sdDB,
  5. Connections;
  6. type
  7. {1. 生成临时文件夹
  8. 2. 打开项目
  9. 3. 修改项目(上报、批复相应修改)
  10. 4. 保存修改后项目的属性至xml文件
  11. 5. 保存项目至临时文件夹中
  12. 6. 压缩临时文件夹,得到上报、批复文件
  13. 7. 复制粘贴结果文件得用户选择
  14. 8. 删除临时文件夹}
  15. TReportBase = class
  16. private
  17. // 临时文件夹(生成的项目文件、xml属性文件)
  18. FTempFolder: string;
  19. FProjectName: string;
  20. FFileName: string;
  21. FProjectID: Integer;
  22. FProjectData: TProjectData;
  23. FFileType: string;
  24. // xml项目信息文件
  25. FXmlInfoFile: string;
  26. // 结果文件
  27. FResultFile: string;
  28. // 接收文件时是否需要升级文件
  29. FNeedUpdate: Boolean;
  30. procedure SaveProjectInfo(AXmlNode: IXMLNode);
  31. procedure SaveTenderProperty(AXmlNode: IXMLNode);
  32. procedure SaveInfoToXmlDocument(AXmlNode: IXMLNode);
  33. procedure ExportXmlInfo;
  34. function GetNewOutputFileName: string;
  35. function CheckFile(const AFileName: string): Boolean;
  36. protected
  37. procedure OpenProject; virtual;
  38. procedure SaveProject; virtual;
  39. public
  40. constructor Create(const AProjectName, AFileName: string; AProjectID: Integer);
  41. destructor Destroy; override;
  42. function Execute: Boolean; virtual;
  43. function ExportTo(AFileName: string): Boolean; virtual;
  44. end;
  45. TSubmitProject = class(TReportBase)
  46. protected
  47. procedure OpenProject; override;
  48. procedure SaveProject; override;
  49. public
  50. function Execute: Boolean; override;
  51. function ExportTo(AFileName: string): Boolean; override;
  52. end;
  53. TReplyProject = class(TReportBase)
  54. protected
  55. procedure OpenProject; override;
  56. procedure SaveProject; override;
  57. public
  58. function Execute: Boolean; override;
  59. function ExportTo(AFileName: string): Boolean; override;
  60. end;
  61. {1. 生成临时文件夹
  62. 2. 解压选中文件至临时文件夹
  63. 3. 读取xml信息文件中的数据
  64. 4. 检查同名项目,存在则备份原项目,不存在则创建新节点
  65. 5. 根据xml文件更新数据项目信息,标段属性
  66. 6. 从临时文件夹中复制粘贴项目文件至新节点的数据文件
  67. 7. 打开该数据文件,根据情况修改
  68. 8. 保存该数据文件
  69. 9. 删除临时文件夹}
  70. TReceiveProject = class
  71. private
  72. FTempFolder: string;
  73. FFileType: string;
  74. FXmlDocument: IXMLDocument;
  75. // 导入后的节点
  76. FCurNode: TsdIDTreeNode;
  77. FProjectName: string;
  78. FFileName: string;
  79. FSelect: TsdIDTreeNode;
  80. FProjectData: TProjectData;
  81. // 初次在线审批人,自上次Exe上报/审批
  82. FStartAudit: Integer;
  83. // 末次在线审批人,自上次Exe上报/审批
  84. FEndAudit: Integer;
  85. // 文件中的审核状态
  86. FOrgAuditStatus: Integer;
  87. // 应升级至的审核状态
  88. FNewAuditStatus: Integer;
  89. FStageCount: Integer;
  90. FReply: Boolean;
  91. FLostStageCount: Integer;
  92. // 控制是否需要升级更新文件
  93. FNeedUpdate: Boolean;
  94. FLock: Boolean;
  95. FMessageID: Integer;
  96. FIsReback: Boolean;
  97. FWebBidName: string;
  98. function CheckOpen: Boolean;
  99. function GetNewTender: TsdIDTreeNode;
  100. procedure GetCurNode;
  101. procedure LoadProjectInfo(AXmlNode: IXMLNode);
  102. procedure LoadTenderProperty(AXmlNode: IXMLNode);
  103. procedure LoadInfoFromXmlDocument;
  104. function CheckUpdateStatusValid: Boolean;
  105. procedure ReadXmlInfo;
  106. function UpdateData(const AFileName: string): Boolean;
  107. procedure SetWebBidName(const Value: string);
  108. public
  109. constructor Create(ASelect: TsdIDTreeNode);
  110. destructor Destroy; override;
  111. function Receive(const AFileName: string): TsdIDTreeNode;
  112. // 在线审批使用
  113. // 原报、1审(Online)、2审(Online)、3审(Online)、4审、5审(Online)、6审、7审
  114. // 则4审在Exe端打开项目时,AStartAudit=1,AEndAudit=3
  115. // 6审在Exe端打开项目时,AStartAudit=AEndAudit=5
  116. // 7审在Exe端打开项目时,AStartAudit=AEndAudit=0
  117. function ReceiveForLost(const AFileName: string; AStartAudit, AEndAudit: Integer; AReply: Boolean = False): TsdIDTreeNode;
  118. // 供网络版使用
  119. // 原报已提交,1审已审核并提交后,此时除了2审人以外的参与人接收数据时不可生成二审数据
  120. property Lock: Boolean read FLock write FLock;
  121. // 被打回的数据
  122. property IsReback: Boolean read FIsReback write FIsReback;
  123. // 信息: 0[接收成功]
  124. // 1[接收失败,应接收节点打开状态]
  125. // 2[接收失败,下载文件跟网页状态不一致]
  126. // 3[接收失败,升级文件失败]
  127. property MessageID: Integer read FMessageID;
  128. // ProjectName 是标段名。之前是读自文件包中的XML文件属性,现在要从线上取。
  129. property WebBidName: string read FWebBidName write SetWebBidName;
  130. end;
  131. {1. 生成临时文件夹
  132. 2. 保存标段的属性至xml文件
  133. 3. 复制粘贴标段文件至临时文件夹
  134. 4. 压缩临时文件夹,得到导出的标段文件(结果文件)
  135. 5. 复制粘贴结果文件得用户选择
  136. 6. 删除临时文件夹}
  137. TTenderExport = class
  138. private
  139. // 临时文件夹(生成的项目文件、xml属性文件)
  140. FTempFolder: string;
  141. FProjectName: string;
  142. FFileName: string;
  143. FProjectID: Integer;
  144. FFileType: string;
  145. // xml项目信息文件
  146. FXmlInfoFile: string;
  147. // 结果文件
  148. FResultFile: string;
  149. FAttachmentPath: string;
  150. procedure SaveProjectInfo(AXmlNode: IXMLNode);
  151. procedure SaveTenderProperty(AXmlNode: IXMLNode);
  152. procedure SaveInfoToXmlDocument(AXmlNode: IXMLNode);
  153. procedure ExportXmlInfo;
  154. public
  155. constructor Create(ARec: TsdDataRecord; const AFileName: string);
  156. destructor Destroy; override;
  157. // 参数AExportAttachment:是否导出附件
  158. procedure Execute(AExportAttachment: Boolean = False);
  159. end;
  160. TTenderImport = class
  161. private
  162. FTempFolder: string;
  163. FSelect: TsdIDTreeNode;
  164. FNewNode: TsdIDTreeNode;
  165. FProjectName: string;
  166. FFileName: string;
  167. FTenderFileName: string;
  168. procedure GetNewNode;
  169. procedure LoadProjectInfo(AXmlNode: IXMLNode);
  170. procedure LoadTenderProperty(AXmlNode: IXMLNode);
  171. procedure LoadInfoFromXmlDocument(AXmlNode: IXMLNode);
  172. procedure LoadXmlInfo;
  173. public
  174. constructor Create(ASelect: TsdIDTreeNode; const AProjectName, AFileName: string);
  175. destructor Destroy; override;
  176. procedure Execute;
  177. procedure ImportToSelect;
  178. end;
  179. {1. 生成临时文件夹
  180. 2. 导出选中节点及其所有子节点信息
  181. 3. 递归所有子节点,分类(Type = 0)则新建同名文件夹,标段(Type = 1)则导出该标段
  182. 4. 压缩临时文件夹,得到导出的分类文件(结果文件)
  183. 5. 复制粘贴结果文件得用户选择
  184. 6. 删除临时文件夹}
  185. TProjectExport = class
  186. private
  187. // 临时文件夹(按层次结构生成所有项目文件)
  188. FTempFolder: string;
  189. // xml树结构文件
  190. FXmlInfoFile: string;
  191. // 结果文件
  192. FResultFile: string;
  193. FExportNode: TsdIDTreeNode;
  194. FTenderExportor: TTenderExport;
  195. FExportAttachment: Boolean;
  196. procedure SaveTreeNodeInfo(AXmlNode: IXMLNode; ANode: TsdIDTreeNode);
  197. procedure ExportXmlInfo;
  198. procedure ExportTender(ANode: TsdIDTreeNode; const AExportPath: string);
  199. procedure ExportNode(ANode: TsdIDTreeNode; const AExportPath: string);
  200. public
  201. constructor Create(ANode: TsdIDTreeNode; const AFileName: string; AExportAttachment: Boolean = False);
  202. destructor Destroy; override;
  203. procedure Execute;
  204. end;
  205. {1. 生成临时文件夹
  206. 2. 解压选中文件至临时文件夹
  207. 3. 根据用户选择新建子分类FNew
  208. 3. 打开Xml树结构信息文件
  209. 4. 根据Xml文件中结构,依次建立分类或导入标段文件
  210. 5. 删除临时文件夹}
  211. TProjectImport = class
  212. private
  213. FTempFolder: string;
  214. FProjectName: string;
  215. FFileName: string;
  216. FSelect: TsdIDTreeNode;
  217. FNew: TsdIDTreeNode;
  218. function AddNewNode(AParentID, ANextID: Integer; const ANodeName: string): TsdIDTreeNode;
  219. procedure LoadTender(AXmlNode: IXMLNode;
  220. AParent: TsdIDTreeNode; const APath: string);
  221. procedure LoadChild(AXmlNode: IXMLNode;
  222. AParent: TsdIDTreeNode; const APath: string);
  223. procedure LoadChildrenFormXml;
  224. public
  225. constructor Create(ASelect: TsdIDTreeNode; const AProjectName, AFileName: string);
  226. destructor Destroy; override;
  227. procedure Execute;
  228. end;
  229. // 文件检验
  230. {
  231. 检验分为两部分:
  232. 1. 一致性检验:检验文件中的xml记录数据,与数据库中数据是否一致,以检验文件是否可用
  233. 2. 主动检验: 提供xml记录的部分数据,用户主动检验是否为所需文件
  234. 流程:
  235. 1. 解压文件,得到xml文件,项目文件
  236. 2. 读取xml文件,得到主要数据,与项目文件名
  237. 3. 读取项目文件,并检验基本数据是否与xml文件中描述一致
  238. PS:用于主动检验的数据,在第2步中同步进行。要求,如果进行主动检验,必须先通过一致性检验。
  239. }
  240. TTenderFileChecker = class
  241. private
  242. FFileName: string;
  243. FTempFolder: string;
  244. FTenderFileName: string;
  245. FTenderTempFolder: string;
  246. FValid: Boolean;
  247. FPhaseCount: Integer;
  248. FAuditStatus: Integer;
  249. FProjectName: string;
  250. procedure LoadProjectInfo(AXmlNode: IXMLNode);
  251. procedure LoadInfoFromXmlDocument(AXmlNode: IXMLNode);
  252. procedure LoadInfoFromXml;
  253. procedure LoadInfo;
  254. function DecryptFile(const AFileName: string): Boolean;
  255. function CheckFileMatchXml: Boolean;
  256. public
  257. // 检验项目数据库数据与xml文件中主要数据是否吻合
  258. function CheckFileValid(const AFileName: string): Boolean;
  259. // xml文件中记录的信息,用于主动检验
  260. property PhaseCount: Integer read FPhaseCount;
  261. property AuditStatus: Integer read FAuditStatus;
  262. end;
  263. TTenderZipCheckType = (zctAllPhase, zctLastPhase);
  264. // 文件检验
  265. TTenderZipCompleteChecker = class
  266. private
  267. FFileName: string;
  268. FTempFolder: string;
  269. FProjectData: TProjectData;
  270. FCheckType: TTenderZipCheckType;
  271. function CheckMain: Boolean;
  272. function CheckAllPhase: Boolean;
  273. function CheckLastPhase: Boolean;
  274. public
  275. constructor Create;
  276. destructor Destroy; override;
  277. function CheckFileValid(const AFileName: string): Boolean;
  278. property CheckType: TTenderZipCheckType read FCheckType write FCheckType;
  279. end;
  280. implementation
  281. uses
  282. UtilMethods, ZhAPI, Globals, SysUtils, SupportUnit, NewProjectFrm,
  283. PhaseData, ConfigDoc, ConstUnit, PHPWebDm;
  284. { TSubmitProject }
  285. function TSubmitProject.Execute: Boolean;
  286. begin
  287. FFileType := '.rmf';
  288. FNeedUpdate := True;
  289. //FProjectData.LockedDataForSubmit;
  290. Result := inherited Execute;
  291. end;
  292. function TSubmitProject.ExportTo(AFileName: string): Boolean;
  293. begin
  294. FNeedUpdate := True;
  295. //FProjectData.LockedDataForSubmit;
  296. Result := inherited ExportTo(AFileName);
  297. end;
  298. procedure TSubmitProject.OpenProject;
  299. begin
  300. FProjectData.OpenForSubmit(FFileName);
  301. end;
  302. procedure TSubmitProject.SaveProject;
  303. begin
  304. FProjectData.SaveAsForSubmit(FTempFolder + '\' + ExtractSimpleFileName(FFileName));
  305. end;
  306. { TReportBase }
  307. constructor TReportBase.Create(const AProjectName, AFileName: string;
  308. AProjectID: Integer);
  309. begin
  310. FProjectName := AProjectName;
  311. FFileName := AFileName;
  312. FProjectID := AProjectID;
  313. FProjectData := TProjectData.Create;
  314. FFileType := '.dat';
  315. FTempFolder := GenerateTempFolder(GetTempFilePath);
  316. FXmlInfoFile := FTempFolder + '\Info.xml';
  317. FResultFile := GetTempFileName;
  318. FNeedUpdate := False;
  319. OpenProject;
  320. end;
  321. destructor TReportBase.Destroy;
  322. begin
  323. DeleteFileOrFolder(FTempFolder);
  324. DeleteFileOrFolder(FResultFile);
  325. FProjectData.Free;
  326. inherited;
  327. end;
  328. function TReportBase.Execute: Boolean;
  329. var
  330. sFileName: string;
  331. begin
  332. Result := False;
  333. ExportXmlInfo;
  334. SaveProject;
  335. ZipFolder(FTempFolder, FResultFile);
  336. // 检验导出文件
  337. if CheckFile(FResultFile) then
  338. begin
  339. Result := True;
  340. sFileName := GetNewOutputFileName;
  341. if SaveFile(sFileName, FFileType) then
  342. CopyFileOrFolder(FResultFile, sFileName);
  343. end;
  344. end;
  345. function TReportBase.ExportTo(AFileName: string): Boolean;
  346. begin
  347. Result := False;
  348. ExportXmlInfo;
  349. FProjectData.SimpleSaveAs(FTempFolder + '\' + ExtractSimpleFileName(FFileName));
  350. ZipFolder(FTempFolder, FResultFile);
  351. if CheckFile(FResultFile) then
  352. begin
  353. Result := True;
  354. CopyFileOrFolder(FResultFile, AFileName);
  355. end;
  356. end;
  357. procedure TReportBase.ExportXmlInfo;
  358. var
  359. FXmlDocument: IXMLDocument;
  360. begin
  361. FXmlDocument := TXMLDocument.Create(nil) as IXMLDocument;
  362. try
  363. FXmlDocument.Options := [doNodeAutoCreate,doNodeAutoIndent,doAttrNull,doAutoPrefix,doNamespaceDecl];
  364. FXmlDocument.Active := True;
  365. FXmlDocument.Encoding := 'GB2312';
  366. FXmlDocument.AddChild('ProjectMangerInfo');
  367. SaveInfoToXmlDocument(FXmlDocument.DocumentElement);
  368. FXmlDocument.SaveToFile(FXmlInfoFile);
  369. finally
  370. FXmlDocument := nil;
  371. end;
  372. end;
  373. function TReportBase.GetNewOutputFileName: string;
  374. begin
  375. Result := SupportManager.ConfigInfo.AuditPath + FProjectName
  376. + Format('-第%d期', [FProjectData.ProjProperties.PhaseCount]);
  377. if FProjectData.ProjProperties.AuditCompany <> '' then
  378. Result := Result + '-' + FProjectData.ProjProperties.AuditCompany;
  379. Result := Result + Format('-%s-', [FProjectData.ProjProperties.AuditStatusStr])
  380. + FormatDateTime('yyyy-mm-dd', Date) + FFileType;
  381. end;
  382. procedure TReportBase.OpenProject;
  383. begin
  384. FProjectData.SimpleOpen(FFileName);
  385. end;
  386. procedure TReportBase.SaveProject;
  387. begin
  388. FProjectData.SimpleSaveAs(FTempFolder + '\' + ExtractSimpleFileName(FFileName));
  389. end;
  390. procedure TReportBase.SaveInfoToXmlDocument(AXmlNode: IXMLNode);
  391. begin
  392. SaveProjectInfo(AXmlNode);
  393. SaveTenderProperty(AXmlNode);
  394. end;
  395. procedure TReportBase.SaveProjectInfo(AXmlNode: IXMLNode);
  396. var
  397. vInfo: IXMLNode;
  398. InfoRec: TsdDataRecord;
  399. begin
  400. vInfo := AXmlNode.AddChild('ProjectInfo');
  401. InfoRec := ProjectManager.sddProjectsInfo.FindKey('idxID', FProjectID);
  402. vInfo.Attributes['ProjectName'] := FProjectName;
  403. vInfo.Attributes['NeedUpdate'] := FNeedUpdate;
  404. vInfo.Attributes['DealTotalPrice'] := InfoRec.ValueByName('DealTotalPrice').AsFloat;
  405. vInfo.Attributes['PhaseTotalPrice'] := InfoRec.ValueByName('PhaseTotalPrice').AsFloat;
  406. vInfo.Attributes['EndDealTotalPrice'] := InfoRec.ValueByName('EndDealTotalPrice').AsFloat;
  407. vInfo.Attributes['EndChangeTotalPrice'] := InfoRec.ValueByName('EndChangeTotalPrice').AsFloat;
  408. vInfo.Attributes['EndTotalPrice'] := InfoRec.ValueByName('EndTotalPrice').AsFloat;
  409. vInfo.Attributes['PreTotalPrice'] := InfoRec.ValueByName('PreTotalPrice').AsFloat;
  410. vInfo.Attributes['PhasePay'] := InfoRec.ValueByName('PhasePay').AsFloat;
  411. vInfo.Attributes['Deal_BGLTotalPrice'] := InfoRec.ValueByName('Deal_BGLTotalPrice').AsFloat;
  412. vInfo.Attributes['PhaseCount'] := FProjectData.ProjProperties.PhaseCount;
  413. vInfo.Attributes['AuditStatus'] := FProjectData.ProjProperties.AuditStatus;
  414. vInfo.Attributes['FileName'] := ExtractSimpleFileName(FFileName);
  415. if G_IsCloud then
  416. begin
  417. vInfo.Attributes['WebID'] := InfoRec.ValueByName('WebID').AsInteger;
  418. vInfo.Attributes['WebOwnerID'] := InfoRec.ValueByName('WebOwnerID').AsInteger;
  419. vInfo.Attributes['WebAuthorID'] := InfoRec.ValueByName('WebAuthorID').AsInteger;
  420. end;
  421. end;
  422. procedure TReportBase.SaveTenderProperty(AXmlNode: IXMLNode);
  423. var
  424. vProp: IXMLNode;
  425. begin
  426. vProp := AXmlNode.AddChild('TenderProperty');
  427. end;
  428. function TReportBase.CheckFile(const AFileName: string): Boolean;
  429. var
  430. vChecker: TTenderFileChecker;
  431. begin
  432. Result := False;
  433. vChecker := TTenderFileChecker.Create;
  434. try
  435. Result := vChecker.CheckFileValid(AFileName);
  436. finally
  437. vChecker.Free;
  438. end;
  439. end;
  440. { TReplyProject }
  441. function TReplyProject.Execute: Boolean;
  442. begin
  443. FFileType := '.arf';
  444. FProjectData.LockedDataForReply;
  445. Result := inherited Execute;
  446. end;
  447. function TReplyProject.ExportTo(AFileName: string): Boolean;
  448. begin
  449. FProjectData.LockedDataForReply;
  450. Result := inherited ExportTo(AFileName);
  451. end;
  452. procedure TReplyProject.OpenProject;
  453. begin
  454. FProjectData.OpenForReply(FFileName);
  455. end;
  456. procedure TReplyProject.SaveProject;
  457. begin
  458. FProjectData.SaveForReply(FTempFolder + '\' + ExtractSimpleFileName(FFileName));
  459. end;
  460. { TReceiveProject }
  461. function TReceiveProject.CheckUpdateStatusValid: Boolean;
  462. procedure GetCurAuditStatus;
  463. begin
  464. {if FStageCount > 0 then
  465. FLostStageCount := FStageCount - (AXmlNode.Attributes['AuditStatus'] + 1) - 1;
  466. if FNeedUpdate then
  467. begin
  468. if FReply then
  469. Result := -1
  470. else if FStageCount > 0 then
  471. Result := FStageCount - 1
  472. else
  473. Result := AXmlNode.Attributes['AuditStatus'] + 1
  474. end
  475. else
  476. Result := AXmlNode.Attributes['AuditStatus'];}
  477. end;
  478. var
  479. ChildNodes: IXMLNodeList;
  480. vProjInfo, vXmlElement: IXMLNode;
  481. begin
  482. Result := True;
  483. vXmlElement := FXmlDocument.DocumentElement;
  484. ChildNodes := vXmlElement.ChildNodes;
  485. vProjInfo := ChildNodes.FindNode('ProjectInfo');
  486. FFileName := vProjInfo.Attributes['FileName'];
  487. FNeedUpdate := vProjInfo.Attributes['NeedUpdate'];
  488. FOrgAuditStatus := vProjInfo.Attributes['AuditStatus'];
  489. if not FIsReback and FNeedUpdate then
  490. begin
  491. if FStartAudit <> 0 then
  492. begin
  493. if (FStartAudit <> FOrgAuditStatus + 1) or (FEndAudit < FStartAudit) then
  494. Result := False
  495. else
  496. FLostStageCount := FEndAudit - FStartAudit + 1 + 1;
  497. end
  498. else
  499. FLostStageCount := 1;
  500. // 锁定的情况下
  501. if FLock then
  502. FLostStageCount := FLostStageCount - 1;
  503. if FReply then
  504. FNewAuditStatus := -1
  505. else
  506. FNewAuditStatus := FOrgAuditStatus + FLostStageCount;
  507. end
  508. else
  509. FNewAuditStatus := FOrgAuditStatus;
  510. end;
  511. function TReceiveProject.CheckOpen: Boolean;
  512. begin
  513. Result := OpenProjectManager.ProjectIndex(FCurNode.ID) <> -1;
  514. if Result then
  515. FMessageID := 1;
  516. end;
  517. constructor TReceiveProject.Create(ASelect: TsdIDTreeNode);
  518. begin
  519. FSelect := ASelect;
  520. FTempFolder := GenerateTempFolder(GetTempFilePath);
  521. FReply := False;
  522. FLock := False;
  523. FMessageID := 0;
  524. FIsReback := False;
  525. FXmlDocument := TXMLDocument.Create(nil) as IXMLDocument;
  526. end;
  527. destructor TReceiveProject.Destroy;
  528. begin
  529. FXmlDocument := nil;
  530. DeleteFileOrFolder(FTempFolder);
  531. inherited;
  532. end;
  533. procedure TReceiveProject.GetCurNode;
  534. var
  535. I: Integer;
  536. begin
  537. if FSelect.Rec.ValueByName('Type').AsInteger = 0 then
  538. FCurNode := FSelect.FirstChild
  539. else
  540. FCurNode := FSelect.Parent.FirstChild;
  541. while Assigned(FCurNode) and (FCurNode.Rec.ValueByName('Name').AsString <> FProjectName) do
  542. FCurNode := FCurNode.NextSibling;
  543. if not Assigned(FCurNode) then
  544. FCurNode := GetNewTender
  545. else if CheckOpen then Abort;
  546. end;
  547. function TReceiveProject.GetNewTender: TsdIDTreeNode;
  548. begin
  549. if FSelect.Rec.ValueByName('Type').AsInteger = 0 then
  550. Result := ProjectManager.ProjectsTree.Add(FSelect.ID, -1)
  551. else
  552. Result := ProjectManager.ProjectsTree.Add(FSelect.ParentID, FSelect.NextSiblingID);
  553. Result.Rec.ValueByName('Name').AsString := FProjectName;
  554. Result.Rec.ValueByName('Type').AsInteger := 1;
  555. Result.Rec.ValueByName('FileName').AsString := ExtractSimpleFileName(GetNewGUIDFileName(GetMyProjectsFilePath));
  556. end;
  557. procedure TReceiveProject.LoadInfoFromXmlDocument;
  558. var
  559. ChildNodes: IXMLNodeList;
  560. vProjInfo, vXmlElement: IXMLNode;
  561. begin
  562. vXmlElement := FXmlDocument.DocumentElement;
  563. ChildNodes := vXmlElement.ChildNodes;
  564. vProjInfo := ChildNodes.FindNode('ProjectInfo');
  565. if (G_IsCloud and (FWebBidName <> '')) then
  566. FProjectName := FWebBidName
  567. else
  568. FProjectName := vProjInfo.Attributes['ProjectName'];
  569. GetCurNode;
  570. // 备份旧文件
  571. // 备份须放在这里的原因是,需要打开xml文件后,才能确认是否要备份文件以及应备份哪个文件
  572. // 但是又不能再导入xml数据以后,导入xml数据后,项目的属性会变掉
  573. ProjectManager.RestoreTender(FCurNode.ID);
  574. LoadProjectInfo(ChildNodes.FindNode('ProjectInfo'));
  575. LoadTenderProperty(ChildNodes.FindNode('TenderProperty'));
  576. end;
  577. procedure TReceiveProject.LoadProjectInfo(AXmlNode: IXMLNode);
  578. begin
  579. FCurNode.Rec.ValueByName('DealTotalPrice').AsFloat := AXmlNode.Attributes['DealTotalPrice'];
  580. FCurNode.Rec.ValueByName('PhaseTotalPrice').AsFloat := AXmlNode.Attributes['PhaseTotalPrice'];
  581. FCurNode.Rec.ValueByName('EndDealTotalPrice').AsFloat := AXmlNode.Attributes['EndDealTotalPrice'];
  582. FCurNode.Rec.ValueByName('EndChangeTotalPrice').AsFloat := AXmlNode.Attributes['EndChangeTotalPrice'];
  583. FCurNode.Rec.ValueByName('EndTotalPrice').AsFloat := AXmlNode.Attributes['EndTotalPrice'];
  584. FCurNode.Rec.ValueByName('PreTotalPrice').AsFloat := AXmlNode.Attributes['PreTotalPrice'];
  585. FCurNode.Rec.ValueByName('PhasePay').AsFloat := AXmlNode.Attributes['PhasePay'];
  586. if AXmlNode.HasAttribute('Deal_BGLTotalPrice') then
  587. FCurNode.Rec.ValueByName('Deal_BGLTotalPrice').AsFloat := AXmlNode.Attributes['Deal_BGLTotalPrice'];
  588. FCurNode.Rec.ValueByName('PhaseCount').AsInteger := AXmlNode.Attributes['PhaseCount'];
  589. FCurNode.Rec.ValueByName('AuditStatus').AsInteger := FNewAuditStatus;
  590. FCurNode.Rec.ValueByName('CreateDate').AsString := FormatDateTime('yyyy-mm-dd', Date);
  591. if G_IsCloud then
  592. begin
  593. FCurNode.Rec.ValueByName('WebID').AsInteger := AXmlNode.Attributes['WebID'];
  594. FCurNode.Rec.ValueByName('WebOwnerID').AsInteger := AXmlNode.Attributes['WebOwnerID'];
  595. FCurNode.Rec.ValueByName('WebAuthorID').AsInteger := AXmlNode.Attributes['WebAuthorID'];
  596. end;
  597. ProjectManager.CalculateParentInfo(FCurNode.ParentID);
  598. end;
  599. procedure TReceiveProject.LoadTenderProperty(AXmlNode: IXMLNode);
  600. begin
  601. // ToDo
  602. end;
  603. procedure TReceiveProject.ReadXmlInfo;
  604. begin
  605. FXmlDocument.LoadFromFile(FTempFolder + '\Info.xml');
  606. FXmlDocument.Options := [doNodeAutoCreate,doNodeAutoIndent,doAutoPrefix,doNamespaceDecl];
  607. end;
  608. function TReceiveProject.Receive(const AFileName: string): TsdIDTreeNode;
  609. begin
  610. Result := nil;
  611. FFileType := ExtractFileExt(AFileName);
  612. UnZipFile(AFileName, FTempFolder);
  613. ReadXmlInfo;
  614. if CheckUpdateStatusValid then
  615. begin
  616. if UpdateData(FTempFolder + '\' + FFileName) then
  617. begin
  618. LoadInfoFromXmlDocument;
  619. CopyFileOrFolder(FTempFolder + '\' + FFileName,
  620. GetMyProjectsFilePath + FCurNode.Rec.ValueByName('FileName').AsString);
  621. Result := FCurNode;
  622. end
  623. else
  624. FMessageID := 3;
  625. end
  626. else
  627. FMessageID := 2;
  628. end;
  629. function TReceiveProject.ReceiveForLost(const AFileName: string;
  630. AStartAudit, AEndAudit: Integer; AReply: Boolean = False): TsdIDTreeNode;
  631. begin
  632. FStartAudit := AStartAudit;
  633. FEndAudit := AEndAudit;
  634. FReply := AReply;
  635. Result := Receive(AFileName);
  636. end;
  637. function TReceiveProject.UpdateData(const AFileName: string): Boolean;
  638. var
  639. I: Integer;
  640. begin
  641. if not IsReback and FNeedUpdate then
  642. begin
  643. Result := False;
  644. FProjectData := TProjectData.Create;
  645. try
  646. FProjectData.OpenForReceive(AFileName);
  647. FProjectData.LockedDataForSubmit;
  648. for I := 0 to FLostStageCount - 1 do
  649. FProjectData.UpdateDataForReceive;
  650. if FReply then
  651. FProjectData.LockedDataForReply;
  652. FProjectData.SaveForReceive(AFileName);
  653. Result := True;
  654. finally
  655. FProjectData.Free;
  656. end;
  657. end
  658. else
  659. Result := True;
  660. end;
  661. procedure TReceiveProject.SetWebBidName(const Value: string);
  662. begin
  663. FWebBidName := Value;
  664. end;
  665. { TTenderExport }
  666. constructor TTenderExport.Create(ARec: TsdDataRecord;
  667. const AFileName: string);
  668. begin
  669. FProjectName := ARec.ValueByName('Name').AsString;
  670. FFileName := GetMyProjectsFilePath + ARec.ValueByName('FileName').AsString;
  671. if not G_IsCloud then
  672. FAttachmentPath := GetMyProjectsFilePath + 'Attachment\' + ARec.ValueByName('FileName').AsString + '\';
  673. FProjectID := ARec.ValueByName('ID').AsInteger;
  674. FTempFolder := GenerateTempFolder(GetTempFilePath);
  675. FXmlInfoFile := FTempFolder + '\Info.xml';
  676. FResultFile := AFileName;
  677. end;
  678. destructor TTenderExport.Destroy;
  679. begin
  680. DeleteFileOrFolder(FTempFolder);
  681. inherited;
  682. end;
  683. procedure TTenderExport.Execute(AExportAttachment: Boolean);
  684. var
  685. sFileName: string;
  686. begin
  687. ExportXmlInfo;
  688. sFileName := ExtractSimpleFileName(FResultFile);
  689. CopyFileOrFolder(FFileName, FTempFolder + '\' + sFileName);
  690. // if not G_IsCloud then // 云版不导出附件,云版的运作机制是从网上下载
  691. // if AExportAttachment then
  692. // CopyFolder(FAttachmentPath, FTempFolder + '\' + sFileName + '[附件包]');
  693. ZipFolder(FTempFolder, FResultFile);
  694. end;
  695. procedure TTenderExport.ExportXmlInfo;
  696. var
  697. FXmlDocument: IXMLDocument;
  698. begin
  699. FXmlDocument := TXMLDocument.Create(nil) as IXMLDocument;
  700. try
  701. FXmlDocument.Options := [doNodeAutoCreate,doNodeAutoIndent,doAttrNull,doAutoPrefix,doNamespaceDecl];
  702. FXmlDocument.Active := True;
  703. FXmlDocument.Encoding := 'GB2312';
  704. FXmlDocument.AddChild('ProjectMangerInfo');
  705. SaveInfoToXmlDocument(FXmlDocument.DocumentElement);
  706. FXmlDocument.SaveToFile(FXmlInfoFile);
  707. finally
  708. FXmlDocument := nil;
  709. end;
  710. end;
  711. procedure TTenderExport.SaveInfoToXmlDocument(AXmlNode: IXMLNode);
  712. begin
  713. SaveProjectInfo(AXmlNode);
  714. SaveTenderProperty(AXmlNode);
  715. end;
  716. procedure TTenderExport.SaveProjectInfo(AXmlNode: IXMLNode);
  717. var
  718. vInfo: IXMLNode;
  719. InfoRec: TsdDataRecord;
  720. begin
  721. vInfo := AXmlNode.AddChild('ProjectInfo');
  722. InfoRec := ProjectManager.sddProjectsInfo.FindKey('idxID', FProjectID);
  723. vInfo.Attributes['ProjectName'] := FProjectName;
  724. vInfo.Attributes['DealTotalPrice'] := InfoRec.ValueByName('DealTotalPrice').AsFloat;
  725. vInfo.Attributes['PhaseTotalPrice'] := InfoRec.ValueByName('PhaseTotalPrice').AsFloat;
  726. vInfo.Attributes['EndDealTotalPrice'] := InfoRec.ValueByName('EndDealTotalPrice').AsFloat;
  727. vInfo.Attributes['EndChangeTotalPrice'] := InfoRec.ValueByName('EndChangeTotalPrice').AsFloat;
  728. vInfo.Attributes['EndTotalPrice'] := InfoRec.ValueByName('EndTotalPrice').AsFloat;
  729. vInfo.Attributes['PreTotalPrice'] := InfoRec.ValueByName('PreTotalPrice').AsFloat;
  730. vInfo.Attributes['PhasePay'] := InfoRec.ValueByName('PhasePay').AsFloat;
  731. vInfo.Attributes['Deal_BGLTotalPrice'] := InfoRec.ValueByName('Deal_BGLTotalPrice').AsFloat;
  732. vInfo.Attributes['PhaseCount'] := InfoRec.ValueByName('PhaseCount').AsInteger;
  733. vInfo.Attributes['AuditStatus'] := InfoRec.ValueByName('AuditStatus').AsInteger;
  734. vInfo.Attributes['FileName'] := ExtractSimpleFileName(FResultFile);
  735. if G_IsCloud then
  736. begin
  737. vInfo.Attributes['WebID'] := InfoRec.ValueByName('WebID').AsInteger;
  738. vInfo.Attributes['WebOwnerID'] := InfoRec.ValueByName('WebOwnerID').AsInteger;
  739. vInfo.Attributes['WebAuthorID'] := InfoRec.ValueByName('WebAuthorID').AsInteger;
  740. end;
  741. end;
  742. procedure TTenderExport.SaveTenderProperty(AXmlNode: IXMLNode);
  743. var
  744. vProp: IXMLNode;
  745. begin
  746. vProp := AXmlNode.AddChild('TenderProperty');
  747. end;
  748. { TProjectExport }
  749. constructor TProjectExport.Create(ANode: TsdIDTreeNode; const AFileName: string; AExportAttachment: Boolean);
  750. begin
  751. FTempFolder := GenerateTempFolder(GetTempFilePath);
  752. FExportNode := ANode;
  753. FResultFile := AFileName;
  754. FExportAttachment := AExportAttachment;
  755. FXmlInfoFile := FTempFolder + '\TreeInfo.xml';
  756. end;
  757. destructor TProjectExport.Destroy;
  758. begin
  759. DeleteFileOrFolder(FTempFolder);
  760. inherited;
  761. end;
  762. procedure TProjectExport.Execute;
  763. begin
  764. ExportXmlInfo;
  765. ExportNode(FExportNode.FirstChild, FTempFolder + '\');
  766. ZipFolder(FTempFolder, FResultFile);
  767. end;
  768. procedure TProjectExport.ExportNode(ANode: TsdIDTreeNode;
  769. const AExportPath: string);
  770. var
  771. ACurPath: string;
  772. begin
  773. if not Assigned(ANode) then Exit;
  774. if ANode.HasChildren or (ANode.Rec.ValueByName('Type').AsInteger = 0) then
  775. begin
  776. ACurPath := AExportPath + ANode.Rec.ValueByName('Name').AsString + '\';
  777. CreateDirectoryInDeep(ACurPath);
  778. ExportNode(ANode.FirstChild, ACurPath);
  779. end
  780. else
  781. ExportTender(ANode, AExportPath);
  782. ExportNode(ANode.NextSibling, AExportPath);
  783. end;
  784. procedure TProjectExport.ExportTender(ANode: TsdIDTreeNode;
  785. const AExportPath: string);
  786. begin
  787. FTenderExportor := TTenderExport.Create(ANode.Rec,
  788. AExportPath + ANode.Rec.ValueByName('Name').AsString);
  789. try
  790. FTenderExportor.Execute(FExportAttachment);
  791. finally
  792. FTenderExportor.Free;
  793. end;
  794. end;
  795. procedure TProjectExport.ExportXmlInfo;
  796. var
  797. FXmlDocument: IXMLDocument;
  798. begin
  799. FXmlDocument := TXMLDocument.Create(nil) as IXMLDocument;
  800. try
  801. FXmlDocument.Options := [doNodeAutoCreate,doNodeAutoIndent,doAttrNull,doAutoPrefix,doNamespaceDecl];
  802. FXmlDocument.Active := True;
  803. FXmlDocument.Encoding := 'GB2312';
  804. FXmlDocument.AddChild('ProjectTreeInfo');
  805. SaveTreeNodeInfo(FXmlDocument.DocumentElement, FExportNode.FirstChild);
  806. FXmlDocument.SaveToFile(FXmlInfoFile);
  807. finally
  808. FXmlDocument := nil;
  809. end;
  810. end;
  811. procedure TProjectExport.SaveTreeNodeInfo(AXmlNode: IXMLNode;
  812. ANode: TsdIDTreeNode);
  813. var
  814. CurNode: IXMLNode;
  815. begin
  816. if not Assigned(ANode) then Exit;
  817. CurNode := AXmlNode.AddChild('TreeNode');
  818. CurNode.Attributes['Name'] := ANode.Rec.ValueByName('Name').AsString;
  819. CurNode.Attributes['Type'] := ANode.Rec.ValueByName('Type').AsInteger;
  820. if ANode.HasChildren then
  821. SaveTreeNodeInfo(CurNode, ANode.FirstChild);
  822. SaveTreeNodeInfo(AXmlNode, ANode.NextSibling);
  823. end;
  824. { TProjectImport }
  825. function TProjectImport.AddNewNode(AParentID, ANextID: Integer;
  826. const ANodeName: string): TsdIDTreeNode;
  827. begin
  828. with ProjectManager.ProjectsTree do
  829. Result := Add(AParentID, ANextID);
  830. Result.Rec.ValueByName('Name').AsString := ANodeName;
  831. Result.Rec.ValueByName('Type').AsInteger := 0;
  832. end;
  833. constructor TProjectImport.Create(ASelect: TsdIDTreeNode;
  834. const AProjectName, AFileName: string);
  835. begin
  836. FSelect := ASelect;
  837. FProjectName := AProjectName;
  838. FFileName := AFileName;
  839. FTempFolder := GenerateTempFolder(GetTempFilePath);
  840. end;
  841. destructor TProjectImport.Destroy;
  842. begin
  843. DeleteFileOrFolder(FTempFolder);
  844. inherited;
  845. end;
  846. procedure TProjectImport.Execute;
  847. begin
  848. UnZipFile(FFileName, FTempFolder);
  849. // ID 188 需求变更,一直作为后兄弟节点导入
  850. {if FSelect.Rec.ValueByName('Type').AsInteger = 1 then
  851. FNew := AddNewNode(FSelect.ParentID, FSelect.NextSiblingID, FProjectName)
  852. else
  853. FNew := AddNewNode(FSelect.ID, -1, FProjectName);}
  854. if Assigned(FSelect) then
  855. FNew := AddNewNode(FSelect.ParentID, FSelect.NextSiblingID, FProjectName)
  856. else
  857. FNew := AddNewNode(-1, -1, FProjectName);
  858. LoadChildrenFormXml;
  859. end;
  860. procedure TProjectImport.LoadChild(AXmlNode: IXMLNode;
  861. AParent: TsdIDTreeNode; const APath: string);
  862. var
  863. I, iType: Integer;
  864. XmlNode: IXMLNode;
  865. stnNewNode: TsdIDTreeNode;
  866. begin
  867. for I := 0 to AXmlNode.ChildNodes.Count - 1 do
  868. begin
  869. XmlNode := AXmlNode.ChildNodes.Get(I);
  870. iType := XmlNode.Attributes['Type'];
  871. if iType = 0 then
  872. begin
  873. stnNewNode := AddNewNode(AParent.ID, -1, XmlNode.Attributes['Name']);
  874. if XmlNode.HasChildNodes then
  875. LoadChild(XmlNode, stnNewNode, APath + XmlNode.Attributes['Name'] + '\');
  876. end
  877. else
  878. LoadTender(XmlNode, AParent, APath);
  879. end;
  880. end;
  881. procedure TProjectImport.LoadChildrenFormXml;
  882. var
  883. FXmlDocument: IXMLDocument;
  884. XmlNode: IXMLNode;
  885. FRootList: IXMLNodeList;
  886. begin
  887. FXmlDocument := TXMLDocument.Create(nil) as IXMLDocument;
  888. try
  889. FXmlDocument.LoadFromFile(FTempFolder + '\TreeInfo.xml');
  890. FXmlDocument.Options := [doNodeAutoCreate,doNodeAutoIndent,doAutoPrefix,doNamespaceDecl];
  891. XmlNode := FXmlDocument.DocumentElement;
  892. LoadChild(XmlNode, FNew, FTempFolder + '\');
  893. finally
  894. FRootList := nil;
  895. FXmlDocument := nil;
  896. end;
  897. end;
  898. procedure TProjectImport.LoadTender(AXmlNode: IXMLNode;
  899. AParent: TsdIDTreeNode; const APath: string);
  900. var
  901. TenderImportor: TTenderImport;
  902. begin
  903. TenderImportor := TTenderImport.Create(AParent,
  904. AXmlNode.Attributes['Name'], APath + AXmlNode.Attributes['Name']);
  905. try
  906. TenderImportor.Execute;
  907. finally
  908. TenderImportor.Free;
  909. end;
  910. end;
  911. { TTenderImport }
  912. constructor TTenderImport.Create(ASelect: TsdIDTreeNode;
  913. const AProjectName, AFileName: string);
  914. begin
  915. FSelect := ASelect;
  916. FProjectName := AProjectName;
  917. FFileName := AFileName;
  918. FTempFolder := GenerateTempFolder(GetTempFilePath);
  919. end;
  920. destructor TTenderImport.Destroy;
  921. begin
  922. DeleteFileOrFolder(FTempFolder);
  923. inherited;
  924. end;
  925. procedure TTenderImport.Execute;
  926. var
  927. sFile, sFJ: string;
  928. begin
  929. UnZipFile(FFileName, FTempFolder);
  930. GetNewNode;
  931. LoadXmlInfo;
  932. sFile := FTempFolder + '\' + FTenderFileName;
  933. // sFJ := sFile + '[附件包]';
  934. CopyFileOrFolder(sFile, GetMyProjectsFilePath + FNewNode.Rec.ValueByName('FileName').AsString);
  935. // if not G_IsCloud then // 云版附件从服务器获取,不导入。
  936. // if DirectoryExists(sFJ) then
  937. // CopyFolder(sFJ, GetMyProjectsFilePath + 'Attachment\' + FNewNode.Rec.ValueByName('FileName').AsString);
  938. end;
  939. procedure TTenderImport.GetNewNode;
  940. begin
  941. if FSelect.Rec.ValueByName('Type').AsInteger = 1 then
  942. FNewNode := ProjectManager.ProjectsTree.Add(FSelect.ParentID, FSelect.NextSiblingID)
  943. else
  944. FNewNode := ProjectManager.ProjectsTree.Add(FSelect.ID, -1);
  945. FNewNode.Rec.ValueByName('Name').AsString := FProjectName;
  946. FNewNode.Rec.ValueByName('Type').AsInteger := 1;
  947. FNewNode.Rec.ValueByName('FileName').AsString := ExtractSimpleFileName(GetNewGUIDFileName(GetMyProjectsFilePath));
  948. end;
  949. procedure TTenderImport.ImportToSelect;
  950. begin
  951. UnZipFile(FFileName, FTempFolder);
  952. FNewNode := FSelect;
  953. LoadXmlInfo;
  954. CopyFileOrFolder(FTempFolder + '\' + FTenderFileName,
  955. GetMyProjectsFilePath + FNewNode.Rec.ValueByName('FileName').AsString);
  956. end;
  957. procedure TTenderImport.LoadInfoFromXmlDocument(AXmlNode: IXMLNode);
  958. var
  959. ChildNodes: IXMLNodeList;
  960. begin
  961. ChildNodes := AXmlNode.ChildNodes;
  962. LoadProjectInfo(ChildNodes.FindNode('ProjectInfo'));
  963. LoadTenderProperty(ChildNodes.FindNode('TenderProperty'));
  964. end;
  965. procedure TTenderImport.LoadProjectInfo(AXmlNode: IXMLNode);
  966. begin
  967. FTenderFileName := AXmlNode.Attributes['FileName'];
  968. FNewNode.Rec.ValueByName('DealTotalPrice').AsFloat := AXmlNode.Attributes['DealTotalPrice'];
  969. FNewNode.Rec.ValueByName('PhaseTotalPrice').AsFloat := AXmlNode.Attributes['PhaseTotalPrice'];
  970. FNewNode.Rec.ValueByName('EndDealTotalPrice').AsFloat := AXmlNode.Attributes['EndDealTotalPrice'];
  971. FNewNode.Rec.ValueByName('EndChangeTotalPrice').AsFloat := AXmlNode.Attributes['EndChangeTotalPrice'];
  972. FNewNode.Rec.ValueByName('EndTotalPrice').AsFloat := AXmlNode.Attributes['EndTotalPrice'];
  973. FNewNode.Rec.ValueByName('PreTotalPrice').AsFloat := AXmlNode.Attributes['PreTotalPrice'];
  974. FNewNode.Rec.ValueByName('PhasePay').AsFloat := AXmlNode.Attributes['PhasePay'];
  975. if AXmlNode.HasAttribute('Deal_BGLTotalPrice') then
  976. FNewNode.Rec.ValueByName('Deal_BGLTotalPrice').AsFloat := AXmlNode.Attributes['Deal_BGLTotalPrice'];
  977. FNewNode.Rec.ValueByName('PhaseCount').AsInteger := AXmlNode.Attributes['PhaseCount'];
  978. FNewNode.Rec.ValueByName('AuditStatus').AsInteger := AXmlNode.Attributes['AuditStatus'];
  979. FNewNode.Rec.ValueByName('CreateDate').AsString := FormatDateTime('yyyy-mm-dd', Date);
  980. if G_IsCloud then
  981. begin
  982. FNewNode.Rec.ValueByName('WebID').AsInteger := AXmlNode.Attributes['WebID'];
  983. FNewNode.Rec.ValueByName('WebOwnerID').AsInteger := AXmlNode.Attributes['WebOwnerID'];
  984. FNewNode.Rec.ValueByName('WebAuthorID').AsInteger := AXmlNode.Attributes['WebAuthorID'];
  985. end;
  986. ProjectManager.CalculateParentInfo(FNewNode.ParentID);
  987. end;
  988. procedure TTenderImport.LoadTenderProperty(AXmlNode: IXMLNode);
  989. begin
  990. // TODO
  991. end;
  992. procedure TTenderImport.LoadXmlInfo;
  993. var
  994. FXmlDocument: IXMLDocument;
  995. XmlNode: IXMLNode;
  996. FRootList: IXMLNodeList;
  997. begin
  998. FXmlDocument := TXMLDocument.Create(nil) as IXMLDocument;
  999. try
  1000. FXmlDocument.LoadFromFile(FTempFolder + '\Info.xml');
  1001. FXmlDocument.Options := [doNodeAutoCreate,doNodeAutoIndent,doAutoPrefix,doNamespaceDecl];
  1002. XmlNode := FXmlDocument.DocumentElement;
  1003. LoadInfoFromXmlDocument(XmlNode);
  1004. finally
  1005. FRootList := nil;
  1006. FXmlDocument := nil;
  1007. end;
  1008. end;
  1009. { TTenderFileChecker }
  1010. function TTenderFileChecker.CheckFileMatchXml: Boolean;
  1011. var
  1012. FProjectData: TProjectData;
  1013. begin
  1014. FProjectData := TProjectData.Create;
  1015. try
  1016. try
  1017. FProjectData.SimpleOpen(FTenderFileName);
  1018. Result := FProjectData.CheckDataBaseInfo(FPhaseCount, FAuditStatus);
  1019. except
  1020. Result := False;
  1021. end;
  1022. finally
  1023. FProjectData.Free;
  1024. end;
  1025. end;
  1026. function TTenderFileChecker.CheckFileValid(const AFileName: string): Boolean;
  1027. begin
  1028. FTempFolder := GenerateTempFolder(GetTempFilePath);
  1029. FTenderTempFolder := FTempFolder + '\Tender';
  1030. CreateDirectoryInDeep(FTenderTempFolder);
  1031. try
  1032. Result := DecryptFile(AFileName) and CheckFileMatchXml;
  1033. finally
  1034. DeleteFileOrFolder(FTempFolder);
  1035. end;
  1036. end;
  1037. function TTenderFileChecker.DecryptFile(const AFileName: string): Boolean;
  1038. begin
  1039. Result := UnZipFile(AFileName, FTempFolder);
  1040. if not Result then Exit;
  1041. LoadInfo;
  1042. Result := UnZipFile(FTenderFileName, FTenderTempFolder);
  1043. end;
  1044. procedure TTenderFileChecker.LoadInfo;
  1045. begin
  1046. LoadInfoFromXml;
  1047. end;
  1048. procedure TTenderFileChecker.LoadInfoFromXml;
  1049. var
  1050. FXmlDocument: IXMLDocument;
  1051. XmlNode: IXMLNode;
  1052. FRootList: IXMLNodeList;
  1053. begin
  1054. FXmlDocument := TXMLDocument.Create(nil) as IXMLDocument;
  1055. try
  1056. FXmlDocument.LoadFromFile(FTempFolder + '\Info.xml');
  1057. FXmlDocument.Options := [doNodeAutoCreate,doNodeAutoIndent,doAutoPrefix,doNamespaceDecl];
  1058. XmlNode := FXmlDocument.DocumentElement;
  1059. LoadInfoFromXmlDocument(XmlNode);
  1060. finally
  1061. FRootList := nil;
  1062. FXmlDocument := nil;
  1063. end;
  1064. end;
  1065. procedure TTenderFileChecker.LoadInfoFromXmlDocument(AXmlNode: IXMLNode);
  1066. var
  1067. ChildNodes: IXMLNodeList;
  1068. begin
  1069. ChildNodes := AXmlNode.ChildNodes;
  1070. LoadProjectInfo(ChildNodes.FindNode('ProjectInfo'));
  1071. end;
  1072. procedure TTenderFileChecker.LoadProjectInfo(AXmlNode: IXMLNode);
  1073. begin
  1074. FProjectName := AXmlNode.Attributes['ProjectName'];
  1075. FPhaseCount := AXmlNode.Attributes['PhaseCount'];
  1076. FAuditStatus := AXmlNode.Attributes['AuditStatus'];
  1077. FTenderFileName := FTempFolder + '\' + AXmlNode.Attributes['FileName'];
  1078. end;
  1079. { TTenderZipCompleteChecker }
  1080. function TTenderZipCompleteChecker.CheckAllPhase: Boolean;
  1081. begin
  1082. Result := Assigned(FProjectData) and FProjectData.CheckPhaseFileComplete;
  1083. end;
  1084. function TTenderZipCompleteChecker.CheckFileValid(
  1085. const AFileName: string): Boolean;
  1086. begin
  1087. FFileName := AFileName;
  1088. FTempFolder := GenerateTempFolder(GetTempFilePath);
  1089. try
  1090. case CheckType of
  1091. zctAllPhase: Result := UnZipFile(AFileName, FTempFolder) and CheckMain and CheckAllPhase;
  1092. zctLastPhase: Result := UnZipFile(AFileName, FTempFolder) and CheckMain and CheckLastPhase;
  1093. end;
  1094. finally
  1095. if Assigned(FProjectData) then
  1096. FProjectData.Free;
  1097. DeleteFileOrFolder(FTempFolder);
  1098. end;
  1099. end;
  1100. function TTenderZipCompleteChecker.CheckLastPhase: Boolean;
  1101. begin
  1102. Result := Assigned(FProjectData) and FProjectData.CheckLastPhaseFileExist;
  1103. end;
  1104. function TTenderZipCompleteChecker.CheckMain: Boolean;
  1105. begin
  1106. Result := False;
  1107. if FileExists(FTempFolder + '\main.dat') then
  1108. begin
  1109. try
  1110. FProjectData := TProjectData.Create;
  1111. FProjectData.OpenForSubmit(FFileName);
  1112. Result := True;
  1113. except
  1114. Result := False;
  1115. end;
  1116. end;
  1117. end;
  1118. constructor TTenderZipCompleteChecker.Create;
  1119. begin
  1120. FCheckType := zctAllPhase;
  1121. end;
  1122. destructor TTenderZipCompleteChecker.Destroy;
  1123. begin
  1124. inherited;
  1125. end;
  1126. end.