Page 1 of 2

instant refresh

PostPosted: Sun Aug 26, 2007 2:12 pm
by Ehab Samir Aziz
How can I have instant refresh after deletion a record .
Code: Select all  Expand view
#include "fivewin.ch"
#include "xbrowse.ch"


function main()
    local oWnd,oBar

    field me_mc_serl, me_date

    set date format to "DD/MM/YYYY"
    set deleted on
    set resources to "test04.dll"
    setHandleCount(99)

    use mete exclusive
    *recall all
    index on me_mc_serl to mete
    index on me_date to mete2
    use

    define window oWnd title "Test Tmeter class" MDI

    define buttonbar oBar of oWnd size 26,28 3d

    define button of oBar resource "people" noborder;
      action Tmeter():new():browser()

    activate window oWnd

    set resources to
    close databases

return nil
//--- End test



//---------------------------------------------------------------------------//

//--- meter class
class Tmeter from TData
   method new
   method browser
   method add
   method edit
   message delete method _delete
Hidden:
   data lAdd as logical
endclass

//---------------------------------------------------------------------------//

method new()
   super:new(,"mete")
   if ::use()
      ::addIndex("mete")
      ::addIndex("mete2")
      ::setOrder(1)
      ::gotop()
      msgInfo( ::recno(),"recno()")
      msgInfo( ::fcount(),"fcount()")
     
   endif
   ::lAdd:=.f.
return self

//---------------------------------------------------------------------------//


method browser()

   local oDlg,oBrw,oMeter,oFont,oCol,nFor,oChild

   ::setOrder(2)
   ::gotop()


   define font oFont name "Ms Sans Serif" size 0,-14 BOLD
   *define font oFont name getsysfont() size 0,-14

   DEFINE DIALOG oDlg FROM 0,0 TO 45,128 TITLE "meter reads browse "

   oBrw := TXBrowse():New( oDlg )
   oBrw:nMarqueeStyle       := MARQSTYLE_HIGHLCELL
   oBrw:nColDividerStyle    := LINESTYLE_BLACK
   oBrw:nRowDividerStyle    := LINESTYLE_BLACK
   oBrw:lColDividerComplete := .t.
   oBrw:nHeaderLines        := 1
   oBrw:nFooterLines        := 1
   oBrw:nDataLines          := 1
   oBrw:lFooter             := .t.
   oBrw:CreateFromCode()
   oBrw:nTop = 0
   oBrw:nLeft = 0
   oBrw:nWidth = 1000
   oBrw:nHeight =600
   oBrw:SetRDD()
   


      for nFor := 1 to ::Fcount()
         oBrw:aCols[ nFor ]:oDataFont := oFont
      next
   
   // Setup for using database class
   oBrw:cAlias:= ::cAlias
   oBrw:bSkip:= {|nRecs| ::skipper( nRecs ) }
   oBrw:bGotop:= {|| ::gotop() }
   oBrw:bGoBottom:= {|| ::goBottom() }
   oBrw:bBookMark := {| n | iif( n == nil, ::RecNo() , ::Goto( n ) ) }
   

oMeter:= self

ACTIVATE DIALOG oDlg ON INIT (oBrw:SetSize( 1000, 600 ), BuildButtons( oMeter,oBrw,oDlg),oBrw:Refresh(.t.), oDlg:Refresh(.t.))






RETURN nil

//---------------------------------------------------------------------------//


function BuildButtons(oMeter, oBrw, oDlg)
*--------------------------------------------------
    @ 34,   1 BUTTON "&New"    OF oDlg SIZE 60, 20 ACTION ( oMeter:add(oBrw),oBrw:refresh(),oDlg:update())

    @ 34,  15 BUTTON "&Modify" OF oDlg SIZE 60, 20 ACTION ( oMeter:edit(oBrw),oBrw:refresh(),oDlg:update())

    @ 34, 30 BUTTON "&Delete" OF oDlg  SIZE 60, 20 ACTION ( oMeter:delete(oBrw,oDlg),oBrw:refresh(),oDlg:update())

    @ 34,45 BUTTON "&Search" OF oDlg SIZE 60, 20 //ACTION addmete( oBrw , oDlg )

    @ 34,60 BUTTON "&Print" OF oDlg SIZE 60, 20 //ACTION oDlg:Report ( "meter reads Report", .t. )

    @ 36,  1 BUTTON "&Order"    OF oDlg SIZE 60, 20//ACTION ordercust(oLbx) SIZE 40, 12

    @ 36,  15 BUTTON "&Filter"    OF oDlg SIZE 60, 20//ACTION filtercust(oLbx) SIZE 40, 12

    @ 36,  30 BUTTON "&Unfilter" OF oDlg SIZE 60, 20//ACTION Nonfiltercust(oLbx) SIZE 40, 12

    @ 36, 45 BUTTON "&Exit"   OF oDlg SIZE 60, 20 //ACTION oDlg:End() SIZE 40, 12


return nil



method add(oBrw)
   ::lAdd:=.t.
   ::edit(oBrw)
   ::load()   // in case they cancel
   ::lAdd:=.f.
   ::GOTOP()
return self

//---------------------------------------------------------------------------//

