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

Progress Bar is not updating inside the special slots

9 Answers 122 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Alapan
Top achievements
Rank 1
Alapan asked on 08 Nov 2011, 02:41 PM
Hi Team,

I have a requirement to show a progress bar (based on some business logic) for the resources who has booking on each day (in Week view). I am achieving this through special slot. Every thing is working fine (like applying special slots fo the days and resources which has bookings, setting the progrss bar value based on the booking for that resource on that day etc.) except one, the progress bar is not getting updated based on its binding value. 
                Whenever I am trying to edit the booking and modifying its data, I am adding theslots into the  SpecialSlots (SpecialSlots is observable collection my case), every data like I am using a textbox below the progress bar where I am binding one property (EffortHours) is of custom Slot class, another property "Effort" which is of same class is also getting update as I have tested it by setting it to textblock instead of progressbar but the filling of progress bar is not getting updated. But when I scrolled the ScheduleView to some position and then come back to view the modified booking , the progress bar is getting updated. I am trying it hard but not able to understand where is the problem.Also, I have also attached a screenshot to provide you a better picture.

I am also providing the related pieces of codes. which might hel you guys to analyse the problem.

//Custom Slot Class
public class WorkingHourOccurence : Slot
   {
 
       public float Effort
       {
           get;
           set;
       }
 
       public string EffortHours
       {
           get;
           set;
       }
 
       public override Slot Copy()
       {
           WorkingHourOccurence workingDayOcc = new WorkingHourOccurence();
           workingDayOcc.Start = this.Start;
           workingDayOcc.End = this.End;
           workingDayOcc.Effort = this.Effort;
           workingDayOcc.EffortHours = this.EffortHours;
           //workingDayOcc.RecurrencePattern = this.RecurrencePattern.Copy();
           workingDayOcc.Resources.AddRange(this.Resources);
           return workingDayOcc;
       }
 
   }

 // Special Slot Source
private ObservableCollection<Slot> specialSlots = null;
    public ObservableCollection<Slot> SpecialSlots
        {
            get { return specialSlots; }
            set { specialSlots = value; this.OnPropertyChanged("SpecialSlots"); }
        }

// Adding Special Slots based on some Business Logic

foreach (Trainer trainer in resourcesWithEffort)
    {
        for (DateTime dtT = startDate; dtT <= endDate; dtT = dtT.AddDays(1))
        {
            //
            var tempBookings = customBookingList.Where(b => b.StartDate == dtT && b.TrainerID == trainer.TrainerID && b.IsTimeBooking.HasValue?b.IsTimeBooking.Value:false);
 
            //
            var rangeBookings = customBookingList.Where(b => dtT >= b.StartDate && dtT < b.StartDate.Value.AddDays(b.Duration.HasValue ? b.Duration.Value : 1) && b.TrainerID == trainer.TrainerID && !(b.IsTimeBooking.HasValue ? b.IsTimeBooking.Value : false)).Select(b => b.Effort / (b.Duration.HasValue ? b.Duration.Value : 1));
            if (tempBookings.Count() > 0 && rangeBookings.Count() > 0)
            {
                float flEffort = tempBookings.Sum(b => (float)(b.Effort.Value)) + (float)(rangeBookings.Sum());
                //double flDuration = tempBookings.Sum(b => ((Booking)b).Duration) + rangeBookings.Sum(b => ((Booking)b).Duration);
 
                WorkingHourOccurence workingDayOcc = new WorkingHourOccurence();
                workingDayOcc.Effort = (float)Math.Round(flEffort * 100, 2);
                workingDayOcc.EffortHours = Math.Round(flEffort * 8, 2).ToString();
                workingDayOcc.Start = dtT;
                workingDayOcc.End = workingDayOcc.Start.AddDays(1);
                workingDayOcc.RecurrencePattern = new RecurrencePattern(dtT.Day, GetRecurrenceDayOfWeekDay(dtT.DayOfWeek), RecurrenceFrequency.Daily, 1, dtT.Month, null);
                if (resources != null)
                    workingDayOcc.Resources.Add(trainer);
                specialSlots.Add(workingDayOcc);
                workingDayOcc.Dispose();
            }
            else if (tempBookings.Count() > 0 && rangeBookings.Count() < 1)
            {
                float flEffort = tempBookings.Sum(b => (float)(b.Effort));
                //double flDuration = tempBookings.Sum(b => ((Booking)b).Duration);
                WorkingHourOccurence workingDayOcc = new WorkingHourOccurence();
                workingDayOcc.Effort = (float)Math.Round(flEffort * 100, 2); //(float)Math.Round((flEffort / flDuration) * 100, 2);
                workingDayOcc.EffortHours = Math.Round(flEffort * 8, 2).ToString();
                workingDayOcc.Start = dtT;
                workingDayOcc.End = workingDayOcc.Start.AddDays(1);
                workingDayOcc.RecurrencePattern = new RecurrencePattern(dtT.Day, GetRecurrenceDayOfWeekDay(dtT.DayOfWeek), RecurrenceFrequency.Daily, 1, dtT.Month, null);
                if (resources != null)
                    workingDayOcc.Resources.Add(trainer);
                specialSlots.Add(workingDayOcc);
                workingDayOcc.Dispose();
            }
            else if (tempBookings.Count() < 1 && rangeBookings.Count() > 0)
            {
                float flEffort = (float)(rangeBookings.Sum());// rangeBookings.Sum(b => ((Booking)b).Effort);
                //double flDuration = rangeBookings.Sum(b => ((Booking)b).Duration);
                WorkingHourOccurence workingDayOcc = new WorkingHourOccurence();
                workingDayOcc.Effort = (float)Math.Round(flEffort * 100, 2); //(float)Math.Round((flEffort / flDuration) * 100, 2);
                workingDayOcc.EffortHours = Math.Round(flEffort * 8, 2).ToString();
                workingDayOcc.Start = dtT;
                workingDayOcc.End = workingDayOcc.Start.AddDays(1);
                workingDayOcc.RecurrencePattern = new RecurrencePattern(dtT.Day, GetRecurrenceDayOfWeekDay(dtT.DayOfWeek), RecurrenceFrequency.Daily, 1, dtT.Month, null);
                if (resources != null)
                    workingDayOcc.Resources.Add(trainer);
                specialSlots.Add(workingDayOcc);
                workingDayOcc.Dispose();
            }
        }
 
        // Dispose();
 
    }

