⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cxdbvgrid.pas

📁 delphi的的三方控件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{********************************************************************}
{                                                                    }
{       Developer Express Visual Component Library                   }
{       ExpressVerticalGrid                                          }
{                                                                    }
{       Copyright (c) 1998-2007 Developer Express Inc.               }
{       ALL RIGHTS RESERVED                                          }
{                                                                    }
{   The entire contents of this file is protected by U.S. and        }
{   International Copyright Laws. Unauthorized reproduction,         }
{   reverse-engineering, and distribution of all or any portion of   }
{   the code contained in this file is strictly prohibited and may   }
{   result in severe civil and criminal penalties and will be        }
{   prosecuted to the maximum extent possible under the law.         }
{                                                                    }
{   RESTRICTIONS                                                     }
{                                                                    }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES            }
{   (DCU, OBJ, DLL, ETC.) ARE CONFIDENTIAL AND PROPRIETARY TRADE     }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS    }
{   LICENSED TO DISTRIBUTE THE EXPRESSVERTICALGRID AND ALL           }
{   ACCOMPANYING VCL CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY. }
{                                                                    }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED       }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE         }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE        }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT   }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                       }
{                                                                    }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON        }
{   ADDITIONAL RESTRICTIONS.                                         }
{                                                                    }
{********************************************************************}
unit cxDBVGrid;

{$I cxVer.inc}

interface

uses
  cxVGrid, cxInplaceContainer, Classes, DB, cxCustomData, cxDBData,
  cxDataStorage, cxEdit, cxDBEdit, cxEditRepositoryItems, cxDataUtils;

