Refreshing xbrowse when dataset is closed and re-opened

Refreshing xbrowse when dataset is closed and re-opened

Postby Rick Lipkin » Tue Jul 13, 2010 1:22 am

To All

I have a xBrowse list box already established .. I have a change motorpool option that worked fine under fwh txbrowse ..

Image

What happends is the record set is completely changed because the dataset is closed and re-opened with a new set of values .. did not have a problem pryor to migrating my listbox to xbrowse..

Here is the jist of the code :

Code: Select all  Expand view  RUN

xTITLE := "TRIPS Records Browse for Agency\Motorpool "+ALLTRIM(xAGENCY)+"\"+ALLTRIM(xPOOL)

nWd := GetSysMetrics(0) * .79
nHt := GetSysMetrics(1) * .8

DEFINE ICON oICO RESOURCE "
KEY1"

DEFINE WINDOW oEMP                         ;
      FROM 10,10 to nHt, nWd PIXEL         ;
      of oWndMDI                           ;
      TITLE xTITLE                         ;
      MENU BuildMenu( cTYPE )              ;
      ICON oICO                            ;
      NOMINIMIZE                           ;
      NOZOOM                               ;
      MDICHILD

@ 0, 0 xBROWSE oBrw of oEmp                ;
       RECORDSET oRsTrip                   ;
       COLUMNS                             ;
       'DATE',                             ;
       'DATE_BACK',                        ;
       'LNAME',                            ;
       'FNAME',                            ;
       'VNUMBER',                          ;
       'LICENSE',                          ;
       'STARTMILES',                       ;
       'ENDMILES',                         ;
       'DESTINAT',                         ;
       'PROGNAME',                         ;
       'AGENCY',                           ;
       'MTRPOOL'                           ;
       COLSIZES 80,80,100,100,50,70,70,70,180,150,50,50   ;
       HEADERS "
Date",                  ;
               "
Returned",              ;
               "
Lname",                 ;
               "
Fname",                 ;
               "
Vnumb",                 ;
               "
License",               ;
               "
Start",                 ;
               "
End",                   ;
               "
Destination",           ;
               "
Program",               ;
               "
Agency",                ;
               "
Mtrpool"                ;
       AUTOSORT AUTOCOLS LINES CELL

       oEmp:oClient := oBrw
       oBrw:CreateFromCode()    // recommendation from daniel

       oBrw:bLDblClick := { |nRow,nCol | _tripview( "
V", "","",oRsTrip ) }


ACTIVATE WINDOW oEMP ;
               ON INIT( oBrw:SetFocus(), .F. ) ;
               VALID ( IIF( !lOK2, _TripClose(.T., oRsTrip, oBar1), .F. ))

RETURN( .T. )


Change motorpool code errors when I try to reopen the new recordset :

Code: Select all  Expand view  RUN

//-----------------------
Static Func _Chgmtrpool() // oRsTrip )

LOCAL SAYING,oDLG,oLBX, oRsPool, cSQL, oERR
LOCAL cTITLE, lOK, cSAY, oSAY

SysReFresh()

IF xADMIN = 'Y' .or. xMGR = 'Y' .or. xSUPER = 'Y'
ELSE
   SAYING := "Sorry .. your do not have rights to look at other MotorPools"
   MsgInfo( saying )
   RETURN(.F.)
ENDIF

oRsPool := TOleAuto():New( "ADODB.Recordset" )
oRsPool:CursorType     := 1        // opendkeyset
oRsPool:CursorLocation := 3        // local cache
oRsPool:LockType       := 3        // lockoportunistic

DO CASE
CASE (xSUPER = 'Y' .or. xADMIN = 'Y')
   cSQL   := "SELECT * from MTRPOOL where ageneid = '"+xAGENEID+"' order by mtrpool"
   cTITLE := "ALL Motorpool for Agency "+xAGENCY
CASE xMGR = 'Y'
   cSQL   := "SELECT * from MPOOLOC where ageneid = '"+xAGENEID+"' and userid = '"+xLOGIN+"' order by mtrpool"
   cTITLE := "SELECTed Motorpools for Agency "+alltrim(xAGENCY)+"\"+xLOGIN
OTHERWISE
   SAYING := "
SORRY ... you do not have rights to see other MotorPools"
   MsgInfo( saying )
   RETURN(.F.)
ENDCASE

TRY
   oRSPool:Open(cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )
CATCH oErr
   DO CASE
   CASE (xSUPER = 'Y' .or. xADMIN = 'Y')
      MsgInfo( "
Error in Opening MTRPOOL table" )
   CASE xMGR = 'Y'
      MsgInfo( "
Error in Opening MPOOLOC table" )
   ENDCASE

   RETURN(.F.)
END TRY

IF oRsPool:eof
   SAYING := "
Sorry ... there are no Motorpools found"
   MsgAlert( SAYING )
   oRsPool:Close()
   RETURN(.F.)
ENDIF

lOK := .F.
oRsPool:MoveFirst()

DEFINE DIALOG oDlg                       ;
       FROM 2, 45 to 18, 89              ;
       COLOR "
W+/W"                      ;
       TITLE cTITLE                      ;
       STYLE nOr( WS_POPUP,WS_CAPTION,WS_THICKFRAME )

   @ 0.5, 0.5 LISTBOX oLBX FIELDS        ;
     oRsPool:Fields("
mtrpool"):Value     ;
     HEADERS "
Motorpool"                 ;
     SIZE 165,100                        ;
     SIZES 120                           ;
     of oDlg                             ;
     UPDATE

   @ 6,3  BUTTON "
&Ok"                   ;
       SIZE 25,10 of oDLG                ;
       ACTION ( xPOOLID := oRsPool:Fields("
poolid"):Value, ;
                xPOOL   := oRsPool:Fields("
mtrpool"):Value,;
                lOK := .T.,              ;
                oDlg:END() )             ;
       DEFAULT

   @ 6,8  BUTTON "
&Cancel"               ;
       SIZE 25,10 of oDLG                ;
       ACTION ( oDlg:END(), lOK := .F. )

    oLbx:bLogicLen := { || oRsPool:RecordCount }
    oLbx:bGoTop    := { || oRsPool:MoveFirst() }
    oLbx:bGoBottom := { || oRsPool:MoveLast() }
    oLbx:bSkip     := { | nSkip | Skipper( oRsPool, nSkip ) }
    oLbx:cAlias    := "
ARRAY1"

ACTIVATE DIALOG oDlg

oRsPool:CLose()
SysReFresh()

IF lOK = .F.
ELSE

   oBRW:cALIAS:=NIL  // this worked under txbrowse to reset the browse object
   oRsTrip:CLose()
   oRsTrip := nil

   DEFINE DIALOG oDlg                                            ;
       FROM 5, 8 to 10, 75                                       ;
       TITLE "
Please be patient    "                             ;
       COLOR "
N/W"                                               ;
       STYLE nOr( WS_POPUP,WS_CAPTION,WS_THICKFRAME )

       cSAY  := "
Opening Initial  TRIPS  Data Recordset for Motorpool "+alltrim( xPOOL )

       @ 1,10 SAY oSay  var cSAY  of oDLG COLOR "
N/W"
       oDLG:bStart := { | | lOK1 := _OpenUm(oDlg ) }

     ACTIVATE DIALOG oDLG CENTERED

   IF lOK1 = .F.
      SysReFresh()
      RETURN(.F.)
   ENDIF


ENDIF

oEMP:ReFresh()
oBrw:ReFresh()
SysReFresh()

xTITLE := "
TRIPS Records Browse for Agency\Motorpool "+ALLTRIM(xAGENCY)+"\"+ALLTRIM(xPOOL)
oEMP:cTITLE(xTITLE)
oEMP:ReFresh()
SysReFresh()

RETURN( .T. )

//----------------
Static Func _OpenUm(oDlg )

LOCAL oErr, SAYING, cSTRING, cSQL

SysReFresh()

cSQL := "
SELECT * from TRIPS where AGENCY = '"+xAGENCY+"' and MTRPOOL = '"+xPOOL+"'" //order by LICENSE,DATE DESC"

oRsTRIP := TOleAuto():New( "ADODB.Recordset" )
oRsTRIP:CursorType     := 1        // opendkeyset
oRsTRIP:CursorLocation := 3        // local cache
oRsTRIP:LockType       := 3        // lockoportunistic

TRY
   oRsTRIP:Open( cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )
CATCH oErr
   MsgInfo( "Error in Opening TRIPS table" )
   oDLG:END()
   RETURN(.F.)
END TRY

oDlg:End()
RETURN(.T.)
 


Error code :

Code: Select all  Expand view  RUN

Application
===========
   Path and name: C:\FOX\DHEC\VEHSQL-NEW\Veh32.Exe (32 bits)
   Size: 3,510,784 bytes
   Time from start: 0 hours 0 mins 56 secs
   Error occurred at: 07/12/2010, 21:10:33
   Error description: Error ADODB.Recordset/6  DISP_E_UNKNOWNNAME: RECORDCOUNT
   Args:

Stack Calls
===========
   Called from: source\rtl\win32ole.prg => TOLEAUTO:RECORDCOUNT(0)
   Called from: .\source\classes\XBROWSE.PRG => (b)TXBROWSE:SETADO(3972)
   Called from: .\source\classes\XBROWSE.PRG => (b)TXBROWSE:TXBROWSE(349)
   Called from:  => TXBROWSE:KEYCOUNT(0)
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:REFRESH(922)
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:MOUSELEAVE(3126)
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:HANDLEEVENT(10155)
   Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
   Called from:  => DIALOGBOXINDIRECT(0)
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE(273)
   Called from: .\source\function\ERRSYSW.PRG => ERRORDIALOG(343)
   Called from: .\source\function\ERRSYSW.PRG => (b)ERRORSYS(27)
   Called from: source\rtl\win32ole.prg => TOLEAUTO:RECORDCOUNT(0)
   Called from: .\source\classes\XBROWSE.PRG => (b)TXBROWSE:SETADO(3972)
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:PAINT(1285)
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:DISPLAY(990)
   Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT(1439)
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:HANDLEEVENT(10158)
   Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
   Called from:  => DIALOGBOXINDIRECT(0)
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE(273)
   Called from: TRIPBROW.PRG => _CHGMTRPOOL(566)
   Called from: TRIPBROW.PRG => (b)BUILDMENU(290)
   Called from: .\source\classes\MENU.PRG => TMENU:COMMAND(437)
   Called from: .\source\classes\WINDOW.PRG => TWINDOW:COMMAND(1017)
   Called from: .\source\classes\MDIFRAME.PRG => TMDIFRAME:COMMAND(243)
   Called from:  => TMDIFRAME:HANDLEEVENT(0)
   Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
   Called from:  => WINRUN(0)
   Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ACTIVATE(966)
   Called from: MAIN.PRG => MAIN(411)
 


The error happends in the dialog the calls the bStart OpenUM() code

There has to be a way to re-use the existing listbox and refill and refresh the data .. Any ideas ??

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby James Bott » Tue Jul 13, 2010 1:41 pm

Rick,

Your code is quite complex for us to easily debug.

Note that the parameters for listboxes and TXBrowse are quite different, so you can't just plug in TXBrowse.

The error you are getting seems to indicate that the new recordset is not opened. Try verifying that it is.

You could try a call to oBrw:setADO( oRecordset ) after opening the new recordset.

Perhaps you could make a very simple example of switching the recordset and using the same TXBrowse.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby nageswaragunupudi » Tue Jul 13, 2010 2:17 pm

Mr Rick

When you want to switch recordsets, you open the second recordset with a new variable and assign the new recordset to oBrw:oRs := oRsNew and call oBrw:Refresh(). Later you may close the old recordset.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10662
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby Rick Lipkin » Tue Jul 13, 2010 10:38 pm

Rao

Assigning new recordset variables is almost an impossible task since I use the oRsTrip var in the 'RECORDSET oRsTrip' declaration in the setup of the xBrowse ..

My error does seem to be associated with closing the origional oRsTrip recordset .. If I rem out the Close() .. the program does not error ..

Code: Select all  Expand view  RUN

IF lOK = .F.
ELSE

  // rem these out
  // need something here to close out the recordset alias
  // then close the recordset

  * oBRW:cALIAS:=NIL
  * oRsTrip:CLose()
  * oRsTrip := nil

   oDLG := NIL
   SysReFresh()

   lOK1 := .F.

   DEFINE DIALOG oDlg                                            ;
       FROM 5, 8 to 10, 75                                       ;
       TITLE "Please be patient    "                             ;
       STYLE nOr( WS_POPUP,WS_CAPTION,WS_THICKFRAME ) TRANSPARENT

       cSAY  := "Opening Initial  TRIPS  Data Recordset for Motorpool "+alltrim( xPOOL )

       @ 1,10 SAY oSay  var cSAY  of oDLG
       oDLG:bStart := { | | lOK1 := _OpenUm(oDlg ) }

     ACTIVATE DIALOG oDLG CENTERED ;
              ON PAINT GradientFill( hDC, 0, 0, odlg:nHeight, odlg:nWidth, xGrad1, .T. )

   IF lOK1 = .F.
      SysReFresh()
      RETURN(.F.)
   ENDIF


ENDIF

// need something here to refresh the listbox

oBrw:ReFresh()
SysReFresh()

xTITLE := "TRIPS Records Browse for Agency\Motorpool "+ALLTRIM(xAGENCY)+"\"+ALLTRIM(xPOOL)
oEMP:cTITLE(xTITLE)
oEMP:ReFresh()
SysReFresh()

RETURN( .T. )


If I double click on what appears to be the stale data ... it opens the new data .. but I never see the new data refreshed in the listbox.

What I can not understand is why it worked with the standard FWH listbox class .. and not with xbrowse .. There is just no way to asign new recordset variable since the program allows administrators to hop around and look at other motorpools as many times as they wish..

There must be a way to gracefully release the oBrw object and reassociate it with the new data .. using the same oRs variable ?? .. It appears the new data is there .. just the xbrowse has no clue the data has changed.

Thanks
Rick
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby James Bott » Tue Jul 13, 2010 11:58 pm

Rick,

I think it is crashing because the browse is looking for the recordset during the brief time when it doesn't exist. I have had this problem with TXBrowse also.

Try disabling the browse before you close the old recordset, then do a sysrefresh() after the new recordset is open. Finally, enable the browse then refresh it.

Code: Select all  Expand view  RUN
oBrw:disable()
...  //close the old RS and open the new one
sysrefresh()
oBrw:enable()
oBrw:refresh()


James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby Rick Lipkin » Wed Jul 14, 2010 4:39 pm

James

It did not work .. somehow I need to disable the alias recordset into the oBrw object .. The disable and enable was a good idea ..

Code: Select all  Expand view  RUN


//----------------
Static Func _OpenUm(oDlg )

LOCAL oErr, SAYING, cSTRING, cSQL

MSGINFO( "IN OPENUM" )
IF empty(oRsTrip)
ELSE
   MSGINFO( "CLOSING ORSTRIP" )
   oBrw:Disable()
   oRsTrip:CLose()  // <-------  blows here
   oRsTrip := NIL
   oBrw:Enable()
ENDIF
 


Whenever the recordset is closed .. the listbox errors out :

Code: Select all  Expand view  RUN

Application
===========
   Path and name: C:\FOX\DHEC\VEHSQL-NEW\Veh32.Exe (32 bits)
   Size: 3,510,784 bytes
   Time from start: 0 hours 0 mins 17 secs
   Error occurred at: 07/14/2010, 12:35:10
   Error description: Error ADODB.Recordset/6  DISP_E_UNKNOWNNAME: RECORDCOUNT
   Args:

Stack Calls
===========
   Called from: source\rtl\win32ole.prg => TOLEAUTO:RECORDCOUNT(0)
   Called from: .\source\classes\XBROWSE.PRG => (b)TXBROWSE:SETADO(3972)
   Called from: .\source\classes\XBROWSE.PRG => (b)TXBROWSE:TXBROWSE(349)
   Called from:  => TXBROWSE:KEYCOUNT(0)
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:REFRESH(922)
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:MOUSELEAVE(3126)
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:HANDLEEVENT(10155)
   Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
   Called from:  => DIALOGBOXINDIRECT(0)
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE(273)
   Called from: .\source\function\ERRSYSW.PRG => ERRORDIALOG(343)
   Called from: .\source\function\ERRSYSW.PRG => (b)ERRORSYS(27)
   Called from: source\rtl\win32ole.prg => TOLEAUTO:RECORDCOUNT(0)
   Called from: .\source\classes\XBROWSE.PRG => (b)TXBROWSE:SETADO(3972)
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:PAINT(1285)
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:DISPLAY(990)
   Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT(1439)
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:HANDLEEVENT(10158)
   Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
   Called from:  => DIALOGBOXINDIRECT(0)
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE(273)
   Called from: .\source\function\ERRSYSW.PRG => ERRORDIALOG(343)
   Called from: .\source\function\ERRSYSW.PRG => (b)ERRORSYS(27)
   Called from: source\rtl\win32ole.prg => TOLEAUTO:RECORDCOUNT(0)
   Called from: .\source\classes\XBROWSE.PRG => (b)TXBROWSE:SETADO(3972)
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:PAINT(1285)
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:DISPLAY(990)
   Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT(1439)
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:HANDLEEVENT(10158)
   Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
   Called from:  => SYSREFRESH(0)
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:END(530)
   Called from: TRIPBROW.PRG => _OPENUM(99)
   Called from: TRIPBROW.PRG => (b)_CHGMTRPOOL(724)
   Called from: .\source\classes\DIALOG.PRG => (b)TDIALOG:TDIALOG(86)
   Called from:  => TDIALOG:DISPLAY(0)
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:HANDLEEVENT(915)
   Called from:  => DIALOGBOXINDIRECT(0)
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE(273)
   Called from: TRIPBROW.PRG => _CHGMTRPOOL(727)
   Called from: TRIPBROW.PRG => (b)BUILDMENU(300)
   Called from: .\source\classes\MENU.PRG => TMENU:COMMAND(437)
   Called from: .\source\classes\WINDOW.PRG => TWINDOW:COMMAND(1017)
   Called from: .\source\classes\MDIFRAME.PRG => TMDIFRAME:COMMAND(243)
   Called from:  => TMDIFRAME:HANDLEEVENT(0)
   Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
   Called from:  => WINRUN(0)
   Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ACTIVATE(966)
   Called from: MAIN.PRG => MAIN(411)
 


Just need a way to release the alias like in the fwh standard listbox :


Code: Select all  Expand view  RUN

  oBRW:cALIAS:=NIL
  oRsTrip:CLose()
  oRsTrip := nil
 


Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby James Bott » Wed Jul 14, 2010 5:11 pm

Rick,

Code: Select all  Expand view  RUN
  MSGINFO( "CLOSING ORSTRIP" )
   oBrw:Disable()
   oRsTrip:CLose()  // <-------  blows here
   oRsTrip := NIL
   oBrw:Enable()


Well, you didn't do it exactly the way I suggested. You have enabled the browse before opening the new recordset.

I am also not sure that is it erroring out on the oRsTrip:Close() as you indicated. How about putting a MsgInfo() right after that statement to see.

Your error message is indicating that it is erroring out right after a call to TXBrowse:setado().

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby Rick Lipkin » Wed Jul 14, 2010 5:28 pm

James

Here is the sequence of events

1) Open the origional recordset :

Code: Select all  Expand view  RUN

lOK  := .F.
lOK1 := .F.

DEFINE DIALOG oDlg                                               ;
       FROM 5, 8 to 10, 75                                       ;
       TITLE "Please be patient    "                             ;
       STYLE nOr( WS_POPUP,WS_CAPTION,WS_THICKFRAME ) TRANSPARENT

       cSAY  := "Opening Initial  TRIPS  Data Recordset for Motorpool "+alltrim( xPOOL )

       @ 1,10 SAY oSay  var cSAY  of oDLG
       oDLG:bStart := { | | lOK1 := _OpenUm(oDlg ) }

ACTIVATE DIALOG oDLG CENTERED ;
         ON PAINT GradientFill( hDC, 0, 0, odlg:nHeight, odlg:nWidth, xGrad1, .T. )

IF lOK1 = .F.
   oWndChild:Show()
   oBar1:Show()
   SysReFresh()
   _CleanUP()
   RETURN(.F.)
ENDIF

SysReFresh()

_TBrow(oWndMdi, oWndChild, oBar1 ) // xbrowse defined here

SysReFresh()
Return(nil)

//----------------
Static Func _OpenUm(oDlg )

LOCAL oErr, SAYING, cSTRING, cSQL

SysReFresh()

cSQL := "SELECT * from TRIPS where AGENCY = '"+xAGENCY+"' and MTRPOOL = '"+xPOOL+"'" //order by LICENSE,DATE DESC"

oRsTRIP := TOleAuto():New( "ADODB.Recordset" )
oRsTRIP:CursorType     := 1        // opendkeyset
oRsTRIP:CursorLocation := 3        // local cache
oRsTRIP:LockType       := 3        // lockoportunistic

TRY
   oRsTRIP:Open( cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )
CATCH oErr
   MsgInfo( "Error in Opening TRIPS table" )
   oDLG:END()
   RETURN(.F.)
END TRY

oDlg:End()
RETURN(.T.)
 


User wants to change to a different motorpool and different parameters are passed to the SQL statement and OpenUM() is called again.. modified with your code :


Code: Select all  Expand view  RUN

IF lOK = .F.
ELSE

    oBrw:Disable()
  * oRsTrip:CLose()
  * oRsTrip := nil

   oDLG := NIL
   SysReFresh()

   lOK1 := .F.

   // re open a new recordset

   DEFINE DIALOG oDlg                                            ;
       FROM 5, 8 to 10, 75                                       ;
       TITLE "Please be patient    "                             ;
       STYLE nOr( WS_POPUP,WS_CAPTION,WS_THICKFRAME ) TRANSPARENT

       cSAY  := "Opening Initial  TRIPS  Data Recordset for Motorpool "+alltrim( xPOOL )

       @ 1,10 SAY oSay  var cSAY  of oDLG
       oDLG:bStart := { | | lOK1 := _OpenUm(oDlg ) }

     ACTIVATE DIALOG oDLG CENTERED ;
              ON PAINT GradientFill( hDC, 0, 0, odlg:nHeight, odlg:nWidth, xGrad1, .T. )

   IF lOK1 = .F.
      SysReFresh()
      RETURN(.F.)
   ENDIF


ENDIF

oBrw:Enable()
oBrw:ReFresh()
SysReFresh()

xTITLE := "TRIPS Records Browse for Agency\Motorpool "+ALLTRIM(xAGENCY)+"\"+ALLTRIM(xPOOL)
oEMP:cTITLE(xTITLE)
oEMP:ReFresh()
SysReFresh()

RETURN( .T. )


I do not get an error .. but the listbox still containes the old data .. however, if I double click on a line to view the data .. the new data is there in the detail just the listbox never gets updated.
Rick
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby James Bott » Wed Jul 14, 2010 5:34 pm

Rick,

Try issuing a oBrw:gotop() right before the oBrw:refresh().

Also, are you using oBrw:setADO(oRecordset) to setup the original browse?

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby Rick Lipkin » Wed Jul 14, 2010 5:39 pm

James

Just initializing the recordset with this code :

Code: Select all  Expand view  RUN

DEFINE WINDOW oEMP                         ;
      FROM 10,10 to nHt, nWd PIXEL         ;
      of oWndMDI                           ;
      TITLE xTITLE                         ;
      MENU BuildMenu( cTYPE )              ;
      ICON oICO                            ;
      NOMINIMIZE                           ;
      NOZOOM                               ;
      MDICHILD

@ 0, 0 xBROWSE oBrw of oEmp                ;
       RECORDSET oRsTrip                   ;   // recordset alias
       COLUMNS                             ;
       'DATE',                             ;
       'DATE_BACK',                        ;
       'LNAME',                            ;
       'FNAME',                            ;
       'VNUMBER',                          ;
       'LICENSE',                          ;
       'STARTMILES',                       ;
       'ENDMILES',                         ;
       'DESTINAT',                         ;
       'PROGNAME',                         ;
       'AGENCY',                           ;
       'MTRPOOL'                           ;
       COLSIZES 80,80,100,100,50,70,70,70,180,150,50,50   ;
       HEADERS "Date",                  ;
               "Returned",              ;
               "Lname",                 ;
               "Fname",                 ;
               "Vnumb",                 ;
               "License",               ;
               "Start",                 ;
               "End",                   ;
               "Destination",           ;
               "Program",               ;
               "Agency",                ;
               "Mtrpool"                ;
       AUTOSORT AUTOCOLS LINES CELL

       oEmp:oClient := oBrw
       oBrw:CreateFromCode()    // recommendation from daniel

       oBrw:bLDblClick := { |nRow,nCol | _tripview( "V", "","",oRsTrip ) }


ACTIVATE WINDOW oEMP ;
               ON INIT( oBrw:SetFocus(), .F. ) ;
               VALID ( IIF( !lOK2, _TripClose(.T., oRsTrip, oBar1), .F. ))


 
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby Rick Lipkin » Wed Jul 14, 2010 5:44 pm

Rao

I am trying to use your method of opening a new recordset when the user select a new motorpool and the xpool changes :

I added a second parameter nNUM so when OpenUm is called .. I use a new recordset variable and I get this error :

Code: Select all  Expand view  RUN

//----------------
Static Func _OpenUm(oDlg,nNUM )

LOCAL oErr, SAYING, cSTRING, cSQL

SysReFresh()


DO CASE
CASE nNUM = 1

   MSGINFO( "initial empty oRstrip" )
   SysReFresh()

   cSQL := "SELECT * from TRIPS where AGENCY = '"+xAGENCY+"' and MTRPOOL = '"+xPOOL+"'" //order by LICENSE,DATE DESC"

   oRsTRIP := TOleAuto():New( "ADODB.Recordset" )
   oRsTRIP:CursorType     := 1        // opendkeyset
   oRsTRIP:CursorLocation := 3        // local cache
   oRsTRIP:LockType       := 3        // lockoportunistic

   TRY
      oRsTRIP:Open( cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )
   CATCH oErr
      MsgInfo( "Error in Opening TRIPS table" )
      oDLG:END()
      RETURN(.F.)
   END TRY

CASE nNUM = 2

   msginfo( "NNUM = 2" )

   oRsTrip1 := nil
   SysReFresh()

   cSQL := "SELECT * from TRIPS where AGENCY = '"+xAGENCY+"' and MTRPOOL = '"+xPOOL+"'" //order by LICENSE,DATE DESC"

   oRsTRIP1 := TOleAuto():New( "ADODB.Recordset" )
   oRsTRIP1:CursorType     := 1        // opendkeyset
   oRsTRIP1:CursorLocation := 3        // local cache
   oRsTRIP1:LockType       := 3        // lockoportunistic

   TRY
      oRsTRIP1:Open( cSQL,'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD )
   CATCH oErr
      MsgInfo( "Error in Opening TRIPS1 table" )
      oDLG:END()
      RETURN(.F.)
   END TRY

   oBrw:oRsTrip := oRsTrip1  // -- errors here line 118
   oBrw:ReFresh()
   SysReFresh()

   oRsTrip:CLose()
   oRsTrip := NIL
   SysReFresh()

ENDCASE

oDlg:End()
RETURN(.T.)
 



Code: Select all  Expand view  RUN

Application
===========
   Path and name: C:\FOX\DHEC\VEHSQL-NEW\Veh32.Exe (32 bits)
   Size: 3,511,296 bytes
   Time from start: 0 hours 0 mins 16 secs
   Error occurred at: 07/14/2010, 13:36:53
   Error description: Error BASE/1005  Message not found: TXBROWSE:ORSTRIP
   Args:

Stack Calls
===========
   Called from: .\source\function\HARBOUR.PRG => _CLSSETERROR(168)
   Called from: .\source\classes\XBROWSE.PRG => TXBROWSE:_ORSTRIP(6811)
   Called from: TRIPBROW.PRG => _OPENUM(118)
   Called from: TRIPBROW.PRG => (b)_CHGMTRPOOL(792)
   Called from: .\source\classes\DIALOG.PRG => (b)TDIALOG:TDIALOG(86)
   Called from:  => TDIALOG:DISPLAY(0)
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:HANDLEEVENT(915)
   Called from:  => DIALOGBOXINDIRECT(0)
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE(273)
   Called from: TRIPBROW.PRG => _CHGMTRPOOL(795)
   Called from: TRIPBROW.PRG => (b)BUILDMENU(367)
   Called from: .\source\classes\MENU.PRG => TMENU:COMMAND(437)
   Called from: .\source\classes\WINDOW.PRG => TWINDOW:COMMAND(1017)
   Called from: .\source\classes\MDIFRAME.PRG => TMDIFRAME:COMMAND(243)
   Called from:  => TMDIFRAME:HANDLEEVENT(0)
   Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
   Called from:  => WINRUN(0)
   Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ACTIVATE(966)
   Called from: MAIN.PRG => MAIN(411)
 


Rao .. what am I missing here ??

Rick
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby James Bott » Wed Jul 14, 2010 5:50 pm

Rick,

Code: Select all  Expand view  RUN
RECORDSET oRsTrip                   ;   // recordset alias


This syntax is OK; it is the same as oBrw:setADO( oRS )

Note that a recordset is not an alias. There is no alias used when using a recordset. In TWbrowse you had to set cAlias to nil to prevent it erroring--this was really a workaround for a bug.

Did you try the oBrw:gotop()?

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby James Bott » Wed Jul 14, 2010 5:59 pm

Rick,

Code: Select all  Expand view  RUN
  oBrw:oRsTrip := oRsTrip1  // -- errors here line 118


There is no oBrw:oRsTrip. Try this instead:

oBrw:oRs:= oRsTrip1

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby Rick Lipkin » Wed Jul 14, 2010 6:01 pm

James

I placed the gotop like this :


Code: Select all  Expand view  RUN

IF lOK = .F.
ELSE

    oBrw:Disable()
  * oRsTrip:CLose()
  * oRsTrip := nil

   oDLG := NIL
   SysReFresh()

   lOK1 := .F.

   // re open a new recordset

   DEFINE DIALOG oDlg                                            ;
       FROM 5, 8 to 10, 75                                       ;
       TITLE "Please be patient    "                             ;
       STYLE nOr( WS_POPUP,WS_CAPTION,WS_THICKFRAME ) TRANSPARENT

       cSAY  := "Opening Initial  TRIPS  Data Recordset for Motorpool "+alltrim( xPOOL )

       @ 1,10 SAY oSay  var cSAY  of oDLG
       oDLG:bStart := { | | lOK1 := _OpenUm(oDlg,1 ) }

     ACTIVATE DIALOG oDLG CENTERED ;
              ON PAINT GradientFill( hDC, 0, 0, odlg:nHeight, odlg:nWidth, xGrad1, .T. )

   IF lOK1 = .F.
      SysReFresh()
      RETURN(.F.)
   ENDIF


ENDIF

oBrw:Enable()
oBrw:GoTop()
oBrw:ReFresh()
SysReFresh()

xTITLE := "TRIPS Records Browse for Agency\Motorpool "+ALLTRIM(xAGENCY)+"\"+ALLTRIM(xPOOL)
oEMP:cTITLE(xTITLE)
oEMP:ReFresh()
SysReFresh()

RETURN( .T. )


And here is the result .. The listbox stays the same .. as you can see .. double clock on the line and it does not match the line .. meaning the new recordset is there .. just the listbox is not updating .. somehow there needs to be a way to disconnect the listbox from the browse object .. open the new data and re-connect the listbox object to the new data and refresh()

Image

Rick
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Refreshing xbrowse when dataset is closed and re-opened

Postby Rick Lipkin » Wed Jul 14, 2010 6:14 pm

James

There is no oBrw:oRsTrip. Try this instead:

oBrw:oRs:= oRsTrip1

James


YES .. you and Rao said the same thing .. I did not realize the oRs was an internal .. and YES .. the listbox now reveals the correct data .. unfortunitly, when you open the detail .. I pass the oRsTrip object and now I get and error on the detail .. I need to think about how to pass a parameter to the detail in order to use the correct recordset variable ..

Getting closer ..

Rick
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 46 guests