BillsPosTree.pas 3.2 KB

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