Set CustomDrawElements.ResourceViewCell if you need to draw inside the resource lanes instead of headers. Checking whether current cell intersects occupied time could look like this:
static class TimeRange
{
TimeRange(DateTime start, DateTime end)
{
this.start = start;
this.end = end;
}
DateTime start;
DateTime end;
}
List<TimeRange> occupied = new ArrayList<TimeRange>();
TimeRange occupiedPart(DateTime start, DateTime end)
{
for (TimeRange r : occupied)
{
if (end.isLessThanOrEqual(r.start))
continue;
if (r.end.isLessThanOrEqual(start))
continue;
DateTime from = start.isLessThan(r.start) ? r.start : start;
DateTime to = end.isLessThan(r.end) ? end : r.end;
return new TimeRange(from, to);
}
return null;
}
Since you are using the range selector which allows zooming, cells could be different than a whole hour, and you might want to fill them only partially:
void calendar_Draw(CalendarDrawEvent e)
{
AwtGraphics g = new AwtGraphics(e.getGraphics());
Brush brush = new SolidBrush(new Color(255, 0, 0, 75));
if (e.getElement() == CustomDrawElements.ResourceViewCell)
{
DateTime cellStart = DateTime.op_Addition(e.getDate(), e.getStartTime());
DateTime cellEnd = DateTime.op_Addition(e.getDate(), e.getEndTime());
TimeRange occupied = occupiedPart(cellStart, cellEnd);
if (occupied != null)
{
double ticksPerPixel =
(cellEnd.getTicks() - cellStart.getTicks()) /
e.getBounds().getWidth();
double startDx = (occupied.start.getTicks() - cellStart.getTicks()) / ticksPerPixel;
double endDx = (occupied.end.getTicks() - cellEnd.getTicks()) / ticksPerPixel;
Rectangle2D occupiedRect = new Rectangle2D.Double();
occupiedRect.setFrameFromDiagonal(
e.getBounds().getMinX() + startDx, e.getBounds().getMinY(),
e.getBounds().getMaxX() + endDx, e.getBounds().getMaxY());
g.fillRectangle(brush, occupiedRect);
}
}
}
I guess you will also be considering the e.getResource() value in all this, e.g. you could store a HashMap<Resource, occupied_time_list>, or your own resource model objects could store the list.
Instead of all the custom drawing, you could maybe represent unavailable times as locked items in the schedule, and just style those items.
Regards,
Slavcho
Mindfusion