type
  TcxDBVerticalGrid = class;
  TcxDBCellEdit = class;

  { TcxDBVerticalGridDefaultValuesProvider }

  TcxDBVerticalGridDefaultValuesProvider = class(TcxCustomDBEditDefaultValuesProvider)
  public
    function IsDisplayFormatDefined(AIsCurrencyValueAccepted: Boolean): Boolean; override;
  end;

  { TcxDBVerticalGridDataController }

  TcxDBVerticalGridDataController = class(TcxDBDataController,
    IcxVerticalGridDBDataContoller)
  private
    FPrevBufferCount: Integer;
    FPrevScrollBarPos: Integer;
    function GetVerticalGrid: TcxDBVerticalGrid;
    function GetGridMode: Boolean;
    function GetGridModeBufferCount: Integer;
    function GetScroller: TcxvgScroller;
    procedure SetGridMode(Value: Boolean);
    procedure SetGridModeBufferCount(Value: Integer);
  protected
    // IcxVerticalGridDBDataContoller
    procedure CheckGridModeBufferCount;
    function DoScroll(AForward: Boolean): Boolean;
    function GetDataSetRecordCount: Integer;
    function GetScrollBarPos: Integer;
    function GetScrollBarRecordCount: Integer;
    function SetScrollBarPos(APos: Integer): Boolean;

    function GetDefaultGridModeBufferCount: Integer; override;
    function GetItemID(AItem: TObject): Integer; override;
    function SupportsScrollBarParams: Boolean; virtual;
    procedure UpdateControl(AInfo: TcxUpdateControlInfo); override;
    procedure UpdateScrollBars; override;
    property Scroller: TcxvgScroller read GetScroller;
    property VerticalGrid: TcxDBVerticalGrid read GetVerticalGrid;
  public
    procedure CreateAllItems;
    procedure FocusControl(AItemIndex: Integer; var Done: Boolean); override;
    function GetItem(Index: Integer): TObject; override;
    function GetItemValueSource(AItemIndex: Integer): TcxDataEditValueSource; override;
    procedure UpdateData; override;
    procedure UpdateItemIndexes; override;
  published
    property DataSource;
    property GridMode: Boolean read GetGridMode write SetGridMode default False;
    property GridModeBufferCount: Integer read GetGridModeBufferCount write SetGridModeBufferCount default 0;
  end;

  { TcxDBVerticalGridItemDataBinding }

  TcxDBVerticalGridItemDataBinding = class(TcxCustomItemDataBinding)
  private
    function GetDataController: TcxDBVerticalGridDataController;
    function GetField: TField;
    function GetFieldName: string;
    procedure SetFieldName(const Value: string);
  protected
    function DefaultRepositoryItem: TcxEditRepositoryItem; override;
    function GetDefaultValuesProviderClass: TcxCustomEditDefaultValuesProviderClass; override;
    function GetValueTypeClass: TcxValueTypeClass; override;
    procedure Init; override;
    procedure ValueTypeClassChanged; override;
  public
    procedure Assign(Source: TPersistent); override;
    function DefaultCaption: string; virtual;
    property DataController: TcxDBVerticalGridDataController read GetDataController;
    property Field: TField read GetField;
  published
    property FieldName: string read GetFieldName write SetFieldName;
  end;

  { TcxDBCellEdit }

  TcxDBCellEdit = class(TcxCellEdit)
  protected
    function GetDataBindingClass: TcxItemDataBindingClass; override;
  end;

  { TcxDBEditorRowItemProperties }

  TcxDBEditorRowItemProperties = class(TcxCollectionItemEditorRowProperties)
  private
    function GetDataBinding: TcxDBVerticalGridItemDataBinding;
    procedure SetDataBinding(Value: TcxDBVerticalGridItemDataBinding);
  protected
    function DefaultCaption: string; override;
    function GetDisplayName: string; override;
    function GetInplaceEditContainerClass: TcxCellEditClass; override;
  published
    property DataBinding: TcxDBVerticalGridItemDataBinding read GetDataBinding write SetDataBinding;
    property Options;
    property OnGetDisplayText;
    property OnGetEditProperties;
    property OnGetEditingProperties;
  end;

  { TcxDBEditorPropertiesCollection }

  TcxDBEditorPropertiesCollection = class(TcxEditorPropertiesCollection)
  private
    function GetItem(Index: Integer): TcxDBEditorRowItemProperties;
  protected
    function GetCollectionItemClass: TCollectionItemClass; override;
  public
    function Add: TcxDBEditorRowItemProperties;
    property Items[Index: Integer]: TcxDBEditorRowItemProperties read GetItem; default;
  end;

  { TcxDBEditorRowProperties }

  TcxDBEditorRowProperties = class(TcxCustomEditorRowProperties)
  private
    function GetDataBinding: TcxDBVerticalGridItemDataBinding;
    procedure SetDataBinding(Value: TcxDBVerticalGridItemDataBinding);
  protected
    function DefaultCaption: string; override;
    function GetInplaceEditContainerClass: TcxCellEditClass; override;
  public
    property Value;
  published
    property DataBinding: TcxDBVerticalGridItemDataBinding read GetDataBinding write SetDataBinding;
    property Options;
    property OnGetDisplayText;
    property OnGetEditProperties;
    property OnGetEditingProperties;
  end;

  { TcxDBEditorRow }

  TcxDBEditorRow = class(TcxCustomEditorRow)
  private
    function GetProperties: TcxDBEditorRowProperties;
    procedure SetProperties(Value: TcxDBEditorRowProperties);
  protected
    function GetPropertiesClass: TcxRowPropertiesClass; override;
  published
    property Expanded;
    property Height;
    property Options;
    property Properties: TcxDBEditorRowProperties read GetProperties write SetProperties;
    property Styles;
    property Visible;
  end;

  { TcxDBMultiEditorRowProperties }

  TcxDBMultiEditorRowProperties = class(TcxMultiEditorRowProperties)
  private
    function GetEditors: TcxDBEditorPropertiesCollection;
    procedure SetEditors(Value: TcxDBEditorPropertiesCollection);
  protected
    function GetCollectionClass: TcxEditorPropertiesCollectionClass; override;
  published
    property Editors: TcxDBEditorPropertiesCollection read GetEditors write SetEditors;
  end;

  { TcxDBMultiEditorRow }

  TcxDBMultiEditorRow = class(TcxCustomMultiEditorRow)
  private
    function GetProperties: TcxDBMultiEditorRowProperties;
    procedure SetProperties(Value: TcxDBMultiEditorRowProperties);
  protected
    function GetPropertiesClass: TcxRowPropertiesClass; override;
  published
    property Expanded;
    property Height;
    property Options;
    property Properties: TcxDBMultiEditorRowProperties read GetProperties write SetProperties;
    property Styles;
    property Visible;
  end;

  { TcxDBVerticalGrid }

  TcxDBVerticalGrid = class(TcxVirtualVerticalGrid, IcxVGridDesignerRows)
  private
    function GetDataController: TcxDBVerticalGridDataController;
    procedure SetDataController(Value: TcxDBVerticalGridDataController);
  protected
    function GetDataControllerClass: TcxCustomDataControllerClass; override;
    function GetEditCellDataBindingClass: TcxItemDataBindingClass; override;
    function GetEditorRowClass: TcxCustomRowClass; override;
    function GetMultiEditorRowClass: TcxCustomRowClass; override;
    procedure InitDataController; override;
  published
    property Align;
    property Anchors;
    property Constraints;
    property DataController: TcxDBVerticalGridDataController read GetDataController write SetDataController;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property Font;
    property Images;
    property LayoutStyle;
    property LookAndFeel;
    property OptionsView; //before OptionsBehavior
    property OptionsBehavior;
    property OptionsData;
    property ParentFont;
    property PopupMenu;
    property Styles;
    property TabOrder;
    property TabStop;
    property Visible;

    property OnClick;
  {$IFDEF DELPHI5}
    property OnContextPopup;
  {$ENDIF}
    property OnCustomizationFormVisibleChanged;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnDrawBackground;
    property OnDrawRowHeader;
    property OnDrawValue;
    property OnEdited;
    property OnEditing;
    property OnEditValueChanged;
    property OnEndDock;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnFilterControlDialogShow;
    property OnFilterRecord;
    property OnFocusedRecordChanged;
    property OnInitEdit;
    property OnItemChanged;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnLayoutChanged;
    property OnLeftVisibleBandIndexChanged;
    property OnLeftVisibleRecordIndexChanged;
    property OnMouseDown;
    property OnMouseEnter;
    property OnMouseLeave;
    property OnMouseMove;
    property OnMouseUp;
    property OnMouseWheel;
    property OnMouseWheelDown;
    property OnMouseWheelUp;
    property OnResize;
  {$IFDEF VCL}
    property OnStartDock;
  {$ENDIF}
    property OnStartDrag;
    property OnTopRowIndexChanged;
  end;

