DBGridEh 使用 UniDAC访问数据时的过滤及排序问题

使用下面的代码能正常过滤

function DateValueToMyDacSQLStringProc(DataSet: TDataSet; Value: Variant): String;
begin
Result := DateValueToDataBaseSQLString(‘MYSQL’, Value)
end;

procedure Tfrm_pin.DBGridEh1ApplyFilter(Sender: TObject);
var
Exp: string;
begin
Exp:=GetExpressionAsFilterString(TDBGridEh(Sender), GetOneExpressionAsSQLWhereString, DatevalueToMyDacSQLStringProc, True);
t_kc.FilterSQL:=Exp;
end;
//——————————–以上部份是我自己用的,下面的是网上的朋友写的,我没测试过.

unit EhLibUniDac;

{$I EhLib.Inc}

interface

uses
DbUtilsEh, DBGridEh, Db, DBAccess, Uni, UniDacVcl, VirtualTable;

type
TUniQuerySQLDatasetFeaturesEh = class(TSQLDatasetFeaturesEh)
public
constructor Create; override;
procedure ApplyFilter(Sender: TObject; DataSet: TDataSet; IsReopen: Boolean); override;
end;

TUniTableSQLDatasetFeaturesEh = class(TDatasetFeaturesEh)
public
procedure ApplySorting(Sender: TObject; DataSet: TDataSet; IsReopen: Boolean); override;
procedure ApplyFilter(Sender: TObject; DataSet: TDataSet; IsReopen: Boolean); override;
end;

TVirtualTableSQLDatasetFeaturesEh = class(TDatasetFeaturesEh)
public
procedure ApplyFilter(Sender: TObject; DataSet: TDataSet; IsReopen: Boolean); override;
end;

implementation

function DateValueToMyDacSQLStringProc(DataSet: TDataSet; Value: Variant): String;
begin
Result := DateValueToDataBaseSQLString(‘MYSQL’, Value)
end;

{ TUniQuerySQLDatasetFeaturesEh }

constructor TUniQuerySQLDatasetFeaturesEh.Create;
begin
inherited Create;
SortUsingFieldName := True;
DateValueToSQLString := DateValueToMyDacSQLStringProc;
end;

procedure TUniQuerySQLDatasetFeaturesEh.ApplyFilter(Sender: TObject; DataSet: TDataSet; IsReopen: Boolean);
begin
if TDBGridEh(Sender).STFilter.Local
then DataSet.Filter := GetExpressionAsFilterString(TDBGridEh(Sender), GetOneExpressionAsLocalFilterString, nil)
else (DataSet as TUniQuery).FilterSQL := GetExpressionAsFilterString(TDBGridEh(Sender), GetOneExpressionAsSQLWhereString, DateValueToMyDacSQLStringProc, True)
end;

{ TUniTableSQLDatasetFeaturesEh }

procedure TUniTableSQLDatasetFeaturesEh.ApplySorting(Sender: TObject; DataSet: TDataSet; IsReopen: Boolean);
var
i: Integer;
sOrderFields: String;
begin
If Sender is TCustomDBGridEh then
With TCustomDBGridEh(Sender) do
begin
sOrderFields := ”;
If SortMarkedColumns.Count>0 then
For i := 0 to SortMarkedColumns.Count – 1 do
begin
sOrderFields := sOrderFields + SortMarkedColumns[i].FieldName;
If SortMarkedColumns[i].Title.SortMarker = smUpEh then
sOrderFields := sOrderFields + ‘ DESC’;
sOrderFields := sOrderFields + ‘,’
end;
Delete(sOrderFields,Length(sOrderFields),1);
(DataSet as TUniTable).OrderFields := sOrderFields;
End
end;

procedure TUniTableSQLDatasetFeaturesEh.ApplyFilter(Sender: TObject; DataSet: TDataSet; IsReopen: Boolean);
begin
if TDBGridEh(Sender).STFilter.Local
then DataSet.Filter := GetExpressionAsFilterString(TDBGridEh(Sender), GetOneExpressionAsLocalFilterString, nil)
else (DataSet as TUniQuery).FilterSQL := GetExpressionAsFilterString(TDBGridEh(Sender), GetOneExpressionAsSQLWhereString, DateValueToMyDacSQLStringProc, True)
end;

{ TVirtualTableSQLDatasetFeaturesEh }

procedure TVirtualTableSQLDatasetFeaturesEh.ApplyFilter(Sender: TObject; DataSet: TDataSet; IsReopen: Boolean);
begin
DataSet.Filter := GetExpressionAsFilterString(TDBGridEh(Sender), GetOneExpressionAsLocalFilterString, nil)
end;

initialization
RegisterDatasetFeaturesEh(TUniQuerySQLDatasetFeaturesEh, TUniQuery);
RegisterDatasetFeaturesEh(TUniTableSQLDatasetFeaturesEh, TUniTable);
RegisterDatasetFeaturesEh(TVirtualTableSQLDatasetFeaturesEh, TVirtualTable);
end.

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注

− 1 = 1