示例#1
0
        public void ResetPosition(bool showHelp = true)
        {
            if (window.ScheduleGrid.Children.Contains(this))
            {
                window.ScheduleGrid.Children.Remove(this);
            }
            if (!originalParent.Children.Contains(this))
            {
                originalParent.Children.Add(this);
            }
            Margin = originalMargin;
            Height = originalHeight;
            SectionType.Content = type;
            BG.RadiusX          = radius.X;
            BG.RadiusY          = radius.Y;
            onGrid = false;
            if (showHelp)
            {
                searchParent.Dragging_Info.Visibility = Visibility.Visible;
            }
            Grid.SetZIndex(this, -10);

            for (int i = 0; i < sections.Length; i++)
            {
                for (int j = 0; j < sections[i].Length; j++)
                {
                    GridSection g = sections[i][j];
                    g.SetStay(false);
                    g.ShadowConnected();
                }
            }
        }
示例#2
0
 private void Window_MouseMove(object sender, MouseEventArgs e)
 {
     if (released == null)
     {
         foreach (UIElement ui in ScheduleGrid.Children)
         {
             GridSection gs = ui as GridSection;
             if (gs != null)
             {
                 bool anyHovering = false;
                 foreach (GridSection g in gs.connected)
                 {
                     Point p = Mouse.GetPosition(g);
                     anyHovering = anyHovering || IsHoveringGridSection(g, p);
                 }
                 if (anyHovering)
                 {
                     gs.HighlightConnected();
                 }
                 else
                 {
                     gs.ShadowConnected();
                 }
             }
         }
         if (IsHoveringGarbage(TrashEmpty) || IsHoveringGarbage(TrashFull))
         {
             Garbage_MouseEnter();
         }
         else
         {
             Garbage_MouseLeave();
         }
     }
 }
示例#3
0
        private void PlaceOnGrid(GridSection gs)
        {
            bool inOldSpot = (Grid.GetRow(gs) == Grid.GetRow(released)) && (Grid.GetColumn(gs) == Grid.GetColumn(released)) && (Grid.GetRowSpan(released) == Grid.GetRowSpan(gs));

            Grid.SetRow(released, Grid.GetRow(gs));
            Grid.SetColumn(released, Grid.GetColumn(gs));
            Grid.SetRowSpan(released, Grid.GetRowSpan(gs));
            Grid.SetZIndex(released, -10);
            released.VerticalAlignment = VerticalAlignment.Top;
            released.Height            = gs.Height;
            released.Margin            = gs.Margin;
            released.OnGridPlace();
            released.linked = gs;
            if (gs.parentClass.enrolled && !inOldSpot)
            {
                gs.parentClass.SetEnrollment(false);
                foreach (CourseListItem cli in enrolled)
                {
                    if (cli.name.Equals(gs.parentClass.data.name))
                    {
                        cli.SetEnrollment(false, false);
                        break;
                    }
                }
            }
            released = null;
        }
示例#4
0
        public ClassSection(MainWindow Window, bool IsTutorial, Panel OriginalParent, ClassData Data, Brush Color, SearchItem SearchParent)
        {
            InitializeComponent();

            window       = Window;
            searchParent = SearchParent;

            originalParent = OriginalParent;
            originalMargin = new Thickness(5, 0, 5, 0);
            originalHeight = Height;

            data                = Data;
            isTutorial          = IsTutorial;
            name                = data.name;
            type                = (IsTutorial) ? "Tutorial" : "Lecture";
            SectionType.Content = type;
            radius              = new Point(BG.RadiusX, BG.RadiusY);
            color               = Color;
            BG.Fill             = Color;
            placedOnce          = false;
            onGrid              = false;
            other               = null;

            TimeSlot[] slots = (IsTutorial) ? Data.tutorialSlots : Data.timeSlots;

            sections = new GridSection[slots.Length][];
            for (int j = 0; j < slots.Length; j++)
            {
                TimeSlot t = slots[j];
                time = getTime(t.startTime, t.duration);
                GridSection[] gs = new GridSection[t.days.Length];
                for (int i = 0; i < t.days.Length; i++)
                {
                    GridSection g = new GridSection(this, name, type, color, t.location, time, t);
                    Grid.SetRow(g, (int)Math.Floor(t.startTime));
                    Grid.SetColumn(g, t.days[i]);
                    Grid.SetRowSpan(g, (int)Math.Ceiling(t.duration));
                    g.VerticalAlignment = VerticalAlignment.Top;
                    double defaultHeight = 116.5;
                    double height        = t.duration * defaultHeight;
                    g.Height = height;
                    Thickness thickness = new Thickness(0);
                    thickness.Top = (t.startTime - Math.Floor(t.startTime)) * defaultHeight;
                    g.Margin      = thickness;
                    gs[i]         = g;
                    window.ScheduleGrid.Children.Add(g);
                }
                foreach (GridSection g in gs)
                {
                    g.SetConnected(gs);
                }
                if (gs.Length > 0)
                {
                    gs[0].HideConnected();
                }
                sections[j] = gs;
            }
        }
