ProjectData.pas 65 KB

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