Exemplo n.º 1
0
        /// <summary>
        /// Shows flyoutmenu for one lesson
        /// </summary>
        /// <param name="lessonGrid">grid where lesson's placed</param>
        public static void ShowFlyOutMenuForLesson(Grid lessonGrid, int lesssonId = 0, bool inPlaceView = false)
        {
            if (_clickedLessonId != lesssonId)
            {
                _clickedLessonId = lesssonId;
            }

            var lesson = Lesson.GetLessonFromLessonGrid(lessonGrid, _timeTable);

            var thicknes5  = new Thickness(5.0);
            var thickness1 = new Thickness(1.0);
            var color      = new SolidColorBrush(Colors.Brown);

            Button flyoutButtonClass = null;

            if (!inPlaceView)
            {
                flyoutButtonClass = new Button
                {
                    Content         = "Pokaż salę" + Environment.NewLine + (_clickedLessonId == 0 ? lesson.lesson1Place : lesson.lesson2Place),
                    Padding         = thicknes5,
                    Margin          = thicknes5,
                    BorderBrush     = color,
                    BorderThickness = thickness1
                };
                flyoutButtonClass.Click += FlyoutButton_Click;
            }

            var flyoutButtonSubject = new Button
            {
                Content         = "Pokaż przedmiot" + Environment.NewLine + (_clickedLessonId == 0 ? lesson.lesson1Name : lesson.lesson2Name),
                Padding         = thicknes5,
                Margin          = thicknes5,
                BorderBrush     = color,
                BorderThickness = thickness1
            };

            flyoutButtonSubject.Click += FlyoutButton_Click;
            Grid.SetColumn(flyoutButtonSubject, 1);

            Button flyoutButtonTeacher = null;

            if (!lesson.IsLessonTeacherLesson())
            {
                var teacherName = _clickedLessonId == 0 ? lesson.lesson1Tag : lesson.lesson2Tag;

                var timetableOfTeacher = _timeTable.TimetableOfTeachers.FirstOrDefault(p => p.name.Substring(p.name.IndexOf('('),
                                                                                                             p.name.IndexOf(p.name.ElementAt((p.name.Length - 1) - p.name.IndexOf('(')))).Contains(teacherName.Replace("#", "").Trim()));

                if (timetableOfTeacher == null) // thgere was problem with #Pa; linq expression ^ did not found it
                {
                    timetableOfTeacher = _timeTable.TimetableOfTeachers.First(p => p.name.Contains("J.Pusiak"));
                }

                flyoutButtonTeacher = new Button
                {
                    Content         = "Pokaż nauczyciela" + Environment.NewLine + timetableOfTeacher.name,
                    Padding         = thicknes5,
                    Margin          = thicknes5,
                    BorderBrush     = color,
                    BorderThickness = thickness1
                };

                flyoutButtonTeacher.Click += FlyoutButton_Click;
            }
            ShowFlyOutMenu(lessonGrid, flyoutButtonClass, flyoutButtonSubject, flyoutButtonTeacher);
        }