FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour xBrowse With DatePicker & TimePicker
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
xBrowse With DatePicker & TimePicker
Posted: Sat Feb 28, 2009 05:02 AM
Saludos/Regards

Hoy les dejo otra contribucion para la xBrowse, uso de DatePicker y TimePicker en edicion de celdas.
Other contribution for xbrowse class, use datepicker and timepicker in celledition


Comenzamos/Start
Este Link es un Exe si quieren probar antes de hacer cambios
this link is EXE, if you want to try first before making any changes ...

http://www.sitasoft.com/fivewin/test/testdtp.rar


Archivos a editar / file to edit
xbrowse.ch
xbrowse.prg

Metodos a Editar en xBrowse.prg/ Methods to Edit in xBrwose.prg
METHOD PaintData() CLASS TXBrwColumn
METHOD Edit() CLASS TXBrwColumn
function EditGetkeyDown()
METHOD PostEdit() CLASS TXBrwColumn


Abrir/open xBrowse.ch

Buscar / find
Code (fw): Select all Collapse
#define EDIT_GET_BUTTON       5


Agregar Despues/ Add After
Code (fw): Select all Collapse
#define EDIT_DATE             6
#define EDIT_TIME             7


Guardar/save

Abrir xBrowse.prg

Bucar / Find
Code (fw): Select all Collapse
#include "Report.ch"


Agregar Despues / Add After
Code (fw): Select all Collapse
#include "dtpicker.ch"


Buscar METHOD nEditType(); // Sets or Gets de Edit Mode / Find METHOD nEditType(); // Sets or Gets de Edit Mode

Agregar Antes / Add Before
Code (fw): Select all Collapse
   METHOD EditDateTime( nKey )


Buscar en METHOD PaintData() / Find in METHOD PaintData()
Code (fw): Select all Collapse
   if nType > 1
      if lSelected

Reemplazar con / Replace With
Code (fw): Select all Collapse
   if nType > 1 .and. nType < EDIT_DATE
      if lSelected


Buscar en Method Edit / Find In Edit Method
Code (fw): Select all Collapse
   aColors := Eval( ::bClrEdit )


Agregar Antes / Add Before
Code (fw): Select all Collapse
   if ::nEditType >= EDIT_DATE
      return ::EditDateTime( nKey )
   endif

Buscar en function EditGetkeyDown / Find in function EditGetkeyDown
Code (fw): Select all Collapse
   If lExit
      ::oEditGet:nLastKey := nKey
      ::oEditGet:End()
   Endif



Reemplazar con / Replace With please check it in http://forums.fivetechsupport.com/viewtopic.php?p=76306#p76306 (see post bellow)
Code (fw): Select all Collapse
   If lExit .and. ::nEditType != EDIT_DATE
      ::oEditGet:nLastKey := nKey
      ::oEditGet:End()
   else
      ::PostEdit()
   Endif


Buscar en function EditGetkeyDown / Find in function EditGetkeyDown
Code (fw): Select all Collapse
return nil


Agregar Depues / Add After
Code (fw): Select all Collapse
METHOD EditDateTime( nKey ) CLASS TXBrwColumn
local aColors
local lCenter, lRight
local nRow, nCol, nWidth, nHeight
local hBrush
local oFont
local uValue



   if ValType ( ::oEditFont ) == "B"
         oFont = Eval( ::oEditFont, Self )
    else
         oFont = ::oEditFont
   endif

   uValue  := Eval( ::bEditValue )

   aColors := Eval( ::bClrEdit )
   lCenter := ( ::nDataStrAlign == AL_CENTER )
   lRight  := ( ::nDataStrAlign == AL_RIGHT )

   nRow    := ( ( ::oBrw:nRowSel - 1 ) * ::oBrw:nRowHeight ) + ::oBrw:HeaderHeight()

   hBrush := CreateSolidBrush( aColors[ 2 ] )
   ::EraseData( nRow, ::nDisplayCol, ::oBrw:nRowHeight , hBrush )
   DeleteObject( hBrush )

   if ::nEditType == EDIT_DATE
      ::oEditGet := TDatePick():New( 0, 0, { | u | If(PCount()==0,uValue,uValue:= u ) }, ::oBrw, 0, 0, , aColors[ 1 ],;
                  aColors[ 2 ], oFont, .f., , , , .f., , , )
   else
      ::oEditGet := TTimePick():New( 0, 0, { | u | If(PCount()==0,uValue,uValue:= u ) }, ::oBrw, 0, 0, , aColors[ 1 ],;
                  aColors[ 2 ], oFont, .f., , , , .f., , , )
      ::oEditGet:SetTime( uValue )
   endif   
        
   nRow    := ( ( ::oBrw:nRowSel - 1 ) * ::oBrw:nRowHeight ) + ::oBrw:HeaderHeight() + 2
   nCol    := ::nDisplayCol + 3

   nWidth  := ::nWidth - 4

   nHeight := ::oBrw:nRowHeight - 4

   if ::bEditValid != nil
      ::oEditGet:bValid := { | oGet, lRet | oGet:lValidating := .T., lRet := Eval( ::bEditValid, oGet, Self ), oGet:lValidating := .F., If( ! lRet, oGet:SetFocus(),), lRet }
   endif

   ::oEditGet:bKeyDown   := { | nKey | EditGetkeyDown( Self, nKey ) }
   
   if ::nEditType != EDIT_DATE
      ::oEditGet:bLostFocus := { | oGet, hWndFocus | EditGetLostFocus( oGet, hWndFocus, ::oBrw, ::oEditGet, Self ) }
   endif


   ::oEditGet:nLastKey := 0

   ::oEditGet:Move( nRow, nCol, nWidth, nHeight, .t. )
   ::oEditGet:SetFocus()
   ::oEditGet:SelectAll()

   ::oBrw:lEditMode := .T.

    if ::lEditBorder
      WndBoxIn( ::oBrw:GetDC(), nRow-1, nCol-1, nRow + nHeight + 1, nCol + nWidth + 1)
       ::oBrw:ReleaseDC()
   endif

    if nKey != nil
      PostMessage( ::oEditGet:hWnd, WM_CHAR, nKey )
    endif

   ::oBrw:nLastEditCol := ::nPos        
    
        
RETURN .t.


Buscar En METHOD PostEdit / Find In METHOD PostEdit
Code (fw): Select all Collapse
      case ::nEditType == EDIT_GET


En linea Agregar Despues (Fin de Linea) / IN Line Add After (end of Line)

Code (fw): Select all Collapse
.or. ::nEditType >= EDIT_DATE


Guardar / Save

Ejemplo / Sample...
Code (fw): Select all Collapse
#include "fivewin.ch"
#include "xbrowse.ch"
#include "dtpicker.ch"

Function main()
local oWnd, oBrw, oBrw2, oFld
local aArray := { {"one",time(),DATE()},;
                  {"two",time(),DATE()},;
                  {"three",time(),DATE()},;
                  {"four",time(),DATE()},;
                  {"five",time(),DATE()} }


    set date format to "mm/dd/yyyy"

    use customer alias customer new

    define window oWnd title "Test DatePick and TimePick on xBrwose" 
    
  
    @ 0,0 FOLDER oFld OF oWnd size 300,300;
      PROMPTS "Array", "Dbf" 

    @ 0,0 xbrowse oBrw columns {1,2,3} array aArray of oFld:aDialogs[ 1 ] fastedit
    
    oBrw:nRowHeight := 25
    
    oBrw:aCols[ 1 ]:nEditType := EDIT_GET
    
    oBrw:aCols[ 2 ]:nEditType := EDIT_TIME
    oBrw:aCols[ 2 ]:nWidth := 130
    
    oBrw:aCols[ 3 ]:nEditType := EDIT_DATE
    oBrw:aCols[ 3 ]:nWidth := 130

    oBrw:lAutoappend := .f.
    oBrw:CreateFromCode()
    
    @ 0,0 xbrowse oBrw2 columns "first", "last", "hiredate" alias "customer" of oFld:aDialogs[ 2 ] fastedit
    
    oBrw2:nRowHeight := 25
    
    
    oBrw2:aCols[ 3 ]:nEditType := EDIT_DATE
    oBrw2:aCols[ 3 ]:nWidth := 130

    oBrw2:lAutoappend := .f.
    oBrw2:CreateFromCode()

    oWnd:oClient := oFld
    oFld:aDialogs[ 1 ]:oClient := oBrw
    oFld:aDialogs[ 2 ]:oClient := oBrw2
    
    activate window oWnd on init (oFld:aDialogs[ 1 ]:resize())
    
    
return nil
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: xBrowse With DatePicker &amp; TimePicker
Posted: Sat Feb 28, 2009 03:31 PM

Hello Daniel,
thank you very much. These are really useful features.

One question:
Is there a reason why you must commit a change made with the mouse with the enter key?

Thanks again,
Otto

Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: xBrowse With DatePicker &amp; TimePicker
Posted: Sat Feb 28, 2009 03:45 PM
thank otto for feedback

One question:
Is there a reason why you must commit a change made with the mouse with the enter key?


no for me, is xbrowse, when you do edit any cell, it never commit the change with mouse only enter key
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: xBrowse With DatePicker &amp; TimePicker
Posted: Sat Feb 28, 2009 04:23 PM

Hello Daniel,
but if you have a look at the object inspector of FW VISUAL it is different.
If you select a item with the mouse it is changed without ENTER.

I think it should be that way.
Best regards,
Otto

Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: xBrowse With DatePicker &amp; TimePicker
Posted: Sat Feb 28, 2009 05:32 PM

Otto...

Yes, you have reason but... dtpicker have edit features no button features

i dont know how get control on dtpicker button

:(

Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: xBrowse With DatePicker &amp; TimePicker
Posted: Sat Feb 28, 2009 05:33 PM
Please change this line on function EditGetkeyDown
find
Code (fw): Select all Collapse
         ::PostEdit()

replace with
Code (fw): Select all Collapse
      if lExit
         ::PostEdit()
      endif
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: xBrowse With DatePicker &amp; TimePicker
Posted: Sat Feb 28, 2009 06:39 PM

Hello Daniel,
thank you.
I will make the changes this evening.
Regards,
Otto

Continue the discussion