ProjectData.pas 63 KB

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