private void ResizeAppointment(TimeSlotItem item)
        {
            Debug.Assert(this.resizedAppointmentSlot != null, "Appointment to resize should not be null.");

            if (this.resizeMode == AppointmentResizeMode.Start)
            {
                if (item.TimeSlot.Start < this.resizedAppointmentSlot.Occurrence.Master.End)
                {
                    if (!this.resizeOffset.HasValue)
                    {
                        this.resizeOffset = this.resizedAppointmentSlot.Occurrence.Start - item.TimeSlot.Start;
                    }

                    this.resizedAppointmentSlot.Occurrence.Master.Start = item.TimeSlot.Start + this.resizeOffset.Value;
                }
            }
            else if (this.resizeMode == AppointmentResizeMode.End)
            {
                if (item.TimeSlot.End > this.resizedAppointmentSlot.Occurrence.Master.Start)
                {
                    if (!this.resizeOffset.HasValue)
                    {
                        this.resizeOffset = this.resizedAppointmentSlot.Occurrence.End - item.TimeSlot.Start;
                    }

                    this.resizedAppointmentSlot.Occurrence.Master.End = item.TimeSlot.Start + this.resizeOffset.Value;
                }
            }
        }
Exemplo n.º 2
0
        private Rect GetLayoutSlot(AppointmentSlot appSlot)
        {
            var timeSlotGroup = appSlot.TimeSlot as TimeSlotGroup;

            Debug.Assert(timeSlotGroup != null, "TimeSlot should be TimeSlotGroup");
            if (timeSlotGroup == null)
            {
                return(new Rect());
            }

            var firstTimeSlot = timeSlotGroup.TimeSlots.FirstOrDefault();

            Debug.Assert(firstTimeSlot != null, "TimeSlotGroup TimeSlots should not be empty");
            if (firstTimeSlot == null)
            {
                return(new Rect());
            }

            var lastTimeSlot = timeSlotGroup.TimeSlots.LastOrDefault();

            Debug.Assert(lastTimeSlot != null, "TimeSlotGroup TimeSlots should not be empty");
            if (lastTimeSlot == null)
            {
                return(new Rect());
            }

            var timeSlotItemsControl = this.TimeSlotItemsControl;

            Debug.Assert(timeSlotItemsControl != null, "TimeSlotItemsControl should not be null");
            if (timeSlotItemsControl == null)
            {
                return(new Rect());
            }

            TimeSlotItem firstTimeSlotItem = timeSlotItemsControl.ItemContainerGenerator.ContainerFromItem(firstTimeSlot) as TimeSlotItem;

            Debug.Assert(firstTimeSlotItem != null, "First TimeSlotItem should not be null");
            if (firstTimeSlotItem == null)
            {
                return(new Rect());
            }

            TimeSlotItem lastTimeSlotItem = timeSlotItemsControl.ItemContainerGenerator.ContainerFromItem(lastTimeSlot) as TimeSlotItem;

            Debug.Assert(lastTimeSlotItem != null, "Last TimeSlotItem should not be null");
            if (lastTimeSlotItem == null)
            {
                return(new Rect());
            }

            var firstContentHost = firstTimeSlotItem.ContentHost ?? firstTimeSlotItem;
            var lastContentHost  = lastTimeSlotItem.ContentHost ?? lastTimeSlotItem;

            Point topLeft     = firstContentHost.TransformToVisual(this).Transform(new Point());
            Point bottomRight = lastContentHost.TransformToVisual(this).Transform(new Point(lastContentHost.ActualWidth, lastContentHost.ActualHeight));

            return(new Rect(topLeft, bottomRight));
        }
        private void OnAppointmentItemsControlDragQuery(object sender, DragDropQueryEventArgs e)
        {
            ////TODO: change the following code for the SP.

            var button = e.GetElement <ButtonBase>(e.Options.CurrentDragPoint);

            if (button == null)
            {
                e.QueryResult = !this.Scheduler.IsReadOnly && !this.IsResizing;
            }
            else
            {
                e.QueryResult = false;
            }

            if (e.QueryResult == true && e.Options.u_IsStatus)
            {
                this.IsDragging = true;
                var item         = e.Options.Source as AppointmentItem;
                var editingEvent = this.RaiseAppointmentEditingEvent(item.AppointmentSlot.Occurrence.Appointment, AppointmentEditAction.Drag);
                if (!editingEvent.Cancel)
                {
                    e.Options.Payload = e.Options.Source;
                    ContentControl cue = new ContentControl();
                    cue.ContentTemplate            = item.Scheduler.DragVisualCueTemplate;
                    cue.Content                    = new DragVisualCue(item.AppointmentSlot.Occurrence.Appointment, true);
                    cue.Width                      = item.ActualWidth;
                    cue.MinHeight                  = item.ActualHeight;
                    cue.HorizontalContentAlignment = HorizontalAlignment.Stretch;
                    cue.VerticalContentAlignment   = VerticalAlignment.Stretch;
                    e.Options.DragCue              = cue;

                    TimeSlotItem timeslotItem = e.GetElement <TimeSlotItem>(e.Options.MouseClickPoint);
                    if (timeslotItem == null)
                    {
                        e.QueryResult   = false;
                        this.IsDragging = false;
                        return;
                    }
                    TimeSlot sl   = timeslotItem.TimeSlot;
                    TimeSlot apps = (item.Content as AppointmentSlot).TimeSlot;
                    if (this.Scheduler != null)
                    {
                        this.Scheduler.DroppedAppointmentDuration = (sl.Start - apps.Start).Duration();
                    }
                }
                else
                {
                    this.IsDragging = true;
                    e.QueryResult   = false;
                }
            }
        }
