生成表格,请稍候...

根据查询生成表格

CreateColumns(dbbtvResult, 'SELECT * FROM ' + sViewName + ' where 1 = 0 ');
      sSql := 'SELECT * FROM ' + sViewName + ' where 1 = 0 ';

function TfrmBatchSignature.CreateColumns(
  AcxGrid1DBBandedTableView: TcxGridDBBandedTableView;
  AsSql: string): string;
  function IsAddBands(str: string): Boolean;//是否需要插入bans
  var
    J: Integer;
  begin
    Result := True;
    for J := 0 to AcxGrid1DBBandedTableView.Bands.Count - 1 do
      if AcxGrid1DBBandedTableView.Bands[j].Caption = str then
        Result := False;
  end;
  function FieldTypeUpperCase(AField: TField):string;
  begin
    Result := FieldTypeNames[AField.DataType];
    Result := UpperCase(Result);
    //(tdttypeStr=UpperCase('Float'))
  end;
var
  I, J: integer;
  BandsStr, CaptionStr, strSQL, sFieldType: string;
  cxGridBand: TcxGridBand;
  cxGridDBBandedColumn: TcxGridDBBandedColumn;
  FuncOnGridTableDataCell: TMethod;
begin
  //先清空表格数据
  AcxGrid1DBBandedTableView.Bands.Clear;
  with AcxGrid1DBBandedTableView do
  begin
    (DataController as IcxCustomGridDataController).DeleteAllItems;
    (DataController as IcxCustomGridDataController).CreateAllItems(True);
  end;  //根据 datasource自动产生columns
  Result := '';
  if Trim(AsSql) = '' then Exit;
  
  try
    if not CommonDB.QryOpen(qryTemp, AsSql) then Exit;
   // CommonDB.ExecQuery(qryTemp, AsSql);
    qryTemp.DisableControls;
    for i := 0 to qryTemp.FieldCount - 1 do
    begin
      sFieldType := FieldTypeUpperCase(qryTemp.Fields[i]);
      if Pos('|', qryTemp.Fields[i].FieldName) > 0 then
      begin
        BandsStr := Copy(qryTemp.Fields[i].FieldName, 1, Pos('|', qryTemp.Fields[i].FieldName) - 1);
        CaptionStr := Copy(qryTemp.Fields[i].FieldName, Pos('|', qryTemp.Fields[i].FieldName) + 1, 2555);
        if AcxGrid1DBBandedTableView.Bands.Count = 0 then
          AcxGrid1DBBandedTableView.Bands.Add.Caption := BandsStr;

        if IsAddBands(BandsStr) then
          AcxGrid1DBBandedTableView.Bands.Add.Caption := BandsStr;

        cxGridDBBandedColumn := AcxGrid1DBBandedTableView.CreateColumn;
        for J := 0 to AcxGrid1DBBandedTableView.Bands.Count - 1 do
        begin
          if AcxGrid1DBBandedTableView.Bands[j].Caption = BandsStr then
          begin
            cxGridDBBandedColumn.Caption := CaptionStr;
            cxGridDBBandedColumn.DataBinding.FieldName := qryTemp.Fields[i].FieldName;
            cxGridDBBandedColumn.Position.BandIndex := AcxGrid1DBBandedTableView.Bands[j].Position.ColIndex;
            cxGridDBBandedColumn.HeaderAlignmentHorz := taCenter;
            cxGridDBBandedColumn.HeaderAlignmentVert := vaCenter;
            cxGridDBBandedColumn.Width :=  AcxGrid1DBBandedTableView.ViewInfo.Canvas.TextWidth(qryTemp.Fields[i].FieldName) + 10;
            if (sFieldType = 'FLOAT') or (sFieldType = 'BCD') then
            begin
              cxGridDBBandedColumn.Options.Editing := False;
              cxGridDBBandedColumn.PropertiesClass := TcxCalcEditProperties;
            end;
          end;
          if (j = 0) and (AcxGrid1DBBandedTableView.Bands[j].Caption = '固定列') then
          begin
            AcxGrid1DBBandedTableView.Bands[j].FixedKind := fkLeft;
          end;
        end;
      end
      else
      begin
        cxGridBand := AcxGrid1DBBandedTableView.Bands.Add;
        cxGridBand.Caption := '';
        CaptionStr := qryTemp.Fields[i].FieldName;

        cxGridDBBandedColumn := AcxGrid1DBBandedTableView.CreateColumn;
        cxGridDBBandedColumn.Caption := CaptionStr;
        cxGridDBBandedColumn.DataBinding.FieldName := qryTemp.Fields[i].FieldName;
        cxGridDBBandedColumn.Position.BandIndex := AcxGrid1DBBandedTableView.Bands[cxGridBand.Index].Position.ColIndex;

        cxGridDBBandedColumn.HeaderAlignmentHorz := taCenter;
        cxGridDBBandedColumn.HeaderAlignmentVert := vaCenter;
        cxGridDBBandedColumn.Width :=  AcxGrid1DBBandedTableView.ViewInfo.Canvas.TextWidth(qryTemp.Fields[i].FieldName) + 10;

        if (sFieldType = 'FLOAT') or (sFieldType = 'BCD') then
        begin
          cxGridDBBandedColumn.Options.Editing := False;
          cxGridDBBandedColumn.PropertiesClass := TcxCalcEditProperties;
        end;
      end;

    end;
  finally
    qryTemp.EnableControls;
  end;
end;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值