CalcDecimal.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. FRelaDecimal: TDecimal;
  12. procedure SetDigit(const Value: Integer);
  13. function GetDisplayFormat(ADigit: Integer): string;
  14. procedure SetRelaDecimal(const Value: TDecimal);
  15. public
  16. constructor Create;
  17. destructor Destroy; override;
  18. function RoundTo(AValue: Double): Double;
  19. function StrRoundTo(const AValue: string): string;
  20. procedure ClearLinkViewCols;
  21. procedure AddLinkViewCol(ACol: TObject);
  22. procedure RefreshLinkViewColsFormat;
  23. property Digit: Integer read FDigit write SetDigit;
  24. property Format: string read FFormat;
  25. property RelaDecimal: TDecimal read FRelaDecimal write SetRelaDecimal;
  26. end;
  27. TCalcDecimal = class
  28. private
  29. FQuantity: TDecimal;
  30. FTotalPrice: TDecimal;
  31. FPrice: TDecimal;
  32. FRelaCalcDecimal: TCalcDecimal;
  33. procedure SetRelaCalcDecimal(const Value: TCalcDecimal);
  34. public
  35. constructor Create;
  36. destructor Destroy; override;
  37. procedure RefreshLinkViewColumnsFormat;
  38. property Quantity: TDecimal read FQuantity;
  39. property TotalPrice: TDecimal read FTotalPrice;
  40. property Price: TDecimal read FPrice;
  41. property RelaCalcDecimal: TCalcDecimal read FRelaCalcDecimal write SetRelaCalcDecimal;
  42. end;
  43. TDecimalManager = class
  44. private
  45. FProjectData: TObject;
  46. FCommon: TCalcDecimal;
  47. FCompile: TCalcDecimal;
  48. FPriceMargin: TCalcDecimal;
  49. FDealPay: TCalcDecimal;
  50. public
  51. constructor Create(AProjectData: TObject);
  52. destructor Destroy; override;
  53. procedure ResetLinkViewColumns;
  54. property Common: TCalcDecimal read FCommon;
  55. property Compile: TCalcDecimal read FCompile;
  56. property PriceMargin: TCalcDecimal read FPriceMargin;
  57. property DealPay: TCalcDecimal read FDealPay;
  58. end;
  59. implementation
  60. uses
  61. ProjectData, UtilMethods, SysUtils;
  62. { TDecimal }
  63. procedure TDecimal.AddLinkViewCol(ACol: TObject);
  64. begin
  65. FLinkViewCols.Add(ACol);
  66. end;
  67. procedure TDecimal.ClearLinkViewCols;
  68. begin
  69. FLinkViewCols.Clear;
  70. end;
  71. constructor TDecimal.Create;
  72. begin
  73. FLinkViewCols := TList.Create;
  74. FDigit := -1;
  75. end;
  76. destructor TDecimal.Destroy;
  77. begin
  78. FLinkViewCols.Free;
  79. inherited;
  80. end;
  81. function TDecimal.GetDisplayFormat(ADigit: Integer): string;
  82. begin
  83. case ADigit of
  84. 0: Result := '0';
  85. 1: Result := '0.#';
  86. 2: Result := '0.##';
  87. 3: Result := '0.###';
  88. 4: Result := '0.####';
  89. 5: Result := '0.#####';
  90. 6: Result := '0.######';
  91. 7: Result := '0.#######';
  92. 8: Result := '0.########';
  93. 9: Result := '0.#########';
  94. else
  95. Result := '0.##########';
  96. end;
  97. end;
  98. procedure TDecimal.RefreshLinkViewColsFormat;
  99. var
  100. i: Integer;
  101. ViewCol: TsdViewColumn;
  102. begin
  103. for i := 0 to FLinkViewCols.Count - 1 do
  104. begin
  105. ViewCol := TsdViewColumn(FLinkViewCols.Items[i]);
  106. if not Assigned(ViewCol) then Continue;
  107. if Assigned(RelaDecimal) then
  108. begin
  109. ViewCol.DisplayFormat := FRelaDecimal.FFormat;
  110. ViewCol.EditFormat := FRelaDecimal.FFormat;
  111. end
  112. else
  113. begin
  114. ViewCol.DisplayFormat := FFormat;
  115. ViewCol.EditFormat := FFormat;
  116. end;
  117. end;
  118. end;
  119. function TDecimal.RoundTo(AValue: Double): Double;
  120. begin
  121. if Assigned(RelaDecimal) then
  122. Result := FRelaDecimal.RoundTo(AValue)
  123. else
  124. Result := CommonRoundTo(AValue, -Digit);
  125. end;
  126. procedure TDecimal.SetDigit(const Value: Integer);
  127. begin
  128. if FDigit <> Value then
  129. begin
  130. FDigit := Value;
  131. FFormat := GetDisplayFormat(FDigit);
  132. RefreshLinkViewColsFormat;
  133. end;
  134. end;
  135. procedure TDecimal.SetRelaDecimal(const Value: TDecimal);
  136. begin
  137. FRelaDecimal := Value;
  138. RefreshLinkViewColsFormat;
  139. end;
  140. function TDecimal.StrRoundTo(const AValue: string): string;
  141. begin
  142. if Assigned(FRelaDecimal) then
  143. Result := RelaDecimal.StrRoundTo(AValue)
  144. else
  145. Result := FloatToStr(RoundTo(StrToFloatDef(AValue, 0)));
  146. end;
  147. { TCalcDecimal }
  148. constructor TCalcDecimal.Create;
  149. begin
  150. FQuantity := TDecimal.Create;
  151. FTotalPrice := TDecimal.Create;
  152. FPrice := TDecimal.Create;
  153. end;
  154. destructor TCalcDecimal.Destroy;
  155. begin
  156. FPrice.Free;
  157. FTotalPrice.Free;
  158. FQuantity.Free;
  159. inherited;
  160. end;
  161. procedure TCalcDecimal.RefreshLinkViewColumnsFormat;
  162. begin
  163. Quantity.RefreshLinkViewColsFormat;
  164. TotalPrice.RefreshLinkViewColsFormat;
  165. Price.RefreshLinkViewColsFormat;
  166. end;
  167. procedure TCalcDecimal.SetRelaCalcDecimal(const Value: TCalcDecimal);
  168. begin
  169. FRelaCalcDecimal := Value;
  170. if Assigned(FRelaCalcDecimal) then
  171. begin
  172. Quantity.RelaDecimal := FRelaCalcDecimal.Quantity;
  173. TotalPrice.RelaDecimal := FRelaCalcDecimal.TotalPrice;
  174. Price.RelaDecimal := FRelaCalcDecimal.Price;
  175. end
  176. else
  177. begin
  178. Quantity.RelaDecimal := nil;
  179. TotalPrice.RelaDecimal := nil;
  180. Price.RelaDecimal := nil;
  181. end;
  182. end;
  183. { TDecimalManager }
  184. constructor TDecimalManager.Create(AProjectData: TObject);
  185. begin
  186. FProjectData := AProjectData;
  187. FCommon := TCalcDecimal.Create;
  188. FCompile := TCalcDecimal.Create;
  189. FPriceMargin := TCalcDecimal.Create;
  190. FDealPay := TCalcDecimal.Create;
  191. end;
  192. destructor TDecimalManager.Destroy;
  193. begin
  194. FDealPay.Free;
  195. FPriceMargin.Free;
  196. FCompile.Free;
  197. FCommon.Free;
  198. inherited;
  199. end;
  200. procedure TDecimalManager.ResetLinkViewColumns;
  201. procedure ResetCommonLink;
  202. begin
  203. FCommon.Quantity.ClearLinkViewCols;
  204. FCommon.TotalPrice.ClearLinkViewCols;
  205. FCommon.Price.ClearLinkViewCols;
  206. with TProjectData(FProjectData).BillsCompileData.sdvBillsCompile do
  207. begin
  208. // Quantity
  209. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('OrgQuantity'));
  210. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('MisQuantity'));
  211. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('OthQuantity'));
  212. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('Quantity'));
  213. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('DgnQuantity1'));
  214. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('DgnQuantity2'));
  215. // TotalPrice
  216. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('OrgTotalPrice'));
  217. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('MisTotalPrice'));
  218. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('OthTotalPrice'));
  219. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('TotalPrice'));
  220. // Price
  221. FCommon.Price.AddLinkViewCol(Columns.FindColumn('Price'));
  222. FCommon.Price.AddLinkViewCol(Columns.FindColumn('NewPrice'));
  223. end;
  224. with TProjectData(FProjectData).BillsMeasureData.sdvBillsMeasure do
  225. begin
  226. // Quantity
  227. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('Quantity'));
  228. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CurDealQuantity'));
  229. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CurQcQuantity'));
  230. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CurPcQuantity'));
  231. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CurGatherQuantity'));
  232. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('EndDealQuantity'));
  233. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('EndQcQuantity'));
  234. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('EndPcQuantity'));
  235. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('EndGahterQuantity'));
  236. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('AddDealQuantity'));
  237. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('AddQcQuantity'));
  238. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('AddPcQuantity'));
  239. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('AddGahterQuantity'));
  240. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('DealDgnQuantity1'));
  241. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('DealDgnQuantity2'));
  242. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CDgnQuantity1'));
  243. FCommon.Quantity.AddLinkViewCol(Columns.FindColumn('CDgnQuantity2'));
  244. // TotalPrice
  245. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('TotalPrice'));
  246. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('CurDealTotalPrice'));
  247. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('CurQcTotalPrice'));
  248. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('CurPcTotalPrice'));
  249. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('CurGatherTotalPrice'));
  250. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('EndDealTotalPrice'));
  251. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('EndQcTotalPrice'));
  252. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('EndPcTotalPrice'));
  253. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('EndGahterTotalPrice'));
  254. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('AddDealTotalPrice'));
  255. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('AddQcTotalPrice'));
  256. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('AddPcTotalPrice'));
  257. FCommon.TotalPrice.AddLinkViewCol(Columns.FindColumn('AddGahterTotalPrice'));
  258. // Price
  259. FCommon.Price.AddLinkViewCol(Columns.FindColumn('Price'));
  260. FCommon.Price.AddLinkViewCol(Columns.FindColumn('NewPrice'));
  261. end;
  262. end;
  263. procedure ResetComplieLink;
  264. begin
  265. end;
  266. procedure ResetPriceMarginLink;
  267. begin
  268. FPriceMargin.Price.ClearLinkViewCols;
  269. with TProjectData(FProjectData).ProjectGLData.sdvProjectGL do
  270. begin
  271. FPriceMargin.Price.AddLinkViewCol(Columns.FindColumn('BasePrice'));
  272. FPriceMargin.Price.AddLinkViewCol(Columns.FindColumn('InfoPrice'));
  273. FPriceMargin.Price.AddLinkViewCol(Columns.FindColumn('DeltaPrice'));
  274. FPriceMargin.Price.AddLinkViewCol(Columns.FindColumn('ValidDeltaPrice'));
  275. FPriceMargin.Quantity.AddLinkViewCol(Columns.FindColumn('PM_Quantity'));
  276. FPriceMargin.Quantity.AddLinkViewCol(Columns.FindColumn('UsedQuantity'));
  277. FPriceMargin.Quantity.AddLinkViewCol(Columns.FindColumn('PAL_UsedQuantity'));
  278. FPriceMargin.TotalPrice.AddLinkViewCol(Columns.FindColumn('PM_TotalPrice'));
  279. FPriceMargin.TotalPrice.AddLinkViewCol(Columns.FindColumn('UsedTotalPrice'));
  280. FPriceMargin.TotalPrice.AddLinkViewCol(Columns.FindColumn('PAL_UsedTotalPrice'));
  281. FPriceMargin.TotalPrice.AddLinkViewCol(Columns.FindColumn('PAL_UsedTotalPrice'));
  282. FPriceMargin.TotalPrice.AddLinkViewCol(Columns.FindColumn('PAL_DeltaPrice'));
  283. FPriceMargin.TotalPrice.AddLinkViewCol(Columns.FindColumn('PAL_Total'));
  284. end;
  285. with TProjectData(FProjectData).ProjectGLData.sdvGather do
  286. begin
  287. FPriceMargin.TotalPrice.AddLinkViewCol(Columns.FindColumn('CurTotalPrice'));
  288. FPriceMargin.TotalPrice.AddLinkViewCol(Columns.FindColumn('PreTotalPrice'));
  289. FPriceMargin.TotalPrice.AddLinkViewCol(Columns.FindColumn('EndTotalPrice'));
  290. FPriceMargin.TotalPrice.AddLinkViewCol(Columns.FindColumn('AddTotalPrice'));
  291. end;
  292. with TProjectData(FProjectData).PriceMarginBillsData.sdvDetailGclBills do
  293. begin
  294. FPriceMargin.TotalPrice.AddLinkViewCol(Columns.FindColumn('PM_TotalPrice'));
  295. end;
  296. with TProjectData(FProjectData).PriceMarginBillsData.sdvDetailGL do
  297. begin
  298. FPriceMargin.Quantity.AddLinkViewCol(Columns.FindColumn('Quantity'));
  299. FPriceMargin.TotalPrice.AddLinkViewCol(Columns.FindColumn('PM_PreTotalPrice'));
  300. FPriceMargin.TotalPrice.AddLinkViewCol(Columns.FindColumn('PM_CurTotalPrice'));
  301. FPriceMargin.TotalPrice.AddLinkViewCol(Columns.FindColumn('PM_EndTotalPrice'));
  302. end;
  303. end;
  304. procedure ResetDealPayLink;
  305. begin
  306. with TProjectData(FProjectData).DealPaymentData.sdvDealPayment do
  307. begin
  308. FDealPay.TotalPrice.AddLinkViewCol(Columns.FindColumn('CurTotalPrice'));
  309. FDealPay.TotalPrice.AddLinkViewCol(Columns.FindColumn('TotalPrice'));
  310. FDealPay.TotalPrice.AddLinkViewCol(Columns.FindColumn('StartPrice'));
  311. FDealPay.TotalPrice.AddLinkViewCol(Columns.FindColumn('RangePrice'));
  312. end;
  313. end;
  314. begin
  315. {ResetCommonLink;
  316. FCommon.RefreshLinkViewColumnsFormat;
  317. ResetComplieLink;
  318. FCompile.RefreshLinkViewColumnsFormat;}
  319. ResetPriceMarginLink;
  320. FPriceMargin.RefreshLinkViewColumnsFormat;
  321. ResetDealPayLink;
  322. FDealPay.RefreshLinkViewColumnsFormat;
  323. end;
  324. end.