Exemplo n.º 1
0
        /// <summary>
        /// Creates a new <see cref="Calendar"/> control
        /// </summary>
        public Calendar()
        {
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.Selectable, true);

            DoubleBuffered = true;

            _selectedElements = new List<CalendarSelectableElement>();
            _items = new CalendarItemCollection(this);
            _renderer = new CalendarProfessionalRenderer(this);
            _maximumFullDays = 8;
            _maximumViewDays = 35;

            HighlightRanges = new CalendarHighlightRange[] {
                new CalendarHighlightRange( DayOfWeek.Monday, new TimeSpan(8,0,0), new TimeSpan(17,0,0)),
                new CalendarHighlightRange( DayOfWeek.Tuesday, new TimeSpan(8,0,0), new TimeSpan(17,0,0)),
                new CalendarHighlightRange( DayOfWeek.Wednesday, new TimeSpan(8,0,0), new TimeSpan(17,0,0)),
                new CalendarHighlightRange( DayOfWeek.Thursday, new TimeSpan(8,0,0), new TimeSpan(17,0,0)),
                new CalendarHighlightRange( DayOfWeek.Friday, new TimeSpan(8,0,0), new TimeSpan(17,0,0)),
            };

            _timeScale = CalendarTimeScale.ThirtyMinutes;
            SetViewRange(DateTime.Now, DateTime.Now.AddDays(2));

            _itemsDateFormat = "dd/MMM";
            _itemsTimeFormat = "hh:mm tt";
            _allowItemEdit = true;
            _allowNew = true;
            _allowItemResize = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Indicates if the time of the item intersects with the provided time
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public bool IntersectsWith(TimeSpan timeStart, TimeSpan timeEnd, CalendarTimeScale scale)
        {
            int startMin  = Convert.ToInt32(StartDate.TimeOfDay.TotalMinutes);
            int endMin    = Convert.ToInt32(EndDate.TimeOfDay.TotalMinutes);
            int startMin2 = Convert.ToInt32(timeStart.TotalMinutes);
            int endMin2   = Convert.ToInt32(timeEnd.TotalMinutes);

            int scaleInt = Convert.ToInt32(scale);

            while (startMin % scaleInt != 0)
            {
                startMin--;
            }
            while (endMin % scaleInt != 0)
            {
                endMin++;
            }
            while (startMin2 % scaleInt != 0)
            {
                startMin2--;
            }
            while (endMin2 % scaleInt != 0)
            {
                endMin2++;
            }

            Rectangle r1 = Rectangle.FromLTRB(0, Convert.ToInt32(startMin), 5, Convert.ToInt32(endMin));
            Rectangle r2 = Rectangle.FromLTRB(0, Convert.ToInt32(startMin2), 5, Convert.ToInt32(endMin2 - 1));

            //Rectangle r1 = Rectangle.FromLTRB(0, Convert.ToInt32(StartDate.TimeOfDay.TotalMinutes), 5, Convert.ToInt32(EndDate.TimeOfDay.TotalMinutes));
            //Rectangle r2 = Rectangle.FromLTRB(0, Convert.ToInt32(timeStart.TotalMinutes), 5, Convert.ToInt32(timeEnd.TotalMinutes - 1));
            return(r1.IntersectsWith(r2));
        }