ProjectManagerFme.pas 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781
  1. unit ProjectManagerFme;
  2. interface
  3. uses
  4. ProjectManagerDm, ZhAPI,
  5. NewProjectFrm,
  6. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7. Dialogs, ZjGridDBA, ZJGrid, ComCtrls, ToolWin, ActnList,
  8. dxBar, sdGridDBA, sdGridTreeDBA, sdIDTree, CslJson, ExtCtrls,
  9. StdCtrls, sdDB, CslButton, OrderCheckerFme, Contnrs;
  10. type
  11. TStrArr = array of string;
  12. TProjectManagerFrame = class(TFrame)
  13. ToolBar: TToolBar;
  14. tobtnOpen: TToolButton;
  15. zgProjects: TZJGrid;
  16. tobtnDelete: TToolButton;
  17. ActionList1: TActionList;
  18. actnOpen: TAction;
  19. actnDelete: TAction;
  20. dxpmProjectManager: TdxBarPopupMenu;
  21. actnReceiveProject: TAction;
  22. stdProjects: TsdGridTreeDBA;
  23. actnNewProject: TAction;
  24. actnNewSubProject: TAction;
  25. actnNewTender: TAction;
  26. pnlTenderProperty: TPanel;
  27. sdTenderProperty: TsdGridDBA;
  28. sprProperty: TSplitter;
  29. tobtnRenane: TToolButton;
  30. actnRename: TAction;
  31. tobtnImport: TToolButton;
  32. tobtnExport: TToolButton;
  33. actnImport: TAction;
  34. actnExport: TAction;
  35. tobtn1: TToolButton;
  36. pnlWeb: TPanel;
  37. pnlProject: TPanel;
  38. shp2: TShape;
  39. shp1: TShape;
  40. shp3: TShape;
  41. shp4: TShape;
  42. pnlTenderTitle: TPanel;
  43. lblBidName: TLabel;
  44. pnlShadow: TPanel;
  45. pnlProgress: TPanel;
  46. lblPeriodTotal: TLabel;
  47. lblPeriodState: TLabel;
  48. lblProgress: TLabel;
  49. lblPeriod: TLabel;
  50. pnlBelongProject: TPanel;
  51. lblBelongProject: TLabel;
  52. lblProjName: TLabel;
  53. lblLeftHalfBracket: TLabel;
  54. lblOnwerCompany: TLabel;
  55. lblOnwerName: TLabel;
  56. pnlProjectType: TPanel;
  57. lblProjectType: TLabel;
  58. lblWebProjCtgyName: TLabel;
  59. zgTenderProperty: TZJGrid;
  60. actnOpenBackupFolder: TAction;
  61. sbChecker: TScrollBox;
  62. procedure actnOpenExecute(Sender: TObject);
  63. procedure actnDeleteExecute(Sender: TObject);
  64. procedure zgProjectsMouseDown(Sender: TObject; Button: TMouseButton;
  65. Shift: TShiftState; X, Y: Integer);
  66. procedure actnReceiveProjectExecute(Sender: TObject);
  67. procedure actnNewProjectExecute(Sender: TObject);
  68. procedure actnNewSubProjectExecute(Sender: TObject);
  69. procedure actnNewTenderExecute(Sender: TObject);
  70. procedure zgProjectsDrawCellText(ACanvas: TCanvas; const ARect: TRect;
  71. const ACoord: TPoint; AGrid: TZJGrid; const Text: String;
  72. var ADefaultDraw: Boolean);
  73. procedure actnNewSubProjectUpdate(Sender: TObject);
  74. procedure actnNewTenderUpdate(Sender: TObject);
  75. procedure zgProjectsCurrentChanged(Sender: TObject; Col, Row: Integer);
  76. procedure actnSubmitProjectUpdate(Sender: TObject);
  77. procedure actnReplyProjectUpdate(Sender: TObject);
  78. procedure actnRenameExecute(Sender: TObject);
  79. procedure actnOpenUpdate(Sender: TObject);
  80. procedure actnImportExecute(Sender: TObject);
  81. procedure actnExportExecute(Sender: TObject);
  82. procedure actnDeleteUpdate(Sender: TObject);
  83. procedure actnOpenBackupFolderExecute(Sender: TObject);
  84. procedure actnRenameUpdate(Sender: TObject);
  85. procedure zgProjectsShowHint(var HintStr: String; var CanShow: Boolean;
  86. var HintInfo: THintInfo; const ACoord: TPoint);
  87. private
  88. FProjectManagerData: TProjectManagerData;
  89. // Chenshilong,2016.03.24
  90. // 这部分线上和本地一致,无需区分
  91. FID: Integer; // 本地标段文件ID
  92. FWebID: Integer; // 关联服务器用的ID(服务器有自己的ID体系)
  93. FWebAuthorID: Integer; // 编制人
  94. FWebOwnerID: Integer; // 业主
  95. // 本地存储值、线上存储值。线上修改后,需要同步到本地
  96. FWebMD5_Local: string; // 本地存储的MD5
  97. FWebMD5_OnLine: string; // 线上存储的最新的MD5(下同)
  98. FWebBidName_Local: string; // 标段名 (当无法同线上取得联系时,本地需要用到该名称来提示)
  99. FWebBidName_OnLine: string;
  100. FWebFolder_OnLine: string; // 这个命名不妥,但很直观。线上的项目名称、项目类型概念跟本地颠倒,很混乱。
  101. FWebSubFolder_OnLine: string;
  102. FWebOwnerCompany: string;
  103. FWebOwnerRole: string;
  104. FWebOwnerName: string;
  105. FWebCheckStatusMy: TCheckStatus; // 登陆用户在当前项目中的工作状态。
  106. FWebCheckStatusProject: TCheckStatus; // 项目的审核状态。
  107. FOnLineCheckerBegin: Integer; // 线上审批的起始人。 010110111 起7止9。 0101101110 起0止0。
  108. FOnLineCheckerEnd: Integer; // 线上审批的截止人。
  109. FPhaseTotal: Integer;
  110. FPhaseNo: Integer;
  111. FCurPos: Integer; // 用来控制审核人的添加位置
  112. FCheckerList: TObjectList;
  113. function ReceiveFile(const AFileName: string; AFileMD5: string = ''; ANeedLock: Boolean = False): Boolean;
  114. function ImportFile(const AFileName: string; AFileMD5: string = ''): Boolean;
  115. procedure ConnectButtonWithAction;
  116. function GetImportProjectName(const AFileName: string; AParent: TsdIDTreeNode): string;
  117. function IsProject(ANode: TsdIDTreeNode): Boolean;
  118. function IsLeafProject(ANode: TsdIDTreeNode): Boolean;
  119. function IsUnEmptyLeafProject(ANode: TsdIDTreeNode): Boolean;
  120. function CheckOpened(ANode: TsdIDTreeNode): Boolean;
  121. procedure SetPropertyVisible(AVisible: Boolean);
  122. procedure ShowProjectInfoTopAndCheckers;
  123. // 网络上的目录结构,本地有则定位,没有则创建。
  124. procedure CheckWebFolders(AFolderID, ASubFolderID: Integer;
  125. AFolderName, ASubFolderName: string);
  126. // ANewBidName: 项目的最新标段名(取自服务器,有人改名了,本地的就变成旧的)
  127. procedure CheckBidName(AID: Integer; ANewBidName: string); overload;
  128. procedure CheckBidName(AUserID, AWebID: Integer; ANewBidName: string); overload;
  129. procedure ClearLocalValues;
  130. procedure GetLocalValues(ARec: TsdDataRecord); overload;
  131. // 用户ID、网络标段ID、Type=1可以定位一个标段。
  132. procedure GetLocalValues(AUserID, AWebID: Integer); overload;
  133. // 1 等待我审核的标段文件; 2 我参与的全部标段文件
  134. procedure DoBatchReceiveOnline(ARequestType: Integer);
  135. function LocalMD5(AUserID, AWebID: Integer): string;
  136. procedure BubbleSortProjects;
  137. // AReceiveKind: 1 接收; 2 导入
  138. function FileDownAndReceive(ADownURL: string; AReceiveKind: Integer): Boolean;
  139. // 线上审批的起止人
  140. procedure OnLineChecker(AAr: TOVArr; var ABegin, AEnd: Integer);
  141. public
  142. constructor Create(AOwner: TComponent); override;
  143. destructor Destroy; override;
  144. procedure DoBatchReceiveAllOnline;
  145. // AType: -2 繁忙; -1 正常读取; 0 第0期; 1 第1期。
  146. procedure ShowProjectInfoTop(AType: Integer = -1);
  147. function Rec(AProjectID: Integer): TsdDataRecord;
  148. function CurRec: TsdDataRecord;
  149. function CurRecAttachmentPath: string;
  150. function AttachmentFileCountsWithoutManageFile(ANode: TsdIDTreeNode): Integer;
  151. property ProjectCheckStatus: TCheckStatus read FWebCheckStatusProject;
  152. end;
  153. implementation
  154. uses
  155. MainFrm, UtilMethods, ProjectCommands, Globals, ConfigDoc, ConstUnit,
  156. WebNewTenderFrm, PHPWebDm, Math, mProgressFrm, ProgressHintFrm,
  157. ShellAPI;
  158. {$R *.dfm}
  159. procedure TProjectManagerFrame.ConnectButtonWithAction;
  160. begin
  161. SetDxBtnAction(actnNewProject, MainForm.dxbtnNewProject);
  162. SetDxBtnAction(actnNewSubProject, MainForm.dxbtnNewSubProject);
  163. SetDxBtnAction(actnNewTender, MainForm.dxbtnNewTender);
  164. SetDxBtnAction(actnOpen, MainForm.dxbtnOpenProject);
  165. SetDxBtnAction(actnDelete, MainForm.dxbtnDeleteProject);
  166. SetDxBtnAction(actnReceiveProject, MainForm.dxbtnReceiveProject);
  167. SetDxBtnAction(actnOpenBackupFolder, MainForm.dxbtnOpenBackupFolder);
  168. SetDxBtnAction(actnRename, MainForm.dxbtnRename);
  169. end;
  170. constructor TProjectManagerFrame.Create(AOwner: TComponent);
  171. begin
  172. inherited;
  173. FCheckerList := TObjectList.Create;
  174. FProjectManagerData := ProjectManager;
  175. FProjectManagerData.Open;
  176. stdProjects.IDTree := FProjectManagerData.ProjectsTree;
  177. sdTenderProperty.DataView := FProjectManagerData.sdvTenderProperty;
  178. ConnectButtonWithAction;
  179. SetPropertyVisible(False);
  180. sbChecker.Height := 0;
  181. if G_IsCloud then
  182. begin
  183. Application.HintPause := 200;
  184. Application.HintHidePause := 60000;
  185. tobtnImport.Visible := False;
  186. stdProjects.TreeOptions := stdProjects.TreeOptions - [aoAllowUpLevel, aoAllowDownLevel];
  187. stdProjects.Options := stdProjects.Options - [aoAllowUpMove, aoAllowDownMove];
  188. CreateProgress('正在从云端下载新项目');
  189. try
  190. actnReceiveProject.Execute;
  191. finally
  192. CloseProgress;
  193. end;
  194. end;
  195. end;
  196. function SearchFileOnline(AURL: string; var ADownURL, AFolder, ASubFolder, ABidName, AMD5Web, AError: string;
  197. var AFolderID, ASubFolderID: Integer): Integer;
  198. var vArr: TOVArr;
  199. begin
  200. Result := PHPWeb.Search(AURL, [''], [''], vArr);
  201. AError := '';
  202. if Result = 1 then
  203. begin
  204. if High(vArr) >= 0 then
  205. begin
  206. ADownURL := vArr[0, 0];
  207. AFolder := vArr[0, 2];
  208. ASubFolder := vArr[0, 3];
  209. AMD5Web := vArr[0, 1];
  210. AFolderID := StrToInt(vArr[0, 4]);
  211. ASubFolderID := StrToInt(vArr[0, 5]);
  212. ABidName := vArr[0, 6];
  213. end
  214. else
  215. Result := 10; // 返回10,表示无记录。用这个数字代表是否觉得怪异?没办法,0被占用了。
  216. end
  217. else if Result = 0 then
  218. AError := PHPWeb.PageError('标段更新数据失败')
  219. else if Result = -1 then
  220. AError := PHPWeb.NetError('标段更新数据失败');
  221. end;
  222. // 双击打开项目 TagB
  223. procedure TProjectManagerFrame.actnOpenExecute(Sender: TObject);
  224. var
  225. vSel: TsdIDTreeNode;
  226. vRec: TsdDataRecord;
  227. sHint: string;
  228. function CanOpen: Boolean;
  229. var
  230. sSearchURL, sDownURL,
  231. sMD5_UnLock, sError, sLocalFile: string;
  232. iSearch, iFolderID, iSubFolderID: Integer;
  233. function HasWebBidInfo(AWebID: Integer): Boolean;
  234. var vArr: array of string;
  235. iResult: Integer;
  236. begin
  237. sSearchURL := Format('%stender/get/%d/exist', [PHPWeb.MeasureURL, AWebID]);
  238. vArr := VarArrayOf(['id', 'name']);
  239. iResult := PHPWeb.Search(sSearchURL, [''], [''], vArr);
  240. if (iResult = 1) and (High(vArr) >= 0) then
  241. Result := True
  242. else
  243. Result := False;
  244. end;
  245. begin
  246. Result := False;
  247. // 先按正常接口找到最新的MD5码看是否需要更新
  248. sSearchURL := Format('%stender/get/%d/update', [PHPWeb.MeasureURL, FWebID]);
  249. iSearch := SearchFileOnline(sSearchURL, sDownURL, FWebFolder_OnLine, FWebSubFolder_OnLine, FWebBidName_OnLine, FWebMD5_OnLine, sError, iFolderID, iSubFolderID);
  250. if iSearch = 1 then
  251. begin
  252. try
  253. CheckWebFolders(iFolderID, iSubFolderID, FWebFolder_OnLine, FWebSubFolder_OnLine);
  254. CheckBidName(FID, FWebBidName_OnLine);
  255. finally
  256. if vSel <> nil then
  257. vSel.LocateInControl;
  258. end;
  259. // 打开前一定要先下载最新的标段文件(无论审核有没有通过)
  260. if FWebMD5_OnLine <> FWebMD5_Local then
  261. if not FileDownAndReceive(sDownURL, 1) then Exit;
  262. // 编制人且项目末通过
  263. if (FWebAuthorID = PHPWeb.UserID) and (FWebCheckStatusProject = csNotPass) then
  264. begin
  265. sHint := '本期计量审批不通过,你现在可以:' + #10#13 + '点击【是(Y)】重新开始本期计量,软件将打开本期上报时的数据,开始重新计量;' +
  266. #10#13 +'点击【否(N)】查看不通过计量,软件将打开本期最后审批的数据,重新打开标段' + '可再次打开本确认窗口。';
  267. if Application.MessageBox(PChar(sHint), '询问', MB_YESNO + MB_ICONQUESTION) = ID_Yes then
  268. begin
  269. sSearchURL := Format('%suser/create/%d/%d/new/audit', [PHPWeb.MeasureURL, FWebID, FPhaseNo]);
  270. case SearchFileOnline(sSearchURL, sDownURL, FWebFolder_OnLine, FWebSubFolder_OnLine, FWebBidName_OnLine, sMD5_UnLock, sError, iFolderID, iSubFolderID) of
  271. 1:
  272. begin
  273. if not FileDownAndReceive(sDownURL, 2) then Exit;
  274. end;
  275. 0, -1:
  276. begin
  277. sHint := sError + '(因网络出错,无法连接到云端以获取本期原报上传的无锁文件,无法重新开始本期,本次操作已取消。请重试。';
  278. Application.MessageBox(PChar(sHint), '警告', MB_OK + MB_ICONWARNING);
  279. Exit;
  280. end;
  281. end;
  282. end;
  283. end;
  284. end
  285. else if (iSearch = 10) then
  286. begin
  287. if not HasWebBidInfo(FWebID) then
  288. begin
  289. sHint :='该项目[' + FWebBidName_Local + ']在云端已被删除,点击"确定"后,可手动删除该项目。';
  290. Application.MessageBox(PChar(sHint), '提示', MB_OK + MB_ICONINFORMATION);
  291. Exit;
  292. end;
  293. end
  294. else if (iSearch = 0) or (iSearch = -1) then
  295. begin
  296. sHint := sError + '(因网络出错,无法检测[' + FWebBidName_Local + ']在云端是否有更新,本次操作已取消,请重试)。';
  297. Application.MessageBox(PChar(sHint), '警告', MB_OK + MB_ICONWARNING);
  298. Exit;
  299. end;
  300. Result := True;
  301. end;
  302. begin
  303. // 打开前先下载更新
  304. Screen.Cursor := crHourGlass;
  305. try
  306. vSel := stdProjects.IDTree.Selected;
  307. vRec := vSel.Rec;
  308. if G_IsCloud then
  309. begin
  310. GetLocalValues(CurRec);
  311. // 以下这段已经包含在MainForm.OpenProject(vRec)中了,但在调用这句之前,网络版要提前用一下。
  312. if MainForm.HasOpened(FID) then
  313. begin
  314. MainForm.LocateProject(FID);
  315. Exit;
  316. end;
  317. if not CanOpen then
  318. Exit;
  319. end;
  320. MainForm.OpenProject(vRec);
  321. if G_IsCloud then
  322. begin
  323. if not MainForm.CurProjectFrame.CheckFileAndCloudChekerList then
  324. begin
  325. sHint := '项目校验:“' + FWebBidName_OnLine + '”文件中的审核人和云端的审核人不一致,' +
  326. '禁止继续操作,项目即将关闭!请删除本地项目重新从云端获取,' +
  327. '重新获取后如果仍然存在同样的问题,请联系纵横服务人员以寻求帮助。';
  328. Application.MessageBox(PChar(sHint), '文件错误', MB_OK +MB_ICONWARNING);
  329. MainForm.actnCloseProject.Execute;
  330. Exit;
  331. end;
  332. end;
  333. finally
  334. Screen.Cursor := crDefault;
  335. end;
  336. end;
  337. procedure TProjectManagerFrame.actnDeleteExecute(Sender: TObject);
  338. begin
  339. if stdProjects.IDTree.Count = 0 then Exit;
  340. with stdProjects.IDTree.Selected.Rec do
  341. if QuestMessage(Format('确定要删除[%s]吗?', [ValueByName('Name').AsString])) then
  342. begin
  343. Screen.Cursor := crHourGlass;
  344. try
  345. FProjectManagerData.Delete;
  346. finally
  347. Screen.Cursor := crDefault;
  348. end;
  349. end;
  350. end;
  351. procedure TProjectManagerFrame.zgProjectsMouseDown(Sender: TObject;
  352. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  353. begin
  354. if Button = mbRight then
  355. dxpmProjectManager.PopupFromCursorPos
  356. else if (zgProjects.CurCol = 1) and (Button = mbLeft) and (ssDouble in Shift)
  357. and Assigned(stdProjects.IDTree.Selected) then
  358. begin
  359. if IsProject(stdProjects.IDTree.Selected) then
  360. stdProjects.IDTree.Selected.Expand
  361. else
  362. actnOpen.Execute;
  363. end;
  364. end;
  365. function TProjectManagerFrame.ReceiveFile(const AFileName: string; AFileMD5: string;
  366. ANeedLock: Boolean): Boolean;
  367. var
  368. Recevier: TReceiveProject;
  369. vNode: TsdIDTreeNode;
  370. begin
  371. Result := False;
  372. Recevier := TReceiveProject.Create(stdProjects.IDTree.Selected);
  373. try
  374. try
  375. if G_IsCloud then
  376. Recevier.Lock := ANeedLock;
  377. ProjectManager.RefreshSeedID;
  378. vNode := Recevier.Receive(AFileName);
  379. if G_IsCloud then
  380. begin
  381. vNode.Rec.BeginUpdate;
  382. vNode.Rec.ValueByName('WebMD5').AsString := AFileMD5;
  383. vNode.Rec.ValueByName('WebUserID').AsInteger := PHPWeb.UserID;
  384. vNode.Rec.EndUpdate;
  385. end;
  386. vNode.LocateInControl;
  387. Result := True;
  388. except
  389. Result := False;
  390. end;
  391. finally
  392. if Recevier.MessageID = 1 then
  393. ErrorMessage('当前标段处于打开状态,未能成功接收,请先关闭标段再次接收。');
  394. Recevier.Free;
  395. FProjectManagerData.Save;
  396. end;
  397. end;
  398. // 登录后自动扫描等待我审核的项目 TagC
  399. procedure TProjectManagerFrame.actnReceiveProjectExecute(Sender: TObject);
  400. procedure DoReceiveLocal;
  401. var
  402. sFileName: string;
  403. begin
  404. if SelectFile(sFileName, '.rmf;*.arf') then
  405. begin
  406. ShowProgressHint('正在接收项目并升级数据');
  407. try
  408. ReceiveFile(sFileName);
  409. finally
  410. CloseProgressHint;
  411. end;
  412. end;
  413. end;
  414. var OnCC: TZjCellNotifyEvent;
  415. begin
  416. Screen.Cursor := crHourGlass;
  417. try
  418. if G_IsCloud then
  419. begin
  420. OnCC := zgProjects.OnCurrentChanged;
  421. try
  422. zgProjects.OnCurrentChanged := nil;
  423. DoBatchReceiveOnline(1);
  424. if stdProjects.IDTree.FirstNode <> nil then
  425. stdProjects.IDTree.FirstNode.LocateInControl;
  426. finally
  427. zgProjects.OnCurrentChanged := OnCC;
  428. end;
  429. end
  430. else
  431. DoReceiveLocal;
  432. finally
  433. Screen.Cursor := crDefault;
  434. end;
  435. end;
  436. function TProjectManagerFrame.GetImportProjectName(
  437. const AFileName: string; AParent: TsdIDTreeNode): string;
  438. begin
  439. Result := ExtractSimpleFileName(AFileName);
  440. while FProjectManagerData.ExistProject(Result, AParent) do
  441. if not InputNewProjectName(Result, '导入', AParent) then Abort;
  442. end;
  443. procedure TProjectManagerFrame.actnNewProjectExecute(Sender: TObject);
  444. var
  445. sName: string;
  446. begin
  447. if G_IsCloud then Exit; // 云版线上与本地要保持同步,不允许本地新建
  448. if InputNewProjectName(sName, '新建', stdProjects.IDTree.Selected) then
  449. FProjectManagerData.InsertProject(sName, stdProjects.IDTree.Selected);
  450. end;
  451. procedure TProjectManagerFrame.actnNewSubProjectExecute(Sender: TObject);
  452. var
  453. sName: string;
  454. begin
  455. if G_IsCloud then Exit;
  456. if InputNewProjectName(sName, '新建', stdProjects.IDTree.Selected) then
  457. FProjectManagerData.InsertSubProject(sName, stdProjects.IDTree.Selected);
  458. end;
  459. procedure TProjectManagerFrame.actnNewTenderExecute(Sender: TObject);
  460. function AddAndOpenTender(const ATenderName: string): TsdIDTreeNode;
  461. begin
  462. Result := FProjectManagerData.InsertTender(ATenderName, stdProjects.IDTree.Selected);
  463. MainForm.OpenProject(Result.Rec);
  464. end;
  465. // 网络版新建标段 TagD
  466. procedure NewProjectWithOnline;
  467. var
  468. WebNewTenderForm: TWebNewTenderForm;
  469. sName, sKey, sURL: string;
  470. stnNew: TsdIDTreeNode;
  471. iID, iFolderID, iSubFolderID: Integer;
  472. vRec: TsdDataRecord;
  473. vArr: array of string;
  474. begin
  475. WebNewTenderForm := TWebNewTenderForm.Create(nil);
  476. try
  477. WebNewTenderForm.ShowModal;
  478. if WebNewTenderForm.ModalResult = mrOK then
  479. begin
  480. sKey := WebNewTenderForm.edtKey.Text;
  481. sName := WebNewTenderForm.edtTenderName.Text;
  482. // 同服务器取得联系
  483. iID := -1;
  484. vArr := VarArrayOf(['catid', 'name', 'company', 'phone', 'mobile', 'qq',
  485. 'pname', 'ptype', 'jobs', 'avatar', 'ownuid', 'pnameid', 'ptypeid']);
  486. sURL := Format('%s%d/%s/%s/creatmeasure', [PHPWeb.MeasureURL, PHPWeb.UserID, sName, sKey]); // AnsiToUtf8(sName)
  487. case PHPWeb.Search(sURL, [], [], vArr) of
  488. 1:
  489. begin
  490. iID := StrToInt(vArr[0]);
  491. iFolderID := StrToInt(vArr[11]);
  492. iSubFolderID := StrToInt(vArr[12]);
  493. CheckWebFolders(iFolderID, iSubFolderID, vArr[6], vArr[7]);
  494. end;
  495. 0:
  496. begin
  497. Application.MessageBox(PChar(PHPWeb.PageError('创建标段失败' + '[' + vArr[0] + ']')),
  498. '警告', MB_OK + MB_ICONWARNING);
  499. Exit;
  500. end;
  501. -1:
  502. begin
  503. Application.MessageBox(PChar(PHPWeb.NetError('创建标段失败')),
  504. '警告', MB_OK + MB_ICONWARNING);
  505. Exit;
  506. end;
  507. end;
  508. // 本地创建
  509. stnNew := FProjectManagerData.InsertTender(sName, stdProjects.IDTree.Selected);
  510. // 这里把Web获取的信息存储到项目管理里面。
  511. vRec := stnNew.Rec;
  512. vRec.BeginUpdate;
  513. vRec.ValueByName('WebID').AsInteger := iID;
  514. vRec.ValueByName('WebOwnerID').AsInteger := StrToInt(vArr[10]); // 业主
  515. vRec.ValueByName('WebAuthorID').AsInteger := PHPWeb.UserID; // 编制人
  516. vRec.ValueByName('WebUserID').AsInteger := PHPWeb.UserID; // 当前用户,用于只显示自己的项目
  517. vRec.ValueByName('WebKey').AsString := sKey;
  518. vRec.EndUpdate;
  519. GetLocalValues(vRec);
  520. FWebOwnerName := vArr[1];
  521. FWebOwnerCompany := vArr[2];
  522. FWebOwnerRole := vArr[8];
  523. FWebFolder_OnLine := vArr[6];
  524. FWebSubFolder_OnLine := vArr[7];
  525. // WebOwnerImage := vArr[9];
  526. // WebOwnerPhone := vArr[3];
  527. // WebOwnerMobile := vArr[4];
  528. // WebOwnerQQ := vArr[5];
  529. ShowProjectInfoTop(0);
  530. FProjectManagerData.Save;
  531. MainForm.OpenProject(vRec);
  532. end;
  533. finally
  534. WebNewTenderForm.Free;
  535. end;
  536. end;
  537. procedure NewProject;
  538. var
  539. sName: string;
  540. begin
  541. if InputNewProjectName(sName, '新建', stdProjects.IDTree.Selected) then
  542. AddAndOpenTender(sName);
  543. end;
  544. begin
  545. if G_IsCloud then
  546. NewProjectWithOnline
  547. else
  548. NewProject;
  549. end;
  550. procedure TProjectManagerFrame.zgProjectsDrawCellText(ACanvas: TCanvas;
  551. const ARect: TRect; const ACoord: TPoint; AGrid: TZJGrid;
  552. const Text: String; var ADefaultDraw: Boolean);
  553. procedure GetBitmap(AImage: TBitmap);
  554. begin
  555. with stdProjects.IDTree.Items[ACoord.Y - 1] do
  556. if Rec.ValueByName('Type').AsInteger = 0 then
  557. if Expanded and HasChildren then
  558. MainForm.Images.GetBitmap(34, AImage)
  559. else
  560. MainForm.Images.GetBitmap(34, AImage)
  561. else
  562. MainForm.Images.GetBitmap(11, AImage);
  563. end;
  564. const
  565. rIconWidth = 16;
  566. rIconHeight = 16;
  567. var
  568. Img: TBitmap;
  569. Cell: TZjCell;
  570. rImg: TRect;
  571. begin
  572. if (ACoord.X = 1) and (ACoord.Y > zgProjects.FixedRowCount - 1) then
  573. begin
  574. Cell := zgProjects.Cells[ACoord.X, ACoord.Y];
  575. Img := TBitmap.Create;
  576. try
  577. GetBitmap(Img);
  578. case Cell.Align of
  579. gaTopLeft, gaTopCenter, gaTopRight:
  580. rImg := Rect(ARect.Left + 2, ARect.Top, ARect.Left + rIconWidth, ARect.Top + rIconHeight);
  581. gaCenterLeft, gaCenterCenter, gaCenterRight:
  582. rImg := Rect(ARect.Left + 2, ARect.Top + (ARect.Bottom - ARect.Top - rIconHeight) div 2, ARect.Left + rIconWidth, ARect.Bottom - (ARect.Bottom - ARect.Top - rIconHeight) div 2);
  583. gaBottomLeft, gaBottomCenter, gaBottomRight:
  584. rImg := Rect(ARect.Left + 2, ARect.Bottom - rIconHeight, ARect.Left + rIconWidth, ARect.Bottom);
  585. end;
  586. ACanvas.StretchDraw(rImg, Img);
  587. WriteText(ACanvas, Rect(ARect.Left + rIconWidth, ARect.Top, ARect.Right, ARect.Bottom)
  588. , 2, 2, Text, Cell.Align, False);
  589. ADefaultDraw := False;
  590. finally
  591. Img.Free;
  592. end;
  593. end;
  594. end;
  595. procedure TProjectManagerFrame.actnNewSubProjectUpdate(Sender: TObject);
  596. begin
  597. TAction(Sender).Enabled := Assigned(stdProjects.IDTree.Selected)
  598. and IsProject(stdProjects.IDTree.Selected)
  599. and (not IsUnEmptyLeafProject(stdProjects.IDTree.Selected));
  600. end;
  601. procedure TProjectManagerFrame.actnNewTenderUpdate(Sender: TObject);
  602. var bCloud: Boolean;
  603. vNode: TsdIDTreeNode;
  604. begin
  605. bCloud := G_IsCloud;
  606. // 只有编制人才能创建新标段?逻辑先后有问题:编制人是在创建标段之后产生的。
  607. // 创建前,当前用户只是一个帐户,它是不是编制人末知,因为它还可以是其它角色。
  608. // 同一帐户在不同的标段可以作为不同的角色。
  609. if bCloud then
  610. begin
  611. TAction(Sender).Enabled := True;
  612. end
  613. else
  614. begin
  615. vNode := stdProjects.IDTree.Selected;
  616. TAction(Sender).Enabled := Assigned(vNode) and IsProject(vNode) and IsLeafProject(vNode);
  617. end;
  618. end;
  619. function TProjectManagerFrame.IsLeafProject(ANode: TsdIDTreeNode): Boolean;
  620. begin
  621. if ANode.HasChildren then
  622. Result := ANode.FirstChild.Rec.ValueByName('Type').AsInteger = 1
  623. else
  624. Result := ANode.Rec.ValueByName('Type').AsInteger = 0;
  625. end;
  626. function TProjectManagerFrame.IsProject(ANode: TsdIDTreeNode): Boolean;
  627. begin
  628. Result := ANode.Rec.ValueByName('Type').AsInteger = 0;
  629. end;
  630. function TProjectManagerFrame.IsUnEmptyLeafProject(
  631. ANode: TsdIDTreeNode): Boolean;
  632. begin
  633. Result := ANode.HasChildren and (ANode.Rec.ValueByName('Type').AsInteger = 1);
  634. end;
  635. procedure TProjectManagerFrame.SetPropertyVisible(AVisible: Boolean);
  636. begin
  637. // 单击刷新项目信息 TagA
  638. if G_IsCloud then
  639. begin
  640. if CurRec = nil then Exit;
  641. pnlTenderProperty.Visible := False;
  642. pnlWeb.Visible := AVisible;
  643. if AVisible then
  644. begin
  645. CreateProgress('云端读取项目信息');
  646. try
  647. ShowProjectInfoTopAndCheckers;
  648. finally
  649. CloseProgress;
  650. end;
  651. end;
  652. end
  653. else
  654. begin
  655. pnlWeb.Visible := False;
  656. pnlTenderProperty.Visible := AVisible;
  657. sprProperty.Visible := AVisible;
  658. end;
  659. end;
  660. procedure TProjectManagerFrame.zgProjectsCurrentChanged(Sender: TObject;
  661. Col, Row: Integer);
  662. begin
  663. if G_IsCloud then
  664. begin
  665. if CurRec <> nil then
  666. begin
  667. // 加这句后产生Bug:上报项目后,记录不曾移动,FID不变,不会刷新
  668. // if FID <> CurRec.ValueByName('ID').AsInteger then
  669. SetPropertyVisible(CurRec.ValueByName('Type').AsInteger = 1);
  670. // OnCurrentChanged取得的 CurRec.ValueByName() 值并不总是可靠,这里加保险。
  671. // 如调用locateInControl后,执行到这里取得的CurRec.ValueByName('ID')值还是上一条的。
  672. if (CurRec.ValueByName('Type').AsInteger = 1) and (not pnlWeb.Visible) then
  673. pnlWeb.Visible := True;
  674. end;
  675. end;
  676. end;
  677. procedure TProjectManagerFrame.actnSubmitProjectUpdate(Sender: TObject);
  678. begin
  679. TAction(Sender).Enabled := Assigned(stdProjects.IDTree.Selected)
  680. and (stdProjects.IDTree.Selected.Rec.ValueByName('Type').AsInteger = 1)
  681. and (stdProjects.IDTree.Selected.Rec.ValueByName('AuditStatus').AsInteger < iMaxStageCount-1);
  682. end;
  683. procedure TProjectManagerFrame.actnReplyProjectUpdate(Sender: TObject);
  684. begin
  685. TAction(Sender).Enabled := Assigned(stdProjects.IDTree.Selected)
  686. and (stdProjects.IDTree.Selected.Rec.ValueByName('Type').AsInteger = 1);
  687. end;
  688. procedure TProjectManagerFrame.actnRenameExecute(Sender: TObject);
  689. function CanRename(ARec: TsdDataRecord; const ANewName: string): Boolean;
  690. var
  691. sURL: string;
  692. iRename: Integer;
  693. vArr: array of string;
  694. begin
  695. Result := True;
  696. if not G_IsCloud then Exit;
  697. // 云版 重命名须确保同步服务器
  698. sURL := Format('%stender/%d/%s/update', [PHPWeb.MeasureURL, ARec.ValueByName('WebID').AsInteger, ANewName]);
  699. iRename := PHPWeb.Search(sURL, [], [], vArr);
  700. Result := iRename = 1;
  701. case iRename of
  702. 1: ShowMessage('新的标段名称已同步到服务器!');
  703. 0: Application.MessageBox(PChar(PHPWeb.PageError('重命名同步到云端失败' + '[' + vArr[0] + ']')),
  704. '警告', MB_OK + MB_ICONWARNING);
  705. -1: Application.MessageBox(PChar(PHPWeb.NetError('重命名同步到云端失败')),
  706. '警告', MB_OK + MB_ICONWARNING);
  707. end;
  708. end;
  709. var
  710. stnNode: TsdIDTreeNode;
  711. sName: string;
  712. begin
  713. stnNode := stdProjects.IDTree.Selected;
  714. sName := stnNode.Rec.ValueByName('Name').AsString;
  715. if not Assigned(OpenProjectManager.FindProjectData(stnNode.ID)) then
  716. begin
  717. if InputNewProjectName(sName, '重命名', stnNode.Parent, stnNode.ID) then
  718. begin
  719. if CanRename(stnNode.Rec, sName) then
  720. begin
  721. stnNode.Rec.ValueByName('Name').AsString := sName;
  722. ProjectManager.Save;
  723. end;
  724. end;
  725. end
  726. else
  727. ErrorMessage(Format('项目[%s]已经打开,无法重命名!', [sName]));
  728. end;
  729. procedure TProjectManagerFrame.actnOpenUpdate(Sender: TObject);
  730. begin
  731. TAction(Sender).Enabled := Assigned(stdProjects.IDTree.Selected)
  732. and (stdProjects.IDTree.Selected.Rec.ValueByName('Type').AsInteger = 1);
  733. end;
  734. procedure TProjectManagerFrame.actnImportExecute(Sender: TObject);
  735. procedure ImportTender(const AFileName, AProjectName: string);
  736. var
  737. Importor: TTenderImport;
  738. begin
  739. Importor := TTenderImport.Create(stdProjects.IDTree.Selected,
  740. AProjectName, AFileName);
  741. try
  742. Importor.Execute;
  743. finally
  744. Importor.Free;
  745. end;
  746. end;
  747. procedure ImportProject(const AFileName, AProjectName: string);
  748. var
  749. Importor: TProjectImport;
  750. begin
  751. Importor := TProjectImport.Create(stdProjects.IDTree.Selected,
  752. AProjectName, AFileName);
  753. try
  754. Importor.Execute;
  755. finally
  756. Importor.Free;
  757. end;
  758. end;
  759. var
  760. sFileName, sProjectName: string;
  761. begin
  762. if SelectFile(sFileName, '.mtf;*.mpf') then
  763. begin
  764. if SameText(ExtractFileExt(sFileName), '.mtf')
  765. and (stdProjects.IDTree.Selected.Rec.ValueByName('Type').AsInteger = 0) then
  766. sProjectName := GetImportProjectName(sFileName, stdProjects.IDTree.Selected)
  767. else
  768. sProjectName := GetImportProjectName(sFileName, stdProjects.IDTree.Selected.Parent);
  769. Screen.Cursor := crHourGlass;
  770. try
  771. if SameText(ExtractFileExt(sFileName), '.mtf') then
  772. ImportTender(sFileName, sProjectName)
  773. else
  774. ImportProject(sFileName, sProjectName);
  775. finally
  776. Screen.Cursor := crDefault;
  777. end;
  778. end;
  779. FProjectManagerData.Save;
  780. end;
  781. procedure TProjectManagerFrame.actnExportExecute(Sender: TObject);
  782. procedure ExportTender(ANode: TsdIDTreeNode);
  783. var
  784. Exportor: TTenderExport;
  785. sFileName, sHint: string;
  786. bExpAtch: Boolean;
  787. iCount: Integer;
  788. begin
  789. bExpAtch := False;
  790. sFileName := SupportManager.ConfigInfo.OutputPath + ANode.Rec.ValueByName('Name').AsString + '.mtf';
  791. if SaveFile(sFileName, '.mtf') then
  792. begin
  793. if FileExists(sFileName) and not QuestMessage(Format('存在同名文件“%s”,是否替换?', [ExtractFileName(sFileName)])) then
  794. Exit;
  795. Screen.Cursor := crHourGlass;
  796. try
  797. Exportor := TTenderExport.Create(ANode.Rec, sFileName);
  798. try
  799. { if not G_IsCloud then
  800. begin
  801. iCount := FileCount(CurRecAttachmentPath);
  802. if iCount > 1 then // 排除管理文件库
  803. begin
  804. sHint := Format('本标段包含 %d 个附件,是否将附件一起导出?', [iCount - 1]);
  805. bExpAtch := Application.MessageBox(PChar(sHint), '询问', MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2) = ID_Yes;
  806. end;
  807. end; } // FFFFF
  808. Exportor.Execute(bExpAtch);
  809. finally
  810. Exportor.Free;
  811. end;
  812. finally
  813. Screen.Cursor := crDefault;
  814. end;
  815. end;
  816. end;
  817. procedure ExportProject(ANode: TsdIDTreeNode);
  818. var
  819. Exportor: TProjectExport;
  820. sFileName, sHint: string;
  821. bExpAtch: Boolean;
  822. iCount: Integer;
  823. begin
  824. sFileName := SupportManager.ConfigInfo.OutputPath + ANode.Rec.ValueByName('Name').AsString + '.mpf';
  825. if SaveFile(sFileName, '.mpf') then
  826. begin
  827. if FileExists(sFileName) and not QuestMessage(Format('存在同名文件“%s”,是否替换?', [ExtractFileName(sFileName)])) then
  828. Exit;
  829. Screen.Cursor := crHourGlass;
  830. try
  831. bExpAtch := False;
  832. { if not G_IsCloud then
  833. begin
  834. iCount := AttachmentFileCountsWithoutManageFile(ANode);
  835. if iCount > 0 then
  836. begin
  837. sHint := Format('本建设项目共包含 %d 个附件,是否将附件一起导出?', [iCount]);
  838. bExpAtch := Application.MessageBox(PChar(sHint), '询问', MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2) = ID_Yes;
  839. end;
  840. end; } // FFFFF
  841. Exportor := TProjectExport.Create(ANode, sFileName, bExpAtch);
  842. try
  843. Exportor.Execute;
  844. finally
  845. Exportor.Free;
  846. end;
  847. finally
  848. Screen.Cursor := crDefault;
  849. end;
  850. end;
  851. end;
  852. var
  853. stnNode: TsdIDTreeNode;
  854. begin
  855. stnNode := stdProjects.IDTree.Selected;
  856. if stnNode.Rec.ValueByName('Type').AsInteger = 1 then
  857. begin
  858. ExportTender(stnNode);
  859. end
  860. else
  861. ExportProject(stnNode);
  862. end;
  863. procedure TProjectManagerFrame.actnDeleteUpdate(Sender: TObject);
  864. begin
  865. if Assigned(stdProjects.IDTree.Selected) then
  866. TAction(Sender).Enabled := not CheckOpened(stdProjects.IDTree.Selected);
  867. end;
  868. function TProjectManagerFrame.CheckOpened(ANode: TsdIDTreeNode): Boolean;
  869. var
  870. iChild: Integer;
  871. begin
  872. Result := False;
  873. if ANode.Rec.ValueByName('Type').AsInteger = 1 then
  874. Result := OpenProjectManager.ProjectIndex(ANode.ID) > -1
  875. else
  876. begin
  877. if not ANode.HasChildren then
  878. Result := False
  879. else
  880. begin
  881. for iChild := 0 to ANode.ChildCount - 1 do
  882. Result := Result or CheckOpened(ANode.ChildNodes[iChild]);
  883. end
  884. end;
  885. end;
  886. procedure TProjectManagerFrame.ShowProjectInfoTopAndCheckers;
  887. var
  888. vPSArr: TStrArr;
  889. vCArr: TOVArr; // Checkers
  890. vChecker: TOrderCheckerFrame;
  891. sPicPath, sURL: string;
  892. procedure AddChecker(AType: TCheckerFrameType; AArr: array of string);
  893. begin
  894. vChecker := TOrderCheckerFrame.Create(self);
  895. FCheckerList.Add(vChecker);
  896. vChecker.Owner := Self;
  897. sbChecker.VertScrollBar.Range := sbChecker.VertScrollBar.Range + vChecker.Height;
  898. sbChecker.Height := Min(sbChecker.Height + vChecker.Height, pnlWeb.Height - pnlProject.Height);
  899. vChecker.Parent := sbChecker;
  900. vChecker.Top := FCurPos;
  901. FCurPos := FCurPos + vChecker.Height;
  902. vChecker.Align := alTop;
  903. sPicPath := PHPWeb.UserPath + '1_' + AArr[0] + '.jpg';
  904. PHPWeb.DownFile(AArr[4], sPicPath);
  905. vChecker.Init(AType, StrToInt(AArr[0]), AArr[1], AArr[3],
  906. AArr[2], sPicPath, AArr[6], TCheckStatus(StrToInt(AArr[5])-1), AArr[8], StrToInt(AArr[7]));
  907. vChecker.Name := 'ProjectOrderFrame' + AArr[0];
  908. end;
  909. procedure RepairOrder;
  910. var k: Integer;
  911. begin
  912. for k := 0 to sbChecker.ControlCount - 1 do
  913. TOrderCheckerFrame(sbChecker.Controls[k]).Order := k + 1;
  914. end;
  915. procedure ShowProjectCheckers;
  916. var i, j, n: Integer;
  917. vOwner: array of string; // 业主信息
  918. begin
  919. FCheckerList.Clear;
  920. sbChecker.Height := 0;
  921. FCurPos := 0;
  922. n := Length(vCArr[Low(vCArr)]);
  923. SetLength(vOwner, n);
  924. sbChecker.VertScrollBar.Range := 0;
  925. for i := Low(vCArr) to High(vCArr) do
  926. begin
  927. if StrToInt(vCArr[i, 0]) = PHPWeb.UserID then
  928. FWebCheckStatusMy := TCheckStatus(StrToInt(vCArr[i, 5])-1);
  929. if StrToInt(vCArr[i, 0]) = FWebOwnerID then
  930. begin
  931. for j := 0 to n - 1 do
  932. vOwner[j] := vCArr[i, j];
  933. Continue;
  934. end;
  935. AddChecker(cftChecker, vCArr[i]);
  936. end;
  937. if vOwner[0] <> '' then
  938. AddChecker(cftOwner, vOwner);
  939. RepairOrder;
  940. OnLineChecker(vCArr, FOnLineCheckerBegin, FOnLineCheckerEnd);
  941. end;
  942. begin
  943. GetLocalValues(CurRec);
  944. if FWebID = 0 then Exit;
  945. SetLength(vPSArr, 8);
  946. sURL := Format('%smeasure/status/%d/get', [PHPWeb.MeasureURL, FWebID]);
  947. if PHPWeb.Search(sURL, [''], [''], 3, vPSArr, vCArr) = 1 then
  948. begin
  949. LockWindowUpdate(pnlWeb.Handle);
  950. try
  951. FPhaseNo := StrToInt(vPSArr[0]);
  952. FWebCheckStatusProject := TCheckStatus(StrToInt(vPSArr[1])-1);
  953. FPhaseTotal := StrToInt(vPSArr[2]);
  954. FWebFolder_OnLine := vPSArr[3];
  955. FWebSubFolder_OnLine := vPSArr[4];
  956. FWebOwnerName := vPSArr[5];
  957. FWebOwnerCompany := vPSArr[6];
  958. FWebOwnerRole := vPSArr[7];
  959. ShowProjectInfoTop;
  960. ShowProjectCheckers;
  961. finally
  962. LockWindowUpdate(0);
  963. end;
  964. end
  965. else
  966. begin
  967. FPhaseNo := 0;
  968. FWebCheckStatusProject := csNotBegin;
  969. FPhaseTotal := 0;
  970. FWebFolder_OnLine := '';
  971. FWebSubFolder_OnLine := '';
  972. FWebOwnerName := '';
  973. FWebOwnerCompany := '';
  974. FWebOwnerRole := '';
  975. ShowProjectInfoTop;
  976. sbChecker.Height := 0;
  977. end;
  978. end;
  979. procedure TProjectManagerFrame.ShowProjectInfoTop(AType: Integer);
  980. procedure ShowOwner;
  981. begin
  982. lblBidName.Caption := FWebBidName_Local;
  983. lblBidName.Update;
  984. lblProjName.Caption := FWebFolder_OnLine;
  985. lblProjName.Update;
  986. lblWebProjCtgyName.Caption := FWebSubFolder_OnLine;
  987. lblWebProjCtgyName.Update;
  988. lblOnwerName.Caption := FWebOwnerName;
  989. lblOnwerName.Update;
  990. lblOnwerCompany.Caption := Format('-%s)', [FWebOwnerCompany]);
  991. lblOnwerCompany.Update;
  992. lblOnwerCompany.Left := lblOnwerName.Left + lblOnwerName.Width;
  993. end;
  994. procedure ShowStatus(ANo: Integer; AState: TCheckStatus);
  995. begin
  996. lblPeriod.Caption := Format('第%d期', [ANo]);
  997. lblPeriod.Update;
  998. lblPeriodState.Caption := CheckStatusNames[AState];
  999. lblPeriodState.Font.Color := CheckStatusColors[AState];
  1000. lblPeriodState.Update;
  1001. lblPeriodState.Left := lblPeriod.Left + lblPeriod.Width + 5;
  1002. lblPeriodTotal.Caption := Format('(共%d期)', [ANo]);
  1003. lblPeriodTotal.Update;
  1004. lblPeriodTotal.Left := lblPeriodState.Left + lblPeriodState.Width + 3;
  1005. end;
  1006. begin
  1007. GetLocalValues(CurRec);
  1008. case AType of
  1009. -2:
  1010. begin
  1011. lblPeriod.Caption := '正在从云端读取状态信息...';
  1012. lblPeriod.Update;
  1013. end;
  1014. -1:
  1015. begin
  1016. ShowOwner;
  1017. ShowStatus(FPhaseNo, FWebCheckStatusProject);
  1018. end;
  1019. 0:
  1020. begin
  1021. ShowOwner;
  1022. ShowStatus(0, csNotBegin);
  1023. end;
  1024. end;
  1025. end;
  1026. // 检查后,应该定位到最后一层目录,不应该回到原先的选择节点。否则从网络拉下来的项目无法组织正确的树结构。
  1027. procedure TProjectManagerFrame.CheckWebFolders(AFolderID, ASubFolderID: Integer;
  1028. AFolderName, ASubFolderName: string);
  1029. var
  1030. vTree: TsdIDTree;
  1031. vNode, vSubNode: TsdIDTreeNode;
  1032. i: Integer;
  1033. sName: string;
  1034. iUserID, iWebID, iWebFolderLevel: Integer;
  1035. bExist, bSubExist, bModified: Boolean;
  1036. begin
  1037. bExist := False;
  1038. bSubExist := False;
  1039. bModified := False;
  1040. vTree := stdProjects.IDTree;
  1041. for i := 0 to vTree.Count - 1 do
  1042. begin
  1043. vNode := vTree.Items[i];
  1044. sName := vNode.Rec.ValueByName('Name').AsString;
  1045. iUserID := vNode.Rec.ValueByName('WebUserID').AsInteger;
  1046. iWebID := vNode.Rec.ValueByName('WebID').AsInteger;
  1047. iWebFolderLevel := vNode.Rec.ValueByName('WebFolderLevel').AsInteger;
  1048. if (iWebID = AFolderID) and (iWebFolderLevel = G_WFL_ProjName) and (iUserID = PHPWeb.UserID) then
  1049. begin
  1050. bExist := True;
  1051. vNode.LocateInControl;
  1052. if not SameText(sName, AFolderName) then
  1053. begin
  1054. vNode.Rec.ValueByName('Name').AsString := AFolderName;
  1055. bModified := True;
  1056. end;
  1057. Break;
  1058. end;
  1059. end;
  1060. if not bExist then
  1061. begin
  1062. vNode := vTree.Items[0];
  1063. if Assigned(vNode) then
  1064. vNode.LocateInControl;
  1065. vNode := FProjectManagerData.InsertProject(AFolderName, stdProjects.IDTree.Selected, AFolderID, G_WFL_ProjName);
  1066. vNode.LocateInControl;
  1067. end;
  1068. for i := 0 to vNode.ChildCount - 1 do
  1069. begin
  1070. vSubNode := vNode.ChildNodes[i];
  1071. sName := vSubNode.Rec.ValueByName('Name').AsString;
  1072. iUserID := vSubNode.Rec.ValueByName('WebUserID').AsInteger;
  1073. iWebID := vSubNode.Rec.ValueByName('WebID').AsInteger;
  1074. iWebFolderLevel := vSubNode.Rec.ValueByName('WebFolderLevel').AsInteger;
  1075. if (iWebID = ASubFolderID) and (iWebFolderLevel = G_WFL_BidType) and (iUserID = PHPWeb.UserID) then
  1076. begin
  1077. bSubExist := True;
  1078. vSubNode.LocateInControl;
  1079. if not SameText(sName, ASubFolderName) then
  1080. begin
  1081. vSubNode.Rec.ValueByName('Name').AsString := ASubFolderName;
  1082. bModified := True;
  1083. end;
  1084. Break;
  1085. end;
  1086. end;
  1087. if not bSubExist then
  1088. begin
  1089. vNode.LocateInControl;
  1090. vNode := FProjectManagerData.InsertSubProject(ASubFolderName, stdProjects.IDTree.Selected, ASubFolderID, G_WFL_BidType);
  1091. vNode.LocateInControl;
  1092. end;
  1093. if bModified then
  1094. ProjectManager.Save;
  1095. end;
  1096. function TProjectManagerFrame.Rec(AProjectID: Integer): TsdDataRecord;
  1097. var i: Integer;
  1098. vTree: TsdIDTree;
  1099. begin
  1100. vTree := stdProjects.IDTree;
  1101. if vTree.Selected.Rec.ValueByName('ID').AsInteger = AProjectID then
  1102. begin
  1103. Result := stdProjects.IDTree.Selected.Rec;
  1104. Exit;
  1105. end;
  1106. for i := 0 to vTree.Count - 1 do
  1107. begin
  1108. if vTree.Items[i].Rec.ValueByName('ID').AsInteger = AProjectID then
  1109. begin
  1110. Result := vTree.Items[i].Rec;
  1111. vTree.Items[i].LocateInControl;
  1112. Break;
  1113. end;
  1114. end;
  1115. end;
  1116. destructor TProjectManagerFrame.Destroy;
  1117. begin
  1118. FCheckerList.Free;
  1119. inherited;
  1120. end;
  1121. procedure TProjectManagerFrame.DoBatchReceiveOnline(ARequestType: Integer);
  1122. var
  1123. sURL, sHint: string;
  1124. vArr: TOVArr;
  1125. i, iFolderID, iSubFolderID: Integer;
  1126. begin
  1127. // 查询等待我审核的标段文件,杰哥说分三种:①业主未审核 ②业主审核中 ③审核人审核中 (为什么加①?问杰哥)
  1128. case PHPWeb.Search(PHPWeb.MeasureURL + 'user/get/audit/project', ['audituid', 'RequestType'],
  1129. [IntToStr(PHPWeb.UserID), IntToStr(ARequestType)], vArr) of
  1130. 1:
  1131. begin
  1132. CreateProgress('正在从云端下载新项目');
  1133. try
  1134. for i := Low(vArr) to High(vArr) do
  1135. begin
  1136. sURL := vArr[i, 0];
  1137. FWebFolder_OnLine := vArr[i, 1];
  1138. FWebSubFolder_OnLine := vArr[i, 2];
  1139. FWebMD5_OnLine := vArr[i, 3];
  1140. FWebID := StrToInt(vArr[i, 5]);
  1141. iFolderID := StrToInt(vArr[i, 6]);
  1142. iSubFolderID := StrToInt(vArr[i, 7]);
  1143. FWebCheckStatusMy := TCheckStatus(StrToInt(vArr[i, 8])-1); // vArr[i, 4]项目审核状态;vArr[i, 8]当前登陆用户的审核状态
  1144. FWebAuthorID := StrToInt(vArr[i, 9]);
  1145. FWebBidName_OnLine := vArr[i, 10];
  1146. FWebMD5_Local := LocalMD5(PHPWeb.UserID, FWebID);
  1147. CheckWebFolders(iFolderID, iSubFolderID, FWebFolder_OnLine, FWebSubFolder_OnLine);
  1148. CheckBidName(PHPWeb.UserID, FWebID, FWebBidName_OnLine);
  1149. if FWebMD5_OnLine <> FWebMD5_Local then
  1150. if not FileDownAndReceive(sURL, 1) then Exit;
  1151. end;
  1152. BubbleSortProjects;
  1153. finally
  1154. CloseProgress;
  1155. end;
  1156. end;
  1157. 0, -1:
  1158. begin
  1159. sHint := '网络出错,无法查询云端项目的更新情况,请重试!';
  1160. Application.MessageBox(PChar(sHint), '警告', MB_OK + MB_ICONWARNING);
  1161. Exit;
  1162. end;
  1163. end;
  1164. end;
  1165. function TProjectManagerFrame.ImportFile(const AFileName: string; AFileMD5: string): Boolean;
  1166. var
  1167. vImport: TTenderImport;
  1168. vNode: TsdIDTreeNode;
  1169. begin
  1170. Result := False;
  1171. vNode := stdProjects.IDTree.Selected;
  1172. vImport := TTenderImport.Create(vNode, '', AFileName);
  1173. try
  1174. try
  1175. vImport.ImportToSelect;
  1176. vNode.LocateInControl;
  1177. Result := True;
  1178. except
  1179. Result := False;
  1180. end;
  1181. finally
  1182. vImport.Free;
  1183. vNode.Rec.BeginUpdate;
  1184. vNode.Rec.ValueByName('WebMD5').AsString := AFileMD5;
  1185. vNode.Rec.ValueByName('WebUserID').AsInteger := PHPWeb.UserID;
  1186. vNode.Rec.EndUpdate;
  1187. FProjectManagerData.Save;
  1188. end;
  1189. end;
  1190. procedure TProjectManagerFrame.actnOpenBackupFolderExecute(
  1191. Sender: TObject);
  1192. var
  1193. stnNode: TsdIDTreeNode;
  1194. begin
  1195. stnNode := stdProjects.IDTree.Selected;
  1196. if stnNode.Rec.ValueByName('BackupFolder').AsString = '' then
  1197. TipMessage('该项目暂无备份数据!')
  1198. else
  1199. ShellExecute(Handle, 'open', 'Explorer.exe',
  1200. PChar(FProjectManagerData.BackupPath(stnNode.ID)), nil, 1);
  1201. end;
  1202. procedure TProjectManagerFrame.actnRenameUpdate(Sender: TObject);
  1203. var
  1204. Rec: TsdDataRecord;
  1205. bNet: Boolean;
  1206. begin
  1207. if stdProjects.IDTree.Selected = nil then Exit;
  1208. Rec := stdProjects.IDTree.Selected.Rec;
  1209. if Rec = nil then Exit;
  1210. bNet := G_IsCloud;
  1211. if bNet then
  1212. begin
  1213. tobtnRenane.Enabled := (Rec.ValueByName('Type').AsInteger = 1) and
  1214. (Rec.ValueByName('WebAuthorID').AsInteger = PHPWeb.UserID);
  1215. end;
  1216. end;
  1217. procedure TProjectManagerFrame.CheckBidName(AID: Integer; ANewBidName: string);
  1218. var vNode: TsdIDTreeNode;
  1219. begin
  1220. vNode := stdProjects.IDTree.FindNode(AID);
  1221. if vNode = nil then Exit;
  1222. if vNode.Rec.ValueByName('Name').AsString <> ANewBidName then
  1223. begin
  1224. vNode.Rec.ValueByName('Name').AsString := ANewBidName;
  1225. ProjectManager.Save;
  1226. end;
  1227. end;
  1228. procedure TProjectManagerFrame.DoBatchReceiveAllOnline;
  1229. var
  1230. OnCC: TZjCellNotifyEvent;
  1231. begin
  1232. OnCC := zgProjects.OnCurrentChanged;
  1233. try
  1234. zgProjects.OnCurrentChanged := nil;
  1235. DoBatchReceiveOnline(2);
  1236. if stdProjects.IDTree.FirstNode <> nil then
  1237. stdProjects.IDTree.FirstNode.LocateInControl;
  1238. finally
  1239. zgProjects.OnCurrentChanged := OnCC;
  1240. end;
  1241. end;
  1242. procedure TProjectManagerFrame.GetLocalValues(ARec: TsdDataRecord);
  1243. begin
  1244. if not Assigned(ARec) then
  1245. begin
  1246. ClearLocalValues;
  1247. Exit;
  1248. end;
  1249. // 加这句后产生Bug:上报项目后,记录不曾移动,FID不变,不会刷新
  1250. // if ARec.ValueByName('ID').AsInteger <> FID then
  1251. begin
  1252. FID := ARec.ValueByName('ID').AsInteger;
  1253. FWebID := ARec.ValueByName('WebID').AsInteger;
  1254. FWebAuthorID := ARec.ValueByName('WebAuthorID').AsInteger;
  1255. FWebOwnerID := ARec.ValueByName('WebOwnerID').AsInteger;
  1256. FWebMD5_Local := ARec.ValueByName('WebMD5').AsString;
  1257. FWebBidName_Local := ARec.ValueByName('Name').AsString;
  1258. end;
  1259. end;
  1260. procedure TProjectManagerFrame.GetLocalValues(AUserID, AWebID: Integer);
  1261. var i: Integer;
  1262. vTree: TsdIDTree;
  1263. vRec: TsdDataRecord;
  1264. begin
  1265. ClearLocalValues; // 先清空,以防没找到。
  1266. if (CurRec <> nil) and
  1267. (CurRec.ValueByName('WebUserID').AsInteger = AUserID) and
  1268. (CurRec.ValueByName('WebID').AsInteger = AWebID) and
  1269. (CurRec.ValueByName('Type').AsInteger = 1) then
  1270. begin
  1271. GetLocalValues(vRec);
  1272. Exit;
  1273. end;
  1274. vTree := stdProjects.IDTree;
  1275. for i := 0 to vTree.Count - 1 do
  1276. begin
  1277. vRec := vTree.Items[i].Rec;
  1278. if (vRec.ValueByName('WebUserID').AsInteger = AUserID) and
  1279. (vRec.ValueByName('WebID').AsInteger = AWebID) and
  1280. (vRec.ValueByName('Type').AsInteger = 1) then
  1281. begin
  1282. GetLocalValues(vRec);
  1283. Break;
  1284. end;
  1285. end;
  1286. end;
  1287. procedure TProjectManagerFrame.ClearLocalValues;
  1288. begin
  1289. FID := -1;
  1290. FWebID := -1;
  1291. FWebAuthorID := -1;
  1292. FWebOwnerID := -1;
  1293. FWebMD5_Local := '';
  1294. FWebBidName_Local := '';
  1295. end;
  1296. function TProjectManagerFrame.LocalMD5(AUserID, AWebID: Integer): string;
  1297. var i: Integer;
  1298. vTree: TsdIDTree;
  1299. vRec: TsdDataRecord;
  1300. begin
  1301. Result := '本地无MD5码';
  1302. if (CurRec <> nil) and
  1303. (CurRec.ValueByName('WebUserID').AsInteger = AUserID) and
  1304. (CurRec.ValueByName('WebID').AsInteger = AWebID) and
  1305. (CurRec.ValueByName('Type').AsInteger = 1) then
  1306. begin
  1307. Result := vRec.ValueByName('WebMD5').AsString;
  1308. Exit;
  1309. end;
  1310. vTree := stdProjects.IDTree;
  1311. for i := 0 to vTree.Count - 1 do
  1312. begin
  1313. vRec := vTree.Items[i].Rec;
  1314. if (vRec.ValueByName('WebUserID').AsInteger = AUserID) and
  1315. (vRec.ValueByName('WebID').AsInteger = AWebID) and
  1316. (vRec.ValueByName('Type').AsInteger = 1) then
  1317. begin
  1318. Result := vRec.ValueByName('WebMD5').AsString;
  1319. Break;
  1320. end;
  1321. end;
  1322. end;
  1323. function TProjectManagerFrame.CurRec: TsdDataRecord;
  1324. begin
  1325. if stdProjects.IDTree.Selected = nil then
  1326. Result := nil
  1327. else
  1328. Result := stdProjects.IDTree.Selected.Rec;
  1329. end;
  1330. procedure TProjectManagerFrame.CheckBidName(AUserID, AWebID: Integer;
  1331. ANewBidName: string);
  1332. var i: Integer;
  1333. vTree: TsdIDTree;
  1334. vRec: TsdDataRecord;
  1335. begin
  1336. if (CurRec <> nil) and
  1337. (CurRec.ValueByName('WebUserID').AsInteger = AUserID) and
  1338. (CurRec.ValueByName('WebID').AsInteger = AWebID) and
  1339. (CurRec.ValueByName('Type').AsInteger = 1) then
  1340. begin
  1341. if (CurRec.ValueByName('Name').AsString <> ANewBidName) then
  1342. begin
  1343. CurRec.ValueByName('Name').AsString := ANewBidName;
  1344. ProjectManager.Save;
  1345. end;
  1346. Exit;
  1347. end;
  1348. vTree := stdProjects.IDTree;
  1349. for i := 0 to vTree.Count - 1 do
  1350. begin
  1351. vRec := vTree.Items[i].Rec;
  1352. if (vRec.ValueByName('WebUserID').AsInteger = AUserID) and
  1353. (vRec.ValueByName('WebID').AsInteger = AWebID) and
  1354. (vRec.ValueByName('Type').AsInteger = 1) then
  1355. begin
  1356. if vRec.ValueByName('Name').AsString <> ANewBidName then
  1357. begin
  1358. vRec.ValueByName('Name').AsString := ANewBidName;
  1359. ProjectManager.Save;
  1360. end;
  1361. Break;
  1362. end;
  1363. end;
  1364. end;
  1365. function TProjectManagerFrame.CurRecAttachmentPath: string;
  1366. begin
  1367. if G_IsCloud then
  1368. Result := PHPWeb.WebPath + 'Projects\' + CurRec.ValueByName('WebID').AsString + '\Attachment\'
  1369. else
  1370. Result := GetMyProjectsFilePath + 'Attachment\' + CurRec.ValueByName('FileName').AsString + '\';
  1371. end;
  1372. function TProjectManagerFrame.AttachmentFileCountsWithoutManageFile(ANode: TsdIDTreeNode): Integer;
  1373. function GetCount(ANode: TsdIDTreeNode): Integer;
  1374. var sPath: string;
  1375. begin
  1376. if not Assigned(ANode) then Exit;
  1377. Result := 0;
  1378. if ANode.Rec.ValueByName('Type').AsInteger = 0 then
  1379. Result := Result + 0
  1380. else
  1381. begin
  1382. sPath := GetMyProjectsFilePath + 'Attachment\' + ANode.Rec.ValueByName('FileName').AsString + '\';
  1383. Result := Result + FileCount(sPath) - 1;
  1384. end;
  1385. if Assigned(ANode.FirstChild) then
  1386. Result := Result + GetCount(ANode.FirstChild);
  1387. if Assigned(ANode.NextSibling) then
  1388. Result := Result + GetCount(ANode.NextSibling);
  1389. end;
  1390. begin
  1391. if not Assigned(ANode) then Exit;
  1392. if Assigned(ANode.FirstChild) then
  1393. Result := GetCount(ANode.FirstChild)
  1394. else
  1395. Result := 0;
  1396. end;
  1397. procedure TProjectManagerFrame.BubbleSortProjects;
  1398. // 不能排最顶层
  1399. procedure BubbleSort(ANode: TsdIDTreeNode);
  1400. var n, t, c, temp: Integer;
  1401. bSwap: Boolean;
  1402. vNode1, vNode2, vTempNode: TsdIDTreeNode;
  1403. begin
  1404. if ANode = nil then Exit;
  1405. // if ANode.Rec.ValueByName('WebFolderLevel').AsInteger = G_WFL_ProjName then Exit;
  1406. n := ANode.ChildCount;
  1407. for t := 1 to n - 1 do
  1408. begin
  1409. bSwap := False;
  1410. for c := 1 to (n - t) do
  1411. begin
  1412. vNode1 := ANode.ChildNodes[c - 1];
  1413. vNode2 := ANode.ChildNodes[c];
  1414. if AnsiCompareStr(vNode1.Rec.ValueByName('Name').AsString,
  1415. vNode2.Rec.ValueByName('Name').AsString) = 1 then
  1416. begin
  1417. vNode1.DownMove;
  1418. bSwap := True;
  1419. end;
  1420. end;
  1421. if bSwap = False then Break;
  1422. end;
  1423. if Assigned(ANode.FirstChild) then
  1424. BubbleSort(ANode.FirstChild);
  1425. if Assigned(ANode.NextSibling) then
  1426. BubbleSort(ANode.NextSibling);
  1427. end;
  1428. begin
  1429. BubbleSort(stdProjects.IDTree.FirstNode);
  1430. end;
  1431. procedure TProjectManagerFrame.zgProjectsShowHint(var HintStr: String;
  1432. var CanShow: Boolean; var HintInfo: THintInfo; const ACoord: TPoint);
  1433. var
  1434. vCell: TZjCell;
  1435. vNode: TsdIDTreeNode;
  1436. iLevelWidth: Integer;
  1437. rText: TRect;
  1438. procedure CalcTextRect(var R: TRect);
  1439. var
  1440. DC: HDC;
  1441. iTextHeight: Integer;
  1442. begin
  1443. DC := CreateCompatibleDC(0);
  1444. try
  1445. SelectObject(DC, vCell.Font.Handle);
  1446. iTextHeight := DrawText(DC, PChar(vCell.Text), Length(vCell.Text), R, DT_SINGLELINE or DT_VCenter
  1447. or DT_NOCLIP or DT_CALCRECT);
  1448. finally
  1449. DeleteDC(DC);
  1450. end;
  1451. end;
  1452. begin
  1453. if (ACoord.Y < 1) and (ACoord.X <> 1) then Exit;
  1454. vCell := zgProjects.Cells[ACoord.X, ACoord.Y];
  1455. with HintInfo do
  1456. begin
  1457. vNode := stdProjects.IDTree.Items[ACoord.Y - 1];
  1458. if not Assigned(vNode) then Exit;
  1459. iLevelWidth := (vNode.Level + 1) * 20 + 16;
  1460. rText := CursorRect;
  1461. CalcTextRect(rText);
  1462. if (rText.Right - rText.Left + iLevelWidth > CursorRect.Right - CursorRect.Left) or
  1463. (rText.Right > ClientWidth) then
  1464. begin
  1465. CanShow := True;
  1466. HintStr := vCell.Text;
  1467. GetCursorPos(HintPos);
  1468. end;
  1469. end;
  1470. end;
  1471. function TProjectManagerFrame.FileDownAndReceive(ADownURL: string; AReceiveKind: Integer): Boolean;
  1472. var sLocalFile, sHint: string;
  1473. bLock, bCanImp, bIsOwner: Boolean;
  1474. vFileCheck: TTenderFileChecker;
  1475. begin
  1476. Result := False;
  1477. // 下载
  1478. sLocalFile := PHPWeb.UserPath + ExtractFileName(ADownURL);
  1479. if not PHPWeb.DownFile(ADownURL, sLocalFile) then
  1480. begin
  1481. if AReceiveKind = 1 then
  1482. sHint := Format('云端已找到[%s]的新文件,但由于网络原因下载失败!请重试!', [FWebBidName_Local])
  1483. else if AReceiveKind = 2 then
  1484. sHint := '云端已找到原报上传的无锁文件,但因网络出错无法下载,本次操作已取消。请重试!';
  1485. Application.MessageBox(PChar(sHint), '系统提醒', MB_OK + MB_ICONWARNING);
  1486. Exit;
  1487. end;
  1488. // 接收更新
  1489. if AReceiveKind = 1 then
  1490. begin
  1491. bLock := (FWebAuthorID = PHPWeb.UserID) or
  1492. ((FWebAuthorID <> PHPWeb.UserID) and (FWebCheckStatusMy <> csChecking));
  1493. bIsOwner := FWebOwnerID = PHPWeb.UserID;
  1494. if not ReceiveFile(sLocalFile, FWebMD5_OnLine, bLock) then
  1495. // if not ReceiveForLost(sLocalFile, FWebMD5_OnLine, bLock, FOnLineCheckerBegin, FOnLineCheckerEnd, bIsOwner) then
  1496. begin
  1497. sHint := Format('已从云端下载新的[%s]到本地[%s],但接收失败,请删除该项目然后重新从云端获取!', [FWebBidName_Local, sLocalFile]);
  1498. Application.MessageBox(PChar(sHint), '系统提醒', MB_OK + MB_ICONWARNING);
  1499. Exit;
  1500. end;
  1501. end
  1502. // 导入更新
  1503. else if AReceiveKind = 2 then
  1504. begin
  1505. // 有时无锁文件出错:包含了1审2审的数据。所以导入前须检测。
  1506. vFileCheck := TTenderFileChecker.Create;
  1507. try
  1508. // 有一期以上数据,且最新期数据审核状态为原报
  1509. bCanImp := vFileCheck.CheckFileValid(sLocalFile) and (vFileCheck.PhaseCount > 0) and (vFileCheck.AuditStatus = 0);
  1510. if not bCanImp then
  1511. begin
  1512. Application.MessageBox(PChar('已从云端下载原报上传的无锁文件到本地,但文件有错误,禁止导入!请致电纵横服务人员以获取帮助。'),
  1513. '警告', MB_OK + MB_ICONWARNING);
  1514. Exit;
  1515. end;
  1516. finally
  1517. vFileCheck.Free;
  1518. end;
  1519. {注意: 审核末通过的导入更新,这里的MD5码应取最终审核不通过项目的,否则会带来下载循环问题。
  1520. 问题描述:
  1521. ①编制人运行软件,双击项目,发现审核不通过,自动下载无锁文件,开始新一期,保存关闭。
  1522. ②编制人再次运行软件,双击项目,MD5码不同,自动下载旧的审核不通过文件,覆盖本地。
  1523. ③编制人再次运行软件,双击项目,发现审核不通过,重复①,循环....
  1524. 问:①那里下载无锁文件后不能改成新的MD5码吗?
  1525. 答:不能,因为审核人的项目会变成无锁文件,看不到不通过项目。MD5码只能在上传后更新。
  1526. 且编制人有个交互界面2种选择:a.下载更新不通过项目查看;b.下载更新无锁文件开始新一期。}
  1527. if not ImportFile(sLocalFile, FWebMD5_OnLine) then
  1528. begin
  1529. Application.MessageBox(PChar('已从云端下载原报上传的无锁文件到本地,但导入失败!请重试。'), '警告', MB_OK + MB_ICONWARNING);
  1530. Exit;
  1531. end;
  1532. end;
  1533. if FileExists(sLocalFile) then
  1534. DeleteFile(sLocalFile);
  1535. Result := True;
  1536. end;
  1537. // 为了跟PHP的数组兼容,这里限制数组的第一个元素是A[0](不能是A[1])
  1538. procedure TProjectManagerFrame.OnLineChecker(AAr: TOVArr; var ABegin,
  1539. AEnd: Integer);
  1540. var i, j, n: Integer;
  1541. vCS: TCheckStatus;
  1542. begin
  1543. ABegin := 0;
  1544. AEnd := 0;
  1545. n := -1;
  1546. for i := 0 to High(AAr) do
  1547. begin
  1548. vCS := TCheckStatus(StrToInt(AAr[i, 5])-1);
  1549. if vCS = csChecking then
  1550. begin
  1551. n := i; // 非常重要:传入的数组必须从第一个审核人到轮到工作中的那个人的前一个人
  1552. Break;
  1553. end;
  1554. end;
  1555. for i := n downto 0 do
  1556. begin
  1557. if AAr[i, 7] = '1' then // 接口返回的第7列是线上审批标记
  1558. begin
  1559. AEnd := i + 1;
  1560. Break;
  1561. end
  1562. else
  1563. Break;
  1564. end;
  1565. if AEnd = 0 then Exit;
  1566. i := i - 1;
  1567. if i < 0 then
  1568. begin
  1569. ABegin := 1;
  1570. Exit;
  1571. end;
  1572. for j := i downto 0 do
  1573. begin
  1574. if AAr[j, 7] = '0' then
  1575. begin
  1576. ABegin := j + 2;
  1577. Break;
  1578. end
  1579. else
  1580. begin
  1581. if j = 0 then
  1582. ABegin := 1;
  1583. end;
  1584. end;
  1585. end;
  1586. end.