ProjectData.pas 67 KB

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