2007-10-17 10:19:26 +00:00
|
|
|
unit exsortzeos;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2011-02-23 08:29:55 +00:00
|
|
|
Classes, SysUtils, DB, RxDBGrid, ZConnection, ZDataset, ZAbstractRODataset,
|
|
|
|
ZMacroQuery;
|
2007-10-17 10:19:26 +00:00
|
|
|
|
|
|
|
type
|
2011-01-08 12:26:10 +00:00
|
|
|
|
|
|
|
{ TZeosDataSetSortEngine }
|
|
|
|
|
|
|
|
TZeosDataSetSortEngine = class(TRxDBGridSortEngine)
|
2007-10-17 10:19:26 +00:00
|
|
|
public
|
2011-01-08 12:26:10 +00:00
|
|
|
procedure Sort(Field:TField; ADataSet:TDataSet; Asc:boolean; SortOptions:TRxSortEngineOptions);override;
|
2012-09-21 19:54:03 +00:00
|
|
|
procedure SortList(ListField: string; ADataSet: TDataSet; Asc: array of boolean; SortOptions: TRxSortEngineOptions); override;
|
2007-10-17 10:19:26 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2011-01-08 12:26:10 +00:00
|
|
|
procedure TZeosDataSetSortEngine.Sort(Field:TField; ADataSet:TDataSet; Asc:boolean; SortOptions:TRxSortEngineOptions);
|
2007-10-17 10:19:26 +00:00
|
|
|
begin
|
2011-02-23 08:29:55 +00:00
|
|
|
if not Assigned(ADataSet) then exit;
|
|
|
|
if ADataSet.ClassName='TZReadOnlyQuery' then
|
|
|
|
begin
|
|
|
|
(ADataSet as TZReadOnlyQuery).SortedFields:=Field.FieldName;
|
|
|
|
if Asc then
|
|
|
|
(ADataSet as TZReadOnlyQuery).SortType:=stAscending
|
|
|
|
else
|
|
|
|
(ADataSet as TZReadOnlyQuery).SortType:=stDescending;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if (ADataSet.ClassName='TZQuery') or (ADataSet is TZMacroQuery) then
|
|
|
|
begin
|
|
|
|
(ADataSet as TZQuery).SortedFields:=Field.FieldName;
|
2009-08-29 12:01:16 +00:00
|
|
|
if Asc then
|
2011-02-23 08:29:55 +00:00
|
|
|
(ADataSet as TZQuery).SortType:=stAscending
|
2009-08-29 12:01:16 +00:00
|
|
|
else
|
2011-02-23 08:29:55 +00:00
|
|
|
(ADataSet as TZQuery).SortType:=stDescending;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if ADataSet.ClassName='TZTable' then
|
|
|
|
begin
|
|
|
|
(ADataSet as TZTable).SortedFields:=Field.FieldName;
|
2009-08-29 12:01:16 +00:00
|
|
|
if Asc then
|
2011-02-23 08:29:55 +00:00
|
|
|
(ADataSet as TZTable).SortType:=stAscending
|
2009-08-29 12:01:16 +00:00
|
|
|
else
|
2011-02-23 08:29:55 +00:00
|
|
|
(ADataSet as TZTable).SortType:=stDescending;
|
|
|
|
end;
|
2007-10-17 10:19:26 +00:00
|
|
|
end;
|
|
|
|
|
2012-09-21 19:54:03 +00:00
|
|
|
procedure TZeosDataSetSortEngine.SortList(ListField: string;
|
|
|
|
ADataSet: TDataSet; Asc: array of boolean; SortOptions: TRxSortEngineOptions);
|
|
|
|
var
|
|
|
|
S:string;
|
|
|
|
i, C:integer;
|
2009-08-29 12:01:16 +00:00
|
|
|
begin
|
2011-02-23 08:29:55 +00:00
|
|
|
if not Assigned(ADataSet) then exit;
|
2012-09-21 19:54:03 +00:00
|
|
|
|
|
|
|
S:='';
|
|
|
|
C:=Pos(';', ListField);
|
|
|
|
i:=0;
|
|
|
|
while C>0 do
|
2011-02-23 08:29:55 +00:00
|
|
|
begin
|
2012-09-21 19:54:03 +00:00
|
|
|
if S<>'' then S:=S+';';
|
|
|
|
S:=S + Copy(ListField, 1, C-1);
|
|
|
|
Delete(ListField, 1, C);
|
|
|
|
|
|
|
|
if (i<=High(Asc)) and (not Asc[i]) then
|
|
|
|
S:=S + ' DESC';
|
|
|
|
C:=Pos(';', ListField);
|
|
|
|
inc(i);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if ListField<>'' then
|
|
|
|
begin
|
|
|
|
if S<>'' then S:=S+';';
|
|
|
|
S:=S + ListField;
|
|
|
|
if (i<=High(Asc)) and (not Asc[i]) then
|
|
|
|
S:=S + ' DESC';
|
|
|
|
end;
|
|
|
|
|
|
|
|
(ADataSet as TZAbstractRODataset).SortedFields:=S;
|
|
|
|
|
|
|
|
{ if ADataSet.ClassName='TZReadOnlyQuery' then
|
|
|
|
(ADataSet as TZReadOnlyQuery).SortedFields:=S
|
2011-02-23 08:29:55 +00:00
|
|
|
else
|
|
|
|
if (ADataSet.ClassName='TZQuery') or (ADataSet is TZMacroQuery) then
|
2012-09-21 19:54:03 +00:00
|
|
|
(ADataSet as TZQuery).SortedFields:=S
|
2011-02-23 08:29:55 +00:00
|
|
|
else
|
|
|
|
if ADataSet.ClassName='TZTable' then
|
|
|
|
begin
|
2012-09-21 19:54:03 +00:00
|
|
|
(ADataSet as TZTable).SortedFields:=S}
|
2009-08-29 12:01:16 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-10-17 10:19:26 +00:00
|
|
|
initialization
|
2011-01-08 12:26:10 +00:00
|
|
|
RegisterRxDBGridSortEngine(TZeosDataSetSortEngine, TZReadOnlyQuery);
|
|
|
|
RegisterRxDBGridSortEngine(TZeosDataSetSortEngine, TZQuery);
|
|
|
|
RegisterRxDBGridSortEngine(TZeosDataSetSortEngine, TZTable);
|
2011-02-23 08:29:55 +00:00
|
|
|
RegisterRxDBGridSortEngine(TZeosDataSetSortEngine, TZMacroQuery);
|
2007-10-17 10:19:26 +00:00
|
|
|
end.
|
|
|
|
|