private void UserControl_Loaded(object sender, RoutedEventArgs ea)
        {
            DependencyObject ucParent = (sender as DayScheduler).Parent;

            while (!(ucParent is Scheduler))
            {
                ucParent = LogicalTreeHelper.GetParent(ucParent);
            }

            _scheduler = ucParent as Scheduler;

            _scheduler.OnEventAdded += ((object s, Event e) =>
            {
                if (e.Start.Date == e.End.Date)
                {
                    PaintAllEvents();
                }
                else
                {
                    PaintAllDayEvents();
                }
            });

            _scheduler.OnEventDeleted += ((object s, Event e) =>
            {
                if (e.Start.Date == e.End.Date)
                {
                    PaintAllEvents();
                }
                else
                {
                    PaintAllDayEvents();
                }
            });

            _scheduler.OnEventsModified += ((object s, EventArgs e) =>
            {
                PaintAllEvents();
                PaintAllDayEvents();
            });

            _scheduler.OnStartJourneyChanged += ((object s, TimeSpan t) =>
            {
                if (_scheduler.StartJourney.Hours == 0)
                {
                    startJourney.Visibility = System.Windows.Visibility.Hidden;
                }
                else
                {
                    Grid.SetRowSpan(startJourney, (int)t.TotalHours * 2);
                }
            });

            _scheduler.OnEndJourneyChanged += ((object s, TimeSpan t) =>
            {
                if (_scheduler.EndJourney.Hours == 0)
                {
                    endJourney.Visibility = System.Windows.Visibility.Hidden;
                }
                else
                {
                    Grid.SetRow(endJourney, (int)t.Hours);
                    Grid.SetRowSpan(endJourney, 48 - (int)t.Hours * 2);
                }
            });

            (sender as DayScheduler).SizeChanged += DayScheduler_SizeChanged;

            ResizeGrids(new Size(this.ActualWidth, this.ActualHeight));
            PaintAllEvents();
            PaintAllDayEvents();
            if (_scheduler.StartJourney.Hours != 0)
            {
                double hourHeight = EventsGrid.ActualHeight / 22;
                ScrollEventsViewer.ScrollToVerticalOffset(hourHeight * (_scheduler.StartJourney.Hours - 1));
            }

            if (_scheduler.StartJourney.Hours == 0)
            {
                startJourney.Visibility = System.Windows.Visibility.Hidden;
            }
            else
            {
                Grid.SetRowSpan(startJourney, _scheduler.StartJourney.Hours * 2);
            }

            if (_scheduler.EndJourney.Hours == 0)
            {
                endJourney.Visibility = System.Windows.Visibility.Hidden;
            }
            else
            {
                Grid.SetRow(endJourney, _scheduler.EndJourney.Hours * 2);
                Grid.SetRowSpan(endJourney, 48 - _scheduler.EndJourney.Hours * 2);
            }
        }
