ProjectData.pas 67 KB

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