public DialogResult ShowDialog(Timetable timetable, Unavailability unavail, int earliest, int latest) { Timetable_ = timetable; Unavail_ = unavail; Earliest_ = earliest; Latest_ = latest; return(base.ShowDialog()); }
public DialogResult ShowDialog(Timetable timetable, Unavailability unavail, int earliest, int latest) { Timetable_ = timetable; Unavail_ = unavail; Earliest_ = earliest; Latest_ = latest; return base.ShowDialog(); }
public void SetActive(Unavailability unavail) { if (unavail == null || ActiveUnavail_ == unavail) { return; } ActiveUnavail_ = unavail; ActiveStream_ = null; Invalidate(); }
public void SetActive(Stream stream) { if (stream == null || ActiveStream_ == stream) { return; } ActiveStream_ = stream; ActiveUnavail_ = null; Invalidate(); }
/// <summary> /// Finds an unavailable timeslot that clashes with a given stream. /// </summary> /// <returns>The first unavailable timeslot within the stream, or null if none were found.</returns> public Unavailability FindUnavailableDuringStream(Stream stream) { foreach (Session session in stream.Classes) { Unavailability u = FindUnavailableDuring(session); if (u != null) { return(u); } } 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 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)); } }
public Cursor DragCursor(Unavailability u) { return(DragCursor(u.Length, Color.DarkGray)); }
public Cursor DragCursor(Unavailability u) { return DragCursor(u.Length, Color.DarkGray); }
public void ClearActive() { ActiveStream_ = null; ActiveUnavail_ = null; Invalidate(); }
public void SetActive(Unavailability unavail) { if (unavail == null || ActiveUnavail_ == unavail) return; ActiveUnavail_ = unavail; ActiveStream_ = null; Invalidate(); }
public void SetActive(Stream stream) { if (stream == null || ActiveStream_ == stream) return; ActiveStream_ = stream; ActiveUnavail_ = null; Invalidate(); }
private void DrawTimeslotText(Graphics g, Unavailability u) { DrawTimeslotText(g, u, u.Name); }
private void btnOK_Click(object sender, EventArgs e) { // take focus away from time pickers btnOK.Focus(); // if no day is selected if (ddDay.SelectedIndex == -1) { MessageBox.Show("Please select a day.", "Unavailable Timeslot", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ddDay.Focus(); return; } // get start and end times from input TimeOfDay start = TimeOfDay.FromDateTime(timeStart.Value); TimeOfDay end = TimeOfDay.FromDateTime(timeEnd.Value); // if it starts before it ends if (start >= end) { MessageBox.Show("Start time must be before end time.", "Unavailable Timeslot", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // if it's not within the scope of the timetable if (end <= new TimeOfDay(Earliest_, 0)) { MessageBox.Show("End time must be after 8am.", "Unavailable Timeslot", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); timeEnd.Focus(); return; } if (start >= new TimeOfDay(Latest_, 0)) { MessageBox.Show("Start time must be before 9pm.", "Unavailable Timeslot", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); timeStart.Focus(); return; } // clip the timeslot to be within the bounds of the timetable if (start < new TimeOfDay(Earliest_, 0)) start = new TimeOfDay(Earliest_, 0); if (end > new TimeOfDay(Latest_, 0)) end = new TimeOfDay(Latest_, 0); // build new unavailability from input Unavailability unavail = new Unavailability(txtName.Text, ddDay.SelectedIndex, start.Hour, start.Minute, end.Hour, end.Minute); if (Unavail_ != null && Unavail_.EquivalentTo(unavail) && Unavail_.Name == unavail.Name) { DialogResult = DialogResult.Cancel; Close(); return; } // if editing, remove the old timeslot if (Unavail_ != null) Timetable_.UnavailableList.Remove(Unavail_); // if it doesn't fit in the current timetable if (!Timetable_.FreeDuring(unavail, true)) { MessageBox.Show("Selected time slot is currently occupied.", "Unavailable Timeslot", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); // if editing, add the old timeslot back in if (Unavail_ != null) Timetable_.UnavailableList.Add(Unavail_); return; } // insert the edited timeslot Timetable_.UnavailableList.Add(unavail); // recompute solutions Timetable_.RecomputeSolutions = true; // return DialogResult = DialogResult.OK; Close(); }
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); } }
private void FindClickDetails(TimetableEventArgs e) { ClickTime_ = e.Time; if (Timetable_ == null) { ClickSession_ = null; ClickUnavail_ = null; } else { ClickSession_ = Timetable_.FindClassAt(ClickTime_, true); ClickUnavail_ = Timetable_.FindUnavailableAt(ClickTime_); } }
public Unavailability(Unavailability other) : base(other) { Name_ = other.Name_; }
private void btnOK_Click(object sender, EventArgs e) { // take focus away from time pickers btnOK.Focus(); // if no day is selected if (ddDay.SelectedIndex == -1) { MessageBox.Show("Please select a day.", "Unavailable Timeslot", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); ddDay.Focus(); return; } // get start and end times from input TimeOfDay start = TimeOfDay.FromDateTime(timeStart.Value); TimeOfDay end = TimeOfDay.FromDateTime(timeEnd.Value); // if it starts before it ends if (start >= end) { MessageBox.Show("Start time must be before end time.", "Unavailable Timeslot", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // if it's not within the scope of the timetable if (end <= new TimeOfDay(Earliest_, 0)) { MessageBox.Show("End time must be after 8am.", "Unavailable Timeslot", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); timeEnd.Focus(); return; } if (start >= new TimeOfDay(Latest_, 0)) { MessageBox.Show("Start time must be before 9pm.", "Unavailable Timeslot", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); timeStart.Focus(); return; } // clip the timeslot to be within the bounds of the timetable if (start < new TimeOfDay(Earliest_, 0)) { start = new TimeOfDay(Earliest_, 0); } if (end > new TimeOfDay(Latest_, 0)) { end = new TimeOfDay(Latest_, 0); } // build new unavailability from input Unavailability unavail = new Unavailability(txtName.Text, ddDay.SelectedIndex, start.Hour, start.Minute, end.Hour, end.Minute); if (Unavail_ != null && Unavail_.EquivalentTo(unavail) && Unavail_.Name == unavail.Name) { DialogResult = DialogResult.Cancel; Close(); return; } // if editing, remove the old timeslot if (Unavail_ != null) { Timetable_.UnavailableList.Remove(Unavail_); } // if it doesn't fit in the current timetable if (!Timetable_.FreeDuring(unavail, true)) { MessageBox.Show("Selected time slot is currently occupied.", "Unavailable Timeslot", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); // if editing, add the old timeslot back in if (Unavail_ != null) { Timetable_.UnavailableList.Add(Unavail_); } return; } // insert the edited timeslot Timetable_.UnavailableList.Add(unavail); // recompute solutions Timetable_.RecomputeSolutions = true; // return DialogResult = DialogResult.OK; Close(); }