ProjectData.pas 64 KB

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