cxfiltercontrolutils.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 425 行 · 第 1/2 页
PAS
425 行
{********************************************************************}
{ }
{ Developer Express Visual Component Library }
{ ExpressFilterControl }
{ }
{ Copyright (c) 1998-2008 Developer Express Inc. }
{ ALL RIGHTS RESERVED }
{ }
{ The entire contents of this file is protected by U.S. and }
{ International Copyright Laws. Unauthorized reproduction, }
{ reverse-engineering, and distribution of all or any portion of }
{ the code contained in this file is strictly prohibited and may }
{ result in severe civil and criminal penalties and will be }
{ prosecuted to the maximum extent possible under the law. }
{ }
{ RESTRICTIONS }
{ }
{ THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES }
{ (DCU, OBJ, DLL, ETC.) ARE CONFIDENTIAL AND PROPRIETARY TRADE }
{ SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS }
{ LICENSED TO DISTRIBUTE THE EXPRESSEDITORS AND ALL }
{ ACCOMPANYING VCL CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY. }
{ }
{ THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED }
{ FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE }
{ COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE }
{ AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT }
{ AND PERMISSION FROM DEVELOPER EXPRESS INC. }
{ }
{ CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON }
{ ADDITIONAL RESTRICTIONS. }
{ }
{********************************************************************}
unit cxFilterControlUtils;
{$I cxVer.inc}
interface
uses
{$IFDEF DELPHI6}
Variants,
{$ELSE}
cxVariants,
{$ENDIF}
Classes, Controls, Forms, SysUtils, cxClasses, cxDataStorage, cxEdit, cxFilter;
type
TcxFilterControlOperator = (fcoNone, fcoEqual, fcoNotEqual, fcoLess,
fcoLessEqual, fcoGreater, fcoGreaterEqual, fcoLike, fcoNotLike,
fcoBlanks, fcoNonBlanks, fcoBetween, fcoNotBetween, fcoInList,
fcoNotInList, fcoYesterday, fcoToday, fcoTomorrow,
fcoLast7Days, fcoLastWeek, fcoLast14Days, fcoLastTwoWeeks, fcoLast30Days, fcoLastMonth, fcoLastYear, fcoInPast,
fcoThisWeek, fcoThisMonth, fcoThisYear,
fcoNext7Days, fcoNextWeek, fcoNext14Days, fcoNextTwoWeeks, fcoNext30Days, fcoNextMonth, fcoNextYear, fcoInFuture);
TcxFilterControlOperators = set of TcxFilterControlOperator;
EcxFilterControlError = class(Exception);
{ TcxCustomFilterEditHelper }
TcxCustomFilterEditHelper = class
protected
class procedure ClearPropertiesEvents(AProperties: TcxCustomEditProperties); virtual;
class procedure InitializeEdit(AEdit: TcxCustomEdit;
AEditProperties: TcxCustomEditProperties); virtual;
class function IsIDefaultValuesProviderNeeded(
AEditProperties: TcxCustomEditProperties): Boolean; virtual;
public
class function EditPropertiesHasButtons: Boolean; virtual;
class function GetFilterEdit(AEditProperties: TcxCustomEditProperties;
AInplaceEditList: TcxInplaceEditList = nil): TcxCustomEdit;
class function GetFilterEditClass: TcxCustomEditClass; virtual;
class procedure GetFilterValue(AEdit: TcxCustomEdit;
AEditProperties: TcxCustomEditProperties; var V: Variant; var S: TCaption); virtual;
class function GetSupportedFilterOperators(
AProperties: TcxCustomEditProperties;
AValueTypeClass: TcxValueTypeClass;
AExtendedSet: Boolean = False): TcxFilterControlOperators; virtual;
class procedure InitializeProperties(AProperties,
AEditProperties: TcxCustomEditProperties; AHasButtons: Boolean); virtual;
class function IsValueValid(AValueTypeClass: TcxValueTypeClass;
var AValue: Variant): Boolean; virtual;
class procedure SetFilterValue(AEdit: TcxCustomEdit;
AEditProperties: TcxCustomEditProperties; AValue: Variant); virtual;
class function UseDisplayValue: Boolean; virtual;
end;
TcxCustomFilterEditHelperClass = class of TcxCustomFilterEditHelper;
{ TcxFilterEditsController }
TcxFilterEditsController = class(TcxRegisteredClassList)
private
function GetItemClass(AItemClass: TClass): TClass;
public
function FindHelper(APropertiesClass: TClass): TcxCustomFilterEditHelperClass;
procedure Register(AItemClass, ARegisteredClass: TClass); override;
procedure Unregister(AItemClass, ARegisteredClass: TClass); override;
end;
function GetFilterOperatorKind(AOperator: TcxFilterControlOperator): TcxFilterOperatorKind;
function GetFilterControlOperator(AOperatorKind: TcxFilterOperatorKind; AIsNull: Boolean): TcxFilterControlOperator;
procedure CorrectDlgParams(var Params: TCreateParams);
procedure FilterControlError(const Msg: string);
procedure FilterControlValidateValue(AEdit: TcxCustomEdit; var AValue: Variant;
AOperator: TcxFilterControlOperator; AValueTypeClass: TcxValueTypeClass;
AFilterEditHelper: TcxCustomFilterEditHelperClass);
function FilterEditsController: TcxFilterEditsController;
function GetFilterControlOperatorText(AOperator: TcxFilterControlOperator): string;
implementation
uses
cxFilterConsts, cxFilterControlStrs;
var
FController: TcxFilterEditsController;
function GetFilterOperatorKind(AOperator: TcxFilterControlOperator): TcxFilterOperatorKind;
const
OperatorMap: array[TcxFilterControlOperator] of TcxFilterOperatorKind = (
foEqual, foEqual, foNotEqual, foLess, foLessEqual,
foGreater, foGreaterEqual, foLike, foNotLike,
foEqual, foNotEqual, // blank - non blank
foBetween, foNotBetween, foInList, foNotInList, foYesterday, foToday, foTomorrow,
foLast7Days, foLastWeek, foLast14Days, foLastTwoWeeks, foLast30Days, foLastMonth, foLastYear, foInPast,
foThisWeek, foThisMonth, foThisYear,
foNext7Days, foNextWeek, foNext14Days, foNextTwoWeeks, foNext30Days, foNextMonth, foNextYear, foInFuture);
begin
Result := OperatorMap[AOperator];
end;
function GetFilterControlOperator(AOperatorKind: TcxFilterOperatorKind; AIsNull: Boolean): TcxFilterControlOperator;
const
OperatorKindMap: array[TcxFilterOperatorKind] of TcxFilterControlOperator = (
fcoEqual, fcoNotEqual, fcoLess, fcoLessEqual, fcoGreater, fcoGreaterEqual,
fcoLike, fcoNotLike, fcoBetween, fcoNotBetween, fcoInList, fcoNotInList,
fcoYesterday, fcoToday, fcoTomorrow,
fcoLast7Days, fcoLastWeek, fcoLast14Days, fcoLastTwoWeeks, fcoLast30Days, fcoLastMonth, fcoLastYear, fcoInPast,
fcoThisWeek, fcoThisMonth, fcoThisYear,
fcoNext7Days, fcoNextWeek, fcoNext14Days, fcoNextTwoWeeks, fcoNext30Days, fcoNextMonth, fcoNextYear, fcoInFuture);
ExtOperatorKindMap: array[Boolean] of TcxFilterControlOperator =
(fcoNonBlanks, fcoBlanks);
begin
Result := OperatorKindMap[AOperatorKind];
if (Result in [fcoEqual, fcoNotEqual]) and AIsNull then
Result := ExtOperatorKindMap[Result = fcoEqual];
end;
procedure CorrectDlgParams(var Params: TCreateParams);
var
I: Integer;
AActiveForm: TForm;
begin
AActiveForm := Screen.ActiveForm;
if AActiveForm <> nil then
begin
for I := 0 to Screen.FormCount - 1 do
if (Screen.Forms[I] <> AActiveForm) and (Screen.Forms[I].FormStyle = fsStayOnTop) then
begin
AActiveForm := nil;
break;
end;
end;
if AActiveForm <> nil then
Params.WndParent := AActiveForm.Handle;
end;
procedure FilterControlError(const Msg: string);
begin
raise EcxFilterControlError.Create(Msg);
end;
procedure FilterControlValidateValue(AEdit: TcxCustomEdit; var AValue: Variant;
AOperator: TcxFilterControlOperator; AValueTypeClass: TcxValueTypeClass;
AFilterEditHelper: TcxCustomFilterEditHelperClass);
var
AError: Boolean;
begin
if AValueTypeClass = nil then
Exit;
if VarIsStr(AValue) and (AValue = '') and not AValueTypeClass.IsString then
AValue := Null;
if VarIsNull(AValue) or (AOperator in [fcoLike, fcoNotLike]) then
Exit;
AError := True;
try
AError := not AFilterEditHelper.IsValueValid(AValueTypeClass, AValue);
finally
if AError then
begin
FilterControlError(cxGetResourceString(@cxSFilterDialogInvalidValue));
AEdit.EditModified := True;
if (AEdit <> nil) and AEdit.CanFocusEx then
AEdit.SetFocus;
end;
end;
end;
function FilterEditsController: TcxFilterEditsController;
begin
if FController = nil then
FController := TcxFilterEditsController.Create;
Result := FController;
end;
function GetFilterControlOperatorText(AOperator: TcxFilterControlOperator): string;
begin
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?