Автор: vladman
Дата сообщения: 28.06.2010 16:28
Cryogen2003
Вот, что получилось реализовать касательно вашего вопроса по PivotGrid.
[more=.pas]
unit Unit12;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, dxmdaset, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters, cxStyles, dxSkinsCore,
dxSkinMcSkin, dxSkinscxPCPainter, cxCustomData, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData,
cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
cxCustomPivotGrid, cxDBPivotGrid;
type
TForm12 = class(TForm)
dxMemData1: TdxMemData;
DataSource1: TDataSource;
dxMemData1Employee: TStringField;
dxMemData1Region: TIntegerField;
dxMemData1Date: TDateField;
dxMemData1Clients: TIntegerField;
dxMemData1AcceptedClients: TIntegerField;
cxDBPivotGrid1: TcxDBPivotGrid;
procedure FormCreate(Sender: TObject);
procedure DoCalculateQuality(Sender: TcxPivotGridField; ASummary: TcxPivotGridCrossCellSummary);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form12: TForm12;
implementation
{$R *.dfm}
function VarToInteger(const AValue: Variant): Integer;
begin
Result := 0;
if not VarIsNull(AValue) then
Result := AValue;
end;
procedure TForm12.FormCreate(Sender: TObject);
begin
dxMemData1.LoadFromTextFile('Data.txt');
dxMemData1.Active := True;
cxDBPivotGrid1.CreateAllFields;
cxDBPivotGrid1.Fields[1].Area := faRow;
cxDBPivotGrid1.Fields[2].Area := faRow;
cxDBPivotGrid1.Fields[4].Area := faData;
cxDBPivotGrid1.Fields[5].Area := faData;
with cxDBPivotGrid1.CreateField do
begin
Area := faData;
Caption := 'Quality';
Visible := True;
SummaryType := stCustom;
OnCalculateCustomSummary := DoCalculateQuality;
end;
dxMemData1.Refresh;
end;
procedure TForm12.DoCalculateQuality(Sender: TcxPivotGridField; ASummary: TcxPivotGridCrossCellSummary);
var
vAcceptedClients: Integer;
vClients: Integer;
begin
vClients := VarToInteger(ASummary.Owner.GetSummaryByField( cxDBPivotGrid1.Fields[4], stSum));
vAcceptedClients := VarToInteger(ASummary.Owner.GetSummaryByField( cxDBPivotGrid1.Fields[5], stSum));
if vClients <> 0 then
ASummary.Custom := vAcceptedClients / vClients * 100;
end;
end.
[/more]
[more=.dfm]
object Form12: TForm12
Left = 0
Top = 0
Caption = 'Form12'
ClientHeight = 702
ClientWidth = 1006
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object cxDBPivotGrid1: TcxDBPivotGrid
Left = 32
Top = 72
Width = 913
Height = 593
DataSource = DataSource1
Groups = <>
TabOrder = 0
end
object dxMemData1: TdxMemData
Indexes = <>
SortOptions = []
Left = 16
Top = 16
object dxMemData1Employee: TStringField
FieldName = 'Employee'
end
object dxMemData1Region: TIntegerField
FieldName = 'Region'
end
object dxMemData1Date: TDateField
FieldName = 'Date'
end
object dxMemData1Clients: TIntegerField
FieldName = 'Clients'
end
object dxMemData1AcceptedClients: TIntegerField
FieldName = 'AcceptedClients'
end
end
object DataSource1: TDataSource
DataSet = dxMemData1
Left = 48
Top = 16
end
end
[/more]
[more=Data.txt]
Employee Region Date Clients AcceptedClients
aa 5 27.07.2010 46 28
bb 5 30.06.2010 17 7
cc 2 21.07.2010 11 4
dd 6 16.07.2010 13 1
ee 6 22.07.2010 16 5
ff 2 18.07.2010 2 1
aa 8 12.07.2010 4 3
bb 3 18.07.2010 25 8
cc 7 17.07.2010 14 11
dd 2 01.07.2010 14 12
ee 2 15.07.2010 32 5
ff 2 05.07.2010 21 13
aa 5 28.07.2010 28 17
bb 6 24.07.2010 36 3
cc 6 20.07.2010 9 1
dd 8 20.07.2010 15 3
ee 3 23.07.2010 16 12
ff 5 26.07.2010 6 5
aa 1 17.07.2010 42 14
bb 6 21.07.2010 12 11
cc 5 10.07.2010 25 14
dd 5 29.06.2010 17 1
ee 7 14.07.2010 9 2
ff 3 14.07.2010 8 6
aa 4 14.07.2010 32 21
bb 2 10.07.2010 23 5
cc 2 26.07.2010 37 25
dd 1 01.07.2010 12 8
ee 9 30.06.2010 38 4
ff 9 13.07.2010 3 2
aa 8 18.07.2010 23 22
bb 7 13.07.2010 50 10
cc 2 08.07.2010 43 14
dd 9 14.07.2010 15 12
ee 5 06.07.2010 28 5
ff 2 04.07.2010 12 5
aa 10 27.07.2010 40 12
bb 10 26.07.2010 38 16
cc 10 24.07.2010 4 1
dd 9 22.07.2010 32 23
ee 10 26.07.2010 10 8
ff 9 15.07.2010 44 29
aa 6 10.07.2010 24 22
bb 4 05.07.2010 8 5
cc 5 13.07.2010 23 16
dd 3 02.07.2010 16 2
ee 4 15.07.2010 46 3
ff 5 25.07.2010 10 2
aa 9 23.07.2010 4 2
[/more]
Мое мнение - в Pivot нет необходимости давать уже сгруппированные данные. В том то и задача Pivotа самому выполнять всевозможные группировки и, что немаловажно, самим пользователем.
По поводу Скедюлера - чуть позже.