ProjGatherDealPay.pas 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. unit ProjGatherDealPay;
  2. interface
  3. uses
  4. Classes, sdDB;
  5. type
  6. TDealPayCalcData = class
  7. private
  8. FCurTotalPrice: Double;
  9. FPreTotalPrice: Double;
  10. FEndTotalPrice: Double;
  11. FAddTotalPrice: Double;
  12. FZoneTotalPrice: Double;
  13. public
  14. property CurTotalPrice: Double read FCurTotalPrice write FCurTotalPrice;
  15. property PreTotalPrice: Double read FPreTotalPrice write FPreTotalPrice;
  16. property EndTotalPrice: Double read FEndTotalPrice write FEndTotalPrice;
  17. property AddTotalPrice: Double read FAddTotalPrice write FAddTotalPrice;
  18. property ZoneTotalPrice: Double read FZoneTotalPrice write FZoneTotalPrice;
  19. end;
  20. TProjGatherDealPayNode = class
  21. private
  22. FID: Integer;
  23. FName: string;
  24. FCalcType: Integer;
  25. FIsMinus: Boolean;
  26. FSerialNo: Integer;
  27. FLinkSerialNo: Integer;
  28. FGatherCalc: TDealPayCalcData;
  29. FProjs: TList;
  30. FSpecialProjs: TList;
  31. function GetProj(AIndex: Integer): TDealPayCalcData;
  32. function GetProjCount: Integer;
  33. function GetSpecialProjCount: Integer;
  34. function GetSpecialProj(AIndex: Integer): TDealPayCalcData;
  35. public
  36. constructor Create(AID: Integer; AProjCount, ASpeicalProjCount: Integer);
  37. destructor Destroy; override;
  38. property ID: Integer read FID;
  39. property Name: string read FName;
  40. property CalcType: Integer read FCalcType;
  41. property IsMinus: Boolean read FIsMinus;
  42. property SerialNo: Integer read FSerialNo;
  43. property LinkSerialNo: Integer read FLinkSerialNo;
  44. property GatherCalc: TDealPayCalcData read FGatherCalc;
  45. property ProjCount: Integer read GetProjCount;
  46. property Proj[AIndex: Integer]: TDealPayCalcData read GetProj;
  47. property SpecialProjCount: Integer read GetSpecialProjCount;
  48. property SpecialProj[AIndex: Integer]: TDealPayCalcData read GetSpecialProj;
  49. end;
  50. TProjGatherDealPayList = class
  51. private
  52. FProjCount: Integer;
  53. FSpecialProjCount: Integer;
  54. FNewID: Integer;
  55. FList: TList;
  56. function FindDealPayNode(ARec: TsdDataRecord): TProjGatherDealPayNode;
  57. function CreateDealPayNode(ARec: TsdDataRecord): TProjGatherDealPayNode;
  58. function GetCount: Integer;
  59. function GetDealPay(AIndex: Integer): TProjGatherDealPayNode;
  60. public
  61. constructor Create(AProjCount, ASpeicalProjCount: Integer);
  62. destructor Destroy; override;
  63. function GetDealPayNode(ARec: TsdDataRecord): TProjGatherDealPayNode;
  64. procedure UpdateLinkSerialNo;
  65. property DealPay[AIndex: Integer]: TProjGatherDealPayNode read GetDealPay;
  66. property Count: Integer read GetCount;
  67. end;
  68. implementation
  69. uses
  70. ZhAPI, SysUtils;
  71. { TProjGatherDealPayNode }
  72. constructor TProjGatherDealPayNode.Create(AID: Integer; AProjCount,
  73. ASpeicalProjCount: Integer);
  74. var
  75. i: Integer;
  76. DealPayCalc: TDealPayCalcData;
  77. begin
  78. FID := AID;
  79. FGatherCalc := TDealPayCalcData.Create;
  80. FProjs := TList.Create;
  81. for i := 0 to AProjCount - 1 do
  82. begin
  83. DealPayCalc := TDealPayCalcData.Create;
  84. FProjs.Add(DealPayCalc);
  85. end;
  86. FSpecialProjs := TList.Create;
  87. for i := 0 to ASpeicalProjCount - 1 do
  88. begin
  89. DealPayCalc := TDealPayCalcData.Create;
  90. FSpecialProjs.Add(DealPayCalc);
  91. end;
  92. end;
  93. destructor TProjGatherDealPayNode.Destroy;
  94. begin
  95. FGatherCalc.Free;
  96. ClearObjects(FSpecialProjs);
  97. FSpecialProjs.Free;
  98. ClearObjects(FProjs);
  99. FProjs.Free;
  100. inherited;
  101. end;
  102. function TProjGatherDealPayNode.GetProj(AIndex: Integer): TDealPayCalcData;
  103. begin
  104. Result := TDealPayCalcData(FProjs.Items[AIndex]);
  105. end;
  106. function TProjGatherDealPayNode.GetProjCount: Integer;
  107. begin
  108. Result := FProjs.Count;
  109. end;
  110. function TProjGatherDealPayNode.GetSpecialProj(
  111. AIndex: Integer): TDealPayCalcData;
  112. begin
  113. Result := TDealPayCalcData(FProjs.Items[AIndex]);
  114. end;
  115. function TProjGatherDealPayNode.GetSpecialProjCount: Integer;
  116. begin
  117. Result := FSpecialProjs.Count;
  118. end;
  119. { TProjGatherDealPayList }
  120. constructor TProjGatherDealPayList.Create(AProjCount,
  121. ASpeicalProjCount: Integer);
  122. begin
  123. FProjCount := AProjCount;
  124. FSpecialProjCount := ASpeicalProjCount;
  125. FList := TList.Create;
  126. FNewID := 1;
  127. end;
  128. function TProjGatherDealPayList.CreateDealPayNode(ARec: TsdDataRecord): TProjGatherDealPayNode;
  129. begin
  130. Result := TProjGatherDealPayNode.Create(FNewID, FProjCount, FSpecialProjCount);
  131. Inc(FNewID);
  132. Result.FName := ARec.ValueByName('Name').AsString;
  133. Result.FCalcType := ARec.ValueByName('CalcType').AsInteger;
  134. Result.FIsMinus := ARec.ValueByName('IsMinus').AsBoolean;
  135. Result.FSerialNo := Result.ID;
  136. FList.Add(Result);
  137. end;
  138. destructor TProjGatherDealPayList.Destroy;
  139. begin
  140. ClearObjects(FList);
  141. FList.Free;
  142. inherited;
  143. end;
  144. function TProjGatherDealPayList.FindDealPayNode(ARec: TsdDataRecord): TProjGatherDealPayNode;
  145. var
  146. iDeal: Integer;
  147. vDeal: TProjGatherDealPayNode;
  148. begin
  149. Result := nil;
  150. for iDeal := 0 to FList.Count - 1 do
  151. begin
  152. vDeal := DealPay[iDeal];
  153. if ARec.ValueByName('CalcType').AsInteger in [0, 3] then
  154. begin
  155. if SameText(vDeal.Name, ARec.ValueByName('Name').AsString) and
  156. (vDeal.IsMinus = ARec.ValueByName('IsMinus').AsBoolean) and
  157. (vDeal.CalcType = ARec.ValueByName('CalcType').AsInteger) then
  158. begin
  159. Result := vDeal;
  160. Break;
  161. end;
  162. end
  163. else
  164. begin
  165. if vDeal.CalcType = ARec.ValueByName('CalcType').AsInteger then
  166. begin
  167. Result := vDeal;
  168. Break;
  169. end;
  170. end;
  171. end;
  172. end;
  173. function TProjGatherDealPayList.GetCount: Integer;
  174. begin
  175. Result := FList.Count;
  176. end;
  177. function TProjGatherDealPayList.GetDealPay(AIndex: Integer): TProjGatherDealPayNode;
  178. begin
  179. Result := TProjGatherDealPayNode(FList.Items[AIndex]);
  180. end;
  181. function TProjGatherDealPayList.GetDealPayNode(ARec: TsdDataRecord): TProjGatherDealPayNode;
  182. begin
  183. Result := FindDealPayNode(ARec);
  184. if not Assigned(Result) then
  185. Result := CreateDealPayNode(ARec);
  186. end;
  187. procedure TProjGatherDealPayList.UpdateLinkSerialNo;
  188. var
  189. iPay, iCut, iIndex: Integer;
  190. vDealPay: TProjGatherDealPayNode;
  191. begin
  192. iPay := 1;
  193. iCut := 1;
  194. for iIndex := 0 to Count - 1 do
  195. begin
  196. vDealPay := DealPay[iIndex];
  197. if vDealPay.CalcType in [0, 3] then
  198. begin
  199. if vDealPay.IsMinus then
  200. begin
  201. vDealPay.FLinkSerialNo := iCut;
  202. Inc(iCut);
  203. end
  204. else
  205. begin
  206. vDealPay.FLinkSerialNo := iPay;
  207. Inc(iPay);
  208. end;
  209. end;
  210. end;
  211. end;
  212. end.