This is a migrated thread and some comments may be shown as answers.

Refresh Schedule using Timer

5 Answers 87 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Brett
Top achievements
Rank 1
Brett asked on 02 Apr 2014, 06:19 PM
I'm having trouble getting the schedule view to update when changing the DataContext of the page using a DispatchTimer.  The timer executes correctly, but the data in the schedule view is the same data that populated on load.  I have attached a screenshot of my code.  I based my code off of the latest version of the Schedule_View_DB_CS project.  Could someone please review the screenshot and help me find a solution to update the ScheduleView.

Thanks,
Brett

5 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 03 Apr 2014, 01:11 PM
Hi Bret,

The example is implemented in order to load the appointments when the VisibleRange is changed, the event is fired also through the initial load of the ScheduleView which load them initially. So I assume this might be the issue in this case - when you are changing the DataContext in run time the VisibleRange is not actually changing and the Appointments are not loading from the server. What I can suggest you in order to avoid that behavior would be make the LoadAppointments method in the ViewModel public - this way when you set the new ViewModel you will be able to call the method from the code behind the following way and load the appointments:

this.DataContext = new ScheduleViewViewModel();
var visRange = scheduleView.VisibleRange;
(this.DataContext as ScheduleViewViewModel).LoadAppointments(new DateSpan(visRange.Start, visRange.End));

Hope this will work for you.

Regards,
Kalin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Brett
Top achievements
Rank 1
answered on 03 Apr 2014, 05:15 PM
I am working through the best possible way to keep a ScheduleView updated with a database.  I have about 25 different users that are going to be using the ScheduleView to create appointments.  These appointments are used the schedule preventive maintenance on commercial tractor/trailer units (semi’s). 

I have not been able to find a solution to keep the schedule view in sync with the database.  I have tried resetting the DataContext on the ScheduleView to a new instance of the ScheduleViewViewModel, using a Timer.  I made the suggested changes from your post and I still don’t have a solution. 

I have on instance of the Silverlight project running on a VM inside of Visual Studio.  I have another instance running on site that is publish to a local server. For testing, I have the Timer set to execute every 1 minute. I login as a different user in both instances. 

I create an appointment using the first user (user1) on the local site.  After one minute, the appointment is visible on the ScheduleView in the VM/VS instance.  This part of the update is working correctly.  I then go back into the instance running on
the local server and update one of the resources and change the category.  After a minute has passed, I check the MV/VS
instance, and the appointment is not updated. The Timer executes, but the appointment is not changed.

Then I went back to the instance running on the local server and moved an appointment.  Then checked the VM/VS instance, and the appointment did not move.  I have verified that the correct updates are being applied to the records in SQL Server. 

The problem is, the new instance of the ScheduleViewViewModel is not getting the latest changes from the database.  I set a breakpoint in VS in the ScheduleViewViewModel (see attached image). 

When I check the appointments collection, I only see the original appointment with the original values. None of the updates made by user1 are showing in the appointments collection and the updated values have posted to the database correctly.

Do you have any suggestions? 

What can I change to make sure the ScheduleView is updated, using the Timer, with modified records in the database?

Thank you,
Brett

0
Kalin
Telerik team
answered on 07 Apr 2014, 12:51 PM
Hi Brett,

Thanks for the further details. I tried to reproduce the same scenario using the two ScheduleViews and creating/editing an Appointment on the first one. After that using a timer I'm reloading the Appointments and it was working as expected they do appear as they should. My code behind looks as shown below:

public partial class MainPage : UserControl
{
    private DispatcherTimer timer;
 
    public MainPage()
    {
        InitializeComponent();
        this.timer = new DispatcherTimer();
        timer.Tick += timer_Tick;
        timer.Interval = new TimeSpan(0, 0, 0, 10);
        timer.Start();
             
    }
 
    void timer_Tick(object sender, EventArgs e)
    {
        var visRange = scheduleView.VisibleRange;
        (this.DataContext as ScheduleViewViewModel).LoadAppointments(new DateSpan(visRange.Start, visRange.End));
    }
}

I've also recorded a video which demonstrates the result of my test. What I can also suggest is to try to put the ScheduleView in edit state and the to commit the changes using the following methods:

this.radScheduleView.BeginEdit()
this.radScheduleView.Commit()

For more details about the approach above you can check the following article from our online help documentation:
http://www.telerik.com/help/silverlight/radscheduleview-end-user-capabilities-edit-appointment.html

I hope this will help you to achieve the requirements.

Regards,
Kalin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Brett
Top achievements
Rank 1
answered on 13 Apr 2014, 04:10 PM
Thank you for all of your help.

I was able to get the schedule view to refresh, the way I needed it to, by using the following code:

void timer_Tick(object sender, EventArgs e)
 
    {
    private MainPage mp = (MainPage)((BusyIndicator)Application.Current.RootVisual).Content;
    ScheduleViewRepository.Context.SqlAppointments.Clear();
        mp.ContentFrame.Refresh();      
 
    }
0
Kalin
Telerik team
answered on 14 Apr 2014, 08:22 AM
Hi Brett,

I'm glad you have managed to achieve the required. If you have any other questions, don't hesitate to contact us.

Regards,
Kalin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
ScheduleView
Asked by
Brett
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Brett
Top achievements
Rank 1
Share this question
or