ColVisibleManager.pas 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. unit ColVisibleManager;
  2. interface
  3. uses
  4. Classes, sdGridDBA, ZhAPI, sdGridTreeDBA;
  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. FApprovalCode: Boolean;
  26. FIsGatherZJJL: Boolean;
  27. function GetVisible: Boolean;
  28. public
  29. constructor Create(ACol: TsdGridColumn); override;
  30. procedure RefreshVisible; override;
  31. property PriceChange: Boolean read FPriceChange write FPriceChange;
  32. property BGLCode: Boolean read FBGLCode write FBGLCode;
  33. property Design: Boolean read FDesign write FDesign;
  34. property Alias: Boolean read FAlias write FAlias;
  35. property ApprovalCode: Boolean read FApprovalCode write FApprovalCode;
  36. property IsGatherZJJL: Boolean read FIsGatherZJJL write FIsGatherZJJL;
  37. property Visible: Boolean read GetVisible;
  38. end;
  39. TColVisibleManager = class
  40. private
  41. FColVisibles: TList;
  42. function GetColVisible(AIndex: Integer): TColVisible;
  43. protected
  44. function CreateColVisible(ACol: TsdGridColumn): TColVisible; virtual;
  45. public
  46. constructor Create(ACols: TsdGridColumnList);
  47. destructor Destroy; override;
  48. procedure RefreshVisible; virtual;
  49. procedure ShowGridCol(AShow: Boolean; ABeginCol, AEndCol: Integer);
  50. property ColVisible[AIndex: Integer]: TColVisible read GetColVisible;
  51. end;
  52. TBM_ColVisibleManager = class(TColVisibleManager)
  53. private
  54. FGridFixedColCount: Integer;
  55. FOrgTreeCol: Integer;
  56. FGridTreeDBA: TsdGridTreeDBA;
  57. protected
  58. function CreateColVisible(ACol: TsdGridColumn): TColVisible; override;
  59. public
  60. constructor Create(AGridTreeDBA: TsdGridTreeDBA);
  61. procedure ShowPriceChange(AShow: Boolean);
  62. procedure ShowBGLCode(AShow: Boolean);
  63. procedure ShowDesign(AShow: Boolean);
  64. procedure ShowAlias(AShow: Boolean);
  65. procedure ShowApprovalCode(AShow: Boolean);
  66. procedure ShowIsGather(AShow: Boolean);
  67. procedure RefreshVisible; override;
  68. property GridTreeDBA: TsdGridTreeDBA read FGridTreeDBA;
  69. end;
  70. implementation
  71. uses SysUtils, ZJGrid;
  72. { TColVisible }
  73. constructor TColVisible.Create(ACol: TsdGridColumn);
  74. begin
  75. FDBACol := ACol;
  76. FDefaultCAC := StrToIntDef(FDBACol.Title.CaptionAcrossCols, 1);
  77. FCustom := FDBACol.Visible;
  78. end;
  79. procedure TColVisible.RefreshVisible;
  80. begin
  81. FDBACol.Visible := FCustom;
  82. end;
  83. { TBM_ColVisible }
  84. constructor TBM_ColVisible.Create(ACol: TsdGridColumn);
  85. begin
  86. inherited;
  87. FPriceChange := True;
  88. FBGLCode := True;
  89. FDesign := True;
  90. FAlias := True;
  91. FApprovalCode := True;
  92. FIsGatherZJJL := True;
  93. end;
  94. function TBM_ColVisible.GetVisible: Boolean;
  95. begin
  96. Result := FCustom and FPriceChange and FBGLCode and FDesign and FAlias and FApprovalCode and FIsGatherZJJL;
  97. end;
  98. procedure TBM_ColVisible.RefreshVisible;
  99. begin
  100. FDBACol.Visible := FCustom and FPriceChange and FBGLCode and FDesign and FAlias and FApprovalCode and FIsGatherZJJL;
  101. end;
  102. { TColVisibleManager }
  103. constructor TColVisibleManager.Create(ACols: TsdGridColumnList);
  104. var
  105. iCol: Integer;
  106. ColVisible: TColVisible;
  107. begin
  108. FColVisibles := TList.Create;
  109. for iCol := 0 to ACols.Count - 1 do
  110. begin
  111. ColVisible := CreateColVisible(ACols.Items[iCol]);
  112. FColVisibles.Add(ColVisible);
  113. end;
  114. end;
  115. function TColVisibleManager.CreateColVisible(
  116. ACol: TsdGridColumn): TColVisible;
  117. begin
  118. Result := TColVisible.Create(ACol);
  119. end;
  120. destructor TColVisibleManager.Destroy;
  121. begin
  122. ClearObjects(FColVisibles);
  123. FColVisibles.Free;
  124. inherited;
  125. end;
  126. function TColVisibleManager.GetColVisible(AIndex: Integer): TColVisible;
  127. begin
  128. Result := TColVisible(FColVisibles[AIndex]);
  129. end;
  130. procedure TColVisibleManager.RefreshVisible;
  131. var
  132. iCol: Integer;
  133. begin
  134. for iCol := 0 to FColVisibles.Count - 1 do
  135. TColVisible(FColVisibles.Items[iCol]).RefreshVisible;
  136. end;
  137. procedure TColVisibleManager.ShowGridCol(AShow: Boolean; ABeginCol,
  138. AEndCol: Integer);
  139. var
  140. iCol, iRelaCol: Integer;
  141. vCol, vRelaCol: TColVisible;
  142. begin
  143. for iCol := ABeginCol to AEndCol do
  144. begin
  145. vCol := TColVisible(FColVisibles.Items[iCol]);
  146. if Pos('|', vCol.DBACol.Title.Caption) <> 1 then
  147. begin
  148. vCol.Custom := AShow;
  149. if vCol.DefaultCAC > 1 then
  150. begin
  151. for iRelaCol := 1 to vCol.DefaultCAC - 1 do
  152. begin
  153. vRelaCol := TColVisible(FColVisibles.Items[iCol+iRelaCol]);
  154. vRelaCol.Custom := AShow;
  155. end;
  156. end;
  157. end;
  158. end;
  159. RefreshVisible;
  160. end;
  161. { TBM_ColVisibleManager }
  162. constructor TBM_ColVisibleManager.Create(AGridTreeDBA: TsdGridTreeDBA);
  163. begin
  164. inherited Create(AGridTreeDBA.Columns);
  165. FGridTreeDBA := AGridTreeDBA;
  166. FOrgTreeCol := AGridTreeDBA.TreeCellCol;
  167. if Assigned(AGridTreeDBA.Grid) then
  168. FGridFixedColCount := AGridTreeDBA.Grid.FixedColCount
  169. else
  170. FGridFixedColCount := 1;
  171. end;
  172. function TBM_ColVisibleManager.CreateColVisible(
  173. ACol: TsdGridColumn): TColVisible;
  174. begin
  175. Result := TBM_ColVisible.Create(ACol);
  176. end;
  177. procedure TBM_ColVisibleManager.RefreshVisible;
  178. var
  179. i, iCount: Integer;
  180. vGrid: TZJGrid;
  181. begin
  182. (*
  183. iCount := 0;
  184. for i := 0 to FOrgTreeCol - FGridFixedColCount do
  185. begin
  186. if TBM_ColVisible(ColVisible[i]).Visible then
  187. Inc(iCount);
  188. end;
  189. FGridTreeDBA.TreeCellCol := FGridFixedColCount + iCount - 1;
  190. *)
  191. inherited;
  192. iCount := 0;
  193. for i := 0 to FOrgTreeCol - FGridFixedColCount do
  194. begin
  195. if TBM_ColVisible(ColVisible[i]).Visible then
  196. Inc(iCount);
  197. end;
  198. if FGridTreeDBA.TreeCellCol <> FGridFixedColCount + iCount - 1 then
  199. begin
  200. vGrid := FGridTreeDBA.Grid;
  201. FGridTreeDBA.Grid := nil;
  202. vGrid.BeginUpdate;
  203. vGrid.CellClass.Cols[FGridTreeDBA.TreeCellCol] := vGrid.CellClass.DefaultCellClass;
  204. FGridTreeDBA.TreeCellCol := FGridFixedColCount + iCount - 1;
  205. FGridTreeDBA.Grid := vGrid;
  206. vGrid.EndUpdate;
  207. end;
  208. end;
  209. procedure TBM_ColVisibleManager.ShowAlias(AShow: Boolean);
  210. var
  211. iCol: Integer;
  212. vCol: TBM_ColVisible;
  213. begin
  214. for iCol := 0 to FColVisibles.Count - 1 do
  215. begin
  216. vCol := TBM_ColVisible(FColVisibles.Items[iCol]);
  217. if SameText('Alias', vCol.DBACol.FieldName) then
  218. vCol.FAlias := AShow;
  219. end;
  220. RefreshVisible;
  221. end;
  222. procedure TBM_ColVisibleManager.ShowApprovalCode(AShow: Boolean);
  223. var
  224. iCol: Integer;
  225. vCol: TBM_ColVisible;
  226. begin
  227. for iCol := 0 to FColVisibles.Count - 1 do
  228. begin
  229. vCol := TBM_ColVisible(FColVisibles.Items[iCol]);
  230. if SameText('ApprovalCode', vCol.DBACol.FieldName) then
  231. vCol.FApprovalCode := AShow;
  232. end;
  233. RefreshVisible;
  234. end;
  235. procedure TBM_ColVisibleManager.ShowBGLCode(AShow: Boolean);
  236. var
  237. iCol: Integer;
  238. vCol: TBM_ColVisible;
  239. begin
  240. for iCol := 0 to FColVisibles.Count - 1 do
  241. begin
  242. vCol := TBM_ColVisible(FColVisibles.Items[iCol]);
  243. if SameText('CurQcQuantity', vCol.DBACol.FieldName) or
  244. SameText('CurPcQuantity', vCol.DBACol.FieldName) then
  245. begin
  246. if AShow then
  247. vCol.DBACol.Title.CaptionAcrossCols := '3'
  248. else
  249. vCol.DBACol.Title.CaptionAcrossCols := '2';
  250. end
  251. else if Pos('BGLCode', vCol.DBACol.FieldName) > 1 then
  252. vCol.FBGLCode := AShow;
  253. end;
  254. RefreshVisible;
  255. end;
  256. procedure TBM_ColVisibleManager.ShowDesign(AShow: Boolean);
  257. var
  258. iCol: Integer;
  259. vCol: TBM_ColVisible;
  260. begin
  261. for iCol := 0 to FColVisibles.Count - 1 do
  262. begin
  263. vCol := TBM_ColVisible(FColVisibles.Items[iCol]);
  264. if Pos('Dgn', vCol.DBACol.FieldName) > 1 then
  265. vCol.FDesign := AShow;
  266. end;
  267. RefreshVisible;
  268. end;
  269. procedure TBM_ColVisibleManager.ShowIsGather(AShow: Boolean);
  270. var
  271. iCol: Integer;
  272. vCol: TBM_ColVisible;
  273. begin
  274. for iCol := 0 to FColVisibles.Count - 1 do
  275. begin
  276. vCol := TBM_ColVisible(FColVisibles.Items[iCol]);
  277. if SameText('IsGatherZJJL', vCol.DBACol.FieldName) then
  278. vCol.FIsGatherZJJL := AShow;
  279. end;
  280. RefreshVisible;
  281. end;
  282. procedure TBM_ColVisibleManager.ShowPriceChange(AShow: Boolean);
  283. var
  284. iCol: Integer;
  285. vCol: TBM_ColVisible;
  286. begin
  287. for iCol := 0 to FColVisibles.Count - 1 do
  288. begin
  289. vCol := TBM_ColVisible(FColVisibles.Items[iCol]);
  290. if SameText(vCol.DBACol.FieldName, 'NewPrice') or
  291. (Pos('CurPc', vCol.DBACol.FieldName) = 1) or
  292. (Pos('EndPc', vCol.DBACol.FieldName) = 1) or
  293. (Pos('AddPc', vCol.DBACol.FieldName) = 1) then
  294. vCol.PriceChange := AShow;
  295. end;
  296. RefreshVisible;
  297. end;
  298. end.