예제 #1
0
        private HalfHourLayout[] GetMaxParalelAppointments(List <Appointment> appointments)
        {
            HalfHourLayout[] appLayouts = new HalfHourLayout[24 * 4];

            foreach (Appointment appointment in appointments)
            {
                appointment.m_ConflictCount = 1;
            }

            foreach (Appointment appointment in appointments)
            {
                int firstHalfHour = appointment.StartDate.Hour * 4 + (appointment.StartDate.Minute / 15);
                int lastHalfHour  = appointment.EndDate.Hour * 4 + (appointment.EndDate.Minute / 15);

                for (int halfHour = firstHalfHour; halfHour < lastHalfHour; halfHour++)
                {
                    HalfHourLayout layout = appLayouts[halfHour];

                    if (layout == null)
                    {
                        layout = new HalfHourLayout();
                        layout.Appointments  = new Appointment[200];
                        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);
        }
예제 #2
0
        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 * 4; halfHour++)//2
                {
                    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;

                                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);
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        private static HalfHourLayout[] GetMaxParalelAppointments(List <Appointment> appointments, int slotsPerHour)
        {
            HalfHourLayout[] appLayouts = new HalfHourLayout[24 * 20];

            foreach (Appointment appointment in appointments)
            {
                appointment.conflictCount = 1;
            }

            foreach (Appointment appointment in appointments)
            {
                int firstHalfHour = appointment.StartDate.Hour * slotsPerHour + (appointment.StartDate.Minute / /*30*/ (60 / slotsPerHour));
                int lastHalfHour  = appointment.EndDate.Hour * slotsPerHour + (appointment.EndDate.Minute / /*30*/ (60 / slotsPerHour));

                // Added to allow small parts been displayed
                if (lastHalfHour == firstHalfHour)
                {
                    if (lastHalfHour < 24 * slotsPerHour)
                    {
                        lastHalfHour++;
                    }
                    else
                    {
                        firstHalfHour--;
                    }
                }

                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++;

                    List <string> groups = new List <string>();

                    foreach (Appointment app2 in layout.Appointments)
                    {
                        if ((app2 != null) && (!groups.Contains(app2.Group)))
                        {
                            groups.Add(app2.Group);
                        }
                    }

                    layout.Groups = groups;

                    // update conflicts
                    foreach (Appointment app2 in layout.Appointments)
                    {
                        if ((app2 != null) && (app2.Group == appointment.Group))
                        {
                            if (app2.conflictCount < layout.Count)
                            {
                                app2.conflictCount = layout.Count - (layout.Groups.Count - 1);
                            }
                        }
                    }
                }
            }

            return(appLayouts);
        }
예제 #4
0
        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);
                            }
                        }
                    }
                }
            }
        }