1. TRxDBGrid - add new metod in RxSortEngine for calc total values

2. In TZeosDataSetSortEngine add metod for for calc total values in RxDBGrid
3. In TZeosDataSetSortEngine add metod for for calc total values in RxDBGrid
4. In TRxMemoryDataSortEngine add metod for for calc total values in RxDBGrid

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2705 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
alexs75
2013-03-19 13:45:06 +00:00
parent 8420f0cbf1
commit 0d0db64f45
5 changed files with 188 additions and 1 deletions

View File

@ -48,6 +48,9 @@ type
{ TFBDataSetSortEngine }
TFBDataSetSortEngine = class(TRxDBGridSortEngine)
protected
procedure UpdateFooterRows(ADataSet:TDataSet; AGrid:TRxDBGrid);override;
function EnabledFooterRowsCalc:boolean;override;
public
procedure Sort(Field:TField; ADataSet:TDataSet; Asc:boolean; SortOptions:TRxSortEngineOptions);override;
procedure SortList(ListField:string; ADataSet:TDataSet; Asc: array of boolean; SortOptions: TRxSortEngineOptions);override;
@ -56,6 +59,34 @@ type
implementation
uses FBCustomDataSet;
type
THackFBDataSet = class(TFBDataSet);
THackRxColumnFooter = class(TRxColumnFooter);
procedure TFBDataSetSortEngine.UpdateFooterRows(ADataSet: TDataSet;
AGrid: TRxDBGrid);
var
i,j:integer;
Col:TRxColumn;
begin
if not Assigned(ADataSet) then exit;
for i:=0 to ADataSet.RecordCount-1 do
begin
for j:=0 to AGrid.Columns.Count-1 do
begin
Col:=TRxColumn(AGrid.Columns[j]);
if THackRxColumnFooter(Col.Footer).ValueType in [fvtSum, fvtAvg, fvtMax, fvtMin] then
THackRxColumnFooter(Col.Footer).UpdateTestValueFromVar( THackFBDataSet(ADataSet).GetAnyRecField(i, ADataSet.FieldByName(Col.Footer.FieldName)));
end;
end;
end;
function TFBDataSetSortEngine.EnabledFooterRowsCalc: boolean;
begin
Result:=true;
end;
procedure TFBDataSetSortEngine.Sort(Field: TField; ADataSet: TDataSet;
Asc: boolean; SortOptions: TRxSortEngineOptions);
begin

View File

@ -12,12 +12,49 @@ type
{ TZeosDataSetSortEngine }
TZeosDataSetSortEngine = class(TRxDBGridSortEngine)
protected
procedure UpdateFooterRows(ADataSet:TDataSet; AGrid:TRxDBGrid);override;
function EnabledFooterRowsCalc:boolean;override;
public
procedure Sort(Field:TField; ADataSet:TDataSet; Asc:boolean; SortOptions:TRxSortEngineOptions);override;
procedure SortList(ListField: string; ADataSet: TDataSet; Asc: array of boolean; SortOptions: TRxSortEngineOptions); override;
end;
implementation
uses ZDbcIntfs, ZVariant;
type
THackZeosDS = class(TZAbstractRODataset);
THackRxColumnFooter = class(TRxColumnFooter);
procedure TZeosDataSetSortEngine.UpdateFooterRows(ADataSet: TDataSet;
AGrid: TRxDBGrid);
var
RS:IZResultSet;
CurRow, i:integer;
Col:TRxColumn;
begin
if not Assigned(ADataSet) then exit;
RS:=THackZeosDS(ADataSet).ResultSet;
CurRow:=RS.GetRow;
RS.First;
while not RS.IsLast do
begin
for i:=0 to AGrid.Columns.Count-1 do
begin
Col:=TRxColumn(AGrid.Columns[i]);
if THackRxColumnFooter(Col.Footer).ValueType in [fvtSum, fvtAvg, fvtMax, fvtMin] then
THackRxColumnFooter(Col.Footer).UpdateTestValueFromVar(EncodeVariant(RS.GetValueByName(Col.FieldName)));
end;
RS.Next;
end;
RS.MoveAbsolute(CurRow);
end;
function TZeosDataSetSortEngine.EnabledFooterRowsCalc: boolean;
begin
Result:=true;
end;
procedure TZeosDataSetSortEngine.Sort(Field:TField; ADataSet:TDataSet; Asc:boolean; SortOptions:TRxSortEngineOptions);
begin

View File

