ProjectData.pas 58 KB

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