Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Presentation Tier from Data Tier
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00844369
Message ID:
00844382
Views:
18
Hi Neil

I've resolved that problem with a generic query by example function. I have
a tool bar with buttons to create, delete, update, navigation and QBE.
My QBE fucntion create a parameterized cursorapater or remote view like this:

1. I have properties in my form to know the table that I want to consult,
the query field, the order field.
2. All controls in the form have property search by default is .T.

3. All datasources of controls with searh =.T. are changed the datasource to
variable

4. Press the query button and build your query for example: In a customer
form I want to searh in the filed name all customers with the name Carlos
then I type Carlos in this filed and the last name that begin with M, then
I type M% in that field.

5. preess the answer button

6. create the where sentence

7. create the cursor with the answer. This cursor has the same name in all
my forms. I named CONSULTA

8. When I got a result I begin to navigate over the cursor consulta, usually
this cursor content only index, so when I press the next button or previous
button I'm over this cursor, but I use this cursor to provide the parameter
for my other views for example: In my form customer I have tree
cursoradapters, the customer, customer_invoices, customer_accounts
so when I press the query and consult for the customers with name
is "Carlos" and the Lastname begins with "M%" I get a cursor with 10 records
for example, this cursor can hidden or in a treeview, I select this
cursor "Consulta" and get the field of the first record (I named the field
like "KEY") so, CONSULTA.KEY is the parameter to requery my Customer view,
and is the parameter to requery customer_invoices and customer_accounts.
So I'm navigating like in a desktop form, but really It's a n/tier form.

I'm using this approach with local tables, remote views with SQL Server,
Sybase, Oracle, and know with big clients using webservices.



lcCampoConsulta=thisform.queryfield
lcCamporOrde=thisform.orderfield
lcFrom = thisform.fromtable
lcWhere= this.parent.build_where()

m.lnObjetos=THISFORM.CONTROLCOUNT
FOR i = 1 TO m.lnObjetos
m.variable = " "
o=THISFORM.CONTROLS(i)
IF (o.CLASS="Combo" OR o.CLASS= "Activtxt" OR o.CLASS="Cajaedicion" ;
OR o.CLASS="Botonesdeopciones" OR o.CLASS="Botonlistaview")
IF o.busqueda=.T.
m.variable= "bc"+o.NAME
&variable="%"
ENDIF
ENDIF
ENDFOR

m.lcSelectCmd="SELECT " +lcCampoConsulta + " FROM "+lcfrom +" WHERE "+ bcWhere +" ORDER BY " +lcCampoOrden

THISFORM.DATAENVIRONMENT.ADDOBJECT('Consulta','cursoradapter')
loConsulta=THISFORM.DATAENVIRONMENT.Consulta

WITH loConsulta
.DATASOURCE = THISFORM.coneccion_handle
.DATASOURCETYPE = 'ODBC'
.SELECTCMD = m.lcSelectCmd
.ALIAS = 'consulta'
.BUFFERMODEOVERRIDE=3
.FETCHSIZE=-1
ENDWITH

IF loConsulta.CURSORFILL()

ELSE
THROW "Error al llenar el cursor generado por el comando SQL: "+ m.lcSelectCmd
ENDIF

method build_where
THISFORM.tipo_vista="VFP" && I can choose VFP, MYSQL, Oracle or SQL Server
this.parent.change_datasource_control()

