DCBrowse and DataSets

This forum is for eXpress++ general support.
Post Reply
Message
Author
Stuart.Fraser
Posts: 17
Joined: Thu Jan 28, 2010 10:07 am
Location: Victoria, BC Canada
Contact:

DCBrowse and DataSets

#1 Post by Stuart.Fraser »

Hi All,

I have a DCBrowse of an SQLDataSet (SQLExpress and Oracle 11g). Everything works just fine with the browse, however I wanted to take advantage of the :BrowseFilter property of SQLDataSets to allow the user to filter the data based on the value of one of the fields. I had previously done this when it was foxpro tables using dc_setscope. The list is essentially a browse of different types of entries in an event log and the filter functionality allows the user to say "Let me see only events related to X"

When I try to use the :BrowseFilter property however, the DCBrowse itself goes wonky, always forcing the browse to the bottom row and not allowing the user to scroll up. I can grab the scrollbar and force it up for a second (at which point I can see that the filter did work), but even then, the browse will quickly reposition itself back to the bottom row after a second. If I remove the :BrowseFilter property (set it back to NIL) then everything behaves correctly again.

Has anyone run into anything similar?

Due to the nature of the environment and the work I cannot give you fully compilable / runable code but here are some relevent code snippets for what its worth.

Code: Select all

 
Local bEventRefresh  := {|| LoadEventLog(aLocals),;
                            DC_GETREFRESH( GetList, nil,DCGETREFRESH_ID_INCLUDE,{"EVT"}),DC_GetOrigSet(GetList) }

// making the cursor
If !MakeCursor(@oEVENTLOG,SELECT_EVENTLOG+" WHERE CASE_ID=? ORDER BY EVENTDATE DESC", {|| { oCASES:FieldGet("CASE_ID")} } )
    ErrorMsg("Unable to Open EventLog Table")
    Break
Endif



// throw up the browse
   @ 0.2,0.2 DCBROWSE oBrowEvent DATA oEVENTLOG ;
   SIZE 60,nBHeight-5.2 PARENT oBoxEvent CURSORMODE XBPBRW_CURSOR_ROW ;
   PRESENTATION aBrowPres EVAL bScrollBars ;
   ITEMMARKED bEventRefresh ; //SCOPE ; //DESCENDING;
   ITEMSELECTED {|| IIF(Eval(bEvtEditWhen),Eval(bEvtEditAction),nil) }


//-------------------------------------------------------------------------------
    Function MakeCursor(oCurs,cSelect,aParams,nRows)
//-------------------------------------------------------------------------------
Local lOk:=.t.

default aParams to {}
default nRows to 0

Begin Sequence

oCurs:=CreateSQLDataSet(_goCONN,cSelect,aParams,@nRows)

lOk:=ValType(oCurs)=="O"

EndSequence

Return lOk

//-----------------------------------------------------------------------------
        FUNCTION CreateSQLDataSet( oConnection, cStatement,aParams, nRows )
//-----------------------------------------------------------------------------

Local oCursor, nSuccess := SQL_XPP_ERROR
Local oWin:=SetAppWindow()

dc_pointerwait(oWin)

default aParams to {}
default nRows to 0
default oConnection to _goCONN

Begin Sequence
If ValType(oConnection)<>"O"
    GetConnected()
    oConnection:=_goCONN
ElseIf !oConnection:IsConnected
    GetConnected()
    oConnection:=_goCONN
Endif

oConnection:displayErrors := .t.

oCursor  := SQLDataSet():new(cStatement, oConnection, aParams ,,,,,.t.,.t.)
nSuccess := oCursor:execute()
If nSuccess<>SQL_XPP_ERROR
    nRows := nSuccess
Endif
oConnection:displayErrors := .f.

EndSequence
dc_pointerArrow(oWin)

RETURN oCursor


//-------------------------------------------------------------------------------
    Function EventFilter(aLocals)
//-------------------------------------------------------------------------------
Local GetList[0], GetOptions[0]
Local cStart:="000000SH00"
Local cEnd:="999999SH99"
Local oGroup
Local lOk:=.f.
Local nPick:=1


@ 0,0 DCGROUP oGroup SIZE 40,9

