GclBillsGatherModel.pas 22 KB

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