ProjectData.pas 64 KB

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