rmGclBillsCompareDm.pas 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. unit rmGclBillsCompareDm;
  2. // Report Memory Gcl Bills Compare DataModule
  3. // For [05.�뵙궐싹깊] 連깊01 묏넋좆헌데�뵙궐싹깊(0뵀憩瑯)
  4. interface
  5. uses
  6. SysUtils, Classes, ProjectData, sdDB, DB, DBClient, sdIDTree;
  7. type
  8. TCompareGclNode = class
  9. private
  10. FB_Code: string;
  11. FIndexCode: string;
  12. FName: string;
  13. FUnits: string;
  14. FSQuantity: Double;
  15. FSPrice: Double;
  16. FSTotalPrice: Double;
  17. FCQuantity: Double;
  18. FCPrice: Double;
  19. FCTotalPrice: Double;
  20. FMemoStr: string;
  21. function GetDPrice: Double;
  22. function GetDQuantity: Double;
  23. function GetDTotalPrice: Double;
  24. public
  25. property B_Code: string read FB_Code write FB_Code;
  26. property IndexCode: string read FIndexCode write FIndexCode;
  27. property Name: string read FName write FName;
  28. property Units: string read FUnits write FUnits;
  29. // 覩괩
  30. property SQuantity: Double read FSQuantity write FSQuantity;
  31. property SPrice: Double read FSPrice write FSPrice;
  32. property STotalPrice: Double read FSTotalPrice write FSTotalPrice;
  33. // �뵙
  34. property CQuantity: Double read FCQuantity write FCQuantity;
  35. property CPrice: Double read FCPrice write FCPrice;
  36. property CTotalPrice: Double read FCTotalPrice write FCTotalPrice;
  37. // �뵙 - 覩괩
  38. property DQuantity: Double read GetDQuantity;
  39. property DPrice: Double read GetDPrice;
  40. property DTotalPrice: Double read GetDTotalPrice;
  41. property MemoStr: string read FMemoStr;
  42. end;
  43. TrmGclBillsCompareData = class(TDataModule)
  44. cdsBills: TClientDataSet;
  45. cdsBillsB_Code: TStringField;
  46. cdsBillsCodeIndex: TStringField;
  47. cdsBillsName: TWideStringField;
  48. cdsBillsUnits: TWideStringField;
  49. cdsBillsSQuantity: TFloatField;
  50. cdsBillsSPrice: TFloatField;
  51. cdsBillsSTotalPrice: TFloatField;
  52. cdsBillsCQuantity: TFloatField;
  53. cdsBillsCPrice: TFloatField;
  54. cdsBillsCTotalPrice: TFloatField;
  55. cdsBillsDQuantity: TFloatField;
  56. cdsBillsDPrice: TFloatField;
  57. cdsBillsDTotalPrice: TFloatField;
  58. cdsBillsMemoStr: TWideStringField;
  59. private
  60. FNodeList: TList;
  61. procedure LoadGclNodeData(AGclNode: TCompareGclNode; ARec: TsdDataRecord; AIsSource: Boolean);
  62. procedure FilterGclBills(ANode: TsdIDTreeNode; AIsSource: Boolean);
  63. procedure FilterBills(ANode: TsdIDTreeNode; AIsSource: Boolean);
  64. procedure WriteBills;
  65. public
  66. constructor Create;
  67. destructor Destroy; override;
  68. function AssignData(ASProjectData, ACProjectData: TProjectData): TDataSet;
  69. end;
  70. implementation
  71. uses
  72. Globals, UtilMethods, ZhAPI;
  73. {$R *.dfm}
  74. { TCompareGclNode }
  75. function TCompareGclNode.GetDPrice: Double;
  76. begin
  77. {Result := FCPrice;
  78. if Result = 0 then
  79. Result := FSPrice;}
  80. Result := CPrice - SPrice;
  81. end;
  82. function TCompareGclNode.GetDQuantity: Double;
  83. begin
  84. Result := CQuantity - SQuantity;
  85. end;
  86. function TCompareGclNode.GetDTotalPrice: Double;
  87. begin
  88. Result := CTotalPrice - STotalPrice;
  89. end;
  90. { TGclBillsCompareData }
  91. function TrmGclBillsCompareData.AssignData(
  92. ASProjectData, ACProjectData: TProjectData): TDataSet;
  93. begin
  94. cdsBills.Active := True;
  95. cdsBills.EmptyDataSet;
  96. ClearObjects(FNodeList);
  97. try
  98. FilterBills(ASProjectData.BillsCompileData.BillsCompileTree.FirstNode, True);
  99. FilterBills(ACProjectData.BillsCompileData.BillsCompileTree.FirstNode, False);
  100. WriteBills;
  101. finally
  102. Result := cdsBills;
  103. end;
  104. end;
  105. constructor TrmGclBillsCompareData.Create;
  106. begin
  107. inherited Create(nil);
  108. FNodeList := TList.Create;
  109. cdsBills.IndexFieldNames := 'CodeIndex';
  110. end;
  111. destructor TrmGclBillsCompareData.Destroy;
  112. begin
  113. ClearObjects(FNodeList);
  114. FNodeList.Free;
  115. inherited;
  116. end;
  117. procedure TrmGclBillsCompareData.FilterBills(ANode: TsdIDTreeNode;
  118. AIsSource: Boolean);
  119. begin
  120. if not Assigned(ANode) then Exit;
  121. if ANode.HasChildren then
  122. FilterBills(ANode.FirstChild, AIsSource)
  123. else
  124. FilterGclBills(ANode, AIsSource);
  125. FilterBills(ANode.NextSibling, AIsSource);
  126. end;
  127. procedure TrmGclBillsCompareData.FilterGclBills(ANode: TsdIDTreeNode;
  128. AIsSource: Boolean);
  129. function CreateGclNode(ARec: TsdDataRecord): TCompareGclNode;
  130. begin
  131. Result := TCompareGclNode.Create;
  132. FNodeList.Add(Result);
  133. Result.FB_Code := ARec.ValueByName('B_Code').AsString;
  134. Result.FIndexCode := B_CodeToIndexCode(ARec.ValueByName('B_Code').AsString);
  135. Result.FName := ARec.ValueByName('Name').AsString;
  136. Result.FUnits := ARec.ValueByName('Units').AsString;
  137. end;
  138. function GetGclNode(ARec: TsdDataRecord): TCompareGclNode;
  139. var
  140. I: Integer;
  141. GclNode: TCompareGclNode;
  142. begin
  143. Result := nil;
  144. for I := 0 to FNodeList.Count - 1 do
  145. begin
  146. GclNode := TCompareGclNode(FNodeList.Items[I]);
  147. if SameText(GclNode.FB_Code, ARec.ValueByName('B_Code').AsString) and
  148. SameText(GclNode.FName, ARec.ValueByName('Name').AsString) and
  149. SameText(GclNode.FUnits, ARec.ValueByName('Units').AsString) then
  150. begin
  151. Result := GclNode;
  152. Break;
  153. end;
  154. end;
  155. if not Assigned(Result) then
  156. Result := CreateGclNode(ARec);
  157. end;
  158. var
  159. Rec: TsdDataRecord;
  160. GclNode: TCompareGclNode;
  161. begin
  162. if not Assigned(ANode) then Exit;
  163. Rec := ANode.Rec;
  164. if Rec.ValueByName('B_Code').AsString = '' then Exit;
  165. GclNode := GetGclNode(Rec);
  166. LoadGclNodeData(GclNode, Rec, AIsSource);
  167. end;
  168. procedure TrmGclBillsCompareData.LoadGclNodeData(AGclNode: TCompareGclNode;
  169. ARec: TsdDataRecord; AIsSource: Boolean);
  170. begin
  171. if AIsSource then
  172. begin
  173. AGclNode.FSQuantity := AGclNode.FSQuantity + ARec.ValueByName('Quantity').AsFloat;
  174. AGclNode.FSPrice := ARec.ValueByName('Price').AsFloat;
  175. AGclNode.FSTotalPrice := AGclNode.FSTotalPrice + ARec.ValueByName('TotalPrice').AsFloat;
  176. end
  177. else
  178. begin
  179. AGclNode.FCQuantity := AGclNode.FCQuantity + ARec.ValueByName('Quantity').AsFloat;
  180. AGclNode.FCPrice := ARec.ValueByName('Price').AsFloat;
  181. AGclNode.FCTotalPrice := AGclNode.FCTotalPrice + ARec.ValueByName('TotalPrice').AsFloat;
  182. end;
  183. end;
  184. procedure TrmGclBillsCompareData.WriteBills;
  185. var
  186. I: Integer;
  187. GclNode: TCompareGclNode;
  188. begin
  189. for I := 0 to FNodeList.Count - 1 do
  190. begin
  191. GclNode := TCompareGclNode(FNodeList.Items[I]);
  192. cdsBills.Append;
  193. cdsBillsB_Code.AsString := GclNode.B_Code;
  194. cdsBillsCodeIndex.AsString := GclNode.IndexCode;
  195. cdsBillsName.AsString := GclNode.Name;
  196. cdsBillsUnits.AsString := GclNode.Units;
  197. cdsBillsSQuantity.AsFloat := GclNode.SQuantity;
  198. cdsBillsSPrice.AsFloat := GclNode.SPrice;
  199. cdsBillsSTotalPrice.AsFloat := GclNode.STotalPrice;
  200. cdsBillsCQuantity.AsFloat := GclNode.CQuantity;
  201. cdsBillsCPrice.AsFloat := GclNode.CPrice;
  202. cdsBillsCTotalPrice.AsFloat := GclNode.CTotalPrice;
  203. cdsBillsDQuantity.AsFloat := GclNode.DQuantity;
  204. cdsBillsDPrice.AsFloat := GclNode.DPrice;
  205. cdsBillsDTotalPrice.AsFloat := GclNode.DTotalPrice;
  206. cdsBillsMemoStr.AsString := GclNode.MemoStr;
  207. cdsBills.Post;
  208. end;
  209. end;
  210. end.