瀏覽代碼

计量台账,可选择隐藏(取消隐藏)部分列

MaiXinRong 9 年之前
父節點
當前提交
2b16344e61
共有 5 個文件被更改,包括 364 次插入42 次删除
  1. 28 16
      Forms/MainFrm.dfm
  2. 2 0
      Forms/MainFrm.pas
  3. 24 0
      Frames/BillsMeasureFme.dfm
  4. 74 26
      Frames/BillsMeasureFme.pas
  5. 236 0
      Units/ColVisibleManager.pas

+ 28 - 16
Forms/MainFrm.dfm

@@ -20,8 +20,8 @@ object MainForm: TMainForm
   TextHeight = 12
   object jtsProjects: TJimTabSet
     Left = 0
-    Top = 49
-    Width = 734
+    Top = 48
+    Width = 742
     Height = 21
     Align = alTop
     BackgroundColor = clGradientInactiveCaption
@@ -45,8 +45,8 @@ object MainForm: TMainForm
   end
   object dxStatusBar: TdxStatusBar
     Left = 0
-    Top = 480
-    Width = 734
+    Top = 484
+    Width = 742
     Height = 20
     Panels = <
       item
@@ -78,12 +78,12 @@ object MainForm: TMainForm
     object dxStatusBarContainer2: TdxStatusBarContainerControl
       Left = 604
       Top = 2
-      Width = 128
+      Width = 136
       Height = 16
       object ProgressBar: TProgressBar
         Left = 0
         Top = 0
-        Width = 128
+        Width = 136
         Height = 16
         Align = alClient
         Max = 200
@@ -93,9 +93,9 @@ object MainForm: TMainForm
   end
   object jpsMain: TJimPages
     Left = 0
-    Top = 70
-    Width = 734
-    Height = 410
+    Top = 69
+    Width = 742
+    Height = 415
     ActivePage = jpsMainProjectsManager
     ActivePageIndex = 0
     Align = alClient
@@ -103,8 +103,8 @@ object MainForm: TMainForm
     object jpsMainProjectsManager: TJimPage
       Left = 0
       Top = 0
-      Width = 734
-      Height = 410
+      Width = 742
+      Height = 415
       TabName = 'ProjectsManager'
       Caption = 'ProjsMgr'
       object pnlUser: TPanel
@@ -201,8 +201,8 @@ object MainForm: TMainForm
     object jpsMainProjects: TJimPage
       Left = 0
       Top = 0
-      Width = 734
-      Height = 410
+      Width = 742
+      Height = 415
       TabName = 'Projects'
       Caption = 'Projects'
       object jpsProjects: TJimPages
@@ -220,7 +220,7 @@ object MainForm: TMainForm
     Font.Charset = DEFAULT_CHARSET
     Font.Color = clWindowText
     Font.Height = -12
-    Font.Name = #24494#36719#38597#40657
+    Font.Name = #23435#20307
     Font.Style = []
     Bars = <
       item
@@ -270,7 +270,7 @@ object MainForm: TMainForm
         Caption = #24037#20855#26639
         DockedDockingStyle = dsTop
         DockedLeft = 0
-        DockedTop = 27
+        DockedTop = 26
         DockingStyle = dsTop
         FloatLeft = 484
         FloatTop = 279
@@ -379,7 +379,7 @@ object MainForm: TMainForm
     DockControlHeights = (
       0
       0
-      49
+      48
       0)
     object dxsiFile: TdxBarSubItem
       Caption = #25991#20214'(&F)'
@@ -1039,6 +1039,18 @@ object MainForm: TMainForm
       Hint = #26032#22686#19968#21015
       Visible = ivAlways
     end
+    object dxbtnHidden: TdxBarButton
+      Caption = #38544#34255
+      Category = 0
+      Hint = #38544#34255
+      Visible = ivAlways
+    end
+    object dxbtnCancelHidden: TdxBarButton
+      Caption = #21462#28040#38544#34255
+      Category = 0
+      Hint = #21462#28040#38544#34255
+      Visible = ivAlways
+    end
   end
   object Images: TImageList
     DrawingStyle = dsTransparent

+ 2 - 0
Forms/MainFrm.pas

@@ -154,6 +154,8 @@ type
     dxbtnFxZJJL: TdxBarButton;
     dxbtnGclZJJL: TdxBarButton;
     dxbtnInsertCol: TdxBarButton;