示例#5
0
        private bool IsHoveringGridSection(GridSection gs, Point p)
        {
            bool inX = gs.Margin.Left <= p.X && gs.Margin.Left + gs.ActualWidth >= p.X;
            bool a   = gs.Margin.Top <= p.Y;
            bool b   = gs.ActualHeight >= p.Y;
            bool inY = a && b;

            return(inX && inY);
        }
示例#6
0
        // Make rectangle
        public void OnGridPlace(bool SetHeight = false)
        {
            BG.RadiusX          = 0;
            BG.RadiusY          = 0;
            SectionType.Content = name + " " + type;
            placedOnce          = true;
            onGrid = true;

            for (int i = 0; i < sections.Length; i++)
            {
                for (int j = 0; j < sections[i].Length; j++)
                {
                    GridSection g = sections[i][j];
                    if (Grid.GetRow(g) == Grid.GetRow(this) && Grid.GetColumn(g) == Grid.GetColumn(this))
                    {
                        Grid.SetRowSpan(this, Grid.GetRowSpan(g));
                        g.SetStay(true);
                        g.HighlightConnected();
                        g.ShowConnected();
                        if (SetHeight)
                        {
                            Height = g.Height;
                        }
                        break;
                    }
                    else
                    {
                        g.SetStay(false);
                        g.ShadowConnected();
                        g.HideConnected();
                    }
                }
            }

            if (originalParent.Children.Count == 0)
            {
                searchParent.Dragging_Info.Visibility = Visibility.Collapsed;
                bool alreadyPlaced = false;
                foreach (UIElement ui in window.ListOfCourses.Children)
                {
                    CourseListItem cli = ui as CourseListItem;
                    if (cli != null && cli.name == name)
                    {
                        alreadyPlaced = true;
                        break;
                    }
                }

                if (!alreadyPlaced)
                {
                    window.ListOfCourses.Children.Add(new CourseListItem(this, other, window));
                }
            }
        }
示例#7
0
        // dropping a course onto the schedule
        private void ScheduleGrid_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (released != null)
            {
                bool dropConflict = false;
                foreach (UIElement ui in ScheduleGrid.Children)
                {
                    GridSection gs = ui as GridSection;
                    if (gs != null)
                    {
                        Point p = Mouse.GetPosition(gs);
                        if (IsHoveringGridSection(gs, p) && gs.parentClass == released)
                        {
                            if (!IsReleasedConflicting(gs))
                            {
                                PlaceOnGrid(gs);
                                break;
                            }
                            else
                            {
                                if (!conflicting.parentClass.data.name.Equals(gs.parentClass.data.name))
                                {
                                    ConfirmationWin win = CreateWindow("Dropping", "Are you sure you wish to drop " + conflicting.parentClass.data.name + " to add " + released.data.name + "?");
                                    win.ShowDialog();

                                    if (ConfirmResult)
                                    {
                                        dropConflict = true;
                                        PlaceOnGrid(gs);
                                    }
                                }
                            }
                        }
                    }
                }
                if (dropConflict)
                {
                    conflicting.parentClass.ResetPosition(false);
                    conflicting.parentClass.HideConnected();
                    ClassSection other = conflicting.parentClass.other;
                    if (other != null)
                    {
                        if (other.onGrid)
                        {
                            other.ResetPosition(false);
                            other.HideConnected();
                        }
                    }
                    CourseList_Clear(conflicting.parentClass.data.name);
                }
            }
        }
示例#8
0
 private bool IsReleasedConflicting(GridSection section)
 {
     foreach (UIElement ui in ScheduleGrid.Children)
     {
         GridSection other = ui as GridSection;
         if (other != null && !section.connected.Contains(other) && other.Visibility == Visibility.Visible)
         {
             float start = other.timeSlot.startTime;
             float end   = other.timeSlot.endTime;
             int   col   = Grid.GetColumn(other);
             int   row   = Grid.GetRow(other);
             foreach (GridSection gs in section.connected)
             {
                 float gsStart       = gs.timeSlot.startTime;
                 float gsEnd         = gs.timeSlot.endTime;
                 int   gsCol         = Grid.GetColumn(gs);
                 int   gsRow         = Grid.GetRow(gs);
                 bool  startConflict = gsStart >= start && gsStart <= end;
                 bool  endConflict   = gsEnd >= start && gsEnd <= end;
                 if (gsCol == col)
                 {
                     if (gsRow == row)
                     {
                         conflicting = other;
                         return(true);
                     }
                     else if ((startConflict && gsStart != end) || (endConflict && gsEnd != start))
                     {
                         conflicting = other;
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }