cxgriddbdatadefinitions.pas

来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 682 行 · 第 1/2 页

PAS
682
字号
{********************************************************************}
{                                                                    }
{       Developer Express Visual Component Library                   }
{       ExpressQuantumGrid                                           }
{                                                                    }
{       Copyright (c) 1998-2008 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 EXPRESSQUANTUMGRID 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 cxGridDBDataDefinitions;

{$I cxVer.inc}

interface

uses
  Classes, DB, cxGridCustomView,
  cxCustomData, cxFilter, cxDBData, cxDataStorage, cxDataUtils,
  cxEdit, cxDBEdit, cxGridCustomTableView;

type
  TcxGridDBDefaultValuesProvider = class(TcxCustomDBEditDefaultValuesProvider)
  private
    FFieldName: string;
  public
    function DefaultCanModify: Boolean; override;
    function IsDisplayFormatDefined(AIsCurrencyValueAccepted: Boolean): Boolean; override;
    property FieldName: string read FFieldName write FFieldName;
  end;

  TcxGridDBDataController = class(TcxDBDataController,
    IcxCustomGridDataController, IcxGridDataController)
  private
    FPrevScrollBarPos: Integer;
    function GetController: TcxCustomGridTableController;
    function GetGridViewValue: TcxCustomGridTableView;
  protected
    { IcxCustomGridDataController }
    procedure AssignData(ADataController: TcxCustomDataController);
    procedure DeleteAllItems;
    procedure GetFakeComponentLinks(AList: TList);
    function GetGridView: TcxCustomGridView;
    function HasAllItems: Boolean;
    function IsDataChangeable: Boolean;
    function IsDataLinked: Boolean;
    function SupportsCreateAllItems: Boolean;
    { IcxGridDataController }
    procedure CheckGridModeBufferCount;
    function DoScroll(AForward: Boolean): Boolean;
    function DoScrollPage(AForward: Boolean): Boolean;
    //function GetFilterPropertyValue(const AName: string; var AValue: Variant): Boolean;
    function GetItemDataBindingClass: TcxGridItemDataBindingClass;
    function GetItemDefaultValuesProviderClass: TcxCustomEditDefaultValuesProviderClass;
    function GetNavigatorIsBof: Boolean;
    function GetNavigatorIsEof: Boolean;
    function GetScrollBarPos: Integer;
    function GetScrollBarRecordCount: Integer;
    //function SetFilterPropertyValue(const AName: string; const AValue: Variant): Boolean;
    function SetScrollBarPos(Value: Integer): Boolean;

    function CanSelectRow(ARowIndex: Integer): Boolean; override;
    function CompareByField(ARecordIndex1, ARecordIndex2: Integer;
      AField: TcxCustomDataField; AMode: TcxDataControllerComparisonMode): Integer; override;
    procedure DoDataSetCurrentChanged(AIsCurrent: Boolean); override;
    procedure DoDataSourceChanged; override;
    procedure DoValueTypeClassChanged(AItemIndex: Integer); override;
    procedure FilterChanged; override;
    function GetDefaultActiveRelationIndex: Integer; override;
    function GetDefaultGridModeBufferCount: Integer; override;
    function GetFilterDisplayText(ARecordIndex, AItemIndex: Integer): string; override;
    //function GetIncrementalSearchText(ARecordIndex, AItemIndex: Integer): string; override;
    function GetItemID(AItem: TObject): Integer; override;
    function GetSortingBySummaryEngineClass: TcxSortingBySummaryEngineClass; override;
    function GetSummaryGroupItemLinkClass: TcxDataSummaryGroupItemLinkClass; override;
    function GetSummaryItemClass: TcxDataSummaryItemClass; override;
    function SupportsScrollBarParams: Boolean; virtual;
    function SyncDetailsFocusWithMaster: Boolean; override;
    procedure UpdateScrollBars; override;
  public
    procedure BeginFullUpdate; override;
    procedure EndFullUpdate; override;
    function CreateDetailLinkObject(ARelation: TcxCustomDataRelation;
      ARecordIndex: Integer): TObject; override;
    procedure FocusControl(AItemIndex: Integer; var Done: Boolean); override;
    function GetDetailDataControllerByLinkObject(ALinkObject: TObject): TcxCustomDataController; override;
    function GetDisplayText(ARecordIndex, AItemIndex: Integer): string; override;
    function GetFilterDataValue(ARecordIndex: Integer; AField: TcxCustomDataField): Variant; override;
    function GetFilterItemFieldCaption(AItem: TObject): string; override;
    function GetItem(Index: Integer): TObject; override;
    function GetItemSortByDisplayText(AItemIndex: Integer; ASortByDisplayText: Boolean): Boolean; override;
    function GetItemValueSource(AItemIndex: Integer): TcxDataEditValueSource; override;
    procedure UpdateData; override;

    procedure CreateAllItems(AMissingItemsOnly: Boolean = False);  // IcxCustomGridDataController
    function GetItemByFieldName(const AFieldName: string): TcxCustomGridTableItem;

    property Controller: TcxCustomGridTableController read GetController;
    property GridView: TcxCustomGridTableView read GetGridViewValue;
  published
    property DataModeController;
    property DataSource;
    property DetailKeyFieldNames;
    property Filter;
    property KeyFieldNames;
    property MasterKeyFieldNames;
    property Options;
    property Summary;
    property OnCompare;
    property OnDataChanged;
    property OnDetailCollapsing;
    property OnDetailCollapsed;
    property OnDetailExpanding;
    property OnDetailExpanded;
    property OnDetailHasChildren;
    property OnFilterRecord;
    property OnGroupingChanged;
    property OnSortingChanged;
  end;

  TcxGridItemDBDataBinding = class(TcxGridItemDataBinding)
  private
    function GetDataController: TcxGridDBDataController;
    function GetField: TField;
    function GetFieldName: string;
    procedure SetFieldName(const Value: string);
  protected
    function GetDefaultValueTypeClass: TcxValueTypeClass; override;
    function GetFilterFieldName: string; override;
    procedure Init; override;
    function IsValueTypeStored: Boolean; override;
  public
    procedure Assign(Source: TPersistent); override;
    function DefaultCaption: string; override;
    function DefaultRepositoryItem: TcxEditRepositoryItem; override;
    function DefaultWidth(ATakeHeaderIntoAccount: Boolean = True): Integer; override;
    property DataController: TcxGridDBDataController read GetDataController;
    property Field: TField read GetField;
  published
    property FieldName: string read GetFieldName write SetFieldName;
  end;

implementation

uses
  SysUtils, cxClasses, cxGraphics, cxControls, cxLookAndFeelPainters,
  cxEditDBRegisteredRepositoryItems,
  cxStorage, cxGridCommon, cxGridLevel, Controls, Forms;

type
  TcxComponentAccess = class(TcxComponent);

{ TcxGridDBDefaultValuesProvider }

function TcxGridDBDefaultValuesProvider.DefaultCanModify: Boolean;
begin
  Result := (FieldName = '') or inherited DefaultCanModify;
end;

function TcxGridDBDefaultValuesProvider.IsDisplayFormatDefined(AIsCurrencyValueAccepted: Boolean): Boolean;
begin
  Result := TcxGridItemDataBinding(Owner).IsDisplayFormatDefined(AIsCurrencyValueAccepted);
end;

{ TcxGridDBDataController }

function TcxGridDBDataController.GetController: TcxCustomGridTableController;
begin
  Result := GridView.Controller;
end;

function TcxGridDBDataController.GetGridViewValue: TcxCustomGridTableView;
begin
  Result := TcxCustomGridTableView(GetGridView);
end;

procedure TcxGridDBDataController.AssignData(ADataController: TcxCustomDataController);
begin
end;

procedure TcxGridDBDataController.DeleteAllItems;
begin
  GridView.ClearItems;
end;

procedure TcxGridDBDataController.GetFakeComponentLinks(AList: TList);
begin
  if (DataSource <> nil) and (DataSource.Owner <> GridView.Owner) and
    (AList.IndexOf(DataSource.Owner) = -1) then
    AList.Add(DataSource.Owner);
end;

function TcxGridDBDataController.GetGridView: TcxCustomGridView;
begin
  Result := TcxCustomGridView(GetOwner);
end;

function TcxGridDBDataController.HasAllItems: Boolean;
var
  I: Integer;
begin
  Result := True;
  with DataSet do
    for I := 0 to FieldCount - 1 do
    begin
      Result := GetItemByFieldName(Fields[I].FieldName) <> nil;
      if not Result then Break;
    end;
end;

function TcxGridDBDataController.IsDataChangeable: Boolean;
begin
  Result := False;
end;

function TcxGridDBDataController.IsDataLinked: Boolean;
begin
  Result := DataSet <> nil;
end;

function TcxGridDBDataController.SupportsCreateAllItems: Boolean;
begin
  Result := True;
end;

procedure TcxGridDBDataController.CheckGridModeBufferCount;
begin
  UpdateGridModeBufferCount;
end;

function TcxGridDBDataController.DoScroll(AForward: Boolean): Boolean;
var
  AScrolled: Boolean;
begin
  Result := SupportsScrollBarParams;
  if Result then
  begin
    if AForward then
      AScrolled := Controller.GoToNext(False, False)
    else
      AScrolled := Controller.GoToPrev(False, False);
    if AScrolled then
      SetSelectionAnchor(FocusedRowIndex);
  end;
end;

function TcxGridDBDataController.DoScrollPage(AForward: Boolean): Boolean;
var
  APrevRecNo: Integer;
begin
  Result := SupportsScrollBarParams;
  if Result then
  begin
    APrevRecNo := RecNo;
    if AForward then
      TcxCustomGridTableControllerAccess.FocusNextPage(Controller, False)
    else
      TcxCustomGridTableControllerAccess.FocusPrevPage(Controller, False);
    if RecNo <> APrevRecNo then
      SetSelectionAnchor(FocusedRowIndex);
  end;
end;

{function TcxGridDBDataController.GetFilterPropertyValue(const AName: string;
  var AValue: Variant): Boolean;
begin
  Result := True;
  if AName = 'FilterAutoDataSetFilter' then
    AValue := Filter.AutoDataSetFilter
  else
    Result := False;
end;}

function TcxGridDBDataController.GetItemDataBindingClass: TcxGridItemDataBindingClass;
begin
  Result := TcxGridItemDBDataBinding;
end;

function TcxGridDBDataController.GetItemDefaultValuesProviderClass: TcxCustomEditDefaultValuesProviderClass;
begin
  Result := TcxGridDBDefaultValuesProvider;
end;

function TcxGridDBDataController.GetNavigatorIsBof: Boolean;
begin
  Result := GridView.Controller.IsStart;
end;

function TcxGridDBDataController.GetNavigatorIsEof: Boolean;
begin
  Result := GridView.Controller.IsFinish;
end;

function TcxGridDBDataController.GetScrollBarPos: Integer;
begin
  if SupportsScrollBarParams then
    if dceInsert in EditState then
      Result := FPrevScrollBarPos
    else
      Result := RecNo - 1
  else
    Result := -1;
  FPrevScrollBarPos := Result;  
end;

function TcxGridDBDataController.GetScrollBarRecordCount: Integer;
begin
  if SupportsScrollBarParams then
    Result := DataSetRecordCount + GridView.ViewInfo.VisibleRecordCount - 1
  else
    Result := -1;
end;

{function TcxGridDBDataController.SetFilterPropertyValue(const AName: string;
  const AValue: Variant): Boolean;
begin
  Result := True;

⌨️ 快捷键说明

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