Nueva Clase: TCalendar

Post Reply
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Nueva Clase: TCalendar

Post by Daniel Garcia-Gil »

Saludos...

nueva clase para el control SysMonthCal32, ahora nativa para fivewin,

permite realizar calendarios y manejarlos en forma bastante detallada,
3 caracteristicas importantes son:
1) Poder rasaltar fechas usando el estilo "Day State" (MCS_DAYSTATE), la clase detecta la cantidad de calendarios visibles y elabora un array de 31 posiciones para cada mes visible, que determinaran la cantidad maxima de dias posibles en un mes, solo se marcara la posicicion(es) (dias) que deseamos resaltar, se usa el Metodo SetArrayDayState( nMonth, nDay ), es importante decir, el control toma para este caso como primer mes visible 1, indistintamente que mes del año sea, es decir un calendario donde tengamos visibles 2 meses, nuetros array de fechas resaltadas (aDayState) sera de 2 filas con 31 columnas

2) El uso del dobleclik sobre las fechas, el control como tal no soporta dobleclick, pero esta simulado perfectamente, tomando los valores del registro de la velocidad actual del dobleclik

3) Soporta Accion con ENTER

http://www.sitasoft.net/fivewin/samples/testcal.zip

Image
ejemplo del codigo

Code: Select all | Expand