// XAML FIle
 //Special Style Selector
<local:SpecialSlotStyleSelector x:Key="SpecialSlotStyleSelector">
            <local:SpecialSlotStyleSelector.SaturdayStyle>
                <Style TargetType="telerik:HighlightItem">
                    <Setter Property="Background" Value="Silver" />
                </Style>
            </local:SpecialSlotStyleSelector.SaturdayStyle>
            <local:SpecialSlotStyleSelector.SundayStyle>
                <Style TargetType="telerik:HighlightItem">
                    <Setter Property="Background" Value="Silver" />
 
                </Style>
            </local:SpecialSlotStyleSelector.SundayStyle>
            <local:SpecialSlotStyleSelector.WorkingHourStyle>
                <Style TargetType="scheduleView:HighlightItem">
                    <Setter Property="Background" Value="Transparent" />
                    <Setter Property="VerticalAlignment" Value="Top" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="scheduleView:HighlightItem">
                                <Grid Height="25" Width="Auto" ShowGridLines="False" Background="Silver">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <telerik:RadProgressBar Width="Auto" Value="{Binding Path=Slot.Effort, Mode=TwoWay}" Maximum="100" Minimum="0" >
 
                                    </telerik:RadProgressBar>
                                    <TextBlock Margin="4 2" VerticalAlignment="Center" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Center" Text="{Binding Slot.EffortHours, Mode=TwoWay}" FontWeight="Bold"/>
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </local:SpecialSlotStyleSelector.WorkingHourStyle>
            <local:SpecialSlotStyleSelector.HolidayHourStyle>
                <Style TargetType="telerik:HighlightItem">
                    <Setter Property="Background" Value="Gray"></Setter>
                </Style>
            </local:SpecialSlotStyleSelector.HolidayHourStyle>
        </local:SpecialSlotStyleSelector>

 // Setting Special Slot Source in XAML
<scheduleView:RadScheduleView ...
SpecialSlotStyleSelector="{StaticResource SpecialSlotStyleSelector}"
SpecialSlotsSource="{Binding SpecialSlots, Mode=TwoWay}"
...>....</scheduleView:RadScheduleView>


9 Answers, 1 is accepted

Sort by
0
Pana
Telerik team
answered on 08 Nov 2011, 03:53 PM
Hello Alapan,

As far as I understand you are changing the Effort and EffortHours at runtime while UI for that Slot is visible. When you scroll away the virtualization removes that UI item and when you scroll back a new one is created so the value seems updated.

I guess the problem could be your Effrot and EffortHours does not notify for proeprty changes. Could you try calling OnPropertyChanged("Effort") and OnPropertyChanged("EffortHours") in the setters of these two proeprties?

Regards,
Pana
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Alapan
Top achievements
Rank 1
answered on 09 Nov 2011, 08:59 AM

Hi Pana,

Thanks for reply !!!

I have already tried it, but as I already said the value of Effort and Effort Hours is not a problem. It is updating well and good.I have tested it by placing a text blocks and seting the values to it. It was working fine for me. That means values are updating, only the problem is preogress bar. The progress bar is not getting updated and also first two or three times it is working but after that it started showing this problem.
Please try to produce this scenario at your end. Hoping for positive response.

Thanks
Alapan Sur

0
Alapan
Top achievements
Rank 1
answered on 09 Nov 2011, 09:00 AM

Hi Pana,

Thanks for reply !!!

I have already tried it, but as I already said the value of Effort and Effort Hours is not a problem. It is updating well and good.I have tested it by placing a text blocks and seting the values to it. It was working fine for me. That means values are updating, only the problem is preogress bar. The progress bar is not getting updated and also first two or three times it is working but after that it started showing this problem.
Please try to produce this scenario at your end. Hoping for positive response.

Thanks
Alapan Sur

0
Alapan
Top achievements
Rank 1
answered on 11 Nov 2011, 11:18 AM
Hello Pana,

I am still waiting for your response !!!

Thanks
Alapan Sur
0
Pana
Telerik team
answered on 11 Nov 2011, 04:47 PM
Hello Alapan,

I've figured it out. When you set the SpecialSlots collection you provide a bunch of Slots in there but when you render them on screen the RadScheduleView generates occurrences for them (like if you have recurrence pattern you have to show several UI elements for the same Slot) and so it does use the Copy and CopyFrom to create new objects and place them within in the view model you are trying to bind to. So the Slot instace you are binding to is actually a different instance of your objects. Copied somewhere back in time.

If you use some method to bind the values between copies you may introduce memory leak. Probably the only workaround I could figure out now is to Remove and Add  the Slot from the SpecialSlots collection. This sounds absurd even to me but we never intended to use the SpecialSlots as ContentControls that are about to show user data. Perhaps we will review that behavior in future and provide a better solution.

Kind regards,
Pana
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Alapan
Top achievements
Rank 1
answered on 15 Nov 2011, 08:25 AM
Hi Panna,

Thanks for your response.
The solution which you had suggested, I am already doing it although I missed to show that in the code I provided here. So I am providing you the complete method which I use to call for adding the slots:
private void AddSlots(List<Holiday> holidays)
        {
            specialSlots = specialSlots ?? new ObservableCollection<Slot>();
            specialSlots.Clear();
            if (holidays != null)
            {
                foreach (Holiday h in holidays)
                {
                    DateTime hDay = h.HolidayDate.GetValueOrDefault();
                    HolidayOccurence holiDayOcc = new HolidayOccurence();
                    holiDayOcc.Start = hDay;// new DateTime(2011, 6, 16);
                    holiDayOcc.End = hDay.AddDays(1);
                    holiDayOcc.RecurrencePattern = new RecurrencePattern() { DayOfMonth = hDay.Day, Frequency = RecurrenceFrequency.Yearly, Interval = 1, MonthOfYear = hDay.Month };
                    if (resources != null)
                        holiDayOcc.Resources.AddRange(resources);
                    specialSlots.Add(holiDayOcc);
                    holiDayOcc = null;
                }
            }
            SundayOccurence sundayOcc = new SundayOccurence();
            sundayOcc.Start = new DateTime(2011, 1, 1);
            sundayOcc.End = new DateTime(2011, 1, 1, 23, 59, 59);
            sundayOcc.RecurrencePattern = new RecurrencePattern(null, RecurrenceDays.Sunday, RecurrenceFrequency.Weekly, 1, null, null);
            if (resources != null)
                sundayOcc.Resources.AddRange(resources);
            specialSlots.Add(sundayOcc);
            sundayOcc.Dispose();
 
            SaturdayOccurence saturdayOcc = new SaturdayOccurence();
            saturdayOcc.Start = new DateTime(2011, 1, 1);
            saturdayOcc.End = new DateTime(2011, 1, 1, 23, 59, 59);
            saturdayOcc.RecurrencePattern = new RecurrencePattern(null, RecurrenceDays.Saturday, RecurrenceFrequency.Weekly, 1, null, null);
            if (resources != null)
                saturdayOcc.Resources.AddRange(resources);
            specialSlots.Add(saturdayOcc);
            saturdayOcc.Dispose();
 
            if (customBookingList != null)
            {
 
                var resourcesWithEffort = resources.Where(r => customBookingList.Select(b => b.TrainerID).Contains(r.TrainerID));
                foreach (Trainer trainer in resourcesWithEffort)
                {
                    for (DateTime dtT = startDate; dtT <= endDate; dtT = dtT.AddDays(1))
                    {
                        //
                        var tempBookings = customBookingList.Where(b => b.StartDate == dtT && b.TrainerID == trainer.TrainerID && b.IsTimeBooking.HasValue?b.IsTimeBooking.Value:false);
 
                        //
                        var rangeBookings = customBookingList.Where(b => dtT >= b.StartDate && dtT < b.StartDate.Value.AddDays(b.Duration.HasValue ? b.Duration.Value : 1) && b.TrainerID == trainer.TrainerID && !(b.IsTimeBooking.HasValue ? b.IsTimeBooking.Value : false)).Select(b => b.Effort / (b.Duration.HasValue ? b.Duration.Value : 1));
                        if (tempBookings.Count() > 0 && rangeBookings.Count() > 0)
                        {
                            float flEffort = tempBookings.Sum(b => (float)(b.Effort.Value)) + (float)(rangeBookings.Sum());
                            //double flDuration = tempBookings.Sum(b => ((Booking)b).Duration) + rangeBookings.Sum(b => ((Booking)b).Duration);
 
                            WorkingHourOccurence workingDayOcc = new WorkingHourOccurence();
                            workingDayOcc.Effort = (float)Math.Round(flEffort * 100, 2);
                            workingDayOcc.EffortHours = Math.Round(flEffort * 8, 2).ToString();
                            workingDayOcc.Start = dtT;
                            workingDayOcc.End = workingDayOcc.Start.AddDays(1);
                            workingDayOcc.RecurrencePattern = new RecurrencePattern(dtT.Day, GetRecurrenceDayOfWeekDay(dtT.DayOfWeek), RecurrenceFrequency.Daily, 1, dtT.Month, null);
                            if (resources != null)
                                workingDayOcc.Resources.Add(trainer);
                            specialSlots.Add(workingDayOcc);
                            workingDayOcc.Dispose();
                        }
                        else if (tempBookings.Count() > 0 && rangeBookings.Count() < 1)
                        {
                            float flEffort = tempBookings.Sum(b => (float)(b.Effort));
                            //double flDuration = tempBookings.Sum(b => ((Booking)b).Duration);
                            WorkingHourOccurence workingDayOcc = new WorkingHourOccurence();
                            workingDayOcc.Effort = (float)Math.Round(flEffort * 100, 2); //(float)Math.Round((flEffort / flDuration) * 100, 2);
                            workingDayOcc.EffortHours = Math.Round(flEffort * 8, 2).ToString();
                            workingDayOcc.Start = dtT;
                            workingDayOcc.End = workingDayOcc.Start.AddDays(1);
                            workingDayOcc.RecurrencePattern = new RecurrencePattern(dtT.Day, GetRecurrenceDayOfWeekDay(dtT.DayOfWeek), RecurrenceFrequency.Daily, 1, dtT.Month, null);
                            if (resources != null)
                                workingDayOcc.Resources.Add(trainer);
                            specialSlots.Add(workingDayOcc);
                            workingDayOcc.Dispose();
                        }
                        else if (tempBookings.Count() < 1 && rangeBookings.Count() > 0)
                        {
                            float flEffort = (float)(rangeBookings.Sum());// rangeBookings.Sum(b => ((Booking)b).Effort);
                            //double flDuration = rangeBookings.Sum(b => ((Booking)b).Duration);
                            WorkingHourOccurence workingDayOcc = new WorkingHourOccurence();
                            workingDayOcc.Effort = (float)Math.Round(flEffort * 100, 2); //(float)Math.Round((flEffort / flDuration) * 100, 2);
                            workingDayOcc.EffortHours = Math.Round(flEffort * 8, 2).ToString();
                            workingDayOcc.Start = dtT;
                            workingDayOcc.End = workingDayOcc.Start.AddDays(1);
                            workingDayOcc.RecurrencePattern = new RecurrencePattern(dtT.Day, GetRecurrenceDayOfWeekDay(dtT.DayOfWeek), RecurrenceFrequency.Daily, 1, dtT.Month, null);
                            if (resources != null)
                                workingDayOcc.Resources.Add(trainer);
                            specialSlots.Add(workingDayOcc);
                            workingDayOcc.Dispose();
                        }
                    }
 
                    // Dispose();
 
                }
            }
            IsTaskRunning = false;
        }

As you can see from the abosve code snippet, that I am clearing the Special Slot Collection. I am trying to understand here that this is what you mean to say or anything else.
Waiting for your your quick reply !!!!

Thanks
Alapan Sur
0
Pana
Telerik team
answered on 15 Nov 2011, 03:33 PM
Hello,

Yes, that's it. Does it work for you?

All the best,
Pana
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Alapan
Top achievements
Rank 1
answered on 15 Nov 2011, 04:43 PM
Hello Pana,

Yes, I have done that already from the very begining. But it is not working for me.
Please provide me a solution Pana to achieve this. It is creating a big mess !!!
Should I provide you any more details ?


Thanks
Alpaan Sur
0
Pana
Telerik team
answered on 17 Nov 2011, 10:40 AM
Hello,

I am attaching a project that does display progress. Could you check it out?

Greetings,
Pana
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Tags
ScheduleView
Asked by
Alapan
Top achievements
Rank 1
Answers by
Pana
Telerik team
Alapan
Top achievements
Rank 1
Share this question
or