Create stardard Browse

Create stardard Browse

Postby Silvio.Falconi » Fri Dec 10, 2021 12:31 pm

I need to create a standard browse to avoid rewriting the same lines for all the archives, so I wanted to create something useful to easily recall
I saw the Nages xbrchild.prg example and tried to create my own test but ran into difficulties
obviously I open the archives with tdatabase

Image

as you can see I created a dialog with a buttonbar in the header
and I inserted a get to do the searches and a combobox to select the column on which to search
above on the left I have inserted a line counter (simple btnbmp) and other various buttons to facilitate viewing

I call the function simply with

Code: Select all  Expand view
BrowseDlg( .t., oDbf, "Anagrafica Agenti", aCols,bEdit )


in the test, however, I encountered a problem, when I call BrowseDlg() the procedure not show the archive

Image

not found the dbf ?????


and I didn't understand why

then trying with another archive different from customer.dbf the test makes me mistake when I insert


WHEN oDbf:OrdKeyCount() > 0

or

PROMPT tran(oDbf:OrdKeyNo(),'@E 999,999')+" / "+tran( oDbf:OrdKeycount(),'@E 999,999') ;

make me this error
Code: Select all  Expand view

  Error description: Error BASE/1004  No exported method: ORDKEYNO
   Args:
     [   1] = U  

Stack Calls
===========
   Called from:  => ORDKEYNO( 0 )
   Called from: test.prg => BROWSEDLG( 179 )
   Called from: test.prg => MAIN( 36 )
 



this is my test

Code: Select all  Expand view
#include "fivewin.ch"
#include "constant.ch"


REQUEST HB_Lang_IT
REQUEST HB_CODEPAGE_ITWIN


REQUEST DBFCDX
REQUEST DBFFPT
EXTERNAL ORDKEYNO,ORDKEYCOUNT,ORDCREATE,ORDKEYGOTO

static oFont, cDbfPath
//------------------------------------------------------------------//

function Main()

   local bXbr
   local oDlg, oBrw, oFont
   local oDbf
   local  aCols2    := { ;
        { "DESCRAGE",  "Denominazione"        ,,   200, },;
        { "IND",       "Indirizzo"            ,,   200, },;
        { "CODCATP",   "Categoria Provvigioni",,   200, }}


   local bEdit:= { |oRec| EditaTest( oRec,oDbf,oBrw ) }
   local  aCols    := { ;
        { "ID",  "Codice"        ,,   50, },;
        { "FIRST",  "Cognome"        ,,   200, },;
        { "LAST",       "Nome"            ,,   200, },;
        { "STREET",   "Indirizzo",,   200, }}


  /*
   oDbf:=TAgenti():New()
   oDbf:setorder(1)
   oDbf:Gotop()

   */


   oDbf:=Tcust():New()
   oDbf:setorder(1)
   oDbf:Gotop()


   DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-12

   BrowseDlg( .t., oDbf, "Anagrafica Agenti", aCols,bEdit )
   BrowseDlg()          // Standard TXBrowse


   SET XBROWSE TO MyBrowse() SAVE PREVIOUS TO bXBr
   // same as: bXBr := SetXBrowse( { || MyBrowse() } )

   // From now on all browses created use Child Class

  BrowseDlg()          // Child browse

   SET XBROWSE TO bXBr  // or "TO TXBrowse()"
   // same as: SetXBrowse( bXBr )

   // From now on all browses created use FWH tXBrowse

   BrowseDlg()          // Standard TXBrowse


   RELEASE FONT oFont

return nil



static function BrowseDlg( lSpecifyChild, oDbf,cTitle,aCols,bEdit )

   local oDlg, oBrw
   local nHt:= Int( ScreenHeight() * 0.5 )
   local nWd:= 800
   local oSay:=array(2)
   local cSeek:=Space(100)
   local oGet
   local oCont
   local aBtnBrow[3]
   local oCursorBtn :=TCursor():New(,'HAND')
   local oBar
   local oFont,oBold

