GclBillsGatherModel.pas 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  1. unit GclBillsGatherModel;
  2. // 单项目的工程量清单汇总
  3. interface
  4. uses
  5. Classes, mDataRecord, BillsTree, CalcDecimal;
  6. type
  7. TLeafXmjNode = class
  8. private
  9. FID: Integer;
  10. FXmjCode: string;
  11. FXmjName: string;
  12. FXmjUnits: string;
  13. FPeg: string;
  14. FNameDanWei: string;
  15. FNameFenBu: string;
  16. FNameFenXiang: string;
  17. FNameUnit: string;
  18. FPosition: string;
  19. FDrawingCode: string;
  20. public
  21. constructor Create(ALeafXmj, APeg: TBillsIDTreeNode);
  22. property ID: Integer read FID;
  23. property XmjCode: string read FXmjCode;
  24. property XmjName: string read FXmjName;
  25. property XmjUnits: string read FXmjUnits;
  26. property Peg: string read FPeg;
  27. property NameDanWei: string read FNameDanWei;
  28. property NameFenBu: string read FNameFenBu;
  29. property NameFenXiang: string read FNameFenXiang;
  30. property NameUnit: string read FNameUnit;
  31. property Position: string read FPosition;
  32. property DrawingCode: string read FDrawingCode;
  33. end;
  34. TDetailGclNode = class
  35. private
  36. FID: Integer;
  37. FBillsID: Integer;
  38. FTreeSerialNo: Integer;
  39. FOrgQuantity: Double;
  40. FOrgTotalPrice: Double;
  41. FMisQuantity: Double;
  42. FMisTotalPrice: Double;
  43. FOthQuantity: Double;
  44. FOthTotalPrice: Double;
  45. FQuantity: Double;
  46. FTotalPrice: Double;
  47. FCurDealQuantity: Double;
  48. FCurDealTotalPrice: Double;
  49. FCurQcQuantity: Double;
  50. FCurQcTotalPrice: Double;
  51. FCurGatherQuantity: Double;
  52. FCurGatherTotalPrice: Double;
  53. FPreDealQuantity: Double;
  54. FPreDealTotalPrice: Double;
  55. FPreQcQuantity: Double;
  56. FPreQcTotalPrice: Double;
  57. FPreGatherQuantity: Double;
  58. FPreGatherTotalPrice: Double;
  59. FEndDealQuantity: Double;
  60. FEndDealTotalPrice: Double;
  61. FEndQcQuantity: Double;
  62. FEndQcTotalPrice: Double;
  63. FEndGatherQuantity: Double;
  64. FEndGatherTotalPrice: Double;
  65. FAddDealQuantity: Double;
  66. FAddDealTotalPrice: Double;
  67. FAddQcQuantity: Double;
  68. FAddQcTotalPrice: Double;
  69. FAddGatherQuantity: Double;
  70. FAddGatherTotalPrice: Double;
  71. FPM_PreTotalPrice: Double;
  72. FPM_TotalPrice: Double;
  73. FLeafXmj: TLeafXmjNode;
  74. function GetPercent: Double;
  75. public
  76. constructor Create(AID: Integer);
  77. property ID: Integer read FID;
  78. property BillsID: Integer read FBillsID write FBillsID;
  79. property TreeSerialNo: Integer read FTreeSerialNo write FTreeSerialNo;
  80. property OrgQuantity: Double read FOrgQuantity write FOrgQuantity;
  81. property OrgTotalPrice: Double read FOrgTotalPrice write FOrgTotalPrice;
  82. property MisQuantity: Double read FMisQuantity write FMisQuantity;
  83. property MisTotalPrice: Double read FMisTotalPrice write FMisTotalPrice;
  84. property OthQuantity: Double read FOthQuantity write FOthQuantity;
  85. property OthTotalPrice: Double read FOthTotalPrice write FOthTotalPrice;
  86. property Quantity: Double read FQuantity write FQuantity;
  87. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  88. property CurDealQuantity: Double read FCurDealQuantity write FCurDealQuantity;
  89. property CurDealTotalPrice: Double read FCurDealTotalPrice write FCurDealTotalPrice;
  90. property CurQcQuantity: Double read FCurQcQuantity write FCurQcQuantity;
  91. property CurQcTotalPrice: Double read FCurQcTotalPrice write FCurQcTotalPrice;
  92. property CurGatherQuantity: Double read FCurGatherQuantity write FCurGatherQuantity;
  93. property CurGatherTotalPrice: Double read FCurGatherTotalPrice write FCurGatherTotalPrice;
  94. property PreDealQuantity: Double read FPreDealQuantity write FPreDealQuantity;
  95. property PreDealTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
  96. property PreQcQuantity: Double read FPreQcQuantity write FPreQcQuantity;
  97. property PreQcTotalPrice: Double read FPreQcTotalPrice write FPreQcTotalPrice;
  98. property PreGatherQuantity: Double read FPreGatherQuantity write FPreGatherQuantity;
  99. property PreGatherTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
  100. property EndDealQuantity: Double read FEndDealQuantity write FEndDealQuantity;
  101. property EndDealTotalPrice: Double read FEndDealTotalPrice write FEndDealTotalPrice;
  102. property EndQcQuantity: Double read FEndQcQuantity write FEndQcQuantity;
  103. property EndQcTotalPrice: Double read FEndQcTotalPrice write FEndQcTotalPrice;
  104. property EndGatherQuantity: Double read FEndGatherQuantity write FEndGatherQuantity;
  105. property EndGatherTotalPrice: Double read FEndGatherTotalPrice write FEndGatherTotalPrice;
  106. property Percent: Double read GetPercent;
  107. property AddDealQuantity: Double read FAddDealQuantity write FAddDealQuantity;
  108. property AddDealTotalPrice: Double read FAddDealTotalPrice write FAddDealTotalPrice;
  109. property AddQcQuantity: Double read FAddQcQuantity write FAddQcQuantity;
  110. property AddQcTotalPrice: Double read FAddQcTotalPrice write FAddQcTotalPrice;
  111. property AddGatherQuantity: Double read FAddGatherQuantity write FAddGatherQuantity;
  112. property AddGatherTotalPrice: Double read FAddGatherTotalPrice write FAddGatherTotalPrice;
  113. property PM_PreTotalPrice: Double read FPM_PreTotalPrice write FPM_PreTotalPrice;
  114. property PM_TotalPrice: Double read FPM_TotalPrice write FPM_TotalPrice;
  115. property LeafXmj: TLeafXmjNode read FLeafXmj write FLeafXmj;
  116. end;
  117. TDetailDealNode = class
  118. private
  119. FID: Integer;
  120. FDealID: Integer;
  121. FQuantity: Double;
  122. FTotalPrice: Double;
  123. public
  124. constructor Create(AID: Integer);
  125. property ID: Integer read FID;
  126. property DealID: Integer read FDealID write FDealID;
  127. property Quantity: Double read FQuantity write FQuantity;
  128. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  129. end;
  130. TDetailBGLNode = class
  131. private
  132. FID: Integer;
  133. FBGBillsID: Integer;
  134. FBGLID: Integer;
  135. FBGLCode: string;
  136. FBGLName: string;
  137. FBGLApprovalCode: string;
  138. FBGLDrawingCode: string;
  139. FQuantity: Double;
  140. FTotalPrice: Double;
  141. public
  142. constructor Create(AID: Integer);
  143. property ID: Integer read FID;
  144. property BGBillsID: Integer read FBGBillsID write FBGBillsID;
  145. property BGLID: Integer read FBGLID write FBGLID;
  146. property BGLCode: string read FBGLCode write FBGLCode;
  147. property BGLName: string read FBGLName write FBGLName;
  148. property BGLApprovalCode: string read FBGLApprovalCode write FBGLApprovalCode;
  149. property BGLDrawingCode: string read FBGLDrawingCode write FBGLDrawingCode;
  150. property Quantity: Double read FQuantity write FQuantity;
  151. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  152. end;
  153. TGclNode = class
  154. private
  155. FDetailGcls: TList;
  156. FDetailDeals: TList;
  157. FDetailBGLs: TList;
  158. FLeafXmjs: TList;
  159. FID: Integer;
  160. FB_Code: string;
  161. FIndexCode: string;
  162. FName: string;
  163. FUnits: string;
  164. FPrice: Double;
  165. FOrgQuantity: Double;
  166. FOrgTotalPrice: Double;
  167. FMisQuantity: Double;
  168. FMisTotalPrice: Double;
  169. FOthQuantity: Double;
  170. FOthTotalPrice: Double;
  171. FQuantity: Double;
  172. FTotalPrice: Double;
  173. FCurDealQuantity: Double;
  174. FCurDealTotalPrice: Double;
  175. FCurQcQuantity: Double;
  176. FCurQcTotalPrice: Double;
  177. FCurGatherQuantity: Double;
  178. FCurGatherTotalPrice: Double;
  179. FPreDealQuantity: Double;
  180. FPreDealTotalPrice: Double;
  181. FPreQcQuantity: Double;
  182. FPreQcTotalPrice: Double;
  183. FPreGatherQuantity: Double;
  184. FPreGatherTotalPrice: Double;
  185. FEndDealQuantity: Double;
  186. FEndDealTotalPrice: Double;
  187. FEndQcQuantity: Double;
  188. FEndQcTotalPrice: Double;
  189. FEndGatherQuantity: Double;
  190. FEndGatherTotalPrice: Double;
  191. FAddDealQuantity: Double;
  192. FAddDealTotalPrice: Double;
  193. FAddQcQuantity: Double;
  194. FAddQcTotalPrice: Double;
  195. FAddGatherQuantity: Double;
  196. FAddGatherTotalPrice: Double;
  197. FDealQuantity: Double;
  198. FDealTotalPrice: Double;
  199. FBGLQuantity: Double;
  200. FBGLTotalPrice: Double;
  201. FDeal_BGLQuantity: Double;
  202. FDeal_BGLTotalPrice: Double;
  203. FDeal_BGLPercent: Double;
  204. FDecimal: TCalcDecimal;
  205. procedure InitCalculate;
  206. procedure GatherDetailGcl;
  207. procedure GatherDetailDeal;
  208. procedure GatherDetailBGL;
  209. procedure CalculateOther;
  210. procedure SetB_Code(const Value: string);
  211. function GetDetailBGL(AIndex: Integer): TDetailBGLNode;
  212. function GetDetailBGLCount: Integer;
  213. function GetDetailDeal(AIndex: Integer): TDetailDealNode;
  214. function GetDetailDealCount: Integer;
  215. function GetDetailGcl(AIndex: Integer): TDetailGclNode;
  216. function GetDetailGclCount: Integer;
  217. function GetLeafXmjCount: Integer;
  218. function GetLeafXmj(AIndex: Integer): TLeafXmjNode;
  219. public
  220. constructor Create(AID: Integer; ADecimal: TCalcDecimal);
  221. destructor Destroy; override;
  222. procedure AddLeafXmj(ALeafXmj: TLeafXmjNode);
  223. function AddDetailGcl(AID: Integer): TDetailGclNode;
  224. function AddDetailDeal(AID: Integer): TDetailDealNode;
  225. function AddDetailBGL(AID: Integer): TDetailBGLNode;
  226. procedure Calculate;
  227. property ID: Integer read FID;
  228. property B_Code: string read FB_Code write SetB_Code;
  229. property IndexCode: string read FIndexCode;
  230. property Name: string read FName write FName;
  231. property Units: string read FUnits write FUnits;
  232. property Price: Double read FPrice write FPrice;
  233. property OrgQuantity: Double read FOrgQuantity;
  234. property OrgTotalPrice: Double read FOrgTotalPrice;
  235. property MisQuantity: Double read FMisQuantity;
  236. property MisTotalPrice: Double read FMisTotalPrice;
  237. property OthQuantity: Double read FOthQuantity;
  238. property OthTotalPrice: Double read FOthTotalPrice;
  239. property Quantity: Double read FQuantity;
  240. property TotalPrice: Double read FTotalPrice;
  241. property CurDealQuantity: Double read FCurDealQuantity;
  242. property CurDealTotalPrice: Double read FCurDealTotalPrice;
  243. property CurQcQuantity: Double read FCurQcQuantity;
  244. property CurQcTotalPrice: Double read FCurQcTotalPrice;
  245. property CurGatherQuantity: Double read FCurGatherQuantity;
  246. property CurGatherTotalPrice: Double read FCurGatherTotalPrice;
  247. property PreDealQuantity: Double read FPreDealQuantity;
  248. property PreDealTotalPrice: Double read FPreGatherTotalPrice;
  249. property PreQcQuantity: Double read FPreQcQuantity;
  250. property PreQcTotalPrice: Double read FPreQcTotalPrice;
  251. property PreGatherQuantity: Double read FPreGatherQuantity;
  252. property PreGatherTotalPrice: Double read FPreGatherTotalPrice;
  253. property EndDealQuantity: Double read FEndDealQuantity;
  254. property EndDealTotalPrice: Double read FEndDealTotalPrice;
  255. property EndQcQuantity: Double read FEndQcQuantity;
  256. property EndQcTotalPrice: Double read FEndQcTotalPrice;
  257. property EndGatherQuantity: Double read FEndGatherQuantity;
  258. property EndGatherTotalPrice: Double read FEndGatherTotalPrice;
  259. property AddDealQuantity: Double read FAddDealQuantity;
  260. property AddDealTotalPrice: Double read FAddGatherTotalPrice;
  261. property AddQcQuantity: Double read FAddQcQuantity;
  262. property AddQcTotalPrice: Double read FAddQcTotalPrice;
  263. property AddGatherQuantity: Double read FAddGatherQuantity;
  264. property AddGatherTotalPrice: Double read FAddGatherTotalPrice;
  265. property DealQuantity: Double read FDealQuantity;
  266. property DealTotalPrice: Double read FDealTotalPrice;
  267. property BGLQuantity: Double read FBGLQuantity;
  268. property BGLTotalPrice: Double read FBGLTotalPrice;
  269. // ---------- Calculate --------------
  270. property Deal_BGLQuantity: Double read FDeal_BGLQuantity;
  271. property Deal_BGLTotalPrice: Double read FDeal_BGLTotalPrice;
  272. property Deal_BGLPercent: Double read FDeal_BGLPercent;
  273. // -----------------------------------
  274. property DetailGclCount: Integer read GetDetailGclCount;
  275. property DetailGcl[AIndex: Integer]: TDetailGclNode read GetDetailGcl;
  276. property LeafXmjCount: Integer read GetLeafXmjCount;
  277. property LeafXmj[AIndex: Integer]: TLeafXmjNode read GetLeafXmj;
  278. property DetailDealCount: Integer read GetDetailDealCount;
  279. property DetailDeal[AIndex: Integer]: TDetailDealNode read GetDetailDeal;
  280. property DetailBGLCount: Integer read GetDetailBGLCount;
  281. property DetailBGL[AIndex: Integer]: TDetailBGLNode read GetDetailBGL;
  282. property Decimal: TCalcDecimal read FDecimal;
  283. end;
  284. TGatherNode = class
  285. private
  286. FID: Integer;
  287. FOrgTotalPrice: Double;
  288. FMisTotalPrice: Double;
  289. FOthTotalPrice: Double;
  290. FTotalPrice: Double;
  291. FCurDealTotalPrice: Double;
  292. FCurQcTotalPrice: Double;
  293. FCurGatherTotalPrice: Double;
  294. FPreDealTotalPrice: Double;
  295. FPreQcTotalPrice: Double;
  296. FPreGatherTotalPrice: Double;
  297. FEndDealTotalPrice: Double;
  298. FEndQcTotalPrice: Double;
  299. FEndGatherTotalPrice: Double;
  300. FAddDealTotalPrice: Double;
  301. FAddQcTotalPrice: Double;
  302. FAddGatherTotalPrice: Double;
  303. FDealTotalPrice: Double;
  304. FBGLTotalPrice: Double;
  305. FDeal_BGLTotalPrice: Double;
  306. FDeal_BGLPercent: Double;
  307. public
  308. property ID: Integer read FID write FID;
  309. property OrgTotalPrice: Double read FOrgTotalPrice write FOrgTotalPrice;
  310. property MisTotalPrice: Double read FMisTotalPrice write FMisTotalPrice;
  311. property OthTotalPrice: Double read FOthTotalPrice write FOthTotalPrice;
  312. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  313. property CurDealTotalPrice: Double read FCurDealTotalPrice write FCurDealTotalPrice;
  314. property CurQcTotalPrice: Double read FCurQcTotalPrice write FCurQcTotalPrice;
  315. property CurGatherTotalPrice: Double read FCurGatherTotalPrice write FCurGatherTotalPrice;
  316. property PreDealTotalPrice: Double read FPreGatherTotalPrice write FPreDealTotalPrice;
  317. property PreQcTotalPrice: Double read FPreQcTotalPrice write FPreQcTotalPrice;
  318. property PreGatherTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
  319. property EndDealTotalPrice: Double read FEndDealTotalPrice write FEndDealTotalPrice;
  320. property EndQcTotalPrice: Double read FEndQcTotalPrice write FEndQcTotalPrice;
  321. property EndGatherTotalPrice: Double read FEndGatherTotalPrice write FEndGatherTotalPrice;
  322. property AddDealTotalPrice: Double read FAddGatherTotalPrice write FAddDealTotalPrice;
  323. property AddQcTotalPrice: Double read FAddQcTotalPrice write FAddQcTotalPrice;
  324. property AddGatherTotalPrice: Double read FAddGatherTotalPrice write FAddGatherTotalPrice;
  325. property DealTotalPrice: Double read FDealTotalPrice write FDealTotalPrice;
  326. property BGLTotalPrice: Double read FBGLTotalPrice write FBGLTotalPrice;
  327. // ---------- Calculate --------------
  328. property Deal_BGLTotalPrice: Double read FDeal_BGLTotalPrice write FDeal_BGLTotalPrice;
  329. property Deal_BGLPercent: Double read FDeal_BGLPercent write FDeal_BGLPercent;
  330. // -----------------------------------
  331. end;
  332. TGatherDataWriteEvent = procedure (AGcls, AXmjs: TList; AGather: TGatherNode) of object;
  333. TGclGatherModel = class
  334. private
  335. FProjectData: TObject;
  336. FBillsTree: TBillsIDTree;
  337. FMergeDetailGcl: Boolean;
  338. FGatherDeal: Boolean;
  339. FGatherBGL: Boolean;
  340. FGcls: TList;
  341. FXmjs: TList;
  342. FNewGclID: Integer;
  343. FNewDetailGclID: Integer;
  344. FNewDetailDealID: Integer;
  345. FNewDetailBGLID: Integer;
  346. FGather: TGatherNode;
  347. FWriteGatherData: TGatherDataWriteEvent;
  348. FDecimal: TCalcDecimal;
  349. procedure BeginGather;
  350. procedure EndGather;
  351. function FindLeafXmj(ALeafXmj: TBillsIDTreeNode): TLeafXmjNode;
  352. function NewLeafXmj(ALeafXmj: TBillsIDTreeNode): TLeafXmjNode;
  353. function GetLeafXmj(ANode: TBillsIDTreeNode): TLeafXmjNode;
  354. function FindGclNode(const AB_Code, AName, AUnits: string; APrice: Double): TGclNode;
  355. function NewGclNode(const AB_Code, AName, AUnits: string; APrice: Double): TGclNode;
  356. function GetGclNode(const AB_Code, AName, AUnits: string; APrice: Double): TGclNode; overload;
  357. function GetGclNode(ARec: TBillsRecord): TGclNode; overload;
  358. procedure AddBillsNode(ANode: TMeasureBillsIDTreeNode);
  359. procedure GatherBillsData;
  360. procedure GatherDealData;
  361. procedure GatherBGLData;
  362. procedure CalculateGather;
  363. procedure CalculateAll;
  364. function GetNewDetailBGLID: Integer;
  365. function GetNewDetailDealID: Integer;
  366. function GetNewDetailGclID: Integer;
  367. public
  368. constructor Create(AProjectData: TObject);
  369. destructor Destroy; override;
  370. procedure Execute;
  371. property GatherDeal: Boolean read FGatherDeal write FGatherDeal;
  372. property GatherBGL: Boolean read FGatherBGL write FGatherBGL;
  373. property NewDetailGclID: Integer read GetNewDetailGclID;
  374. property NewDetailDealID: Integer read GetNewDetailDealID;
  375. property NewDetailBGLID: Integer read GetNewDetailBGLID;
  376. // 在使用汇总模型的数据单元创建数据库写入方法,并赋值,否则汇总数据不写入
  377. property WriteGatherData: TGatherDataWriteEvent read FWriteGatherData write FWriteGatherData;
  378. property Decimal: TCalcDecimal read FDecimal;
  379. end;
  380. implementation
  381. uses
  382. ZhAPI, SysUtils, ProjectData, UtilMethods, sdDB, sdIDTree, BGLDm, DB,
  383. Math;
  384. { TGclGatherModel }
  385. procedure TGclGatherModel.AddBillsNode(ANode: TMeasureBillsIDTreeNode);
  386. var
  387. vGclNode: TGclNode;
  388. vDetailGclNode: TDetailGclNode;
  389. vLeafXmj: TLeafXmjNode;
  390. begin
  391. vGclNode := GetGclNode(ANode.Rec);
  392. vDetailGclNode := vGclNode.AddDetailGcl(NewDetailGclID);
  393. vDetailGclNode.BillsID := ANode.ID;
  394. vDetailGclNode.TreeSerialNo := ANode.MajorIndex;
  395. vDetailGclNode.OrgQuantity := ANode.Rec.OrgQuantity.AsFloat;
  396. vDetailGclNode.OrgTotalPrice := ANode.Rec.OrgTotalPrice.AsFloat;
  397. vDetailGclNode.MisQuantity := ANode.Rec.MisQuantity.AsFloat;
  398. vDetailGclNode.MisTotalPrice := ANode.Rec.MisTotalPrice.AsFloat;
  399. vDetailGclNode.OthQuantity := ANode.Rec.OthQuantity.AsFloat;
  400. vDetailGclNode.OthTotalPrice := ANode.Rec.OthTotalPrice.AsFloat;
  401. vDetailGclNode.Quantity := ANode.Rec.Quantity.AsFloat;
  402. vDetailGclNode.TotalPrice := ANode.Rec.TotalPrice.AsFloat;
  403. if Assigned(ANode.StageRec) then
  404. begin
  405. vDetailGclNode.CurDealQuantity := ANode.StageRec.DealQuantity.AsFloat;
  406. vDetailGclNode.CurDealTotalPrice := ANode.StageRec.DealTotalPrice.AsFloat;
  407. vDetailGclNode.CurQcQuantity := ANode.StageRec.QcQuantity.AsFloat;
  408. vDetailGclNode.CurQcTotalPrice := ANode.StageRec.QcTotalPrice.AsFloat;
  409. vDetailGclNode.CurGatherQuantity := ANode.StageRec.GatherQuantity.AsFloat;
  410. vDetailGclNode.CurGatherTotalPrice := ANode.StageRec.GatherTotalPrice.AsFloat;
  411. vDetailGclNode.PreDealQuantity := ANode.StageRec.PreDealQuantity.AsFloat;
  412. vDetailGclNode.PreDealTotalPrice := ANode.StageRec.PreDealTotalPrice.AsFloat;
  413. vDetailGclNode.PreQcQuantity := ANode.StageRec.PreQcQuantity.AsFloat;
  414. vDetailGclNode.PreQcTotalPrice := ANode.StageRec.PreQcTotalPrice.AsFloat;
  415. vDetailGclNode.PreGatherQuantity := ANode.StageRec.PreGatherQuantity.AsFloat;
  416. vDetailGclNode.PreGatherTotalPrice := ANode.StageRec.PreGatherTotalPrice.AsFloat;
  417. vDetailGclNode.EndDealQuantity := ANode.StageRec.EndDealQuantity.AsFloat;
  418. vDetailGclNode.EndDealTotalPrice := ANode.StageRec.EndDealTotalPrice.AsFloat;
  419. vDetailGclNode.EndQcQuantity := ANode.StageRec.EndQcQuantity.AsFloat;
  420. vDetailGclNode.EndQcTotalPrice := ANode.StageRec.EndQcTotalPrice.AsFloat;
  421. vDetailGclNode.EndGatherQuantity := ANode.StageRec.EndGatherQuantity.AsFloat;
  422. vDetailGclNode.EndGatherTotalPrice := ANode.StageRec.EndGatherTotalPrice.AsFloat;
  423. vDetailGclNode.PM_PreTotalPrice := ANode.StageRec.PM_PreTotalPrice.AsFloat;
  424. vDetailGclNode.PM_TotalPrice := ANode.StageRec.PM_TotalPrice.AsFloat;
  425. end;
  426. vDetailGclNode.AddDealQuantity := ANode.Rec.AddDealQuantity.AsFloat;
  427. vDetailGclNode.AddDealTotalPrice := ANode.Rec.AddDealTotalPrice.AsFloat;
  428. vDetailGclNode.AddQcQuantity := ANode.Rec.AddQcQuantity.AsFloat;
  429. vDetailGclNode.AddQcTotalPrice := ANode.Rec.AddQcTotalPrice.AsFloat;
  430. vDetailGclNode.AddGatherQuantity := ANode.Rec.AddGatherQuantity.AsFloat;
  431. vDetailGclNode.AddGatherTotalPrice := ANode.Rec.AddGatherTotalPrice.AsFloat;
  432. vDetailGclNode.LeafXmj := GetLeafXmj(ANode);
  433. vGclNode.AddLeafXmj(vDetailGclNode.LeafXmj);
  434. end;
  435. procedure TGclGatherModel.BeginGather;
  436. begin
  437. FGcls := TList.Create;
  438. FXmjs := TList.Create;
  439. FGather := TGatherNode.Create;
  440. end;
  441. procedure TGclGatherModel.CalculateAll;
  442. var
  443. iGcl: Integer;
  444. begin
  445. for iGcl := 0 to FGcls.Count - 1 do
  446. TGclNode(FGcls.Items[iGcl]).Calculate;
  447. CalculateGather;
  448. end;
  449. procedure TGclGatherModel.CalculateGather;
  450. var
  451. i: Integer;
  452. vGcl: TGclNode;
  453. begin
  454. FGather.ID := FNewGclID + 1;
  455. for i := 0 to FGcls.Count - 1 do
  456. begin
  457. vGcl := TGclNode(FGcls.Items[i]);
  458. FGather.TotalPrice := FGather.TotalPrice + vGcl.TotalPrice;
  459. FGather.OrgTotalPrice := FGather.OrgTotalPrice + vGcl.OrgTotalPrice;
  460. FGather.MisTotalPrice := FGather.MisTotalPrice + vGcl.MisTotalPrice;
  461. FGather.OthTotalPrice := FGather.OthTotalPrice + vGcl.OthTotalPrice;
  462. FGather.CurDealTotalPrice := FGather.CurDealTotalPrice + vGcl.CurDealTotalPrice;
  463. FGather.CurQcTotalPrice := FGather.CurQcTotalPrice + vGcl.CurQcTotalPrice;
  464. FGather.CurGatherTotalPrice := FGather.CurGatherTotalPrice + vGcl.CurGatherTotalPrice;
  465. FGather.PreDealTotalPrice := FGather.PreDealTotalPrice + vGcl.PreDealTotalPrice;
  466. FGather.PreQcTotalPrice := FGather.PreQcTotalPrice + vGcl.PreQcTotalPrice;
  467. FGather.PreGatherTotalPrice := FGather.PreGatherTotalPrice + vGcl.PreGatherTotalPrice;
  468. FGather.EndDealTotalPrice := FGather.EndDealTotalPrice + vGcl.EndDealTotalPrice;
  469. FGather.EndQcTotalPrice := FGather.EndQcTotalPrice + vGcl.EndQcTotalPrice;
  470. FGather.EndGatherTotalPrice := FGather.EndGatherTotalPrice + vGcl.EndGatherTotalPrice;
  471. FGather.AddDealTotalPrice := FGather.AddDealTotalPrice + vGcl.AddDealTotalPrice;
  472. FGather.AddQcTotalPrice := FGather.AddQcTotalPrice + vGcl.AddQcTotalPrice;
  473. FGather.AddGatherTotalPrice := FGather.AddGatherTotalPrice + vGcl.AddGatherTotalPrice;
  474. FGather.DealTotalPrice := FGather.DealTotalPrice + vGcl.DealTotalPrice;
  475. FGather.BGLTotalPrice := FGather.BGLTotalPrice + vGcl.BGLTotalPrice;
  476. end;
  477. FGather.Deal_BGLTotalPrice := Decimal.TotalPrice.RoundTo(FGather.TotalPrice + FGather.BGLTotalPrice);
  478. if FGather.Deal_BGLTotalPrice <> 0 then
  479. FGather.Deal_BGLPercent := CommonRoundTo(FGather.EndGatherTotalPrice/FGather.Deal_BGLTotalPrice*100, -2)
  480. else
  481. FGather.Deal_BGLPercent := 0;
  482. end;
  483. constructor TGclGatherModel.Create(AProjectData: TObject);
  484. begin
  485. FProjectData := AProjectData;
  486. FBillsTree := TProjectData(FProjectData).BillsMeasureData.BillsMeasureTree;
  487. FGatherDeal := False;
  488. FGatherBGL := False;
  489. FDecimal := TProjectData(FProjectData).ProjProperties.DecimalManager.Common;
  490. end;
  491. destructor TGclGatherModel.Destroy;
  492. begin
  493. inherited;
  494. end;
  495. procedure TGclGatherModel.EndGather;
  496. begin
  497. ClearObjects(FXmjs);
  498. FXmjs.Free;
  499. ClearObjects(FGcls);
  500. FGcls.Free;
  501. FGather.Free;
  502. end;
  503. procedure TGclGatherModel.Execute;
  504. begin
  505. BeginGather;
  506. try
  507. GatherBillsData;
  508. GatherDealData;
  509. GatherBGLData;
  510. CalculateAll;
  511. if Assigned(FWriteGatherData) then
  512. FWriteGatherData(FGcls, FXmjs, FGather);
  513. finally
  514. EndGather;
  515. end;
  516. end;
  517. function TGclGatherModel.FindGclNode(const AB_Code, AName, AUnits: string;
  518. APrice: Double): TGclNode;
  519. var
  520. i: Integer;
  521. vGcl: TGclNode;
  522. begin
  523. Result := nil;
  524. for i := 0 to FGcls.Count - 1 do
  525. begin
  526. vGcl := TGclNode(FGcls.Items[i]);
  527. if SameText(vGcl.B_Code, TrimRight(AB_Code)) and
  528. SameText(vGcl.Name, TrimRight(AName)) and
  529. SameText(vGcl.Units, TrimRight(AUnits)) and
  530. (abs(vGcl.Price - APrice) < 0.001) then
  531. begin
  532. Result := vGcl;
  533. Break;
  534. end;
  535. end;
  536. end;
  537. function TGclGatherModel.FindLeafXmj(
  538. ALeafXmj: TBillsIDTreeNode): TLeafXmjNode;
  539. var
  540. iXmj: Integer;
  541. vLeafXmj: TLeafXmjNode;
  542. begin
  543. Result := nil;
  544. for iXmj := 0 to FXmjs.Count - 1 do
  545. begin
  546. vLeafXmj := TLeafXmjNode(FXmjs.Items[iXmj]);
  547. if vLeafXmj.ID = ALeafXmj.ID then
  548. begin
  549. Result := vLeafXmj;
  550. Break;
  551. end;
  552. end;
  553. end;
  554. procedure TGclGatherModel.GatherBGLData;
  555. var
  556. vGclNode: TGclNode;
  557. DetailBGL: TDetailBGLNode;
  558. begin
  559. if not FGatherBGL then Exit;
  560. with TProjectData(FProjectData).BGLData do
  561. begin
  562. cdsBGBills.First;
  563. while not cdsBGBills.Eof do
  564. begin
  565. vGclNode := GetGclNode(cdsBGBillsB_Code.AsString, cdsBGBillsName.AsString,
  566. cdsBGBillsUnits.AsString, cdsBGBillsPrice.AsFloat);
  567. if cdsBGL.FindKey([cdsBGBillsBGID.AsInteger]) then
  568. begin
  569. DetailBGL := vGclNode.AddDetailBGL(NewDetailBGLID);
  570. DetailBGL.BGBillsID := cdsBGBillsID.AsInteger;
  571. DetailBGL.BGLCode := cdsBGLCode.AsString;
  572. DetailBGL.BGLName := cdsBGLName.AsString;
  573. DetailBGL.BGLApprovalCode := cdsBGLApprovalCode.AsString;
  574. DetailBGL.BGLDrawingCode := cdsBGLDrawingCode.AsString;
  575. DetailBGL.BGLID := cdsBGBillsBGID.AsInteger;
  576. DetailBGL.Quantity := cdsBGBillsQuantity.AsFloat;
  577. DetailBGL.TotalPrice := cdsBGBillsTotalPrice.AsFloat;
  578. end;
  579. cdsBGBills.Next;
  580. end;
  581. end;
  582. end;
  583. procedure TGclGatherModel.GatherBillsData;
  584. var
  585. i: Integer;
  586. vNode: TMeasureBillsIDTreeNode;
  587. begin
  588. for i := 0 to FBillsTree.Count - 1 do
  589. begin
  590. vNode := TMeasureBillsIDTreeNode(FBillsTree.Items[i]);
  591. if not vNode.HasChildren and (vNode.Rec.B_Code.AsString <> '') then
  592. AddBillsNode(vNode);
  593. end;
  594. end;
  595. procedure TGclGatherModel.GatherDealData;
  596. var
  597. vGclNode: TGclNode;
  598. vDetailDeal: TDetailDealNode;
  599. iDeal: Integer;
  600. Rec: TsdDataRecord;
  601. begin
  602. if not FGatherDeal then Exit;
  603. with TProjectData(FProjectData).DealBillsData do
  604. for iDeal := 0 to sddDealBills.RecordCount - 1 do
  605. begin
  606. Rec := sddDealBills.Records[iDeal];
  607. vGclNode := GetGclNode(Rec.ValueByName('B_Code').AsString, Rec.ValueByName('Name').AsString,
  608. Rec.ValueByName('Units').AsString, Rec.ValueByName('Price').AsFloat);
  609. vDetailDeal := vGclNode.AddDetailDeal(NewDetailDealID);
  610. vDetailDeal.Quantity := Rec.ValueByName('Quantity').AsFloat;
  611. vDetailDeal.TotalPrice := Rec.ValueByName('TotalPrice').AsFloat;
  612. end;
  613. end;
  614. function TGclGatherModel.GetGclNode(ARec: TBillsRecord): TGclNode;
  615. begin
  616. Result := GetGclNode(ARec.B_Code.AsString, ARec.Name.AsString,
  617. ARec.Units.AsString, ARec.Price.AsFloat);
  618. end;
  619. function TGclGatherModel.GetGclNode(const AB_Code, AName, AUnits: string;
  620. APrice: Double): TGclNode;
  621. begin
  622. Result := FindGclNode(AB_Code, AName, AUnits, APrice);
  623. if not Assigned(Result) then
  624. Result := NewGclNode(AB_Code, AName, AUnits, APrice);
  625. end;
  626. function TGclGatherModel.GetLeafXmj(
  627. ANode: TBillsIDTreeNode): TLeafXmjNode;
  628. function GetFirstXmjParent: TBillsIDTreeNode;
  629. begin
  630. Result := ANode;
  631. while Assigned(Result) and (Result.Rec.B_Code.AsString <> '') do
  632. Result := TBillsIDTreeNode(Result.Parent);
  633. end;
  634. var
  635. vFirstXmjParent: TBillsIDTreeNode;
  636. begin
  637. vFirstXmjParent := GetFirstXmjParent;
  638. Result := nil;
  639. if not Assigned(vFirstXmjParent) then Exit;
  640. Result := FindLeafXmj(vFirstXmjParent);
  641. if not Assigned(Result) then
  642. Result := NewLeafXmj(vFirstXmjParent);
  643. end;
  644. function TGclGatherModel.GetNewDetailBGLID: Integer;
  645. begin
  646. Result := FNewDetailBGLID;
  647. Inc(FNewDetailBGLID)
  648. end;
  649. function TGclGatherModel.GetNewDetailDealID: Integer;
  650. begin
  651. Result := FNewDetailDealID;
  652. Inc(FNewDetailDealID);
  653. end;
  654. function TGclGatherModel.GetNewDetailGclID: Integer;
  655. begin
  656. Result := FNewDetailGclID;
  657. Inc(FNewDetailGclID);
  658. end;
  659. function TGclGatherModel.NewGclNode(const AB_Code, AName, AUnits: string;
  660. APrice: Double): TGclNode;
  661. begin
  662. Result := TGclNode.Create(FNewGclID, FDecimal);
  663. FGcls.Add(Result);
  664. Result.B_Code := TrimRight(AB_Code);
  665. Result.Name := TrimRight(AName);
  666. Result.Units := TrimRight(AUnits);
  667. Result.Price := APrice;
  668. Inc(FNewGclID);
  669. end;
  670. function TGclGatherModel.NewLeafXmj(
  671. ALeafXmj: TBillsIDTreeNode): TLeafXmjNode;
  672. function GetPegNode(ANode: TBillsIDTreeNode): TBillsIDTreeNode;
  673. begin
  674. Result := nil;
  675. if not Assigned(ANode) then Exit;
  676. if CheckPeg(ANode.Rec.Name.AsString) then
  677. Result := ANode
  678. else
  679. Result := GetPegNode(TBillsIDTreeNode(ANode.Parent));
  680. end;
  681. var
  682. vPeg: TBillsIDTreeNode;
  683. begin
  684. vPeg := GetPegNode(ALeafXmj);
  685. Result := TLeafXmjNode.Create(ALeafXmj, vPeg);
  686. FXmjs.Add(Result);
  687. end;
  688. { TGclNode }
  689. function TGclNode.AddDetailBGL(AID: Integer): TDetailBGLNode;
  690. begin
  691. Result := TDetailBGLNode.Create(AID);
  692. FDetailBGLs.Add(Result);
  693. end;
  694. function TGclNode.AddDetailDeal(AID: Integer): TDetailDealNode;
  695. begin
  696. Result := TDetailDealNode.Create(AID);
  697. FDetailDeals.Add(Result);
  698. end;
  699. function TGclNode.AddDetailGcl(AID: Integer): TDetailGclNode;
  700. begin
  701. Result := TDetailGclNode.Create(AID);
  702. FDetailGcls.Add(Result);
  703. end;
  704. procedure TGclNode.AddLeafXmj(ALeafXmj: TLeafXmjNode);
  705. begin
  706. if FLeafXmjs.IndexOf(ALeafXmj) = -1 then
  707. FLeafXmjs.Add(ALeafXmj);
  708. end;
  709. procedure TGclNode.Calculate;
  710. begin
  711. InitCalculate;
  712. GatherDetailGcl;
  713. GatherDetailDeal;
  714. GatherDetailBGL;
  715. CalculateOther;
  716. end;
  717. procedure TGclNode.CalculateOther;
  718. begin
  719. FDeal_BGLQuantity := Decimal.Quantity.RoundTo(FQuantity + FBGLQuantity);
  720. FDeal_BGLTotalPrice := Decimal.TotalPrice.RoundTo(FTotalPrice + FBGLTotalPrice);
  721. if FDeal_BGLTotalPrice <> 0 then
  722. FDeal_BGLPercent := CommonRoundTo(FEndGatherTotalPrice/FDeal_BGLTotalPrice*100, -2)
  723. else
  724. FDeal_BGLPercent := 0;
  725. end;
  726. constructor TGclNode.Create(AID: Integer; ADecimal: TCalcDecimal);
  727. begin
  728. FID := AID;
  729. FDetailGcls := TList.Create;
  730. FDetailDeals := TList.Create;
  731. FDetailBGLs := TList.Create;
  732. FLeafXmjs := TList.Create;
  733. FDecimal := ADecimal;
  734. end;
  735. destructor TGclNode.Destroy;
  736. begin
  737. FLeafXmjs.Free;
  738. ClearObjects(FDetailBGLs);
  739. FDetailBGLs.Free;
  740. ClearObjects(FDetailDeals);
  741. FDetailDeals.Free;
  742. ClearObjects(FDetailGcls);
  743. FDetailGcls.Free;
  744. inherited;
  745. end;
  746. procedure TGclNode.GatherDetailBGL;
  747. var
  748. iBGL: Integer;
  749. vDetailBGL: TDetailBGLNode;
  750. begin
  751. for iBGL := 0 to DetailBGLCount - 1 do
  752. begin
  753. vDetailBGL := DetailBGL[iBGL];
  754. FBGLQuantity := FBGLQuantity + vDetailBGL.Quantity;
  755. FBGLTotalPrice := FBGLTotalPrice + vDetailBGL.TotalPrice;
  756. end;
  757. end;
  758. procedure TGclNode.GatherDetailDeal;
  759. var
  760. iDeal: Integer;
  761. vDetailDeal: TDetailDealNode;
  762. begin
  763. for iDeal := 0 to DetailDealCount - 1 do
  764. begin
  765. vDetailDeal := DetailDeal[iDeal];
  766. FDealQuantity := FDealQuantity + vDetailDeal.Quantity;
  767. FDealTotalPrice := FDealTotalPrice + vDetailDeal.TotalPrice;
  768. end;
  769. end;
  770. procedure TGclNode.GatherDetailGcl;
  771. var
  772. iGcl: Integer;
  773. vDetailGcl: TDetailGclNode;
  774. begin
  775. for iGcl := 0 to DetailGclCount - 1 do
  776. begin
  777. vDetailGcl := DetailGcl[iGcl];
  778. FOrgQuantity := FOrgQuantity + vDetailGcl.OrgQuantity;
  779. FOrgTotalPrice := FOrgTotalPrice + vDetailGcl.OrgTotalPrice;
  780. FMisQuantity := FMisQuantity + vDetailGcl.MisQuantity;
  781. FMisTotalPrice := FMisTotalPrice + vDetailGcl.MisTotalPrice;
  782. FOthQuantity := FOthQuantity + vDetailGcl.OthQuantity;
  783. FOthTotalPrice := FOthTotalPrice + vDetailGcl.OthTotalPrice;
  784. FQuantity := FQuantity + vDetailGcl.Quantity;
  785. FTotalPrice := FTotalPrice + vDetailGcl.TotalPrice;
  786. FCurDealQuantity := FCurDealQuantity + vDetailGcl.CurDealQuantity;
  787. FCurDealTotalPrice := FCurDealTotalPrice + vDetailGcl.CurDealTotalPrice;
  788. FCurQcQuantity := FCurQcQuantity + vDetailGcl.CurQcQuantity;
  789. FCurQcTotalPrice := FCurQcTotalPrice + vDetailGcl.CurQcTotalPrice;
  790. FCurGatherQuantity := FCurGatherQuantity + vDetailGcl.CurGatherQuantity;
  791. FCurGatherTotalPrice := FCurGatherTotalPrice + vDetailGcl.CurGatherTotalPrice;
  792. FPreDealQuantity := FPreDealQuantity + vDetailGcl.PreDealQuantity;
  793. FPreDealTotalPrice := FPreDealTotalPrice + vDetailGcl.PreDealTotalPrice;
  794. FPreQcQuantity := FPreQcQuantity + vDetailGcl.PreQcQuantity;
  795. FPreQcTotalPrice := FPreQcTotalPrice + vDetailGcl.PreQcTotalPrice;
  796. FPreGatherQuantity := FPreGatherQuantity + vDetailGcl.PreGatherQuantity;
  797. FPreGatherTotalPrice := FPreGatherTotalPrice + vDetailGcl.PreGatherTotalPrice;
  798. FEndDealQuantity := FEndDealQuantity + vDetailGcl.EndDealQuantity;
  799. FEndDealTotalPrice := FEndDealTotalPrice + vDetailGcl.EndDealTotalPrice;
  800. FEndQcQuantity := FEndQcQuantity + vDetailGcl.EndQcQuantity;
  801. FEndQcTotalPrice := FEndQcTotalPrice + vDetailGcl.EndQcTotalPrice;
  802. FEndGatherQuantity := FEndGatherQuantity + vDetailGcl.EndGatherQuantity;
  803. FEndGatherTotalPrice := FEndGatherTotalPrice + vDetailGcl.EndGatherTotalPrice;
  804. FAddDealQuantity := FAddDealQuantity + vDetailGcl.AddDealQuantity;
  805. FAddDealTotalPrice := FAddDealTotalPrice + vDetailGcl.AddDealTotalPrice;
  806. FAddQcQuantity := FAddQcQuantity + vDetailGcl.AddQcQuantity;
  807. FAddQcTotalPrice := FAddQcTotalPrice + vDetailGcl.AddQcTotalPrice;
  808. FAddGatherQuantity := FAddGatherQuantity + vDetailGcl.AddGatherQuantity;
  809. FAddGatherTotalPrice := FAddGatherTotalPrice + vDetailGcl.AddGatherTotalPrice;
  810. end;
  811. end;
  812. function TGclNode.GetDetailBGL(AIndex: Integer): TDetailBGLNode;
  813. begin
  814. Result := TDetailBGLNode(FDetailBGLs.Items[AIndex]);
  815. end;
  816. function TGclNode.GetDetailBGLCount: Integer;
  817. begin
  818. Result := FDetailBGLs.Count;
  819. end;
  820. function TGclNode.GetDetailDeal(AIndex: Integer): TDetailDealNode;
  821. begin
  822. Result := TDetailDealNode(FDetailDeals.Items[AIndex]);
  823. end;
  824. function TGclNode.GetDetailDealCount: Integer;
  825. begin
  826. Result := FDetailDeals.Count;
  827. end;
  828. function TGclNode.GetDetailGcl(AIndex: Integer): TDetailGclNode;
  829. begin
  830. Result := TDetailGclNode(FDetailGcls.Items[AIndex]);
  831. end;
  832. function TGclNode.GetDetailGclCount: Integer;
  833. begin
  834. Result := FDetailGcls.Count;
  835. end;
  836. function TGclNode.GetLeafXmj(AIndex: Integer): TLeafXmjNode;
  837. begin
  838. Result := TLeafXmjNode(FLeafXmjs.Items[AIndex]);
  839. end;
  840. function TGclNode.GetLeafXmjCount: Integer;
  841. begin
  842. Result := FLeafXmjs.Count;
  843. end;
  844. procedure TGclNode.InitCalculate;
  845. begin
  846. FOrgQuantity := 0;
  847. FOrgTotalPrice := 0;
  848. FMisQuantity := 0;
  849. FMisTotalPrice := 0;
  850. FOthQuantity := 0;
  851. FOthTotalPrice := 0;
  852. FQuantity := 0;
  853. FTotalPrice := 0;
  854. FCurDealQuantity := 0;
  855. FCurDealTotalPrice := 0;
  856. FCurQcQuantity := 0;
  857. FCurQcTotalPrice := 0;
  858. FCurGatherQuantity := 0;
  859. FCurGatherTotalPrice := 0;
  860. FPreDealQuantity := 0;
  861. FPreDealTotalPrice := 0;
  862. FPreQcQuantity := 0;
  863. FPreQcTotalPrice := 0;
  864. FPreGatherQuantity := 0;
  865. FPreGatherTotalPrice := 0;
  866. FEndDealQuantity := 0;
  867. FEndDealTotalPrice := 0;
  868. FEndQcQuantity := 0;
  869. FEndQcTotalPrice := 0;
  870. FEndGatherQuantity := 0;
  871. FEndGatherTotalPrice := 0;
  872. FAddDealQuantity := 0;
  873. FAddDealTotalPrice := 0;
  874. FAddQcQuantity := 0;
  875. FAddQcTotalPrice := 0;
  876. FAddGatherQuantity := 0;
  877. FAddGatherTotalPrice := 0;
  878. FDealQuantity := 0;
  879. FDealTotalPrice := 0;
  880. FBGLQuantity := 0;
  881. FBGLTotalPrice := 0;
  882. FDeal_BGLQuantity := 0;
  883. FDeal_BGLTotalPrice := 0;
  884. FDeal_BGLPercent := 0;
  885. end;
  886. procedure TGclNode.SetB_Code(const Value: string);
  887. begin
  888. FB_Code := Value;
  889. FIndexCode := B_CodeToIndexCode(FB_Code);
  890. end;
  891. { TDetailGclNode }
  892. constructor TDetailGclNode.Create(AID: Integer);
  893. begin
  894. FID := AID;
  895. end;
  896. function TDetailGclNode.GetPercent: Double;
  897. var
  898. fTotal: Double;
  899. begin
  900. fTotal := abs(FQuantity + FEndQcQuantity);
  901. if fTotal <> 0 then
  902. Result := CommonRoundTo(abs(FEndGatherQuantity) / fTotal * 100, -2)
  903. else
  904. Result := 0;
  905. end;
  906. { TDetailBGLNode }
  907. constructor TDetailBGLNode.Create(AID: Integer);
  908. begin
  909. FID := AID;
  910. end;
  911. { TDetailDealNode }
  912. constructor TDetailDealNode.Create(AID: Integer);
  913. begin
  914. FID := AID;
  915. end;
  916. { TLeafXmjNode }
  917. constructor TLeafXmjNode.Create(ALeafXmj, APeg: TBillsIDTreeNode);
  918. function GetPegName: string;
  919. begin
  920. if Assigned(APeg) then
  921. Result := APeg.Rec.Name.AsString
  922. else
  923. Result := '';
  924. end;
  925. // 取树结构的第ALevel层节点的名称(level从0开始)
  926. function GetNameByLevel(ANode: TBillsIDTreeNode; ALevel: Integer): string;
  927. begin
  928. Result := '';
  929. if not Assigned(ANode) then Exit;
  930. if ANode.Level = ALevel then
  931. Result := ANode.Rec.Name.AsString
  932. else if ANode.Level > ALevel then
  933. Result := GetNameByLevel(TBillsIDTreeNode(ANode.Parent), ALevel);
  934. end;
  935. function GetNameDanWei(ANode: TBillsIDTreeNode): string;
  936. begin
  937. // 取树结构的第二层节点的名称
  938. Result := GetNameByLevel(ANode, 1);
  939. end;
  940. // ANode为计量单元节点,APegNode为桩号节点
  941. function GetNameFenBu(ANode, APegNode: TBillsIDTreeNode): string;
  942. var
  943. vCurNode: TBillsIDTreeNode;
  944. begin
  945. // 如果计量单元节点的名称为桩号(转化为判断计量单元节点与桩号节点为同一个)
  946. if not Assigned(APegNode) or (ANode.ID = APegNode.ID) then
  947. // 取树结构的第三层节点的名称
  948. Result := GetNameByLevel(ANode, 2)
  949. // 否则,取桩号节点的子节点的名称
  950. else
  951. begin
  952. vCurNode := ANode;
  953. while vCurNode.Level > APegNode.Level + 1 do
  954. vCurNode := TBillsIDTreeNode(vCurNode.Parent);
  955. Result := vCurNode.Rec.Name.AsString;
  956. end;
  957. end;
  958. // ANode为计量单元节点,APegNode为桩号节点
  959. function GetNameFenXiang(ANode, APegNode: TBillsIDTreeNode): string;
  960. var
  961. iTopLevel: Integer;
  962. vCurNode: TBillsIDTreeNode;
  963. begin
  964. if Assigned(APegNode) then
  965. begin
  966. iTopLevel := 3;
  967. if APegNode.ID <> ANode.ID then
  968. iTopLevel := APegNode.Level + 2;
  969. Result := '';
  970. vCurNode := TBillsIDTreeNode(ANode.Parent);
  971. while vCurNode.Level >= iTopLevel do
  972. begin
  973. Result := vCurNode.Rec.Name.AsString + ';' + Result;
  974. vCurNode := TBillsIDTreeNode(vCurNode.Parent);
  975. end;
  976. end
  977. else
  978. Result := GetNameByLevel(ANode, 3);
  979. end;
  980. function GetNameUnit(ANode: TBillsIDTreeNode): string;
  981. begin
  982. Result := ANode.Rec.Name.AsString;
  983. end;
  984. function GetDrawingCode(ANode: TBillsIDTreeNode): string;
  985. begin
  986. Result := '';
  987. if not Assigned(ANode) then Exit;
  988. Result := ANode.Rec.DrawingCode.AsString;
  989. if Result = '' then
  990. Result := GetDrawingCode(TBillsIDTreeNode(ANode.Parent));
  991. end;
  992. function GetPosition(ANode, APegNode: TBillsIDTreeNode): string;
  993. begin
  994. // 如果计量单元节点的名称为桩号(转化为判断计量单元节点与桩号节点为同一个)
  995. if not Assigned(APegNode) or (ANode.ID = APegNode.ID) then
  996. // 取分项工程
  997. Result := GetNameFenXiang(ANode, APegNode)
  998. // 反之,取分项工程+计量单元
  999. else
  1000. Result := GetNameFenXiang(ANode, APegNode) + GetNameUnit(ANode);
  1001. end;
  1002. begin
  1003. if not Assigned(ALeafXmj) then Exit;
  1004. FID := ALeafXmj.ID;
  1005. FXmjCode := ALeafXmj.Rec.Code.AsString;
  1006. FXmjName := ALeafXmj.Rec.Name.AsString;
  1007. FXmjUnits := ALeafXmj.Rec.Units.AsString;
  1008. FPeg := GetPegName;
  1009. FNameDanWei := GetNameDanWei(ALeafXmj);
  1010. FNameFenBu := GetNameFenBu(ALeafXmj, APeg);
  1011. FNameFenXiang := GetNameFenXiang(ALeafXmj, APeg);
  1012. FNameUnit := GetNameUnit(ALeafXmj);
  1013. FPosition := GetPosition(ALeafXmj, APeg);
  1014. FDrawingCode := GetDrawingCode(ALeafXmj);
  1015. end;
  1016. end.