Exemplo n.º 4
0
        private void OnTimeSlotItemsControlDropInfo(object sender, DragDropEventArgs e)
        {
            if (this.Scheduler != null)
            {
                this.Scheduler.CurrentTimeSlotItemsControl = this;
            }
            var          item         = e.Options.Source as AppointmentItem;
            TimeSlotItem timeslotItem = e.Options.Destination as TimeSlotItem;
            var          slot         = timeslotItem.TimeSlot;
            IAppointment app          = null;

            if (item != null)
            {
                app = item.AppointmentSlot.Occurrence.Appointment;
            }
            if (e.Options.Status == DragStatus.DropComplete && item != null)
            {
                ChangeAllDraggedItemsOpacity(item);

                if (Keyboard.Modifiers == ModifierKeys.Control)
                {
                    app = app.Copy();
                    this.Scheduler.Appointments.Add(app);
                }
                this.ChangeAppointmentTime(app, slot);
                this.ChangeResourceGroup(app);
                this.CompleteDrop(app);
            }

            if (e.Options.Status == DragStatus.DropPossible && item != null)
            {
                this.HighlightDropArea(app, slot);
            }

            ContentControl control = e.Options.DragCue as ContentControl;

            if (control != null)
            {
                var tooltip = control.Content as DragVisualCue;
                if (tooltip != null)
                {
                    tooltip.IsDraggingPossible = e.Options.Status != DragStatus.DropImpossible;
                }
            }
        }
Exemplo n.º 5
0
        private void HideShowMoreButtons()
        {
            bool isHorizontal         = this.Orientation == Orientation.Horizontal;
            var  timeSlotItemsControl = this.TimeSlotItemsControl;

            if (!isHorizontal && timeSlotItemsControl != null)
            {
                for (int i = 0; i < timeSlotItemsControl.Items.Count; i++)
                {
                    TimeSlotItem item = timeSlotItemsControl.ItemContainerGenerator.ContainerFromIndex(i) as TimeSlotItem;
                    if (item != null && item.ShowMoreButton != null)
                    {
                        item.ShowMoreButton.Opacity   = 0;
                        item.ShowMoreButton.IsEnabled = false;
                    }
                }
            }
        }
Exemplo n.º 6
0
        private Size GetTimeSlotItemContentHostRenderSize(out int timeSlotsCount)
        {
            timeSlotsCount = 0;
            Size timeSlotSize = Size.Empty;
            TimeSlotItemsControl timeSlotItemsControl = this.TimeSlotItemsControl;

            if (timeSlotItemsControl != null)
            {
                timeSlotsCount = timeSlotItemsControl.Items.Count;
                for (int i = 0; i < timeSlotsCount; i++)
                {
                    TimeSlotItem item = timeSlotItemsControl.ItemContainerGenerator.ContainerFromIndex(i) as TimeSlotItem;
                    if (item != null)
                    {
                        var contentHost = item.ContentHost ?? item;
                        timeSlotSize = contentHost.RenderSize;
                        break;
                    }
                }
            }

            return(timeSlotSize);
        }
Exemplo n.º 7
0
 public TimeSlotItemAppointments(TimeSlotItem timeSlotItem)
 {
     this.TimeSlotItem = timeSlotItem;
     this.Appointments = new Dictionary <int, AppointmentSlot>();
 }
Exemplo n.º 8
0
        private void GenerateSlots(int timeSlotsCount)
        {
            var source = this.AppointmentItemsControl.ItemsSource as AppointmentSlotCollection;

            for (int i = 0; i < timeSlotsCount; i++)
            {
                TimeSlotItem item = this.TimeSlotItemsControl.ItemContainerGenerator.ContainerFromIndex(i) as TimeSlotItem;
                if (item != null)
                {
                    this.slots.Add(new TimeSlotItemAppointments(item));
                }
            }

            foreach (var item in this.slots)
            {
                TimeSlotItem timeSlotItem = item.TimeSlotItem;
                TimeSlot     timeSlot     = item.TimeSlot;

                var appointmentSlots = (from appointmentSlot in source
                                        where appointmentSlot.TimeSlot.Start == timeSlot.Start
                                        orderby appointmentSlot.Occurrence.Duration() descending
                                        select appointmentSlot).ToList();

                int index = 0;

                bool indexInUse = item.Appointments.ContainsKey(index);

                while (indexInUse)
                {
                    index++;
                    indexInUse = item.Appointments.ContainsKey(index);
                }

                foreach (var appSlot in appointmentSlots)
                {
                    int durationInDays = this.GetAppointmentSlotDuration(appSlot);

                    item.Appointments[index] = appSlot;

                    if (durationInDays > 1)
                    {
                        int timeSlotIndex = this.slots.IndexOf(item) + 1;
                        int count         = Math.Min(durationInDays + timeSlotIndex - 1, this.slots.Count);

                        for (int i = timeSlotIndex; i < count; i++)
                        {
                            TimeSlotItemAppointments nextTimeSlotAppointment = this.slots[i];
                            nextTimeSlotAppointment.Appointments[index] = appSlot;
                        }
                    }

                    index++;
                    indexInUse = item.Appointments.ContainsKey(index);

                    while (indexInUse)
                    {
                        index++;
                        indexInUse = item.Appointments.ContainsKey(index);
                    }
                }
            }
        }
Exemplo n.º 9
0
        private static void IsDropPossibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TimeSlotItem item = d as TimeSlotItem;

            item.ChangeVisualState(true);
        }