ProjectData.pas 89 KB

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