Alpha Video Training
Results 1 to 5 of 5

Thread: Embedded Calendar Supercontrol

  1. #1
    "Certified" Alphaholic Tom Henkel's Avatar
    Real Name
    Tom Henkel
    Join Date
    May 2002
    Location
    New Jersey, USA
    Posts
    1,875

    Default Embedded Calendar Supercontrol

    I am using the embedded Calendar for users to select a date. I am also disabling dates if they are before "today" or if a condition exists on a matching date record in a specific table.

    I have it working correctly for "This month", but I am stumped as to where to put code defining the "disabled" dates when we navigate to a new month.

    This is the code I use when we first initialize the calendar, and it works exactly as needed.

    Code:
    DIM SHARED V_DATE as D
    DIM end_month as N = day(month_end(date()))
    DIM SHARED varC_result as C
    DIM V_DATE_EmbeddedCalendar as P
    DIM V_DATE_EmbeddedCalendar.startWeekOnMonday as L
    DIM V_DATE_EmbeddedCalendar.disabled as P
    DIM V_DATE_EmbeddedCalendar.disabled.dates[end_month] as P
    
    dim tbl as P
    tbl = table.open("appt_control",FILE_RO_SHARED)
    tbl.index_primary_put("A_date")
    tbl.fetch_find(month_start(date()))
    dim j as N = 1
    while tbl.a_date<=month_end(date())
    	dim tdate as D = {}
    	if tbl.a_date<date() .or. tbl.date_closed
    		tdate = tbl.a_date
    		evaluate_template(evaluate_string("DIM V_DATE_EmbeddedCalendar.disabled.dates[{j}].date as D = \{{tdate}\}"))
    		evaluate_template(evaluate_string("DIM V_DATE_EmbeddedCalendar.disabled.dates[{j}].ignoreYear as L"))
    		j=j+1
    	end if
    	tbl.fetch_next()
    end while
    tbl.close()
    V_DATE_EmbeddedCalendar.disabled.dates.resize(j-1)
    it defines the fields in the pointer arrary "V_DATE_EmbeddedCalendar.disabled.dates".

    What I need to do is to redefine these fields and refresh the calendar when we navigate to another month.

    I added the code in RED to the "<<code>>" section of the dialog which doesn't work.

    Code:
    if a_dlg_button = "update_V_DATE_EmbeddedCalendar" then
    	a_dlg_button = ""
    	if V_DATE <> V_DATE_EmbeddedCalendar.date then
    		V_DATE_EmbeddedCalendar.date = V_DATE
    	end if
    	if month(v_date) <> month(date())
    		tbl = table.open("appt_control",FILE_RO_SHARED)
    		tbl.index_primary_put("A_date")
    		tbl.fetch_find(month_start(v_date))
    		dim j as N = 1
    		while tbl.a_date<=month_end(v_date)
    			dim tdate as D = {}
    			if tbl.date_closed
    				tdate = tbl.a_date
    				evaluate_template(evaluate_string("DIM V_DATE_EmbeddedCalendar.disabled.dates[{j}].date as D = \{{tdate}\}"))
    				evaluate_template(evaluate_string("DIM V_DATE_EmbeddedCalendar.disabled.dates[{j}].ignoreYear as L"))
    				j=j+1
    			end if
    			tbl.fetch_next()
    		end while
    		tbl.close()
    		V_DATE_EmbeddedCalendar.disabled.dates.resize(j-1)		
    	end if
    end if
    Any assistance would be greatly appreciated.

    Tom

  2. #2
    "Certified" Alphaholic Tom Henkel's Avatar
    Real Name
    Tom Henkel
    Join Date
    May 2002
    Location
    New Jersey, USA
    Posts
    1,875

    Default Re: Embedded Calendar Supercontrol

    The Help file states that I should be able to update the disabled.dates[] array elements in the "onMonthNavigate" event of the embedded Calendar control. I've been fiddling wit it all afternoon, to no avail. I wound up just pre-loading the array with our holidays, and then checking my appointment table for 6 months out. That seemed to work.

    Code:
    DIM SHARED V_DATE as D
    DIM end_month as N = month_end(addmonths(date(),6))-month_start(date())+15  'add 15 for holidays
    DIM SHARED varC_result as C
    DIM V_DATE_EmbeddedCalendar as P
    DIM V_DATE_EmbeddedCalendar.startWeekOnMonday as L
    DIM V_DATE_EmbeddedCalendar.disabled as P
    DIM V_DATE_EmbeddedCalendar.disabled.dates[end_month] as P
    
    dim j as N = 1
    for j = 1 to end_month
    		evaluate_template(evaluate_string("DIM V_DATE_EmbeddedCalendar.disabled.dates[{j}].date as D "))
    		evaluate_template(evaluate_string("DIM V_DATE_EmbeddedCalendar.disabled.dates[{j}].ignoreYear as L"))
    next j
    
    'lets get the holidays
    dim hd as P
    hd = table.open("holiday",FILE_RO_SHARED)
    hd.index_primary_put("Holiday")
    begyear = Ctod("01/01//"+cyear(date()))
    hd.fetch_find(begyear)
    j=1
    while year(hd.holiday)=year(date())
    	tdate = hd.holiday
    	evaluate_template(evaluate_string("V_DATE_EmbeddedCalendar.disabled.dates[{j}].date = \{{tdate}\}"))
    	j=j+1
    	if hd.eof()
    		exit while
    	end if
    	hd.fetch_next()
    end while
    'now the appointment dates
    'don't re-initialize "j" as it is pointing to the next array slot
    hd.close()
    dim tbl as P
    tbl = table.open("appt_control",FILE_RO_SHARED)
    tbl.index_primary_put("A_date")
    tbl.fetch_find(month_start(date()))
    while tbl.a_date<=month_end(addmonths(date(),6))
    	if tbl.eof()
    		exit while
    	end if
    	dim tdate as D = {}
    	if tbl.a_date<date() .or. tbl.date_closed
    		tdate = tbl.a_date
    		evaluate_template(evaluate_string("V_DATE_EmbeddedCalendar.disabled.dates[{j}].date = \{{tdate}\}"))
    		j=j+1
    	end if
    	tbl.fetch_next()
    end while
    tbl.close()
    V_DATE_EmbeddedCalendar.disabled.dates.resize(j-1)
    Note that dates before "today" are disabled, and the date of the 11th has no available appointments, now switch to April and see that Good Friday (a holiday) is disaBLED.

    Calendars.jpg

    Tom

  3. #3
    "Certified" Alphaholic Ray in Capetown's Avatar
    Real Name
    Ray Hendler
    Join Date
    Jan 2009
    Location
    South Africa
    Posts
    2,036

    Default Re: Embedded Calendar Supercontrol

    Nice one Tom.

  4. #4
    "Certified" Alphaholic Tom Henkel's Avatar
    Real Name
    Tom Henkel
    Join Date
    May 2002
    Location
    New Jersey, USA
    Posts
    1,875

    Default Re: Embedded Calendar Supercontrol

    Now there is a new twist. I need to DYNAMICALLY build the Disabled dates based on the value of a radio button selected earlier in the Dialog. Is there an event to trap on a radio button in x_dialog?

    We have 2 types of appointments, face-to-face, and telephone. The disabled dates are based on the number of available face-to-face or telephone slots available on a given date.
    If there are no face-to-face slots available, I want to disable that date only if the selected interview type is for face-to-face, however, if it is a telephone interview, and there is an available telephone interview on that same date, I need to make it enabled.

    Tom

  5. #5
    "Certified" Alphaholic Tom Henkel's Avatar
    Real Name
    Tom Henkel
    Join Date
    May 2002
    Location
    New Jersey, USA
    Posts
    1,875

    Default Re: Embedded Calendar Supercontrol

    I figured it out.

    I used the "change" event on the radio button to determine which type of dates to close.
    in the event code, I resize the disabled dates array back to its original size, then beginning after the holidays, populate it based on the type of dates I want to close.

    Works like a charm!!!!!

    Code:
    'Date Created: 07-Mar-2014 03:54:58 PM
    'Last Updated: 12-Mar-2014 12:32:22 PM
    'Created By  : Thomas Henkel
    'Updated By  : Thomas Henkel
    'Create an XDialog dialog box to prompt for parameters.
    'debugcheck()
    DIM SHARED V_DATE as D = Date()
    DIM end_month as N = month_end(addmonths(date(),6))-month_start(date())+15  'add 15 for holidays
    DIM SHARED varC_result as C
    DIM V_DATE_EmbeddedCalendar as P
    DIM V_DATE_EmbeddedCalendar.startWeekOnMonday as L
    DIM V_DATE_EmbeddedCalendar.disabled as P
    DIM V_DATE_EmbeddedCalendar.disabled.dates[end_month] as P
    DIM V_Type as C = ""
    dim j as N = 1
    for j = 1 to end_month
    		evaluate_template(evaluate_string("DIM V_DATE_EmbeddedCalendar.disabled.dates[{j}].date as D "))
    		evaluate_template(evaluate_string("DIM V_DATE_EmbeddedCalendar.disabled.dates[{j}].ignoreYear as L"))
    next j
    
    'lets get the holidays
    dim hd as P
    hd = table.open("holiday",FILE_RO_SHARED)
    hd.index_primary_put("Holiday")
    begyear = Ctod("01/01//"+cyear(date()))
    hd.fetch_find(begyear)
    j=1
    while year(hd.holiday)=year(date())
    	tdate = hd.holiday
    	evaluate_template(evaluate_string("V_DATE_EmbeddedCalendar.disabled.dates[{j}].date = \{{tdate}\}"))
    	j=j+1
    	if hd.eof()
    		exit while
    	end if
    	hd.fetch_next()
    end while
    'now the appointment dates
    'don't re-initialize "j" as it is pointing to the next array slot
    DIM i as N = j
    hd.close()
    'dim tbl as P
    'tbl = table.open("appt_control",FILE_RO_SHARED)
    'tbl.index_primary_put("A_date")
    'tbl.fetch_find(month_start(date()))
    'while tbl.a_date<=month_end(addmonths(date(),6))
    '	if tbl.eof()
    '		exit while
    '	end if
    '	dim tdate as D = {}
    '	if tbl.a_date<date() .or. tbl.date_closed
    '		tdate = tbl.a_date
    '		evaluate_template(evaluate_string("V_DATE_EmbeddedCalendar.disabled.dates[{j}].date = \{{tdate}\}"))
    '		j=j+1
    '	end if
    '	tbl.fetch_next()
    'end while
    'tbl.close()
    'V_DATE_EmbeddedCalendar.disabled.dates.resize(j-1)
    DIM V_DATE_EmbeddedCalendar.range as P
    DIM V_DATE_EmbeddedCalendar.range.useRange as L
    DIM V_DATE_EmbeddedCalendar.range.startDate as D
    DIM V_DATE_EmbeddedCalendar.range.endDate as D
    DIM V_DATE_EmbeddedCalendar.range.ignoreYear as L
    DIM V_DATE_EmbeddedCalendar.useDropdowns as L = .T.
    DIM V_DATE_EmbeddedCalendar.events as C = <<%str%
    ' The variable "ptr" provides a pointer to the calendar's properties.
    ' Properties that can be set at runtime are:
    '	ptr.date					as D - the date that is currently selected.
    '	ptr.focusDate				as D - the date that currently has focus on the calendar (setting this will navigate the calendar to the date).
    '	ptr.range.useRange			as L - whether to use the range restrictions.
    '	ptr.range.startDate			as D - start date of the range.
    '	ptr.range.startDate			as D - end date of the range.
    '	ptr.range.ignoreYear		as L - whether the range should be used every year.
    '	ptr.disabled.weekDays		as C - a comma separated list of days of the week to disable. (Note: if you have set the calendar to show Monday as the first day of the week, settings ptr.disabled.weekDays = "1" would disable Monday not Sunday)
    '	ptr.disabled.dates[]		as P - a property array of dates that will be rendered as disabled.
    '					.date		as D - the date to disable.
    '					.ignoreYear	as L - whether the date should be disabled every year.
    '	ptr.flaggedDates[]			as P - a property array of dates that will be rendered as flagged in the calendar.
    '					.date		as D - the date to flag.
    '					.color		as C - the color of the flag.
    '					.ignoreYear	as L - whether the date should be flagged every year.
    
    function onInitialize as v (ptr as p)
    	
    end function
    
    function onDateSelect as v (date as d, ptr as p)
    	
    	' Generated code. Do not delete!
    	' ------------------------------------------------------------------------
    	if eval_valid("ptr.variableName") then
    		dim sv as p
    		sv = session_variables()
    		evaluate_template("sv."+ptr.variableName+" = date")
    	end if
    	' ------------------------------------------------------------------------
    end function
    
    function onDateRightClick as v (date as d, ptr as p)
    	
    	' Generated code. Do not delete!
    	' ------------------------------------------------------------------------
    	if eval_valid("ptr.variableName") then
    		dim sv as p
    		sv = session_variables()
    		evaluate_template("sv."+ptr.variableName+" = date")
    	end if
    	' ------------------------------------------------------------------------	
    end function
    
    function onMonthNavigate as v (year as n, month as n, ptr as p)
    
    end function
    
    function onYearNavigate as v (year as n, month as n, ptr as p)
    	
    end function
    %str%
    DIM V_DATE_EmbeddedCalendar.style as P
    DIM V_DATE_EmbeddedCalendar.style.font as P
    DIM V_DATE_EmbeddedCalendar.style.font.size as N = 8
    DIM V_DATE_EmbeddedCalendar.style.font.bold as L
    DIM V_DATE_EmbeddedCalendar.style.font.italic as L
    
    DIM V_DATE_EmbeddedCalendar.date as D = V_DATE
    DIM V_DATE_EmbeddedCalendar.variableName as C = "V_DATE"
    ok_button_label = "&OK"
    cancel_button_label = "&Cancel"
    varC_result = ui_dlg_box("Alpha Five",<<%dlg%
    {region}
    Please select Interview Type:  (v_type={In Person, Telephone}!v_type_*);
    
    Please select Date:| {DatePicker=50,10V_DATE_EmbeddedCalendar}{watch=V_DATE!update_V_DATE_EmbeddedCalendar};
    {endregion};
    {line=1,0};
    {region}
    <*15=ok_button_label!OK> <15=cancel_button_label!CANCEL>
    {endregion};
    %dlg%,<<%code%
    'debugcheck()
    'traceln(a_dlg_button)
    if left(a_dlg_button,7)="v_type_"
    	if a_dlg_button = "v_type_change"
    	'debugcheck()		
    		'put code her to dynamically select disabled dates
    		if alltrim(v_type) = "Telephone"
    		  	expr1 = "tbl.phone_closed"
    		  else
    			expr1 = "tbl.date_closed"
    		end if
    		dim tbl as P
    '	Resize the disable date back to the original size
    '		Clear the disabled dates from j to the end
    		V_DATE_EmbeddedCalendar.disabled.dates.resize(end_month)
    		V_DATE_EmbeddedCalendar.disabled.dates.clear(i,end_month)
    		'populate the array with valid disabled dates
    		for n = i to end_month
    			evaluate_template(evaluate_string("DIM V_DATE_EmbeddedCalendar.disabled.dates[{n}].date as D "))
    			evaluate_template(evaluate_string("DIM V_DATE_EmbeddedCalendar.disabled.dates[{n}].ignoreYear as L"))
    		next n
    		j=i
    		tbl = table.open("appt_control",FILE_RO_SHARED)
    		tbl.index_primary_put("A_date")
    		tbl.fetch_find(month_start(v_date))
    		while tbl.a_date<=month_end(v_date)
    			dim tdate as D = {}
    			if tbl.a_date<date() .or. eval(expr1)
    				tdate = tbl.a_date
    				evaluate_template(evaluate_string("V_DATE_EmbeddedCalendar.disabled.dates[{j}].date = \{{tdate}\}"))
    				j=j+1
    			end if
    			tbl.fetch_next()
    		end while
    		tbl.close()
    		V_DATE_EmbeddedCalendar.disabled.dates.resize(j-1)
    	end if
    	a_dlg_button=""
    end if
    if a_dlg_button = "update_V_DATE_EmbeddedCalendar" then
    	a_dlg_button = ""
    	if V_DATE <> V_DATE_EmbeddedCalendar.date then
    		V_DATE_EmbeddedCalendar.date = V_DATE
    	end if
    
    end if
    %code%)
    Examples: I closed the 18th for "In person" appointments and the 17th for "telephone". Notice that the days are properly disabled.

    datepicker.jpg

    Hope this is helpful to anyone who need it.

    Tom

Similar Threads

  1. Calendar supercontrol refresh
    By Mike Wilson in forum Alpha Five Version 11 - Desktop Applications
    Replies: 8
    Last Post: 01-28-2013, 01:41 PM
  2. resetting calendar supercontrol
    By Mike Wilson in forum Alpha Five Version 10 - Desktop Applications
    Replies: 6
    Last Post: 02-21-2011, 12:50 AM
  3. calendar supercontrol events
    By enstorms in forum Alpha Five Version 10 - Desktop Applications
    Replies: 0
    Last Post: 11-13-2010, 11:58 AM
  4. calendar in embedded dialog supercontrol
    By crimmelcp in forum Alpha Five Version 9 - Desktop Applications
    Replies: 6
    Last Post: 08-02-2009, 08:13 PM
  5. Calendar Supercontrol daytimer view
    By netgeorger in forum Alpha Five Version 9 - Desktop Applications
    Replies: 0
    Last Post: 01-11-2009, 02:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •