General query component design (continued)

zhaozj2021-02-16  46

General query component design (continued)

Author: nxyc_twz@163.com

Some time ago, due to work, innocent documents, please understand! I will organize all relevant documents and source code for this component.

Set the default match type

Procedure tdbfilterdialog.setDefaultMatchType (const value: tdbfiltermatchty);

Begin

// Set the default match type

FDEFAULTMATCHPE: = Value;

IF assigned (fdialog) and not (csdesigning in componentstate) THEN

Case fdefaultmatchtype of

FDMATHNONE:

Begin

FDIALOG.GRPSEARCHPE.ITEMINDEX: = 0;

FDIALOG.CBXNONMATCHING.CHECKED: = TRUE;

END;

FDMATCHRANGE:

FDIALOG.PGECRITERIA.ACTIVEPAGE: = fdialog.tabbyrange;

Else

FDIALOG.GRPSEARCHPE.ITEMINDEX: = Integer (fdefaultmatchType);

END;

END;

Set field

Procedure TDBFILTERDIALOG.SETFIELDS;

VAR

I, J, P: Integer;

Field, Display: String;

Begin

// Set field

FDIALOG.LSTALLFIELDS.CLEAR; / / Clear all fields

IF ffields.count = 0 THEN

Begin

For i: = 0 to fdataset.fieldlist.count - 1 do

If fdatanet.fields [i] .visible life // Define Query Fields

FDIALOG.LSTALLFIELDS.ITEMS.ADDObject (fdataSet.fields [i] .displayName, fdatanet.fieldlist.fields [i]);

end

Else

For j: = 0 to ffields.count - 1 do

Begin

P: = POS (';', ffields.strings [j]);

Field: = COPY (Ffields.Strings [J], 1, P - 1);

IF P = Length (ffields.strings [j]) THEN

Display: = Field

Else

Display: = COPY (Ffields.Strings [J], P 1, Length (ffields.strings [j]));

For i: = 0 to fdataset.fieldlist.count - 1 do

if fdatanet.fieldlist.fields [i] .fieldname = field the

FDIALOG.LSTALLFIELDS.ITEMS.AddObject (Display, fdataSet.fieldList.fields [i]);

END;

IF fdialog.lstallfields.Items.count> 0 THEN

Begin

FDIALOG.LSTALLFIELDS.ITEMINDEX: = 0;

Fdialog.fieldsListBoxClick (nil); / / Click the list box

END;

END;

Set field list

Procedure TDBFILTERDIALOG.SETFIELDSLISL (Const Value: Tstringlist); Begin

/ / Set field list

Ffields.Assign (Value);

END;

Set SQL

Procedure TdbfilterDialog.setoriginalsql (Const Value: Tstrings);

VAR

i: integer;

Begin

/ / Set SQL statement

IF fortersql.text <> value.text dam

Begin

Foriginalsql.clear;

ForiginalSql.Addstrings (value);

IF not (cslineing in componentstate) THEN

Ffields.clear;

FDIALOG.NEWSQL; // New SQL query

END;

For i: = 0 to foriGinalvariables.count - 1 do

TDBVARIABLE (foriginalvariables [i]). Free; // Defines the parameter data variable class

ForiginalVariables.clear;

IF TSTRINGS (getordprop (fdataaset, sqlprop)). Text = '' Then

EXIT;

For i: = 0 to TQuery (fdataset) .Params.count - 1 DO

ForiginalVariables.Add (TDBVARIABLE.CREATE (TQuery (fdataaset) .Params [i] .name, tQuery (fdataset) .Params [i] .value)); / / Define Parameter Data Variable Class

SetFields; // Set field

END;

Restore SQL

Procedure tdbfilterdialog.restoresql;

VAR

i: integer;

Begin

/ / Restore SQL statement

// disable the controls while we are working

FDataSet.disableControls;

FDataSet.Close;

// clear the existing sql and variable declarations

// restore the Original SQL and Variables

