CalcDecimal.pas 7.2 KB

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