コード例 #1
0
        private Mode GetMode(System.Windows.Forms.MouseEventArgs e)
        {
            if (dayView.SelectedAppointment == null)
            {
                return(Mode.None);
            }

            if (dayView.appointmentViews.Contains(dayView.SelectedAppointment))
            {
                AppointmentView view = dayView.appointmentViews[dayView.SelectedAppointment];

                Rectangle topRect    = view.Rectangle;
                Rectangle bottomRect = view.Rectangle;

                bottomRect.Y      = bottomRect.Bottom - 5;
                bottomRect.Height = 5;
                topRect.Height    = 5;

                if (topRect.Contains(new Point(e.X, e.Y)))
                {
                    return(Mode.ResizeTop);
                }
                else if (bottomRect.Contains(new Point(e.X, e.Y)))
                {
                    return(Mode.ResizeBottom);
                }
                else
                {
                    return(Mode.Move);
                }
            }

            return(Mode.None);
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
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);
                            }
                        }
                    }
                }
            }
        }
コード例 #4
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 * 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);
                            }
                        }
                    }
                }
            }
        }
 public void Add(Appointment key, AppointmentView value)
 {
     Dictionary.Add(key, value);
 }