GclBillsGatherModel.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. unit GclBillsGatherModel;
  2. // 单项目的工程量清单汇总
  3. interface
  4. uses
  5. Classes, mDataRecord, BillsTree;
  6. type
  7. TGatherDataWriteEvent = procedure (AGLJs: TList) of object;
  8. TDetailGclNode = class
  9. private
  10. FID: Integer;
  11. FBillsID: Integer;
  12. FTreeSerialNo: Integer;
  13. FLeafXmjID: Integer;
  14. FXmjCode: string;
  15. FXmjName: string;
  16. FXmjUnits: string;
  17. FPeg: string;
  18. FNameDanWei: string;
  19. FNameFenBu: string;
  20. FNameFenXiang: string;
  21. FNameUnit: string;
  22. FPosition: string;
  23. FDrawingCode: string;
  24. FQuantity: Double;
  25. FTotalPrice: Double;
  26. FCurDealQuantity: Double;
  27. FCurDealTotalPrice: Double;
  28. FCurQcQuantity: Double;
  29. FCurQcTotalPrice: Double;
  30. FCurGatherQuantity: Double;
  31. FCurGatherTotalPrice: Double;
  32. FPreDealQuantity: Double;
  33. FPreDealTotalPrice: Double;
  34. FPreQcQuantity: Double;
  35. FPreQcTotalPrice: Double;
  36. FPreGatherQuantity: Double;
  37. FPreGatherTotalPrice: Double;
  38. public
  39. constructor Create(AID: Integer);
  40. procedure AddPosData(ALeafXmj, APeg: TBillsIDTreeNode);
  41. property ID: Integer read FID;
  42. property BillsID: Integer read FBillsID write FBillsID;
  43. property TreeSerialNo: Integer read FTreeSerialNo write FTreeSerialNo;
  44. property LeafXmjID: Integer read FLeafXmjID;
  45. property XmjCode: string read FXmjCode;
  46. property XmjName: string read FXmjName;
  47. property XmjUnits: string read FXmjUnits;
  48. property Peg: string read FPeg;
  49. property NameDanWei: string read FNameDanWei;
  50. property NameFenBu: string read FNameFenBu;
  51. property NameFenXiang: string read FNameFenXiang;
  52. property NameUnit: string read FNameUnit;
  53. property Position: string read FPosition;
  54. property DrawingCode: string read FDrawingCode;
  55. property Quantity: Double read FQuantity write FQuantity;
  56. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  57. property CurDealQuantity: Double read FCurDealQuantity write FCurDealQuantity;
  58. property CurDealTotalPrice: Double read FCurDealTotalPrice write FCurDealTotalPrice;
  59. property CurQcQuantity: Double read FCurQcQuantity write FCurQcQuantity;
  60. property CurQcTotalPrice: Double read FCurQcTotalPrice write FCurQcTotalPrice;
  61. property CurGatherQuantity: Double read FCurGatherQuantity write FCurGatherQuantity;
  62. property CurGatherTotalPrice: Double read FCurGatherTotalPrice write FCurGatherTotalPrice;
  63. property PreDealQuantity: Double read FPreDealQuantity write FPreDealQuantity;
  64. property PreDealTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
  65. property PreQcQuantity: Double read FPreQcQuantity write FPreQcQuantity;
  66. property PreQcTotalPrice: Double read FPreQcTotalPrice write FPreQcTotalPrice;
  67. property PreGatherQuantity: Double read FPreGatherQuantity write FPreGatherQuantity;
  68. property PreGatherTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
  69. end;
  70. TDetailDealNode = class
  71. private
  72. FID: Integer;
  73. FDealID: Integer;
  74. FQuantity: Double;
  75. FTotalPrice: Double;
  76. public
  77. constructor Create(AID: Integer);
  78. property ID: Integer read FID;
  79. property DealID: Integer read FDealID write FDealID;
  80. property Quantity: Double read FQuantity write FQuantity;
  81. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  82. end;
  83. TDetailBGLNode = class
  84. private
  85. FID: Integer;
  86. FBGLID: Integer;
  87. FQuantity: Double;
  88. FTotalPrice: Double;
  89. public
  90. constructor Create(AID: Integer);
  91. property ID: Integer read FID;
  92. property BGLID: Integer read FBGLID;
  93. property Quantity: Double read FQuantity write FQuantity;
  94. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  95. end;
  96. TGclNode = class
  97. private
  98. FDetailGcls: TList;
  99. FDetailDeals: TList;
  100. FDetailBGLs: TList;
  101. FID: Integer;
  102. FB_Code: string;
  103. FIndexCode: string;
  104. FName: string;
  105. FUnits: string;
  106. FPrice: Double;
  107. FQuantity: Double;
  108. FTotalPrice: Double;
  109. FCurDealQuantity: Double;
  110. FCurDealTotalPrice: Double;
  111. FCurQcQuantity: Double;
  112. FCurQcTotalPrice: Double;
  113. FCurGatherQuantity: Double;
  114. FCurGatherTotalPrice: Double;
  115. FPreDealQuantity: Double;
  116. FPreDealTotalPrice: Double;
  117. FPreQcQuantity: Double;
  118. FPreQcTotalPrice: Double;
  119. FPreGatherQuantity: Double;
  120. FPreGatherTotalPrice: Double;
  121. FDealQuantity: Double;
  122. FDealTotalPrice: Double;
  123. FBGLQuantity: Double;
  124. FBGLTotalPrice: Double;
  125. procedure InitCalculate;
  126. procedure GatherDetailGcl;
  127. procedure GatherDetailDeal;
  128. procedure GatherDetailBGL;
  129. procedure SetB_Code(const Value: string);
  130. function GetDetailBGL(AIndex: Integer): TDetailBGLNode;
  131. function GetDetailBGLCount: Integer;
  132. function GetDetailDeal(AIndex: Integer): TDetailDealNode;
  133. function GetDetailDealCount: Integer;
  134. function GetDetailGcl(AIndex: Integer): TDetailGclNode;
  135. function GetDetailGclCount: Integer;
  136. public
  137. constructor Create(AID: Integer);
  138. destructor Destroy; override;
  139. function AddDetailGcl(AID: Integer): TDetailGclNode;
  140. function AddDetailDeal(AID: Integer): TDetailDealNode;
  141. function AddDetailBGL(AID: Integer): TDetailBGLNode;
  142. procedure Calculate;
  143. property ID: Integer read FID;
  144. property B_Code: string read FB_Code write SetB_Code;
  145. property IndexCode: string read FIndexCode;
  146. property Name: string read FName write FName;
  147. property Units: string read FUnits write FUnits;
  148. property Price: Double read FPrice write FPrice;
  149. property Quantity: Double read FQuantity write FQuantity;
  150. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  151. property CurDealQuantity: Double read FCurDealQuantity write FCurDealQuantity;
  152. property CurDealTotalPrice: Double read FCurDealTotalPrice write FCurDealTotalPrice;
  153. property CurQcQuantity: Double read FCurQcQuantity write FCurQcQuantity;
  154. property CurQcTotalPrice: Double read FCurQcTotalPrice write FCurQcTotalPrice;
  155. property CurGatherQuantity: Double read FCurGatherQuantity write FCurGatherQuantity;
  156. property CurGatherTotalPrice: Double read FCurGatherTotalPrice write FCurGatherTotalPrice;
  157. property PreDealQuantity: Double read FPreDealQuantity write FPreDealQuantity;
  158. property PreDealTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
  159. property PreQcQuantity: Double read FPreQcQuantity write FPreQcQuantity;
  160. property PreQcTotalPrice: Double read FPreQcTotalPrice write FPreQcTotalPrice;
  161. property PreGatherQuantity: Double read FPreGatherQuantity write FPreGatherQuantity;
  162. property PreGatherTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
  163. property DealQuantity: Double read FDealQuantity write FDealQuantity;
  164. property DealTotalPrice: Double read FDealTotalPrice write FDealTotalPrice;
  165. property BGLQuantity: Double read FBGLQuantity write FBGLQuantity;
  166. property BGLTotalPrice: Double read FBGLTotalPrice write FBGLTotalPrice;
  167. property DetailGclCount: Integer read GetDetailGclCount;
  168. property DetailGcl[AIndex: Integer]: TDetailGclNode read GetDetailGcl;
  169. property DetailDealCount: Integer read GetDetailDealCount;
  170. property DetailDeal[AIndex: Integer]: TDetailDealNode read GetDetailDeal;
  171. property DetailBGLCount: Integer read GetDetailBGLCount;
  172. property DetailBGL[AIndex: Integer]: TDetailBGLNode read GetDetailBGL;
  173. end;
  174. TGclGatherModel = class
  175. private
  176. FProjectData: TObject;
  177. FBillsTree: TBillsIDTree;
  178. FGatherDeal: Boolean;
  179. FGatherBGL: Boolean;
  180. FGcls: TList;
  181. FNewGclID: Integer;
  182. FNewDetailGclID: Integer;
  183. FNewDetailDealID: Integer;
  184. FNewDetailBGLID: Integer;
  185. FWriteGatherData: TGatherDataWriteEvent;
  186. procedure BeginGather;
  187. procedure EndGather;
  188. function FindGclNode(const AB_Code, AName, AUnits: string; APrice: Double): TGclNode;
  189. function NewGclNode(const AB_Code, AName, AUnits: string; APrice: Double): TGclNode;
  190. function GetGclNode(const AB_Code, AName, AUnits: string; APrice: Double): TGclNode; overload;
  191. function GetGclNode(ARec: TBillsRecord): TGclNode; overload;
  192. procedure AddBillsNode(ANode: TBillsIDTreeNode);
  193. procedure GatherBillsData;
  194. procedure GatherDealData;
  195. procedure GatherBGLData;
  196. procedure CalculateAll;
  197. function GetNewDetailBGLID: Integer;
  198. function GetNewDetailDealID: Integer;
  199. function GetNewDetailGclID: Integer;
  200. public
  201. constructor Create(AProjectData: TObject);
  202. destructor Destroy; override;
  203. procedure Execute;
  204. property GatherDeal: Boolean read FGatherDeal write FGatherDeal;
  205. property GatherBGL: Boolean read FGatherBGL write FGatherBGL;
  206. property NewDetailGclID: Integer read GetNewDetailGclID;
  207. property NewDetailDealID: Integer read GetNewDetailDealID;
  208. property NewDetailBGLID: Integer read GetNewDetailBGLID;
  209. // 在使用汇总模型的数据单元创建数据库写入方法,并赋值,否则汇总数据不写入
  210. property WriteGatherData: TGatherDataWriteEvent read FWriteGatherData write FWriteGatherData;
  211. end;
  212. implementation
  213. uses
  214. ZhAPI, SysUtils, ProjectData, UtilMethods, sdDB, sdIDTree;
  215. { TGclGatherModel }
  216. procedure TGclGatherModel.AddBillsNode(ANode: TBillsIDTreeNode);
  217. function GetFirstXmjParent: TBillsIDTreeNode;
  218. begin
  219. Result := ANode;
  220. while Assigned(Result) and (Result.Rec.B_Code.AsString <> '') do
  221. Result := TBillsIDTreeNode(Result.Parent);
  222. end;
  223. function GetPegNode(ALeafXmj: TBillsIDTreeNode): TBillsIDTreeNode;
  224. begin
  225. Result := nil;
  226. if not Assigned(ALeafXmj) then Exit;
  227. if CheckPeg(ALeafXmj.Rec.Name.AsString) then
  228. Result := ANode
  229. else
  230. Result := GetPegNode(TBillsIDTreeNode(ALeafXmj.Parent));
  231. end;
  232. var
  233. vGclNode: TGclNode;
  234. vDetailGclNode: TDetailGclNode;
  235. vLeafXmj, vPeg: TBillsIDTreeNode;
  236. begin
  237. vGclNode := GetGclNode(ANode.Rec);
  238. vDetailGclNode := vGclNode.AddDetailGcl(NewDetailGclID);
  239. vDetailGclNode.BillsID := ANode.ID;
  240. vDetailGclNode.TreeSerialNo := ANode.MajorIndex;
  241. vDetailGclNode.Quantity := ANode.Rec.Quantity.AsFloat;
  242. vDetailGclNode.TotalPrice := ANode.Rec.TotalPrice.AsFloat;
  243. if Assigned(ANode.StageRec) then
  244. begin
  245. vDetailGclNode.CurDealQuantity := ANode.StageRec.DealQuantity.AsFloat;
  246. vDetailGclNode.CurDealTotalPrice := ANode.StageRec.DealTotalPrice.AsFloat;
  247. vDetailGclNode.CurQcQuantity := ANode.StageRec.QcQuantity.AsFloat;
  248. vDetailGclNode.CurQcTotalPrice := ANode.StageRec.QcTotalPrice.AsFloat;
  249. vDetailGclNode.CurGatherQuantity := ANode.StageRec.GatherQuantity.AsFloat;
  250. vDetailGclNode.CurGatherTotalPrice := ANode.StageRec.GatherTotalPrice.AsFloat;
  251. vDetailGclNode.PreDealQuantity := ANode.StageRec.PreDealQuantity.AsFloat;
  252. vDetailGclNode.PreDealTotalPrice := ANode.StageRec.PreDealTotalPrice.AsFloat;
  253. vDetailGclNode.PreQcQuantity := ANode.StageRec.PreQcQuantity.AsFloat;
  254. vDetailGclNode.PreQcTotalPrice := ANode.StageRec.PreQcTotalPrice.AsFloat;
  255. vDetailGclNode.PreGatherQuantity := ANode.StageRec.PreGatherQuantity.AsFloat;
  256. vDetailGclNode.PreGatherTotalPrice := ANode.StageRec.PreGatherTotalPrice.AsFloat;
  257. end;
  258. vLeafXmj := GetFirstXmjParent;
  259. vPeg := GetPegNode(vLeafXmj);
  260. vDetailGclNode.AddPosData(vLeafXmj, vPeg);
  261. end;
  262. procedure TGclGatherModel.BeginGather;
  263. begin
  264. FGcls := TList.Create;
  265. end;
  266. procedure TGclGatherModel.CalculateAll;
  267. var
  268. iGcl: Integer;
  269. begin
  270. for iGcl := 0 to FGcls.Count - 1 do
  271. TGclNode(FGcls.Items[iGcl]).Calculate;
  272. end;
  273. constructor TGclGatherModel.Create(AProjectData: TObject);
  274. begin
  275. FProjectData := AProjectData;
  276. FBillsTree := TProjectData(FProjectData).BillsMeasureData.BillsMeasureTree;
  277. FGatherDeal := False;
  278. FGatherBGL := False;
  279. end;
  280. destructor TGclGatherModel.Destroy;
  281. begin
  282. inherited;
  283. end;
  284. procedure TGclGatherModel.EndGather;
  285. begin
  286. ClearObjects(FGcls);
  287. FGcls.Free;
  288. end;
  289. procedure TGclGatherModel.Execute;
  290. begin
  291. BeginGather;
  292. try
  293. GatherBillsData;
  294. GatherDealData;
  295. GatherBGLData;
  296. CalculateAll;
  297. if Assigned(FWriteGatherData) then
  298. FWriteGatherData(FGcls);
  299. finally
  300. EndGather;
  301. end;
  302. end;
  303. function TGclGatherModel.FindGclNode(const AB_Code, AName, AUnits: string;
  304. APrice: Double): TGclNode;
  305. var
  306. i: Integer;
  307. vGcl: TGclNode;
  308. begin
  309. Result := nil;
  310. for i := 0 to FGcls.Count - 1 do
  311. begin
  312. vGcl := TGclNode(FGcls.Items[i]);
  313. if SameText(vGcl.B_Code, TrimRight(AB_Code)) and
  314. SameText(vGcl.Name, TrimRight(AName)) and
  315. SameText(vGcl.Units, TrimRight(AUnits)) and
  316. (abs(vGcl.Price - APrice) < 0.001) then
  317. begin
  318. Result := vGcl;
  319. Break;
  320. end;
  321. end;
  322. end;
  323. procedure TGclGatherModel.GatherBGLData;
  324. begin
  325. if not FGatherBGL then Exit;
  326. // To Do
  327. end;
  328. procedure TGclGatherModel.GatherBillsData;
  329. var
  330. i: Integer;
  331. vNode: TBillsIDTreeNode;
  332. begin
  333. for i := 0 to FBillsTree.Count - 1 do
  334. begin
  335. vNode := TBillsIDTreeNode(FBillsTree.Items[i]);
  336. if not vNode.HasChildren and (vNode.Rec.B_Code.AsString <> '') then
  337. AddBillsNode(vNode);
  338. end;
  339. end;
  340. procedure TGclGatherModel.GatherDealData;
  341. var
  342. vGclNode: TGclNode;
  343. vDetailDeal: TDetailDealNode;
  344. iDeal: Integer;
  345. Rec: TsdDataRecord;
  346. begin
  347. if not FGatherDeal then Exit;
  348. with TProjectData(FProjectData).DealBillsData do
  349. for iDeal := 0 to sddDealBills.RecordCount - 1 do
  350. begin
  351. Rec := sddDealBills.Records[iDeal];
  352. vGclNode := GetGclNode(Rec.ValueByName('B_Code').AsString, Rec.ValueByName('Name').AsString,
  353. Rec.ValueByName('Units').AsString, Rec.ValueByName('Price').AsFloat);
  354. vDetailDeal := vGclNode.AddDetailDeal(NewDetailDealID);
  355. vDetailDeal.Quantity := Rec.ValueByName('Quantity').AsFloat;
  356. vDetailDeal.TotalPrice := Rec.ValueByName('TotalPrice').AsFloat;
  357. end;
  358. end;
  359. function TGclGatherModel.GetGclNode(ARec: TBillsRecord): TGclNode;
  360. begin
  361. Result := GetGclNode(ARec.B_Code.AsString, ARec.Name.AsString,
  362. ARec.Units.AsString, ARec.Price.AsFloat);
  363. end;
  364. function TGclGatherModel.GetGclNode(const AB_Code, AName, AUnits: string;
  365. APrice: Double): TGclNode;
  366. begin
  367. Result := FindGclNode(AB_Code, AName, AUnits, APrice);
  368. if not Assigned(Result) then
  369. Result := NewGclNode(AB_Code, AName, AUnits, APrice);
  370. end;
  371. function TGclGatherModel.GetNewDetailBGLID: Integer;
  372. begin
  373. Result := FNewDetailBGLID;
  374. Inc(FNewDetailBGLID)
  375. end;
  376. function TGclGatherModel.GetNewDetailDealID: Integer;
  377. begin
  378. Result := FNewDetailDealID;
  379. Inc(FNewDetailDealID);
  380. end;
  381. function TGclGatherModel.GetNewDetailGclID: Integer;
  382. begin
  383. Result := FNewDetailGclID;
  384. Inc(FNewDetailGclID);
  385. end;
  386. function TGclGatherModel.NewGclNode(const AB_Code, AName, AUnits: string;
  387. APrice: Double): TGclNode;
  388. begin
  389. Result := TGclNode.Create(FNewGclID);
  390. FGcls.Add(Result);
  391. Result.B_Code := TrimRight(AB_Code);
  392. Result.Name := TrimRight(AName);
  393. Result.Units := TrimRight(AUnits);
  394. Result.Price := APrice;
  395. Inc(FNewGclID);
  396. end;
  397. { TGclNode }
  398. function TGclNode.AddDetailBGL(AID: Integer): TDetailBGLNode;
  399. begin
  400. Result := TDetailBGLNode.Create(AID);
  401. FDetailBGLs.Add(Result);
  402. end;
  403. function TGclNode.AddDetailDeal(AID: Integer): TDetailDealNode;
  404. begin
  405. Result := TDetailDealNode.Create(AID);
  406. FDetailDeals.Add(Result);
  407. end;
  408. function TGclNode.AddDetailGcl(AID: Integer): TDetailGclNode;
  409. begin
  410. Result := TDetailGclNode.Create(AID);
  411. FDetailGcls.Add(Result);
  412. end;
  413. procedure TGclNode.Calculate;
  414. begin
  415. InitCalculate;
  416. GatherDetailGcl;
  417. GatherDetailDeal;
  418. GatherDetailBGL;
  419. end;
  420. constructor TGclNode.Create(AID: Integer);
  421. begin
  422. FID := AID;
  423. FDetailGcls := TList.Create;
  424. FDetailDeals := TList.Create;
  425. FDetailBGLs := TList.Create;
  426. end;
  427. destructor TGclNode.Destroy;
  428. begin
  429. ClearObjects(FDetailBGLs);
  430. FDetailBGLs.Free;
  431. ClearObjects(FDetailDeals);
  432. FDetailDeals.Free;
  433. ClearObjects(FDetailGcls);
  434. FDetailGcls.Free;
  435. inherited;
  436. end;
  437. procedure TGclNode.GatherDetailBGL;
  438. var
  439. iBGL: Integer;
  440. vDetailBGL: TDetailBGLNode;
  441. begin
  442. for iBGL := 0 to DetailBGLCount - 1 do
  443. begin
  444. vDetailBGL := DetailBGL[iBGL];
  445. FBGLQuantity := FBGLQuantity + vDetailBGL.Quantity;
  446. FBGLTotalPrice := FBGLTotalPrice + vDetailBGL.TotalPrice;
  447. end;
  448. end;
  449. procedure TGclNode.GatherDetailDeal;
  450. var
  451. iDeal: Integer;
  452. vDetailDeal: TDetailDealNode;
  453. begin
  454. for iDeal := 0 to DetailDealCount - 1 do
  455. begin
  456. vDetailDeal := DetailDeal[iDeal];
  457. FDealQuantity := FDealQuantity + vDetailDeal.Quantity;
  458. FDealTotalPrice := FDealTotalPrice + vDetailDeal.TotalPrice;
  459. end;
  460. end;
  461. procedure TGclNode.GatherDetailGcl;
  462. var
  463. iGcl: Integer;
  464. vDetailGcl: TDetailGclNode;
  465. begin
  466. for iGcl := 0 to DetailGclCount - 1 do
  467. begin
  468. vDetailGcl := DetailGcl[iGcl];
  469. FQuantity := FQuantity + vDetailGcl.Quantity;
  470. FTotalPrice := FTotalPrice + vDetailGcl.TotalPrice;
  471. FCurDealQuantity := FCurDealQuantity + vDetailGcl.CurDealQuantity;
  472. FCurDealTotalPrice := FCurDealTotalPrice + vDetailGcl.CurDealTotalPrice;
  473. FCurQcQuantity := FCurQcQuantity + vDetailGcl.CurQcQuantity;
  474. FCurQcTotalPrice := FCurQcTotalPrice + vDetailGcl.CurQcTotalPrice;
  475. FCurGatherQuantity := FCurGatherQuantity + vDetailGcl.CurGatherQuantity;
  476. FCurGatherTotalPrice := FCurGatherTotalPrice + vDetailGcl.CurGatherTotalPrice;
  477. FPreDealQuantity := FPreDealQuantity + vDetailGcl.PreDealQuantity;
  478. FPreDealTotalPrice := FPreDealTotalPrice + vDetailGcl.PreDealTotalPrice;
  479. FPreQcQuantity := FPreQcQuantity + vDetailGcl.PreQcQuantity;
  480. FPreQcTotalPrice := FPreQcTotalPrice + vDetailGcl.PreQcTotalPrice;
  481. FPreGatherQuantity := FPreGatherQuantity + vDetailGcl.PreGatherQuantity;
  482. FPreGatherTotalPrice := FPreGatherTotalPrice + vDetailGcl.PreGatherTotalPrice;
  483. end;
  484. end;
  485. function TGclNode.GetDetailBGL(AIndex: Integer): TDetailBGLNode;
  486. begin
  487. Result := TDetailBGLNode(FDetailBGLs.Items[AIndex]);
  488. end;
  489. function TGclNode.GetDetailBGLCount: Integer;
  490. begin
  491. Result := FDetailBGLs.Count;
  492. end;
  493. function TGclNode.GetDetailDeal(AIndex: Integer): TDetailDealNode;
  494. begin
  495. Result := TDetailDealNode(FDetailDeals.Items[AIndex]);
  496. end;
  497. function TGclNode.GetDetailDealCount: Integer;
  498. begin
  499. Result := FDetailDeals.Count;
  500. end;
  501. function TGclNode.GetDetailGcl(AIndex: Integer): TDetailGclNode;
  502. begin
  503. Result := TDetailGclNode(FDetailGcls.Items[AIndex]);
  504. end;
  505. function TGclNode.GetDetailGclCount: Integer;
  506. begin
  507. Result := FDetailGcls.Count;
  508. end;
  509. procedure TGclNode.InitCalculate;
  510. begin
  511. FQuantity := 0;
  512. FTotalPrice := 0;
  513. FCurDealQuantity := 0;
  514. FCurDealTotalPrice := 0;
  515. FCurQcQuantity := 0;
  516. FCurQcTotalPrice := 0;
  517. FCurGatherQuantity := 0;
  518. FCurGatherTotalPrice := 0;
  519. FPreDealQuantity := 0;
  520. FPreDealTotalPrice := 0;
  521. FPreQcQuantity := 0;
  522. FPreQcTotalPrice := 0;
  523. FPreGatherQuantity := 0;
  524. FPreGatherTotalPrice := 0;
  525. FDealQuantity := 0;
  526. FDealTotalPrice := 0;
  527. FBGLQuantity := 0;
  528. FBGLTotalPrice := 0;
  529. end;
  530. procedure TGclNode.SetB_Code(const Value: string);
  531. begin
  532. FB_Code := Value;
  533. FIndexCode := B_CodeToIndexCode(FB_Code);
  534. end;
  535. { TDetailGclNode }
  536. procedure TDetailGclNode.AddPosData(ALeafXmj, APeg: TBillsIDTreeNode);
  537. function GetPegName: string;
  538. begin
  539. if Assigned(APeg) then
  540. Result := APeg.Rec.Name.AsString
  541. else
  542. Result := '';
  543. end;
  544. // 取树结构的第ALevel层节点的名称(level从0开始)
  545. function GetNameByLevel(ANode: TBillsIDTreeNode; ALevel: Integer): string;
  546. begin
  547. Result := '';
  548. if not Assigned(ANode) then Exit;
  549. if ANode.Level = ALevel then
  550. Result := ANode.Rec.Name.AsString
  551. else if ANode.Level > ALevel then
  552. Result := GetNameByLevel(TBillsIDTreeNode(ANode.Parent), ALevel);
  553. end;
  554. function GetNameDanWei(ANode: TBillsIDTreeNode): string;
  555. begin
  556. // 取树结构的第二层节点的名称
  557. Result := GetNameByLevel(ANode, 1);
  558. end;
  559. // ANode为计量单元节点,APegNode为桩号节点
  560. function GetNameFenBu(ANode, APegNode: TBillsIDTreeNode): string;
  561. var
  562. vCurNode: TBillsIDTreeNode;
  563. begin
  564. // 如果计量单元节点的名称为桩号(转化为判断计量单元节点与桩号节点为同一个)
  565. if not Assigned(APegNode) or (ANode.ID = APegNode.ID) then
  566. // 取树结构的第三层节点的名称
  567. Result := GetNameByLevel(ANode, 2)
  568. // 否则,取桩号节点的子节点的名称
  569. else
  570. begin
  571. vCurNode := ANode;
  572. while vCurNode.Level > APegNode.Level + 1 do
  573. vCurNode := TBillsIDTreeNode(vCurNode.Parent);
  574. Result := vCurNode.Rec.Name.AsString;
  575. end;
  576. end;
  577. // ANode为计量单元节点,APegNode为桩号节点
  578. function GetNameFenXiang(ANode, APegNode: TBillsIDTreeNode): string;
  579. var
  580. iTopLevel: Integer;
  581. vCurNode: TBillsIDTreeNode;
  582. begin
  583. if Assigned(APegNode) then
  584. begin
  585. iTopLevel := 3;
  586. if APegNode.ID <> ANode.ID then
  587. iTopLevel := APegNode.Level + 2;
  588. Result := '';
  589. vCurNode := TBillsIDTreeNode(ANode.Parent);
  590. while vCurNode.Level >= iTopLevel do
  591. begin
  592. Result := vCurNode.Rec.Name.AsString + ';' + Result;
  593. vCurNode := TBillsIDTreeNode(vCurNode.Parent);
  594. end;
  595. end
  596. else
  597. Result := GetNameByLevel(ANode, 3);
  598. end;
  599. function GetNameUnit(ANode: TBillsIDTreeNode): string;
  600. begin
  601. Result := ANode.Rec.Name.AsString;
  602. end;
  603. function GetDrawingCode(ANode: TBillsIDTreeNode): string;
  604. begin
  605. Result := '';
  606. if not Assigned(ANode) then Exit;
  607. Result := ANode.Rec.DrawingCode.AsString;
  608. if Result = '' then
  609. Result := GetDrawingCode(TBillsIDTreeNode(ANode.Parent));
  610. end;
  611. function GetPosition(ANode, APegNode: TBillsIDTreeNode): string;
  612. begin
  613. // 如果计量单元节点的名称为桩号(转化为判断计量单元节点与桩号节点为同一个)
  614. if not Assigned(APegNode) or (ANode.ID = APegNode.ID) then
  615. // 取分部工程
  616. Result := GetNameFenXiang(ANode, APegNode)
  617. // 反之,取分项工程+计量单元
  618. else
  619. Result := GetNameFenXiang(ANode, APegNode) + GetNameUnit(ANode);
  620. end;
  621. begin
  622. if not Assigned(ALeafXmj) then Exit;
  623. FLeafXmjID := ALeafXmj.ID;
  624. FXmjCode := ALeafXmj.Rec.Code.AsString;
  625. FXmjName := ALeafXmj.Rec.Name.AsString;
  626. FXmjUnits := ALeafXmj.Rec.Units.AsString;
  627. FPeg := GetPegName;
  628. FNameDanWei := GetNameDanWei(ALeafXmj);
  629. FNameFenBu := GetNameFenBu(ALeafXmj, APeg);
  630. FNameFenXiang := GetNameFenXiang(ALeafXmj, APeg);
  631. FNameUnit := GetNameUnit(ALeafXmj);
  632. FPosition := GetPosition(ALeafXmj, APeg);
  633. FDrawingCode := GetDrawingCode(ALeafXmj);
  634. end;
  635. constructor TDetailGclNode.Create(AID: Integer);
  636. begin
  637. FID := AID;
  638. end;
  639. { TDetailBGLNode }
  640. constructor TDetailBGLNode.Create(AID: Integer);
  641. begin
  642. FID := AID;
  643. end;
  644. { TDetailDealNode }
  645. constructor TDetailDealNode.Create(AID: Integer);
  646. begin
  647. FID := AID;
  648. end;
  649. end.