ProjectData.pas 52 KB

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