ProjectData.pas 59 KB

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