ProjectData.pas 75 KB

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