ProjectData.pas 59 KB

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