Ejemplo n.º 1
0
        private void treePreview_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // clear textbox
            txtTreeDetails.Text = "";
            // if nothing selected, done already
            if (treePreview.SelectedNode == null)
            {
                return;
            }

            // level 0: subject
            if (treePreview.SelectedNode.Level == 0)
            {
                // get subject
                Subject subject = (Subject)treePreview.SelectedNode.Tag;
                // print subject name
                txtTreeDetails.Text += subject.Name + "\r\n";
                // print all the types within the subject
                foreach (Type type in subject.Types)
                {
                    txtTreeDetails.Text += "\r\n\t" + type.Name + " (" + type.Streams.Count + ")";
                }
                // preview pane
                timetableControl1.Timetable = Timetable.From(subject);
            }
            // level 1: type
            else if (treePreview.SelectedNode.Level == 1)
            {
                // get type
                Type type = (Type)treePreview.SelectedNode.Tag;
                // print type name
                txtTreeDetails.Text += type.Subject.Name + " " + type.Name + "\r\n";
                // print all the streams within the type
                foreach (Stream stream in type.Streams)
                {
                    txtTreeDetails.Text += "\r\n\t" + stream.ToString();
                }
                // preview pane
                timetableControl1.Timetable = Timetable.From(type);
            }
            // level 2: stream
            else
            {
                // get stream
                Stream stream = (Stream)treePreview.SelectedNode.Tag;
                // print stream name
                txtTreeDetails.Text += stream.Type.Subject.Name + " " + stream.ToString();
                // print all the classes within the type
                foreach (Session session in stream.Classes)
                {
                    txtTreeDetails.Text += "\r\n\t\r\n\t" + session.ToString();
                }
                // preview pane
                timetableControl1.Timetable = Timetable.From(stream);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }