CalcDecimal.pas 8.0 KB

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