cxlookupdbgrid.pas

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

PAS
526
字号
function TcxLookupDBGridColumns.ColumnByFieldName(const AFieldName: string): TcxLookupDBGridColumn;
var
  I: Integer;
begin
  for I := 0 to Count - 1 do
  begin
    Result := Items[I];
    if AnsiCompareText(Result.FieldName, AFieldName) = 0 then
      Exit;
  end;
  Result := nil;
end;

function TcxLookupDBGridColumns.GetColumn(Index: Integer): TcxLookupDBGridColumn;
begin
  Result := inherited Items[Index] as TcxLookupDBGridColumn;
end;

procedure TcxLookupDBGridColumns.SetColumn(Index: Integer; Value: TcxLookupDBGridColumn);
begin
  inherited Items[Index] := Value;
end;

{ TcxLookupGridDBDataController }

constructor TcxLookupGridDBDataController.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  DataModeController.SyncMode := DefaultSyncMode;
  DataModeController.SyncInsert := False;
end;

function TcxLookupGridDBDataController.GetItem(Index: Integer): TObject;
begin
  Result := Grid.Columns[Index];
end;

procedure TcxLookupGridDBDataController.UpdateScrollBars;
begin
  Grid.UpdateScrollBars;
end;

function TcxLookupGridDBDataController.GetGrid: TcxCustomLookupDBGrid;
begin
  Result := GetOwner as TcxCustomLookupDBGrid;
end;

{ TcxLookupDBGridOptions }

procedure TcxLookupDBGridOptions.Assign(Source: TPersistent);
begin
  if Source is TcxLookupDBGridOptions then
  begin
    if Assigned(Grid) then
      Grid.BeginUpdate;
    try
      inherited Assign(Source);
      SyncMode := TcxLookupDBGridOptions(Source).SyncMode;
    finally
      if Assigned(Grid) then
        Grid.EndUpdate;
    end;
  end
  else
    inherited Assign(Source);
end;

function TcxLookupDBGridOptions.GetGrid: TcxCustomLookupDBGrid;
begin
  Result := TcxCustomLookupDBGrid(FGrid);
end;

function TcxLookupDBGridOptions.GetSyncMode: Boolean;
begin
  if Assigned(Grid) then
    Result := Grid.DataController.DataModeController.SyncMode
  else
    Result := DefaultSyncMode;
end;

procedure TcxLookupDBGridOptions.SetSyncMode(Value: Boolean);
begin
  if Assigned(Grid) then
    Grid.DataController.DataModeController.SyncMode := Value;
end;

{ TcxCustomLookupDBGrid }

procedure TcxCustomLookupDBGrid.CreateAllColumns;
var
  ADataSet: TDataSet;
  AFieldNames: TStrings;
begin
  Columns.Clear;
  ADataSet := DataController.DataSet;
  if ADataSet <> nil then
  begin
    AFieldNames := TStringList.Create;
    try
    {$WARNINGS OFF} { for Borland Delphi 10 }
      ADataSet.GetFieldNames(AFieldNames);
    {$WARNINGS ON}
      CreateColumnsByFields(AFieldNames);
    finally
      AFieldNames.Free;
    end;
  end;
end;

procedure TcxCustomLookupDBGrid.CreateColumnsByFieldNames(const AFieldNames: string);
var
  AFieldNamesList: TStrings;
begin
  Columns.Clear;
  AFieldNamesList := TStringList.Create;
  try
    GetFieldNames(AFieldNames, AFieldNamesList);
    CreateColumnsByFields(AFieldNamesList);
  finally
    AFieldNamesList.Free;
  end;
end;

procedure TcxCustomLookupDBGrid.CreateColumnsByFields(AFieldNames: TStrings);
var
  I: Integer;
begin
  BeginUpdate;
  try
    for I := 0 to AFieldNames.Count - 1 do
      Columns.Add.FieldName := AFieldNames[I];
  finally
    EndUpdate;
  end;
end;

