Refreshing xbrowse when dataset is closed and re-opened

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

Postby James Bott » Wed Jul 14, 2010 6:19 pm

Are you sure that the oBrw:refresh() is being called? I don't see how the display can be showing different records than the dialog, unless it wasn't refreshed.

Can you see the browse being repainted?

The only other possibility I can think of is that the dialog is not loading the current record.

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 7:51 pm

James

I found re-using the same recordset variable worked just fine .. just after the recordset is reset did I need to reset the list box with yours and Rao's suggestion of oBrw:oRs := oRsTrip

Code: Select all  Expand view

IF lOK = .F.
ELSE

   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
 
   // here was the solution //
   
   oBrw:oRs:= oRsTrip
   oBrw:ReFresh()
   SysReFresh()

ENDIF


oBrw:ReFresh()
SysReFresh()

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

RETURN( .T. )

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

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

Postby Armando » Wed Jul 14, 2010 8:05 pm

Tim and friends:

Perhaps I don't understand very well the problem but

Code: Select all  Expand view

STATIC FUNCTION FilHdr(nAmo,oBrw,aGets)
oRsHdr:Close()

oRsHdr:Source :=    "SELECT " +;
                            "hdrfac.*," +;
                            "cliente.cli_nom " +;
                        "FROM " +;
                            "hdrfac," +;
                            "cliente " +;
                        "WHERE " +;
                            "hdrfac.hdr_cli = cliente.cli_cli " +;
                        "AND " +;
                            "YEAR(HDR_FDE) = '" + STR(nAmo,4,0) + "' " +;
                        "ORDER BY " +;
                            "hdr_fac"

oRsHdr:Open()
oRsHdr:Refresh()
oBrw:Refresh()
aGets[1]:oJump  := oBrw
RETURN(.T.)
 


Initialy I made a recordset (oRsHdr) with including only records of 2010 year and
with a spinner the user can retrive records of others years an the above code works
fine.

Best regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3228
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

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

Postby James Bott » Thu Jul 15, 2010 12:01 am

Rick,

Glad to hear you found a solution.

Here is a suggestion for a tiny improvement.

Regards,
James


Code: Select all  Expand view
  // here was the solution //
   
   oBrw:oRs:= oRsTrip
  // These are redundant since they are executed
  // right after the ENDIF
  // oBrw:ReFresh()
  // SysReFresh()

ENDIF

oBrw:ReFresh()
SysReFresh()
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 » Thu Jul 15, 2010 12:04 am

James,Rao

Thanks for all your help !!

Rick
User avatar
Rick Lipkin
 
Posts: 2665
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 » Thu Jul 15, 2010 12:05 am

Armando,

Well, that is just too easy!

Where were you when we needed you?


Rick,

The only difference I see in his code is:

oRsHdr:Refresh()

I am making a note.

Would you mind testing it?

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 Rick Lipkin » Thu Jul 15, 2010 12:29 am

James

The oRsTrip:ReFresh() did not work and here is the placement of the code :

Code: Select all  Expand view

IF lOK = .F.
ELSE

   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

   * oBrw:oRs:= oRsTrip    // this does work
   oRsTrip:Refresh()          // does not work
   oBrw:ReFresh()
   SysReFresh()

ENDIF


oBrw:ReFresh()
SysReFresh()

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

RETURN( .T. )
User avatar
Rick Lipkin
 
Posts: 2665
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 » Thu Jul 15, 2010 12:41 am

Rick,

Thanks for testing it. Maybe Armando has an idea?

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 Armando » Thu Jul 15, 2010 1:50 am

James and friends:

I'm so sorry, too much work and later deserved vacations :wink:

Perhaps this code can help a little bit more.

This is the original code to create the initial recordset
Code: Select all  Expand view

oRsHdr:CursorLocation   := adUseClient
oRsHdr:LockType         := adLockOptimistic
oRsHdr:CursorType           := adOpenDynamic
oRsHdr:Source               := "SELECT " +;
                                        "hdrfac.*," +;
                                        "cliente.cli_nom " +;
                                    "FROM " +;
                                        "hdrfac," +;
                                        "cliente " +;
                                    "WHERE " +;
                                        "hdrfac.hdr_cli = cliente.cli_cli " +;
                                    "AND " +;
                                        "YEAR(HDR_FDE) = '" + STR(nAmo,4,0) + "' " +;
                                    "ORDER BY " +;
                                        "hdr_fac"
 


And this is the code with the spinner to let to choice a diferent year
Code: Select all  Expand view

        REDEFINE GET aGets[ 1] VAR nAmo ID 101 OF oDlg UPDATE;
            PICTURE "9999" SPINNER;
            ON CHANGE (FilHdr(nAmo,oBrw,aGets),oBrw:SetFocus(),oBrw:GoTop(),oDlg:UPDATE());
            MESSAGE "Año de las facturas a mostrar"
 