implementation

uses
  SysUtils, cxGraphics, cxControls, cxLookAndFeelPainters, cxEditDBRegisteredRepositoryItems,
{$IFDEF DELPHI6}
  Types,
{$ENDIF}
  cxGeometry, cxVGridViewInfo, cxClasses;

{ TcxDBVerticalGridDefaultValuesProvider }

function TcxDBVerticalGridDefaultValuesProvider.IsDisplayFormatDefined(AIsCurrencyValueAccepted: Boolean): Boolean;
begin
  Result := TcxDBVerticalGridItemDataBinding(Owner).IsDisplayFormatDefined(AIsCurrencyValueAccepted);
end;

{ TcxDBVerticalGridDataController }

procedure TcxDBVerticalGridDataController.CreateAllItems;
var
  I: Integer;
  AItem: TcxDBEditorRow;
begin
  if DataSet = nil then Exit;
  ShowHourglassCursor;
  try
    VerticalGrid.BeginUpdate;
    try
      with DataSet do
        for I := 0 to FieldCount - 1 do
        begin
          AItem := TcxDBEditorRow(GetVerticalGrid.Add(TcxDBEditorRow));
          AItem.Name := CreateUniqueName(VerticalGrid.Owner, VerticalGrid, AItem, 'Tcx', Fields[I].FieldName);
          with AItem.Properties do
          begin
            DataBinding.FieldName := Fields[I].FieldName;
            Caption := DataBinding.DefaultCaption;
          end;
          AItem.Visible := Fields[I].Visible;
        end;
    finally
      VerticalGrid.EndUpdate;
    end;
  finally
    HideHourglassCursor;
  end;
end;

procedure TcxDBVerticalGridDataController.FocusControl(AItemIndex: Integer;
  var Done: Boolean);
begin
  TcxDBCellEdit(GetItem(AItemIndex)).Editing := True;
  Done := TcxDBCellEdit(GetItem(AItemIndex)).Editing;
end;

function TcxDBVerticalGridDataController.GetItem(Index: Integer): TObject;
begin
  Result := VerticalGrid.ContainerList.List^[Index];
end;

function TcxDBVerticalGridDataController.GetItemValueSource(
  AItemIndex: Integer): TcxDataEditValueSource;
begin
  Result := TcxDBCellEdit(GetItem(AItemIndex)).PropertiesValue.GetEditValueSource(True);
end;

procedure TcxDBVerticalGridDataController.UpdateData;
begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -