Hello Telerik Team
Small introduction:
I plan to use a RadCalendard on a project for display and edit the public holiday over a year. The list of public holiday is stored in a SQL database (one row is one day) and the data are fetch with EntityFramework. These days are also listed on a listview (with a filter based on the current year displayed on the calendard) for a different point of view. To add a new public holiday, has to doubleclick on the corresponding date in the calendar.
My RadYearCalendar is called YearCalendar
The public holiday are store in an entity called Jourferie with the following properties :
- ID As Integer
- Jour As Date
- Description As String
- IsPaid As Boolean
The ToString() Function have an override for displaying the date and the description of a Jourferie
My Radlistview is called ListJourFerie
I use a modal forms Add_Jourferie to get the description and the IsPaid properties when a new public holiday is added.
On this project I use Aqua theme (Not the best choice I agree, but my end-users love Appel's Stuff so...)
I appologize for the frenchy comments on my code !
Okay, so what I have done (could help someone else):
- A multiview calendard which display 12 month from january to december, with a correct year navigation.
- Fetch the data in my database, populate the special date and my listview.
Private
Sub
View_Calendrier_Load(sender
As
System.
Object
, e
As
System.EventArgs)
Handles
MyBase
.Load
'We do not want to bind to database in design mode !
If
Not
Me
.DesignMode
Then
_datactx =
New
IconEntities(ConnectionManager.GetConnection())
'Charge les données des jours feriés
Me
.ListJourFerie.DataSource = _datactx.Jourferie.OrderBy(
Function
(c) c.Jour)
Me
.YearCalendar.SpecialDays.Clear()
For
Each
holidayDay
As
JourFerie
In
_datactx.Jourferie
Me
.YearCalendar.SpecialDays.Add(
New
RadCalendarDay(holidayDay.Jour))
Next
'Déplace le calendrier sur l'année courante
Me
.YearCalendar.FocusedDate =
New
Date
(Today.Year, 1, 1)
End
If
End
Sub
- Filtering my listview using the period displayed on the calendard
Private
Sub
YearCalendar_ViewChanged(sender
As
System.
Object
, e
As
System.EventArgs)
Handles
YearCalendar.ViewChanged
If
Not
Me
.YearCalendar.IsLoaded
Then
Exit
Sub
Try
'Active le filtrage si nécessaire
If
Not
Me
.ListJourFerie.EnableFiltering
Then
Me
.ListJourFerie.EnableFiltering =
True
'Supprime les filtres actifs
Me
.ListJourFerie.FilterDescriptors.Clear()
'Filtre la liste afin d'afficher les enregistrements selon l'affichage du calendrier
Me
.ListJourFerie.FilterDescriptors.Add(
"Jour"
,
Telerik.WinControls.Data.FilterOperator.IsGreaterThanOrEqualTo,
Me
.YearCalendar.DefaultView.Children(0).ViewStartDate)
Me
.ListJourFerie.FilterDescriptors.Add(
"Jour"
,
Telerik.WinControls.Data.FilterOperator.IsLessThanOrEqualTo,
Me
.YearCalendar.DefaultView.Children(11).ViewEndDate)
Catch
ex
As
Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, ex.
GetType
.ToString)
End
Try
End
Sub
Private
Sub
YearCalendar_DoubleClick(sender
As
System.
Object
, e
As
Windows.Forms.MouseEventArgs)
Handles
YearCalendar.MouseDoubleClick
Dim
cell
As
CalendarCellElement = TryCast(
Me
.YearCalendar.ElementTree.GetElementAtPoint(e.Location), CalendarCellElement)
If
cell IsNot
Nothing
AndAlso
Not
cell.VisualState.Contains(
"Header"
)
Then
Dim
formAddJour
As
New
Add_Jourferie()
formAddJour.Jour.Text = cell.
Date
.ToShortDateString
If
formAddJour.ShowDialog() = DialogResult.OK
Then
Dim
newrecord
As
New
JourFerie()
With
{.Jour = cell.
Date
,
.Description = formAddJour.Description.Text,
.IsPaid = formAddJour.IsPaid.Checked}
_datactx.Jourferie.AddObject(newrecord)
Try
_datactx.SaveChanges()
Me
.YearCalendar.SpecialDays.Add(
New
RadCalendarDay(newrecord.Jour))
Me
.ListJourFerie.DataSource = _datactx.Jourferie.OrderBy(
Function
(c) c.Jour)
Catch
ex
As
UpdateException
MsgBox(
String
.Format(
"{0}{1}{2}"
, ex.Message, vbNewLine, ex.InnerException.Message), MsgBoxStyle.Exclamation, ex.
GetType
.ToString())
_datactx.Jourferie.DeleteObject(newrecord)
End
Try
End
If
End
If
End
Sub
But I need some help for :
- To hidde CellEment (also SpecialDays) in a CalendarTableElement when the day don't belong to the month. The default theme show a different style for theses days, but not Aqua theme. Also some specials days are displaying twice (on two CalendarTableElement) and this make the calendar not very clear. My boss will thinks that's there are too much public holiday and will make a heart attack.
- The focused date and today should display as other date because these informations are usless (in my case of course) and could hide a public holiday.
- Adding bold to month name.
- Change style on the weekend's CellElement
- Change style on the specialDay's CellElement (I don't really like the dark blue)
By the way... :
- Having a fast CalendardDayCollection.AddRange(IEnumerable Of Date) function would be great ! I haven't find something else than than an old "For Each Next Loop" for adding SpecialDays from my datasource. Each date takes 200 ms to add. It's not really fast.
- The listview do not update when it's databound to a ObjectSet (even with a datasource = Nothing and datasource = ObjectSet !). I have to use ObjectSet.Tolist() for a correct update. I Don't know if it is a correct behavior?
.