unit ColVisibleManager; interface uses Classes, sdGridDBA, ZhAPI; type TColVisible = class private FCustom: Boolean; // Defualt CaptionAcrossCols FDefaultCAC: Integer; FDBACol: TsdGridColumn; public constructor Create(ACol: TsdGridColumn); virtual; procedure RefreshVisible; virtual; property DBACol: TsdGridColumn read FDBACol; property DefaultCAC: Integer read FDefaultCAC; property Custom: Boolean read FCustom write FCustom; end; TBM_ColVisible = class(TColVisible) private FPriceChange: Boolean; FBGLCode: Boolean; FAlias: Boolean; FDesign: Boolean; public constructor Create(ACol: TsdGridColumn); override; procedure RefreshVisible; override; property PriceChange: Boolean read FPriceChange write FPriceChange; property BGLCode: Boolean read FBGLCode write FBGLCode; property Design: Boolean read FDesign write FDesign; property Alias: Boolean read FAlias write FAlias; end; TColVisibleManager = class private FColVisibles: TList; protected function CreateColVisible(ACol: TsdGridColumn): TColVisible; virtual; public constructor Create(ACols: TsdGridColumnList); destructor Destroy; override; procedure RefreshVisible; procedure ShowGridCol(AShow: Boolean; ABeginCol, AEndCol: Integer); end; TBM_ColVisibleManager = class(TColVisibleManager) protected function CreateColVisible(ACol: TsdGridColumn): TColVisible; override; public procedure ShowPriceChange(AShow: Boolean); procedure ShowBGLCode(AShow: Boolean); procedure ShowDesign(AShow: Boolean); procedure ShowAlias(AShow: Boolean); end; implementation uses SysUtils; { TColVisible } constructor TColVisible.Create(ACol: TsdGridColumn); begin FDBACol := ACol; FDefaultCAC := StrToIntDef(FDBACol.Title.CaptionAcrossCols, 1); FCustom := FDBACol.Visible; end; procedure TColVisible.RefreshVisible; begin FDBACol.Visible := FCustom; end; { TBM_ColVisible } constructor TBM_ColVisible.Create(ACol: TsdGridColumn); begin inherited; FPriceChange := True; FBGLCode := True; FDesign := True; FAlias := True; end; procedure TBM_ColVisible.RefreshVisible; begin FDBACol.Visible := FCustom and FPriceChange and FBGLCode and FDesign and FAlias; end; { TColVisibleManager } constructor TColVisibleManager.Create(ACols: TsdGridColumnList); var iCol: Integer; ColVisible: TColVisible; begin FColVisibles := TList.Create; for iCol := 0 to ACols.Count - 1 do begin ColVisible := CreateColVisible(ACols.Items[iCol]); FColVisibles.Add(ColVisible); end; end; function TColVisibleManager.CreateColVisible( ACol: TsdGridColumn): TColVisible; begin Result := TColVisible.Create(ACol); end; destructor TColVisibleManager.Destroy; begin ClearObjects(FColVisibles); FColVisibles.Free; inherited; end; procedure TColVisibleManager.RefreshVisible; var iCol: Integer; begin for iCol := 0 to FColVisibles.Count - 1 do TColVisible(FColVisibles.Items[iCol]).RefreshVisible; end; procedure TColVisibleManager.ShowGridCol(AShow: Boolean; ABeginCol, AEndCol: Integer); var iCol, iRelaCol: Integer; vCol, vRelaCol: TColVisible; begin for iCol := ABeginCol to AEndCol do begin vCol := TColVisible(FColVisibles.Items[iCol]); if Pos('|', vCol.DBACol.Title.Caption) <> 1 then begin vCol.Custom := AShow; if vCol.DefaultCAC > 1 then begin for iRelaCol := 1 to vCol.DefaultCAC - 1 do begin vRelaCol := TColVisible(FColVisibles.Items[iCol+iRelaCol]); vRelaCol.Custom := AShow; end; end; end; end; RefreshVisible; end; { TBM_ColVisibleManager } function TBM_ColVisibleManager.CreateColVisible( ACol: TsdGridColumn): TColVisible; begin Result := TBM_ColVisible.Create(ACol); end; procedure TBM_ColVisibleManager.ShowAlias(AShow: Boolean); var iCol: Integer; vCol: TBM_ColVisible; begin for iCol := 0 to FColVisibles.Count - 1 do begin vCol := TBM_ColVisible(FColVisibles.Items[iCol]); if SameText('Alias', vCol.DBACol.FieldName) then vCol.FAlias := AShow; end; RefreshVisible; end; procedure TBM_ColVisibleManager.ShowBGLCode(AShow: Boolean); var iCol: Integer; vCol: TBM_ColVisible; begin for iCol := 0 to FColVisibles.Count - 1 do begin vCol := TBM_ColVisible(FColVisibles.Items[iCol]); if SameText('CurQcQuantity', vCol.DBACol.FieldName) or SameText('CurPcQuantity', vCol.DBACol.FieldName) then begin if AShow then vCol.DBACol.Title.CaptionAcrossCols := '3' else vCol.DBACol.Title.CaptionAcrossCols := '2'; end else if Pos('BGLCode', vCol.DBACol.FieldName) > 1 then vCol.FBGLCode := AShow; end; RefreshVisible; end; procedure TBM_ColVisibleManager.ShowDesign(AShow: Boolean); var iCol: Integer; vCol: TBM_ColVisible; begin for iCol := 0 to FColVisibles.Count - 1 do begin vCol := TBM_ColVisible(FColVisibles.Items[iCol]); if Pos('Dgn', vCol.DBACol.FieldName) > 1 then vCol.FDesign := AShow; end; RefreshVisible; end; procedure TBM_ColVisibleManager.ShowPriceChange(AShow: Boolean); var iCol: Integer; vCol: TBM_ColVisible; begin for iCol := 0 to FColVisibles.Count - 1 do begin vCol := TBM_ColVisible(FColVisibles.Items[iCol]); if SameText(vCol.DBACol.FieldName, 'NewPrice') or (Pos('CurPc', vCol.DBACol.FieldName) = 1) or (Pos('EndPc', vCol.DBACol.FieldName) = 1) or (Pos('AddPc', vCol.DBACol.FieldName) = 1) then vCol.PriceChange := AShow; end; RefreshVisible; end; end.