rmCacheData.pas 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. unit rmCacheData;
  2. // Report Memory Cache Data
  3. interface
  4. uses
  5. Classes, CacheTree, sdIDTree, sdDB;
  6. type
  7. TDoubleArray = array of Double;
  8. TStringArray = array of string;
  9. TGclGatherNode = class
  10. private
  11. FB_Code: string;
  12. FIndexCode: string;
  13. FName: string;
  14. FUnits: string;
  15. FPrice: Double;
  16. FQuantity: Double;
  17. FTotalPrice: Double;
  18. FAddDealQuantity: Double;
  19. FAddDealTotalPrice: Double;
  20. FAddQcQuantity: Double;
  21. FAddQcTotalPrice: Double;
  22. FAddPcQuantity: Double;
  23. FAddPcTotalPrice: Double;
  24. FP_Price: TDoubleArray;
  25. FP_Quantity: TDoubleArray;
  26. FP_TotalPrice: TDoubleArray;
  27. FP_AddGatherQuantity: TDoubleArray;
  28. FP_AddGatherTotalPrice: TDoubleArray;
  29. procedure SetB_Code(const Value: string);
  30. public
  31. constructor Create(AProjectCount: Integer);
  32. property B_Code: string read FB_Code write SetB_Code;
  33. property IndexCode: string read FIndexCode;
  34. property Name: string read FName write FName;
  35. property Units: string read FUnits write FUnits;
  36. property Price: Double read FPrice write FPrice;
  37. property Quantity: Double read FQuantity write FQuantity;
  38. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  39. property AddDealQuantity: Double read FAddDealQuantity write FAddDealQuantity;
  40. property AddDealTotalPrice: Double read FAddDealTotalPrice write FAddDealTotalPrice;
  41. property AddQcQuantity: Double read FAddQcQuantity write FAddQcQuantity;
  42. property AddQcTotalPrice: Double read FAddQcTotalPrice write FAddQcTotalPrice;
  43. property AddPcQuantity: Double read FAddPcQuantity write FAddPcQuantity;
  44. property AddPcTotalPrice: Double read FAddPcTotalPrice write FAddPcTotalPrice;
  45. property P_Price: TDoubleArray read FP_Price write FP_Price;
  46. property P_Quantity: TDoubleArray read FP_Quantity write FP_Quantity;
  47. property P_TotalPrice: TDoubleArray read FP_TotalPrice write FP_TotalPrice;
  48. property P_AddGatherQuantity: TDoubleArray read FP_AddGatherQuantity write FP_AddGatherQuantity;
  49. property P_AddGatherTotalPrice: TDoubleArray read FP_AddGatherTotalPrice write FP_AddGatherTotalPrice;
  50. end;
  51. TGclGatherList = class
  52. private
  53. FList: TList;
  54. FComparePrice: Boolean;
  55. FProjectName: TStringArray;
  56. FProjectCount: Integer;
  57. FGatherNode: TGclGatherNode;
  58. function SameGclNode(AGclNode: TGclGatherNode; ARec: TsdDataRecord): Boolean;
  59. function FindGclNode(ARec: TsdDataRecord): TGclGatherNode;
  60. function AddGclNode(ARec: TsdDataRecord): TGclGatherNode;
  61. function GetCount: Integer;
  62. function GetNode(AIndex: Integer): TGclGatherNode;
  63. public
  64. constructor Create(AProjectCount: Integer; AComparePrice: Boolean = True);
  65. destructor Destroy; override;
  66. function GetGclGatherNode(ARec: TsdDataRecord): TGclGatherNode;
  67. procedure ReCalcualteGatherNode;
  68. property ProjectCount: Integer read FProjectCount;
  69. property Count: Integer read GetCount;
  70. property Node[AIndex: Integer]: TGclGatherNode read GetNode;
  71. property GatherNode: TGclGatherNode read FGatherNode;
  72. property ProjectName: TStringArray read FProjectName write FProjectName;
  73. end;
  74. TFixedIDBillsNode = class
  75. private
  76. FFixedID: Integer;
  77. FName: string;
  78. FTotalPrice: Double;
  79. FP_TotalPrice: TDoubleArray;
  80. FAddGatherTotalPrice: Double;
  81. FP_AddGatherTotalPrice: TDoubleArray;
  82. public
  83. constructor Create(AProjectCount: Integer);
  84. property FixedID: Integer read FFixedID write FFixedID;
  85. property Name: string read FName write FName;
  86. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  87. property P_TotalPrice: TDoubleArray read FP_TotalPrice write FP_TotalPrice;
  88. property AddGatherTotalPrice: Double read FAddGatherTotalPrice write FAddGatherTotalPrice;
  89. property P_AddGatherTotalPrice: TDoubleArray read FP_AddGatherTotalPrice write FP_AddGatherTotalPrice;
  90. end;
  91. TFixedIDBillsList = class
  92. private
  93. FList: TList;
  94. FProjectName: TStringArray;
  95. FProjectCount: Integer;
  96. function AddNode(AFixedID: Integer): TFixedIDBillsNode;
  97. function GetCount: Integer;
  98. function GetNode(AIndex: Integer): TFixedIDBillsNode;
  99. public
  100. constructor Create(AProjectCount: Integer);
  101. destructor Destroy; override;
  102. function GetFixedIDBillsNode(AFixedID: Integer): TFixedIDBillsNode;
  103. function FixedIDBillsNode(AFixedID: Integer): TFixedIDBillsNode;
  104. property ProjectCount: Integer read FProjectCount;
  105. property Count: Integer read GetCount;
  106. property Node[AIndex: Integer]: TFixedIDBillsNode read GetNode;
  107. property ProjectName: TStringArray read FProjectName write FProjectName;
  108. end;
  109. implementation
  110. uses
  111. ZhAPI, DateUtils, SysUtils, UtilMethods;
  112. { TGclGatherNode }
  113. constructor TGclGatherNode.Create(AProjectCount: Integer);
  114. begin
  115. SetLength(FP_Price, AProjectCount);
  116. SetLength(FP_Quantity, AProjectCount);
  117. SetLength(FP_TotalPrice, AProjectCount);
  118. SetLength(FP_AddGatherQuantity, AProjectCount);
  119. SetLength(FP_AddGatherTotalPrice, AProjectCount);
  120. end;
  121. procedure TGclGatherNode.SetB_Code(const Value: string);
  122. begin
  123. FB_Code := Value;
  124. FIndexCode := B_CodeToIndexCode(FB_Code);
  125. end;
  126. { TGclGatherList }
  127. constructor TGclGatherList.Create(AProjectCount: Integer;
  128. AComparePrice: Boolean = True);
  129. begin
  130. FProjectCount := AProjectCount;
  131. FList := TList.Create;
  132. FComparePrice := AComparePrice;
  133. SetLength(FProjectName, FProjectCount);
  134. FGatherNode := TGclGatherNode.Create(FProjectCount);
  135. end;
  136. destructor TGclGatherList.Destroy;
  137. begin
  138. FGatherNode.Free;
  139. ClearObjects(FList);
  140. FList.Free;
  141. inherited;
  142. end;
  143. function TGclGatherList.FindGclNode(ARec: TsdDataRecord): TGclGatherNode;
  144. var
  145. i: Integer;
  146. GclNode: TGclGatherNode;
  147. begin
  148. Result := nil;
  149. for i := 0 to FList.Count - 1 do
  150. begin
  151. GclNode := TGclGatherNode(FList.Items[i]);
  152. if SameGclNode(GclNode, ARec) then
  153. begin
  154. Result := GclNode;
  155. Break;
  156. end;
  157. end;
  158. end;
  159. function TGclGatherList.GetCount: Integer;
  160. begin
  161. Result := FList.Count;
  162. end;
  163. function TGclGatherList.GetNode(AIndex: Integer): TGclGatherNode;
  164. begin
  165. Result := TGclGatherNode(FList.Items[AIndex]);
  166. end;
  167. function TGclGatherList.GetGclGatherNode(ARec: TsdDataRecord): TGclGatherNode;
  168. begin
  169. Result := FindGclNode(ARec);
  170. if not Assigned(Result) then
  171. Result := AddGclNode(ARec);
  172. end;
  173. function TGclGatherList.AddGclNode(ARec: TsdDataRecord): TGclGatherNode;
  174. begin
  175. Result := TGclGatherNode.Create(FProjectCount);
  176. FList.Add(Result);
  177. Result.B_Code := ARec.ValueByName('B_Code').AsString;
  178. Result.Name := ARec.ValueByName('Name').AsString;
  179. Result.Units := ARec.ValueByName('Units').AsString;
  180. Result.Price := ARec.ValueByName('Price').AsFloat;
  181. end;
  182. procedure TGclGatherList.ReCalcualteGatherNode;
  183. var
  184. iNode, iP: Integer;
  185. GclNode: TGclGatherNode;
  186. begin
  187. for iNode := 0 to FList.Count - 1 do
  188. begin
  189. GclNode := TGclGatherNode(FList.Items[iNode]);
  190. FGatherNode.Quantity := FGatherNode.Quantity + GclNode.Quantity;
  191. FGatherNode.TotalPrice := FGatherNode.TotalPrice + GclNode.TotalPrice;
  192. FGatherNode.AddDealQuantity := FGatherNode.AddDealQuantity + GclNode.AddDealQuantity;
  193. FGatherNode.AddDealTotalPrice := FGatherNode.AddDealTotalPrice + GclNode.AddDealTotalPrice;
  194. FGatherNode.AddQcQuantity := FGatherNode.AddQcQuantity + GclNode.AddQcQuantity;
  195. FGatherNode.AddQcTotalPrice := FGatherNode.AddQcTotalPrice + GclNode.AddQcTotalPrice;
  196. FGatherNode.AddPcQuantity := FGatherNode.AddPcQuantity + GclNode.AddPcQuantity;
  197. FGatherNode.AddPcTotalPrice := FGatherNode.AddPcTotalPrice + GclNode.AddPcTotalPrice;
  198. for iP := 0 to FProjectCount - 1 do
  199. begin
  200. FGatherNode.P_Quantity[iP] := FGatherNode.P_Quantity[iP] + GclNode.P_Quantity[iP];
  201. FGatherNode.P_TotalPrice[iP] := FGatherNode.P_TotalPrice[iP] + GclNode.P_TotalPrice[iP];
  202. FGatherNode.P_AddGatherQuantity[iP] := FGatherNode.P_AddGatherQuantity[iP] + GclNode.P_AddGatherQuantity[iP];
  203. FGatherNode.P_AddGatherTotalPrice[iP] := FGatherNode.P_AddGatherTotalPrice[iP] + GclNode.P_AddGatherTotalPrice[iP];
  204. end;
  205. end;
  206. end;
  207. function TGclGatherList.SameGclNode(AGclNode: TGclGatherNode; ARec: TsdDataRecord): Boolean;
  208. begin
  209. Result := SameText(AGclNode.B_Code, ARec.ValueByName('B_Code').AsString) and
  210. SameText(AGclNode.Name, ARec.ValueByName('Name').AsString) and
  211. SameText(AGclNode.Units, ARec.ValueByName('Units').AsString);
  212. if FComparePrice then
  213. Result := Result and (AGclNode.Price = ARec.ValueByName('Price').AsFloat);
  214. end;
  215. { TFixedIDBillsNode }
  216. constructor TFixedIDBillsNode.Create(AProjectCount: Integer);
  217. begin
  218. SetLength(FP_TotalPrice, AProjectCount);
  219. SetLength(FP_AddGatherTotalPrice, AProjectCount);
  220. end;
  221. { TFixedIDBillsList }
  222. function TFixedIDBillsList.AddNode(AFixedID: Integer): TFixedIDBillsNode;
  223. begin
  224. Result := TFixedIDBillsNode.Create(FProjectCount);
  225. FList.Add(Result);
  226. Result.FixedID := AFixedID;
  227. end;
  228. constructor TFixedIDBillsList.Create(AProjectCount: Integer);
  229. begin
  230. FProjectCount := AProjectCount;
  231. FList := TList.Create;
  232. SetLength(FProjectName, FProjectCount);
  233. end;
  234. destructor TFixedIDBillsList.Destroy;
  235. begin
  236. ClearObjects(FList);
  237. FList.Free;
  238. inherited;
  239. end;
  240. function TFixedIDBillsList.FixedIDBillsNode(
  241. AFixedID: Integer): TFixedIDBillsNode;
  242. var
  243. i: Integer;
  244. begin
  245. Result := nil;
  246. for i := 0 to FList.Count - 1 do
  247. begin
  248. if TFixedIDBillsNode(FList.Items[i]).FixedID = AFixedID then
  249. begin
  250. Result := TFixedIDBillsNode(FList.Items[i]);
  251. Break;
  252. end;
  253. end;
  254. end;
  255. function TFixedIDBillsList.GetCount: Integer;
  256. begin
  257. Result := FList.Count;
  258. end;
  259. function TFixedIDBillsList.GetFixedIDBillsNode(
  260. AFixedID: Integer): TFixedIDBillsNode;
  261. begin
  262. Result := FixedIDBillsNode(AFixedID);
  263. if not Assigned(Result) then
  264. Result := AddNode(AFixedID);
  265. end;
  266. function TFixedIDBillsList.GetNode(AIndex: Integer): TFixedIDBillsNode;
  267. begin
  268. Result := TFixedIDBillsNode(FList.Items[AIndex]);
  269. end;
  270. end.