/// <summary> /// Find an unavailable slot at a given time. /// </summary> /// <returns>The first unavailable slot found, or null if none were found.</returns> public Unavailability FindUnavailableAt(TimeOfWeek time) { foreach (Unavailability u in UnavailableList) { if (time >= u.Start && time <= u.End) { return(u); } } return(null); }
/// <summary> /// Find all unavailable slots at a given time. /// </summary> /// <returns>The list of unavailable slots found.</returns> public List <Unavailability> FindAllUnavailableAt(TimeOfWeek time) { List <Unavailability> us = new List <Unavailability>(); foreach (Unavailability u in UnavailableList) { if (time >= u.Start && time <= u.End) { us.Add(u); } } return(us); }
/// <summary> /// Find a class at a given time. /// </summary> /// <returns>The first class found, or null if none were found.</returns> public Session FindClassAt(TimeOfWeek time, bool selected) { foreach (Session session in ClassList) { if (selected && !session.Stream.Selected) { continue; } if (time >= session.Start && time <= session.End) { return(session); } } return(null); }
protected override void OnDragDrop(DragEventArgs drgevent) { TimeOfWeek time = FindClickTime(PointToClient(new Point(drgevent.X, drgevent.Y))); if (drgevent.Data.GetDataPresent(typeof(Stream))) { Session dragSession = (Session)drgevent.Data.GetData(typeof(Session)); Session dropSession = Timetable.From(dragSession.Stream.Type).FindClassAt(time, false); if (dropSession != null && dropSession.Stream != dragSession.Stream) { if (Timetable_.SelectStream(dropSession.Stream)) { TimetableChanged(this); } } } if (drgevent.Data.GetDataPresent(typeof(Type))) { Type dragType = (Type)drgevent.Data.GetData(typeof(Type)); Session dropSession = Timetable.From(dragType).FindClassAt(time, false); if (dropSession != null) { if (Timetable_.SelectStream(dropSession.Stream)) { TimetableChanged(this); } } } else if (drgevent.Data.GetDataPresent(typeof(Unavailability))) { Unavailability dragUnavail = (Unavailability)drgevent.Data.GetData(typeof(Unavailability)); Timetable_.UnavailableList.Remove(dragUnavail); if (HoverUnavail_ != null && Timetable_.FreeDuring(HoverUnavail_, true)) { Timetable_.UnavailableList.Add(new Unavailability(dragUnavail.Name, HoverUnavail_)); TimetableChanged(this); } else { Timetable_.UnavailableList.Add(dragUnavail); } dragUnavail = null; } else { base.OnDragDrop(drgevent); } }
protected override void OnMouseDoubleClick(MouseEventArgs e) { base.OnMouseDoubleClick(e); TimeOfWeek time = FindClickTime(e); if (TimeOfWeek.ReferenceEquals(time, null)) { return; } if (TimetableMouseDoubleClick != null) { TimetableMouseDoubleClick(this, new TimetableEventArgs(e, time)); } }
/// <summary> /// Find all classes at a given time. /// </summary> public List <Session> FindAllClassesAt(TimeOfWeek time, bool selected) { List <Session> sessions = new List <Session>(); // examine every class foreach (Session session in ClassList) { if (selected && !session.Stream.Selected) { continue; } if (time >= session.Start && time <= session.End) { sessions.Add(session); } } return(sessions); }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); TimeOfWeek time = FindClickTime(e); if (TimeOfWeek.ReferenceEquals(time, null)) { return; } if (EnableDrag_ && e.Button == MouseButtons.Left && Timetable_ != null) { DragSession_ = Timetable_.FindClassAt(time, !ShowAll_); Unavailability dragUnavail = Timetable_.FindUnavailableAt(time); if (DragSession_ != null) { BeginDrag(DragSession_.Stream.Type); DragCursor_ = DragCursor(DragSession_); DoDragDrop(DragSession_.Stream.Type, DragDropEffects.Move); EndDrag(); DragCursor_ = null; } else if (dragUnavail != null) { HoverUnavail_ = null; Invalidate(); DragCursor_ = DragCursor(dragUnavail); DoDragDrop(dragUnavail, DragDropEffects.Move); HoverUnavail_ = null; Invalidate(); DragCursor_ = null; } } if (TimetableMouseDown != null) { TimetableMouseDown(this, new TimetableEventArgs(e, time)); } }
/// <summary> /// Check if there's a class on at a given time. /// </summary> public bool ClassAt(TimeOfWeek time, bool selected) { return(FindClassAt(time, selected) != null); }
/// <summary> /// Check if a time is within an unavailable slot. /// </summary> public bool UnavailableAt(TimeOfWeek time) { return(FindUnavailableAt(time) != null); }
/// <summary> /// Check if the timetable is free at a given time. /// </summary> /// <returns>True if it's free.</returns> public bool FreeAt(TimeOfWeek time, bool selected) { return(!ClassAt(time, selected) && !UnavailableAt(time)); }
protected override void OnDragOver(DragEventArgs drgevent) { TimeOfWeek time = FindClickTime(PointToClient(new Point(drgevent.X, drgevent.Y))); // outside of table bounds? if (TimeOfWeek.ReferenceEquals(time, null)) { // clear current preview (at edge of timetable) EndPreviewStream(); // cannot drag outside of the actual table drgevent.Effect = DragDropEffects.None; return; } // dragging a class if (drgevent.Data.GetDataPresent(typeof(Session)) || drgevent.Data.GetDataPresent(typeof(Type))) { drgevent.Effect = DragDropEffects.Move; Type dragType; if (drgevent.Data.GetDataPresent(typeof(Session))) { dragType = ((Session)drgevent.Data.GetData(typeof(Session))).Stream.Type; } else { dragType = (Type)drgevent.Data.GetData(typeof(Type)); } Session session = Timetable.From(dragType).FindClassAt(time, false); if (session == null) { EndPreviewStream(); } else { PreviewEquiv(session.Stream); } } // dragging an unavailability else if (drgevent.Data.GetDataPresent(typeof(Unavailability))) { Unavailability dragUnavail = (Unavailability)drgevent.Data.GetData(typeof(Unavailability)); TimeLength offset = new TimeLength(dragUnavail.StartMinute); TimeOfWeek start = time - dragUnavail.Length / 2; start -= offset; start.RoundToNearestHour(); start += offset; HoverUnavail_ = new Timeslot(start.Day, (TimeOfDay)start, (TimeOfDay)start + dragUnavail.Length); if (HoverUnavail_.StartTime < new TimeOfDay(HourStart_, 0) || HoverUnavail_.EndTime > new TimeOfDay(HourEnd_, 0)) { drgevent.Effect = DragDropEffects.None; HoverUnavail_ = null; } else { drgevent.Effect = DragDropEffects.Move; } Invalidate(); } else { base.OnDragOver(drgevent); } }
public TimetableEventArgs(MouseEventArgs e, TimeOfWeek time) : base(e.Button, e.Clicks, e.X, e.Y, e.Delta) { Time_ = time; }
public TimetableEventArgs(MouseButtons button, int clicks, int x, int y, int delta, TimeOfWeek time) : base(button, clicks, x, y, delta) { Time_ = time; }