#include "FiveWin.ch"#include "dtpicker.ch"#include "calendar.ch"#include "wcolors.ch"FUNCTION Main()   LOCAL oWnd, oCal, oDtp1, oDtp2, oDtp3, oDtp4, oCbx   LOCAL oSayClr   LOCAL nColor   LOCAL dDate1, dDate2, dDate3, dDate4, dDate5, dDate6   LOCAL cItemClr   LOCAL lWeekNumbers   := .F.   LOCAL lNoTodayCircle := .F.   LOCAL lNoToday       := .F.   LOCAL lDayState      := .F.   LOCAL oRange3, aRanges2 := { , }   LOCAL oRange4   LOCAL aColorItems    := { "MCSC_BACKGROUND  " ,;                             "MCSC_TEXT        " ,;                             "MCSC_TITLEBK     " ,;                             "MCSC_TITLETEXT   " ,;                             "MCSC_MONTHBK     " ,;                             "MCSC_TRAILINGTEXT" }   LOCAL oDayOfWeek, cDayOfWeek:="Monday", aDayOfWeek:={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"}                                LOCAL oCal2   LOCAL oRange1, aRanges := { , }   LOCAL oRange2   LOCAL oMax, nMax   LOCAL lSunday   := .T.   LOCAL lSaturday := .T.     SET DATE TO BRITISH     SET EPOCH TO 1980      dDate1 = Date()   dDate2 = Date()   dDate3 = Date()   dDate4 = Date() + 7   dDate5 = Date()   dDate6 = Date()    DEFINE WINDOW oWnd TITLE "Test Calendar" FROM 0, 0 TO 600, 600 PIXEL     // Start Calendar 1      @ 001, 205 CALENDAR oCal VAR dDate1 OF oWnd PIXEL;              DBLCLICK MsgInfo( oCal:GetDate() );              ON CHANGE oDtp2:cText := oCal:GetDate() SIZE 200, 170;              ACTION( MsgInfo( "ok" ) );              WEEKNUMBER                 @ 001, 001 BUTTON "Get Today" OF oWnd PIXEL SIZE 100, 020 ACTION oDtp1:cText := oCal:GetToday()   @ 025, 001 BUTTON "Set Today" OF oWnd PIXEL SIZE 100, 020 ACTION oCal:SetToday( dDate1 )   @ 012, 105 DTPICKER oDtp1 VAR dDate1 OF oWnd PIXEL   @ 050, 001 BUTTON "Get Color" OF oWnd PIXEL SIZE 100, 020 ACTION( oSayClr:SetColor( CLR_BLACK, oCal:GetColors( oCbx:nAt - 1 ) ), oSayClr:Refresh() )   @ 050, 105 BUTTON "Set Color" OF oWnd PIXEL SIZE 100, 020 ACTION( nColor := ChooseColor(), ;                                                                     oCal:SetColor( oCbx:nAt - 1, nColor ), ;                                                                     oSayClr:SetColor( CLR_BLACK, nColor ),;                                                                     oSayClr:Refresh() )                                                                        @ 075, 001 COMBOBOX oCbx VAR cItemClr PROMPTS aColorItems PIXEL SIZE 205, 200 OF oWnd    @ 100, 001 SAY oSayClr VAR "        " PIXEL SIZE 100, 020 OF oWnd BORDER      @ 125, 001 BUTTON "Get 1 Day Week" OF oWnd SIZE 100, 20 PIXEL ACTION( cDayofWeek := aDayOfWeek[ oCal:GetFirstDayOfWeek() + 1 ], oDayOfWeek:Refresh() )   @ 125, 105 BUTTON "Set 1 Day Week" OF oWnd SIZE 100, 20 PIXEL ACTION( oCal:SetFirstDayOfWeek( oDayOfWeek:FindString( cDayOfWeek ) - 1 ) )       @ 150, 001 COMBOBOX oDayOfWeek VAR cDayofWeek ITEMS aDayOfWeek OF oWnd SIZE 205, 200 PIXEL   @ 175, 001 BUTTON "Get Selected Day" OF oWnd PIXEL SIZE 100, 020 ACTION Msginfo( oCal:GetDate() )   @ 200, 001 BUTTON "Set Selected Day" OF oWnd PIXEL SIZE 100, 020 ACTION oCal:SetDate( dDate2 )   @ 186, 105 DTPICKER oDtp2 VAR dDate2 OF oWnd PIXEL      @ 175, 210 BUTTON "Get Range" OF oWnd PIXEL SIZE 100, 020 ;              ACTION( aRanges2 := oCal:GetRange(), oRange3:Refresh(), oRange4:Refresh() )   @ 175, 310 GET oRange3 VAR aRanges2[ 1 ] OF oWnd SIZE 100, 20 PIXEL    @ 175, 420 GET oRange4 VAR aRanges2[ 2 ] OF oWnd SIZE 100, 20 PIXEL    @ 200, 210 BUTTON "Set Range" OF oWnd PIXEL SIZE 100, 020 ACTION oCal:SetRange( dDate5, dDate6 )   @ 200, 315 DTPICKER oDtp3 VAR dDate5 OF oWnd PIXEL   @ 200, 420 DTPICKER oDtp4 VAR dDate6 OF oWnd PIXEL      @ 001, 410 CHECKBOX oCal:lWeekNumbers PROMPT "Week Numbers" OF oWnd SIZE 100, 20 PIXEL;              ON CHANGE  oCal:SetWeekNumbers( oCal:lWeekNumbers )      @ 025, 410 CHECKBOX oCal:lNoTodayCircle PROMPT "No Today Circle" OF oWnd SIZE 100, 20 PIXEL;              ON CHANGE  oCal:SetNoTodayCircle( oCal:lNoTodayCircle )                 @ 050, 410 CHECKBOX oCal:lNoToday PROMPT "No Today" OF oWnd SIZE 100, 20 PIXEL;              ON CHANGE  oCal:SetNoToday( oCal:lNoToday )     oCal:bGotFocus  := {|| oCal:SetTitleBk( CLR_YELLOW ) }     oCal:bLostFocus := {|| oCal:SetTitleBk( GetSysColor( COLOR_ACTIVECAPTION ) ) }       // Start Calendar 2                 @ 250, 001 CALENDAR oCal2 VAR dDate3, dDate4 OF oWnd PIXEL MULTISELECT DAYSTATE;              DBLCLICK MsgInfo( oCal2:GetDate() ) SIZE 550, 170 COLOR CLR_BLACK, CLR_HRED   @ 230, 001 SAY "MONTHS DISPLAYED: " + StrZero( ocal2:GetVisibleMonths(), 2 )  OF oWnd PIXEL COLOR CLR_WHITE, CLR_BLACK   @ 430, 001 BUTTON "Get Selected Range" OF oWnd SIZE 100, 20 PIXEL ;              ACTION( aRanges := oCal2:GetDateRange(), oRange1:Refresh(), oRange2:Refresh() )   @ 430, 105 GET oRange1 VAR aRanges[ 1 ] OF oWnd SIZE 100, 20 PIXEL    @ 430, 210 GET oRange2 VAR aRanges[ 2 ] OF oWnd SIZE 100, 20 PIXEL      oCal2:bGotFocus  := {|| oCal2:SetTitleBk( CLR_YELLOW ) }     oCal2:bLostFocus := {|| oCal2:SetTitleBk( CLR_HRED ) }   nMax = oCal2:GetMaxSelCount()      @ 455, 001 BUTTON "Set Max Selected Day" OF oWnd SIZE 150, 20 PIXEL ;              ACTION( oCal2:SetMaxSelCount( nMax ) )                 @ 455, 155 GET oMax VAR nMax OF oWnd SIZE 50, 20 PIXEL SPINNER ;              MIN 1 MAX 60                 @ 480, 001 CHECKBOX oCal2:lDayState PROMPT "Day State" OF oWnd SIZE 100, 20 PIXEL;              ON CHANGE( oCal2:SetDayStateStyle( oCal2:lDayState ), ;                        If( oCal2:lDayState, ( OnGetState( oCal2, lSunday, lSaturday ), oCal2:SetDayState() ), ) )   @ 505, 001 CHECKBOX lSunday PROMPT "Bold Sunday" OF oWnd SIZE 100, 20 PIXEL   @ 530, 001 CHECKBOX lSaturday PROMPT "Bold Saturday" OF oWnd SIZE 100, 20 PIXEL    OnGetState( oCal2, lSunday, lSaturday )    oCal2:SetDayState()    oCal2:bOnGetState = { | oCal | OnGetState( oCal, lSunday, lSaturday ) }           ACTIVATE WINDOW oWnd RETURN NILFunction OnGetState( oCal, lSun, lSat )   LOCAL i, imax, j, jmax, nDay, nDayState, nMonth   LOCAL dStartDate    LOCAL dCurrentDay := oCal:dDate      oCal:GetMonthRange()      dStartDate = oCal:dDate    imax   := Len( oCal:aDayState )   nMonth := Month( dStartDate )   FOR i:=1 TO imax      nDayState := 0      FOR j:=1 TO 31         nDay := DoW( dStartDate ) - 2         IF nDay < 0            nDay += 7         ENDIF         IF nDay == 5 .AND. lSat            oCal:SetArrayDayState( i, j )         ENDIF         IF nDay == 6 .AND. lSUN            oCal:SetArrayDayState( i, j )         ENDIF                  dStartDate ++         IF Month( dStartDate ) <> nMonth            EXIT         ENDIF      NEXT      nMonth       := Month( dStartDate )   NEXT   oCal:SetDate( dCurrentDay )return nil 
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
User avatar
Patricio Avalos Aguirre
Posts: 1060
Joined: Fri Oct 07, 2005 1:56 pm
Location: La Serena, Chile
Contact:

