ProjectData.pas 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933
  1. unit ProjectData;
  2. interface
  3. uses
  4. Connections, BillsDm, PhaseData, UpdateDataBase, ZhAPI, ProjectProperty,
  5. PhaseCompareDm, DealPaymentDm, SearchDm, DealBillsDm, MainDataListDm,
  6. BillsGatherDm, BGLDm, StaffDm, BillsCompileDm, BillsMeasureDm,
  7. BillsBookmarkDm, UpFileManageUnit, ProjectGLDm, PriceMarginBillsDm,
  8. DetailGLDm,
  9. Classes, SysUtils, ADODB, sdDB, Checker;
  10. type
  11. TProjectData = class
  12. private
  13. // 临时文件夹,解压项目后存放文件的文件夹
  14. FTempFolder: string;
  15. // 项目管理界面看到的项目名称
  16. FProjectName: string;
  17. FFileName: string;
  18. FProjectID: Integer;
  19. FConnection: TEncryptConnection;
  20. FUpdator: TUpdateProjectDB;
  21. FIsNewFile: Boolean;
  22. FDebugDir: string;
  23. FBillsData: TBillsData;
  24. FBillsCompileData: TBillsCompileData;
  25. FBillsMeasureData: TBillsMeasureData;
  26. FBillsBookmarkData: TBillsBookmarkData;
  27. FDealBillsData: TDealBillsData;
  28. FProjProperties: TProjProperties;
  29. FPhaseIndex: Integer;
  30. FPhaseData: TPhaseData;
  31. FPhaseCompareData: TPhaseCompareData;
  32. FBillsGatherData: TBillsGatherData;
  33. FDealPaymentData: TDealPaymentData;
  34. FBGLData: TBGLData;
  35. FStaffData: TStaffData;
  36. FSearchData: TSearchData;
  37. FMainListData: TMainListData;
  38. FProjectGLData: TProjectGLData;
  39. FDetailGLData: TDetailGLData;
  40. FPriceMarginBillsData: TPriceMarginBillsData;
  41. FCanUnlockInfo: Boolean;
  42. FWebID: Integer;
  43. FWebOwnerID: Integer;
  44. FWebAuthorID: Integer;
  45. FAuthorHasSubmited: Boolean;
  46. FProjectReadOnly: Boolean;
  47. FAttachmentData: TUpFiles;
  48. FCheckers: TCheckers;
  49. {For Open}
  50. procedure UpdateProjectDataBase;
  51. procedure CheckNewFile(AConnection: TADOConnection);
  52. procedure OpenLastPhaseData;
  53. procedure UpdateOldData;
  54. procedure SaveInfoToManager;
  55. procedure DropCacheTable(const AKey: string);
  56. // 备份0号台账的历史数据
  57. procedure CopyLedgerHistoryData(AAudit: Integer);
  58. // 备份各期的截止本期累计完成数据
  59. procedure CopyPhaseCompleteData;
  60. procedure SetPhaseIndexSimple(AIndex: Integer);
  61. // 锁定数据 -- Sql语句方式(使用时注意相应的DataMoudle应处于关闭状态)
  62. procedure LockBillsBaseData;
  63. procedure LockDealPaymentData;
  64. procedure LockBGLData;
  65. procedure LockProjectGLData;
  66. procedure LockDetailGLData;
  67. procedure UpdatePhaseData;
  68. procedure CloseAllData;
  69. procedure OpenAllData;
  70. function GetMainFileName: string;
  71. procedure SetPhaseIndex(const Value: Integer);
  72. function GetTempPath: string;
  73. function GetProjectFileName: string;
  74. function GetAllowInsert: Boolean;
  75. function GetBaseDataReadOnly: Boolean;
  76. function GetADOConnection: TADOConnection;
  77. procedure SetCheckers(const Value: TCheckers);
  78. function GetStageDataReadOnly: Boolean;
  79. function GetPriceMarginReadOnly: Boolean;
  80. function GetStageIndex: Integer;
  81. procedure SetStageIndex(const Value: Integer);
  82. function GetCanInsertNormalBills: Boolean;
  83. function GetValidStageIsRefer: Boolean;
  84. public
  85. constructor Create;
  86. destructor Destroy; override;
  87. procedure Open(AProjRec: TsdDataRecord);
  88. procedure Save;
  89. //----------------------- Begin ---后台打开 ------------------------
  90. {总说明:
  91. 为节省内存使用,对不同的后台打开分别写不同的方法
  92. 按需使用,稍有不同,则新增后台打开方法
  93. 变更(新增)方法须同步变更(新增)注释
  94. }
  95. {OpenForSubmit: ProjProperties, StaffData}
  96. procedure OpenForSubmit(const AFileName: string);
  97. procedure SaveAsForSubmit(const AFileName: string);
  98. {OpenForReply: ProjProperties, StaffData, PhaseData, DetailGLData}
  99. procedure OpenForReply(const AFileName: string);
  100. procedure SaveForReply(const AFileName: string);
  101. {OpenForReceive: ProjProperties, StaffData, PhaseData, StageData}
  102. procedure OpenForReceive(const AFileName: string);
  103. procedure SaveForReceive(const AFileName: string);
  104. {SimpleOpen: 仅打开数据库[项目+最后一期],不打开除属性以外的任何数据表(项目属性都是通过Sql语句修改)}
  105. procedure SimpleOpen(const AFileName: string);
  106. procedure SimpleSaveAs(const AFileName: string);
  107. {OpenForReport: BillsData, BillsCompileData, DealPaymentData, BGLData 报表仅读取数据不做任何修改}
  108. procedure OpenForReport(const AFileName: string);
  109. {OpenForReport2: OpenForReport的基础上打开最后一期数据}
  110. procedure OpenForReport2(const AFileName: string);
  111. {OpenForReport3: OpenForReport2的基础上打开最后一个审核人数据,打开BillsMeasureTree不打开BillsCompileTree,链接BillsMeasureTree跟StageData}
  112. procedure OpenForReport3(const AFileName: string);
  113. //----------------------- End ---后台打开 ------------------------
  114. procedure SaveDebugFile(const AFileName: string);
  115. procedure SaveTempDataBaseFile(const AFileName: string);
  116. procedure SaveLastestPhaseMainData;
  117. procedure CopyPreData;
  118. procedure CreateNewPhase;
  119. {重设所有LookUpDataset连接}
  120. procedure ResetPhaseDataLink;
  121. {重设所有DataView小数位数显示}
  122. procedure ResetFloatDigitView;
  123. {锁定数据}
  124. // 上报
  125. procedure LockedDataForSubmit;
  126. // 终审批复
  127. procedure LockedDataForReply;
  128. {创建审核数据}
  129. procedure UpdateDataForReceive;
  130. // 上报文件:
  131. { 返回值:
  132. 1. True 文件检验结果正确,生成文件
  133. 2. False 文件检验结果错误,不生成文件}
  134. function SubmitProject(const AFileName: string = ''): Boolean;
  135. // 批复文件: 返回值含义同上报
  136. function ReplyProject(const AFileName: string = ''): Boolean;
  137. // json文件:清单
  138. procedure ExportJson_Bills(const AFileName: string);
  139. procedure ExportJson_Common(const AFileName: string);
  140. // 断开所有树的链接
  141. procedure DisConnectTree;
  142. // 重新连接所有的树
  143. procedure ReConnectTree;
  144. {For Reports: 复制当期的全部数据到项目数据中}
  145. procedure CopyPhaseData;
  146. procedure ClearReportCacheData;
  147. procedure ClearReportPrepareData;
  148. procedure ExecuteSql(const ASql: string);
  149. procedure CalculateAll;
  150. procedure CalculatePriceMargin;
  151. function CheckDataBaseInfo(APhaseCount, AAuditStatus: Integer): Boolean;
  152. procedure ImportCloudTenderFile(const AFileName: string);
  153. procedure ImportDmfFile(const AFileName: string);
  154. function CheckPassword: Boolean;
  155. function CurUserIsOwner: Boolean;
  156. function CurUserIsAuthor: Boolean;
  157. function CurUserIsChecker: Boolean;
  158. property BillsData: TBillsData read FBillsData;
  159. property BillsCompileData: TBillsCompileData read FBillsCompileData;
  160. property BillsMeasureData: TBillsMeasureData read FBillsMeasureData;
  161. property BillsBookmarkData: TBillsBookmarkData read FBillsBookmarkData;
  162. property DealBillsData: TDealBillsData read FDealBillsData;
  163. property PhaseIndex: Integer read FPhaseIndex write SetPhaseIndex;
  164. property StageIndex: Integer read GetStageIndex write SetStageIndex;
  165. property PhaseData: TPhaseData read FPhaseData;
  166. property ProjProperties: TProjProperties read FProjProperties;
  167. property PhaseCompareData: TPhaseCompareData read FPhaseCompareData;
  168. property BillsGatherData: TBillsGatherData read FBillsGatherData;
  169. property DealPaymentData: TDealPaymentData read FDealPaymentData;
  170. property BGLData: TBGLData read FBGLData;
  171. property StaffData: TStaffData read FStaffData;
  172. property SearchData: TSearchData read FSearchData;
  173. property MainListData: TMainListData read FMainListData;
  174. property AttachmentData: TUpFiles read FAttachmentData; // 附件
  175. property ProjectGLData: TProjectGLData read FProjectGLData;
  176. property DetailGLData: TDetailGLData read FDetailGLData;
  177. property PriceMarginBillsData: TPriceMarginBillsData read FPriceMarginBillsData;
  178. // 台账、合同支付
  179. property AllowInsert: Boolean read GetAllowInsert;
  180. property BaseDataReadOnly: Boolean read GetBaseDataReadOnly;
  181. property StageDataReadOnly: Boolean read GetStageDataReadOnly;
  182. property PriceMarginReadOnly: Boolean read GetPriceMarginReadOnly;
  183. property ValidStageIsRefer: Boolean read GetValidStageIsRefer;
  184. property CanUnlockInfo: Boolean read FCanUnlockInfo write FCanUnlockInfo;
  185. property CanInsertNormalBills: Boolean read GetCanInsertNormalBills;
  186. property ProjectName: string read FProjectName;
  187. // 磁盘上存储该项目的文件名称
  188. property FileName: string read FFileName;
  189. property ProjectID: Integer read FProjectID;
  190. property MainFileName: string read GetMainFileName;
  191. property TempPath: string read GetTempPath;
  192. property ADOConnection: TADOConnection read GetADOConnection;
  193. property WebID: Integer read FWebID;
  194. property WebOwnerID: Integer read FWebOwnerID;
  195. property WebAuthorID: Integer read FWebAuthorID;
  196. property AuthorHasSubmited: Boolean read FAuthorHasSubmited write FAuthorHasSubmited;
  197. property ProjectReadOnly: Boolean read FProjectReadOnly;
  198. property Checkers: TCheckers read FCheckers write SetCheckers;
  199. end;
  200. implementation
  201. uses UtilMethods, Globals, ProjectCommands, sdIDTree, StageDm,
  202. ZJJLDm, PHPWebDm, XMLDoc, XMLIntf, ConstUnit, PasswordInputFrm,
  203. mProgressProFrm, mDataRecord, ConditionalDefines, DbTreeImport;
  204. { TProjectData }
  205. procedure TProjectData.CheckNewFile(AConnection: TADOConnection);
  206. var
  207. FTableList: TStringList;
  208. begin
  209. FTableList := TStringList.Create;
  210. try
  211. AConnection.GetTableNames(FTableList);
  212. FIsNewFile := FTableList.Count = 0;
  213. finally
  214. FTableList.Free;
  215. end;
  216. end;
  217. procedure TProjectData.CopyLedgerHistoryData(AAudit: Integer);
  218. const
  219. sSql = 'Select ID as BillsID, Quantity, TotalPrice, QtyFlag, QtyFormula ' +
  220. 'Into LedgerHistory%d '+
  221. 'From Bills';
  222. begin
  223. ExecuteSql(Format(sSql, [AAudit]));
  224. end;
  225. constructor TProjectData.Create;
  226. begin
  227. FCheckers := TCheckers.Create;
  228. FTempFolder := GenerateTempFolder(GetTempFilePath);
  229. FConnection := TEncryptConnection.Create;
  230. FUpdator := TUpdateProjectDB.Create;
  231. FProjProperties := TProjProperties.Create(Self);
  232. FBillsData := TBillsData.Create(Self);
  233. FBillsCompileData := TBillsCompileData.Create(Self);
  234. FBillsMeasureData := TBillsMeasureData.Create(Self);
  235. FBillsBookmarkData := TBillsBookmarkData.Create(Self);
  236. FDealBillsData := TDealBillsData.Create(Self);
  237. FPhaseData := TPhaseData.Create(Self);
  238. FPhaseCompareData := TPhaseCompareData.Create(Self);
  239. FBillsGatherData := TBillsGatherData.Create(Self);
  240. FDealPaymentData := TDealPaymentData.Create(Self);
  241. FBGLData := TBGLData.Create(Self);
  242. FStaffData := TStaffData.Create(Self);
  243. FSearchData := TSearchData.Create(Self);
  244. FMainListData := TMainListData.Create(Self);
  245. FProjectGLData := TProjectGLData.Create(Self);
  246. FDetailGLData := TDetailGLData.Create(Self);
  247. FPriceMarginBillsData := TPriceMarginBillsData.Create(Self);
  248. FAttachmentData := TUpFiles.Create;
  249. FPhaseIndex := 0;
  250. end;
  251. procedure TProjectData.CreateNewPhase;
  252. var
  253. sPhaseFileName: string;
  254. begin
  255. FBillsData.LockedBaseData;
  256. FProjProperties.PhaseCount := FProjProperties.PhaseCount + 1;
  257. FProjProperties.AuditStatus := 0;
  258. FStaffData.UpdateDataForNewPhase;
  259. sPhaseFileName := Format('%s\Phase%d.dat', [TempPath, FProjProperties.PhaseCount]);
  260. CopyFileOrFolder(GetEmptyDataBaseFileName, sPhaseFileName);
  261. end;
  262. destructor TProjectData.Destroy;
  263. begin
  264. try
  265. FCheckers.Free;
  266. FPriceMarginBillsData.Free;
  267. FDetailGLData.Free;
  268. FProjectGLData.Free;
  269. FMainListData.Free;
  270. FSearchData.Free;
  271. FStaffData.Free;
  272. FBGLData.Free;
  273. FDealPaymentData.Free;
  274. FPhaseCompareData.Free;
  275. FPhaseData.Free;
  276. FProjProperties.Free;
  277. FDealBillsData.Free;
  278. FBillsBookmarkData.Free;
  279. FBillsMeasureData.Free;
  280. FBillsCompileData.Free;
  281. FBillsData.Free;
  282. FAttachmentData.Free;
  283. FUpdator.Free;
  284. FConnection.Free;
  285. finally
  286. DeleteFileOrFolder(FTempFolder);
  287. DeleteFileOrFolder(FDebugDir);
  288. end;
  289. inherited;
  290. end;
  291. function TProjectData.GetBaseDataReadOnly: Boolean;
  292. begin
  293. if FProjProperties.PhaseCount = 0 then
  294. Result := False
  295. else
  296. Result := not AllowInsert;
  297. end;
  298. function TProjectData.GetAllowInsert: Boolean;
  299. begin
  300. if FPhaseData.Active then
  301. Result := FPhaseData.AllowInsert
  302. else
  303. Result := True;
  304. end;
  305. function TProjectData.GetMainFileName: string;
  306. begin
  307. Result := TempPath + 'Main.dat';
  308. end;
  309. function TProjectData.GetProjectFileName: string;
  310. begin
  311. Result := GetMyProjectsFilePath + FProjectName;
  312. end;
  313. function TProjectData.GetTempPath: string;
  314. begin
  315. Result := FTempFolder + '\';
  316. end;
  317. procedure TProjectData.LockedDataForReply;
  318. begin
  319. LockBillsBaseData;
  320. LockDealPaymentData;
  321. LockProjectGLData;
  322. LockDetailGLData;
  323. FPhaseData.PhaseProperty.FinalAudit := True;
  324. // 有顺序限制,谨慎修改
  325. FProjProperties.AuditCompany := FStaffData.FinalStaffCompany;
  326. FProjProperties.AuditStatus := -1;
  327. FProjProperties.FinalAuditCount := FProjProperties.PhaseCount;
  328. FStaffData.LockedDataForReply;
  329. LockBGLData;
  330. end;
  331. procedure TProjectData.LockedDataForSubmit;
  332. begin
  333. LockBillsBaseData;
  334. LockDealPaymentData;
  335. FProjProperties.AuditCompany := FStaffData.FinalStaffCompany;
  336. FStaffData.LockedDataForAudit;
  337. LockBGLData;
  338. end;
  339. procedure TProjectData.Open(AProjRec: TsdDataRecord);
  340. begin
  341. {Open规则:在打开Phase或者设置PhaseIndex时,会设置多个LookUpDataset,
  342. 故要求须在BillsData、DealPayment打开之后}
  343. FProjectName := AProjRec.ValueByName('Name').AsString;
  344. FFileName := GetMyProjectsFilePath + AProjRec.ValueByName('FileName').AsString;
  345. FProjectID := AProjRec.ValueByName('ID').AsInteger;
  346. FWebID := AProjRec.ValueByName('WebID').AsInteger;
  347. FWebOwnerID := AProjRec.ValueByName('WebOwnerID').AsInteger;
  348. FWebAuthorID := AProjRec.ValueByName('WebAuthorID').AsInteger;
  349. FAttachmentData.ProjectData := Self;
  350. FAttachmentData.LoadDatas;
  351. UpdateSysProgress(5, '正在打开项目');
  352. UnZipFile(FileName, TempPath);
  353. UpdateSysProgress(10, '正在打开项目');
  354. FConnection.Open(MainFileName);
  355. CheckNewFile(FConnection.Connection);
  356. UpdateSysProgress(15, '正在升级文件');
  357. UpdateProjectDataBase;
  358. UpdateSysProgress(20, '正在读取数据');
  359. FProjProperties.Open(FConnection.Connection);
  360. if FIsNewFile then
  361. FProjProperties.UpdateFlag := 1;
  362. UpdateOldData;
  363. ResetFloatDigitView;
  364. FProjProperties.DecimalManager.ResetLinkViewColumns;
  365. UpdateSysProgress(25, '正在读取数据');
  366. FBillsData.Open(FConnection.Connection);
  367. if FIsNewFile then
  368. FBillsData.InitBills;
  369. FBillsCompileData.Open;
  370. FBillsMeasureData.Open;
  371. UpdateSysProgress(65, '正在读取数据');
  372. FBillsBookmarkData.Open;
  373. UpdateSysProgress(70, '正在读取数据');
  374. FDealBillsData.Open(FConnection.Connection);
  375. UpdateSysProgress(80, '正在读取数据');
  376. FDealPaymentData.Open(FConnection.Connection);
  377. if FIsNewFile then
  378. FDealPaymentData.Init;
  379. UpdateSysProgress(90, '正在读取数据');
  380. OpenLastPhaseData;
  381. UpdateSysProgress(140, '正在读取数据');
  382. // 价差数据应在当期数据打开后打开
  383. FProjectGLData.Open(FConnection.Connection);
  384. FDetailGLData.Open(FConnection.Connection);
  385. FBGLData.Open(FConnection.Connection);
  386. UpdateSysProgress(160, '正在读取数据');
  387. FStaffData.Open(FConnection.Connection);
  388. UpdateSysProgress(180, '正在读取数据');
  389. //FBillsGatherData.RefreshBills;
  390. FMainListData.Open(FConnection.Connection);
  391. UpdateSysProgress(200, '就绪');
  392. if _IsDebugView then
  393. begin
  394. FDebugDir := GetAppFilePath + 'Debug\' + FProjectName;
  395. CreateDirectoryInDeep(FDebugDir);
  396. end;
  397. end;
  398. procedure TProjectData.OpenLastPhaseData;
  399. begin
  400. if ProjProperties.PhaseCount = 0 then Exit;
  401. FPhaseIndex := ProjProperties.PhaseCount;
  402. FProjProperties.PhaseIndex := FPhaseIndex;
  403. FPhaseData.Open(Format('%sPhase%d.dat', [TempPath, FPhaseIndex]));
  404. ResetPhaseDataLink;
  405. end;
  406. procedure TProjectData.Save;
  407. begin
  408. try
  409. UpdateSysProgress(5, '正在保存数据');
  410. SaveLastestPhaseMainData;
  411. UpdateSysProgress(10, '正在保存数据');
  412. if (FPhaseData.Active) and (FPhaseIndex = ProjProperties.PhaseCount) then
  413. FPhaseData.Save;
  414. UpdateSysProgress(40, '正在保存数据');
  415. FMainListData.Save;
  416. FDealPaymentData.Save;
  417. UpdateSysProgress(50, '正在保存数据');
  418. FStaffData.Save;
  419. UpdateSysProgress(60, '正在保存数据');
  420. FBGLData.Save;
  421. UpdateSysProgress(70, '正在保存数据');
  422. FDealBillsData.Save;
  423. UpdateSysProgress(80, '正在保存数据');
  424. FProjectGLData.Save;
  425. FDetailGLData.Save;
  426. UpdateSysProgress(100, '正在保存数据');
  427. FBillsCompileData.ReLockBaseData;
  428. UpdateSysProgress(110, '正在保存数据');
  429. FBillsData.Save;
  430. UpdateSysProgress(170, '正在保存数据');
  431. FProjProperties.AuditCompany := FStaffData.FinalStaffCompany;
  432. FProjProperties.Save;
  433. UpdateSysProgress(180, '正在保存数据');
  434. FConnection.Save;
  435. UpdateSysProgress(190, '正在保存数据');
  436. ZipFolder(FTempFolder, FileName);
  437. SaveInfoToManager;
  438. UpdateSysProgress(200, '就绪');
  439. ProjectManager.AddSaveTenderBackup(FProjectID);
  440. except
  441. ErrorMessage('保存数据出错。请重试,或联系纵横客服:企业QQ:800003850 客服热线:(0756)3850888');
  442. end;
  443. end;
  444. procedure TProjectData.SaveInfoToManager;
  445. var
  446. InfoRec, PhaseRec: TsdDataRecord;
  447. begin
  448. InfoRec := ProjectManager.sddProjectsInfo.FindKey('idxID', FProjectID);
  449. PhaseRec := MainListData.GetPhaseMainRecord(ProjProperties.PhaseCount);
  450. InfoRec.ValueByName('DealTotalPrice').AsFloat := FBillsData.Settlement[DealIndex];
  451. InfoRec.ValueByName('Deal_BGLTotalPrice').AsFloat := FBillsData.Settlement[DealIndex] + FBGLData.AllBGLTotalPrice;
  452. InfoRec.ValueByName('PhaseTotalPrice').AsFloat := PhaseRec.ValueByName('GatherTotalPrice').AsFloat;
  453. InfoRec.ValueByName('EndDealTotalPrice').AsFloat := PhaseRec.ValueByName('EndDealTotalPrice').AsFloat;
  454. InfoRec.ValueByName('EndChangeTotalPrice').AsFloat :=
  455. PhaseRec.ValueByName('EndQcTotalPrice').AsFloat + PhaseRec.ValueByName('EndPcTotalPrice').AsFloat;
  456. InfoRec.ValueByName('EndTotalPrice').AsFloat := PhaseRec.ValueByName('EndGatherTotalPrice').AsFloat;
  457. InfoRec.ValueByName('PreTotalPrice').AsFloat := PhaseRec.ValueByName('PreGatherTotalPrice').AsFloat;
  458. InfoRec.ValueByName('PhasePay').AsFloat := PhaseRec.ValueByName('PhasePay').AsFloat;
  459. InfoRec.ValueByName('PhaseCount').AsInteger := FProjProperties.PhaseCount;
  460. InfoRec.ValueByName('AuditStatus').AsInteger := FProjProperties.AuditStatus;
  461. ProjectManager.Save;
  462. end;
  463. procedure TProjectData.SetPhaseIndex(const Value: Integer);
  464. function GetPhaseFileName: string;
  465. begin
  466. Result := Format('%s\Phase%d.dat', [TempPath, FPhaseIndex]);
  467. end;
  468. procedure ReCreatePhaseData(AOrgPhaseIndex: Integer);
  469. begin
  470. if (FPhaseData.Active) and (AOrgPhaseIndex = ProjProperties.PhaseCount) then
  471. FPhaseData.Save;
  472. FPhaseData.Free;
  473. FPhaseData := TPhaseData.Create(Self);
  474. end;
  475. var
  476. iOrgPhaseIndex: Integer;
  477. begin
  478. SaveLastestPhaseMainData;
  479. FProjectGLData.Save;
  480. iOrgPhaseIndex := FPhaseIndex;
  481. FPhaseIndex := Value;
  482. ProjProperties.PhaseIndex := FPhaseIndex;
  483. ReCreatePhaseData(iOrgPhaseIndex);
  484. FPhaseData.Open(GetPhaseFileName);
  485. ResetPhaseDataLink;
  486. // 须保存项目工料数据,重新加载当期的项目工料数据
  487. FProjectGLData.LoadCurPhaseInfoPrice;
  488. FProjectGLData.LoadStagePM_CalcData;
  489. //BillsGatherData.RefreshBills;
  490. end;
  491. procedure TProjectData.SetPhaseIndexSimple(AIndex: Integer);
  492. begin
  493. FPhaseIndex := AIndex;
  494. if FPhaseData.Active then
  495. FPhaseData.SimpleSave;
  496. FPhaseData.Free;
  497. FPhaseData := TPhaseData.Create(Self);
  498. FPhaseData.SimpleOpen(Format('%s\Phase%d.dat', [TempPath, FPhaseIndex]));
  499. end;
  500. procedure TProjectData.UpdateProjectDataBase;
  501. begin
  502. if TEncryptConnection(FConnection).OverExe then
  503. WarningMessage('标段版本高于当前软件版本,可能会产生错误。');
  504. FUpdator.Update(FConnection);
  505. end;
  506. procedure TProjectData.ResetPhaseDataLink;
  507. begin
  508. BillsMeasureData.ResetPhaseStageLink;
  509. BillsMeasureData.ResetTreeNodeStageRec;
  510. DealPaymentData.ResetPhaseLink;
  511. BillsBookmarkData.ResetPhaseStageLink;
  512. end;
  513. procedure TProjectData.SimpleOpen(const AFileName: string);
  514. begin
  515. FProjectID := -1;
  516. UnZipFile(AFileName, TempPath);
  517. FConnection.Open(MainFileName);
  518. UpdateProjectDataBase;
  519. FProjProperties.Open(FConnection.Connection);
  520. if ProjProperties.PhaseCount > 0 then
  521. begin
  522. FPhaseIndex := ProjProperties.PhaseCount;
  523. FPhaseData.SimpleOpen(Format('%sPhase%d.dat', [TempPath, FPhaseIndex]));
  524. end;
  525. end;
  526. procedure TProjectData.SimpleSaveAs(const AFileName: string);
  527. begin
  528. if FPhaseData.Active then
  529. FPhaseData.SimpleSave;
  530. FProjProperties.Save;
  531. FConnection.Save;
  532. ZipFolder(FTempFolder, AFileName);
  533. end;
  534. procedure TProjectData.UpdateDataForReceive;
  535. begin
  536. UpdatePhaseData;
  537. end;
  538. procedure TProjectData.UpdatePhaseData;
  539. procedure UpdateGLPriceData;
  540. const
  541. sUpdateSql = 'Update GLPrice Set PM_Quantity%d = PM_Quantity%d, PM_TotalPrice%d = PM_TotalPrice%d'+
  542. ' Where PhaseID = %d';
  543. var
  544. sSql: string;
  545. begin
  546. if (ProjProperties.PhaseCount < 1) or (ProjProperties.AuditStatus < 1) then Exit;
  547. with ProjProperties do
  548. sSql := Format(sUpdateSql, [AuditStatus, AuditStatus-1, AuditStatus, AuditStatus-1, PhaseCount]);
  549. ExecuteSql(sSql);
  550. end;
  551. var
  552. iPhase: Integer;
  553. begin
  554. FProjProperties.AuditStatus := FProjProperties.AuditStatus + 1;
  555. for iPhase := FProjProperties.FinalAuditCount + 1 to FProjProperties.PhaseCount do
  556. begin
  557. SetPhaseIndexSimple(iPhase);
  558. PhaseData.CreateNewAuditData;
  559. StaffData.UpdateDataForNewAudit;
  560. UpdateGLPriceData;
  561. end;
  562. end;
  563. function TProjectData.ReplyProject(const AFileName: string = ''): Boolean;
  564. var
  565. Replyor: TReplyProject;
  566. begin
  567. Replyor := TReplyProject.Create(FProjectName, FFileName, FProjectID);
  568. try
  569. if AFileName = '' then
  570. Result := Replyor.Execute
  571. else
  572. Result := Replyor.ExportTo(AFileName);
  573. finally
  574. Replyor.Free;
  575. end;
  576. end;
  577. function TProjectData.SubmitProject(const AFileName: string = ''): Boolean;
  578. var
  579. Submitor :TSubmitProject;
  580. begin
  581. Submitor := TSubmitProject.Create(FProjectName, FFileName, FProjectID);
  582. try
  583. if AFileName = '' then
  584. Result := Submitor.Execute
  585. else
  586. Result := Submitor.ExportTo(AFileName);
  587. finally
  588. Submitor.Free;
  589. end;
  590. end;
  591. procedure TProjectData.ExportJson_Bills(const AFileName: string);
  592. function GetProjectName: string;
  593. var
  594. vNode: tsdIDTreeNode;
  595. begin
  596. vNode := ProjectManager.ProjectsTree.FindNode(FProjectID).Parent;
  597. Result := vNode.Rec.ValueByName('Name').AsString;
  598. end;
  599. // lkJSON 暂时未找到添加数组结构的办法,官方也没有提供相关的Demo,自己合成。
  600. // lkJSON 合成的长文本自动带有大量“\”转义字符,这点有些烦人。
  601. // 其实这么折腾,还不如自己直接合成。那为什么还要用它?自己写是很容易,但是
  602. // 要自己读JSON,那写起来就很麻烦了。
  603. function BillsStr: string;
  604. var vRec: TsdDataRecord;
  605. i: Integer;
  606. sSplit: string;
  607. function v(AFieldName: string): string;
  608. begin
  609. Result := vRec.ValueByName(AFieldName).AsString;
  610. end;
  611. // 杰哥那头不识别中文,将中文转成URL编码形式
  612. function URLEncode(const S: string; const InQueryString: Boolean): string;
  613. var
  614. Idx: Integer;
  615. begin
  616. Result := '';
  617. for Idx := 1 to Length(S) do
  618. begin
  619. case S[Idx] of
  620. 'A'..'Z', 'a'..'z', '0'..'9', '-', '_', '.':
  621. Result := Result + S[Idx];
  622. ' ':
  623. if InQueryString then
  624. Result := Result + '+'
  625. else
  626. Result := Result + '%20';
  627. else
  628. Result := Result + '%' + SysUtils.IntToHex(Ord(S[Idx]), 2);
  629. end;
  630. end;
  631. end;
  632. begin
  633. for i := 0 to BillsMeasureData.BillsMeasureTree.Count - 1 do
  634. begin
  635. vRec := BillsMeasureData.BillsMeasureTree.Items[i].Rec;
  636. if (i mod 100) = 0 then
  637. ProgressProRun('生成汇总数据... ' + IntToStr(i), 0, pmtEdit, pptSet);
  638. if i = 0 then
  639. sSplit := ''
  640. else
  641. sSplit := ',';
  642. Result := Result + sSplit + Format('{"Code":"%s","B_Code":"%s","Name":"%s",' +
  643. '"Units":"%s","Price":"%s","Quantity":"%s","TotalPrice":"%s"}',
  644. [v('Code'), v('B_Code'), v('Name'), v('Units'), v('Price'),
  645. v('Quantity'), v('TotalPrice')]);
  646. end;
  647. end;
  648. var
  649. fPhasePay: Double;
  650. vSL: TStringList;
  651. begin
  652. vSL := TStringList.Create;
  653. try
  654. vSL.Text := Format('{"DealTotalPrice":"%s","Bills":[%s]}',
  655. [FloatToStr(FBillsData.Settlement[DealIndex]), AnsiToUtf8(BillsStr)]);
  656. vSL.SaveToFile(AFileName);
  657. finally
  658. vSL.Free;
  659. end;
  660. end;
  661. procedure TProjectData.DisConnectTree;
  662. begin
  663. BillsMeasureData.BillsMeasureTree.Active := False;
  664. BillsCompileData.BillsCompileTree.Active := False;
  665. end;
  666. procedure TProjectData.ReConnectTree;
  667. begin
  668. BillsCompileData.ReConnectTree;
  669. BillsMeasureData.ReConnectTree;
  670. end;
  671. procedure TProjectData.CopyPhaseCompleteData;
  672. const
  673. sInsertSql = 'Insert Into PhaseComplete (BillsID)' +
  674. ' Select ID' +
  675. ' From Bills where Bills.CreatePhaseID = %d';
  676. sUpdateSql = 'Update PhaseComplete Inner Join [Bills]' +
  677. ' On PhaseComplete.BillsID=Bills.ID' +
  678. ' Set PhaseComplete.Quantity%d=Bills.AddGatherQuantity,' +
  679. ' PhaseComplete.TotalPrice%d=Bills.AddGatherTotalPrice';
  680. var
  681. iPhase: Integer;
  682. sSql: string;
  683. begin
  684. for iPhase := FProjProperties.FinalAuditCount + 1 to FProjProperties.PhaseCount do
  685. begin
  686. SetPhaseIndexSimple(iPhase);
  687. // 插入本期新增的数据
  688. sSql := Format(sInsertSql, [iPhase]);
  689. ExecuteSql(sSql);
  690. // 更新所有截止本期完成计量数据
  691. sSql := Format(sInsertSql, [iPhase, iPhase]);
  692. ExecuteSql(sSql);
  693. end;
  694. end;
  695. procedure TProjectData.CopyPhaseData;
  696. procedure CopyStageData(const AFileName, ASourceTable, AResultTable: string);
  697. const
  698. sCopySql = 'Select BillsID, DealQuantity, DealTotalPrice, QcQuantity, QcTotalPrice, QcBGLCode, QcBGLNum,' +
  699. ' PcQuantity, PcTotalPrice, PcBGLCode, PcBGLNum, GatherQuantity, GatherTotalPrice,' +
  700. ' EndDealQuantity, EndDealTotalPrice, EndQcQuantity, EndQcTotalPrice,' +
  701. ' EndPcQuantity, EndPcTotalPrice, EndGatherQuantity, EndGatherTotalPrice,' +
  702. ' PreDealQuantity, PreDealTotalPrice, PreQcQuantity, PreQcTotalPrice,' +
  703. ' PrePcQuantity, PrePcTotalPrice, PreGatherQuantity, PreGatherTotalPrice' +
  704. ' Into %s' +
  705. ' From %s' +
  706. ' In ''%s''';
  707. var
  708. sSql: string;
  709. begin
  710. sSql := Format(sCopySql, [AResultTable, ASourceTable, AFileName]);
  711. ExecuteSql(sSql);
  712. end;
  713. procedure CopyEmptyStageData(const AFileName, ASourceTable, AResultTable: string);
  714. const
  715. sCopySql = 'Select BillsID, DealQuantity, DealTotalPrice, QcQuantity, QcTotalPrice, QcBGLCode, QcBGLNum,' +
  716. ' PcQuantity, PcTotalPrice, PcBGLCode, PcBGLNum, GatherQuantity, GatherTotalPrice,' +
  717. ' EndDealQuantity, EndDealTotalPrice, EndQcQuantity, EndQcTotalPrice,' +
  718. ' EndPcQuantity, EndPcTotalPrice, EndGatherQuantity, EndGatherTotalPrice,' +
  719. ' PreDealQuantity, PreDealTotalPrice, PreQcQuantity, PreQcTotalPrice,' +
  720. ' PrePcQuantity, PrePcTotalPrice, PreGatherQuantity, PreGatherTotalPrice' +
  721. ' Into %s' +
  722. ' From %s' +
  723. ' In ''%s''' +
  724. ' Where 1=2';
  725. var
  726. sSql: string;
  727. begin
  728. sSql := Format(sCopySql, [AResultTable, ASourceTable, AFileName]);
  729. ExecuteSql(sSql);
  730. end;
  731. procedure AddSettlementData;
  732. const
  733. sAddSql = 'Insert Into P_Stage (BillsID,' +
  734. ' DealTotalPrice, QcTotalPrice, PcTotalPrice, GatherTotalPrice,' +
  735. ' EndDealTotalPrice, EndQcTotalPrice, EndPcTotalPrice, EndGatherTotalPrice,' +
  736. ' PreDealTotalPrice, PreQcTotalPrice, PrePcTotalPrice, PreGatherTotalPrice)' +
  737. ' Values (-2,'+
  738. ' %f, %f, %f, %f,'+
  739. ' %f, %f, %f, %f,'+
  740. ' %f, %f, %f, %f)';
  741. var
  742. sSql: string;
  743. begin
  744. with PhaseData.StageData do
  745. sSql := Format(sAddSql,
  746. [StageSettlement[1,1], StageSettlement[1,2], StageSettlement[1,3], StageSettlement[1,4],
  747. StageSettlement[2,1], StageSettlement[2,2], StageSettlement[2,3], StageSettlement[2,4],
  748. StageSettlement[3,1], StageSettlement[3,2], StageSettlement[3,3], StageSettlement[3,4]]);
  749. ExecuteSql(sSql);
  750. end;
  751. procedure UpdateZJJLData;
  752. const
  753. sUpdateSql = 'Update P_ZJJL' +
  754. ' Set BGLCode = ''%s'', PegName = ''%s'', FBFXName = ''%s'',' +
  755. ' UnitName = ''%s'', DrawingCode = ''%s''' +
  756. ' Where ID = %d';
  757. var
  758. sSql: string;
  759. ZJJLInfoRec: TZJJLInfoRec;
  760. begin
  761. with PhaseData.ZJJLData do
  762. begin
  763. cdsZJJL.First;
  764. while not cdsZJJL.Eof do
  765. begin
  766. ZJJLInfoRec := GetInfoRec(cdsZJJLBillsID.AsInteger, cdsZJJLType.AsInteger);
  767. sSql := Format(sUpdateSql, [ZJJLInfoRec.BGLCode, ZJJLInfoRec.PegName,
  768. ZJJLInfoRec.FBFXName, ZJJLInfoRec.UnitName, ZJJLInfoRec.DrawingCode,
  769. cdsZJJLID.AsInteger]);
  770. ExecuteSql(sSql);
  771. cdsZJJL.Next;
  772. end;
  773. end;
  774. end;
  775. procedure CopyZJJLBillsData;
  776. var
  777. sSql: string;
  778. begin
  779. sSql := 'Select PZ.ID, B.B_Code, B.Name, B.Units, B.Price, PS.GatherQuantity As Quantity, PS.GatherTotalPrice As TotalPrice' +
  780. ' Into P_ZJJLBills'+
  781. ' From Bills As B, P_Stage As PS, P_ZJJL As PZ' +
  782. ' Where (PZ.BillsID = B.LeafXmjParentID) And (B.ID = PS.BillsID) And (B.IsLeaf=True)';
  783. ExecuteSql(sSql);
  784. end;
  785. procedure CopyZJJLData(const AFileName: string);
  786. var
  787. sSql: string;
  788. begin
  789. sSql := 'Select ID, BillsID, Code, CertificateCode, BillsCode, FormulaMemo, RelaFile,' +
  790. ' '''' As BGLCode, '''' As PegName, '''' As FBFXName, '''' As UnitName, '''' As DrawingCode' +
  791. ' Into P_ZJJL' +
  792. ' From ' + PhaseData.ZJJLData.atZJJL.TableName +
  793. ' In ' + Format('''%s''', [AFileName]);
  794. ExecuteSql(sSql);
  795. // 获取分部分项等实时统计字段值
  796. UpdateZJJLData;
  797. CopyZJJLBillsData;
  798. end;
  799. procedure CopyPhasePayData(const AFileName: string);
  800. const
  801. sCopySql = 'Select ID, TotalPrice%d As CurTotalPrice, EndTotalPrice%d As EndTotalPrice,' +
  802. ' PreTotalPrice%d As PreTotalPrice,' +
  803. ' TotalPrice0, EndTotalPrice0, PreTotalPrice0,' +
  804. ' TotalPrice1, EndTotalPrice1, PreTotalPrice1,' +
  805. ' TotalPrice2, EndTotalPrice2, PreTotalPrice2,' +
  806. ' TotalPrice3, EndTotalPrice3, PreTotalPrice3,' +
  807. ' TotalPrice4, EndTotalPrice4, PreTotalPrice4,' +
  808. ' TotalPrice5, EndTotalPrice5, PreTotalPrice5,' +
  809. ' TotalPrice6, EndTotalPrice6, PreTotalPrice6,' +
  810. ' TotalPrice7, EndTotalPrice7, PreTotalPrice7,' +
  811. ' TotalPrice8, EndTotalPrice8, PreTotalPrice8,' +
  812. ' TotalPrice9, EndTotalPrice9, PreTotalPrice9,' +
  813. ' TotalPrice10, EndTotalPrice10, PreTotalPrice10,' +
  814. ' TotalPrice11, EndTotalPrice11, PreTotalPrice11,' +
  815. ' TotalPrice12, EndTotalPrice12, PreTotalPrice12,' +
  816. ' TotalPrice13, EndTotalPrice13, PreTotalPrice13,' +
  817. ' TotalPrice14, EndTotalPrice14, PreTotalPrice14,' +
  818. ' TotalPrice%d As TotalPrice_F, EndTotalPrice%d As EndTotalPrice_F, PreTotalPrice%d As PreTotalPrice_F' +
  819. ' Into P_PhasePay' +
  820. ' From PhasePay' +
  821. ' In ''%s''';
  822. var
  823. sSql: string;
  824. begin
  825. with PhaseData do
  826. sSql := Format(sCopySql, [StageIndex, StageIndex, StageIndex, StageCount - 1, StageCount - 1, StageCount - 1, AFileName]);
  827. ExecuteSql(sSql);
  828. end;
  829. procedure CopyReportData(const AFileName: string);
  830. const
  831. sCopySql = 'Select Flag, SubFlag, SerialNo, Select1, Result1, Result2' +
  832. ' Into P_ReportData' +
  833. ' From ReportData' +
  834. ' In ''%s''';
  835. begin
  836. ExecuteSql(Format(sCopySql, [AFileName]));
  837. end;
  838. procedure CopyCurPhaseData;
  839. var
  840. sTempFile: string;
  841. i: Integer;
  842. begin
  843. sTempFile := GetTempFileName;
  844. try
  845. SimpleDecrypt(Format('%s\Phase%d.dat', [TempPath, FPhaseIndex]), sTempFile);
  846. // 复制当前阶段数据
  847. CopyStageData(sTempFile, PhaseData.StageData.sdpStage.TableName, 'P_Stage');
  848. // 复制原报、审核、批复数据
  849. // 其中审核、批复数据,如果存在则复制,如果不存在,则创建空表
  850. CopyStageData(sTempFile, 'Refer', 'P_Refer');
  851. for i := 1 to iMaxStageCount - 1 do
  852. if PhaseData.AuditCount >= i then
  853. CopyStageData(sTempFile, PhaseData.StageTableName[i],
  854. 'P_Audit' + IntToStr(i))
  855. else
  856. CopyEmptyStageData(sTempFile, PhaseData.StageTableName[PhaseData.AuditCount],
  857. 'P_Audit' + IntToStr(i));
  858. if PhaseData.StageCount > 1 then
  859. CopyStageData(sTempFile, PhaseData.StageTableName[PhaseData.AuditCount], 'P_Reply')
  860. else
  861. CopyEmptyStageData(sTempFile, PhaseData.StageTableName[PhaseData.AuditCount], 'P_Reply');
  862. AddSettlementData;
  863. CopyZJJLData(sTempFile);
  864. CopyPhasePayData(sTempFile);
  865. CopyReportData(sTempFile);
  866. finally
  867. DeleteFile(sTempFile);
  868. end;
  869. end;
  870. procedure CopyHistoryCompleteData;
  871. const
  872. sCopySql1 = 'Select BillsID, 0 As Quantity1, 0 As TotalPrice1,' +
  873. ' Quantity%d As Quantity2, TotalPrice%d As TotalPrice2' +
  874. ' Into P_Complete' +
  875. ' From PhaseComplete';
  876. sCopySqlN = 'Select BillsID, Quantity%d As Quantity1, TotalPrice%d As TotalPrice1,' +
  877. ' Quantity%d As Quantity2, TotalPrice%d As TotalPrice2' +
  878. ' Into P_Complete' +
  879. ' From PhaseComplete';
  880. sUnionCopySql1 = 'Select BillsID, 0 As Quantity1, 0 As TotalPrice1,' +
  881. ' GatherQuantity As Quantity2, GatherTotalPrice As TotalPrice2' +
  882. ' Into P_Complete' +
  883. ' From P_Stage';
  884. sUnionCopySqlN = 'Select PS.BillsID As BillsID,' +
  885. ' PC.Quantity%d As Quantity1,' +
  886. ' PC.TotalPrice%d As TotalPrice1,' +
  887. ' PC.Quantity%d + PS.GatherQuantity As Quantity2,' +
  888. ' PC.TotalPrice%d + PS.GatherTotalPrice As TotalPrice2' +
  889. ' Into P_Complete' +
  890. ' From PhaseComplete As PC, P_Stage As PS';
  891. var
  892. sSql: string;
  893. begin
  894. if (ProjProperties.FinalAuditCount >= PhaseIndex) then
  895. if PhaseIndex <= 1 then
  896. sSql := Format(sCopySql1, [FPhaseIndex, FPhaseIndex])
  897. else
  898. sSql := Format(sCopySqlN, [PhaseIndex - 1, PhaseIndex - 1, PhaseIndex, PhaseIndex])
  899. else
  900. if PhaseIndex <= 1 then
  901. sSql := sUnionCopySql1
  902. else
  903. sSql := Format(sUnionCopySqlN, [PhaseIndex - 1, PhaseIndex - 1, PhaseIndex - 1, PhaseIndex - 1]);
  904. ExecuteSql(sSql);
  905. end;
  906. procedure UpdateBillsByDealBills;
  907. const
  908. sClearSql = 'Update Bills Set GclDealQuantity = 0, GclDealTotalPrice = 0';
  909. sUpdateSql = 'Update Bills As B, DealBills As D' +
  910. ' Set B.GclDealQuantity = D.Quantity, B.GclDealTotalPrice = D.TotalPrice' +
  911. ' Where (B.B_Code = D.B_Code) and (B.Name = D.Name) and (B.Units = D.Units) and (B.Price = D.Price)';
  912. begin
  913. ExecuteSql(sClearSql);
  914. ExecuteSql(sUpdateSql);
  915. end;
  916. procedure FilterDealBillsByBills;
  917. const
  918. sFilterSql = 'Select D.*' +
  919. ' Into P_FilterDealBills' +
  920. ' From DealBills As D inner join' +
  921. ' (Select D.ID' +
  922. ' From DealBills As D Left join Bills As B' +
  923. ' On (D.B_Code = B.B_Code) and (D.Name = B.Name) and (D.Units = B.Units) and (D.Price = B.Price)' +
  924. ' where B.ID is Null) As R' +
  925. ' On (D.ID = R.ID)';
  926. begin
  927. ExecuteSql(sFilterSql);
  928. end;
  929. procedure CopyCacheReportsData;
  930. begin
  931. // DealBills的数量金额填至Bills中
  932. UpdateBillsByDealBills;
  933. // 过滤DealBills中在Bills中不存在的清单
  934. FilterDealBillsByBills;
  935. end;
  936. procedure SaveCurPhaseCheckers;
  937. const
  938. sCreateSql = 'Create Table P_Checkers (CheckerNo Integer NOT NULL, Name Text(50), Role Text(50), MemoStr Text(255), CheckedDateTime Text(20), Flag Integer,'+
  939. ' CONSTRAINT PrimaryKey PRIMARY KEY (CheckerNo, Flag))';
  940. sInsertSql = 'Insert Into P_Checkers (CheckerNo, Name, Role, MemoStr, CheckedDateTime, Flag) Values (%d, ''%s'', ''%s'', ''%s'', ''%s'', %d)';
  941. var
  942. i: Integer;
  943. vChecker: TChecker;
  944. sSql: string;
  945. begin
  946. ExecuteSql(sCreateSql);
  947. // 全部审核人
  948. for i := 0 to Checkers.Count - 1 do
  949. begin
  950. vChecker := Checkers.Item[i];
  951. sSql := Format(sInsertSql, [vChecker.No, vChecker.Name, vChecker.Role, vChecker.Memo, vChecker.CheckedDateTime, 0]);
  952. ExecuteSql(sSql);
  953. end;
  954. // 审核通过的最后一人
  955. if ProjProperties.AuditStatus <> 0 then
  956. begin
  957. if ProjProperties.AuditStatus = -1 then
  958. vChecker := Checkers.Item[Checkers.Count -1]
  959. else
  960. vChecker := Checkers.Item[ProjProperties.AuditStatus-1];
  961. sSql := Format(sInsertSql, [vChecker.No, vChecker.Name, vChecker.Role, vChecker.Memo, vChecker.CheckedDateTime, 1]);
  962. end
  963. else
  964. sSql := Format(sInsertSql, [-1, '', '', '', '', 1]);
  965. ExecuteSql(sSql);
  966. end;
  967. procedure SaveCloudInfo;
  968. begin
  969. SaveCurPhaseCheckers;
  970. end;
  971. begin
  972. Save;
  973. ClearReportCacheData;
  974. CopyCacheReportsData;
  975. if FPhaseIndex > 0 then
  976. CopyCurPhaseData;
  977. FDealPaymentData.UpdateLinkSerialNo;
  978. //CopyHistoryCompleteData;
  979. if G_IsCloud then
  980. SaveCloudInfo;
  981. if _IsDebugView then
  982. SaveDebugFile('Report.dat');
  983. end;
  984. procedure TProjectData.ExecuteSql(const ASql: string);
  985. var
  986. FQuery: TADOQuery;
  987. begin
  988. FQuery := TADOQuery.Create(nil);
  989. try
  990. FQuery.Connection := FConnection.Connection;
  991. FQuery.SQL.Clear;
  992. FQuery.SQL.Add(ASql);
  993. FQuery.ExecSQL;
  994. finally
  995. FQuery.Free;
  996. end;
  997. end;
  998. function TProjectData.GetADOConnection: TADOConnection;
  999. begin
  1000. Result := FConnection.Connection;
  1001. end;
  1002. procedure TProjectData.ExportJson_Common(const AFileName: string);
  1003. var
  1004. Rec: TsdDataRecord;
  1005. vSL: TStringList;
  1006. sBQHTJL, sBQSLBGJL, sJZSQLJWC, sBQWCJL, sLJWCJL, sTotalPrice: string;
  1007. begin
  1008. vSL := TStringList.Create;
  1009. try
  1010. Rec := MainListData.GetPhaseMainRecord(ProjProperties.PhaseCount);
  1011. sBQHTJL := FloatToStr(Rec.ValueByName('DealTotalPrice').AsFloat); // 本期合同计量
  1012. sBQSLBGJL := FloatToStr(Rec.ValueByName('QcTotalPrice').AsFloat); // 本期数量变更计量
  1013. sJZSQLJWC := FloatToStr(Rec.ValueByName('PreGatherTotalPrice').AsFloat); // 截止上期累计完成
  1014. sBQWCJL := FloatToStr(Rec.ValueByName('GatherTotalPrice').AsFloat); // 本期完成计量
  1015. sLJWCJL := FloatToStr(Rec.ValueByName('EndGatherTotalPrice').AsFloat); // 累计完成计量
  1016. sTotalPrice := FloatToStr(BillsData.Settlement[0] + Rec.ValueByName('EndQcTotalPrice').AsFloat); // 0号台帐+截止本期累期变更计量
  1017. vSL.Text := Format('{"BQHTJL":"%s","BQSLBGJL":"%s","JZSQLJWC":"%s","BQWCJL":"%s","LJWCJL":"%s","TotalPrice":"%s"}',
  1018. [sBQHTJL, sBQSLBGJL, sJZSQLJWC, sBQWCJL, sLJWCJL, sTotalPrice]);
  1019. vSL.SaveToFile(AFileName);
  1020. finally
  1021. vSL.Free;
  1022. end;
  1023. end;
  1024. function TProjectData.CurUserIsAuthor: Boolean;
  1025. begin
  1026. Result := PHPWeb.UserID = WebAuthorID;
  1027. end;
  1028. function TProjectData.CurUserIsChecker: Boolean;
  1029. begin
  1030. Result := (PHPWeb.UserID <> WebOwnerID) and (PHPWeb.UserID <> WebAuthorID);
  1031. end;
  1032. function TProjectData.CurUserIsOwner: Boolean;
  1033. begin
  1034. Result := PHPWeb.UserID = WebOwnerID;
  1035. end;
  1036. procedure TProjectData.SaveLastestPhaseMainData;
  1037. var
  1038. Rec: TsdDataRecord;
  1039. begin
  1040. if (FPhaseIndex = ProjProperties.PhaseCount) and PhaseData.IsLastStage then
  1041. begin
  1042. Rec := MainListData.GetPhaseMainRecord(FPhaseIndex);
  1043. Rec.ValueByName('DealTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[1, 1];
  1044. Rec.ValueByName('QcTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[1, 2];
  1045. Rec.ValueByName('PcTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[1, 3];
  1046. Rec.ValueByName('GatherTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[1, 4];
  1047. Rec.ValueByName('EndDealTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[2, 1];
  1048. Rec.ValueByName('EndQcTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[2, 2];
  1049. Rec.ValueByName('EndPcTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[2, 3];
  1050. Rec.ValueByName('EndGatherTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[2, 4];
  1051. Rec.ValueByName('PreDealTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[3, 1];
  1052. Rec.ValueByName('PreQcTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[3, 2];
  1053. Rec.ValueByName('PrePcTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[3, 3];
  1054. Rec.ValueByName('PreGatherTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[3, 4];
  1055. Rec.ValueByName('PhasePay').AsFloat := PhaseData.PhasePayData.LastestPhasePay[1];
  1056. Rec.ValueByName('EndPhasePay').AsFloat := PhaseData.PhasePayData.LastestPhasePay[2];
  1057. Rec.ValueByName('PrePhasePay').AsFloat := PhaseData.PhasePayData.LastestPhasePay[3];
  1058. end;
  1059. end;
  1060. procedure TProjectData.CalculateAll;
  1061. begin
  1062. FBillsCompileData.CalculateAll; //台账
  1063. FProjectGLData.CalculateAll; //工料价差
  1064. FPhaseData.StageData.CalculateAll; //计量&清单价差
  1065. FBillsMeasureData.CalculateAll; //累计
  1066. FPhaseData.PhasePayData.CalculateAll;
  1067. end;
  1068. procedure TProjectData.ImportCloudTenderFile(const AFileName: string);
  1069. function GetTempFile(const TempDir: string): string;
  1070. var
  1071. FXmlDocument: IXMLDocument;
  1072. XmlNode, InfoXmlNode: IXMLNode;
  1073. ChildNodes: IXMLNodeList;
  1074. begin
  1075. FXmlDocument := TXMLDocument.Create(nil) as IXMLDocument;
  1076. try
  1077. FXmlDocument.LoadFromFile(TempDir + '\Info.xml');
  1078. FXmlDocument.Options := [doNodeAutoCreate,doNodeAutoIndent,doAutoPrefix,doNamespaceDecl];
  1079. XmlNode := FXmlDocument.DocumentElement;
  1080. ChildNodes := XmlNode.ChildNodes;
  1081. InfoXmlNode := ChildNodes.FindNode('ProjectInfo');
  1082. Result := TempDir + '\' + InfoXmlNode.Attributes['FileName'];
  1083. finally
  1084. FXmlDocument := nil;
  1085. end;
  1086. end;
  1087. procedure ClearAllData;
  1088. var
  1089. sSql: string;
  1090. begin
  1091. sSql := 'Delete * From Bills';
  1092. ExecuteSql(sSql);
  1093. sSql := 'Delete * From DealBills';
  1094. ExecuteSql(sSql);
  1095. sSql := 'Delete * From ProjProperties';
  1096. ExecuteSql(sSql);
  1097. sSql := 'Delete * From DealPayment';
  1098. ExecuteSql(sSql);
  1099. end;
  1100. procedure CopyData(const AFileName: string);
  1101. const
  1102. sBillsSql = 'Insert Into Bills (ID, ParentID, NextSiblingID,' +
  1103. ' Code, B_Code, Name, Units, Alias, Price, NewPrice,' +
  1104. ' OrgQuantity, OrgTotalPrice, MisQuantity, MisTotalPrice, OthQuantity, OthTotalPrice,' +
  1105. ' DgnQuantity1, DgnQuantity2,'+
  1106. ' Peg, DrawingCode, MemoStr, HasBookMark, MarkMemo)'+
  1107. ' Select ID, ParentID, NextSiblingID,'+
  1108. ' Code, B_Code, Name, Units, Alias, Price, NewPrice,' +
  1109. ' OrgQuantity, OrgTotalPrice, MisQuantity, MisTotalPrice, OthQuantity, OthTotalPrice,' +
  1110. ' DgnQuantity1, DgnQuantity2,'+
  1111. ' Peg, DrawingCode, MemoStr, HasBookMark, MarkMemo'+
  1112. ' From Bills In ''%s''';
  1113. sDealBillsSql = 'Insert Into DealBills Select ID, B_Code, Name, Units, Price, Quantity, TotalPrice'+
  1114. ' From DealBills In ''%s''';
  1115. sDealPaymentSql = 'Insert Into DealPayment (ID, Name, CalcType, IsMinus,'+
  1116. ' Formula, StartedPrice, SFormula, RangePrice, RFormula)'+
  1117. ' Select ID, Name, CalcType, IsMinus,'+
  1118. ' Formula, StartedPrice, SFormula, RangePrice, RFormula'+
  1119. ' From DealPayment In ''%s''';
  1120. sPropertySql = 'Insert Into ProjProperties'+
  1121. ' Select * From ProjProperties In ''%s'''+
  1122. ' Where (Name <> ''PHASECOUNT'') and (Name <> ''UNLOCKINFOPASSWORD'') and (Name <> ''AUDITSTATUS'')'+
  1123. ' and (Name <> ''FINALAUDITCOUNT'') and (Name <> ''AUDITCOMPANY'') and (Name <> ''UPDATEFLAG'')';
  1124. var
  1125. sSql: string;
  1126. begin
  1127. sSql := Format(sBillsSql, [AFileName]);
  1128. ExecuteSql(sSql);
  1129. sSql := Format(sDealBillsSql, [AFileName]);
  1130. ExecuteSql(sSql);
  1131. sSql := Format(sDealPaymentSql, [AFileName]);
  1132. ExecuteSql(sSql);
  1133. sSql := Format(sPropertySql, [AFileName]);
  1134. ExecuteSql(sSql);
  1135. end;
  1136. function CreateTempSourceFile: string;
  1137. var
  1138. TempDir, TempDir2: string;
  1139. begin
  1140. TempDir := GenerateTempFolder(GetTempPath);
  1141. UnZipFile(AFileName, TempDir);
  1142. try
  1143. TempDir2 := GenerateTempFolder(GetTempPath);
  1144. try
  1145. UnZipFile(GetTempFile(TempDir), TempDir2);
  1146. Result := GetTempFileName;
  1147. SimpleDecrypt(TempDir2 + '\Main.dat', Result);
  1148. finally
  1149. DeleteFileOrFolder(TempDir2);
  1150. end;
  1151. finally
  1152. DeleteFileOrFolder(TempDir);
  1153. end;
  1154. end;
  1155. procedure BeforeCopyData;
  1156. begin
  1157. DisConnectTree;
  1158. CloseAllData;
  1159. end;
  1160. procedure EndCopyData;
  1161. begin
  1162. OpenAllData;
  1163. FProjProperties.Reload;
  1164. FProjProperties.UpdateFlag := 1;
  1165. ReConnectTree;
  1166. ResetFloatDigitView;
  1167. BillsCompileData.CalculateAll;
  1168. end;
  1169. function CheckFile: Boolean;
  1170. var
  1171. TempDir: string;
  1172. Proj: TProjectData;
  1173. begin
  1174. TempDir := GenerateTempFolder(GetTempPath);
  1175. UnZipFile(AFileName, TempDir);
  1176. try
  1177. Proj := TProjectData.Create;
  1178. Proj.SimpleOpen(GetTempFile(TempDir));
  1179. Result := Proj.ProjProperties.UpdateFlag = 1;
  1180. finally
  1181. Proj.Free;
  1182. DeleteFileOrFolder(TempDir);
  1183. end;
  1184. end;
  1185. procedure UpdateSourceFile(const AFileName: string);
  1186. var
  1187. vCon: TADOConnection;
  1188. vUpdate: TUpdateProjectDB;
  1189. begin
  1190. vCon := TADOConnection.Create(nil);
  1191. vCon.LoginPrompt := False;
  1192. try
  1193. vCon.ConnectionString := Format(SAdoConnectStr, [AFileName]);
  1194. vUpdate := TUpdateProjectDB.Create;
  1195. vUpdate.ForceUpdate(vCon);
  1196. finally
  1197. vUpdate.Free;
  1198. vCon.Free;
  1199. end;
  1200. end;
  1201. var
  1202. sTemMainFile: string;
  1203. begin
  1204. sTemMainFile := CreateTempSourceFile;
  1205. UpdateSourceFile(sTemMainFile);
  1206. BeforeCopyData;
  1207. try
  1208. ClearAllData;
  1209. CopyData(sTemMainFile);
  1210. finally
  1211. EndCopyData;
  1212. DeleteFileOrFolder(sTemMainFile);
  1213. end;
  1214. end;
  1215. function TProjectData.CheckPassword: Boolean;
  1216. var
  1217. sPassword: string;
  1218. begin
  1219. if ProjProperties.UnlockInfoPassword = '' then
  1220. Result := True
  1221. else
  1222. begin
  1223. Result := InputPassword(sPassword);
  1224. if Result then
  1225. begin
  1226. Result := sPassword = ProjProperties.UnlockInfoPassword;
  1227. if not Result then ErrorMessage('您输入的密码不正确!');
  1228. end;
  1229. end;
  1230. end;
  1231. procedure TProjectData.SetCheckers(const Value: TCheckers);
  1232. begin
  1233. FCheckers := Value;
  1234. end;
  1235. procedure TProjectData.OpenForSubmit(const AFileName: string);
  1236. begin
  1237. FProjectID := -1;
  1238. UnZipFile(AFileName, TempPath);
  1239. FConnection.Open(MainFileName);
  1240. UpdateProjectDataBase;
  1241. FProjProperties.Open(FConnection.Connection);
  1242. FStaffData.Open(FConnection.Connection);
  1243. end;
  1244. procedure TProjectData.SaveAsForSubmit(const AFileName: string);
  1245. begin
  1246. FStaffData.Save;
  1247. FProjProperties.Save;
  1248. FConnection.Save;
  1249. ZipFolder(FTempFolder, AFileName);
  1250. end;
  1251. procedure TProjectData.LockBillsBaseData;
  1252. const
  1253. sLockInfoSql = 'Update Bills Set LockedInfo = True, LockedLevel = True';
  1254. sLockNPSql = 'Update Bills Set LockedNewPrice = True Where NewPrice <> 0';
  1255. begin
  1256. ExecuteSql(sLockInfoSql);
  1257. ExecuteSql(sLockNPSql);
  1258. end;
  1259. procedure TProjectData.LockDealPaymentData;
  1260. const
  1261. sLockDealSql = 'Update DealPayment Set Locked = True';
  1262. sLockFormulaSql = 'Update DealPayment Set LockedFormula = True Where (Formula <> '''')';
  1263. begin
  1264. ExecuteSql(sLockDealSql);
  1265. ExecuteSql(sLockFormulaSql);
  1266. end;
  1267. procedure TProjectData.LockBGLData;
  1268. const
  1269. sBGSql = 'Update BGL Set Locked = True';
  1270. sBGBillsSql = 'Update BGBills Set Locked = True';
  1271. begin
  1272. ExecuteSql(sBGSql);
  1273. ExecuteSql(sBGBillsSql);
  1274. end;
  1275. procedure TProjectData.OpenForReport(const AFileName: string);
  1276. begin
  1277. FProjectID := -1;
  1278. UnZipFile(AFileName, TempPath);
  1279. FConnection.Open(MainFileName);
  1280. UpdateProjectDataBase;
  1281. FProjProperties.Open(FConnection.Connection);
  1282. UpdateOldData;
  1283. FBillsData.Open(FConnection.Connection);
  1284. FBillsCompileData.Open;
  1285. FDealPaymentData.Open(FConnection.Connection);
  1286. FBGLData.Open(FConnection.Connection);
  1287. end;
  1288. procedure TProjectData.OpenForReply(const AFileName: string);
  1289. begin
  1290. FProjectID := -1;
  1291. UnZipFile(AFileName, TempPath);
  1292. FConnection.Open(MainFileName);
  1293. UpdateProjectDataBase;
  1294. FProjProperties.Open(FConnection.Connection);
  1295. if ProjProperties.PhaseCount > 0 then
  1296. begin
  1297. FPhaseIndex := ProjProperties.PhaseCount;
  1298. FPhaseData.SimpleOpen(Format('%sPhase%d.dat', [TempPath, FPhaseIndex]));
  1299. end;
  1300. FStaffData.Open(FConnection.Connection);
  1301. FDetailGLData.Open(FConnection.Connection);
  1302. end;
  1303. procedure TProjectData.SaveForReply(const AFileName: string);
  1304. begin
  1305. FDetailGLData.Save;
  1306. FStaffData.Save;
  1307. if FPhaseData.Active then
  1308. FPhaseData.SimpleSave;
  1309. FProjProperties.Save;
  1310. FConnection.Save;
  1311. ZipFolder(FTempFolder, AFileName);
  1312. end;
  1313. procedure TProjectData.OpenForReceive(const AFileName: string);
  1314. begin
  1315. FProjectID := -1;
  1316. UnZipFile(AFileName, TempPath);
  1317. FConnection.Open(MainFileName);
  1318. UpdateProjectDataBase;
  1319. FProjProperties.Open(FConnection.Connection);
  1320. if ProjProperties.PhaseCount > 0 then
  1321. begin
  1322. FPhaseIndex := ProjProperties.PhaseCount;
  1323. FPhaseData.SimpleOpen(Format('%sPhase%d.dat', [TempPath, FPhaseIndex]));
  1324. end;
  1325. FStaffData.Open(FConnection.Connection);
  1326. end;
  1327. procedure TProjectData.SaveForReceive(const AFileName: string);
  1328. begin
  1329. FStaffData.Save;
  1330. if FPhaseData.Active then
  1331. FPhaseData.SimpleSave;
  1332. FProjProperties.Save;
  1333. FConnection.Save;
  1334. ZipFolder(FTempFolder, AFileName);
  1335. end;
  1336. procedure TProjectData.CloseAllData;
  1337. begin
  1338. FBillsBookmarkData.Close;
  1339. FBillsData.Close;
  1340. FBillsCompileData.Close;
  1341. FBillsMeasureData.Close;
  1342. FDealBillsData.Close;
  1343. FDealPaymentData.Close;
  1344. FBGLData.Close;
  1345. FStaffData.Close;
  1346. FMainListData.Close;
  1347. end;
  1348. procedure TProjectData.OpenAllData;
  1349. begin
  1350. FProjProperties.Open(FConnection.Connection);
  1351. FBillsData.Open(FConnection.Connection);
  1352. FBillsCompileData.Open;
  1353. FBillsMeasureData.Open;
  1354. FDealBillsData.Open(FConnection.Connection);
  1355. FDealPaymentData.Open(FConnection.Connection);
  1356. FBGLData.Open(FConnection.Connection);
  1357. FStaffData.Open(FConnection.Connection);
  1358. FMainListData.Open(FConnection.Connection);
  1359. FBillsBookmarkData.Open;
  1360. end;
  1361. procedure TProjectData.UpdateOldData;
  1362. procedure UpdateBills_OrgData;
  1363. const
  1364. sUpdateSql = 'Update Bills Set OrgQuantity = Quantity, OrgTotalPrice = TotalPrice';
  1365. begin
  1366. ExecuteSql(sUpdateSql);
  1367. end;
  1368. begin
  1369. if ProjProperties.UpdateFlag = 1 then Exit;
  1370. ProjProperties.UpdateFlag := 1;
  1371. UpdateBills_OrgData;
  1372. end;
  1373. procedure TProjectData.ResetFloatDigitView;
  1374. procedure SetBillsCompileDigit;
  1375. begin
  1376. with FBillsCompileData.sdvBillsCompile do
  1377. begin
  1378. Columns.FindColumn('OrgQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1379. Columns.FindColumn('MisQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1380. Columns.FindColumn('OthQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1381. Columns.FindColumn('Quantity').DisplayFormat := FProjProperties.QuantityFormat;
  1382. Columns.FindColumn('DgnQuantity1').DisplayFormat := FProjProperties.QuantityFormat;
  1383. Columns.FindColumn('DgnQuantity2').DisplayFormat := FProjProperties.QuantityFormat;
  1384. Columns.FindColumn('OrgTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1385. Columns.FindColumn('MisTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1386. Columns.FindColumn('OthTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1387. Columns.FindColumn('TotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1388. Columns.FindColumn('Price').DisplayFormat := FProjProperties.PriceFormat;
  1389. Columns.FindColumn('DgnPrice').DisplayFormat := FProjProperties.PriceFormat;
  1390. Columns.FindColumn('OrgQuantity').EditFormat := FProjProperties.QuantityFormat;
  1391. Columns.FindColumn('MisQuantity').EditFormat := FProjProperties.QuantityFormat;
  1392. Columns.FindColumn('OthQuantity').EditFormat := FProjProperties.QuantityFormat;
  1393. Columns.FindColumn('Quantity').EditFormat := FProjProperties.QuantityFormat;
  1394. Columns.FindColumn('DgnQuantity1').EditFormat := FProjProperties.QuantityFormat;
  1395. Columns.FindColumn('DgnQuantity2').EditFormat := FProjProperties.QuantityFormat;
  1396. Columns.FindColumn('OrgTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1397. Columns.FindColumn('MisTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1398. Columns.FindColumn('OthTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1399. Columns.FindColumn('TotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1400. Columns.FindColumn('Price').EditFormat := FProjProperties.PriceFormat;
  1401. Columns.FindColumn('DgnPrice').EditFormat := FProjProperties.PriceFormat;
  1402. end;
  1403. end;
  1404. procedure SetBillsMeasureDigit;
  1405. begin
  1406. with FBillsMeasureData.sdvBillsMeasure do
  1407. begin
  1408. Columns.FindColumn('Quantity').DisplayFormat := FProjProperties.QuantityFormat;
  1409. Columns.FindColumn('CurDealQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1410. Columns.FindColumn('CurQcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1411. Columns.FindColumn('CurPcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1412. Columns.FindColumn('CurGatherQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1413. Columns.FindColumn('EndDealQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1414. Columns.FindColumn('EndQcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1415. Columns.FindColumn('EndPcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1416. Columns.FindColumn('EndGatherQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1417. Columns.FindColumn('AddDealQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1418. Columns.FindColumn('AddQcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1419. Columns.FindColumn('AddPcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1420. Columns.FindColumn('AddGatherQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1421. Columns.FindColumn('DealDgnQuantity1').DisplayFormat := FProjProperties.QuantityFormat;
  1422. Columns.FindColumn('DealDgnQuantity2').DisplayFormat := FProjProperties.QuantityFormat;
  1423. Columns.FindColumn('CDgnQuantity1').DisplayFormat := FProjProperties.QuantityFormat;
  1424. Columns.FindColumn('CDgnQuantity2').DisplayFormat := FProjProperties.QuantityFormat;
  1425. Columns.FindColumn('TotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1426. Columns.FindColumn('CurDealTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1427. Columns.FindColumn('CurQcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1428. Columns.FindColumn('CurPcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1429. Columns.FindColumn('CurGatherTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1430. Columns.FindColumn('EndDealTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1431. Columns.FindColumn('EndQcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1432. Columns.FindColumn('EndPcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1433. Columns.FindColumn('EndGatherTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1434. Columns.FindColumn('AddDealTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1435. Columns.FindColumn('AddQcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1436. Columns.FindColumn('AddPcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1437. Columns.FindColumn('AddGatherTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1438. Columns.FindColumn('Price').DisplayFormat := FProjProperties.PriceFormat;
  1439. Columns.FindColumn('NewPrice').DisplayFormat := FProjProperties.PriceFormat;
  1440. Columns.FindColumn('Quantity').EditFormat := FProjProperties.QuantityFormat;
  1441. Columns.FindColumn('CurDealQuantity').EditFormat := FProjProperties.QuantityFormat;
  1442. Columns.FindColumn('CurQcQuantity').EditFormat := FProjProperties.QuantityFormat;
  1443. Columns.FindColumn('CurPcQuantity').EditFormat := FProjProperties.QuantityFormat;
  1444. Columns.FindColumn('CurGatherQuantity').EditFormat := FProjProperties.QuantityFormat;
  1445. Columns.FindColumn('EndDealQuantity').EditFormat := FProjProperties.QuantityFormat;
  1446. Columns.FindColumn('EndQcQuantity').EditFormat := FProjProperties.QuantityFormat;
  1447. Columns.FindColumn('EndPcQuantity').EditFormat := FProjProperties.QuantityFormat;
  1448. Columns.FindColumn('EndGatherQuantity').EditFormat := FProjProperties.QuantityFormat;
  1449. Columns.FindColumn('AddDealQuantity').EditFormat := FProjProperties.QuantityFormat;
  1450. Columns.FindColumn('AddQcQuantity').EditFormat := FProjProperties.QuantityFormat;
  1451. Columns.FindColumn('AddPcQuantity').EditFormat := FProjProperties.QuantityFormat;
  1452. Columns.FindColumn('AddGatherQuantity').EditFormat := FProjProperties.QuantityFormat;
  1453. Columns.FindColumn('DealDgnQuantity1').EditFormat := FProjProperties.QuantityFormat;
  1454. Columns.FindColumn('DealDgnQuantity2').EditFormat := FProjProperties.QuantityFormat;
  1455. Columns.FindColumn('CDgnQuantity1').EditFormat := FProjProperties.QuantityFormat;
  1456. Columns.FindColumn('CDgnQuantity2').EditFormat := FProjProperties.QuantityFormat;
  1457. Columns.FindColumn('TotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1458. Columns.FindColumn('CurDealTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1459. Columns.FindColumn('CurQcTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1460. Columns.FindColumn('CurPcTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1461. Columns.FindColumn('CurGatherTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1462. Columns.FindColumn('EndDealTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1463. Columns.FindColumn('EndQcTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1464. Columns.FindColumn('EndPcTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1465. Columns.FindColumn('EndGatherTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1466. Columns.FindColumn('AddDealTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1467. Columns.FindColumn('AddQcTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1468. Columns.FindColumn('AddPcTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1469. Columns.FindColumn('AddGatherTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1470. Columns.FindColumn('Price').EditFormat := FProjProperties.PriceFormat;
  1471. Columns.FindColumn('NewPrice').EditFormat := FProjProperties.PriceFormat;
  1472. end;
  1473. end;
  1474. procedure SetBillsGatherDigit;
  1475. begin
  1476. with FBillsGatherData.sdvGclBills do
  1477. begin
  1478. Columns.FindColumn('Price').DisplayFormat := FProjProperties.PriceFormat;
  1479. Columns.FindColumn('DealQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1480. Columns.FindColumn('DealTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1481. Columns.FindColumn('BGLQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1482. Columns.FindColumn('BGLTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1483. Columns.FindColumn('Quantity').DisplayFormat := FProjProperties.QuantityFormat;
  1484. Columns.FindColumn('TotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1485. Columns.FindColumn('CurDealQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1486. Columns.FindColumn('CurDealTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1487. Columns.FindColumn('CurQcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1488. Columns.FindColumn('CurQcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1489. Columns.FindColumn('CurGatherQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1490. Columns.FindColumn('CurGatherTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1491. Columns.FindColumn('PreDealQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1492. Columns.FindColumn('PreDealTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1493. Columns.FindColumn('PreQcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1494. Columns.FindColumn('PreQcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1495. Columns.FindColumn('PreGatherQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1496. Columns.FindColumn('PreGatherTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1497. Columns.FindColumn('AddDealQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1498. Columns.FindColumn('AddDealTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1499. Columns.FindColumn('AddQcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1500. Columns.FindColumn('AddQcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1501. Columns.FindColumn('AddGatherQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1502. Columns.FindColumn('AddGatherTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1503. Columns.FindColumn('EndDealQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1504. Columns.FindColumn('EndDealTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1505. Columns.FindColumn('EndQcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1506. Columns.FindColumn('EndQcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1507. Columns.FindColumn('EndGatherQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1508. Columns.FindColumn('EndGatherTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1509. Columns.FindColumn('Deal_BGLQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1510. Columns.FindColumn('Deal_BGLTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1511. end;
  1512. with FBillsGatherData.sdvDetailGclBills do
  1513. begin
  1514. Columns.FindColumn('Quantity').DisplayFormat := FProjProperties.QuantityFormat;
  1515. end;
  1516. with FBillsGatherData.sdvDetailDealBills do
  1517. begin
  1518. Columns.FindColumn('Quantity').DisplayFormat := FProjProperties.QuantityFormat;
  1519. Columns.FindColumn('TotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1520. end;
  1521. with FBillsGatherData.sdvDetailBGLBills do
  1522. begin
  1523. Columns.FindColumn('Quantity').DisplayFormat := FProjProperties.QuantityFormat;
  1524. Columns.FindColumn('TotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1525. end;
  1526. end;
  1527. procedure SetDealPaymentDigit;
  1528. begin
  1529. with FDealPaymentData.sdvDealPayment do
  1530. begin
  1531. Columns.FindColumn('CurTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1532. Columns.FindColumn('TotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1533. Columns.FindColumn('StartedPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1534. Columns.FindColumn('RangePrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1535. end;
  1536. end;
  1537. begin
  1538. SetBillsCompileDigit;
  1539. SetBillsMeasureDigit;
  1540. SetDealPaymentDigit;
  1541. SetBillsGatherDigit;
  1542. end;
  1543. function TProjectData.GetStageDataReadOnly: Boolean;
  1544. begin
  1545. if FPhaseData.Active then
  1546. Result := FPhaseData.StageDataReadOnly
  1547. else
  1548. Result := True;
  1549. end;
  1550. procedure TProjectData.OpenForReport2(const AFileName: string);
  1551. begin
  1552. FProjectID := -1;
  1553. UnZipFile(AFileName, TempPath);
  1554. FConnection.Open(MainFileName);
  1555. UpdateProjectDataBase;
  1556. FProjProperties.Open(FConnection.Connection);
  1557. UpdateOldData;
  1558. FBillsData.Open(FConnection.Connection);
  1559. FBillsCompileData.Open;
  1560. FDealPaymentData.Open(FConnection.Connection);
  1561. FBGLData.Open(FConnection.Connection);
  1562. if ProjProperties.PhaseCount > 0 then
  1563. begin
  1564. FPhaseIndex := ProjProperties.PhaseCount;
  1565. FPhaseData.SimpleOpen(Format('%sPhase%d.dat', [TempPath, FPhaseIndex]));
  1566. end;
  1567. end;
  1568. function TProjectData.CheckDataBaseInfo(APhaseCount, AAuditStatus: Integer): Boolean;
  1569. begin
  1570. Result := (FProjProperties.PhaseCount = APhaseCount)
  1571. and (FProjProperties.AuditStatus = AAuditStatus);
  1572. if Result and (APhaseCount > 0) and (AAuditStatus <> -1) then
  1573. Result := PhaseData.AuditCount = AAuditStatus;
  1574. end;
  1575. procedure TProjectData.OpenForReport3(const AFileName: string);
  1576. begin
  1577. FProjectID := -1;
  1578. UnZipFile(AFileName, TempPath);
  1579. FConnection.Open(MainFileName);
  1580. UpdateProjectDataBase;
  1581. FProjProperties.Open(FConnection.Connection);
  1582. UpdateOldData;
  1583. FBillsData.Open(FConnection.Connection);
  1584. FBillsMeasureData.Open;
  1585. FDealPaymentData.Open(FConnection.Connection);
  1586. FBGLData.Open(FConnection.Connection);
  1587. if ProjProperties.PhaseCount > 0 then
  1588. begin
  1589. FPhaseIndex := ProjProperties.PhaseCount;
  1590. FPhaseData.SimpleOpen2(Format('%sPhase%d.dat', [TempPath, FPhaseIndex]));
  1591. end;
  1592. FBillsMeasureData.ResetTreeNodeStageRec;
  1593. end;
  1594. function TProjectData.GetPriceMarginReadOnly: Boolean;
  1595. begin
  1596. if FPhaseData.Active then
  1597. Result := not((FPhaseIndex = FProjProperties.PhaseCount) and (FPhaseData.StageCount = 1) and (FProjProperties.AuditStatus <> -1))
  1598. else
  1599. Result := True;
  1600. end;
  1601. procedure TProjectData.CalculatePriceMargin;
  1602. begin
  1603. // 计算工料价差数据
  1604. FProjectGLData.CalculateAll;
  1605. if not FPhaseData.StageDataReadOnly then
  1606. begin
  1607. // 计算清单价差节点
  1608. PhaseData.StageData.CalculatePriceMarginNode;
  1609. // 计算合同支付
  1610. PhaseData.PhasePayData.CalculateAll;
  1611. end;
  1612. end;
  1613. procedure TProjectData.LockProjectGLData;
  1614. const
  1615. sLockSql = 'Update ProjectGL As P, GLPrice As G' +
  1616. ' Set P.LockedPhaseID = %d'+
  1617. ' Where (P.ID = G.GLID) and (G.PM_Quantity_F <> 0) and (IsNull(P.LockedPhaseID) or (P.LockedPhaseID = 0))';
  1618. var
  1619. sSql: string;
  1620. begin
  1621. sSql := Format(sLockSql, [FProjProperties.PhaseCount]);
  1622. ExecuteSql(sSql);
  1623. end;
  1624. procedure TProjectData.LockDetailGLData;
  1625. const
  1626. sLockSql = 'Update DetailGL As D Set D.LockedPhaseID = %d' +
  1627. ' Where (D.LastBillsQuantity <> 0) and (IsNull(D.LockedPhaseID) or (D.LockedPhaseID = 0))';
  1628. var
  1629. sSql: string;
  1630. begin
  1631. sSql := Format(sLockSql, [FProjProperties.PhaseCount]);
  1632. ExecuteSql(sSql);
  1633. end;
  1634. procedure TProjectData.CopyPreData;
  1635. procedure CopyPreGLPrice;
  1636. const
  1637. sCopySql = 'Insert Into GLPrice (GLID, PhaseID,' +
  1638. ' InfoPrice, InfoDate, DeltaPrice, ValidDeltaPrice,' +
  1639. ' PM_PreQuantity, PM_PreTotalPrice)'+
  1640. ' Select GLID, %d,'+
  1641. ' InfoPrice, InfoDate, DeltaPrice, ValidDeltaPrice,'+
  1642. ' PM_PreQuantity+PM_Quantity_F, PM_PreTotalPrice+PM_TotalPrice_F'+
  1643. ' From GLPrice Where PhaseID = %d';
  1644. begin
  1645. if FProjProperties.PhaseCount > 1 then
  1646. ExecuteSql(Format(sCopySql, [FProjProperties.PhaseCount, FProjProperties.PhaseCount - 1]));
  1647. end;
  1648. begin
  1649. CopyPreGLPrice;
  1650. PhaseData.CopyPreData;
  1651. ProjectGLData.LoadCurPhaseInfoPrice;
  1652. ProjectGLData.LoadStagePM_CalcData;
  1653. BillsMeasureData.ResetTreeNodeStageRec;
  1654. end;
  1655. function TProjectData.GetStageIndex: Integer;
  1656. begin
  1657. Result := FPhaseData.StageIndex;
  1658. end;
  1659. procedure TProjectData.SetStageIndex(const Value: Integer);
  1660. begin
  1661. FProjectGLData.Save;
  1662. FPhaseData.StageIndex := Value;
  1663. FProjectGLData.LoadStagePM_CalcData;
  1664. end;
  1665. procedure TProjectData.ClearReportCacheData;
  1666. begin
  1667. DropCacheTable('P_');
  1668. end;
  1669. function TProjectData.GetCanInsertNormalBills: Boolean;
  1670. begin
  1671. if FProjProperties.PhaseCount > 0 then
  1672. Result := CanUnlockInfo
  1673. else
  1674. Result := True;
  1675. end;
  1676. procedure TProjectData.ClearReportPrepareData;
  1677. begin
  1678. DropCacheTable('rdp_');
  1679. end;
  1680. procedure TProjectData.DropCacheTable(const AKey: string);
  1681. var
  1682. FTableList: TStringList;
  1683. iIndex: Integer;
  1684. sDeleteTableSql: String;
  1685. begin
  1686. FTableList := TStringList.Create;
  1687. try
  1688. FConnection.Connection.GetTableNames(FTableList);
  1689. iIndex := 0;
  1690. while iIndex < FTableList.Count do
  1691. begin
  1692. if Pos(AKey, FTableList.Strings[iIndex]) = 1 then
  1693. begin
  1694. sDeleteTableSql := Format('Drop Table %s', [FTableList.Strings[iIndex]]);
  1695. ExecuteSql(sDeleteTableSql);
  1696. end;
  1697. Inc(iIndex);
  1698. end;
  1699. finally
  1700. FTableList.Free;
  1701. end;
  1702. end;
  1703. procedure TProjectData.SaveDebugFile(const AFileName: string);
  1704. var
  1705. sFileName: string;
  1706. begin
  1707. sFileName := ExtractFileName(AFileName);
  1708. FConnection.SaveDebugFile(FDebugDir + '\' + sFileName);
  1709. end;
  1710. procedure TProjectData.SaveTempDataBaseFile(const AFileName: string);
  1711. begin
  1712. FConnection.SaveDebugFile(AFileName);
  1713. end;
  1714. procedure TProjectData.ImportDmfFile(const AFileName: string);
  1715. begin
  1716. ImportDbTreeTo(AFileName, Self);
  1717. end;
  1718. function TProjectData.GetValidStageIsRefer: Boolean;
  1719. begin
  1720. if FPhaseData.Active then
  1721. Result := (FPhaseIndex = FProjProperties.PhaseCount) and (FPhaseData.StageCount = 1) and (FProjProperties.AuditStatus <> -1)
  1722. else
  1723. Result := False;
  1724. end;
  1725. end.