procedure TcxCustomLookupDBGrid.DataChanged;
var
  I: Integer;
begin
  for I := 0 to Columns.Count - 1 do
    Columns[I].InitDefaultValuesProvider;
  inherited DataChanged;
end;

function TcxCustomLookupDBGrid.GetColumnClass: TcxLookupGridColumnClass;
begin
  Result := TcxLookupDBGridColumn;
end;

function TcxCustomLookupDBGrid.GetColumnsClass: TcxLookupGridColumnsClass;
begin
  Result := TcxLookupDBGridColumns;
end;

function TcxCustomLookupDBGrid.GetDataControllerClass: TcxCustomDataControllerClass;
begin
  Result := TcxLookupGridDBDataController;
end;

function TcxCustomLookupDBGrid.GetOptionsClass: TcxLookupGridOptionsClass;
begin
  Result := TcxLookupDBGridOptions;
end;

procedure TcxCustomLookupDBGrid.InitScrollBarsParameters;
begin
  if DataController.IsGridMode and DataController.IsSequenced then
  begin
    SetScrollBarInfo(sbVertical, 0,
      (DataController.DataSetRecordCount - 1) + (ViewInfo.VisibleRowCount - 1),
      1, ViewInfo.VisibleRowCount, DataController.RecNo - 1, True, True);
  end
  else
    inherited InitScrollBarsParameters;
end;

procedure TcxCustomLookupDBGrid.Scroll(AScrollBarKind: TScrollBarKind;
  AScrollCode: TScrollCode; var AScrollPos: Integer);
begin
  if DataController.IsGridMode and DataController.IsSequenced then
  begin
    if AScrollBarKind = sbVertical then
    begin
      case AScrollCode of
        scLineUp:
          FocusNextRow(False);
        scLineDown:
          FocusNextRow(True);
        scPageUp:
          FocusPriorPage;
        scPageDown:
          FocusNextPage;
        scTrack: ;
        scPosition:
          DataController.RecNo := AScrollPos + 1;
      end;
    end
    else
      inherited Scroll(AScrollBarKind, AScrollCode, AScrollPos);
    AScrollPos := DataController.RecNo - 1;
  end
  else
    inherited Scroll(AScrollBarKind, AScrollCode, AScrollPos);
end;

procedure TcxCustomLookupDBGrid.UpdateScrollBars;
begin
  inherited UpdateScrollBars;
end;

function TcxCustomLookupDBGrid.GetColumns: TcxLookupDBGridColumns;
begin
  Result := inherited Columns as TcxLookupDBGridColumns;
end;

function TcxCustomLookupDBGrid.GetDataController: TcxLookupGridDBDataController;
begin
  Result := TcxLookupGridDBDataController(FDataController);
end;

function TcxCustomLookupDBGrid.GetDataSource: TDataSource;
begin
  Result := DataController.DataSource;
end;

function TcxCustomLookupDBGrid.GetKeyFieldNames: string;
begin
  Result := DataController.KeyFieldNames;
end;

function TcxCustomLookupDBGrid.GetOptions: TcxLookupDBGridOptions;
begin
  Result := TcxLookupDBGridOptions(FOptions);
end;

procedure TcxCustomLookupDBGrid.SetColumns(Value: TcxLookupDBGridColumns);
begin
  inherited Columns := Value;
end;

procedure TcxCustomLookupDBGrid.SetDataController(Value: TcxLookupGridDBDataController);
begin
  FDataController.Assign(Value);
end;

procedure TcxCustomLookupDBGrid.SetDataSource(Value: TDataSource);
begin
  DataController.DataSource := Value;
end;

procedure TcxCustomLookupDBGrid.SetKeyFieldNames(const Value: string);
begin
  DataController.KeyFieldNames := Value;
end;

procedure TcxCustomLookupDBGrid.SetOptions(Value: TcxLookupDBGridOptions);
begin
  FOptions.Assign(Value);
end;

end.

⌨️ 快捷键说明

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