Re: Nueva Clase: TCalendar

Post by Patricio Avalos Aguirre »

Daniel muy buena noticia

hay aveces que arroja este error

Code: Select all | Expand

Application===========   Path and name: C:\Documents and Settings\Patricio\Configuración local\Temp\wz7423\testcal.exe (32 bits)   Size: 1,465,856 bytes   Time from start: 0 hours 1 mins 44 secs    Error occurred at: 18/04/2010, 20:52:10   Error description: Error BASE/1132  Bound error: array access   Args:     [   1] = A   { ... }     [   2] = N   65543Stack Calls===========   Called from: C:\fivewin\svn\repo\samples\testcal.prg => (b)MAIN(67)   Called from: .\source\classes\BUTTON.PRG => TBUTTON:CLICK(176)   Called from: .\source\classes\CONTROL.PRG => TBUTTON:HANDLEEVENT(1446)   Called from: .\source\classes\WINDOW.PRG => _FWH(3383)   Called from:  => SENDMESSAGE(0)   Called from: .\source\classes\WINDOW.PRG => TWINDOW:COMMAND(1033)   Called from:  => TWINDOW:HANDLEEVENT(0)   Called from: .\source\classes\WINDOW.PRG => _FWH(3383)   Called from:  => WINRUN(0)   Called from: .\source\classes\WINDOW.PRG => TWINDOW:ACTIVATE(974)   Called from: C:\fivewin\svn\repo\samples\testcal.prg => MAIN(133)System======   CPU type: Intel(R) Pentium(R) Dual  CPU  T2330  @ 1.60GHz 1600 Mhz   Hardware memory: 2040 megs   Free System resources: 90 %        GDI    resources: 90 %        User   resources: 90
Saludos
Patricio

__________________________________________________________________
Version: Harbour 3.2.0dev (r1307082134),Compiler: Borland C++ 5.8.2 (32-bit)
PCode version: 0.3, FWH 13.2
http://www.sialm.cl
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: Nueva Clase: TCalendar

Post by Daniel Garcia-Gil »

Saludos Patricio...

al momento lo reviso, pero aparenta ser un problema en la logica del ejemplo ;)
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: Nueva Clase: TCalendar

Post by Daniel Garcia-Gil »

Patricio

esta correjido y subido en el mismo link, ciertamente el problema venia de la clase

Gracias por el feedback...
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
User avatar
txon
Posts: 38
Joined: Thu Oct 13, 2005 9:38 am
Location: Santurce / Vizcaya / España
Contact:

Re: Nueva Clase: TCalendar

Post by txon »

Queria probar la clase TCalendar, y me descarge el ejemplo que venia en el link, pero al compilar veo que me falta en la carpeta include el archivo calendar.ch.
Agradeceria que alguien me lo pueda enviar a mi email.

Gracias de antemano por vuestra yuda.
Un saludo
Un saludo
Alfonso Larrinaga
info@bsinformatica.net
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: Nueva Clase: TCalendar

Post by Daniel Garcia-Gil »

txon wrote:Queria probar la clase TCalendar, y me descarge el ejemplo que venia en el link, pero al compilar veo que me falta en la carpeta include el archivo calendar.ch.
Agradeceria que alguien me lo pueda enviar a mi email.

Gracias de antemano por vuestra yuda.
Un saludo


Saludos

viene con la distribucion de fivewin...
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
renato
Posts: 1
Joined: Fri Jan 25, 2013 1:20 pm

Re: Nueva Clase: TCalendar

Post by renato »

Olá Daniel

É possível definir a cor de vários dias ? como na imagem abaixo
Teria alguma sugestão para algo do tipo ?

Image


Abraços
Post Reply