xBrowse Con DatePicker y TimePicker

xBrowse Con DatePicker y TimePicker

Postby Daniel Garcia-Gil » Sat Feb 28, 2009 5:01 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: Select all  Expand view
#define EDIT_GET_BUTTON       5


Agregar Despues/ Add After
Code: Select all  Expand view
#define EDIT_DATE             6
#define EDIT_TIME             7


Guardar/save

Abrir xBrowse.prg

Bucar / Find
Code: Select all  Expand view
#include "Report.ch"


Agregar Despues / Add After
Code: Select all  Expand view
#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: Select all  Expand view
  METHOD EditDateTime( nKey )


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

Reemplazar con / Replace With
Code: Select all  Expand view
  if nType > 1 .and. nType < EDIT_DATE
      if lSelected


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


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

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



Reemplazar con / Replace With (revisar este cambio en el proximo post)
Code: Select all  Expand view
  If lExit .and. ::nEditType != EDIT_DATE
      ::oEditGet:nLastKey := nKey
      ::oEditGet:End()
   else
      ::PostEdit()
   Endif


Buscar en function EditGetkeyDown / Find in function EditGetkeyDown
Code: Select all  Expand view
return nil


Agregar Depues / Add After
Code: Select all  Expand view
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: Select all  Expand view
     case ::nEditType == EDIT_GET


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

Code: Select all  Expand view
.or. ::nEditType >= EDIT_DATE


Guardar / Save

Ejemplo / Sample

Code: Select all  Expand view
#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
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: xBrowse Con DatePicker y TimePicker

Postby Daniel Garcia-Gil » Sat Feb 28, 2009 5:34 pm

Descubri un pequeño bugs en estos cambios, aqui esta la solucion...

cambiar en function EditGetkeyDown
buscar
Code: Select all  Expand view
        ::PostEdit()
 

reemplazar con
Code: Select all  Expand view

      if lExit
         ::PostEdit()
      endif
 
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 87 guests