method edit(oBrw)

   local oDlg,oBtnNew
   local ometer:= TRecord():new( self )
   if ::lAdd
      ometer:blank()
   endif


   DEFINE DIALOG oDlg FROM 8, 2 TO 600, 700 PIXEL ;
      TITLE if(::lAdd,"Untitled","Update")


   @ 1,2 SAY "&Serial" OF oDlg PIXEL
   @ 1,50 SAY ":" OF oDlg PIXEL
   @ 1,60 GET ometer:me_mc_serl OF oDlg PIXEL UPDATE

   @ 15,1 SAY "&Meter date" OF oDlg PIXEL
   @ 15,50 SAY ":" OF oDlg PIXEL
   @ 15,60 GET ometer:me_date pict ("99/99/9999") OF oDlg PIXEL UPDATE


   @ 280, 10 BUTTON oBtnNew PROMPT "&Save" OF oDlg PIXEL SIZE 30, 12 ;
      ACTION  ( ometer:save(), oDlg:end() )

   ACTIVATE DIALOG oDlg CENTERED ;
         ON INIT ( oBrw:Refresh(), oDlg:Update() )

ometer:end()
oDlg:update()

return self



//---------------------------------------------------------------------------//

method _delete(oBrw,oDlg)
   if msgYesNo("Delete this record?")
      super:delete()
   endif
return self

//---------------------------------------------------------------------------//


PostPosted: Sun Aug 26, 2007 2:21 pm
by Antonio Linares
oBrw:Refresh()

PostPosted: Sun Aug 26, 2007 2:29 pm
by Ehab Samir Aziz
It does not do instant refresh. Refresh happneded after moving the cursor between records . I added in such way :
Code: Select all  Expand view
method _delete(oBrw,oDlg)
   if msgYesNo("Delete this record?")
      super:delete()
   endif
   oBrw:refresh()
   

return self

PostPosted: Sun Aug 26, 2007 2:37 pm
by Rick Lipkin
Ehab

I assume you have SET DELETE ON ... and do you not have to skip to the next record after you DELETE ??

Rick Lipkin

PostPosted: Sun Aug 26, 2007 4:13 pm
by Ehab Samir Aziz
What I needed is to make the record deleted disappeared immediately from the browse ( INSTANTLY). That what I asked for .
Thanks

PostPosted: Sun Aug 26, 2007 4:41 pm
by Rick Lipkin
Ehab

This code works for me ..

SELECT EMPLOYEE
nRECNO := RECNO()

IF MsgYesNo( "Are you SURE you want to DELETE this?" )
dbSelectArea( "EMPLOYEE" )
IF RECLOCK( 5 )
dbDelete()
dbUnlock()
dbCommit()
SKIP+1

IF EOF()
dbGoTop()
ENDIF

nRECNO := RECNO()

ENDIF
ENDIF

GOTO nRECNO

oBROW:UpStable()
oBROW:Refresh(.T.)
SysReFresh()

PostPosted: Sun Aug 26, 2007 6:34 pm
by Ehab Samir Aziz
Can I have the old browse with the first record browsed before the deletion ? I mean updating the browse having the first ecord before the deletion except the record deleted .

PostPosted: Sun Aug 26, 2007 11:04 pm
by James Bott
Ehab,

XBrowse does an unusal type of refresh. I have tried a few things and found that this works. Change the Delete() method to this:

Code: Select all  Expand view
method _delete(oBrw,oDlg)
   if msgYesNo("Delete this record?")
      super:delete()
   endif
   ::skip(-1)
   ::skip(1)
   oBrw:refresh()
return self


James

PostPosted: Mon Aug 27, 2007 7:22 pm
by Ehab Samir Aziz
But that is not valid with first record in the browse and last record if I delete either of them ? I tried all possible methods from Xbrowse concerning the eof() , bof() with no success .
Thanks

PostPosted: Tue Aug 28, 2007 1:25 am
by James Bott
Ehab,

Gee, you want it to work all the time...Ok, if you insist.

Code: Select all  Expand view
method _delete(oBrw,oDlg)
   if msgYesNo("Delete this record?")
      super:delete()
   endif
   ::skip(-1)
   ::skip(0)
   oBrw:refresh()
return self



James

PostPosted: Tue Aug 28, 2007 6:06 am
by Ehab Samir Aziz
That is not working all the time . It works with first and last recrd but in the middle I need the previous code . That code does not detect bof() and eof()
Code: Select all  Expand view
   if ::eof() .OR. ::bof()
   ::skip(-1)
   ::skip(0)
   else
   ::skip(-1)
   ::skip(1)
   endif
   

PostPosted: Tue Aug 28, 2007 2:24 pm
by Ehab Samir Aziz
Yes I could solve it like this . It works :
Code: Select all  Expand view
method _delete(oBrw,oDlg)
   if msgYesNo("Delete this record?")
      super:delete()
   endif
   ::skip(1)   
   ::skip(0)   
if oBrw:eof()
   ::skip(-1)   
   ::skip(0)   
endif
oBrw:refresh()   

return self


How to pack . when ever I involve pack command I faced with DBF execlusive required !!

PostPosted: Tue Aug 28, 2007 2:39 pm
by James Bott
Ehab,

>How to pack . when ever I involve pack command I faced with DBF execlusive required !!

A better solution is to reuse deleted records. Change the delete method to blank out the record and the append method to look for blank records before adding a new one.

James

PostPosted: Tue Aug 28, 2007 2:45 pm
by James Bott
I should point out that this delete method should more properly be a method of the browse not the database class since it is dealing with browse issues not database issues. Making it a method of the database class means that you cannot use it when not browsing.

It is curious that none of the browses have delete methods. They would have to also handle arrays.

An alternative would be to make the above delete method of the datbase class something like browseDelete() instead.

James

PostPosted: Wed Aug 29, 2007 2:40 pm
by Ehab Samir Aziz
Could you please help in syntax . I failed totaly ?!
Thanks