ProjectData.pas 67 KB

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