Year RadCalendard for PublicHollidays

8 posts, 1 answers
  1. Marco
    Marco avatar
    87 posts
    Member since:
    Apr 2011

    Posted 22 Nov 2012 Link to this post

    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
  2. Creation of a new public holiday on doubleclick over a date
    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
  3. 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?

    .

     

  • Answer
    Boryana
    Admin
    Boryana avatar
    330 posts

    Posted 27 Nov 2012 Link to this post

    Hello Marco,

    Thank you for writing.

    Also, I would like to thank you for sharing your code, providing full information about your scenario, and for stating explicitly your requirements about the Aqua theme. I highly appreciate each one of these.

    Let me get to the questions at hand:

    1. I have modified the Aqua theme, so that now the CalendarCellElement handles a bit more states (see VSB1.png). Through these states it is possible to style the special days that appear in other months as regular cells. Thus, each special day will appear blue only in the month they belongs to. I hope this will help your boss. Further, I introduced a LightGrayText repository and applied it to all OtherMonth cells. Feel free to change the ForeColor property to any color you find appropriate.

    2. I cleared the styles applied for the Focused and Today states, however, I left the Selected styling. If you would like to remove the selected state, simply click the Remove All Repository Item Associations button for the CalendarCellElement.Selected state (VSB2.png)

    3. The modified Aqua theme applies a Verdana bold text repository to the  MonthViewElement and a non-bold repository to the CalendarTableElement. Thus, only the months' titles are bold.

    4. and 5. Feel free to customize the Weekend and SpecialDay states, so that they match your design (VSB3.png). If you experience any difficulties feel free to write back. I will do my best to assist you.

    I would like to include several articles that explain in details how to load a tssp file in the Visual Style Buidler tool, work with repository items, load themes in your application and apply them:

    I have added your suggestion for AddRange method of RadCalendar SpecialDays collection as a feature request to our Public Issue Tracker. To vote for it and subscribe for its status updates follow this link: http://www.telerik.com/support/pits.aspx#/public/winforms/13584. We will do our best to implement it in a future release. Your Telerik points have been updated for this request.

    I kindly ask you to open a new support ticket and attach a project that demonstrates the issue you experience with the RadListView. To provide you with assistance we will more information on your scenario.

    I hope you find my answer helpful. Let me know if you have any further requirements.

    Kind regards,
    Boryana
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  • UI for WinForms is Visual Studio 2017 Ready
  • Marco
    Marco avatar
    87 posts
    Member since:
    Apr 2011

    Posted 27 Nov 2012 Link to this post

    Hello Boryana

    First of all, thanks you for your quick answer !

    I haven't tested your solution yet, but I will study your link, try your improved Aquathem and upgrade my code as soon as possible. Of course I will give a final feedback when it's done.

    For the last two points, I will follow your recommendations when I got some time (I have a working solution and the project is going on production for the beginning of 2013, don't hurry be happy :-)
  • Boryana
    Admin
    Boryana avatar
    330 posts

    Posted 30 Nov 2012 Link to this post

    Hello Marco,

    I am looking forward to your final feedback.

    Regards,
    Boryana
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  • Marco
    Marco avatar
    87 posts
    Member since:
    Apr 2011

    Posted 04 Jan 2013 Link to this post

    Hello Boryana and happy new year !

     

    I have made a few test with your solution and "Waoo".

    But I have a few questions about theses theme and package.

    The global idea is to create a "custom" theme, based on your exemple which I will name "aqua_MyApplicationName". So I can do some other customisations on it. I have opened your .tssp files in VisualBuider, then "save as" with the new name and the Package option. I have include the new .tssp files to my project and added the two line of code for loading the package.

    On runtime, it works perfectly (Good news).

    On design mode, I'm lost ! The old theme (the default acqua) is still active. And I don't know how to load my customtheme. ThemeManager wants only .xml theme files and not a package file (.tssp). So I can't set the theme property for my controls and the ThemeResolutionServices doesn't do his work on Design.

    So should I explode my package (.tssp) to recover .xml files for feeding the ThemeManager (What's the interest to use package on a project in this case!) ?
    Is there a special manipulation to do for using package on design ?

    I haven't found an answer about it on your documentation (I haven't watch all the video for the moment :-))

  • Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 09 Jan 2013 Link to this post

    Hello Marco,

    Thank you for your reply.

    To get your theme to display in design time you have to create a theme component, similar to the predefined themes. Here is the code you can use:
    Public Class CustomTheme
        Inherits RadThemeComponentBase
        Public Sub New()
            ThemeRepository.RegisterTheme(Me)
        End Sub
     
        Public Overrides Sub Load()
            Dim resourceAssembly As Assembly = GetType(CustomTheme).Assembly
            Me.LoadResource(resourceAssembly, "ProjectDefaultNameSpace.ContainingFolder.CustomTheme.tssp")
        End Sub
     
        Public Overrides ReadOnly Property ThemeName() As String
            Get
                Return "CustomTheme"
            End Get
        End Property
    End Class

    A few things to note to get this to work.
    1. After you add the tssp file to your project change its BuildAction to Embedded Resource. You can do this by right-clicking the file in the Solution Explorer and selecting Properties from the context menu.
    2. You will have to rebuild your project for the component to appear in your toolbox. Once it does you can use it as you use the predefined themes. Also, you no longer have to use the ThemeResolutionService to apply the theme in runtime.
    3. You might want to place this code in a Class Library project and add a reference to the assembly that it produces if you will be using the theme component in more than one project.

    I hope this will be useful. Should you have further questions, I would be glad to help.
     
    Greetings,
    Ivan Petrov
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  • Marco
    Marco avatar
    87 posts
    Member since:
    Apr 2011

    Posted 10 Jan 2013 Link to this post

    Hello,

    It's okay for creating a new theme component. It appears in the toolbox on my custom componant. I have the right theme on design when I use the component.

    But on runtime, it's using the default theme if I remove the line of code concerning the ThemeResolutionServices ! I have the normal behavior (design + runtime working) if I change my custom theme to one of the legacy one.

    I can use my theme componant for design and ThemeResolutionServices for the runtime. I won't scream for two line of code :-)

    But for making things right if you have an idea (and some time to loose about it)...

    One more precision, I haven't make a specific Class Library Project for the componant
  • Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 15 Jan 2013 Link to this post

    Hello Marco,

    Thank you for your writing back.

    I was not able to reproduce the behavior you have described - the theme applied both at design time and runtime. I tested with both a theme component in a separate project/assembly and as a component in the current project. You should check whether you have any theming related code in your project that might change the theme. If you set an non existing theme name to controls they will fall back to ControlDefault. You can conduct an experiment and change the default theme. You can learn how by following this link to a Knowledge base article that explains what to do.

    I hope this will help. Feel free to write back with any further questions.
     
    All the best,
    Ivan Petrov
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  • Back to Top
    UI for WinForms is Visual Studio 2017 Ready