#include "fivewin.ch"
#include "constant.ch"
#include "ttitle.ch"
REQUEST DBFCDX
static cSeek := ''
static oSeek
static nField
static cIniFile
REQUEST HB_Lang_IT
REQUEST HB_CODEPAGE_ITWIN
REQUEST DBFCDX
REQUEST DBFFPT
EXTERNAL ORDKEYNO,ORDKEYCOUNT,ORDCREATE,ORDKEYGOTO
FUNCTION Main()
local cDbf := "Cust"
local aBrowse
HB_LangSelect("IT")
HB_SetCodePage("ITWIN")
SET _3DLOOK ON
SET CENTURY ON
SET DATE ITALIAN
RDDSetDefault( 'DBFCDX' )
cIniFile := cFilePath( GetModuleFileName( GetInstance() ) ) + "tabledb.ini"
USE CUSTOMER ALIAS CUST
INDEX ON FIRST TAG FIRST TO TMFIRST MEMORY
INDEX ON LAST TAG LAST TO TMPLAST MEMORY
INDEX ON CITY TAG CITY TO TMPCITY MEMORY
INDEX ON STATE TAG STATE TO TMPSTATE MEMORY
cust->(dbsetorder(1))
cust->(dbgotop())
// { field, header, picture, size, justify, sortorder }
aBrowse := { { "CUST->FIRST", "First",, 120, },;
{ "CUST->LAST", "Last",, 120, },;
{ "CUST->STREET", "Street",, 180, },;
{ "CUST->CITY", "City",, 150, },;
{ "CUST->STATE", "State",, 50, }}
bedit:= { || MsgInfo( "modify" ) }
TableDb(aBrowse,cDbf,"Customers table","Cust",bedit)
RETURN NIL
//------------------------------------------------------------------------------------//
Function TableDb(aBrowse,cDbf,cTitle,cPrefix,bedit)
local oTabella
local oBrw,oSay1,oSay2
local oFont,oFontSmall,oBold
local oCursorBtn :=TCursor():New(,'HAND')
local nBottom := 28
local nRight := 99.9
local nWidth := Max( nRight * DLG_CHARPIX_W, 180 )
local nHeight := nBottom * DLG_CHARPIX_H
local aBtnBrow := array(4)
local aBtnNav := array(4)
local cSearch:=space(20)
local aGet[2]
local cField:=""
local aHdrs := {} //Headers
local aColumns := {}
local n
// da personalizzare
local cImage:= "C:\Work\fwh\bitmaps\contact.bmp"
local cTitle1:= "Customers"
local cTitle2:= "Insert the customer to search"
// local bNew,bEdit,bDel,bSearch,bPrint,bOk,bExit
local cSelected := ";"
if File( "CUSTSEL.TXT" )
cSelected := MEMOREAD( "CUSTSEL.TXT" )
endif
if Empty( cSelected )
cSelected := ";"
endif
nField :=1
//header
AAdd( aHdrs, "" )
AAdd( aColumns, "" )
for n= 1 to Len(aBrowse)
AAdd( aHdrs, aBrowse[n][2] )
AAdd( aColumns, aBrowse[n][1] )
next
DEFINE FONT oFont NAME 'Tahoma' SIZE 0, -16
DEFINE FONT oFontSmall NAME 'Tahoma' SIZE 0, -14
DEFINE FONT oBold NAME 'Tahoma' SIZE 0, -14 BOLD
DEFINE DIALOG oTabella TITLE cTitle ;
SIZE nWidth, nHeight FONT oFont ;
PIXEL TRUEPIXEL RESIZABLE COLOR CLR_BLACK, nRgb( 245,244,234)
@ 0,0 TITLE oTitle OF oTabella size oTabella:nwidth, 60 BORDER SHADOW NOSHADOW ;
GRADIENT { { 1, CLR_WHITE, CLR_WHITE } }
@ 10, 12 TITLETEXT OF oTitle TEXT cTitle1 FONT oBold COLOR CLR_GRAY
@ 28, 12 TITLETEXT OF oTitle TEXT cTitle2 FONT oFont COLOR CLR_HGRAY
@ 10, 12 TITLEIMG oImg OF oTitle BITMAP cImage SIZE 50,50 TRANSPARENT
@ 66,3 SAY oSay1 Prompt "Search " ;
FONT oBold SIZE 120,20 PIXEL OF oTabella TRANSPARENT
@ 42, 181 Say oSay2 Prompt "in" ;
FONT oBold SIZE 55, 20 PIXEL OF oTabella TRANSPARENT
DEFINE BUTTONBAR oBar OF oTabella SIZE 70,70 BOTTOM NOBORDER 2010
DEFINE BUTTON OF oBar PROMPT "New" ACTION If( oBrw:bEdit == nil, oBrw:Edit( .t. ), oBrw:EditSource( .t. ) )
DEFINE BUTTON OF oBar PROMPT "Modify" GROUP ACTION If( oBrw:bEdit == nil, oBrw:Edit(), oBrw:EditSource() )
DEFINE BUTTON OF oBar PROMPT "Delete" ACTION ( If( MsgNoYes( "Delete Record?" ), oBrw:Delete(), nil ), oBrw:SetFocus() )
DEFINE BUTTON OF oBar PROMPT "Print" ACTION If( Empty( oBrw:bPrint ), oBrw:Report(), oBrw:Print() )
DEFINE BUTTON OF oBar PROMPT "Exit" GROUP ACTION oTabella:End()
oBar:bClrGrad := { | lPressed | If( ! lPressed,;
{ { 1, nRgb(233,229,206),nRgb(233,229,206) } },;
{ { 1, nRgb( 245,244,234), nRgb( 245,244,234) } } ) }
@ 100,5 XBROWSE oBrw ;
SIZE 385,130 PIXEL;
OF oTabella ;
ALIAS cDbf COLUMNS aBrowse NOBORDER FOOTERS
FOR i := 1 TO LEN(oBrw:aCols)
oCol := oBrw:aCols[ i ]
oCol:bClrSelFocus := { || { CLR_BLACK, nRGB(202,224,252) } }
NEXT
WITH OBJECT oBrw
WITH OBJECT oBrw:InsCol(1)
:nwidth:= 30
:bEditValue := { || AScan( oBrw:aSelected, oBrw:BookMark ) > 0 }
:SetCheck( nil, .t.)
:nHeadBmpNo := { || If( Len( oBrw:aSelected ) == oBrw:nLen, 1, 2 ) }
:bFooter := { || ltrim(Str( Len(oBrw:aSelected))) }
:bLClickHeader := { || oBrw:SelectRow( If( Len( oBrw:aSelected ) == oBrw:nLen, 0, 4 ) ), oBrw:Refresh() }
End
:bLClicked := { |r,c,f,oBrw| If( oBrw:MouseColPos( c ) == 1 , ;
If( ( f := AScan( oBrw:aSelected, oBrw:BookMark ) ) == 0, ;
AAdd( oBrw:aSelected, oBrw:BookMark ), ;
ADel( oBrw:aSelected, f, .t. ) ), Nil ), ;
oBrw:RefreshCurrent() }
WITH OBJECT oBrw:aCols[ 2 ]
:bFooter := { || Ltrim( Str( oBrw:KeyNo() ) ) + " / " + LTrim( Str( oBrw:KeyCount() ) )+" customers" }
END
:bChange := { |o| o:RefreshFooters() }
:bKeyChar := { |k| If( k == VK_SPACE, ( oBrw:oCol( 1 ):CheckToggle(), oBrw:RefreshCurrent(), 0 ), nil ) }
:bLDblClick := { || oBrw:oCol( 1 ):CheckToggle(), oBrw:RefreshCurrent() }
:bClrStd := { || { CLR_BLACK, If( oBrw:oCol( 1 ):Value, 0x80ffff, CLR_WHITE ) } }
//
:l2007:=.f.
:lColDividerComplete := .t.
:lRecordSelector := .t.
:lHScroll := .f.
:nHeaderHeight := 30
:nRowHeight := 30
:nFooterHeight := 30
:nStretchCol := -1
:lDrawBorder := .t.
* :lIncrFilter := .t.
* :lSeekWild := .f.
:lAllowColHiding := .f.
:nRecSelColor := nRgb( 245,244,234)
:bClrHeader := {|| { ,nRgb(233,229,206) } }
:bClrFooter := {|| { ,nRgb( 245,244,234) } }
:nColDividerStyle := LINESTYLE_LIGHTGRAY
:nRowDividerStyle := LINESTYLE_LIGHTGRAY
END
@ 40, 45 GET aGet[1] VAR cSearch SIZE 250, 25 PIXEL OF oTabella ON CHANGE (oBrw:cSeek:=AllTrim( cSearch ) ) UPDATE
@ 40, 195 COMBOBOX aGet[2] var nField ITEMS aHdrs SIZE 130, 90 PIXEL;
OF oTabella HEIGHTGET 20 UPDATE ON CHANGE aGet[1]:SetFocus()
// aGet[1]:bKeyDown := { | nKey | KeyChar( oBrw, nKey,nField,cDbf,acolumns[nField],aGet[1]) }
aGet[1]:bKeyDown := { | nKey | KeyChar( oBrw, nKey,nField,cDbf, aGet[2]:cTitle, aGet[1]) }
oBrw:CreateFromCode()
//-----------------------------------------------------------------------//
@ 40, oBrw:nWidth-20 BTNBMP aBtnBrow[1] ;
FLAT SIZE 30, 30 OF oTabella PIXEL ;
COLOR nRgb(203, 225, 252),nRgb(238,236,219) ;
BITMAP ".\bitmaps\rinfresca.bmp" NOROUND;
tooltip "Clear the search" ;
ACTION ( (cDbf)->( DbClearFilter() ) ,;
(cDbf)->( Dbgotop() ) ,;
oBrw:refresh() ,;
cSearch:=space(60) ,;
aGet[1]:SetText( cSearch ) ,;
aGet[1]:refresh() ,;
cSeek := '' ,;
oBrw:cSeek:=AllTrim( cSearch ) ,;
aGet[1]:setfocus() )
@ oBrw:nBottom+2, oBrw:nWidth-50 BTNBMP aBtnBrow[2] ;
FLAT SIZE 30, 30 OF oTabella PIXEL ;
COLOR nRgb(238,236,219),nRgb(238,236,219) ;
BITMAP ".\bitmaps\su.bmp" NOROUND;
ACTION oBrw:KeyDown(VK_UP, 0)
@ oBrw:nBottom+2, oBrw:nWidth-35 BTNBMP aBtnBrow[3] ;
FLAT SIZE 30, 30 OF oTabella PIXEL ;
COLOR nRgb(238,236,219),nRgb(238,236,219) ;
BITMAP ".\bitmaps\giu.bmp" NOROUND;
ACTION oBrw:KeyDown(VK_DOWN, 0)
@ oBrw:nBottom+2, oBrw:nWidth-20 BTNBMP aBtnBrow[4] ;
FLAT SIZE 30, 30 OF oTabella PIXEL ;
COLOR nRgb(238,236,219),nRgb(238,236,219) ;
BITMAP ".\bitmaps\impostazioni.bmp" NOROUND;
ACTION ::ShowPopUp( { |oBtn| MenuContextual(oBtn,oBrw,cPrefix+"Aux",cDbf,aGet) } )
For n= 1 to 4
aBtnBrow[n]:bClrGrad = { | lInvert | If( ! lInvert,;
{ { 1, RGB( 225, 225, 225 ), RGB( 225, 225, 225 ) } },;
{ { 1, RGB( 229,241,251 ), RGB( 229,241,251 ) } } ) }
aBtnBrow[n]:nClrBorder := nRgb(218,214,179)
aBtnBrow[n]:oCursor:= oCursorBtn
next
oTabella:bResized := <||
local oRect := oTabella:GetCliRect()
oTitle:nWidth := oRect:nRight
oBrw:nWidth := oRect:nRight-10
oBrw:nHeight := oRect:nbottom-210
oImg:aImgs[2] := oRect:nRight-60
aGet[1]:nTop := oTitle:nBottom+5
aGet[1]:nLeft := oRect:nLeft+90
oSay1:nTop := oTitle:nBottom+7
oSay1:nLeft := oRect:nLeft+10
oSay2:nTop := oTitle:nBottom+7
oSay2:nLeft := oRect:nLeft+360
aGet[2]:nTop := oTitle:nBottom+5
aGet[2]:nLeft := oRect:nLeft+380
aBtnBrow[1]:nTop := oTitle:nBottom+5
aBtnBrow[1]:nLeft := oRect:nRight-37
aBtnBrow[2]:nTop := oBrw:nBottom+5
aBtnBrow[2]:nLeft := oRect:nRight-112
aBtnBrow[3]:nTop := oBrw:nBottom+5
aBtnBrow[3]:nLeft := oRect:nRight-75
aBtnBrow[4]:nTop := oBrw:nBottom+5
aBtnBrow[4]:nLeft :=oRect:nRight-37
return nil
>
oTabella:aMinMaxInfo := { nil, nil, nil, nil, 650,350, nil, nil }
oBrw:bSeek := nil
ACTIVATE DIALOG oTabella CENTER ;
ON INIT (otabella:resize(),EVAL( oTabella:bResized) )
return nil
//-----------------------------------------------------------------------------------------------------//
Function ChangeBrowse(oBrw,oControl)
local aItems:= {}
AEval( oBrw:aCols, { |o| If( o:lHide,,AAdd( aItems, o:cHeader ) ) } )
oControl[2]:setItems(aItems)
oControl[2]:refresh()
return nil
//-----------------------------------------------------------------------------------------------------//
function SelectColumns( oBrowse )
local oDlg, oBrw,oFont,oBold
local aSave := aCopy( oBrowse:aCols )
Local cSaveState:= oBrowse:SaveState()
DEFINE FONT oFont NAME 'Tahoma' SIZE 0, -16
DEFINE FONT oBold NAME 'Tahoma' SIZE 0, -14 BOLD
DEFINE DIALOG oDlg SIZE 400,400 PIXEL TRUEPIXEL ;
TITLE "Position Columns";
COLOR CLR_BLACK,nRgb(245,244,234)
DEFINE BUTTONBAR oBar OF oDlg SIZE 64,70 2010 BOTTOM NOBORDER
DEFINE BUTTON OF oBar PROMPT "Exit" FILE "NO_DLG";
ACTION ( oDlg:end( IDCANCEL ) )
DEFINE BUTTON OF oBar PROMPT "ok" FILE "OK_DLG";
ACTION ( oDlg:end( IDOK ) ) BTNRIGHT
oBar:bClrGrad := { | lPressed | If( ! lPressed,;
{ { 1, nRgb(233,229,206),nRgb(233,229,206) } },;
{ { 1, nRgb( 245,244,234), nRgb( 245,244,234) } } ) }
@ 10,20 XBROWSE oBrw SIZE -10,-90 PIXEL OF oDlg ;
DATASOURCE oBrowse:aCols ;
COLUMNS "cHeader", "lHide";
HEADERS "Columns","" ;
COLSIZES 100, 40 ;
NOBORDER FONT oFont
WITH OBJECT oBrw
:l2007:=.f.
:nStretchCol := STRETCHCOL_WIDEST
:lDrawBorder := .t.
:bClrHeader := {|| { ,nRgb(233,229,206) } }
:bClrFooter := {|| { ,nRgb( 245,244,234) } }
:nColDividerStyle := LINESTYLE_LIGHTGRAY
:lRecordSelector := .f.
:lHScroll := .f.
WITH OBJECT :aCols[ 2 ]
:bEditValue := { |x| If( x == nil, !oBrw:aRow:lHide, oBrw:aRow:lHide := !x ) }
:SetCheck( nil, .t. )
:nHeadBmpNo := 2
END
:CreateFromCode()
END
ACTIVATE DIALOG oDlg CENTERED;
ON INIT (oDlg:resize())
RELEASE oFont,oBold
IF oDlg:nresult == IDOK
oBrowse:refresh()
ENDIF
return nil
#define EM_GETSEL 176
static function KeyChar( oBrw, nKey,n,cdbf,cField,oControl,oSayCounter)
local nPos, cText
*If nKey == VK_BACK .and. ! Empty( cSeek )
If nKey == VK_BACK .and. cSeek != nil .and. Len( cSeek ) > 0
( oBrw:cAlias )->( IncrFilter( oBrw, Left( cSeek, Len( cSeek ) -1 ),n,cdbf,cField,oControl) )
nPos = nLoWord( oControl:SendMsg( EM_GETSEL ) ) + 1
if nPos < 1
return 0
endif
cText = oControl:GetText()
cText := HB_UTF8LEFT( cText, nPos - 2 ) + HB_UTF8SUBSTR( cText, nPos )
oControl:SetText( cText )
oControl:oGet:buffer = oControl:GetText()
oControl:oGet:pos := oControl:nPos := --nPos
oControl:SetPos( nPos )
oControl:setfocus() //get
return 0
* elseIf nKey > 31
elseIf nKey > 31 .and. nKey != Asc( '*' ) .and. nKey != Asc( '?' )
( oBrw:cAlias )->( IncrFilter( oBrw, cSeek + Chr( nKey ),n,cdbf,cField,oControl) )
oControl:setfocus() //get
return 0
Endif
return nil
//-----------------------------------------------------------------------------------------------------//
static function IncrFilter( oBrw,cPattern,n,cdbf,cField,oControl,oSayCounter)
local cFilter:="", lFound := .f.
local nRecNo, cSaveFilt, lStay
local cField_name :=alltrim(cField)
(cdbf)->(OrdSetFocus(n))
if ValType( cPattern ) == 'C'
if Empty( cPattern )
cSeek := ""
//
* oSeek:SetText( cSeek )
* oSeek:cText( cSeek )
* oSeek:REFRESH()
//
SET FILTER TO !DELETED()
GO TOP
oBrw:Refresh()
lFound := .t.
else
cFilter := 'WildMatch( "*' + Upper(cPattern) + '*", Upper( '+cField_name+')) .AND. !DELETED()'
cSaveFilt := DBFILTER()
nRecNo := RECNO()
lStay := &cFilter
SET FILTER TO &cFilter
GO TOP
if OrdKeyCount() == 0
SET FILTER TO &cSaveFilt
GO TOP
DBGOTO( nRecNo )
else
(cdbf)->(OrdSetFocus(n))
cSeek := cPattern
//
* oSeek:cText( cSeek )
* oSeek:REFRESH()
//
if lStay
DBGOTO( nRecNo )
oBrw:Refresh()
else
oBrw:Refresh( .t. )
endif
lFound := .t.
endif
endif
endif
return lFound
//-------------------------------------------------------------------------------------------//
Function MenuContextual(oControl,oBrw,cIniEntry,cDbf,aGet)
local oMenu
MENU oMenu POPUP
MENUITEM "Seleziona la linea corrente" ;
ACTION NIL
MENUITEM "Seleziona tutto"
MENUITEM "Esporta" Action NIL
MENUITEM "Colonne" ACTION ( SelectColumns( oBrw ) ,;
ChangeBrowse(oBrw,aGet), aGet[1]:SetFocus() )
ENDMENU
return oMenu
//-----------------------------------------------------------------------------------------//