public ResolveAppointmentsEventArgs(DateTime start, DateTime end) { m_StartDate = start; m_EndDate = end; m_Appointments = new AppointmentList(); Appointment appointment = new Appointment(); appointment.Title = "Appointment 1"; appointment.StartDate = new DateTime(2007, 4, 5, 9, 0, 0); appointment.EndDate = new DateTime(2007, 4, 5, 10, 0, 0); m_Appointments.Add(appointment); }
private void DrawDays(PaintEventArgs e, Rectangle rect) { int dayWidth = rect.Width / daysToShow; AppointmentList longAppointments = (AppointmentList)cachedAppointments[-1]; AppointmentList drawnLongApps = new AppointmentList(); AppointmentView view; int y = dayHeadersHeight; bool intersect = false; List <int> layers = new List <int>(); if (longAppointments != null) { foreach (Appointment appointment in longAppointments) { appointment.Layer = 0; if (drawnLongApps.Count != 0) { foreach (Appointment app in drawnLongApps) { if (!layers.Contains(app.Layer)) { layers.Add(app.Layer); } } foreach (int lay in layers) { foreach (Appointment app in drawnLongApps) { if (app.Layer == lay) { if (appointment.StartDate.Date >= app.EndDate.Date || appointment.EndDate.Date <= app.StartDate.Date) { intersect = false; } else { intersect = true; break; } } appointment.Layer = lay; } if (!intersect) { break; } } if (intersect) { appointment.Layer = layers.Count; } } drawnLongApps.Add(appointment); // changed by Gimlei } foreach (Appointment app in drawnLongApps) { if (!layers.Contains(app.Layer)) { layers.Add(app.Layer); } } allDayEventsHeaderHeight = layers.Count * (horizontalAppointmentHeight + 5) + 5; Rectangle backRectangle = rect; backRectangle.Y = y; backRectangle.Height = allDayEventsHeaderHeight; renderer.DrawAllDayBackground(e.Graphics, backRectangle); foreach (Appointment appointment in longAppointments) { Rectangle appointmenRect = rect; int spanDays = appointment.EndDate.Subtract(appointment.StartDate).Days; if (appointment.EndDate.Day != appointment.StartDate.Day && appointment.EndDate.TimeOfDay < appointment.StartDate.TimeOfDay) { spanDays += 1; } appointmenRect.Width = dayWidth * spanDays - 5; appointmenRect.Height = horizontalAppointmentHeight; appointmenRect.X += (appointment.StartDate.Subtract(startDate).Days) * dayWidth; // changed by Gimlei appointmenRect.Y = y + appointment.Layer * (horizontalAppointmentHeight + 5) + 5; // changed by Gimlei view = new AppointmentView(); view.Rectangle = appointmenRect; view.Appointment = appointment; longappointmentViews[appointment] = view; Rectangle gripRect = appointmenRect; gripRect.Width = appointmentGripWidth; renderer.DrawAppointment(e.Graphics, appointmenRect, appointment, appointment == selectedAppointment, gripRect); } } DateTime time = startDate; Rectangle rectangle = rect; rectangle.Width = dayWidth; rectangle.Y += allDayEventsHeaderHeight; rectangle.Height -= allDayEventsHeaderHeight; appointmentViews.Clear(); layers.Clear(); for (int day = 0; day < daysToShow; day++) { if (day == 0) { rectangle.Width += (rect.Width % daysToShow) - 1; } DrawDay(e, rectangle, time); rectangle.X += dayWidth; time = time.AddDays(1); } }
// internal Dictionary<Appointment, AppointmentView> appointmentViews = new Dictionary<Appointment, AppointmentView>(); private void DrawAppointments(PaintEventArgs e, Rectangle rect, DateTime time) { DateTime timeStart = time.Date; DateTime timeEnd = timeStart.AddHours(24); timeEnd = timeEnd.AddSeconds(-1); AppointmentList appointments = (AppointmentList)cachedAppointments[time.Day]; if (appointments != null) { HalfHourLayout[] layout = GetMaxParalelAppointments(appointments); AppointmentList drawnItems = new AppointmentList(); for (int halfHour = 0; halfHour < 24 * 2; halfHour++) { HalfHourLayout hourLayout = layout[halfHour]; if ((hourLayout != null) && (hourLayout.Count > 0)) { for (int appIndex = 0; appIndex < hourLayout.Count; appIndex++) { Appointment appointment = hourLayout.Appointments[appIndex]; if (drawnItems.IndexOf(appointment) < 0) { Rectangle appRect = rect; int appointmentWidth; AppointmentView view; appointmentWidth = rect.Width / appointment.m_ConflictCount; int lastX = 0; foreach (Appointment app in hourLayout.Appointments) { if ((app != null) && (appointmentViews.Contains(app))) { view = appointmentViews[app]; if (lastX < view.Rectangle.X) { lastX = view.Rectangle.X; } } } if ((lastX + (appointmentWidth * 2)) > (rect.X + rect.Width)) { lastX = 0; } appRect.Width = appointmentWidth - 5; if (lastX > 0) { appRect.X = lastX + appointmentWidth; } appRect = GetHourRangeRectangle(appointment.StartDate, appointment.EndDate, appRect); view = new AppointmentView(); view.Rectangle = appRect; view.Appointment = appointment; appointmentViews[appointment] = view; e.Graphics.SetClip(rect); renderer.DrawAppointment(e.Graphics, appRect, appointment, appointment == selectedAppointment, appointmentGripWidth); e.Graphics.ResetClip(); drawnItems.Add(appointment); } } } } } }