ProjectData.pas 59 KB

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