ProjectData.pas 58 KB

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