Combination query

zhaozj2021-02-08  221

use

PB

When developing a database application system, we often filter, query, and query, which requires a record of compliance, which requires the combined condition query function. When I was developed in the application system, I wrote a simple and practical combination condition query template window. It is very convenient to inherit from this window as long as the combined condition query is used. Here is to give its implementation method.

First, build a DataObject object of an external data source, named: D_Tabular_Query, each column as follows:

Name TypeelenthDeccolumn_nameString10 CompareString3 Valuestring255 and_orstring3

Second, build a window W_Condition_Query_Template, Title Set to: "Composite Condition Query Window Template" and join the control:

Control Name Type Description dw_query_condition datawindow to enter the query Datawindow Object Name was built before the DataWindow object d_tabular_query cb_add command button to add a query cb_del command button to delete a query cb_ins command button to insert a query cb_clear command button to clear all the conditions Inquiry The CB_OK Command Button is obtained by the query criteria DW_Query DataWindow query result DataWindow Object Name is empty, and the sub-window after inheritance is added. CB_all Command Button Displays all records CB_PrintCommand Button print query results CB_EXIT Command Button exits the three, write scripts 1, add the following scripts in dw_query_condition's Constractor event: // --------------- --------------------------------------------//// Function Description : Depending on Data Window DW_QUERY Set the Combined Item, for a combination query selection // Notes: Data window DW_QUERY objects in the object of Data window must use the default value, // ie: column name _T // Ke Jianxun on April 27, 1999 day//----------------------------------------------- ---------------------- // long ll_column_count long ll_ilong ll_rowstring ls_columnstring ls_column_namethis.setTransObject (SQLCA) LL_ROW = this.inSertrow (0) this.setItem LL_ROW, 'Compare', '=') This.SetItem (LL_ROW, 'AND_OR', 'AND') LL_COLUMN_COUNT = Long (dw_query.describe ("DataWindow.Column.count") // Total number this.clearvalues "column_name") for ll_i = 1 to ll_column_count if dw_query.describe ("#" string (ll_i) ". Visible") = '1' Then LS_COLUMN = dw_query.describe ("#" string (ll_i) " .Name ") // Column name LS_COLUMN_NAME = dw_query.describe (ls_column " _t.text ") // Column name corresponding text this.setValue (" Column_name ", LL_i, LS_COLUMN_NAME " ~ T " LS_COLUMN) End ifnext2, define the user event UE_ENTERKEYDOWN of DW_QUERY_CONDITION, Event ID Select PBM_DWnProcessenter. This event will be triggered when we press the Enter key. Add the following script in the UE_EnterKeyDown event:

// Enter (ENTER) switch column focus LONG LL_COLUMN_COUNT Long LL_COLUMN

ll_column_count = long (this.Describe ( "DataWindow.Column.Count")) ll_column = this.getcolumn () if ll_column = ll_column_count then cb_add.triggerevent (clicked!) // add a line else this.setcolumn (ll_column 1) end if 3, in the event cb_add Clicked added: long ll_row ll_row = dw_query_condition.insertrow (0) dw_query_condition.setitem (ll_row, 'compare', '=') dw_query_condition.setitem (ll_row, 'and_or', 'and') dw_query_condition. SetColumn (1) 4, is added at Clicked event cb_del: long ll_rowll_row = dw_query_condition.getrow () dw_query_condition.DeleteRow (ll_row) 5, was added in the Clicked event cb_ins: long ll_rowlong ll_new_rowll_row = dw_query_condition.getrow () ll_new_row = dw_query_condition.InsertRow (ll_row) dw_query_condition.setitem (ll_new_row, 'compare', '=') dw_query_condition.setitem (ll_new_row, 'and_or', 'and') dw_query_condition.SetColumn (1) 6, in the event cb_clear Clicked added: long ll_row dw_query_condition. RESET () LL_ROW = dw_query_condition.insertrow (0) dw_query_condition.setitem (ll_row, 'compare', '=') dw_query_condition.setitem (ll_row, 'and_or', 'and') 7, in CB_O K in the Clicked event Add: // -------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------- /// Condition combination Query Ke Jianxun 1999.04.27 // -------- -------------------------------------------------- ------------- // long ll_rowcountlong ll_rowlong ll_jstring ls_filter_conditionstring ls_columnstring ls_comparestring ls_valuestring ls_and_orstring ls_column_type if dw_query_condition.AcceptText () = -1 then returnll_rowcount = dw_query_condition.rowcount () if ll_rowcount <= 0 then returnls_filter_condition = 'FOR LL_ROW = 1 to LL_ROWCOUNT LS_COLUMN =

dw_query_condition.getitemstring (ll_row, 'column_name') ls_compare = dw_query_condition.getitemstring (ll_row, 'compare') ls_value = dw_query_condition.getitemstring (ll_row, 'value') ls_and_or = dw_query_condition.getitemstring (ll_row, 'and_or') ls_column_type = dw_query. Describe (ls_column ".ColType") // ls_column_type = left (ls_column_type, 3) if ll_row = ll_rowcount then // last line (without and, or) choose case ls_column_type // set the Filter conditions case 'cha' according to the data type , 'var', 'str' // character type LS_FILTER_CONDITION = LS_FILTER_CONDITION & LS_COLUMN LS_COMPARE "" LS_VALUE "'" Case' Num ',' DEC ',' LON ',' REA ',' ULO ' // Value type LS_FILTER_CONDITION = LS_FILTER_CONDITION & LS_COLUMN LS_COMPARE LS_VALUE CASE 'DAT', 'TIM' // Date type LS_FILTER_CONDITION = LS_FILTER_CONDITION STRING (" & ls_column ")" ls_compare "" LS_VALUE "" Case Else End Choose Else Choose Case LS_COLUMN_TYPE / / FILTER CASE 'CHA', 'Var', 'Str' // Character_filter_Condition = LS_FILTER_CONDITION & Ls_column ls_compare "'" ls_value "'"

ls_and_or "Case 'Num', 'DEC', 'LON', 'REA', 'ULO' // Value LS_FILTER_CONDITION = LS_FILTER_CONDITION & LS_COLUMN LS_COMPARE LS_VALUE " & LS_AND_OR "" Case ' dat ',' tim '// date type ls_filter_condition = ls_filter_condition "string (" & ls_column ")" ls_compare "" ls_value "'" & ls_and_or "" case else end choose end ifnext dw_query.setredraw ( false) dw_query.setFilter (ls_filter_condition) if dw_query.filter () = 1 and dw_query.rowcount ()> 0 then ls_column = dw_query_condition.getitemstring (1, 'column_name') dw_query.setsort (ls_column 'A') dw_query.sort () Dw_query.setColumn (ls_column) dw_query.selectrow (0, false) dw_query.selectrow (1, true) dw_query.setrow (1) end ifdw_query.setredraw (true) 8, in dw_quer The following script is added to the Y's Constractor event:

This.Object.dataWindow.readOnly = "Yes" this.settransobject (sqlca) this.ReTrieve () if this.rowcount ()> 0 dam.selectrow (0, false) this.selectrow (1, true) this.seture (1) end if

9. Add: in CB_all Clicked Events:

DW_QUERY.SETFILTER ('') dw_query.filter () IF dw_query.rowcount ()> 0 THEN DW_QUERY.SELECTROW (0, false) dw_query.selectrow (1, true) dw_query.setrow (1) end ifdw_query.setfocus ()

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

New Post(0)