ProjectData.pas 73 KB

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