default lSpecifyChild := .f.

      DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
      DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-14 BOLD



    if lSpecifyChild

       DEFINE DIALOG oDlg SIZE nWd, nHt PIXEL FONT oFont TRUEPIXEL;
      TITLE cTitle

   // buttonbar

      DEFINE BUTTONBAR oBar OF oDlg  SIZE 120,70  TOP NOBORDER  2015

     DEFINE BUTTON OF oBar PROMPT "Nuovo" FILENAME "NUOVO";
                       ACTION oBrw:EditSource( .T. )

     DEFINE BUTTON OF oBar PROMPT "Modifica" FILENAME "MODIFICA";
                       ACTION oBrw:EditSource() //WHEN oDbf:OrdKeyCount() > 0

     DEFINE BUTTON OF oBar PROMPT "Elimina" FILENAME "CANCELLA";
                       ACTION NIL  //WHEN oDbf:OrdKeyCount() > 0

     DEFINE BUTTON OF oBar PROMPT "Stampa" FILENAME "STAMPA";
             ACTION NIL
            // WHEN oDbf:OrdKeyCount() > 0

     DEFINE BUTTON OF oBar PROMPT "Uscita" FILENAME "USCITA";
                       ACTION oDlg:End()  BTNRIGHT

              oBar:bClrGrad := { | lPressed | If( ! lPressed,;
                               { { 1,  nRgb(233,229,206),nRgb(233,229,206) } },;
                               { {  1, nRgb( 245,244,234), nRgb( 245,244,234) } } ) }



     //search
     @ 12,15 say oSay[1] Prompt "Cerca :" SIZE 46,24 PIXEL OF oDlg FONT oBold
     @ 12,450 say oSay[2] Prompt "in" SIZE 40,24 PIXEL OF oDlg FONT oBold

     @ 10, 165 GET oGet VAR cSeek SIZE 250,25 PIXEL OF oDlg  ;
                      BITMAP "ELIMINA" ACTION (cSeek    := Space( 100 ),;
                      oBrw:Seek( "" ),oBrw:refresh(),oGet:refresh())
                      oGet:lBtnTransparent :=.t.







      @ 110,10 XBROWSE oBrw CLASS MyBrowse() OF oDlg ;
         DATASOURCE oDbf COLUMNS aCols ;
         SIZE -5,-10 PIXEL   AUTOSORT ;
         NOBORDER CELL LINES

       WITH OBJECT oBrw
            :nRowHeight          := 30
            :l2007               := .F.
            :l2015               := .T.
            :nColDividerStyle    := LINESTYLE_LIGHTGRAY
            :nRowDividerStyle    := LINESTYLE_LIGHTGRAY
            :nStretchCol         := STRETCHCOL_WIDEST
            :lAllowRowSizing     := .F.
            :lAllowColSwapping   := .F.
            :lAllowColHiding     := .F.
              * :RecSelShowRecNo()
            :nRecSelColor     :=   nRgb( 245,244,234)
            :lIncrFilter      := .t.
            :bOnSort          := { |b,oCol| oBrw:Seek( "" ), ;
                                   oBrw:cFilterFld := oCol:cExpr, ;
                                   oBrw:SetFocus() }
            :bClrStd    := { || { CLR_BLACK, If( oBrw:oCol( 1 ):Value, 0x80ffff, CLR_WHITE ) } }
            :bClrHeader       := {|| { ,nRgb( 245,244,234) } }
            :bClrFooter       := {|| { ,nRgb( 245,244,234) } }
            :lDrawBorder := .t.
            :lHScroll  := .f.
            :SetMultiSelectCol()
            :oSeek := oGet
            :bEdit  := bEdit
            :CreateFromCode()
         END



        oBrw:bChange   := { || RefreshCont(oCont,oDbf) }
        oBrw:bLDblClick = { || oBrw:EditSource(,, .T.) }




    @ 10, 550 COMBOBOX oBrw:oSortCbx VAR oBrw:cSortOrder;
        SIZE 200,400 PIXEL OF oDlg HEIGHTGET 20 STYLE CBS_DROPDOWN


       @ oBrw:nBottom+2,  5  BTNBMP oCont OF oDlg;
                PROMPT tran(oDbf:OrdKeyNo(),'@E 999,999')+" / "+tran( oDbf:OrdKeycount(),'@E 999,999') ;
                SIZE 90, 28  PIXEL FLAT NOROUND
        oCont:bClrGrad = { | lInvert | If( ! lInvert,;
                    { { 0.25, RGB( 238,236,219 ), RGB( 238,236,219 ) },;
                      { 0.75, RGB( 238,236,219 ), RGB( 238,236,219 ) } },;
                    { { 0.25, RGB( 238,236,219 ), RGB( 238,236,219 ) }, ;
                      { 0.75, RGB( 238,236,219 ), RGB( 238,236,219 ) } } ) }
                     oCont:nClrBorder := nRgb(218,214,179)
                     oCont:DISABLE()







   @ oBrw:nBottom+2, oBrw:nWidth-50 BTNBMP aBtnBrow[1]   ;
                FLAT  SIZE 30, 28  OF oDlg   PIXEL ;
                COLOR  nRgb(238,236,219),nRgb(238,236,219) ;
                BITMAP "REP_SU" NOROUND;
                ACTION oBrw:KeyDown(VK_UP, 0)

   @ oBrw:nBottom+2, oBrw:nWidth-35 BTNBMP aBtnBrow[2] ;
                FLAT  SIZE 30, 28  OF oDlg   PIXEL ;
                COLOR  nRgb(238,236,219),nRgb(238,236,219) ;
                BITMAP "REP_GIU" NOROUND;
                ACTION oBrw:KeyDown(VK_DOWN, 0)

   @ oBrw:nBottom+2, oBrw:nWidth-20 BTNBMP aBtnBrow[3] ;
                FLAT  SIZE 30, 28  OF oDlg   PIXEL ;
                COLOR  nRgb(238,236,219),nRgb(238,236,219) ;
                BITMAP "REP_IMP" NOROUND  ;
                ACTION NIL

          For n= 1 to 3
              aBtnBrow[n]:bClrGrad = { | lInvert | If( ! lInvert,;
                    { { 0.25, RGB( 238,236,219 ), RGB( 238,236,219 ) },;
                      { 0.75, RGB( 238,236,219 ), RGB( 238,236,219 ) } },;
                    { { 0.25, nRgb( 245,244,234), nRgb( 245,244,234) }, ;
                      { 0.75, nRgb( 245,244,234), nRgb( 245,244,234) } } ) }
             aBtnBrow[n]:nClrBorder := nRgb(218,214,179)
             aBtnBrow[n]:oCursor:=   oCursorBtn
          next

            oDlg:bResized  := <||
                  local oRect         := oDlg:GetCliRect()
                  oBrw:nHeight        := oRect:nBottom - 120
                  oSay[1]:nTop        := oRect:ntop+80
                  oSay[1]:nLeft       := oRect:nLeft+22
                  oSay[2]:nTop        := oRect:ntop+80
                  oSay[2]:nLeft       := oRect:nLeft+350
                  oGet:nTop           := oRect:ntop+81
                  oGet:nLeft          := oRect:nLeft+90
                  oBrw:oSortCbx:nTop  := oRect:ntop+81
                  oBrw:oSortCbx:nLeft := oRect:nLeft+370
                  oCont:nTop          := oRect:ntop+80
                  oCont:nLeft         := oBrw:nWidth-190
                  aBtnBrow[1]:nTop    := oRect:ntop+80
                  aBtnBrow[1]:nLeft   := oBrw:nWidth-98
                  aBtnBrow[2]:nTop    := oRect:ntop+80
                  aBtnBrow[2]:nLeft   := oBrw:nWidth-70
                  aBtnBrow[3]:nTop    := oRect:ntop+80
                  aBtnBrow[3]:nLeft   := oBrw:nWidth-40
                    oBrw:refresh()
                   RETURN nil
                   >
          ACTIVATE DIALOG oDlg CENTERED ;
              ON INIT (oDlg:resize(),ChangeButtons( oBar )  )


  ELSE

     DEFINE DIALOG oDlg SIZE 440,220 PIXEL FONT oFont TITLE 'TEST'

     @  10, 10 XBROWSE oBrw OF oDlg ;
          DATASOURCE oDbf  AUTOCOLS SIZE 200,70 PIXEL

     oBrw:CreateFromCode()

     @  90,170 BUTTON 'Close' SIZE 40,12 PIXEL OF oDlg ;
         ACTION oDlg:End()

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

   endif







