BillsTree.pas 7.5 KB

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