Calendar & custom data binding

4 posts, 1 answers
  1. Wolfshund
    Wolfshund avatar
    50 posts
    Member since:
    Feb 2007

    Posted 03 Apr 2012 Link to this post

    Hi Telerik Team,

    At time I'm developing a small local database application (SQLCe) for our IT stuff to manage the retire/recycle dates or schedule of our Backup tape library. In past this was paper based, then Excel based, but as the tapes amount has increased now up to 400 tapes, finding retired tapes for recycle is a tedious work. At first I wrote a desktop application, but released that I had to write down the tape names to paper, taking it to the server room and replace the tapes. I then decided to write a WP7 app which I can then use in the server room. The app is now a about 50 percent complete. On the main page I have a pivot control with serveral pivot items containing RadDataboundList control(s) which I fill with various observablecollections i.e. today's tape retirements, tomorrow, last week, next seven days, ... etc. All its left to do is the managing the tape retirements (add, edit, delete) and of course the tapes itself (add,edit, delete). When I was working on this stuff, I had the idea, that I also could show the tape retirements in a calendar view combined with a list at bottom (daily), simliar to the calendar's FirstLook sample. A time, all existing retirements are displayed including completed ones.

    But as my table structure is different from the appointment structure, I want to ask how I can achieve the correct binding. I already have an ObservableCollection for all existing Tape retirements filled properly. As I don't have a end date,only a retire date, it could be the same, but zero length appointments are not supported (other forum thread). Here is my table structure:

    1. ID (PK, auto, int)  TapeRetireID
    2. TapeID (FK, int)    relation to Tape table  (TapeName is retrieved correctly through joint query)
    3. TapeRetireDate (datetime) Retire/Recycle Date & Time
    4. CompleteState (boolean)    Retire completed yes/no
    5. Notes (nvarChar)  Memo, just in case something has to be done with tape

    What I want to show in the calender's day cell is the TapeName, whereas I will show all details in the list if a day cell is selected. By the way, the list under the calender is also properly working, but as it is not bound to the calendar yet, it shows all retirements always.
    Is there any sample code available on custom calendar binding? Is this binding possible anyway?
    Kind regards,

    Joerg Schaum





  2. Answer
    Todor
    Admin
    Todor avatar
    778 posts

    Posted 05 Apr 2012 Link to this post

    Hi Joerg,

    Thank you for your question.

    Since you are interested in the achieving the look of the Calendar's FirstLook example then probably its code will be most useful for you. In order to have the properties that you need, you can create your own appointment class. Just make sure that it implements the IAppointment interface. The text that you see in the calendar cell is actually the Appointment's Subject so this should property should serve as the TapeName in you scenario. What you see in the bottom - the appointments list - is just a RadDataBoundListBox, which has an item template where you can specify which properties you want to be visible and how you want them to be arranged.
    To update the appointments you can change the ItemsSource of the DataBoundListBox when Calendar's SelectedValueChanged occurs and only the retirements that are relevant for the selected day with a method like the one used in the FirstLook example:
    private void DisplayAppointmentsForDate(DateTime date)
    {
        appointmentsSource.FetchData(date, date.AddDays(1));
        this.AppointmentsList.ItemsSource = appointmentsSource.GetAppointments((IAppointment appointment) =>
        {
            DateTime startDate = appointment.StartDate;
            DateTime endDate = appointment.EndDate;
            DateTime calendarStartDate = date.Date;
            DateTime calendarEndDate = date.AddDays(1);
     
            if (calendarStartDate >= startDate && calendarEndDate <= endDate)
            {
                return true;
            }
     
            if (startDate >= calendarStartDate && endDate <= calendarEndDate)
            {
                return true;
            }
     
            if (calendarStartDate >= startDate && calendarStartDate <= endDate)
            {
                return true;
            }
     
            if (calendarEndDate >= startDate && calendarEndDate <= endDate)
            {
                return true;
            }
            return false;
        });
    }
    In our online documentation you can find more information about how to display appointments, retirements, etc.

    I hope this helps. Let me know if you need additional assistance.

    Regards,
    Todor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Wolfshund
    Wolfshund avatar
    50 posts
    Member since:
    Feb 2007

    Posted 16 Apr 2012 Link to this post

    Hi Todor,
    thank you very much for your help! I got it to work (screenshot). Still need some XAML refine design, but its basically working.
    But I have two further questions:

    1. How do I bind my boolean field (Retire completed, checkbox) to the Appointment class?

    2. When I checked through the calendar's Firstlook code, I discovered, that, when the CalendarSelectedValue_changed event is triggered, it is lopping or filling the calendar appointmentsource every time during data fetch. What is the reason for this, and is this needed by the calendar control? I thought, I could fill the appointmentsource one time, and then only if a change is happening to the underlying database.

    Thank you very much.
    Kind regards,
    Joerg


  5. Todor
    Admin
    Todor avatar
    778 posts

    Posted 18 Apr 2012 Link to this post

    Hello Joerg,

    Thank you for getting back to us.

    I am not sure I understand correctly your first question. If you mean that you want to bind a CheckBox to a boolean property, you can bind the CheckBox's IsChecked property. If you mean that you want the Retire completed to display a "yes/no" text you can use a converter that takes boolean and return the corresponding string.
    As to your second question, yes you can have your appointment loaded so that you don't get them from the database each time. There isn't any limitation regarding this in the RadCalendar.

    I hope this information is useful. If you have other questions, don't hesitate to write us back.

    All the best,
    Todor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top