cxwwgridconverter.pas

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

PAS
1,078
字号
      end;
    end;
  end
  else
  begin
    AColumns := TStringList.Create;
    AColumnsNeedFree := True;
    GetFieldNames(AColumns);
    AFieldColumns := True;
  end;
  try
    AFontWidth := GetFontWidth(GetClassProperty(nil, 'Font') as TFont);
    for I := 0 to AColumns.Count - 1 do
    begin
      if AFieldColumns then
      begin
        AIndex := ExtractData(AColumns[I], AFieldName, 1, ';');
        ExtractData(AColumns[I], AWidth, AIndex, ';');
        AHeader := AFieldName;
        AReadOnly := False;
      end
      else
      begin
        AIndex := ExtractData(AColumns[I], AFieldName, 1, #9);
        AIndex := ExtractData(AColumns[I], AWidth, AIndex, #9);
        AIndex := ExtractData(AColumns[I], AHeader, AIndex, #9);
        ExtractData(AColumns[I], AReadOnlyString, AIndex, #9);
        AReadOnly := AReadOnlyString = 'T';
      end;
      AcxColumn := cxGridView.CreateColumn;
      AcxColumn.DataBinding.FieldName := AFieldName;
      AcxColumn.Name := UniqueColumnName(AcxColumn, AcxColumn.DataBinding.FieldName);
      AcxColumn.Width := StrToInt(AWidth) * AFontWidth;
      AcxColumn.Caption := AHeader;
      AcxColumn.HeaderAlignmentHorz := ConvertAlignment(GetEnumProperty(nil, 'TitleAlignment'));
      AColumnData := IsColumnDefault(AFieldName);
      if AColumnData <> '' then
      begin
        AIndex := Pass(AColumnData, 1, 1, ';');
        ExtractData(AColumnData, AControlType, AIndex, ';');
        if AControlType = 'Bitmap' then
          ImportColumnImage(AcxColumn, AColumnData, AReadOnly)
        else if AControlType = 'CheckBox' then
          ImportColumnCheckBox(AcxColumn, AColumnData, AReadOnly)
        else if AControlType = 'CustomEdit' then
        begin
          if Designer_ <> nil then
            ImportColumnCustomEdit(AcxColumn, AColumnData);
        end
        else if AControlType = 'ImageIndex' then
        else if AControlType = 'URL-Link' then
          ImportColumnUrlLink(AcxColumn, AReadOnly)
        else if AControlType = 'RichEdit' then
        begin
          if Designer_ <> nil then
            ImportColumnRichEdit(AcxColumn, AColumnData);
        end
      end
      else
        if AReadOnly then
          ImportColumnText(AcxColumn, AReadOnly);
      AcxColumn.Position.BandIndex := 0;
    end;
  finally
    if AColumnsNeedFree then
      AColumns.Free;
  end;
end;

procedure TcxWWGridConverter.ImportGrid;
begin
  ImportWWOptions;
end;

procedure TcxWWGridConverter.ImportGridStyles;
var
  AStyle: TcxCustomStyle;
  AObject: TObject;
  AHighligntColor: Integer;
  AShadowColor: Integer;
  AAlternatingRowColor: Integer;
  AActiveRecordColor: Integer;
begin
  FColor := GetIntegerProperty(nil, 'Color');
  FFont := GetClassProperty(nil, 'Font') as TFont;
  if (FColor <> clWindow) or not DefaultFont(FFont) then
  begin
    AStyle := CreateStyleItem;
    (AStyle as TcxStyle).Color := FColor;
    (AStyle as TcxStyle).Font.Assign(FFont);
    (AStyle as TcxStyle).TextColor := (AStyle as TcxStyle).Font.Color;
    cxGridView.Styles.Content := AStyle as TcxStyle;
  end;
  FTitleColor := GetIntegerProperty(nil, 'TitleColor');
  FTitleFont := GetClassProperty(nil, 'TitleFont') as TFont;
  if (FTitleColor <> clBtnFace) or not DefaultFont(FTitleFont) then
  begin
    AStyle := CreateStyleItem;
    (AStyle as TcxStyle).Color := FTitleColor;
    (AStyle as TcxStyle).Font.Assign(FTitleFont);
    (AStyle as TcxStyle).TextColor := (AStyle as TcxStyle).Font.Color;
    cxGridView.Styles.Header := AStyle as TcxStyle;
    cxGridView.Styles.Footer := AStyle as TcxStyle;
    cxGridView.Styles.Background := AStyle as TcxStyle;
    cxGridView.Styles.Indicator := AStyle as TcxStyle;
  end;
  AObject := GetClassProperty(nil, 'LineColors');
  if AObject <> nil then
  begin
    AHighligntColor := GetIntegerProperty(AObject, 'HighlightColor');
    if AHighligntColor <> clBtnHighlight then
      cxGridView.OptionsView.GridLineColor := AHighligntColor
    else
    begin
      AShadowColor := GetIntegerProperty(AObject, 'ShadowColor');
      if AShadowColor <> clBtnShadow then
        cxGridView.OptionsView.GridLineColor := AShadowColor;
    end;
  end;
  AObject := GetClassProperty(nil, 'PaintOptions');
  if AObject <> nil then
  begin
    AAlternatingRowColor := GetIntegerProperty(AObject, 'AlternatingRowColor');
    if AAlternatingRowColor <> clNone then
    begin
      AStyle := CreateStyleItem;
      (AStyle as TcxStyle).Color := AAlternatingRowColor;
      (AStyle as TcxStyle).Font.Assign(FFont);
      (AStyle as TcxStyle).TextColor := (AStyle as TcxStyle).Font.Color;
      cxGridView.Styles.ContentOdd := AStyle as TcxStyle;
    end;
    AActiveRecordColor := GetIntegerProperty(AObject, 'ActiveRecordColor');
    if AActiveRecordColor <> clNone then
    begin
      AStyle := CreateStyleItem;
      (AStyle as TcxStyle).Color := AActiveRecordColor;
      (AStyle as TcxStyle).Font.Assign(FFont);
      (AStyle as TcxStyle).TextColor := (AStyle as TcxStyle).Font.Color;
      cxGridView.Styles.Selection := AStyle as TcxStyle;
    end;
  end;
end;

procedure TcxWWGridConverter.ImportWWCheckBox(AcxColumn: TcxGridDBBandedColumn; AComponent: TComponent);
  function GetNullStyle(const AStyle: string): TcxCheckBoxNullValueShowingStyle;
  begin
    if AStyle = 'cbGrayed' then
      Result := nssGrayedChecked
    else if AStyle = 'cbUnchecked' then
      Result := nssUnchecked
    else
      Result := nssInactive;  
  end;
begin
  AcxColumn.PropertiesClass := TcxCheckBoxProperties;
  with TcxCheckBoxProperties(AcxColumn.Properties) do
  begin
    Alignment := ConvertAlignment(GetEnumProperty(AComponent, 'Alignment'));
    AllowGrayed := GetBooleanProperty(AComponent, 'AllowGrayed', AllowGrayed);
//    Caption := GetStringProperty(AComponent, 'Caption', Caption);
    DisplayChecked := GetStringProperty(AComponent, 'DisplayValueChecked', DisplayChecked);
    DisplayUnchecked := GetStringProperty(AComponent, 'DisplayValueUnchecked', DisplayUnchecked);
    FullFocusRect := GetBooleanProperty(AComponent, 'ShowFocusRect', FullFocusRect);
    NullStyle := GetNullStyle(GetEnumProperty(AComponent, 'NullAndBlankState'));
    ReadOnly := GetBooleanProperty(AComponent, 'ReadOnly', ReadOnly);
    ValueChecked := GetStringProperty(AComponent, 'ValueChecked', ValueChecked);
    ValueUnchecked := GetStringProperty(AComponent, 'ValueUnchecked', ValueUnchecked);    
  end;
end;

procedure TcxWWGridConverter.ImportWWComboBox(AcxColumn: TcxGridDBBandedColumn; AComponent: TComponent);
var
  AwwItems: TStringList;
  AValue: string;
  AIndex: Integer;
  
  procedure ImportToImageComboBox;
  var
    I: Integer;
    AItem: TcxImageComboBoxItem;
    ADescription: string;
  begin
    AcxColumn.PropertiesClass := TcxImageComboBoxProperties;
    with TcxImageComboBoxProperties(AcxColumn.Properties) do
    begin
      ReadOnly := GetBooleanProperty(AComponent, 'ReadOnly', ReadOnly);
      AwwItems := GetClassProperty(AComponent, 'Items') as TStringList;
      if AwwItems <> nil then
      begin
        for I := 0 to AwwItems.Count - 1 do
        begin
          AItem := Items.Add as TcxImageComboBoxItem;
          AIndex := ExtractData(AwwItems[I], ADescription, 1, #9);
          ExtractData(AwwItems[I], AValue, AIndex, #9);
          AItem.Description := ADescription;
          AItem.Value := AValue;
        end;
      end;
      if GetEnumProperty(AComponent, 'ButtonStyle') = 'cbsCustom' then
        ButtonGlyph.Assign(GetClassProperty(AComponent, 'ButtonGlyph') as TBitmap);
      ImmediateDropDown := GetBooleanProperty(AComponent, 'AutoDropDown', ImmediateDropDown);
      DropDownRows := GetIntegerProperty(AComponent, 'DropDownCount', DropDownRows);
    end;
  end;

  procedure ImportToMRUEdit;
  var
    I: Integer;
  begin
    AcxColumn.PropertiesClass := TcxMRUEditProperties;
    with TcxMRUEditProperties(AcxColumn.Properties) do
    begin
      ReadOnly := GetBooleanProperty(AComponent, 'ReadOnly', ReadOnly);
      AwwItems := GetClassProperty(AComponent, 'Items') as TStringList;
      if AwwItems <> nil then
      begin
        for I := 0 to AwwItems.Count - 1 do
        begin
          AIndex := Pass(AwwItems[I], 1, 1, #9);
          ExtractData(AwwItems[I], AValue, AIndex, #9);
          LookupItems.Add(AValue);
        end;
      end;
      if GetEnumProperty(AComponent, 'ButtonStyle') = 'cbsCustom' then
        ButtonGlyph.Assign(GetClassProperty(AComponent, 'ButtonGlyph') as TBitmap);
      ImmediateDropDown := GetBooleanProperty(AComponent, 'AutoDropDown', ImmediateDropDown);
      DropDownRows := GetIntegerProperty(AComponent, 'DropDownCount', DropDownRows);
      ShowEllipsis := False;
    end;
  end;
var
  AWWHistory: TObject;
begin
  AWWHistory := GetClassProperty(AComponent, 'HistoryList');
  if AWWHistory <> nil then
  begin
    if GetBooleanProperty(AWWHistory, 'Enabled', False) then
      ImportToMRUEdit
    else
      ImportToImageComboBox;
  end
  else
    ImportToImageComboBox;
end;

procedure TcxWWGridConverter.ImportWWComboDlg(AcxColumn: TcxGridDBBandedColumn; AComponent: TComponent);
var
  AButton: TcxEditButton;
  AButtonStyle: string;
begin
  AcxColumn.PropertiesClass := TcxButtonEditProperties;
  with TcxButtonEditProperties(AcxColumn.Properties) do
  begin
    Buttons.Clear;
    AButton := Buttons.Add;
    AButton.Glyph.Assign(GetClassProperty(AComponent, 'ButtonGlyph') as TBitmap);
    AButtonStyle := GetEnumProperty(AComponent, 'ButtonStyle');
    if AButtonStyle = 'cbsCustom' then
      AButton.Kind := bkGlyph
    else if AButtonStyle = 'cbsEllipsis' then
      AButton.Kind := bkEllipsis
    else if AButtonStyle = 'cbsDownArrow' then
      AButton.Kind := bkDown;
    AButton.Width := GetIntegerProperty(AComponent, 'ButtonWidth', AButton.Width);
    CharCase := GetCharCase(GetEnumProperty(AComponent, 'CharCase'));
    MaxLength := GetIntegerProperty(AComponent, 'MaxLength', MaxLength);
    ReadOnly := GetBooleanProperty(AComponent, 'ReadOnly', ReadOnly);
    AButton.Visible := GetBooleanProperty(AComponent, 'ShowButton', AButton.Visible);
  end;
end;

procedure TcxWWGridConverter.ImportWWDateTimePicker(AcxColumn: TcxGridDBBandedColumn; AComponent: TComponent);
  function GetCalendarAlignment(const AValue: string): TAlignment;
  begin
    if AValue = 'wwdtaCenter' then
      Result := taCenter
    else if AValue = 'wwdtaLeft' then
      Result := taLeftJustify
    else if AValue = 'wwdtaRight' then
      Result := taRightJustify
    else
      Result := taCenter;
  end;
var
  AWWCalendarAttributes: TObject;
  ADateButtons: TDateButtons;
  AWWOptions: TStringList;
  I: Integer;
begin
  AcxColumn.PropertiesClass := TcxDateEditProperties;
  with TcxDateEditProperties(AcxColumn.Properties) do
  begin
    AWWCalendarAttributes := GetClassProperty(AComponent, 'CalendarAttributes');
    if AWWCalendarAttributes <> nil then
      Alignment.Horz := GetCalendarAlignment(GetEnumProperty(AWWCalendarAttributes, 'Alignment'));
    ButtonGlyph.Assign(GetClassProperty(AComponent, 'ButtonGlyph') as TBitmap);
    ADateButtons := [btnClear];
    if AWWCalendarAttributes <> nil then
    begin
      AWWOptions := TStringList.Create;
      try
        EnablePropertyException;
        try
          GetSetProperty(AWWCalendarAttributes, 'Options', AWWOptions);
          if not AWWOptions.Find('mdoNoToday', I) then
            Include(ADateButtons, btnToday);
          DateButtons := ADateButtons;
        except
          on EcxUnknownProperty do;
        end;
      finally
        AWWOptions.Free;
        DisablePropertyException;
      end;
    end;
  end;
end;

procedure TcxWWGridConverter.ImportWWExpandButton(AcxColumn: TcxGridDBBandedColumn; AComponent: TComponent);
begin
end;

procedure TcxWWGridConverter.ImportWWLookupCombo(AcxColumn: TcxGridDBBandedColumn;
  AComponent: TComponent);
var
  AListDataSource: TDataSource;
  AListTable: TObject;
  AIndex: Integer;
  ASelected: TStringList;
  I: Integer;
  AListFieldName: string;
  AListFieldWidth: string;
  AListFieldCaption: string;
  AcxLookupColumn: TcxLookupDBGridColumn;
  AWWOptions: TStringList;
  AString: string;
  AWWSeqSearchOptions: TStringList;
begin
  AcxColumn.PropertiesClass := TcxLookupComboBoxProperties;
  with TcxLookupComboBoxProperties(AcxColumn.Properties) do
  begin
    AListTable := GetClassProperty(AComponent, 'LookupTable');
    if AListTable <> nil then
    begin
      AListDataSource := TDataSource.Create(cxGridView);
      AListDataSource.DataSet := AListTable as TDataSet;
      ListSource := AListDataSource;
      KeyFieldNames := GetStringProperty(AComponent, 'LookupField', '');
      ASelected := GetClassProperty(AComponent, 'Selected') as TStringList;
      if ASelected <> nil then
      begin
        for I := 0 to ASelected.Count - 1 do
        begin
          AIndex := ExtractData(ASelected[I], AListFieldName, 1, #9);
          AIndex := ExtractData(ASelected[I], AListFieldWidth, AIndex, #9);
          ExtractData(ASelected[I], AListFieldCaption, AIndex, #9);
          AcxLookupColumn := ListColumns.Add;
          AcxLookupColumn.FieldName := AListFieldName;
          AcxLookupColumn.Caption := AListFieldCaption;
          AcxLookupColumn.Width := StrToInt(AListFieldWidth) *

⌨️ 快捷键说明

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