ProjectData.pas 67 KB

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