@ 1,2 DCSAY "Filter Event Log for 'Relates To' Type" SAYSIZE 0 SAYLEFT

@ 2,2 DCRADIO nPick PROMPT "All Types" VALUE 1
@ 3,2 DCRADIO nPick PROMPT "Cases" VALUE 2
@ 4,2 DCRADIO nPick PROMPT "Incidents" VALUE 3
@ 5,2 DCRADIO nPick PROMPT "Respondents" VALUE 4
@ 6,2 DCRADIO nPick PROMPT "Complainants" VALUE 5
@ 7,2 DCRADIO nPick PROMPT "Employers" VALUE 6

DCGETOPTIONS NOMIN NOMAX AUTORESIZE TABSTOP ENTEREXIT

DCREAD GUI FIT TITLE "Filter Event Log" ;
OPTIONS GETOPTIONS ;
ADDBUTTONS ;
TO lOk ;
MODAL


If lOk
    Do Case
        Case nPick=1
            oEVENTLOG:BrowseFilter := NIL
            cEVT_FILTER:="All Event Types"
        Case nPick=2
            oEVENTLOG:BrowseFilter := {|aRow,nRow,oData| oData:FieldGet("SH_ID")==_STK_CASE}
            cEVT_FILTER:="Cases"
        Case nPick=3
            oEVENTLOG:BrowseFilter := {|aRow,nRow,oData| oData:FieldGet("SH_ID")==_STK_INCIDENT}
            cEVT_FILTER:="Incidents"
        Case nPick=4
            oEVENTLOG:BrowseFilter := {|aRow,nRow,oData| oData:FieldGet("SH_ID")==_STK_RESPONDENT}
            cEVT_FILTER:="Respondents"
        Case nPick=5
            oEVENTLOG:BrowseFilter := {|aRow,nRow,oData| oData:FieldGet("SH_ID")==_STK_COMPLAINANT}
            cEVT_FILTER:="Complainants"
        Case nPick=6
            oEVENTLOG:BrowseFilter := {|aRow,nRow,oData| oData:FieldGet("SH_ID")==_STK_EMPLOYER}
            cEVT_FILTER:="Employers"
     EndCase

     oEVENTLOG:GoTop()

Endif


Return nil
Any input, thoughts or ideas welcome.

Thanks,

Stu

Andy Edward
Posts: 103
Joined: Fri Sep 17, 2010 2:58 am

Re: DCBrowse and DataSets

#2 Post by Andy Edward »

Hi Stu,

I had the same exact issue.

What I did was to make the browse (not the dataset) to go top.

Maybe a oBrowEvent:GoTop() might do the trick.

Here is the question I posted at SQLExpress forum as well

This will be the proper link
http://news.xbwin.com/newsgroups.php?ar ... cle_id=965
or this using the news.xb2.netdomain name
http://news.xb2.net/newsgroups.php?art_ ... cle_id=965

User avatar
rdonnay
Site Admin
Posts: 4775
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: DCBrowse and DataSets

#3 Post by rdonnay »

The :browseFilter concept is something I never tried.
Instead, I would always issue a new SELECT statement using the WHERE clause.

Why don't you do this instead?
The eXpress train is coming - and it has more cars.

Stuart.Fraser
Posts: 17
Joined: Thu Jan 28, 2010 10:07 am
Location: Victoria, BC Canada
Contact:

Re: DCBrowse and DataSets

#4 Post by Stuart.Fraser »

Since it was a dataset I wound up just putting the SQL Parameters into a code block and allowing the user to change them on the fly then re-executing.

Like this:

Code: Select all


cEVT_START:="SH00"  // these get changed in an alternate routine and are used to define a range of event types that are acceptable for display. 
cEVT_END:="SH99"     // SH00 and SH99 are outside of the normal range defined in the code table for event types and so get all.

If !MakeCursor(@oEVENTLOG,SELECT_EVENTLOG+" WHERE CASE_ID=? AND SH_ID>=? AND SH_ID<=? ORDER BY EVENTDATE DESC, EVENTLOG_ID DESC", {|| {oCASES:FieldGet("CASE_ID"),cEVT_START,cEVT_END} } )
    ErrorMsg("Unable to Open EventLog Table")
    Break
Endif

Works great.

Thanks for the input,

Stu

Post Reply