IntervalLoadRatioCalculator.Calculate() Method
Calculates the ratio of the time occupied by appointments to the entire time interval.
Namespace: DevExpress.XtraScheduler.Tools
Assembly: DevExpress.XtraScheduler.v24.1.Core.Desktop.dll
NuGet Package: DevExpress.Scheduler.CoreDesktop
Declaration
Returns
Type | Description |
---|---|
Single | A Single value that is the time occupancy ratio. |
Remarks
This example uses the All-Day Area to display a worktime load, which is the ratio of the time occupied by appointments to the entire time interval. To calculate this parameter, the IntervalLoadRatioCalculator class instance is used.
Visual elements are painted using methods of the GraphicsCache object, available by the CustomDrawObjectEventArgs.Cache property.
public static void scheduler_CustomDrawDayViewAllDayArea(object sender, DevExpress.XtraScheduler.CustomDrawObjectEventArgs e)
{
AllDayAreaCell cell = (AllDayAreaCell)e.ObjectInfo;
Resource resource = cell.Resource;
TimeInterval interval = cell.Interval;
AppointmentBaseCollection apts = ((SchedulerControl)sender).Storage.GetAppointments(interval);
// Specify what precentage of the appointment duration should be painted.
float percent = CalcCurrentWorkTimeLoad(apts, interval, resource);
Brush brush;
// Select the brush color.
if (percent == 0.0)
brush = Brushes.LightYellow;
else if (percent < 0.5)
brush = Brushes.LightBlue;
else brush = Brushes.LightCoral;
// Paint the area with the selected color.
e.Cache.FillRectangle(brush, e.Bounds);
// Draw the percentage text.
StringFormat format = new StringFormat();
format.LineAlignment = StringAlignment.Center;
format.Alignment = StringAlignment.Center;
e.Cache.DrawString(string.Format("{0:P}", percent), cell.Appearance.Font, Brushes.Black, e.Bounds, format);
e.Handled = true;
}
private static float CalcCurrentWorkTimeLoad(AppointmentBaseCollection apts, TimeInterval interval, Resource resource)
{
AppointmentBaseCollection aptsByResource = new AppointmentBaseCollection();
var aptQuery = apts.Where(a => a.ResourceId.Equals(resource.Id));
aptsByResource.AddRange(aptQuery.ToList());
DevExpress.XtraScheduler.Tools.IntervalLoadRatioCalculator calc =
new DevExpress.XtraScheduler.Tools.IntervalLoadRatioCalculator(interval, aptsByResource);
return calc.Calculate();
}
See Also