ProjectData.pas 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952
  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. //BillsGatherData.RefreshBills;
  488. end;
  489. procedure TProjectData.SetPhaseIndexSimple(AIndex: Integer);
  490. begin
  491. FPhaseIndex := AIndex;
  492. if FPhaseData.Active then
  493. FPhaseData.SimpleSave;
  494. FPhaseData.Free;
  495. FPhaseData := TPhaseData.Create(Self);
  496. FPhaseData.SimpleOpen(Format('%s\Phase%d.dat', [TempPath, FPhaseIndex]));
  497. end;
  498. procedure TProjectData.UpdateProjectDataBase;
  499. begin
  500. if TEncryptConnection(FConnection).OverExe then
  501. WarningMessage('标段版本高于当前软件版本,可能会产生错误。');
  502. FUpdator.Update(FConnection);
  503. end;
  504. procedure TProjectData.ResetPhaseDataLink;
  505. begin
  506. BillsMeasureData.ResetPhaseStageLink;
  507. BillsMeasureData.ResetTreeNodeStageRec;
  508. DealPaymentData.ResetPhaseLink;
  509. BillsBookmarkData.ResetPhaseStageLink;
  510. end;
  511. procedure TProjectData.SimpleOpen(const AFileName: string);
  512. begin
  513. FProjectID := -1;
  514. UnZipFile(AFileName, TempPath);
  515. FConnection.Open(MainFileName);
  516. UpdateProjectDataBase;
  517. FProjProperties.Open(FConnection.Connection);
  518. if ProjProperties.PhaseCount > 0 then
  519. begin
  520. FPhaseIndex := ProjProperties.PhaseCount;
  521. FPhaseData.SimpleOpen(Format('%sPhase%d.dat', [TempPath, FPhaseIndex]));
  522. end;
  523. end;
  524. procedure TProjectData.SimpleSaveAs(const AFileName: string);
  525. begin
  526. if FPhaseData.Active then
  527. FPhaseData.SimpleSave;
  528. FProjProperties.Save;
  529. FConnection.Save;
  530. ZipFolder(FTempFolder, AFileName);
  531. end;
  532. procedure TProjectData.UpdateDataForReceive;
  533. begin
  534. UpdatePhaseData;
  535. end;
  536. procedure TProjectData.UpdatePhaseData;
  537. function GetUpdateGLPriceSql(AAuditStatus, APhaseCount: Integer): string;
  538. const
  539. vFields: array [0..5] of String = ('PM_Quantity', 'PM_TotalPrice', 'PAL_UsedQuantity', 'PAL_UsedTotalPrice', 'PAL_DeltaPrice', 'PAL_Total');
  540. sUpdateSql = 'Update GLPrice Set %s Where PhaseID = %d';
  541. {sUpdateSql = 'Update GLPrice Set PM_Quantity%d = PM_Quantity%d, PM_TotalPrice%d = PM_TotalPrice%d,'+
  542. ' PAL_UsedQuantity%d = PAL_UsedQuantity%d, PAL_UsedTotalPrice%d = PAL_UsedTotalPrice%d,'+
  543. ' PAL_DeltaPrice%d = PAL_DeltaPrice%d, PAL_Total%d = PAL_Total%d'+
  544. ' Where PhaseID = %d';}
  545. var
  546. sField: string;
  547. i: Integer;
  548. begin
  549. sField := '';
  550. for i := Low(vFields) to High(vFields) do
  551. begin
  552. if i = High(vFields) then
  553. sField := sField + Format('%s%d = %s%d', [vFields[i], AAuditStatus, vFields[i], AAuditStatus-1])
  554. else
  555. sField := sField + Format('%s%d = %s%d, ', [vFields[i], AAuditStatus, vFields[i], AAuditStatus-1])
  556. end;
  557. Result := Format(sUpdateSql, [sField, APhaseCount]);
  558. end;
  559. procedure UpdateGLPriceData;
  560. var
  561. sSql: string;
  562. begin
  563. if (ProjProperties.PhaseCount < 1) or (ProjProperties.AuditStatus < 1) then Exit;
  564. sSql := GetUpdateGLPriceSql(ProjProperties.AuditStatus, ProjProperties.PhaseCount);
  565. ExecuteSql(sSql);
  566. end;
  567. var
  568. iPhase: Integer;
  569. begin
  570. FProjProperties.AuditStatus := FProjProperties.AuditStatus + 1;
  571. for iPhase := FProjProperties.FinalAuditCount + 1 to FProjProperties.PhaseCount do
  572. begin
  573. SetPhaseIndexSimple(iPhase);
  574. PhaseData.CreateNewAuditData;
  575. StaffData.UpdateDataForNewAudit;
  576. UpdateGLPriceData;
  577. end;
  578. end;
  579. function TProjectData.ReplyProject(const AFileName: string = ''): Boolean;
  580. var
  581. Replyor: TReplyProject;
  582. begin
  583. Replyor := TReplyProject.Create(FProjectName, FFileName, FProjectID);
  584. try
  585. if AFileName = '' then
  586. Result := Replyor.Execute
  587. else
  588. Result := Replyor.ExportTo(AFileName);
  589. finally
  590. Replyor.Free;
  591. end;
  592. end;
  593. function TProjectData.SubmitProject(const AFileName: string = ''): Boolean;
  594. var
  595. Submitor :TSubmitProject;
  596. begin
  597. Submitor := TSubmitProject.Create(FProjectName, FFileName, FProjectID);
  598. try
  599. if AFileName = '' then
  600. Result := Submitor.Execute
  601. else
  602. Result := Submitor.ExportTo(AFileName);
  603. finally
  604. Submitor.Free;
  605. end;
  606. end;
  607. procedure TProjectData.ExportJson_Bills(const AFileName: string);
  608. function GetProjectName: string;
  609. var
  610. vNode: tsdIDTreeNode;
  611. begin
  612. vNode := ProjectManager.ProjectsTree.FindNode(FProjectID).Parent;
  613. Result := vNode.Rec.ValueByName('Name').AsString;
  614. end;
  615. // lkJSON 暂时未找到添加数组结构的办法,官方也没有提供相关的Demo,自己合成。
  616. // lkJSON 合成的长文本自动带有大量“\”转义字符,这点有些烦人。
  617. // 其实这么折腾,还不如自己直接合成。那为什么还要用它?自己写是很容易,但是
  618. // 要自己读JSON,那写起来就很麻烦了。
  619. function BillsStr: string;
  620. var vRec: TsdDataRecord;
  621. i: Integer;
  622. sSplit: string;
  623. function v(AFieldName: string): string;
  624. begin
  625. Result := vRec.ValueByName(AFieldName).AsString;
  626. end;
  627. // 杰哥那头不识别中文,将中文转成URL编码形式
  628. function URLEncode(const S: string; const InQueryString: Boolean): string;
  629. var
  630. Idx: Integer;
  631. begin
  632. Result := '';
  633. for Idx := 1 to Length(S) do
  634. begin
  635. case S[Idx] of
  636. 'A'..'Z', 'a'..'z', '0'..'9', '-', '_', '.':
  637. Result := Result + S[Idx];
  638. ' ':
  639. if InQueryString then
  640. Result := Result + '+'
  641. else
  642. Result := Result + '%20';
  643. else
  644. Result := Result + '%' + SysUtils.IntToHex(Ord(S[Idx]), 2);
  645. end;
  646. end;
  647. end;
  648. begin
  649. for i := 0 to BillsMeasureData.BillsMeasureTree.Count - 1 do
  650. begin
  651. vRec := BillsMeasureData.BillsMeasureTree.Items[i].Rec;
  652. if (i mod 100) = 0 then
  653. ProgressProRun('生成汇总数据... ' + IntToStr(i), 0, pmtEdit, pptSet);
  654. if i = 0 then
  655. sSplit := ''
  656. else
  657. sSplit := ',';
  658. Result := Result + sSplit + Format('{"Code":"%s","B_Code":"%s","Name":"%s",' +
  659. '"Units":"%s","Price":"%s","Quantity":"%s","TotalPrice":"%s"}',
  660. [v('Code'), v('B_Code'), v('Name'), v('Units'), v('Price'),
  661. v('Quantity'), v('TotalPrice')]);
  662. end;
  663. end;
  664. var
  665. fPhasePay: Double;
  666. vSL: TStringList;
  667. begin
  668. vSL := TStringList.Create;
  669. try
  670. vSL.Text := Format('{"DealTotalPrice":"%s","Bills":[%s]}',
  671. [FloatToStr(FBillsData.Settlement[DealIndex]), AnsiToUtf8(BillsStr)]);
  672. vSL.SaveToFile(AFileName);
  673. finally
  674. vSL.Free;
  675. end;
  676. end;
  677. procedure TProjectData.DisConnectTree;
  678. begin
  679. BillsMeasureData.BillsMeasureTree.Active := False;
  680. BillsCompileData.BillsCompileTree.Active := False;
  681. end;
  682. procedure TProjectData.ReConnectTree;
  683. begin
  684. BillsCompileData.ReConnectTree;
  685. BillsMeasureData.ReConnectTree;
  686. end;
  687. procedure TProjectData.CopyPhaseCompleteData;
  688. const
  689. sInsertSql = 'Insert Into PhaseComplete (BillsID)' +
  690. ' Select ID' +
  691. ' From Bills where Bills.CreatePhaseID = %d';
  692. sUpdateSql = 'Update PhaseComplete Inner Join [Bills]' +
  693. ' On PhaseComplete.BillsID=Bills.ID' +
  694. ' Set PhaseComplete.Quantity%d=Bills.AddGatherQuantity,' +
  695. ' PhaseComplete.TotalPrice%d=Bills.AddGatherTotalPrice';
  696. var
  697. iPhase: Integer;
  698. sSql: string;
  699. begin
  700. for iPhase := FProjProperties.FinalAuditCount + 1 to FProjProperties.PhaseCount do
  701. begin
  702. SetPhaseIndexSimple(iPhase);
  703. // 插入本期新增的数据
  704. sSql := Format(sInsertSql, [iPhase]);
  705. ExecuteSql(sSql);
  706. // 更新所有截止本期完成计量数据
  707. sSql := Format(sInsertSql, [iPhase, iPhase]);
  708. ExecuteSql(sSql);
  709. end;
  710. end;
  711. procedure TProjectData.CopyPhaseData;
  712. procedure CopyStageData(const AFileName, ASourceTable, AResultTable: string);
  713. const
  714. sCopySql = 'Select BillsID, DealQuantity, DealTotalPrice, QcQuantity, QcTotalPrice, QcBGLCode, QcBGLNum,' +
  715. ' PcQuantity, PcTotalPrice, PcBGLCode, PcBGLNum, GatherQuantity, GatherTotalPrice,' +
  716. ' EndDealQuantity, EndDealTotalPrice, EndQcQuantity, EndQcTotalPrice,' +
  717. ' EndPcQuantity, EndPcTotalPrice, EndGatherQuantity, EndGatherTotalPrice,' +
  718. ' PreDealQuantity, PreDealTotalPrice, PreQcQuantity, PreQcTotalPrice,' +
  719. ' PrePcQuantity, PrePcTotalPrice, PreGatherQuantity, PreGatherTotalPrice' +
  720. ' Into %s' +
  721. ' From %s' +
  722. ' In ''%s''';
  723. var
  724. sSql: string;
  725. begin
  726. sSql := Format(sCopySql, [AResultTable, ASourceTable, AFileName]);
  727. ExecuteSql(sSql);
  728. end;
  729. procedure CopyEmptyStageData(const AFileName, ASourceTable, AResultTable: string);
  730. const
  731. sCopySql = 'Select BillsID, DealQuantity, DealTotalPrice, QcQuantity, QcTotalPrice, QcBGLCode, QcBGLNum,' +
  732. ' PcQuantity, PcTotalPrice, PcBGLCode, PcBGLNum, GatherQuantity, GatherTotalPrice,' +
  733. ' EndDealQuantity, EndDealTotalPrice, EndQcQuantity, EndQcTotalPrice,' +
  734. ' EndPcQuantity, EndPcTotalPrice, EndGatherQuantity, EndGatherTotalPrice,' +
  735. ' PreDealQuantity, PreDealTotalPrice, PreQcQuantity, PreQcTotalPrice,' +
  736. ' PrePcQuantity, PrePcTotalPrice, PreGatherQuantity, PreGatherTotalPrice' +
  737. ' Into %s' +
  738. ' From %s' +
  739. ' In ''%s''' +
  740. ' Where 1=2';
  741. var
  742. sSql: string;
  743. begin
  744. sSql := Format(sCopySql, [AResultTable, ASourceTable, AFileName]);
  745. ExecuteSql(sSql);
  746. end;
  747. procedure AddSettlementData;
  748. const
  749. sAddSql = 'Insert Into P_Stage (BillsID,' +
  750. ' DealTotalPrice, QcTotalPrice, PcTotalPrice, GatherTotalPrice,' +
  751. ' EndDealTotalPrice, EndQcTotalPrice, EndPcTotalPrice, EndGatherTotalPrice,' +
  752. ' PreDealTotalPrice, PreQcTotalPrice, PrePcTotalPrice, PreGatherTotalPrice)' +
  753. ' Values (-2,'+
  754. ' %f, %f, %f, %f,'+
  755. ' %f, %f, %f, %f,'+
  756. ' %f, %f, %f, %f)';
  757. var
  758. sSql: string;
  759. begin
  760. with PhaseData.StageData do
  761. sSql := Format(sAddSql,
  762. [StageSettlement[1,1], StageSettlement[1,2], StageSettlement[1,3], StageSettlement[1,4],
  763. StageSettlement[2,1], StageSettlement[2,2], StageSettlement[2,3], StageSettlement[2,4],
  764. StageSettlement[3,1], StageSettlement[3,2], StageSettlement[3,3], StageSettlement[3,4]]);
  765. ExecuteSql(sSql);
  766. end;
  767. procedure UpdateZJJLData;
  768. const
  769. sUpdateSql = 'Update P_ZJJL' +
  770. ' Set BGLCode = ''%s'', PegName = ''%s'', FBFXName = ''%s'',' +
  771. ' UnitName = ''%s'', DrawingCode = ''%s''' +
  772. ' Where ID = %d';
  773. var
  774. sSql: string;
  775. ZJJLInfoRec: TZJJLInfoRec;
  776. begin
  777. with PhaseData.ZJJLData do
  778. begin
  779. cdsZJJL.First;
  780. while not cdsZJJL.Eof do
  781. begin
  782. ZJJLInfoRec := GetInfoRec(cdsZJJLBillsID.AsInteger, cdsZJJLType.AsInteger);
  783. sSql := Format(sUpdateSql, [ZJJLInfoRec.BGLCode, ZJJLInfoRec.PegName,
  784. ZJJLInfoRec.FBFXName, ZJJLInfoRec.UnitName, ZJJLInfoRec.DrawingCode,
  785. cdsZJJLID.AsInteger]);
  786. ExecuteSql(sSql);
  787. cdsZJJL.Next;
  788. end;
  789. end;
  790. end;
  791. procedure CopyZJJLBillsData;
  792. var
  793. sSql: string;
  794. begin
  795. sSql := 'Select PZ.ID, B.B_Code, B.Name, B.Units, B.Price, PS.GatherQuantity As Quantity, PS.GatherTotalPrice As TotalPrice' +
  796. ' Into P_ZJJLBills'+
  797. ' From Bills As B, P_Stage As PS, P_ZJJL As PZ' +
  798. ' Where (PZ.BillsID = B.LeafXmjParentID) And (B.ID = PS.BillsID) And (B.IsLeaf=True)';
  799. ExecuteSql(sSql);
  800. end;
  801. procedure CopyZJJLData(const AFileName: string);
  802. var
  803. sSql: string;
  804. begin
  805. sSql := 'Select ID, BillsID, Code, CertificateCode, BillsCode, FormulaMemo, RelaFile,' +
  806. ' '''' As BGLCode, '''' As PegName, '''' As FBFXName, '''' As UnitName, '''' As DrawingCode' +
  807. ' Into P_ZJJL' +
  808. ' From ' + PhaseData.ZJJLData.atZJJL.TableName +
  809. ' In ' + Format('''%s''', [AFileName]);
  810. ExecuteSql(sSql);
  811. // 获取分部分项等实时统计字段值
  812. UpdateZJJLData;
  813. CopyZJJLBillsData;
  814. end;
  815. procedure CopyPhasePayData(const AFileName: string);
  816. const
  817. sCopySql = 'Select ID, TotalPrice%d As CurTotalPrice, EndTotalPrice%d As EndTotalPrice,' +
  818. ' PreTotalPrice%d As PreTotalPrice,' +
  819. ' TotalPrice0, EndTotalPrice0, PreTotalPrice0,' +
  820. ' TotalPrice1, EndTotalPrice1, PreTotalPrice1,' +
  821. ' TotalPrice2, EndTotalPrice2, PreTotalPrice2,' +
  822. ' TotalPrice3, EndTotalPrice3, PreTotalPrice3,' +
  823. ' TotalPrice4, EndTotalPrice4, PreTotalPrice4,' +
  824. ' TotalPrice5, EndTotalPrice5, PreTotalPrice5,' +
  825. ' TotalPrice6, EndTotalPrice6, PreTotalPrice6,' +
  826. ' TotalPrice7, EndTotalPrice7, PreTotalPrice7,' +
  827. ' TotalPrice8, EndTotalPrice8, PreTotalPrice8,' +
  828. ' TotalPrice9, EndTotalPrice9, PreTotalPrice9,' +
  829. ' TotalPrice10, EndTotalPrice10, PreTotalPrice10,' +
  830. ' TotalPrice11, EndTotalPrice11, PreTotalPrice11,' +
  831. ' TotalPrice12, EndTotalPrice12, PreTotalPrice12,' +
  832. ' TotalPrice13, EndTotalPrice13, PreTotalPrice13,' +
  833. ' TotalPrice14, EndTotalPrice14, PreTotalPrice14,' +
  834. ' TotalPrice%d As TotalPrice_F, EndTotalPrice%d As EndTotalPrice_F, PreTotalPrice%d As PreTotalPrice_F' +
  835. ' Into P_PhasePay' +
  836. ' From PhasePay' +
  837. ' In ''%s''';
  838. var
  839. sSql: string;
  840. begin
  841. with PhaseData do
  842. sSql := Format(sCopySql, [StageIndex, StageIndex, StageIndex, StageCount - 1, StageCount - 1, StageCount - 1, AFileName]);
  843. ExecuteSql(sSql);
  844. end;
  845. procedure CopyReportData(const AFileName: string);
  846. const
  847. sCopySql = 'Select Flag, SubFlag, SerialNo, Select1, Result1, Result2' +
  848. ' Into P_ReportData' +
  849. ' From ReportData' +
  850. ' In ''%s''';
  851. begin
  852. ExecuteSql(Format(sCopySql, [AFileName]));
  853. end;
  854. procedure CopyCurPhaseData;
  855. var
  856. sTempFile: string;
  857. i: Integer;
  858. begin
  859. sTempFile := GetTempFileName;
  860. try
  861. SimpleDecrypt(Format('%s\Phase%d.dat', [TempPath, FPhaseIndex]), sTempFile);
  862. // 复制当前阶段数据
  863. CopyStageData(sTempFile, PhaseData.StageData.sdpStage.TableName, 'P_Stage');
  864. // 复制原报、审核、批复数据
  865. // 其中审核、批复数据,如果存在则复制,如果不存在,则创建空表
  866. CopyStageData(sTempFile, 'Refer', 'P_Refer');
  867. for i := 1 to iMaxStageCount - 1 do
  868. if PhaseData.AuditCount >= i then
  869. CopyStageData(sTempFile, PhaseData.StageTableName[i],
  870. 'P_Audit' + IntToStr(i))
  871. else
  872. CopyEmptyStageData(sTempFile, PhaseData.StageTableName[PhaseData.AuditCount],
  873. 'P_Audit' + IntToStr(i));
  874. if PhaseData.StageCount > 1 then
  875. CopyStageData(sTempFile, PhaseData.StageTableName[PhaseData.AuditCount], 'P_Reply')
  876. else
  877. CopyEmptyStageData(sTempFile, PhaseData.StageTableName[PhaseData.AuditCount], 'P_Reply');
  878. AddSettlementData;
  879. CopyZJJLData(sTempFile);
  880. CopyPhasePayData(sTempFile);
  881. CopyReportData(sTempFile);
  882. finally
  883. DeleteFile(sTempFile);
  884. end;
  885. end;
  886. procedure CopyHistoryCompleteData;
  887. const
  888. sCopySql1 = 'Select BillsID, 0 As Quantity1, 0 As TotalPrice1,' +
  889. ' Quantity%d As Quantity2, TotalPrice%d As TotalPrice2' +
  890. ' Into P_Complete' +
  891. ' From PhaseComplete';
  892. sCopySqlN = 'Select BillsID, Quantity%d As Quantity1, TotalPrice%d As TotalPrice1,' +
  893. ' Quantity%d As Quantity2, TotalPrice%d As TotalPrice2' +
  894. ' Into P_Complete' +
  895. ' From PhaseComplete';
  896. sUnionCopySql1 = 'Select BillsID, 0 As Quantity1, 0 As TotalPrice1,' +
  897. ' GatherQuantity As Quantity2, GatherTotalPrice As TotalPrice2' +
  898. ' Into P_Complete' +
  899. ' From P_Stage';
  900. sUnionCopySqlN = 'Select PS.BillsID As BillsID,' +
  901. ' PC.Quantity%d As Quantity1,' +
  902. ' PC.TotalPrice%d As TotalPrice1,' +
  903. ' PC.Quantity%d + PS.GatherQuantity As Quantity2,' +
  904. ' PC.TotalPrice%d + PS.GatherTotalPrice As TotalPrice2' +
  905. ' Into P_Complete' +
  906. ' From PhaseComplete As PC, P_Stage As PS';
  907. var
  908. sSql: string;
  909. begin
  910. if (ProjProperties.FinalAuditCount >= PhaseIndex) then
  911. if PhaseIndex <= 1 then
  912. sSql := Format(sCopySql1, [FPhaseIndex, FPhaseIndex])
  913. else
  914. sSql := Format(sCopySqlN, [PhaseIndex - 1, PhaseIndex - 1, PhaseIndex, PhaseIndex])
  915. else
  916. if PhaseIndex <= 1 then
  917. sSql := sUnionCopySql1
  918. else
  919. sSql := Format(sUnionCopySqlN, [PhaseIndex - 1, PhaseIndex - 1, PhaseIndex - 1, PhaseIndex - 1]);
  920. ExecuteSql(sSql);
  921. end;
  922. procedure UpdateBillsByDealBills;
  923. const
  924. sClearSql = 'Update Bills Set GclDealQuantity = 0, GclDealTotalPrice = 0';
  925. sUpdateSql = 'Update Bills As B, DealBills As D' +
  926. ' Set B.GclDealQuantity = D.Quantity, B.GclDealTotalPrice = D.TotalPrice' +
  927. ' Where (B.B_Code = D.B_Code) and (B.Name = D.Name) and (B.Units = D.Units) and (B.Price = D.Price)';
  928. begin
  929. ExecuteSql(sClearSql);
  930. ExecuteSql(sUpdateSql);
  931. end;
  932. procedure FilterDealBillsByBills;
  933. const
  934. sFilterSql = 'Select D.*' +
  935. ' Into P_FilterDealBills' +
  936. ' From DealBills As D inner join' +
  937. ' (Select D.ID' +
  938. ' From DealBills As D Left join Bills As B' +
  939. ' On (D.B_Code = B.B_Code) and (D.Name = B.Name) and (D.Units = B.Units) and (D.Price = B.Price)' +
  940. ' where B.ID is Null) As R' +
  941. ' On (D.ID = R.ID)';
  942. begin
  943. ExecuteSql(sFilterSql);
  944. end;
  945. procedure CopyCacheReportsData;
  946. begin
  947. // DealBills的数量金额填至Bills中
  948. UpdateBillsByDealBills;
  949. // 过滤DealBills中在Bills中不存在的清单
  950. FilterDealBillsByBills;
  951. end;
  952. procedure SaveCurPhaseCheckers;
  953. const
  954. sCreateSql = 'Create Table P_Checkers (CheckerNo Integer NOT NULL, Name Text(50), Role Text(50), MemoStr Text(255), CheckedDateTime Text(20), Flag Integer,'+
  955. ' CONSTRAINT PrimaryKey PRIMARY KEY (CheckerNo, Flag))';
  956. sInsertSql = 'Insert Into P_Checkers (CheckerNo, Name, Role, MemoStr, CheckedDateTime, Flag) Values (%d, ''%s'', ''%s'', ''%s'', ''%s'', %d)';
  957. var
  958. i: Integer;
  959. vChecker: TChecker;
  960. sSql: string;
  961. begin
  962. ExecuteSql(sCreateSql);
  963. // 全部审核人
  964. for i := 0 to Checkers.Count - 1 do
  965. begin
  966. vChecker := Checkers.Item[i];
  967. sSql := Format(sInsertSql, [vChecker.No, vChecker.Name, vChecker.Role, vChecker.Memo, vChecker.CheckedDateTime, 0]);
  968. ExecuteSql(sSql);
  969. end;
  970. // 审核通过的最后一人
  971. vChecker := Checkers.LastChecker;
  972. if Assigned(vChecker) then
  973. sSql := Format(sInsertSql, [vChecker.No, vChecker.Name, vChecker.Role, vChecker.Memo, vChecker.CheckedDateTime, 1])
  974. else
  975. sSql := Format(sInsertSql, [-1, '', '', '', '', 1]);
  976. ExecuteSql(sSql);
  977. end;
  978. procedure SaveCloudInfo;
  979. begin
  980. SaveCurPhaseCheckers;
  981. end;
  982. begin
  983. Save;
  984. ClearReportCacheData;
  985. CopyCacheReportsData;
  986. if FPhaseIndex > 0 then
  987. CopyCurPhaseData;
  988. FDealPaymentData.UpdateLinkSerialNo;
  989. //CopyHistoryCompleteData;
  990. if _IsCloud then
  991. SaveCloudInfo;
  992. if _IsDebugView then
  993. SaveDebugFile('Report.dat');
  994. end;
  995. procedure TProjectData.ExecuteSql(const ASql: string);
  996. var
  997. FQuery: TADOQuery;
  998. begin
  999. FQuery := TADOQuery.Create(nil);
  1000. try
  1001. FQuery.Connection := FConnection.Connection;
  1002. FQuery.SQL.Clear;
  1003. FQuery.SQL.Add(ASql);
  1004. FQuery.ExecSQL;
  1005. finally
  1006. FQuery.Free;
  1007. end;
  1008. end;
  1009. function TProjectData.GetADOConnection: TADOConnection;
  1010. begin
  1011. Result := FConnection.Connection;
  1012. end;
  1013. procedure TProjectData.ExportJson_Common(const AFileName: string);
  1014. var
  1015. Rec: TsdDataRecord;
  1016. vSL: TStringList;
  1017. sBQHTJL, sBQSLBGJL, sJZSQLJWC, sBQWCJL, sLJWCJL, sTotalPrice: string;
  1018. begin
  1019. vSL := TStringList.Create;
  1020. try
  1021. Rec := MainListData.GetPhaseMainRecord(ProjProperties.PhaseCount);
  1022. sBQHTJL := FloatToStr(Rec.ValueByName('DealTotalPrice').AsFloat); // 本期合同计量
  1023. sBQSLBGJL := FloatToStr(Rec.ValueByName('QcTotalPrice').AsFloat); // 本期数量变更计量
  1024. sJZSQLJWC := FloatToStr(Rec.ValueByName('PreGatherTotalPrice').AsFloat); // 截止上期累计完成
  1025. sBQWCJL := FloatToStr(Rec.ValueByName('GatherTotalPrice').AsFloat); // 本期完成计量
  1026. sLJWCJL := FloatToStr(Rec.ValueByName('EndGatherTotalPrice').AsFloat); // 累计完成计量
  1027. sTotalPrice := FloatToStr(BillsData.Settlement[0] + Rec.ValueByName('EndQcTotalPrice').AsFloat); // 0号台帐+截止本期累期变更计量
  1028. vSL.Text := Format('{"BQHTJL":"%s","BQSLBGJL":"%s","JZSQLJWC":"%s","BQWCJL":"%s","LJWCJL":"%s","TotalPrice":"%s"}',
  1029. [sBQHTJL, sBQSLBGJL, sJZSQLJWC, sBQWCJL, sLJWCJL, sTotalPrice]);
  1030. vSL.SaveToFile(AFileName);
  1031. finally
  1032. vSL.Free;
  1033. end;
  1034. end;
  1035. function TProjectData.CurUserIsAuthor: Boolean;
  1036. begin
  1037. Result := PHPWeb.UserID = WebAuthorID;
  1038. end;
  1039. function TProjectData.CurUserIsChecker: Boolean;
  1040. begin
  1041. Result := (PHPWeb.UserID <> WebOwnerID) and (PHPWeb.UserID <> WebAuthorID);
  1042. end;
  1043. function TProjectData.CurUserIsOwner: Boolean;
  1044. begin
  1045. Result := PHPWeb.UserID = WebOwnerID;
  1046. end;
  1047. procedure TProjectData.SaveLastestPhaseMainData;
  1048. var
  1049. Rec: TsdDataRecord;
  1050. begin
  1051. if (FPhaseIndex = ProjProperties.PhaseCount) and PhaseData.IsLastStage then
  1052. begin
  1053. Rec := MainListData.GetPhaseMainRecord(FPhaseIndex);
  1054. Rec.ValueByName('DealTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[1, 1];
  1055. Rec.ValueByName('QcTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[1, 2];
  1056. Rec.ValueByName('PcTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[1, 3];
  1057. Rec.ValueByName('GatherTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[1, 4];
  1058. Rec.ValueByName('EndDealTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[2, 1];
  1059. Rec.ValueByName('EndQcTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[2, 2];
  1060. Rec.ValueByName('EndPcTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[2, 3];
  1061. Rec.ValueByName('EndGatherTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[2, 4];
  1062. Rec.ValueByName('PreDealTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[3, 1];
  1063. Rec.ValueByName('PreQcTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[3, 2];
  1064. Rec.ValueByName('PrePcTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[3, 3];
  1065. Rec.ValueByName('PreGatherTotalPrice').AsFloat := PhaseData.StageData.StageSettlement[3, 4];
  1066. Rec.ValueByName('PhasePay').AsFloat := PhaseData.PhasePayData.LastestPhasePay[1];
  1067. Rec.ValueByName('EndPhasePay').AsFloat := PhaseData.PhasePayData.LastestPhasePay[2];
  1068. Rec.ValueByName('PrePhasePay').AsFloat := PhaseData.PhasePayData.LastestPhasePay[3];
  1069. end;
  1070. end;
  1071. procedure TProjectData.CalculateAll;
  1072. begin
  1073. FBillsCompileData.CalculateAll; //台账
  1074. FProjectGLData.CalculateAll; //工料价差
  1075. FPhaseData.StageData.CalculateAll; //计量&清单价差
  1076. FBillsMeasureData.CalculateAll; //累计
  1077. FPhaseData.PhasePayData.CalculateAll;
  1078. end;
  1079. procedure TProjectData.ImportCloudTenderFile(const AFileName: string);
  1080. function GetTempFile(const TempDir: string): string;
  1081. var
  1082. FXmlDocument: IXMLDocument;
  1083. XmlNode, InfoXmlNode: IXMLNode;
  1084. ChildNodes: IXMLNodeList;
  1085. begin
  1086. FXmlDocument := TXMLDocument.Create(nil) as IXMLDocument;
  1087. try
  1088. FXmlDocument.LoadFromFile(TempDir + '\Info.xml');
  1089. FXmlDocument.Options := [doNodeAutoCreate,doNodeAutoIndent,doAutoPrefix,doNamespaceDecl];
  1090. XmlNode := FXmlDocument.DocumentElement;
  1091. ChildNodes := XmlNode.ChildNodes;
  1092. InfoXmlNode := ChildNodes.FindNode('ProjectInfo');
  1093. Result := TempDir + '\' + InfoXmlNode.Attributes['FileName'];
  1094. finally
  1095. FXmlDocument := nil;
  1096. end;
  1097. end;
  1098. procedure ClearAllData;
  1099. var
  1100. sSql: string;
  1101. begin
  1102. sSql := 'Delete * From Bills';
  1103. ExecuteSql(sSql);
  1104. sSql := 'Delete * From DealBills';
  1105. ExecuteSql(sSql);
  1106. sSql := 'Delete * From ProjProperties';
  1107. ExecuteSql(sSql);
  1108. sSql := 'Delete * From DealPayment';
  1109. ExecuteSql(sSql);
  1110. end;
  1111. procedure CopyData(const AFileName: string);
  1112. const
  1113. sBillsSql = 'Insert Into Bills (ID, ParentID, NextSiblingID,' +
  1114. ' Code, B_Code, Name, Units, Alias, Price, NewPrice,' +
  1115. ' OrgQuantity, OrgTotalPrice, MisQuantity, MisTotalPrice, OthQuantity, OthTotalPrice,' +
  1116. ' DgnQuantity1, DgnQuantity2,'+
  1117. ' Peg, DrawingCode, MemoStr, HasBookMark, MarkMemo)'+
  1118. ' Select 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. ' From Bills In ''%s''';
  1124. sDealBillsSql = 'Insert Into DealBills Select ID, B_Code, Name, Units, Price, Quantity, TotalPrice'+
  1125. ' From DealBills In ''%s''';
  1126. sDealPaymentSql = 'Insert Into DealPayment (ID, Name, CalcType, IsMinus,'+
  1127. ' Formula, StartedPrice, SFormula, RangePrice, RFormula)'+
  1128. ' Select ID, Name, CalcType, IsMinus,'+
  1129. ' Formula, StartedPrice, SFormula, RangePrice, RFormula'+
  1130. ' From DealPayment In ''%s''';
  1131. sPropertySql = 'Insert Into ProjProperties'+
  1132. ' Select * From ProjProperties In ''%s'''+
  1133. ' Where (Name <> ''PHASECOUNT'') and (Name <> ''UNLOCKINFOPASSWORD'') and (Name <> ''AUDITSTATUS'')'+
  1134. ' and (Name <> ''FINALAUDITCOUNT'') and (Name <> ''AUDITCOMPANY'') and (Name <> ''UPDATEFLAG'')';
  1135. var
  1136. sSql: string;
  1137. begin
  1138. sSql := Format(sBillsSql, [AFileName]);
  1139. ExecuteSql(sSql);
  1140. sSql := Format(sDealBillsSql, [AFileName]);
  1141. ExecuteSql(sSql);
  1142. sSql := Format(sDealPaymentSql, [AFileName]);
  1143. ExecuteSql(sSql);
  1144. sSql := Format(sPropertySql, [AFileName]);
  1145. ExecuteSql(sSql);
  1146. end;
  1147. function CreateTempSourceFile: string;
  1148. var
  1149. TempDir, TempDir2: string;
  1150. begin
  1151. TempDir := GenerateTempFolder(GetTempPath);
  1152. UnZipFile(AFileName, TempDir);
  1153. try
  1154. TempDir2 := GenerateTempFolder(GetTempPath);
  1155. try
  1156. UnZipFile(GetTempFile(TempDir), TempDir2);
  1157. Result := GetTempFileName;
  1158. SimpleDecrypt(TempDir2 + '\Main.dat', Result);
  1159. finally
  1160. DeleteFileOrFolder(TempDir2);
  1161. end;
  1162. finally
  1163. DeleteFileOrFolder(TempDir);
  1164. end;
  1165. end;
  1166. procedure BeforeCopyData;
  1167. begin
  1168. DisConnectTree;
  1169. CloseAllData;
  1170. end;
  1171. procedure EndCopyData;
  1172. begin
  1173. OpenAllData;
  1174. FProjProperties.Reload;
  1175. FProjProperties.UpdateFlag := 1;
  1176. ReConnectTree;
  1177. ResetFloatDigitView;
  1178. BillsCompileData.CalculateAll;
  1179. end;
  1180. function CheckFile: Boolean;
  1181. var
  1182. TempDir: string;
  1183. Proj: TProjectData;
  1184. begin
  1185. TempDir := GenerateTempFolder(GetTempPath);
  1186. UnZipFile(AFileName, TempDir);
  1187. try
  1188. Proj := TProjectData.Create;
  1189. Proj.SimpleOpen(GetTempFile(TempDir));
  1190. Result := Proj.ProjProperties.UpdateFlag = 1;
  1191. finally
  1192. Proj.Free;
  1193. DeleteFileOrFolder(TempDir);
  1194. end;
  1195. end;
  1196. procedure UpdateSourceFile(const AFileName: string);
  1197. var
  1198. vCon: TADOConnection;
  1199. vUpdate: TUpdateProjectDB;
  1200. begin
  1201. vCon := TADOConnection.Create(nil);
  1202. vCon.LoginPrompt := False;
  1203. try
  1204. vCon.ConnectionString := Format(SAdoConnectStr, [AFileName]);
  1205. vUpdate := TUpdateProjectDB.Create;
  1206. vUpdate.ForceUpdate(vCon);
  1207. finally
  1208. vUpdate.Free;
  1209. vCon.Free;
  1210. end;
  1211. end;
  1212. var
  1213. sTemMainFile: string;
  1214. begin
  1215. sTemMainFile := CreateTempSourceFile;
  1216. UpdateSourceFile(sTemMainFile);
  1217. BeforeCopyData;
  1218. try
  1219. ClearAllData;
  1220. CopyData(sTemMainFile);
  1221. finally
  1222. EndCopyData;
  1223. DeleteFileOrFolder(sTemMainFile);
  1224. end;
  1225. end;
  1226. function TProjectData.CheckPassword: Boolean;
  1227. var
  1228. sPassword: string;
  1229. begin
  1230. if ProjProperties.UnlockInfoPassword = '' then
  1231. Result := True
  1232. else
  1233. begin
  1234. Result := InputPassword(sPassword);
  1235. if Result then
  1236. begin
  1237. Result := sPassword = ProjProperties.UnlockInfoPassword;
  1238. if not Result then ErrorMessage('您输入的密码不正确!');
  1239. end;
  1240. end;
  1241. end;
  1242. procedure TProjectData.SetCheckers(const Value: TCheckers);
  1243. begin
  1244. FCheckers := Value;
  1245. end;
  1246. procedure TProjectData.OpenForSubmit(const AFileName: string);
  1247. begin
  1248. FProjectID := -1;
  1249. UnZipFile(AFileName, TempPath);
  1250. FConnection.Open(MainFileName);
  1251. UpdateProjectDataBase;
  1252. FProjProperties.Open(FConnection.Connection);
  1253. FStaffData.Open(FConnection.Connection);
  1254. end;
  1255. procedure TProjectData.SaveAsForSubmit(const AFileName: string);
  1256. begin
  1257. FStaffData.Save;
  1258. FProjProperties.Save;
  1259. FConnection.Save;
  1260. ZipFolder(FTempFolder, AFileName);
  1261. end;
  1262. procedure TProjectData.LockBillsBaseData;
  1263. const
  1264. sLockInfoSql = 'Update Bills Set LockedInfo = True, LockedLevel = True';
  1265. sLockNPSql = 'Update Bills Set LockedNewPrice = True Where NewPrice <> 0';
  1266. begin
  1267. ExecuteSql(sLockInfoSql);
  1268. ExecuteSql(sLockNPSql);
  1269. end;
  1270. procedure TProjectData.LockDealPaymentData;
  1271. const
  1272. sLockDealSql = 'Update DealPayment Set Locked = True';
  1273. sLockFormulaSql = 'Update DealPayment Set LockedFormula = True Where (Formula <> '''')';
  1274. begin
  1275. ExecuteSql(sLockDealSql);
  1276. ExecuteSql(sLockFormulaSql);
  1277. end;
  1278. procedure TProjectData.OpenForReport(const AFileName: string);
  1279. begin
  1280. FProjectID := -1;
  1281. UnZipFile(AFileName, TempPath);
  1282. FConnection.Open(MainFileName);
  1283. UpdateProjectDataBase;
  1284. FProjProperties.Open(FConnection.Connection);
  1285. UpdateOldData;
  1286. FBillsData.Open(FConnection.Connection);
  1287. FBillsCompileData.Open;
  1288. FDealPaymentData.Open(FConnection.Connection);
  1289. FBGLData.Open(FConnection.Connection);
  1290. end;
  1291. procedure TProjectData.OpenForReply(const AFileName: string);
  1292. begin
  1293. FProjectID := -1;
  1294. UnZipFile(AFileName, TempPath);
  1295. FConnection.Open(MainFileName);
  1296. UpdateProjectDataBase;
  1297. FProjProperties.Open(FConnection.Connection);
  1298. if ProjProperties.PhaseCount > 0 then
  1299. begin
  1300. FPhaseIndex := ProjProperties.PhaseCount;
  1301. FPhaseData.SimpleOpen(Format('%sPhase%d.dat', [TempPath, FPhaseIndex]));
  1302. end;
  1303. FStaffData.Open(FConnection.Connection);
  1304. FDetailGLData.Open(FConnection.Connection);
  1305. end;
  1306. procedure TProjectData.SaveForReply(const AFileName: string);
  1307. begin
  1308. FDetailGLData.Save;
  1309. FStaffData.Save;
  1310. if FPhaseData.Active then
  1311. FPhaseData.SimpleSave;
  1312. FProjProperties.Save;
  1313. FConnection.Save;
  1314. ZipFolder(FTempFolder, AFileName);
  1315. end;
  1316. procedure TProjectData.OpenForReceive(const AFileName: string);
  1317. begin
  1318. FProjectID := -1;
  1319. UnZipFile(AFileName, TempPath);
  1320. FConnection.Open(MainFileName);
  1321. UpdateProjectDataBase;
  1322. FProjProperties.Open(FConnection.Connection);
  1323. if ProjProperties.PhaseCount > 0 then
  1324. begin
  1325. FPhaseIndex := ProjProperties.PhaseCount;
  1326. FPhaseData.SimpleOpen(Format('%sPhase%d.dat', [TempPath, FPhaseIndex]));
  1327. end;
  1328. FStaffData.Open(FConnection.Connection);
  1329. end;
  1330. procedure TProjectData.SaveForReceive(const AFileName: string);
  1331. begin
  1332. FStaffData.Save;
  1333. if FPhaseData.Active then
  1334. FPhaseData.SimpleSave;
  1335. FProjProperties.Save;
  1336. FConnection.Save;
  1337. ZipFolder(FTempFolder, AFileName);
  1338. end;
  1339. procedure TProjectData.CloseAllData;
  1340. begin
  1341. FBillsBookmarkData.Close;
  1342. FBillsData.Close;
  1343. FBillsCompileData.Close;
  1344. FBillsMeasureData.Close;
  1345. FDealBillsData.Close;
  1346. FDealPaymentData.Close;
  1347. FBGLData.Close;
  1348. FStaffData.Close;
  1349. FMainListData.Close;
  1350. end;
  1351. procedure TProjectData.OpenAllData;
  1352. begin
  1353. FProjProperties.Open(FConnection.Connection);
  1354. FBillsData.Open(FConnection.Connection);
  1355. FBillsCompileData.Open;
  1356. FBillsMeasureData.Open;
  1357. FDealBillsData.Open(FConnection.Connection);
  1358. FDealPaymentData.Open(FConnection.Connection);
  1359. FBGLData.Open(FConnection.Connection);
  1360. FStaffData.Open(FConnection.Connection);
  1361. FMainListData.Open(FConnection.Connection);
  1362. FBillsBookmarkData.Open;
  1363. end;
  1364. procedure TProjectData.UpdateOldData;
  1365. procedure UpdateBills_OrgData;
  1366. const
  1367. sUpdateSql = 'Update Bills Set OrgQuantity = Quantity, OrgTotalPrice = TotalPrice';
  1368. begin
  1369. ExecuteSql(sUpdateSql);
  1370. end;
  1371. begin
  1372. if ProjProperties.UpdateFlag = 1 then Exit;
  1373. ProjProperties.UpdateFlag := 1;
  1374. UpdateBills_OrgData;
  1375. end;
  1376. procedure TProjectData.ResetFloatDigitView;
  1377. procedure SetBillsCompileDigit;
  1378. begin
  1379. with FBillsCompileData.sdvBillsCompile do
  1380. begin
  1381. Columns.FindColumn('OrgQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1382. Columns.FindColumn('MisQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1383. Columns.FindColumn('OthQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1384. Columns.FindColumn('Quantity').DisplayFormat := FProjProperties.QuantityFormat;
  1385. Columns.FindColumn('DgnQuantity1').DisplayFormat := FProjProperties.QuantityFormat;
  1386. Columns.FindColumn('DgnQuantity2').DisplayFormat := FProjProperties.QuantityFormat;
  1387. Columns.FindColumn('OrgTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1388. Columns.FindColumn('MisTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1389. Columns.FindColumn('OthTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1390. Columns.FindColumn('TotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1391. Columns.FindColumn('Price').DisplayFormat := FProjProperties.PriceFormat;
  1392. Columns.FindColumn('DgnPrice').DisplayFormat := FProjProperties.PriceFormat;
  1393. Columns.FindColumn('OrgQuantity').EditFormat := FProjProperties.QuantityFormat;
  1394. Columns.FindColumn('MisQuantity').EditFormat := FProjProperties.QuantityFormat;
  1395. Columns.FindColumn('OthQuantity').EditFormat := FProjProperties.QuantityFormat;
  1396. Columns.FindColumn('Quantity').EditFormat := FProjProperties.QuantityFormat;
  1397. Columns.FindColumn('DgnQuantity1').EditFormat := FProjProperties.QuantityFormat;
  1398. Columns.FindColumn('DgnQuantity2').EditFormat := FProjProperties.QuantityFormat;
  1399. Columns.FindColumn('OrgTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1400. Columns.FindColumn('MisTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1401. Columns.FindColumn('OthTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1402. Columns.FindColumn('TotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1403. Columns.FindColumn('Price').EditFormat := FProjProperties.PriceFormat;
  1404. Columns.FindColumn('DgnPrice').EditFormat := FProjProperties.PriceFormat;
  1405. end;
  1406. end;
  1407. procedure SetBillsMeasureDigit;
  1408. begin
  1409. with FBillsMeasureData.sdvBillsMeasure do
  1410. begin
  1411. Columns.FindColumn('Quantity').DisplayFormat := FProjProperties.QuantityFormat;
  1412. Columns.FindColumn('CurDealQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1413. Columns.FindColumn('CurQcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1414. Columns.FindColumn('CurPcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1415. Columns.FindColumn('CurGatherQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1416. Columns.FindColumn('EndDealQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1417. Columns.FindColumn('EndQcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1418. Columns.FindColumn('EndPcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1419. Columns.FindColumn('EndGatherQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1420. Columns.FindColumn('AddDealQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1421. Columns.FindColumn('AddQcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1422. Columns.FindColumn('AddPcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1423. Columns.FindColumn('AddGatherQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1424. Columns.FindColumn('DealDgnQuantity1').DisplayFormat := FProjProperties.QuantityFormat;
  1425. Columns.FindColumn('DealDgnQuantity2').DisplayFormat := FProjProperties.QuantityFormat;
  1426. Columns.FindColumn('CDgnQuantity1').DisplayFormat := FProjProperties.QuantityFormat;
  1427. Columns.FindColumn('CDgnQuantity2').DisplayFormat := FProjProperties.QuantityFormat;
  1428. Columns.FindColumn('TotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1429. Columns.FindColumn('CurDealTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1430. Columns.FindColumn('CurQcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1431. Columns.FindColumn('CurPcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1432. Columns.FindColumn('CurGatherTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1433. Columns.FindColumn('EndDealTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1434. Columns.FindColumn('EndQcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1435. Columns.FindColumn('EndPcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1436. Columns.FindColumn('EndGatherTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1437. Columns.FindColumn('AddDealTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1438. Columns.FindColumn('AddQcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1439. Columns.FindColumn('AddPcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1440. Columns.FindColumn('AddGatherTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1441. Columns.FindColumn('Price').DisplayFormat := FProjProperties.PriceFormat;
  1442. Columns.FindColumn('NewPrice').DisplayFormat := FProjProperties.PriceFormat;
  1443. Columns.FindColumn('Quantity').EditFormat := FProjProperties.QuantityFormat;
  1444. Columns.FindColumn('CurDealQuantity').EditFormat := FProjProperties.QuantityFormat;
  1445. Columns.FindColumn('CurQcQuantity').EditFormat := FProjProperties.QuantityFormat;
  1446. Columns.FindColumn('CurPcQuantity').EditFormat := FProjProperties.QuantityFormat;
  1447. Columns.FindColumn('CurGatherQuantity').EditFormat := FProjProperties.QuantityFormat;
  1448. Columns.FindColumn('EndDealQuantity').EditFormat := FProjProperties.QuantityFormat;
  1449. Columns.FindColumn('EndQcQuantity').EditFormat := FProjProperties.QuantityFormat;
  1450. Columns.FindColumn('EndPcQuantity').EditFormat := FProjProperties.QuantityFormat;
  1451. Columns.FindColumn('EndGatherQuantity').EditFormat := FProjProperties.QuantityFormat;
  1452. Columns.FindColumn('AddDealQuantity').EditFormat := FProjProperties.QuantityFormat;
  1453. Columns.FindColumn('AddQcQuantity').EditFormat := FProjProperties.QuantityFormat;
  1454. Columns.FindColumn('AddPcQuantity').EditFormat := FProjProperties.QuantityFormat;
  1455. Columns.FindColumn('AddGatherQuantity').EditFormat := FProjProperties.QuantityFormat;
  1456. Columns.FindColumn('DealDgnQuantity1').EditFormat := FProjProperties.QuantityFormat;
  1457. Columns.FindColumn('DealDgnQuantity2').EditFormat := FProjProperties.QuantityFormat;
  1458. Columns.FindColumn('CDgnQuantity1').EditFormat := FProjProperties.QuantityFormat;
  1459. Columns.FindColumn('CDgnQuantity2').EditFormat := FProjProperties.QuantityFormat;
  1460. Columns.FindColumn('TotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1461. Columns.FindColumn('CurDealTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1462. Columns.FindColumn('CurQcTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1463. Columns.FindColumn('CurPcTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1464. Columns.FindColumn('CurGatherTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1465. Columns.FindColumn('EndDealTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1466. Columns.FindColumn('EndQcTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1467. Columns.FindColumn('EndPcTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1468. Columns.FindColumn('EndGatherTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1469. Columns.FindColumn('AddDealTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1470. Columns.FindColumn('AddQcTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1471. Columns.FindColumn('AddPcTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1472. Columns.FindColumn('AddGatherTotalPrice').EditFormat := FProjProperties.TotalPriceFormat;
  1473. Columns.FindColumn('Price').EditFormat := FProjProperties.PriceFormat;
  1474. Columns.FindColumn('NewPrice').EditFormat := FProjProperties.PriceFormat;
  1475. end;
  1476. end;
  1477. procedure SetBillsGatherDigit;
  1478. begin
  1479. with FBillsGatherData.sdvGclBills do
  1480. begin
  1481. Columns.FindColumn('Price').DisplayFormat := FProjProperties.PriceFormat;
  1482. Columns.FindColumn('DealQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1483. Columns.FindColumn('DealTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1484. Columns.FindColumn('BGLQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1485. Columns.FindColumn('BGLTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1486. Columns.FindColumn('Quantity').DisplayFormat := FProjProperties.QuantityFormat;
  1487. Columns.FindColumn('TotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1488. Columns.FindColumn('CurDealQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1489. Columns.FindColumn('CurDealTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1490. Columns.FindColumn('CurQcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1491. Columns.FindColumn('CurQcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1492. Columns.FindColumn('CurGatherQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1493. Columns.FindColumn('CurGatherTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1494. Columns.FindColumn('PreDealQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1495. Columns.FindColumn('PreDealTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1496. Columns.FindColumn('PreQcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1497. Columns.FindColumn('PreQcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1498. Columns.FindColumn('PreGatherQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1499. Columns.FindColumn('PreGatherTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1500. Columns.FindColumn('AddDealQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1501. Columns.FindColumn('AddDealTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1502. Columns.FindColumn('AddQcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1503. Columns.FindColumn('AddQcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1504. Columns.FindColumn('AddGatherQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1505. Columns.FindColumn('AddGatherTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1506. Columns.FindColumn('EndDealQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1507. Columns.FindColumn('EndDealTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1508. Columns.FindColumn('EndQcQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1509. Columns.FindColumn('EndQcTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1510. Columns.FindColumn('EndGatherQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1511. Columns.FindColumn('EndGatherTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1512. Columns.FindColumn('Deal_BGLQuantity').DisplayFormat := FProjProperties.QuantityFormat;
  1513. Columns.FindColumn('Deal_BGLTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1514. end;
  1515. with FBillsGatherData.sdvDetailGclBills do
  1516. begin
  1517. Columns.FindColumn('Quantity').DisplayFormat := FProjProperties.QuantityFormat;
  1518. end;
  1519. with FBillsGatherData.sdvDetailDealBills do
  1520. begin
  1521. Columns.FindColumn('Quantity').DisplayFormat := FProjProperties.QuantityFormat;
  1522. Columns.FindColumn('TotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1523. end;
  1524. with FBillsGatherData.sdvDetailBGLBills do
  1525. begin
  1526. Columns.FindColumn('Quantity').DisplayFormat := FProjProperties.QuantityFormat;
  1527. Columns.FindColumn('TotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1528. end;
  1529. end;
  1530. procedure SetDealPaymentDigit;
  1531. begin
  1532. with FDealPaymentData.sdvDealPayment do
  1533. begin
  1534. Columns.FindColumn('CurTotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1535. Columns.FindColumn('TotalPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1536. Columns.FindColumn('StartedPrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1537. Columns.FindColumn('RangePrice').DisplayFormat := FProjProperties.TotalPriceFormat;
  1538. end;
  1539. end;
  1540. procedure SetBGLDigit;
  1541. begin
  1542. FBGLData.cdsBGLViewTotalPrice.DisplayFormat := FProjProperties.TotalPriceFormat;
  1543. FBGLData.cdsBGBillsViewPrice.DisplayFormat := FProjProperties.PriceFormat;
  1544. FBGLData.cdsBGBillsViewQuantity.DisplayFormat := FProjProperties.QuantityFormat;
  1545. FBGLData.cdsBGBillsViewTotalPrice.DisplayFormat := FProjProperties.TotalPriceFormat;
  1546. FBGLData.cdsBGBillsViewUsedQuantity.DisplayFormat := FProjProperties.QuantityFormat;
  1547. end;
  1548. begin
  1549. SetBillsCompileDigit;
  1550. SetBillsMeasureDigit;
  1551. SetDealPaymentDigit;
  1552. SetBillsGatherDigit;
  1553. SetBGLDigit;
  1554. end;
  1555. function TProjectData.GetStageDataReadOnly: Boolean;
  1556. begin
  1557. if FPhaseData.Active then
  1558. Result := FPhaseData.StageDataReadOnly
  1559. else
  1560. Result := True;
  1561. end;
  1562. procedure TProjectData.OpenForReport2(const AFileName: string);
  1563. begin
  1564. FProjectID := -1;
  1565. UnZipFile(AFileName, TempPath);
  1566. FConnection.Open(MainFileName);
  1567. UpdateProjectDataBase;
  1568. FProjProperties.Open(FConnection.Connection);
  1569. UpdateOldData;
  1570. FBillsData.Open(FConnection.Connection);
  1571. FBillsCompileData.Open;
  1572. FDealPaymentData.Open(FConnection.Connection);
  1573. FBGLData.Open(FConnection.Connection);
  1574. if ProjProperties.PhaseCount > 0 then
  1575. begin
  1576. FPhaseIndex := ProjProperties.PhaseCount;
  1577. FPhaseData.SimpleOpen(Format('%sPhase%d.dat', [TempPath, FPhaseIndex]));
  1578. end;
  1579. end;
  1580. function TProjectData.CheckDataBaseInfo(APhaseCount, AAuditStatus: Integer): Boolean;
  1581. begin
  1582. Result := (FProjProperties.PhaseCount = APhaseCount)
  1583. and (FProjProperties.AuditStatus = AAuditStatus);
  1584. if Result and (APhaseCount > 0) and (AAuditStatus <> -1) then
  1585. Result := PhaseData.AuditCount = AAuditStatus;
  1586. end;
  1587. procedure TProjectData.OpenForReport3(const AFileName: string);
  1588. begin
  1589. FProjectID := -1;
  1590. UnZipFile(AFileName, TempPath);
  1591. FConnection.Open(MainFileName);
  1592. UpdateProjectDataBase;
  1593. FProjProperties.Open(FConnection.Connection);
  1594. UpdateOldData;
  1595. FBillsData.Open(FConnection.Connection);
  1596. FBillsMeasureData.Open;
  1597. FDealPaymentData.Open(FConnection.Connection);
  1598. FBGLData.Open(FConnection.Connection);
  1599. if ProjProperties.PhaseCount > 0 then
  1600. begin
  1601. FPhaseIndex := ProjProperties.PhaseCount;
  1602. FPhaseData.SimpleOpen2(Format('%sPhase%d.dat', [TempPath, FPhaseIndex]));
  1603. end;
  1604. FBillsMeasureData.ResetTreeNodeStageRec;
  1605. end;
  1606. function TProjectData.GetPriceMarginReadOnly: Boolean;
  1607. begin
  1608. if FPhaseData.Active then
  1609. Result := not((FPhaseIndex = FProjProperties.PhaseCount) and (FPhaseData.StageCount = 1) and (FProjProperties.AuditStatus <> -1))
  1610. else
  1611. Result := True;
  1612. end;
  1613. procedure TProjectData.CalculatePriceMargin;
  1614. begin
  1615. // 计算工料价差数据
  1616. FProjectGLData.CalculateAll;
  1617. if not FPhaseData.StageDataReadOnly then
  1618. begin
  1619. // 计算清单价差节点
  1620. PhaseData.StageData.CalculatePriceMarginNode;
  1621. // 计算合同支付
  1622. PhaseData.PhasePayData.CalculateAll;
  1623. end;
  1624. end;
  1625. procedure TProjectData.LockProjectGLData;
  1626. const
  1627. sLockSql = 'Update ProjectGL As P, GLPrice As G' +
  1628. ' Set P.LockedPhaseID = %d'+
  1629. ' Where (P.ID = G.GLID) and (G.PM_Quantity_F <> 0) and (IsNull(P.LockedPhaseID) or (P.LockedPhaseID = 0))';
  1630. var
  1631. sSql: string;
  1632. begin
  1633. sSql := Format(sLockSql, [FProjProperties.PhaseCount]);
  1634. ExecuteSql(sSql);
  1635. end;
  1636. procedure TProjectData.LockDetailGLData;
  1637. const
  1638. sLockSql = 'Update DetailGL As D Set D.LockedPhaseID = %d' +
  1639. ' Where (D.LastBillsQuantity <> 0) and (IsNull(D.LockedPhaseID) or (D.LockedPhaseID = 0))';
  1640. var
  1641. sSql: string;
  1642. begin
  1643. sSql := Format(sLockSql, [FProjProperties.PhaseCount]);
  1644. ExecuteSql(sSql);
  1645. end;
  1646. procedure TProjectData.CopyPreData;
  1647. procedure CopyPreGLPrice;
  1648. const
  1649. sCopySql = 'Insert Into GLPrice (GLID, PhaseID,' +
  1650. ' InfoPrice, InfoDate, DeltaPrice, ValidDeltaPrice,' +
  1651. ' PreUsedQuantity, PreUsedTotalPrice,' +
  1652. ' PM_PreQuantity, PM_PreTotalPrice,'+
  1653. ' PrePAL_UsedQuantity, PrePAL_UsedTotalPrice,'+
  1654. ' PrePAL_DeltaPrice, PrePAL_Total)'+
  1655. ' Select GLID, %d,'+
  1656. ' InfoPrice, InfoDate, DeltaPrice, ValidDeltaPrice,'+
  1657. ' PreUsedQuantity+UsedQuantity, PreUsedTotalPrice+UsedTotalPrice,'+
  1658. ' PM_PreQuantity+PM_Quantity_F, PM_PreTotalPrice+PM_TotalPrice_F,'+
  1659. ' PrePAL_UsedQuantity+PAL_UsedQuantity_F, PrePAL_UsedTotalPrice+PAL_UsedTotalPrice_F,'+
  1660. ' PrePAL_DeltaPrice+PAL_DeltaPrice_F, PrePAL_Total+PAL_Total_F'+
  1661. ' From GLPrice Where PhaseID = %d';
  1662. begin
  1663. if FProjProperties.PhaseCount > 1 then
  1664. ExecuteSql(Format(sCopySql, [FProjProperties.PhaseCount, FProjProperties.PhaseCount - 1]));
  1665. end;
  1666. begin
  1667. CopyPreGLPrice;
  1668. PhaseData.CopyPreData;
  1669. ProjectGLData.LoadCurPhaseInfoPrice;
  1670. ProjectGLData.LoadStagePM_CalcData;
  1671. BillsMeasureData.ResetTreeNodeStageRec;
  1672. end;
  1673. function TProjectData.GetStageIndex: Integer;
  1674. begin
  1675. Result := FPhaseData.StageIndex;
  1676. end;
  1677. procedure TProjectData.SetStageIndex(const Value: Integer);
  1678. begin
  1679. FProjectGLData.Save;
  1680. FPhaseData.StageIndex := Value;
  1681. FProjectGLData.LoadStagePM_CalcData;
  1682. end;
  1683. procedure TProjectData.ClearReportCacheData;
  1684. begin
  1685. DropCacheTable('P_');
  1686. end;
  1687. function TProjectData.GetCanInsertNormalBills: Boolean;
  1688. begin
  1689. if FProjProperties.PhaseCount > 0 then
  1690. Result := CanUnlockInfo
  1691. else
  1692. Result := True;
  1693. end;
  1694. procedure TProjectData.ClearReportPrepareData;
  1695. begin
  1696. DropCacheTable('rdp_');
  1697. end;
  1698. procedure TProjectData.DropCacheTable(const AKey: string);
  1699. var
  1700. FTableList: TStringList;
  1701. iIndex: Integer;
  1702. sDeleteTableSql: String;
  1703. begin
  1704. FTableList := TStringList.Create;
  1705. try
  1706. FConnection.Connection.GetTableNames(FTableList);
  1707. iIndex := 0;
  1708. while iIndex < FTableList.Count do
  1709. begin
  1710. if Pos(AKey, FTableList.Strings[iIndex]) = 1 then
  1711. begin
  1712. sDeleteTableSql := Format('Drop Table %s', [FTableList.Strings[iIndex]]);
  1713. ExecuteSql(sDeleteTableSql);
  1714. end;
  1715. Inc(iIndex);
  1716. end;
  1717. finally
  1718. FTableList.Free;
  1719. end;
  1720. end;
  1721. procedure TProjectData.SaveDebugFile(const AFileName: string);
  1722. var
  1723. sFileName: string;
  1724. begin
  1725. sFileName := ExtractFileName(AFileName);
  1726. FConnection.SaveDebugFile(FDebugDir + '\' + sFileName);
  1727. end;
  1728. procedure TProjectData.SaveTempDataBaseFile(const AFileName: string);
  1729. begin
  1730. FConnection.SaveDebugFile(AFileName);
  1731. end;
  1732. procedure TProjectData.ImportDmfFile(const AFileName: string);
  1733. begin
  1734. ImportDbTreeTo(AFileName, Self);
  1735. end;
  1736. function TProjectData.GetValidStageIsRefer: Boolean;
  1737. begin
  1738. if FPhaseData.Active then
  1739. Result := (FPhaseIndex = FProjProperties.PhaseCount) and (FPhaseData.StageCount = 1) and (FProjProperties.AuditStatus <> -1)
  1740. else
  1741. Result := False;
  1742. end;
  1743. end.