Finaly the code to refresh the recordset and to show the new browse.
Code: Select all  Expand view

STATIC FUNCTION FilHdr(nAmo,oBrw,aGets)
oRsHdr:Close()

oRsHdr:Source :=    "SELECT " +;
                            "hdrfac.*," +;
                            "cliente.cli_nom " +;
                        "FROM " +;
                            "hdrfac," +;
                            "cliente " +;
                        "WHERE " +;
                            "hdrfac.hdr_cli = cliente.cli_cli " +;
                        "AND " +;
                            "YEAR(HDR_FDE) = '" + STR(nAmo,4,0) + "' " +;
                        "ORDER BY " +;
                            "hdr_fac"

oRsHdr:Open()
oRsHdr:Refresh()
oBrw:Refresh()
aGets[1]:oJump  := oBrw
RETURN(.T.)
 


And that's all folks.

Best regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3228
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

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

Postby nageswaragunupudi » Thu Jul 15, 2010 4:58 am

There is no Refresh method for RecordSet in ADO.
There are only ReSync() and ReQuery() methods.

You can change the source of a RecordSet ( oRs:Souce := <cNewSource> ) and do oRs:ReQuery(), but not Refresh().

This can work:
oBrw:oRs:Source := <cNewSQL Statement>
oBrw:oRs:Requery()
oBrw:GoTop()
oBrw:Refresh()
Regards

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

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

Postby James Bott » Thu Jul 15, 2010 5:46 am

Rao,

Well, that would explain it. Apparently, Armando is not using ADO.

However, shouldn't oRS:refresh() error out if that method doesn't exist?

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 » Thu Jul 15, 2010 11:36 am

James Bott wrote:Rao,

Well, that would explain it. Apparently, Armando is not using ADO.

However, shouldn't oRS:refresh() error out if that method doesn't exist?

James

If it is a recordset, it will error out
Regards

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

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

Postby Armando » Thu Jul 15, 2010 1:35 pm

James:

Yes, I'm using ADO, xHarbour, MySql & FWH810. And not problem at all with
oRsHdr:Refresh()

Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3228
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

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

Postby nageswaragunupudi » Thu Jul 15, 2010 1:39 pm

Mr. James
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.

The command is same is oBrw:SetAdo( oRs, ...... )
There is no need to say oBrw:cAlias := nil.

The entire problem here is in the variable management.

I provide here a simple sample for switching recordset ( as long as columns are the same )
Code: Select all  Expand view
#include 'fivewin.ch'
#include 'xbrowse.ch'

#define FWPATH "c:\fwh\samples\"

static oCn

function Main()

   local cStr  := "
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ;
                  FWPATH + ;
                  "
;Extended Properties=dBASE III;User ID=Admin;Password=;"
   local cSql  := 'SELECT FIRST,CITY,STATE  FROM CUSTOMER WHERE STATE = "
?" ORDER BY FIRST'
   local oDlg, oBrw, oRs
   local cState   := 'NY'

   oCn   := TOleAuto():New( "
ADODB.Connection" )
   oCn:Open( cStr )
   oCn:CursorLocation   := 3 // adUseClient

   oRs   := TOleAuto():New( "
ADODB.RecordSet" )
   oRs:Open( StrTran( cSql, '?', cState ), oCn )

   DEFINE DIALOG oDlg SIZE 600,400 PIXEL
   @ 30,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
      AUTOCOLS AUTOSORT RECORDSET oRs ;
      CELL LINES NOBORDER

   oBrw:CreateFromCode()

   @ 10,240 COMBOBOX cState ITEMS { "
AK", "AL", "AR", "AZ", "CA", "DA", "GE", "HI", "NY" } ;
      SIZE 50,100 PIXEL OF oDlg ;
      ON CHANGE ( ;
         oBrw:oRs:Close(), ;
         oBrw:oRs:Open( StrTran( cSql, "
?", cState ), oCn ), ;
         oBrw:GoTop(), oBrw:Refresh(), oBrw:SetFocus() )

   ACTIVATE DIALOG oDlg CENTERED ON INIT ( oBrw:SetFocus(), .f. )

return nil


Please try this code after changing FWPATH, if necessary.
On selecting a State in the combobox, the recordset is closed and opened with a new Sql and browse is refreshed.
Regards

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

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

Postby nageswaragunupudi » Thu Jul 15, 2010 1:50 pm

Armando wrote:James:

Yes, I'm using ADO, xHarbour, MySql & FWH810. And not problem at all with
oRsHdr:Refresh()

Regards

Yes. I tested and oRecSet:Refresh() does NOT error out.
But refresh method is not documented for ADO.
Regards

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

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 54 guests