* oDbf:Close()
RELEASE  oFont, oBold
RETURN NIL

//-----------------------------------------------------------//
 Function EditaTest( oRec,oDbf,oBrw )
            Msginfo("edit")
 return nil
//------------------------------------------------------------//

Function  RefreshCont(oCont,oDbf)
    if oCont != NIL
    oCont:cTitle := tran(oDbf:OrdKeyNo(),'@E 999,999')+" / "+tran( oDbf:OrdKeycount(),'@E 999,999')
    oCont:refresh()
   endif
   RETURN NIL
//------------------------------------------------------------//
 function ChangeButtons( oBar )
       AEval( oBar:aControls, { | oCtrl | oCtrl:nTop += 4, oCtrl:nHeight -= 4 } )
       return .T.
//------------------------------------------------------------//

//------------------------------------------------------------------//
//xbrchild.prg

CLASS MyBrowse FROM TXBrowse

   CLASSDATA lRegistered AS LOGICAL

   DATA bColClass INIT { || MyXBrCol() }

   METHOD New( oWnd ) CONSTRUCTOR

ENDCLASS

METHOD New( oWnd ) CLASS MyBrowse

   ::Super:New( oWnd )

   ::nMarqueeStyle   := MARQSTYLE_HIGHLROWMS
   ::SetColor( CLR_BLACK, RGB( 255,255,206 ) )
   ::bClrStd         := { || { CLR_BLACK, RGB( 255,255,206 ) } }
   ::bClrSelFocus    := { || { CLR_WHITE, CLR_BLUE } }
   ::bClrRowFocus    := { || { CLR_BLACK, RGB( 150,231,255 ) } }


