ColVisibleManager.pas 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. unit ColVisibleManager;
  2. interface
  3. uses
  4. Classes, sdGridDBA, ZhAPI;
  5. type
  6. TColVisible = class
  7. private
  8. FCustom: Boolean;
  9. // Defualt CaptionAcrossCols
  10. FDefaultCAC: Integer;
  11. FDBACol: TsdGridColumn;
  12. public
  13. constructor Create(ACol: TsdGridColumn); virtual;
  14. procedure RefreshVisible; virtual;
  15. property DBACol: TsdGridColumn read FDBACol;
  16. property DefaultCAC: Integer read FDefaultCAC;
  17. property Custom: Boolean read FCustom write FCustom;
  18. end;
  19. TBM_ColVisible = class(TColVisible)
  20. private
  21. FPriceChange: Boolean;
  22. FBGLCode: Boolean;
  23. FAlias: Boolean;
  24. FDesign: Boolean;
  25. public
  26. constructor Create(ACol: TsdGridColumn); override;
  27. procedure RefreshVisible; override;
  28. property PriceChange: Boolean read FPriceChange write FPriceChange;
  29. property BGLCode: Boolean read FBGLCode write FBGLCode;
  30. property Design: Boolean read FDesign write FDesign;
  31. property Alias: Boolean read FAlias write FAlias;
  32. end;
  33. TColVisibleManager = class
  34. private
  35. FColVisibles: TList;
  36. protected
  37. function CreateColVisible(ACol: TsdGridColumn): TColVisible; virtual;
  38. public
  39. constructor Create(ACols: TsdGridColumnList);
  40. destructor Destroy; override;
  41. procedure RefreshVisible;
  42. procedure ShowGridCol(AShow: Boolean; ABeginCol, AEndCol: Integer);
  43. end;
  44. TBM_ColVisibleManager = class(TColVisibleManager)
  45. protected
  46. function CreateColVisible(ACol: TsdGridColumn): TColVisible; override;
  47. public
  48. procedure ShowPriceChange(AShow: Boolean);
  49. procedure ShowBGLCode(AShow: Boolean);
  50. procedure ShowDesign(AShow: Boolean);
  51. procedure ShowAlias(AShow: Boolean);
  52. end;
  53. implementation
  54. uses SysUtils;
  55. { TColVisible }
  56. constructor TColVisible.Create(ACol: TsdGridColumn);
  57. begin
  58. FDBACol := ACol;
  59. FDefaultCAC := StrToIntDef(FDBACol.Title.CaptionAcrossCols, 1);
  60. FCustom := FDBACol.Visible;
  61. end;
  62. procedure TColVisible.RefreshVisible;
  63. begin
  64. FDBACol.Visible := FCustom;
  65. end;
  66. { TBM_ColVisible }
  67. constructor TBM_ColVisible.Create(ACol: TsdGridColumn);
  68. begin
  69. inherited;
  70. FPriceChange := True;
  71. FBGLCode := True;
  72. FDesign := True;
  73. FAlias := True;
  74. end;
  75. procedure TBM_ColVisible.RefreshVisible;
  76. begin
  77. FDBACol.Visible := FCustom and FPriceChange and FBGLCode and FDesign and FAlias;
  78. end;
  79. { TColVisibleManager }
  80. constructor TColVisibleManager.Create(ACols: TsdGridColumnList);
  81. var
  82. iCol: Integer;
  83. ColVisible: TColVisible;
  84. begin
  85. FColVisibles := TList.Create;
  86. for iCol := 0 to ACols.Count - 1 do
  87. begin
  88. ColVisible := CreateColVisible(ACols.Items[iCol]);
  89. FColVisibles.Add(ColVisible);
  90. end;
  91. end;
  92. function TColVisibleManager.CreateColVisible(
  93. ACol: TsdGridColumn): TColVisible;
  94. begin
  95. Result := TColVisible.Create(ACol);
  96. end;
  97. destructor TColVisibleManager.Destroy;
  98. begin
  99. ClearObjects(FColVisibles);
  100. FColVisibles.Free;
  101. inherited;
  102. end;
  103. procedure TColVisibleManager.RefreshVisible;
  104. var
  105. iCol: Integer;
  106. begin
  107. for iCol := 0 to FColVisibles.Count - 1 do
  108. TColVisible(FColVisibles.Items[iCol]).RefreshVisible;
  109. end;
  110. procedure TColVisibleManager.ShowGridCol(AShow: Boolean; ABeginCol,
  111. AEndCol: Integer);
  112. var
  113. iCol, iRelaCol: Integer;
  114. vCol, vRelaCol: TColVisible;
  115. begin
  116. for iCol := ABeginCol to AEndCol do
  117. begin
  118. vCol := TColVisible(FColVisibles.Items[iCol]);
  119. if Pos('|', vCol.DBACol.Title.Caption) <> 1 then
  120. begin
  121. vCol.Custom := AShow;
  122. if vCol.DefaultCAC > 1 then
  123. begin
  124. for iRelaCol := 1 to vCol.DefaultCAC - 1 do
  125. begin
  126. vRelaCol := TColVisible(FColVisibles.Items[iCol+iRelaCol]);
  127. vRelaCol.Custom := AShow;
  128. end;
  129. end;
  130. end;
  131. end;
  132. RefreshVisible;
  133. end;
  134. { TBM_ColVisibleManager }
  135. function TBM_ColVisibleManager.CreateColVisible(
  136. ACol: TsdGridColumn): TColVisible;
  137. begin
  138. Result := TBM_ColVisible.Create(ACol);
  139. end;
  140. procedure TBM_ColVisibleManager.ShowAlias(AShow: Boolean);
  141. var
  142. iCol: Integer;
  143. vCol: TBM_ColVisible;
  144. begin
  145. for iCol := 0 to FColVisibles.Count - 1 do
  146. begin
  147. vCol := TBM_ColVisible(FColVisibles.Items[iCol]);
  148. if SameText('Alias', vCol.DBACol.FieldName) then
  149. vCol.FAlias := AShow;
  150. end;
  151. RefreshVisible;
  152. end;
  153. procedure TBM_ColVisibleManager.ShowBGLCode(AShow: Boolean);
  154. var
  155. iCol: Integer;
  156. vCol: TBM_ColVisible;
  157. begin
  158. for iCol := 0 to FColVisibles.Count - 1 do
  159. begin
  160. vCol := TBM_ColVisible(FColVisibles.Items[iCol]);
  161. if SameText('CurQcQuantity', vCol.DBACol.FieldName) or
  162. SameText('CurPcQuantity', vCol.DBACol.FieldName) then
  163. begin
  164. if AShow then
  165. vCol.DBACol.Title.CaptionAcrossCols := '3'
  166. else
  167. vCol.DBACol.Title.CaptionAcrossCols := '2';
  168. end
  169. else if Pos('BGLCode', vCol.DBACol.FieldName) > 1 then
  170. vCol.FBGLCode := AShow;
  171. end;
  172. RefreshVisible;
  173. end;
  174. procedure TBM_ColVisibleManager.ShowDesign(AShow: Boolean);
  175. var
  176. iCol: Integer;
  177. vCol: TBM_ColVisible;
  178. begin
  179. for iCol := 0 to FColVisibles.Count - 1 do
  180. begin
  181. vCol := TBM_ColVisible(FColVisibles.Items[iCol]);
  182. if Pos('Dgn', vCol.DBACol.FieldName) > 1 then
  183. vCol.FDesign := AShow;
  184. end;
  185. RefreshVisible;
  186. end;
  187. procedure TBM_ColVisibleManager.ShowPriceChange(AShow: Boolean);
  188. var
  189. iCol: Integer;
  190. vCol: TBM_ColVisible;
  191. begin
  192. for iCol := 0 to FColVisibles.Count - 1 do
  193. begin
  194. vCol := TBM_ColVisible(FColVisibles.Items[iCol]);
  195. if SameText(vCol.DBACol.FieldName, 'NewPrice') or
  196. (Pos('CurPc', vCol.DBACol.FieldName) = 1) or
  197. (Pos('EndPc', vCol.DBACol.FieldName) = 1) or
  198. (Pos('AddPc', vCol.DBACol.FieldName) = 1) then
  199. vCol.PriceChange := AShow;
  200. end;
  201. RefreshVisible;
  202. end;
  203. end.