ProjectData.pas 59 KB

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