ProjectData.pas 59 KB

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