ProjectData.pas 69 KB

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