BillsPosTree.pas 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. unit BillsPosTree;
  2. // 清单--部位明细树 (同导入计量Saas相关,不做他用)
  3. interface
  4. uses
  5. Classes, CacheTree, ZhAPI;
  6. type
  7. TPosNode = class
  8. private
  9. FQuantity: Double;
  10. FMemoStr: string;
  11. FName: string;
  12. public
  13. property Name: string read FName write FName;
  14. property Quantity: Double read FQuantity write FQuantity;
  15. property MemoStr: string read FMemoStr write FMemoStr;
  16. end;
  17. TBillsPosTreeNode = class(TCacheNode)
  18. private
  19. FPosList: TList;
  20. FQuantity: Double;
  21. FPrice: Double;
  22. FDgnQty1: Double;
  23. FDgnQty2: Double;
  24. FUnits: string;
  25. FDrawingCode: string;
  26. FName: string;
  27. FCode: string;
  28. FMemoStr: string;
  29. FB_Code: string;
  30. FTotalPrice: Double;
  31. function GetPos(AIndex: Integer): TPosNode;
  32. function GetPosCount: Integer;
  33. public
  34. constructor Create(ACacheTree: TCacheTree; AID: Integer); override;
  35. destructor Destroy; override;
  36. function AddPos: TPosNode;
  37. procedure Calculate;
  38. property Code: string read FCode write FCode;
  39. property B_Code: string read FB_Code write FB_Code;
  40. property Name: string read FName write FName;
  41. property Units: string read FUnits write FUnits;
  42. property Price: Double read FPrice write FPrice;
  43. property Quantity: Double read FQuantity write FQuantity;
  44. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  45. property DgnQty1: Double read FDgnQty1 write FDgnQty1;
  46. property DgnQty2: Double read FDgnQty2 write FDgnQty2;
  47. property DrawingCode: string read FDrawingCode write FDrawingCode;
  48. property MemoStr: string read FMemoStr write FMemoStr;
  49. property PosCount: Integer read GetPosCount;
  50. property Pos[AIndex: Integer]: TPosNode read GetPos;
  51. end;
  52. TBillsPosTree = class(TCacheTree)
  53. private
  54. protected
  55. function GetNewNode: TCacheNode; override;
  56. public
  57. procedure CalculateAll;
  58. end;
  59. implementation
  60. { TBillsPosTreeNode }
  61. function TBillsPosTreeNode.AddPos: TPosNode;
  62. begin
  63. Result := TPosNode.Create;
  64. FPosList.Add(Result);
  65. end;
  66. procedure TBillsPosTreeNode.Calculate;
  67. var
  68. fQuantity: Double;
  69. iPos: Integer;
  70. begin
  71. fQuantity := 0;
  72. for iPos := 0 to FPosList.Count - 1 do
  73. fQuantity := fQuantity + TPosNode(FPosList.Items[iPos]).Quantity;
  74. Quantity := fQuantity;
  75. TotalPrice := Quantity * Price;
  76. end;
  77. constructor TBillsPosTreeNode.Create(ACacheTree: TCacheTree; AID: Integer);
  78. begin
  79. inherited;
  80. FPosList := TList.Create;
  81. end;
  82. destructor TBillsPosTreeNode.Destroy;
  83. begin
  84. ClearObjects(FPosList);
  85. FPosList.Free;
  86. inherited;
  87. end;
  88. function TBillsPosTreeNode.GetPos(AIndex: Integer): TPosNode;
  89. begin
  90. Result := TPosNode(FPosList.Items[AIndex]);
  91. end;
  92. function TBillsPosTreeNode.GetPosCount: Integer;
  93. begin
  94. Result := FPosList.Count;
  95. end;
  96. { TBillsPosTree }
  97. procedure TBillsPosTree.CalculateAll;
  98. var
  99. i: Integer;
  100. vNode: TBillsPosTreeNode;
  101. begin
  102. for i := 0 to CacheNodes.Count - 1 do
  103. begin
  104. vNode := TBillsPosTreeNode(CacheNodes[i]);
  105. if (vNode.PosCount > 0) then
  106. vNode.Calculate;
  107. end;
  108. end;
  109. function TBillsPosTree.GetNewNode: TCacheNode;
  110. begin
  111. Result := TBillsPosTreeNode.Create(Self, GetNewNodeID);
  112. CacheNodes.Add(Result);
  113. end;
  114. end.