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
// Special Slot Source
// Adding Special Slots based on some Business Logic
// XAML FIle
//Special Style Selector
// Setting Special Slot Source in XAML
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
>