@ -185,6 +185,10 @@ type
TRxSortEngineOptions = set of TRxSortEngineOption;
TRxDBGridSortEngine = class
protected
FGrid:TRxDBGrid;
procedure UpdateFooterRows(ADataSet:TDataSet; AGrid:TRxDBGrid);virtual; abstract;
function EnabledFooterRowsCalc:boolean;virtual;
public
procedure Sort(Field: TField; ADataSet: TDataSet; Asc: boolean; SortOptions: TRxSortEngineOptions); virtual; abstract;
procedure SortList(ListField: string; ADataSet: TDataSet; Asc: array of boolean; SortOptions: TRxSortEngineOptions); virtual;
@ -254,6 +258,8 @@ type
function DeleteTestValue: boolean;
function PostTestValue: boolean;
function ErrorTestValue: boolean;
protected
procedure UpdateTestValueFromVar(AValue:Variant);
public
constructor Create(Owner: TRxColumn);
property Owner: TRxColumn read FOwner;
@ -779,7 +785,7 @@ procedure RegisterRxDBGridSortEngine(RxDBGridSortEngineClass: TRxDBGridSortEngin
implementation
uses Math, rxdconst, rxstrutils, rxdbgrid_findunit, rxdbgrid_columsunit,
rxlookup, tooledit, LCLProc, rxfilterby, rxsortby;
rxlookup, tooledit, LCLProc, rxfilterby, rxsortby, variants;
const
EditorCommandStrs: array[0..10] of TIdentMapEntry =
@ -3691,6 +3697,16 @@ begin
if not APresent then
exit;
if Assigned(FSortEngine) and (FSortEngine.EnabledFooterRowsCalc) then
begin
for i := 0 to Columns.Count - 1 do
TRxColumn(Columns[i]).Footer.ResetTestValue;
FSortEngine.UpdateFooterRows(DataSource.DataSet, Self);
exit;
end;
Inc(FInProcessCalc);
DS := DataSource.DataSet;
;
@ -4888,6 +4904,36 @@ begin
end;
end;
end;
procedure TRxColumnFooter.UpdateTestValueFromVar(AValue: Variant);
var
F: TField;
begin
if ValueType in [fvtSum, fvtAvg, fvtMax, fvtMin] then
begin
F := TRxDBGrid(FOwner.Grid).DataSource.DataSet.FindField(FFieldName);
if (not VarIsEmpty(AValue)) and (AValue <> null) and Assigned(F) then
begin
if F.DataType in [ftDate, ftTime, ftDateTime, ftTimeStamp] then
begin
case FValueType of
fvtMax: FTestValue := Max(FTestValue, AValue);
fvtMin: FTestValue := Min(FTestValue, AValue);
end;
end
else
begin
case FValueType of
fvtSum: FTestValue := FTestValue + AValue;
// fvtAvg:
fvtMax: FTestValue := Max(FTestValue, AValue);
fvtMin: FTestValue := Min(FTestValue, AValue);
end;
end;
end;
end;
end;
///!
constructor TRxColumnFooter.Create(Owner: TRxColumn);
begin
@ -4998,6 +5044,11 @@ end;
{ TExDBGridSortEngine }
function TRxDBGridSortEngine.EnabledFooterRowsCalc: boolean;
begin
Result:=false;
end;
procedure TRxDBGridSortEngine.SortList(ListField: string; ADataSet: TDataSet;
Asc: array of boolean; SortOptions: TRxSortEngineOptions);
begin

View File

@ -150,6 +150,7 @@ type
function GetRecNo: Integer; override;
procedure SetRecNo(Value: Integer); override;
property Records[Index: Integer]: TMemoryRecord read GetMemoryRecord;
function GetAnyRecField(SrcRecNo:integer; AField:TField):variant;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
@ -1323,6 +1324,41 @@ begin
end;
end;
function TRxMemoryData.GetAnyRecField(SrcRecNo: integer; AField: TField
): variant;
var
Data1: PChar;
I: Integer;
Item:TMemoryRecord;
begin
Item:=Records[SrcRecNo];
Data1 := FindFieldData(Item.Data, AField);
Inc(Data1); //Skip null flag
case AField.DataType of
ftString:Result := PChar(Data1);
ftSmallint:Result:=SmallInt(Data1^);
ftInteger,
ftDate,
ftTime,
ftAutoInc:Result:=Longint(Data1^);
ftWord:Result:=Word(Data1^);
ftBoolean:Result:=WordBool(Data1^);
ftFloat, ftCurrency:Result:=PDouble(Data1)^;
ftDateTime:Result:=PDateTime(Data1)^;
ftFixedChar:Result:=PChar(Data1);
ftWideString:Result:=PWideChar(Data1);
ftLargeint:Result:=Int64(Data1^);
ftVariant:
begin
Result := PVariant(Data1)^;
end;
ftGuid:Result:=PChar(Data1);
else
Result:=null;
end;
end;
function TRxMemoryData.IsSequenced: Boolean;
begin
Result := not Filtered;

View File

@ -43,6 +43,9 @@ type
{ TRxMemoryDataSortEngine }
TRxMemoryDataSortEngine = class(TRxDBGridSortEngine)
protected
procedure UpdateFooterRows(ADataSet:TDataSet; AGrid:TRxDBGrid);override;
function EnabledFooterRowsCalc:boolean;override;
public
procedure Sort(Field:TField; ADataSet:TDataSet; Asc:boolean; SortOptions:TRxSortEngineOptions);override;
procedure SortList(ListField:string; ADataSet:TDataSet; Asc: array of boolean; SortOptions: TRxSortEngineOptions);override;
@ -51,6 +54,35 @@ type
implementation
uses rxmemds;
type
THackRxMemoryData = class(TRxMemoryData);
THackRxColumnFooter = class(TRxColumnFooter);
procedure TRxMemoryDataSortEngine.UpdateFooterRows(ADataSet: TDataSet;
AGrid: TRxDBGrid);
var
i, j:integer;
Col:TRxColumn;
begin
if not Assigned(ADataSet) then exit;
for j:=0 to ADataSet.RecordCount-1 do
begin
for i:=0 to AGrid.Columns.Count-1 do
begin
Col:=TRxColumn(AGrid.Columns[i]);
if THackRxColumnFooter(Col.Footer).ValueType in [fvtSum, fvtAvg, fvtMax, fvtMin] then
THackRxColumnFooter(Col.Footer).UpdateTestValueFromVar( THackRxMemoryData(ADataSet).GetAnyRecField(j, ADataSet.FieldByName(Col.Footer.FieldName)));
end;
end;
end;
function TRxMemoryDataSortEngine.EnabledFooterRowsCalc: boolean;
begin
Result:=true;
end;
procedure TRxMemoryDataSortEngine.Sort(Field:TField; ADataSet:TDataSet;
Asc:boolean; SortOptions:TRxSortEngineOptions);
begin