**/I change all datasources of the table that I want to consult and I used them like a variables to put the examples to the query/*********

IF (o.CLASS="Combo" OR o.CLASS= "Activtxt" OR o.CLASS="Desactxt" OR o.CLASS="Cajaedicion" ;
OR o.CLASS="Botonesdeopciones" OR o.CLASS="Botonlistaview" )
IF o.busqueda=.T.
m.variable= "bc"+o.NAME

PUBLIC &variable
&variable=" "
STORE o.NAME TO ArrayControlSource(i,1)
STORE VARTYPE(o.VALUE) TO ArrayControlSource(i,3)

DO CASE
CASE o.CLASS="Cajaedicion"
m.lcDatoTipo ="M"
bccampotabla=o.CONTROLSOURCE
STORE o.CONTROLSOURCE TO ArrayControlSource(i,2)
o.CONTROLSOURCE=m.variable

CASE o.CLASS="Casilla"
m.lcDatoTipo ="L"
bccampotabla=o.CONTROLSOURCE
STORE o.CONTROLSOURCE TO ArrayControlSource(i,2)
o.CONTROLSOURCE=m.variable

CASE o.CLASS="Botonlistaview"
bccampotabla=o.fuentedatos
STORE o.fuentedatos TO ArrayControlSource(i,2)
o.fuentedatos=m.variable
m.lcDatoTipo ="C"
OTHERWISE
m.lcDatoTipo = VARTYPE(o.VALUE)
bccampotabla=o.CONTROLSOURCE
STORE o.CONTROLSOURCE TO ArrayControlSource(i,2)
o.CONTROLSOURCE=m.variable
ENDCASE
********/Build where sentence /*****************************
IF o.CLASS != "Desactxt"

IF (m.llRemoteData=.T. AND THISFORM.tipo_vista="VFP" ) OR m.llRemoteData=.F.
IF m.lcDatoTipo = "N"
bcWhere=bcWhere+ " ALLTRIM(STR("+ m.bccampotabla+")) LIKE UPPER(ALLTRIM(?" + variable+ ")) +" +'"%"' +" AND "
ENDIF
IF m.lcDatoTipo = "C"
bcWhere=bcWhere+ " upper(ALLTRIM("+ m.bccampotabla+")) LIKE UPPER(ALLTRIM(?" + variable+ ")) +" +'"%"' +" AND "
ENDIF

IF m.lcDatoTipo ="M"
bcWhere=bcWhere+ " upper(ALLTRIM("+ m.bccampotabla+")) LIKE UPPER(ALLTRIM(?" + variable+ ")) +" +'"%"' +" AND "
ENDIF

IF (m.lcDatoTipo = "D" OR m.lcDatoTipo = "T")
bcWhere=bcWhere+ " DTOS("+ m.bccampotabla+") LIKE ?" + variable +" AND "
ENDIF

ENDIF

********************************/ Consulta Cliente Servidor /***********************************************


IF (m.llRemoteData=.T. AND THISFORM.tipo_vista="MYSQL")
IF m.lcDatoTipo = "N"
bcWhere=bcWhere+ " RTRIM(STR("+ m.bccampotabla +")) LIKE RTRIM(?"+ variable +") AND "
ENDIF
IF m.lcDatoTipo = "C"
bcWhere=bcWhere+ " UPPER(RTRIM("+m.bccampotabla+ ")) LIKE ?"+ variable +" AND "
ENDIF

IF m.lcDatoTipo ="M"
bcWhere=bcWhere+ " UPPER(RTRIM("+m.bccampotabla+ ")) LIKE ?"+ variable +" AND "
ENDIF

IF (m.lcDatoTipo = "D" OR m.lcDatoTipo = "T")
bcWhere=bcWhere+ " left(concat("+ m.bccampotabla +"),8) LIKE ?"+ variable+ " AND "
ENDIF

ENDIF


IF (m.llRemoteData=.T. AND THISFORM.tipo_vista="SQL")
IF (m.lcDatoTipo = "N" OR m.lcDatoTipo = "I")
bcWhere=bcWhere+ "RTRIM(CONVERT(CHAR(20),"+ m.bccampotabla +")) LIKE RTRIM(?"+ variable +") AND "
ENDIF
IF m.lcDatoTipo = "C"
bcWhere=bcWhere+ " ISNULL(LTRIM(RTRIM("+m.bccampotabla+")),' ') LIKE ?"+ variable +" AND "
ENDIF
IF m.lcDatoTipo ="M"
bcWhere=bcWhere+ m.bccampotabla+ " LIKE ?"+ variable +" AND "
ENDIF
IF (m.lcDatoTipo = "D" OR m.lcDatoTipo = "T")
bcWhere=bcWhere+ "CONVERT(CHAR(10),"+ m.bccampotabla +",103) LIKE ?"+ variable+" AND "
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
NEXT

bcWhere=ALLT(LEFT(bcWhere,LEN(bcWhere)-4))
return bcWhere

**********************************************

method change_datasource_control
TRY
m.gnObjetos=THISFORM.CONTROLCOUNT
FOR i = 1 TO m.gnObjetos
o=THISFORM.CONTROLS(i)
IF (o.CLASS="Combo" OR o.CLASS= "Activtxt" OR o.CLASS="Desactxt" OR o.CLASS="Cajaedicion" ;
OR o.CLASS="Botonesdeopciones" OR o.CLASS="Botonlistaview" OR o.CLASS="Girador";
OR o.CLASS="Casilla" )
IF o.busqueda=.T.
DO CASE
CASE o.CLASS="Botonlistaview"
o.fuentedatos=arrayControlSource(i,2)
OTHERWISE
o.CONTROLSOURCE=arrayControlSource(i,2)
ENDCASE
ENDIF

ENDIF
NEXT

m.lcPagina="thisform."+o.NAME+".page"+ALLT(STR(i))+".CONTROLCOUNT"
m.lcObjetos="thisform."+o.NAME+".page"+ALLT(STR(i))+".CONTROLS(j)"

CATCH TO loException
MESSAGEBOX(Exception_Error(loException),0+16,THISFORM.CAPTION)
FINALLY

ENDTRY

THISFORM.REFRESH()


If you have questions please let me know.

Regards

Carlos
Carlos A. Miranda
E.I.S.lnc
President
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform