Empty date with DTPicker

Empty date with DTPicker

Postby Rimantas » Fri Jun 02, 2006 6:01 pm

Hi ,

How we can pass an empty date to DTPicker control ? I found the one advice in this forum for that , but that was for control from resources . I want to do that in runtime .

With best regards !
Rimantas U.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Postby dbzap » Mon Jun 05, 2006 8:41 pm

Rimantas.
I post the message with the question... but the control start by default with a defined date.
I change the control until new knowledge.
If you need a calendar control i have a litle one from my.

Regards
User avatar
dbzap
 
Posts: 189
Joined: Mon Nov 07, 2005 7:36 pm
Location: Chile

Postby Rimantas » Tue Jun 06, 2006 10:26 am

dbzap wrote:I post the message with the question... but the control start by default with a defined date.
I change the control until new knowledge.
If you need a calendar control i have a litle one from my.


I did it . I found one post from which i downloaded zipped package . So I changed some lines in tdtpickr.prg . Here is my changes :
- add to class DATA something logical DATA lEmptyDate ;
- in New( ) method describe , what you want default value for ::lEmptydate ;
- change Setdate Method()

Code: Select all  Expand view
METHOD SetDate( dDate )  CLASS TDatePick
   local dShow
   local dDat := dDate
   if empty( dDate )
      dDat := if( !::lEmptyDate, date(), dDate )
   endif
   dShow := dDat
   SetDatePick( ::hWnd, Year( dShow ), Month( dShow ), Day( dShow ), 0 )
   if Empty(dDate)
     SetDatePick( ::hWnd, Year( dShow ), Month( dShow ), Day( dShow ), 1 )
   endif
return Self


Now you can use in your sources , something like that, if you want that at first to set an empty date for control :
oDatPck:lEmptydate := .t.
oDatPck:SetDate( dDat )

Works fine . :-)) With best regards !

Full source code :
Code: Select all  Expand view
#include "FiveWin.ch"
#include "constant.ch"

#define COLOR_WINDOW         5
#define COLOR_WINDOWTEXT     8

#define CS_DBLCLKS           8
#define DTS_SHOWNONE         0x0002

#ifdef __XPP__
   #define Super ::TControl
   #define New _New
#endif

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

CLASS TDatePick FROM TControl

   CLASSDATA lRegistered
   DATA      lEmptyDate

   METHOD New( nRow, nCol, bSetGet, oWnd, nWidth, nHeight, bValid, nClrFore,;
               nClrBack, oFont, lDesign, oCursor, lPixel, cMsg, lUpdate,;
               bWhen, bChange, nHelpId,lEmp) CONSTRUCTOR

   METHOD ReDefine( nId, bSetGet,oWnd, nHelpId, cMsg, lUpdate, bWhen, bValid) CONSTRUCTOR

   METHOD cText( cText ) SETGET

   METHOD cToChar() INLINE Super:cToChar( "SysDateTimePick32" )

   METHOD Initiate( hDlg )

   METHOD SetDate( dDate )                                       // Modificado fgondi

   METHOD GetDate()        INLINE GetDatePick( ::hWnd )

   METHOD LostFocus( hCtrl )
   METHOD Change()
   METHOD Changed() INLINE ( Eval( ::bSetGet, ::GetDate() ), ::Change() )

   METHOD Refresh() INLINE ::SetDate( Eval( ::bSetGet ) )

ENDCLASS

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

METHOD New( nRow, nCol, bSetGet, oWnd, nWidth, nHeight, bValid, nClrFore,;
            nClrBack, oFont, lDesign, oCursor, lPixel, cMsg, lUpdate,;
            bWhen, bChange, nHelpId, lEmp ) Class TDatePick

   DEFAULT nRow     := 0, nCol := 0,;
           oWnd     := GetWndDefault(),;
           nWidth   := 100,;
           nHeight  := If( oFont != nil, oFont:nHeight, 22 ),;
           nClrFore := GetSysColor( COLOR_WINDOWTEXT ),;
           nClrBack := GetSysColor( COLOR_WINDOW ),;
           oFont    := oWnd:oFont,;
           nHelpId  := 100,;
           lDesign  := .f.,;
           lPixel   := .f.,;
           lUpdate  := .f.,;
           lEmp     := .t.

   ::cCaption  = ""
   ::nTop      = nRow * If( ! lPixel, BTN_CHARPIX_H, 1 )
   ::nLeft     = nCol * If( ! lPixel, BTN_CHARPIX_W, 1 )
   ::nBottom   = ::nTop  + nHeight
   ::nRight    = ::nLeft + nWidth
   ::nHelpId   = nHelpId
   ::oWnd      = oWnd
   ::oFont     = oFont
   ::bSetGet   = bSetGet
   ::lEmptyDate := lEmp
   if !lEmp
      ::nStyle    = nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP,;
      If( lDesign, WS_CLIPSIBLINGS, 0 ) )
     else
      ::nStyle    = nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP, DTS_SHOWNONE,;
      If( lDesign, WS_CLIPSIBLINGS, 0 ) )
   endif

   ::nId       = ::GetNewId()
   ::lDrag     = lDesign
   ::lCaptured = .f.
   ::cMsg      = cMsg
   ::lUpdate   = lUpdate
   ::bWhen     = bWhen
   ::bValid    = bValid
   ::bChange   = bChange

   InitCommon()

   if ! Empty( oWnd:hWnd )
      ::Create( "SysDateTimePick32" )
      oWnd:AddControl( Self )
      if oFont != nil
         ::SetFont( oFont )
      endif
   else
      oWnd:DefControl( Self )
   endif

   if lDesign
      ::CheckDots()
   endif

return Self

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

METHOD ReDefine( nId, bSetGet, oWnd, nHelpId, nClrFore, nClrBack,;
                 oFont, oCursor, cMsg, lUpdate, bWhen, bValid, bChanged ) Class TDatePick

   DEFAULT oWnd     := GetWndDefault(),;
           nClrFore := GetSysColor( COLOR_WINDOWTEXT ),;
           nClrBack := GetSysColor( COLOR_WINDOW ),;
           lUpdate  := .f.

   ::nId       = nId
   ::hWnd      = 0
   ::nHelpId   = nHelpId
   ::oWnd      = oWnd
   ::oFont     = oFont
   ::oCursor   = oCursor
   ::lCaptured = .f.
   ::lDrag     = .f.
   ::cMsg      = cMsg
   ::lUpdate   = lUpdate
   ::bWhen     = bWhen
   ::bValid    = bValid
   ::bSetGet   = bSetGet
   ::bChange   = bChanged

   InitCommon()
   ::Register()
   oWnd:DefControl( Self )
return Self

METHOD Initiate( hDlg ) Class TDatePick
   Super:Initiate( hDlg )
   ::cText = Eval( ::bSetGet )
return nil

METHOD cText( uVal ) CLASS TDatePick
   if PCount() == 1
      Eval( ::bSetGet, uVal )
      ::SetDate( uVal )
      ::Refresh()
      ::Change()
   endif
return ::GetDate()

//---------------------------------------------------------------------------//
// Controlo si la fecha esta vacia para quitar la marca del checkbox incluido en el campo
// El quinto parametro indica el estado del checkbox. 0 Marcado, 1 Desmarcado.

METHOD SetDate( dDate )  CLASS TDatePick
   local dShow
   local dDat := dDate
   if empty( dDate )
      dDat := if( !::lEmptyDate, date(), dDate )
   endif
   dShow := dDat
   SetDatePick( ::hWnd, Year( dShow ), Month( dShow ), Day( dShow ), 0 )
   if Empty(dDate)
     SetDatePick( ::hWnd, Year( dShow ), Month( dShow ), Day( dShow ), 1 )
   endif
return Self

METHOD LostFocus( hCtrl )  CLASS TDatePick
   Eval( ::bSetGet, ::cText )
return Super:LostFocus( hCtrl )

METHOD Change() CLASS TDatePick
   if ::bChange != nil
      Eval( ::bChange, Self )
   endif
return nil
Rimantas U.
User avatar
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania


Return to FiveWin for Harbour/xHarbour

Who is online

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