BillsTree.pas 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. unit BillsTree;
  2. interface
  3. uses
  4. sdIDTree, sdDB, mDataRecord;
  5. type
  6. TBillsIDTreeNode = class(TsdIDTreeNode)
  7. private
  8. FDealQuantity: Double;
  9. FDealTotalPrice: Double;
  10. FQcQuantity: Double;
  11. FQcTotalPrice: Double;
  12. FPcQuantity: Double;
  13. FPcTotalPrice: Double;
  14. FGatherTotalPrice: Double;
  15. FGatherQuantity: Double;
  16. FStageRec: TStageRecord;
  17. function GetRec: TBillsRecord;
  18. public
  19. function CanUpLevel: Boolean; override;
  20. function CanDownLevel: Boolean; override;
  21. function CanUpMove: Boolean; override;
  22. function CanDownMove: Boolean; override;
  23. function UpLevel: Boolean; override;
  24. function DownLevel: Boolean; override;
  25. function HasMeasure: Boolean;
  26. function HasLedger: Boolean;
  27. property Rec: TBillsRecord read GetRec;
  28. property DealQuantity: Double read FDealQuantity write FDealQuantity;
  29. property DealTotalPrice: Double read FDealTotalPrice write FDealTotalPrice;
  30. property QcQuantity: Double read FQcQuantity write FQcQuantity;
  31. property QcTotalPrice: Double read FQcTotalPrice write FQcTotalPrice;
  32. property PcQuantity: Double read FPcQuantity write FPcQuantity;
  33. property PcTotalPrice: Double read FPcTotalPrice write FPcTotalPrice;
  34. property GatherQuantity: Double read FGatherQuantity write FGatherQuantity;
  35. property GatherTotalPrice: Double read FGatherTotalPrice write FGatherTotalPrice;
  36. // Cache Data
  37. property StageRec: TStageRecord read FStageRec write FStageRec;
  38. end;
  39. TbitAfterDeleteNode = procedure (AParent: TsdIDTreeNode) of object;
  40. TBillsIDTree = class(TsdIDTree)
  41. private
  42. FDoOnAfterDeleteNode: TbitAfterDeleteNode;
  43. protected
  44. function CreateItem: TsdIDTreeNode; override;
  45. public
  46. function CanDelete(ANode: TsdIDTreeNode): Boolean; override;
  47. function DeleteNode(ANode: TsdIDTreeNode): Boolean; override;
  48. function Add(AParentID, ANextSiblingID: TsdTreeNodeID): TsdIDTreeNode; override;
  49. property DoOnAfterDeleteNode: TbitAfterDeleteNode read FDoOnAfterDeleteNode write FDoOnAfterDeleteNode;
  50. end;
  51. TEstimateIDTreeNode = class(TsdIDTreeNode)
  52. public
  53. function CanExpand: Boolean; override;
  54. end;
  55. TEstimateIDTree = class(TsdIDTree)
  56. public
  57. function CreateItem: TsdIDTreeNode; override;
  58. end;
  59. implementation
  60. { TBillsIDTree }
  61. function TBillsIDTree.Add(AParentID,
  62. ANextSiblingID: TsdTreeNodeID): TsdIDTreeNode;
  63. begin
  64. // 不允许插入首层节点
  65. if (Selected <> nil) and (Selected.Level = 0) then
  66. Result := inherited Add(Selected.ID, -1)
  67. else
  68. Result := inherited Add(AParentID, ANextSiblingID);
  69. end;
  70. function TBillsIDTree.CanDelete(ANode: TsdIDTreeNode): Boolean;
  71. begin
  72. Result := Inherited CanDelete(ANode)
  73. and (ANode.ID >= 100)
  74. and (not ANode.Rec.ValueByName('LockedLevel').AsBoolean)
  75. and (ANode.Rec.ValueByName('AddDealQuantity').AsFloat = 0)
  76. and (ANode.Rec.ValueByName('AddDealTotalPrice').AsFloat = 0)
  77. and (ANode.Rec.ValueByName('AddQcQuantity').AsFloat = 0)
  78. and (ANode.Rec.ValueByName('AddQcTotalPrice').AsFloat = 0)
  79. and (ANode.Rec.ValueByName('AddPcQuantity').AsFloat = 0)
  80. and (ANode.Rec.ValueByName('AddPcTotalPrice').AsFloat = 0);
  81. end;
  82. function TBillsIDTree.CreateItem: TsdIDTreeNode;
  83. begin
  84. Result := TBillsIDTreeNode.Create(Self);
  85. end;
  86. function TBillsIDTree.DeleteNode(ANode: TsdIDTreeNode): Boolean;
  87. var
  88. vParent: TsdIDTreeNode;
  89. begin
  90. vParent := ANode.Parent;
  91. Result := inherited DeleteNode(ANode);
  92. if Assigned(FDoOnAfterDeleteNode) then
  93. FDoOnAfterDeleteNode(vParent);
  94. end;
  95. { TBillsIDTreeNode }
  96. function TBillsIDTreeNode.CanDownLevel: Boolean;
  97. begin
  98. Result := Inherited CanDownLevel
  99. and (Level > 0)
  100. and (not Rec.ValueByName('LockedLevel').AsBoolean)
  101. and not HasMeasure;
  102. if Assigned(PrevSibling) then
  103. begin
  104. Result := Result
  105. and (PrevSibling.HasChildren or not TBillsIDTreeNode(PrevSibling).HasMeasure);
  106. end;
  107. end;
  108. function TBillsIDTreeNode.CanDownMove: Boolean;
  109. begin
  110. Result := Inherited CanDownMove
  111. and (not Rec.ValueByName('LockedLevel').AsBoolean);
  112. end;
  113. function TBillsIDTreeNode.CanUpLevel: Boolean;
  114. var
  115. vNextSibling: TsdIDTreeNode;
  116. begin
  117. Result := Inherited CanUpLevel
  118. and (Level > 1)
  119. and (not Rec.ValueByName('LockedLevel').AsBoolean)
  120. and not HasMeasure;
  121. vNextSibling := NextSibling;
  122. while Assigned(vNextSibling) and Result do
  123. begin
  124. Result := Result
  125. and not TBillsIDTreeNode(NextSibling).HasMeasure;
  126. vNextSibling := vNextSibling.NextSibling;
  127. end;
  128. end;
  129. function TBillsIDTreeNode.CanUpMove: Boolean;
  130. begin
  131. Result := Inherited CanUpMove
  132. and (not Rec.ValueByName('LockedLevel').AsBoolean);
  133. end;
  134. function TBillsIDTreeNode.DownLevel: Boolean;
  135. begin
  136. Result := inherited DownLevel;
  137. // 如升级后变为父项,则清空数量、单价
  138. if Assigned(Parent) then
  139. begin
  140. Parent.Rec.ValueByName('Quantity').AsFloat := 0;
  141. Parent.Rec.ValueByName('Price').AsFloat := 0;
  142. end;
  143. end;
  144. function TBillsIDTreeNode.GetRec: TBillsRecord;
  145. begin
  146. Result := TBillsRecord(TsdIDTreeNode(Self).Rec);
  147. end;
  148. function TBillsIDTreeNode.HasLedger: Boolean;
  149. begin
  150. Result := False;
  151. if not Assigned(Rec) then Exit;
  152. Result := (Rec.Price.AsFloat <> 0)
  153. or (Rec.Quantity.AsFloat <> 0);
  154. end;
  155. function TBillsIDTreeNode.HasMeasure: Boolean;
  156. begin
  157. Result := False;
  158. if not Assigned(Rec) then Exit;
  159. Result := (Rec.AddDealQuantity.AsFloat <> 0)
  160. or (Rec.AddDealTotalPrice.AsFloat <> 0)
  161. or (Rec.AddQcQuantity.AsFloat <> 0)
  162. or (Rec.AddQcTotalPrice.AsFloat <> 0)
  163. or (Rec.AddPcQuantity.AsFloat <> 0)
  164. or (Rec.AddPcTotalPrice.AsFloat <> 0);
  165. end;
  166. function TBillsIDTreeNode.UpLevel: Boolean;
  167. begin
  168. Result := inherited UpLevel;
  169. // 如升级后变为父项,则清空数量、单价
  170. if HasChildren then
  171. begin
  172. Rec.ValueByName('Quantity').AsFloat := 0;
  173. Rec.ValueByName('Price').AsFloat := 0;
  174. end;
  175. end;
  176. { TEstimateIDTreeNode }
  177. function TEstimateIDTreeNode.CanExpand: Boolean;
  178. var
  179. iChild: Integer;
  180. vChild: TsdIDTreeNode;
  181. begin
  182. Result := True;
  183. if HasChildren then
  184. for iChild := 0 to ChildCount - 1 do
  185. begin
  186. vChild := ChildNodes[iChild];
  187. if vChild.Rec.ValueByName('B_Code').AsString <> '' then
  188. begin
  189. Result := False;
  190. Break;
  191. end;
  192. end;
  193. end;
  194. { TEstimateIDTree }
  195. function TEstimateIDTree.CreateItem: TsdIDTreeNode;
  196. begin
  197. Result := TEstimateIDTreeNode.Create(Self);
  198. end;
  199. end.