Beispiel #2
0
        private void PaintAllEvents()
        {
            if (_scheduler == null || _scheduler.Events == null)
            {
                return;
            }

            IEnumerable <Event> eventList = TodayEvents.Where(ev => ev.Start.Date == ev.End.Date && !ev.AllDay).OrderBy(ev => ev.Start);

            column.Children.Clear();
            //ADD CURRENT HOUR MARKER AND SCROLL TO IT
            double bdcolumnWidth = EventsGrid.ColumnDefinitions[1].Width.Value;

            column2.Children.Clear();
            Border bd = new Border();

            bd.BorderThickness = new Thickness(2, 2, 2, 2);
            bd.BorderBrush     = new SolidColorBrush(Colors.Red);
            double bdmargintop = 100 * DateTime.Now.Hour;

            bd.Margin = new Thickness(0, bdmargintop, 0, 0);
            bd.Height = 100;
            bd.Width  = bdcolumnWidth;
            bd.HorizontalAlignment = HorizontalAlignment.Stretch;
            column2.Children.Add(bd);
            ScrollEventsViewer.ScrollToVerticalOffset(bdmargintop - 100);

            double columnWidth = EventsGrid.ColumnDefinitions[1].Width.Value;


            foreach (Event e in eventList)
            {
                //column.Width = columnWidth;

                double oneHourHeight = 100;// column.ActualHeight / 46;

                var concurrentEvents = TodayEvents.Where(e1 => ((e1.Start <= e.Start && e1.End > e.Start) ||
                                                                (e1.Start > e.Start && e1.Start < e.End)) &&
                                                         e1.End.Date == e1.Start.Date).OrderBy(ev => ev.Start);

                double marginTop = oneHourHeight * (e.Start.Hour + (e.Start.Minute / 60.0));
                double width     = (columnWidth) / (concurrentEvents.Count()) * 0.82;
                //double marginLeft = width * getIndex(e, concurrentEvents.ToList());

                double marginLeft = width * getIndex(e, concurrentEvents.ToList());


                EventUserControl wEvent = new EventUserControl(e, true);
                //if (width != 0)
                //{
                //    wEvent.Width = width ;
                //    double marginLeft = width * getIndex(e, concurrentEvents.ToList());
                //    wEvent.Margin = new Thickness(marginLeft, marginTop, 0, 0);

                //}
                //else
                //{
                //    wEvent.Width = width;
                //    double marginLeft = width * getIndex(e, concurrentEvents.ToList());
                //    wEvent.Margin = new Thickness(marginLeft, marginTop, 0, 0);

                //}
                wEvent.Width = width;

                wEvent.Margin = new Thickness(marginLeft, marginTop, 0, 0);

                wEvent.Height            = e.End.Subtract(e.Start).TotalHours *oneHourHeight;
                wEvent.MouseDoubleClick += ((object sender, MouseButtonEventArgs ea) =>
                {
                    ea.Handled = true;
                    OnEventDoubleClick(sender, wEvent.Event);
                });

                column.Children.Add(wEvent);
            }
        }
        //private void PaintRowsHour(TimeSpan di, TimeSpan de)
        private void PaintRowsHour(int IdB)
        {
            TimeSpan di, de;

            var result = branchOffice.GetByID(IdB);

            di = (TimeSpan)result.StarHour;
            de = (TimeSpan)result.EndHour;

            _scheduler.OnStartJourneyChanged += ((object s, CustomEventArgsTimeSpan t) =>
            {
                if (di.Hours == 0)
                {
                    startJourney.Visibility = System.Windows.Visibility.Hidden;
                }
                else
                {
                    Grid.SetRowSpan(startJourney, di.Hours);
                }
            });

            _scheduler.OnEndJourneyChanged += ((object s, CustomEventArgsTimeSpan t) =>
            {
                if (de.Hours == 0)
                {
                    endJourney.Visibility = System.Windows.Visibility.Hidden;
                }
                else
                {
                    Grid.SetRow(endJourney, de.Hours);
                    Grid.SetRowSpan(endJourney, 24 - de.Hours);
                }
            });

            // this.SizeChanged += WeekScheduler_SizeChanged;


            if (di.Hours != 0)
            {
                double hourHeight = EventsGrid.ActualHeight / 22;
                ScrollEventsViewer.ScrollToVerticalOffset(hourHeight * (di.Hours - 1));
            }

            if (di.Hours == 0)
            {
                startJourney.Visibility = System.Windows.Visibility.Hidden;
            }
            else
            {
                Grid.SetRowSpan(startJourney, di.Hours);
            }

            if (de.Hours == 0)
            {
                endJourney.Visibility = System.Windows.Visibility.Hidden;
            }
            else
            {
                Grid.SetRow(endJourney, de.Hours);
                Grid.SetRowSpan(endJourney, 24 - de.Hours);
            }
        }
Beispiel #4
0
        private void PaintAllEvents(DateTime?date)

        {
            try
            {
                if (_scheduler == null || _scheduler.Events == null)
                {
                    return;
                }

                IEnumerable <Event> eventList = _scheduler.Events.Where(ev => ev.Start.Date == ev.End.Date && !ev.AllDay).OrderBy(ev => ev.Start);

                if (date == null)
                {
                    column1.Children.Clear();
                    column2.Children.Clear();
                    column3.Children.Clear();
                    column4.Children.Clear();
                    column5.Children.Clear();
                    column6.Children.Clear();
                    column7.Children.Clear();
                }
                else
                {
                    int numColumn = (int)date.Value.Date.Subtract(FirstDay.Date).TotalDays + 1;
                    if (numColumn >= 0 && numColumn <= 7)
                    {
                        ((Canvas)this.FindName("column" + numColumn)).Children.Clear();
                    }

                    eventList = eventList.Where(ev => ev.Start.Date == date.Value.Date).OrderBy(ev => ev.Start);
                }

                double columnWidth = EventsGrid.ColumnDefinitions[1].Width.Value;

                foreach (Event e in eventList)
                {
                    int numColumn = (int)e.Start.Date.Subtract(FirstDay.Date).TotalDays + 1;
                    if (numColumn >= 1 && numColumn <= 7)
                    {
                        Canvas sp = (Canvas)this.FindName("column" + numColumn);
                        sp.Width = columnWidth;

                        double oneHourHeight = sp.ActualHeight / 22;

                        var concurrentEvents = _scheduler.Events.Where(e1 => ((e1.Start <= e.Start && e1.End > e.Start) ||
                                                                              (e1.Start > e.Start && e1.Start < e.End)) &&
                                                                       e1.End.Date == e1.Start.Date).OrderBy(ev => ev.Start);

                        double marginTop  = oneHourHeight * (e.Start.Hour + (e.Start.Minute / 60.0));
                        double width      = columnWidth / (concurrentEvents.Count());
                        double marginLeft = width * getIndex(e, concurrentEvents.ToList());

                        EventUserControl wEvent = new EventUserControl(e, true);
                        wEvent.Width             = width;
                        wEvent.Height            = e.End.Subtract(e.Start).TotalHours *oneHourHeight;
                        wEvent.Margin            = new Thickness(marginLeft, marginTop, 0, 0);
                        wEvent.MouseDoubleClick += ((object sender, MouseButtonEventArgs ea) =>
                        {
                            ea.Handled = true;
                            OnEventDoubleClick(sender, wEvent.Event);
                        });

                        sp.Children.Add(wEvent);
                    }
                }
                ScrollEventsViewer.ScrollToVerticalOffset(700);
            }
            catch (Exception ex)
            {
                var exception = ex;
                throw;
            }
        }