ProjectData.pas 57 KB

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