ProjectData.pas 77 KB

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