oBtnSelCalendar:oPopUp:= { |oBtn| BtnPopCalMenu(@dFirst, @dLast,oDtpFirst,oDtpLast,dMin,dMax) }
obviously I added Update to the datepick controls
the problem is that the dates are not always updated at the first selection from menu, sometimes it happens that they update at the second selection
the test
- Code: Select all Expand view
#include "fivewin.ch"
#include "dtpicker.ch"
function Main()
local oDlg, oFont, oDtpFirst, oDtpLast
local dMin := {^ 2021/05/17 }
local dMax := {^ 2021/09/20 }
local dFirst := {^ 2021/04/08 }
local dLast := {^ 2021/04/08 }
SET DATE ITALIAN
SET CENTURY ON
DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-16
DEFINE DIALOG oDlg SIZE 500,240 PIXEL TRUEPIXEL FONT oFont ;
TITLE FWVERSION + " : RANGE OF DATES WITH TWO DATEPICKERS"
@ 30, 30 DTPICKER oDtpFirst VAR dFirst SIZE 200,28 PIXEL OF oDlg ;
PICTURE "ddd dd mmm yyyy" ;
ON CHANGE ( oDtpLast:SetRange( dFirst ), oDlg:Update() ) UPDATE
WITH OBJECT oDtpFirst
:lNoToday := .t.
:lNoTodayCircle := .t.
:SetRange( dMin, dMax )
END
@ 65, 30 BTNBMP PROMPT "-" SIZE 30,30 PIXEL OF oDlg FLAT ;
ACTION ( dFirst--, oDtpFirst:SetFocus() )
@ 65,200 BTNBMP PROMPT "+" SIZE 30,30 PIXEL OF oDlg FLAT ;
ACTION ( dFirst++, oDtpFirst:SetFocus() )
@ 30,250 DTPICKER oDtpLast VAR dLast SIZE 200,28 PIXEL OF oDlg ;
PICTURE "ddd dd mmm yyyy" ON CHANGE oDlg:Update() UPDATE
WITH OBJECT oDtpLast
:lNoToday := .t.
:lNoTodayCircle := .t.
:SetRange( dFirst, dMax )
END
@ 65,250 BTNBMP PROMPT "-" SIZE 30,30 PIXEL OF oDlg FLAT ;
ACTION ( dLast--, oDtpLast:SetFocus() )
@ 65,420 BTNBMP PROMPT "+" SIZE 30,30 PIXEL OF oDlg FLAT ;
ACTION ( dLast++, oDtpLast:SetFocus() )
@ 120, 30 SAY { || FW_TRANSFORM( dFirst, "ddd dd mmm yyyy" ) } SIZE 200,24 PIXEL OF oDlg UPDATE
@ 120,250 SAY { || FW_TRANSFORM( dLast, "ddd dd mmm yyyy" ) } SIZE 200,24 PIXEL OF oDlg UPDATE
@ 180,70 BTNBMP oBtnSelCalendar FILENAME "calendar.png" FLAT SIZE 40,24 PIXEL OF oDlg NOBORDER
oBtnSelCalendar:oPopUp:= { |oBtn| BtnPopCalMenu(@dFirst, @dLast,oDtpFirst,oDtpLast,dMin,dMax) }
@ 180,370 BUTTON "OK" SIZE 100,30 PIXEL OF oDlg ACTION oDlg:End()
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
? dFirst, dLast
return nil
//----------------------------------------------------------------------------------------------------------------//
Function BtnPopCalMenu(dFirst, dLast,oDtpFirst,oDtpLast,dMin,dMax)
Local oPopupDate
MENU oPopupDate POPUP 2015
MENUITEM "today" ACTION (dFirst:=date(),dLast:=date(),oDtpFirst:refresh(),oDtpLast:refresh())
MENUITEM "Tomorrow" ACTION (dFirst:=date()+1,dLast:=date()+1,oDtpFirst:refresh(),oDtpLast:refresh())
MENUITEM "After tomorrow" ACTION (dFirst:=date()+2,dLast:=date()+2,oDtpFirst:refresh(),oDtpLast:refresh())
MENUITEM "Week" ACTION (dFirst:=date(),dLast:=date()+6,oDtpFirst:refresh(),oDtpLast:refresh())
SEPARATOR
MENUITEM "Current Mounth" ACTION (dFirst:=bom(date()),dLast:=EoM(date()),oDtpFirst:refresh(),oDtpLast:refresh())
MENUITEM "Next Mounth" ACTION (dFirst:=AddMonth(bom(date()),1),dLast:=EoM(dFirst),oDtpFirst:refresh(),oDtpLast:refresh())
MENUITEM "Season" ACTION (dFirst:=dMin,dLast:=dMax,oDtpFirst:refresh(),oDtpLast:refresh())
SEPARATOR
MENUITEM "May" ACTION (dFirst:=AddMonth(Boy(date()),4),dLast:=EoM(dFirst),oDtpFirst:refresh(),oDtpLast:refresh())
MENUITEM "June" ACTION (dFirst:=AddMonth(Boy(date()),5),dLast:=EoM(dFirst),oDtpFirst:refresh(),oDtpLast:refresh())
MENUITEM "July" ACTION (dFirst:=AddMonth(Boy(date()),6),dLast:=EoM(dFirst),oDtpFirst:refresh(),oDtpLast:refresh())
MENUITEM "August" ACTION (dFirst:=AddMonth(Boy(date()),7),dLast:=EoM(dFirst),oDtpFirst:refresh(),oDtpLast:refresh())
MENUITEM "September" ACTION (dFirst:=AddMonth(Boy(date()),8),dLast:=EoM(dFirst),oDtpFirst:refresh(),oDtpLast:refresh())
ENDMENU
return oPopupDate
for a sample :
I set the dmin and dmax on
local dMin := {^ 2021/05/17 }
local dMax := {^ 2021/09/20 }
and it's logic the selections
"today"
"tomorrow"
"after tomorrow"
"week"
"current mounth"
not run because I 'm writing on today 2 May 2021 but if you change the date of your computer on 17 May it can change
the selection "next mouth" sometimes not run here , for a sample if you select before "Season" and then "next mounth " you'll see the dates are not updates
then Maj,june,july,september selections not update the datepick control the dates are update with the first day of the mouth seletected
on second time are updated if you select before another menuitem