return Self

CLASS MyXbrCol FROM TXBrwColumn

   METHOD Adjust()

ENDCLASS

METHOD Adjust() CLASS MyXBrCol

   if ::cDataType == 'D'
      ::cEditPicture := 'dd-mmm-yyyy'
   endif

   ::Super:Adjust()

return Self




//----------------------------------------------------------------------//
   CLASS TXData from TDataBase
       DATA cDbfPath INIT cFilePath( ExeName() ) + "Data\"
    ENDCLASS


   CLASS TAgenti from TXData
       METHOD New()
    ENDCLASS

    METHOD New( lShared ) CLASS TAgenti
       Default lShared := .t.
       ::Super:Open(,::cDbfPath + "
Agenti" ,"DBFCDX", lShared)
       if ::Used()
          ::setOrder(1)
          ::GoTop()
       endif
       return Self
//-------------------------------------------------------------------------//

     CLASS TCust from TXData
       METHOD New()
    ENDCLASS

    METHOD New( lShared ) CLASS TCust
       Default lShared := .t.
       ::Super:Open(,::cDbfPath + "
Customer" ,"DBFCDX", lShared)
       if ::Used()
          ::setOrder(1)
          ::GoTop()
       endif
       return Self





Any solution ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: Create stardard Browse

Postby Silvio.Falconi » Fri Dec 10, 2021 12:55 pm

resolved for the BrowseDlg() Now I see the dbf
BrowseDlg(,oDbf)


the ordkeyNo error I not found the solution
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: Create stardard Browse

Postby Silvio.Falconi » Sat Dec 11, 2021 1:07 pm

I found the problem
I have problem because I use Tdata instead of Tdatabase , I asked to james but not anwered me
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7052
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 89 guests