CalcDecimal.pas 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. unit CalcDecimal;
  2. interface
  3. uses
  4. Classes, sdDB;
  5. type
  6. TDecimal = class
  7. private
  8. FDigit: Integer;
  9. FFormat: string;
  10. FLinkViewCols: TList;
  11. procedure SetDigit(const Value: Integer);
  12. function GetDisplayFormat(ADigit: Integer): string;
  13. public
  14. constructor Create;
  15. destructor Destroy; override;
  16. function RoundTo(AValue: Double): Double;
  17. procedure ClearLinkViewCols;
  18. procedure AddLinkViewCol(ACol: TObject);
  19. procedure RefreshLinkViewColsFormat;
  20. property Digit: Integer read FDigit write SetDigit;
  21. property Format: string read FFormat;
  22. end;
  23. TCalcDecimal = class
  24. private
  25. FQuantity: TDecimal;
  26. FTotalPrice: TDecimal;
  27. FPrice: TDecimal;
  28. public
  29. constructor Create;
  30. destructor Destroy; override;
  31. procedure ResetLinkViewColumns(AProjectData: TObject);
  32. procedure RefreshLinkViewColumnsFormat;
  33. property Quantity: TDecimal read FQuantity;
  34. property TotalPrice: TDecimal read FTotalPrice;
  35. property Price: TDecimal read FPrice;
  36. end;
  37. TDecimalManager = class
  38. private
  39. FProjectData: TObject;
  40. FCommon: TCalcDecimal;
  41. FCompile:TCalcDecimal;
  42. FPriceMargin: TCalcDecimal;
  43. public
  44. constructor Create(AProjectData: TObject);
  45. destructor Destroy; override;
  46. procedure ResetLinkViewColumns;
  47. procedure RefreshLinkViewColumnsFormat;
  48. property Common: TCalcDecimal read FCommon;
  49. property Compile: TCalcDecimal read FCompile;
  50. property PriceMargin: TCalcDecimal read FPriceMargin;
  51. end;
  52. implementation
  53. uses
  54. ProjectData, ScUtils;
  55. { TDecimal }
  56. procedure TDecimal.AddLinkViewCol(ACol: TObject);
  57. begin
  58. FLinkViewCols.Add(ACol);
  59. end;
  60. procedure TDecimal.ClearLinkViewCols;
  61. begin
  62. FLinkViewCols.Clear;
  63. end;
  64. constructor TDecimal.Create;
  65. begin
  66. FLinkViewCols := TList.Create;
  67. end;
  68. destructor TDecimal.Destroy;
  69. begin
  70. FLinkViewCols.Free;
  71. inherited;
  72. end;
  73. function TDecimal.GetDisplayFormat(ADigit: Integer): string;
  74. begin
  75. case ADigit of
  76. 0: Result := '#';
  77. 1: Result := '#.#';
  78. 2: Result := '#.##';
  79. 3: Result := '#.###';
  80. 4: Result := '#.####';
  81. 5: Result := '#.#####';
  82. 6: Result := '#.######';
  83. 7: Result := '#.#######';
  84. 8: Result := '#.########';
  85. 9: Result := '#.#########';
  86. else
  87. Result := '#.##########';
  88. end;
  89. end;
  90. procedure TDecimal.RefreshLinkViewColsFormat;
  91. var
  92. i: Integer;
  93. ViewCol: TsdViewColumn;
  94. begin
  95. for i := 0 to FLinkViewCols.Count - 1 do
  96. begin
  97. ViewCol := TsdViewColumn(FLinkViewCols.Items[i]);
  98. if not Assigned(ViewCol) then Continue;
  99. ViewCol.DisplayFormat := FFormat;
  100. ViewCol.EditFormat := FFormat;
  101. end;
  102. end;
  103. function TDecimal.RoundTo(AValue: Double): Double;
  104. begin
  105. Result := ScRoundTo(AValue, -Digit);
  106. end;
  107. procedure TDecimal.SetDigit(const Value: Integer);
  108. begin
  109. if FDigit <> Value then
  110. begin
  111. FDigit := Value;
  112. FFormat := GetDisplayFormat(FDigit);
  113. RefreshLinkViewColsFormat;
  114. end;
  115. end;
  116. { TCalcDecimal }
  117. constructor TCalcDecimal.Create;
  118. begin
  119. FQuantity := TDecimal.Create;
  120. FTotalPrice := TDecimal.Create;
  121. FPrice := TDecimal.Create;
  122. end;
  123. destructor TCalcDecimal.Destroy;
  124. begin
  125. FPrice.Free;
  126. FTotalPrice.Free;
  127. FQuantity.Free;
  128. inherited;
  129. end;
  130. procedure TCalcDecimal.RefreshLinkViewColumnsFormat;
  131. begin
  132. Price.RefreshLinkViewColsFormat;
  133. end;
  134. procedure TCalcDecimal.ResetLinkViewColumns(AProjectData: TObject);
  135. begin
  136. Price.ClearLinkViewCols;
  137. with TProjectData(AProjectData).ProjectGLData.sdvProjectGL do
  138. begin
  139. Price.AddLinkViewCol(Columns.FindColumn('BasePrice'));
  140. Price.AddLinkViewCol(Columns.FindColumn('InfoPrice'));
  141. Price.AddLinkViewCol(Columns.FindColumn('DeltaPrice'));
  142. Price.AddLinkViewCol(Columns.FindColumn('ValidDeltaPrice'));
  143. end;
  144. Price.RefreshLinkViewColsFormat;
  145. end;
  146. { TDecimalManager }
  147. constructor TDecimalManager.Create(AProjectData: TObject);
  148. begin
  149. FProjectData := AProjectData;
  150. FCommon := TCalcDecimal.Create;
  151. FCompile := TCalcDecimal.Create;
  152. FPriceMargin := TCalcDecimal.Create;
  153. end;
  154. destructor TDecimalManager.Destroy;
  155. begin
  156. FPriceMargin.Free;
  157. FCompile.Free;
  158. FCommon.Free;
  159. inherited;
  160. end;
  161. procedure TDecimalManager.RefreshLinkViewColumnsFormat;
  162. begin
  163. FCommon.Quantity.RefreshLinkViewColsFormat;
  164. FCommon.TotalPrice.RefreshLinkViewColsFormat;
  165. FCommon.Price.RefreshLinkViewColsFormat;
  166. FCompile.Quantity.RefreshLinkViewColsFormat;
  167. FCompile.TotalPrice.RefreshLinkViewColsFormat;
  168. FCompile.Price.RefreshLinkViewColsFormat;
  169. end;
  170. procedure TDecimalManager.ResetLinkViewColumns;
  171. procedure ResetCommonLink;
  172. begin
  173. FCommon.Quantity.ClearLinkViewCols;
  174. FCommon.TotalPrice.ClearLinkViewCols;
  175. FCommon.Price.ClearLinkViewCols;
  176. with TProjectData(FProjectData).BillsCompileData.sdvBillsCompile do
  177. begin
  178. // Quantity
  179. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('OrgQuantity'));
  180. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('MisQuantity'));
  181. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('OthQuantity'));
  182. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('Quantity'));
  183. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('DgnQuantity1'));
  184. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('DgnQuantity2'));
  185. // TotalPrice
  186. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('OrgTotalPrice'));
  187. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('MisTotalPrice'));
  188. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('OthTotalPrice'));
  189. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('TotalPrice'));
  190. // Price
  191. FCommon.Price.AddLinkViewCol(Columns.FindColumn('Price'));
  192. FCommon.Price.AddLinkViewCol(Columns.FindColumn('NewPrice'));
  193. end;
  194. with TProjectData(FProjectData).BillsMeasureData.sdvBillsMeasure do
  195. begin
  196. // Quantity
  197. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('Quantity'));
  198. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CurDealQuantity'));
  199. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CurQcQuantity'));
  200. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CurPcQuantity'));
  201. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CurGatherQuantity'));
  202. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('EndDealQuantity'));
  203. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('EndQcQuantity'));
  204. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('EndPcQuantity'));
  205. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('EndGahterQuantity'));
  206. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('AddDealQuantity'));
  207. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('AddQcQuantity'));
  208. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('AddPcQuantity'));
  209. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('AddGahterQuantity'));
  210. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('DealDgnQuantity1'));
  211. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('DealDgnQuantity2'));
  212. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CDgnQuantity1'));
  213. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CDgnQuantity2'));
  214. // TotalPrice
  215. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('TotalPrice'));
  216. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('CurDealTotalPrice'));
  217. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('CurQcTotalPrice'));
  218. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('CurPcTotalPrice'));
  219. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('CurGatherTotalPrice'));
  220. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('EndDealTotalPrice'));
  221. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('EndQcTotalPrice'));
  222. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('EndPcTotalPrice'));
  223. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('EndGahterTotalPrice'));
  224. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('AddDealTotalPrice'));
  225. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('AddQcTotalPrice'));
  226. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('AddPcTotalPrice'));
  227. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('AddGahterTotalPrice'));
  228. // Price
  229. FCommon.Price.AddLinkViewCol(Columns.FindColumn('Price'));
  230. FCommon.Price.AddLinkViewCol(Columns.FindColumn('NewPrice'));
  231. end;
  232. end;
  233. procedure ResetCompileLink;
  234. begin
  235. // TODO
  236. end;
  237. begin
  238. //ResetCommonLink;
  239. //ResetCompileLink;
  240. FPriceMargin.ResetLinkViewColumns(FProjectData);
  241. end;
  242. end.