ProjectData.pas 73 KB

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