CalcDecimal.pas 12 KB

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