ProjectData.pas 52 KB

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