SetordProp (FDataSet, Sqlprop, Integer (forterSQL);

If fdatanet is tdatathten

For i: = 0 to foriGinalvariables.count - 1 do

TQuery (fdataaset) .Parambyname (tdbvariable (foriginalvariables [i]). Variablename) .Value: =

TDBVARIABLE (ForiginalVariables [i]). VariableValue

Else

For i: = 0 to foriGinalvariables.count - 1 do

TQuery (fdataaset) .Parambyname (tdbvariable (foriginalvariables [i]). Variablename) .Value: =

TDBVARIABLE (foriginalvariables [i]). VariableValue;

FDataSet.Open;

Setfields;

FDataSet.enableControls;

Fmodifiedsql.assign (Tstrings (getordprings (fdataset, sqlprop));

END;

Save the parameter value

Procedure tdbfilterdialog.saveparamvalues; var

i: integer;

Begin

/ / Save the parameter value

If fdatanet is tdatathten

For i: = 0 to foriGinalvariables.count - 1 do

TDBVARIABLE (foriginalvariables [i]). VariableValue: =

TQuery (fdataset) .Parambyname (tdbvariable (foriginalvariables [i]). Variablename) .value

Else

For i: = 0 to foriGinalvariables.count - 1 do

TDBVARIABLE (foriginalvariables [i]). VariableValue: =

TQuery (fdataset) .Parambyname (tdbvariable (foriginalvariables [i]). Variablename) .value;

END;

Load filter dialog

Procedure tdbfilterdialog.loaded;

VAR

i: integer;

Begin

inherited;

IF assigned (fdataset) and not (csdesigningin company) THEN

Begin

Setfields;

Originalsql.assign (Tstrings (getordprings));

For i: = 0 to TQuery (fdataset) .Params.count - 1 DO

ForiginalVariables.Add (TDBVARIABLE.CREATE (TQuery (fdataset) .Params [i] .name,

TQuery (fdataset) .Params [i] .value);

END;

END;

Transmit message

Procedure tdbfilterdialog.Notification (Acomponent: Tcomponent;

Operation: TOPERATION);

Begin

inherited;

IF (ACOMPONENT = fdatanet) and (Operation = Opremove) THEN

FDataSet: = NIL;

END;

Constructor

Constructor TDBFilterDialog.create (Aowner: Tcomponent);

Begin

//Constructor

Inherited Create (Aowner);

FDIALOG: = TMYDBFILTERDIALOG.CREATE (Self);

FOPTIONS: = [fdshowcasensensitive, fdshownonmatching];

FDEFAULTMATCHPE: = fdmatchstart;

Caption: = SDBFILTERCAPTION;

Ffields: = tstringlist.create;

Foriginalsql: = TSTRINGLIST.CREATE;

FMODIFIEDSQL: = TSTRINGLIST.CREATE;

ForiginalVariables: = TLIST.CREATE;

END;

Destructor

Destructor TdbfilterDialog.destroy;

VAR

i: integer;

Begin

FDIALOG.FREE;

Ffields.free;

Foriginalsql.Free;

Fmodifiedsql.free;

For i: = 0 to foriGinalVariables.count - 1 DotdbVariable (foriginalvariables [i]).

ForiginalVariables.Free;

Inherited destroy;

END;

Execute query

Function TDBFILTERDIALOG.EXECUTE: BOOLEAN;

VAR

Currentsql: tstrings;

Begin

// Execute data query

Currentsql: = Tstrings (getordprings (fdataaset, sqlprop);

/ / Check if the SQL statement has changed

IF not fmodifiedsql.equals (currentsql) THEN

Originalsql: = Currentsql;

IF fdialog.lstallfields.Items.count = 0 THEN

Setfields;

FDIALOG.GRPSEARCHPE.ITEMINDEX: = Integer (fdefaultmatchType);

IF fdshowcasensensitive in options the

FDIALOG.CBXCaseSensitive.visible: = TRUE

Else

FDIALOG.CBXCaseSensitive.visible: = false;

IF fdshownonmatch in options

FDIALOG.CBXNONMATCHING.Visible: = TRUE

Else

FDIALOG.CBXNONMATCHING.Visible: = FALSE

IF fdcasensitive in options the

FDIALOG.CBXCaseSensitive.Checked: = TRUE

Else

FDIALOG.CBXCaseSensitive.Checked: = false;

SaveParamvalues; // Save the parameter value

Result: = fdialog.showmodal = mrok; // Click the OK button

IF results

Rebuildsql; // Rebuild SQL statement

END;

转载请注明原文地址:https://www.9cbs.com/read-26396.html

New Post(0)