ProjectData.pas 69 KB

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