+    dxbtnHidden: TdxBarButton;
+    dxbtnCancelHidden: TdxBarButton;
     procedure FormCreate(Sender: TObject);
     procedure FormDestroy(Sender: TObject);
     procedure jtsProjectsChange(Sender: TObject; NewTab: Integer;

+ 24 - 0
Frames/BillsMeasureFme.dfm

@@ -1101,5 +1101,29 @@ object BillsMeasureFrame: TBillsMeasureFrame
       OnExecute = actnSetStageBookmarkExecute
       OnUpdate = actnSetStageBookmarkUpdate
     end
+    object actnHiddenCol: TAction
+      Caption = #38544#34255
+      OnExecute = actnHiddenColExecute
+    end
+    object actnCancelHiddenCol: TAction
+      Caption = #21462#28040#38544#34255
+      OnExecute = actnCancelHiddenColExecute
+    end
+  end
+  object dxpmBillsCol: TdxBarPopupMenu
+    BarManager = MainForm.dxBarManager
+    ItemLinks = <
+      item
+        Item = MainForm.dxbtnHidden
+        Visible = True
+      end
+      item
+        Item = MainForm.dxbtnCancelHidden
+        Visible = True
+      end>
+    UseOwnFont = False
+    OnPopup = dxpmBillsColPopup
+    Left = 232
+    Top = 120
   end
 end

+ 74 - 26
Frames/BillsMeasureFme.pas

@@ -4,6 +4,7 @@ interface
 
 uses
   BillsMeasureDm, UtilMethods, BillsClipboard, sdIDTreeCells,
+  ColVisibleManager,
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, ZJGrid, ComCtrls, ToolWin, StdCtrls, ExtCtrls, sdGridDBA,
   sdGridTreeDBA, sdDB, ActnList, dxBar, sdIDTree, JimLabels;
@@ -24,6 +25,9 @@ type
     pnlDealProperty: TPanel;
     labDealPropertyTitle: TJimGradLabel;
     zgDealProperty: TZJGrid;
+    dxpmBillsCol: TdxBarPopupMenu;
+    actnHiddenCol: TAction;
+    actnCancelHiddenCol: TAction;
     procedure dxpmBillsPopup(Sender: TObject);
     procedure zgBillsMeasureMouseDown(Sender: TObject; Button: TMouseButton;
       Shift: TShiftState; X, Y: Integer);
@@ -50,6 +54,9 @@ type
     procedure zgDealPropertyCellCanEdit(Sender: TObject;
       const ACoord: TPoint; var Allow: Boolean);
     procedure actnSetStageBookmarkUpdate(Sender: TObject);
+    procedure dxpmBillsColPopup(Sender: TObject);
+    procedure actnHiddenColExecute(Sender: TObject);
+    procedure actnCancelHiddenColExecute(Sender: TObject);
   private
     FBillsMeasureData: TBillsMeasureData;
     FShowPriceChange: Boolean;
@@ -60,8 +67,13 @@ type
     FOnAfterSetBookmark: TBookmarkRefreshEvent;
     FShowAlias: Boolean;
 
+    FColVisibleManager: TBM_ColVisibleManager;
+
     procedure ExpandMouseDown(AGridCell: TzjCell);
 
+    function GridColToDBACol(AGridCol: Integer): Integer;
+    procedure ShowGridCols(AShow: Boolean; ALeft, ARight: Integer);
+
     function CheckExprsColumn: Boolean;
 
     procedure SetColumnVisible(const AColumn: string; AVisible: Boolean);
@@ -106,7 +118,7 @@ implementation
 
 uses
   MainFrm, ProjectFme, ProjectData, ExportExcel, BGLDm, BGLSelectFrm,
-  Types, ZhAPI, BillsTree, mDataRecord;
+  Types, ZhAPI, BillsTree, mDataRecord, ConstUnit;
 
 { TBillsFrame }
 
@@ -117,10 +129,13 @@ begin
   FBillsMeasureData := ABillsMeasureData;
   stdBillsMeasure.IDTree := FBillsMeasureData.BillsMeasureTree;
   zgBillsMeasure.OnExpandMouseDown := ExpandMouseDown;
+
+  FColVisibleManager := TBM_ColVisibleManager.Create(stdBillsMeasure.Columns);
 end;
 
 destructor TBillsMeasureFrame.Destroy;
 begin
+  FColVisibleManager.Free;
   inherited;
 end;
 
@@ -138,7 +153,12 @@ var
   vViewCol: TsdViewColumn;
 begin
   if Button = mbRight then
-    dxpmBills.PopupFromCursorPos
+  begin
+    if G_IsTest and (zgBillsMeasure.Selection.SelectType = stCol) and (Y < (zgBillsMeasure.RowHeights[0] + zgBillsMeasure.RowHeights[1])) then
+      dxpmBillsCol.PopupFromCursorPos
+    else
+      dxpmBills.PopupFromCursorPos;
+  end
   else
   begin
     if CheckExprsColumn then
@@ -153,14 +173,7 @@ end;
 procedure TBillsMeasureFrame.SetShowPriceChange(const Value: Boolean);
 begin
   FShowPriceChange := Value;
-  stdBillsMeasure.Column('NewPrice').Visible := FShowPriceChange;
-  stdBillsMeasure.Column('CurPcQuantity').Visible := FShowPriceChange;
-  stdBillsMeasure.Column('CurPcTotalPrice').Visible := FShowPriceChange;
-  stdBillsMeasure.Column('CurPcBGLCode').Visible := FShowBGLCode and FShowPriceChange;
-  stdBillsMeasure.Column('EndPcQuantity').Visible := FShowPriceChange;
-  stdBillsMeasure.Column('EndPcTotalPrice').Visible := FShowPriceChange;
-  stdBillsMeasure.Column('AddPcQuantity').Visible := FShowPriceChange;
-  stdBillsMeasure.Column('AddPcTotalPrice').Visible := FShowPriceChange;
+  FColVisibleManager.ShowPriceChange(FShowPriceChange);
 end;
 
 procedure TBillsMeasureFrame.laEdtExprsKeyDown(Sender: TObject; var Key: Word;
@@ -249,16 +262,7 @@ end;
 procedure TBillsMeasureFrame.SetShowBGLCode(const Value: Boolean);
 begin
   FShowBGLCode := Value;
-  if FShowBGLCode then
-    stdBillsMeasure.Column('CurQcQuantity').Title.CaptionAcrossCols := '3'
-  else
-    stdBillsMeasure.Column('CurQcQuantity').Title.CaptionAcrossCols := '2';
-  stdBillsMeasure.Column('CurQcBGLCode').Visible := FShowBGLCode;
-  if FShowBGLCode then
-    stdBillsMeasure.Column('CurPcQuantity').Title.CaptionAcrossCols := '3'
-  else
-    stdBillsMeasure.Column('CurPcQuantity').Title.CaptionAcrossCols := '2';
-  stdBillsMeasure.Column('CurPcBGLCode').Visible := FShowBGLCode and FShowPriceChange;
+  FColVisibleManager.ShowBGLCode(FShowBGLCode);
 end;
 
 procedure TBillsMeasureFrame.actnExportGridToExcelExecute(Sender: TObject);
@@ -382,11 +386,7 @@ end;
 procedure TBillsMeasureFrame.SetShowDesignQuantity(const Value: Boolean);
 begin
   FShowDesignQuantity := Value;
-  stdBillsMeasure.Column('DealDgnQuantity1').Visible := FShowDesignQuantity;
-  stdBillsMeasure.Column('DealDgnQuantity2').Visible := FShowDesignQuantity;
-  stdBillsMeasure.Column('CDgnQuantity1').Visible := FShowDesignQuantity;
-  stdBillsMeasure.Column('CDgnQuantity2').Visible := FShowDesignQuantity;
-  stdBillsMeasure.Column('AddDgnPrice').Visible := FShowDesignQuantity;
+  FColVisibleManager.ShowDesign(FShowDesignQuantity);
 end;
 
 procedure TBillsMeasureFrame.SetAddFieldVisible(AValue: Boolean);
@@ -559,7 +559,7 @@ end;
 procedure TBillsMeasureFrame.SetShowAlias(const Value: Boolean);
 begin
   FShowAlias := Value;
-  stdBillsMeasure.Column('Alias').Visible := FShowAlias;
+  FColVisibleManager.ShowAlias(FShowAlias);
 end;
 
 procedure TBillsMeasureFrame.actnSetStageBookmarkUpdate(Sender: TObject);
@@ -691,4 +691,52 @@ begin
     CommonExpand(stnNode);
 end;
 
+procedure TBillsMeasureFrame.dxpmBillsColPopup(Sender: TObject);
+begin
+  SetDxBtnAction(actnHiddenCol, MainForm.dxbtnHidden);
+  SetDxBtnAction(actnCancelHiddenCol, MainForm.dxbtnCancelHidden);
+end;
+
+procedure TBillsMeasureFrame.actnHiddenColExecute(Sender: TObject);
+begin
+  ShowGridCols(False, zgBillsMeasure.Selection.Left, zgBillsMeasure.Selection.Right-1);
+end;
+
+function TBillsMeasureFrame.GridColToDBACol(AGridCol: Integer): Integer;
+var
+  iCol, iVisibleCount: Integer;
+begin
+  Result := -1;
+  if AGridCol > stdBillsMeasure.VisibleColCount then Exit;
+
+  iVisibleCount := 0;
+  for iCol := 0 to stdBillsMeasure.Columns.Count - 1 do
+  begin
+    if stdBillsMeasure.Columns.Items[iCol].Visible then
+    begin
+      Inc(iVisibleCount);
+      if iVisibleCount = AGridCol then
+      begin
+        Result := iCol;
+        Break;
+      end;
+    end;
+  end;
+end;
+
+procedure TBillsMeasureFrame.actnCancelHiddenColExecute(Sender: TObject);
+begin
+  ShowGridCols(True, zgBillsMeasure.Selection.Left, zgBillsMeasure.Selection.Right-1);
+end;
+
+procedure TBillsMeasureFrame.ShowGridCols(AShow: Boolean; ALeft,
+  ARight: Integer);
+var
+  iCol, iBegin, iEnd: Integer;
+begin
+  iBegin := GridColToDBACol(ALeft);
+  iEnd := GridColToDBACol(ARight);
+  FColVisibleManager.ShowGridCol(AShow, iBegin, iEnd);
+end;
+
 end.

+ 236 - 0
Units/ColVisibleManager.pas

@@ -0,0 +1,236 @@
+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.