protected virtual void OnResolveAppointments(ResolveAppointmentsEventArgs args) { System.Diagnostics.Debug.WriteLine("Resolve app"); if (ResolveAppointments != null) { ResolveAppointments(this, args); } this.allDayEventsHeaderHeight = 0; // cache resolved appointments in hashtable by days. cachedAppointments.Clear(); if ((selectedAppointmentIsNew) && (selectedAppointment != null)) { if ((selectedAppointment.StartDate > args.StartDate) && (selectedAppointment.StartDate < args.EndDate)) { args.Appointments.Add(selectedAppointment); } } foreach (Appointment appointment in args.Appointments) { int key = -1; AppointmentList list; if (appointment.StartDate.Day == appointment.EndDate.Day) { key = appointment.StartDate.Day; } else { // use -1 for exceeding one more than day key = -1; /** ALL DAY EVENTS IS NOT COMPLETE * this.allDayEventsHeaderHeight += horizontalAppointmentHeight; **/ } list = (AppointmentList)cachedAppointments[key]; if (list == null) { list = new AppointmentList(); cachedAppointments[key] = list; } list.Add(appointment); } }
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); }
protected virtual void OnResolveAppointments(ResolveAppointmentsEventArgs args) { System.Diagnostics.Debug.WriteLine("Resolve app"); if (ResolveAppointments != null) { ResolveAppointments(this, args); } this.allDayEventsHeaderHeight = 0; // cache resolved appointments in hashtable by days. cachedAppointments.Clear(); if ((selectedAppointmentIsNew) && (selectedAppointment != null)) { if ((selectedAppointment.StartDate > args.StartDate) && (selectedAppointment.StartDate < args.EndDate)) { args.Appointments.Add(selectedAppointment); } } foreach (Appointment appointment in args.Appointments) { int key; AppointmentList list; if (appointment.StartDate.Day == appointment.EndDate.Day && appointment.AllDayEvent == false) { key = appointment.StartDate.Day; } else { key = -1; } list = (AppointmentList)cachedAppointments[key]; if (list == null) { list = new AppointmentList(); cachedAppointments[key] = list; } list.Add(appointment); } }
private HalfHourLayout[] GetMaxParalelAppointments(AppointmentList appointments) { HalfHourLayout[] appLayouts = new HalfHourLayout[24 * 2]; foreach (Appointment appointment in appointments) { appointment.m_ConflictCount = 1; } foreach (Appointment appointment in appointments) { int firstHalfHour = appointment.StartDate.Hour * 2 + (appointment.StartDate.Minute / 30); int lastHalfHour = appointment.EndDate.Hour * 2 + (appointment.EndDate.Minute / 30); for (int halfHour = firstHalfHour; halfHour < lastHalfHour; halfHour++) { HalfHourLayout layout = appLayouts[halfHour]; if (layout == null) { layout = new HalfHourLayout(); layout.Appointments = new Appointment[20]; appLayouts[halfHour] = layout; } layout.Appointments[layout.Count] = appointment; layout.Count++; // update conflicts foreach (Appointment app2 in layout.Appointments) { if (app2 != null) { if (app2.m_ConflictCount < layout.Count) { app2.m_ConflictCount = layout.Count; } } } } } return(appLayouts); }
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); } }
private void DrawAppointments(PaintEventArgs e, Rectangle rect, DateTime time, string group) { 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, this.slotsPerHour); List <Appointment> drawnItems = new List <Appointment>(); for (int halfHour = 0; halfHour < 24 * slotsPerHour; 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 (appointment.Group != group) { continue; } if (drawnItems.IndexOf(appointment) < 0) { Rectangle appRect = rect; int appointmentWidth; AppointmentView view; appointmentWidth = rect.Width / appointment.conflictCount; int lastX = 0; foreach (Appointment app in hourLayout.Appointments) { if ((app != null) && (app.Group == appointment.Group) && (appointmentViews.ContainsKey(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; } DateTime appstart = appointment.StartDate; DateTime append = appointment.EndDate; // Draw the appts boxes depending on the height display mode // If small appts are to be drawn in half-hour blocks if (this.AppHeightMode == AppHeightDrawMode.FullHalfHourBlocksShort && appointment.EndDate.Subtract(appointment.StartDate).TotalMinutes < (60 / slotsPerHour)) { // Round the start/end time to the last/next halfhour appstart = appointment.StartDate.AddMinutes(-appointment.StartDate.Minute); append = appointment.EndDate.AddMinutes((60 / slotsPerHour) - appointment.EndDate.Minute); // Make sure we've rounded it to the correct halfhour :) if (appointment.StartDate.Minute >= (60 / slotsPerHour)) { appstart = appstart.AddMinutes((60 / slotsPerHour)); } if (appointment.EndDate.Minute > (60 / slotsPerHour)) { append = append.AddMinutes((60 / slotsPerHour)); } } // This is basically the same as previous mode, but for all appts else if (this.AppHeightMode == AppHeightDrawMode.FullHalfHourBlocksAll) { appstart = appointment.StartDate.AddMinutes(-appointment.StartDate.Minute); if (appointment.EndDate.Minute != 0 && appointment.EndDate.Minute != (60 / slotsPerHour)) { append = appointment.EndDate.AddMinutes((60 / slotsPerHour) - appointment.EndDate.Minute); } else { append = appointment.EndDate; } if (appointment.StartDate.Minute >= (60 / slotsPerHour)) { appstart = appstart.AddMinutes((60 / slotsPerHour)); } if (appointment.EndDate.Minute > (60 / slotsPerHour)) { append = append.AddMinutes((60 / slotsPerHour)); } } // Based on previous code else if (this.AppHeightMode == AppHeightDrawMode.EndHalfHourBlocksShort && appointment.EndDate.Subtract(appointment.StartDate).TotalMinutes < (60 / slotsPerHour)) { // Round the end time to the next halfhour append = appointment.EndDate.AddMinutes((60 / slotsPerHour) - appointment.EndDate.Minute); // Make sure we've rounded it to the correct halfhour :) if (appointment.EndDate.Minute > (60 / slotsPerHour)) { append = append.AddMinutes((60 / slotsPerHour)); } } else if (this.AppHeightMode == AppHeightDrawMode.EndHalfHourBlocksAll) { // Round the end time to the next halfhour if (appointment.EndDate.Minute != 0 && appointment.EndDate.Minute != (60 / slotsPerHour)) { append = appointment.EndDate.AddMinutes((60 / slotsPerHour) - appointment.EndDate.Minute); } else { append = appointment.EndDate; } // Make sure we've rounded it to the correct halfhour :) if (appointment.EndDate.Minute > (60 / slotsPerHour)) { append = append.AddMinutes((60 / slotsPerHour)); } } appRect = GetHourRangeRectangle(appstart, append, appRect); view = new AppointmentView(); view.Rectangle = appRect; view.Appointment = appointment; appointmentViews[appointment] = view; e.Graphics.SetClip(rect); if (this.DrawAllAppBorder) { appointment.DrawBorder = true; } // Procedure for gripper rectangle is always the same Rectangle gripRect = GetHourRangeRectangle(appointment.StartDate, appointment.EndDate, appRect); gripRect.Width = appointmentGripWidth; renderer.DrawAppointment(e.Graphics, appRect, appointment, appointment == selectedAppointment, gripRect); e.Graphics.ResetClip(); drawnItems.Add(appointment); } } } } } }
private void DrawDay(PaintEventArgs e, Rectangle rect, DateTime time) { renderer.DrawDayBackground(e.Graphics, rect); Rectangle workingHoursRectangle = GetHourRangeRectangle(workStart, workEnd, rect); if (workingHoursRectangle.Y < this.HeaderHeight) { workingHoursRectangle.Height -= this.HeaderHeight - workingHoursRectangle.Y; workingHoursRectangle.Y = this.HeaderHeight; } // Handle Saturday and Sunday switch (time.DayOfWeek) { case DayOfWeek.Monday: case DayOfWeek.Tuesday: case DayOfWeek.Wednesday: case DayOfWeek.Thursday: case DayOfWeek.Friday: renderer.DrawHourRange(e.Graphics, workingHoursRectangle, false, false); break; case DayOfWeek.Saturday: if (ActiveSaturday) { renderer.DrawHourRange(e.Graphics, workingHoursRectangle, false, false); } break; case DayOfWeek.Sunday: if (ActiveSunday) { renderer.DrawHourRange(e.Graphics, workingHoursRectangle, false, false); } break; } //if (!((time.DayOfWeek == DayOfWeek.Saturday) || (time.DayOfWeek == DayOfWeek.Sunday))) //weekends off -> no working hours // renderer.DrawHourRange(e.Graphics, workingHoursRectangle, false, false); if ((selection == SelectionType.DateRange) && (time.Day == selectionStart.Day)) { Rectangle selectionRectangle = GetHourRangeRectangle(selectionStart, selectionEnd, rect); if (selectionRectangle.Top + 1 > this.HeaderHeight) { renderer.DrawHourRange(e.Graphics, selectionRectangle, false, true); } } e.Graphics.SetClip(rect); for (int hour = 0; hour < 24 * slotsPerHour; hour++) { int y = rect.Top + (hour * halfHourHeight) - scrollbar.Value; Color color1 = renderer.HourSeperatorColor; Color color2 = renderer.HalfHourSeperatorColor; using (Pen pen = new Pen(((hour % slotsPerHour) == 0 ? color1 : color2))) e.Graphics.DrawLine(pen, rect.Left, y, rect.Right, y); if (y > rect.Bottom) { break; } } renderer.DrawDayGripper(e.Graphics, rect, appointmentGripWidth); e.Graphics.ResetClip(); AppointmentList appointments = (AppointmentList)cachedAppointments[time.Day]; if (appointments != null) { List <string> groups = new List <string>(); foreach (Appointment app in appointments) { if (!groups.Contains(app.Group)) { groups.Add(app.Group); } } Rectangle rect2 = rect; rect2.Width = rect2.Width / groups.Count; groups.Sort(); foreach (string group in groups) { DrawAppointments(e, rect2, time, group); rect2.X += rect2.Width; } } }
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); List <Appointment> drawnItems = new List <Appointment>(); 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.ContainsKey(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); } } } } } }