Esempio n. 1
0
        public void MouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            Appointment selection = dayView.SelectedAppointment;
            Rectangle   viewrect  = dayView.GetTrueRectangle();
            Rectangle   fdrect    = dayView.GetFullDayApptsRectangle();

            if (viewrect.Contains(e.Location) || fdrect.Contains(e.Location))
            {
                if ((selection != null) && (!selection.Locked))
                {
                    switch (e.Button)
                    {
                    case System.Windows.Forms.MouseButtons.Left:

                        // Get time at mouse position
                        DateTime m_Date = dayView.GetTimeAt(e.X, e.Y, ref _column);

                        switch (mode)
                        {
                        case SelectionMode.Move:
                            //can the appointment be moved?
                            AppointmentMoveEventArgs args = new AppointmentMoveEventArgs(selection);
                            dayView.RaiseBeforeAppointmentMoved(args);

                            if (!args.AllowMove)
                            {
                                mode = SelectionMode.None;
                            }

                            // This works for regular (i.e. non full-day or multi-day appointments)

                            if (!selection.AllDayEvent && viewrect.Contains(e.Location))
                            {
                                // add delta value
                                m_Date = m_Date.Add(delta);

                                if (length == TimeSpan.Zero)
                                {
                                    startDate = selection.StartDate;
                                    length    = selection.EndDate - startDate;
                                }
                                else
                                {
                                    DateTime m_EndDate = m_Date.Add(length);

                                    if (m_EndDate.Day == m_Date.Day)
                                    {
                                        if (selection.StartDate != m_Date || selection.Column != Column)
                                        {
                                            selection.AppointmentMoved = true;
                                        }

                                        selection.StartDate = m_Date;
                                        selection.EndDate   = m_EndDate;
                                        selection.Column    = _column;
                                        dayView.RaiseAppointmentMove(new AppointmentEventArgs(selection));
                                        dayView.Invalidate();
                                    }
                                    else
                                    {
                                        if (selection.StartDate != m_Date || selection.Column != _column)
                                        {
                                            selection.AppointmentMoved = true;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (fdrect.Contains(e.Location))
                                {
                                    m_Date = m_Date.Add(delta);

                                    int m_DateDiff = m_Date.Subtract(selection.StartDate).Days;

                                    if (m_DateDiff != 0)
                                    {
                                        if (selection.StartDate.AddDays(m_DateDiff) > dayView.StartDate)
                                        {
                                            selection.StartDate = selection.StartDate.AddDays(m_DateDiff);
                                            selection.EndDate   = selection.EndDate.AddDays(m_DateDiff);
                                            dayView.Invalidate();
                                            dayView.RaiseAppointmentMove(new AppointmentEventArgs(selection));
                                        }
                                    }
                                }
                            }

                            break;

                        case SelectionMode.ResizeBottom:
                            if (!dayView.AllowAppointmentResize)
                            {
                                break;
                            }

                            if (m_Date > selection.StartDate)
                            {
                                if (selection.EndDate.Day == m_Date.Day)
                                {
                                    dayView.SelectedAppointment.AppointmentMoved = true;
                                    selection.EndDate = m_Date;
                                    dayView.Invalidate();
                                    dayView.RaiseAppointmentMove(new AppointmentEventArgs(selection));
                                }
                            }

                            break;

                        case SelectionMode.ResizeTop:
                            if (!dayView.AllowAppointmentResize)
                            {
                                break;
                            }

                            if (m_Date < selection.EndDate)
                            {
                                if (selection.StartDate.Day == m_Date.Day)
                                {
                                    dayView.SelectedAppointment.AppointmentMoved = true;
                                    selection.StartDate = m_Date;
                                    dayView.Invalidate();
                                    dayView.RaiseAppointmentMove(new AppointmentEventArgs(selection));
                                }
                            }
                            break;

                        case SelectionMode.ResizeLeft:
                            if (!selection.AllDayEvent || !dayView.AllowAppointmentResize)
                            {
                                break;
                            }

                            if (m_Date.Date < selection.EndDate.Date)
                            {
                                dayView.SelectedAppointment.AppointmentMoved = true;
                                selection.StartDate = m_Date.Date;
                                dayView.Invalidate();
                                dayView.RaiseAppointmentMove(new AppointmentEventArgs(selection));
                            }

                            break;

                        case SelectionMode.ResizeRight:
                            if (!selection.AllDayEvent || !dayView.AllowAppointmentResize)
                            {
                                break;
                            }

                            if (m_Date.Date >= selection.StartDate.Date)
                            {
                                dayView.SelectedAppointment.AppointmentMoved = true;
                                selection.EndDate = m_Date.Date.AddDays(1);
                                dayView.Invalidate();
                                dayView.RaiseAppointmentMove(new AppointmentEventArgs(selection));
                            }

                            break;
                        }

                        break;

                    default:

                        SelectionMode tmpNode = GetMode(e);

                        switch (tmpNode)
                        {
                        case SelectionMode.Move:
                            dayView.Cursor = System.Windows.Forms.Cursors.Default;
                            break;

                        case SelectionMode.ResizeBottom:
                        case SelectionMode.ResizeTop:
                            if (!selection.AllDayEvent & dayView.AllowAppointmentResize)
                            {
                                dayView.Cursor = System.Windows.Forms.Cursors.SizeNS;
                            }
                            break;

                        case SelectionMode.ResizeLeft:         // changed by Gimlei
                        case SelectionMode.ResizeRight:
                            if (selection.AllDayEvent & dayView.AllowAppointmentResize)
                            {
                                DayView.Cursor = System.Windows.Forms.Cursors.SizeWE;
                            }
                            break;
                        }

                        break;
                    }
                }
            }
        }